blob: 44d6ae78bf943850592b444af95360e49528a8c7 [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
Cody Northropbca3bcd2015-10-27 16:54:28 -06001163// Disable these two tests until we can sort out how to track multiple layer errors
1164#if 0
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001165TEST_F(VkLayerTest, ViewportStateNotBound)
1166{
1167 VkFlags msgFlags;
1168 std::string msgString;
1169 m_errorMonitor->ClearState();
1170 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1171
1172 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1173
1174 msgFlags = m_errorMonitor->GetState(&msgString);
1175 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 -06001176 // TODO : Viewport and scissor currently set as a pair in framework so scissor error masks viewport error
1177 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1178 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001179 }
1180}
1181
1182TEST_F(VkLayerTest, ScissorStateNotBound)
1183{
1184 VkFlags msgFlags;
1185 std::string msgString;
1186 m_errorMonitor->ClearState();
1187 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1188
1189 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1190
1191 msgFlags = m_errorMonitor->GetState(&msgString);
1192 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
1193 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1194 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
1195 }
1196}
Cody Northropbca3bcd2015-10-27 16:54:28 -06001197#endif
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001198
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001199TEST_F(VkLayerTest, BlendStateNotBound)
1200{
1201 VkFlags msgFlags;
1202 std::string msgString;
1203 m_errorMonitor->ClearState();
1204 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1205
1206 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1207
1208 msgFlags = m_errorMonitor->GetState(&msgString);
1209 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
1210 if (!strstr(msgString.c_str(),"Dynamic blend object state not set for this command buffer")) {
1211 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic blend object state not set for this command buffer'";
1212 }
1213}
1214
1215TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1216{
1217 VkFlags msgFlags;
1218 std::string msgString;
1219 m_errorMonitor->ClearState();
1220 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1221
1222 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1223
1224 msgFlags = m_errorMonitor->GetState(&msgString);
1225 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
1226 if (!strstr(msgString.c_str(),"Dynamic depth bounds state not set for this command buffer")) {
1227 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bounds state not set for this command buffer'";
1228 }
1229}
1230
1231TEST_F(VkLayerTest, StencilReadMaskNotSet)
1232{
1233 VkFlags msgFlags;
1234 std::string msgString;
1235 ASSERT_NO_FATAL_FAILURE(InitState());
1236 m_errorMonitor->ClearState();
1237 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1238
1239 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1240
1241 msgFlags = m_errorMonitor->GetState(&msgString);
1242 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Read Mask";
1243 if (!strstr(msgString.c_str(),"Dynamic stencil read mask state not set for this command buffer")) {
1244 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil read mask state not set for this command buffer'";
1245 }
1246}
1247
1248TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1249{
1250 VkFlags msgFlags;
1251 std::string msgString;
1252 ASSERT_NO_FATAL_FAILURE(InitState());
1253 m_errorMonitor->ClearState();
1254 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1255
1256 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1257
1258 msgFlags = m_errorMonitor->GetState(&msgString);
1259 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Write Mask";
1260 if (!strstr(msgString.c_str(),"Dynamic stencil write mask state not set for this command buffer")) {
1261 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil write mask state not set for this command buffer'";
1262 }
1263}
1264
1265TEST_F(VkLayerTest, StencilReferenceNotSet)
1266{
1267 VkFlags msgFlags;
1268 std::string msgString;
1269 m_errorMonitor->ClearState();
1270 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1271
1272 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1273
1274 msgFlags = m_errorMonitor->GetState(&msgString);
1275 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Reference";
1276 if (!strstr(msgString.c_str(),"Dynamic stencil reference state not set for this command buffer")) {
1277 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil reference state not set for this command buffer'";
1278 }
1279}
1280
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001281TEST_F(VkLayerTest, CmdBufferTwoSubmits)
1282{
1283 vk_testing::Fence testFence;
1284 VkFlags msgFlags;
1285 std::string msgString;
1286
1287 VkFenceCreateInfo fenceInfo = {};
1288 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1289 fenceInfo.pNext = NULL;
1290 fenceInfo.flags = 0;
1291
1292 ASSERT_NO_FATAL_FAILURE(InitState());
1293 ASSERT_NO_FATAL_FAILURE(InitViewport());
1294 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1295
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -06001296 // 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 -06001297 BeginCommandBuffer();
1298 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1299 EndCommandBuffer();
1300
1301 testFence.init(*m_device, fenceInfo);
1302
1303 // Bypass framework since it does the waits automatically
1304 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001305 VkSubmitInfo submit_info;
1306 submit_info.waitSemCount = 0;
1307 submit_info.pWaitSemaphores = NULL;
1308 submit_info.cmdBufferCount = 1;
1309 submit_info.pCommandBuffers = &m_cmdBuffer->handle();
1310 submit_info.signalSemCount = 0;
1311 submit_info.pSignalSemaphores = NULL;
1312
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001313 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001314 ASSERT_VK_SUCCESS( err );
1315
1316 m_errorMonitor->ClearState();
1317 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001318 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001319
1320 msgFlags = m_errorMonitor->GetState(&msgString);
1321 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 -06001322 if (!strstr(msgString.c_str(),"was begun w/ VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted")) {
1323 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 -06001324 }
1325}
1326
Tobin Ehlise4076782015-06-24 15:53:07 -06001327TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001328{
1329 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001330 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001331 std::string msgString;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001332 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001333
1334 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001335 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001336 m_errorMonitor->ClearState();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001337
1338 VkDescriptorTypeCount ds_type_count = {};
1339 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1340 ds_type_count.count = 1;
1341
1342 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1343 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1344 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001345 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001346 ds_pool_ci.count = 1;
1347 ds_pool_ci.pTypeCount = &ds_type_count;
1348
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001349 VkDescriptorPool ds_pool;
1350 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001351 ASSERT_VK_SUCCESS(err);
1352
1353 VkDescriptorSetLayoutBinding dsl_binding = {};
1354 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1355 dsl_binding.arraySize = 1;
1356 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1357 dsl_binding.pImmutableSamplers = NULL;
1358
1359 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1360 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1361 ds_layout_ci.pNext = NULL;
1362 ds_layout_ci.count = 1;
1363 ds_layout_ci.pBinding = &dsl_binding;
1364
1365 VkDescriptorSetLayout ds_layout;
1366 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1367 ASSERT_VK_SUCCESS(err);
1368
1369 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001370 VkDescriptorSetAllocInfo alloc_info = {};
1371 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1372 alloc_info.count = 1;
1373 alloc_info.descriptorPool = ds_pool;
1374 alloc_info.pSetLayouts = &ds_layout;
1375 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001376 ASSERT_VK_SUCCESS(err);
1377 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1378 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1379 pipe_ms_state_ci.pNext = NULL;
1380 pipe_ms_state_ci.rasterSamples = 1;
1381 pipe_ms_state_ci.sampleShadingEnable = 0;
1382 pipe_ms_state_ci.minSampleShading = 1.0;
1383 pipe_ms_state_ci.pSampleMask = NULL;
1384
1385 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1386 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1387 pipeline_layout_ci.pNext = NULL;
1388 pipeline_layout_ci.descriptorSetCount = 1;
1389 pipeline_layout_ci.pSetLayouts = &ds_layout;
1390 VkPipelineLayout pipeline_layout;
1391
1392 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1393 ASSERT_VK_SUCCESS(err);
1394
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001395 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1396 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 -06001397 // but add it to be able to run on more devices
1398 VkPipelineObj pipe(m_device);
1399 pipe.AddShader(&vs);
1400 pipe.AddShader(&fs);
1401 pipe.SetMSAA(&pipe_ms_state_ci);
1402 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1403 m_errorMonitor->ClearState();
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001404 // Calls AllocCommandBuffers
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001405 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1406 VkCmdBufferBeginInfo cmd_buf_info = {};
1407 memset(&cmd_buf_info, 0, sizeof(VkCmdBufferBeginInfo));
1408 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1409 cmd_buf_info.pNext = NULL;
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -06001410 cmd_buf_info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001411
1412 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1413 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001414 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001415 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 -06001416 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001417 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 -06001418 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001419
1420 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001421 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1422 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001423}
1424
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001425TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1426{
1427 // Initiate Draw w/o a PSO bound
1428 VkFlags msgFlags;
1429 std::string msgString;
1430 VkResult err;
1431
1432 ASSERT_NO_FATAL_FAILURE(InitState());
1433 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1434 m_errorMonitor->ClearState();
1435
1436 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
1437 VkDescriptorTypeCount ds_type_count = {};
1438 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
1439 ds_type_count.count = 1;
1440
1441 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1442 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1443 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001444 ds_pool_ci.flags = 0;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001445 ds_pool_ci.maxSets = 1;
1446 ds_pool_ci.count = 1;
1447 ds_pool_ci.pTypeCount = &ds_type_count;
1448
1449 VkDescriptorPool ds_pool;
1450 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1451 ASSERT_VK_SUCCESS(err);
1452
1453 VkDescriptorSetLayoutBinding dsl_binding = {};
1454 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1455 dsl_binding.arraySize = 1;
1456 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1457 dsl_binding.pImmutableSamplers = NULL;
1458
1459 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1460 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1461 ds_layout_ci.pNext = NULL;
1462 ds_layout_ci.count = 1;
1463 ds_layout_ci.pBinding = &dsl_binding;
1464
1465 VkDescriptorSetLayout ds_layout;
1466 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1467 ASSERT_VK_SUCCESS(err);
1468
1469 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001470 VkDescriptorSetAllocInfo alloc_info = {};
1471 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1472 alloc_info.count = 1;
1473 alloc_info.descriptorPool = ds_pool;
1474 alloc_info.pSetLayouts = &ds_layout;
1475 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001476
1477 msgFlags = m_errorMonitor->GetState(&msgString);
1478 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after alloc descriptor from pool w/o requested type";
1479 if (!strstr(msgString.c_str(),"Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ")) {
1480 FAIL() << "Error received was not 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...' but rather '" << msgString.c_str() << "'";
1481 }
1482
1483 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1484 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1485}
1486
Tobin Ehlis3c543112015-10-08 13:13:50 -06001487TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1488{
1489 VkFlags msgFlags;
1490 std::string msgString;
1491 VkResult err;
1492
1493 ASSERT_NO_FATAL_FAILURE(InitState());
1494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1495 m_errorMonitor->ClearState();
1496
1497 VkDescriptorTypeCount ds_type_count = {};
1498 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1499 ds_type_count.count = 1;
1500
1501 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1502 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1503 ds_pool_ci.pNext = NULL;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001504 ds_pool_ci.maxSets = 1;
1505 ds_pool_ci.count = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001506 ds_pool_ci.flags = 0;
1507 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1508 // app can only call vkResetDescriptorPool on this pool.;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001509 ds_pool_ci.pTypeCount = &ds_type_count;
1510
1511 VkDescriptorPool ds_pool;
1512 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1513 ASSERT_VK_SUCCESS(err);
1514
1515 VkDescriptorSetLayoutBinding dsl_binding = {};
1516 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1517 dsl_binding.arraySize = 1;
1518 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1519 dsl_binding.pImmutableSamplers = NULL;
1520
1521 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1522 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1523 ds_layout_ci.pNext = NULL;
1524 ds_layout_ci.count = 1;
1525 ds_layout_ci.pBinding = &dsl_binding;
1526
1527 VkDescriptorSetLayout ds_layout;
1528 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1529 ASSERT_VK_SUCCESS(err);
1530
1531 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001532 VkDescriptorSetAllocInfo alloc_info = {};
1533 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1534 alloc_info.count = 1;
1535 alloc_info.descriptorPool = ds_pool;
1536 alloc_info.pSetLayouts = &ds_layout;
1537 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001538 ASSERT_VK_SUCCESS(err);
1539
1540 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1541 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001542 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after freeing descriptor from non-free Pool";
1543
1544 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 -06001545 FAIL() << "Error received was not 'It is invalid to call vkFreeDescriptorSets() with a pool created with...' but instead it was '" << msgString.c_str() << "'";
1546 }
1547
1548 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1549 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1550}
1551
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001552TEST_F(VkLayerTest, InvalidDescriptorPool)
1553{
1554 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1555 // The DS check for this is after driver has been called to validate DS internal data struct
1556 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001557/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001558 std::string msgString;
1559 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1560 vkResetDescriptorPool(device(), badPool);
1561
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001562 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001563 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 -06001564 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1565 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1566 }*/
1567}
1568
1569TEST_F(VkLayerTest, InvalidDescriptorSet)
1570{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001571 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1572 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001573 // Create a valid cmd buffer
1574 // call vkCmdBindDescriptorSets w/ false DS
1575}
1576
1577TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1578{
1579 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1580 // The DS check for this is after driver has been called to validate DS internal data struct
1581}
1582
1583TEST_F(VkLayerTest, InvalidPipeline)
1584{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001585 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1586 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001587 // Create a valid cmd buffer
1588 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001589// VkFlags msgFlags;
1590// std::string msgString;
1591//
1592// ASSERT_NO_FATAL_FAILURE(InitState());
1593// m_errorMonitor->ClearState();
1594// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001595// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001596// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1597// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1598// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001599// 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 -06001600// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1601// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1602// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001603}
1604
Tobin Ehlis254eca02015-06-25 15:46:59 -06001605TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001606{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001607 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001608 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001609 std::string msgString;
1610 VkResult err;
1611
1612 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001613 ASSERT_NO_FATAL_FAILURE(InitViewport());
1614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001615 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001616 VkDescriptorTypeCount ds_type_count = {};
1617 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1618 ds_type_count.count = 1;
1619
1620 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1621 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1622 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001623 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001624 ds_pool_ci.count = 1;
1625 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001626
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001627 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001628 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001629 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001630
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001631 VkDescriptorSetLayoutBinding dsl_binding = {};
1632 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1633 dsl_binding.arraySize = 1;
1634 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1635 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001636
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001637 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1638 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1639 ds_layout_ci.pNext = NULL;
1640 ds_layout_ci.count = 1;
1641 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001642 VkDescriptorSetLayout ds_layout;
1643 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1644 ASSERT_VK_SUCCESS(err);
1645
1646 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001647 VkDescriptorSetAllocInfo alloc_info = {};
1648 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1649 alloc_info.count = 1;
1650 alloc_info.descriptorPool = ds_pool;
1651 alloc_info.pSetLayouts = &ds_layout;
1652 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001653 ASSERT_VK_SUCCESS(err);
1654
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001655 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1656 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1657 pipeline_layout_ci.pNext = NULL;
1658 pipeline_layout_ci.descriptorSetCount = 1;
1659 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001660
1661 VkPipelineLayout pipeline_layout;
1662 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1663 ASSERT_VK_SUCCESS(err);
1664
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001665 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1666 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 -06001667 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001668
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001669 VkPipelineObj pipe(m_device);
1670 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001671 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001672 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001673
1674 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001675 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001676 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001677
Tobin Ehlis254eca02015-06-25 15:46:59 -06001678 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001679 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 -06001680 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1681 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1682 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001683
1684 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001685 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1686 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001687}
1688
1689TEST_F(VkLayerTest, NoBeginCmdBuffer)
1690{
1691 VkFlags msgFlags;
1692 std::string msgString;
1693
1694 ASSERT_NO_FATAL_FAILURE(InitState());
1695 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001696 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001697 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1698 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1699 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001700 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 -06001701 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1702 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1703 }
1704}
1705
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001706TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1707{
1708 VkFlags msgFlags;
1709 std::string msgString;
1710
1711 ASSERT_NO_FATAL_FAILURE(InitState());
1712 m_errorMonitor->ClearState();
1713
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001714 // Calls AllocCommandBuffers
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001715 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1716
1717 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001718 VkCmdBufferBeginInfo cmd_buf_info = {};
1719 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1720 cmd_buf_info.pNext = NULL;
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -06001721 cmd_buf_info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northrop10d8f982015-08-04 17:35:57 -06001722 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1723 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1724
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001725
1726 // The error should be caught by validation of the BeginCommandBuffer call
1727 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1728
1729 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001730 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 -06001731 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001732 FAIL() << "Error received was not 'vkAllocCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001733 }
1734}
1735
1736TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1737{
1738 VkFlags msgFlags;
1739 std::string msgString;
1740 VkResult err;
1741 VkCmdBuffer draw_cmd;
1742 VkCmdPool cmd_pool;
1743
1744 ASSERT_NO_FATAL_FAILURE(InitState());
1745 m_errorMonitor->ClearState();
1746
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001747 VkCmdBufferAllocInfo cmd = {};
1748 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_ALLOC_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06001749 cmd.pNext = NULL;
1750 cmd.cmdPool = m_cmdPool;
1751 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001752 cmd.count = 1;
Cody Northrop10d8f982015-08-04 17:35:57 -06001753
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001754 err = vkAllocCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06001755 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001756
1757 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001758 VkCmdBufferBeginInfo cmd_buf_info = {};
1759 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1760 cmd_buf_info.pNext = NULL;
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -06001761 cmd_buf_info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001762
1763 // The error should be caught by validation of the BeginCommandBuffer call
1764 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1765
1766 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001767 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 -06001768 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001769 FAIL() << "Error received was not 'vkAllocCommandBuffers(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001770 }
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001771 vkFreeCommandBuffers(m_device->device(), m_cmdPool, 1, &draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001772}
1773
Tobin Ehlis254eca02015-06-25 15:46:59 -06001774TEST_F(VkLayerTest, InvalidPipelineCreateState)
1775{
1776 // Attempt to Create Gfx Pipeline w/o a VS
1777 VkFlags msgFlags;
1778 std::string msgString;
1779 VkResult err;
1780
1781 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001782 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06001783 m_errorMonitor->ClearState();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001784
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001785 VkDescriptorTypeCount ds_type_count = {};
1786 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1787 ds_type_count.count = 1;
1788
1789 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1790 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1791 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001792 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001793 ds_pool_ci.count = 1;
1794 ds_pool_ci.pTypeCount = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001795
Tobin Ehlis254eca02015-06-25 15:46:59 -06001796 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001797 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001798 ASSERT_VK_SUCCESS(err);
1799
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001800 VkDescriptorSetLayoutBinding dsl_binding = {};
1801 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1802 dsl_binding.arraySize = 1;
1803 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1804 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001805
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001806 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1807 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1808 ds_layout_ci.pNext = NULL;
1809 ds_layout_ci.count = 1;
1810 ds_layout_ci.pBinding = &dsl_binding;
1811
Tobin Ehlis254eca02015-06-25 15:46:59 -06001812 VkDescriptorSetLayout ds_layout;
1813 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1814 ASSERT_VK_SUCCESS(err);
1815
1816 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001817 VkDescriptorSetAllocInfo alloc_info = {};
1818 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1819 alloc_info.count = 1;
1820 alloc_info.descriptorPool = ds_pool;
1821 alloc_info.pSetLayouts = &ds_layout;
1822 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001823 ASSERT_VK_SUCCESS(err);
1824
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001825 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1826 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001827 pipeline_layout_ci.descriptorSetCount = 1;
1828 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001829
1830 VkPipelineLayout pipeline_layout;
1831 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1832 ASSERT_VK_SUCCESS(err);
1833
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001834 VkViewport vp = {}; // Just need dummy vp to point to
1835 VkRect2D sc = {}; // dummy scissor to point to
1836
1837 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1838 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1839 vp_state_ci.scissorCount = 1;
1840 vp_state_ci.pScissors = &sc;
1841 vp_state_ci.viewportCount = 1;
1842 vp_state_ci.pViewports = &vp;
1843
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001844 VkGraphicsPipelineCreateInfo gp_ci = {};
1845 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001846 gp_ci.pViewportState = &vp_state_ci;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001847 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1848 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001849 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001850
1851 VkPipelineCacheCreateInfo pc_ci = {};
1852 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001853 pc_ci.initialSize = 0;
1854 pc_ci.initialData = 0;
1855 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001856
1857 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001858 VkPipelineCache pipelineCache;
1859
1860 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1861 ASSERT_VK_SUCCESS(err);
1862 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001863
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001864 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001865 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 -06001866 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1867 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1868 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001869
1870 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1871 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001872 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1873 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001874}
Tobin Ehlis20693172015-09-17 08:46:18 -06001875/*// TODO : This test should be good, but needs Tess support in compiler to run
1876TEST_F(VkLayerTest, InvalidPatchControlPoints)
1877{
1878 // Attempt to Create Gfx Pipeline w/o a VS
1879 VkFlags msgFlags;
1880 std::string msgString;
1881 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001882
Tobin Ehlis20693172015-09-17 08:46:18 -06001883 ASSERT_NO_FATAL_FAILURE(InitState());
1884 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1885 m_errorMonitor->ClearState();
1886
1887 VkDescriptorTypeCount ds_type_count = {};
1888 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1889 ds_type_count.count = 1;
1890
1891 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1892 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1893 ds_pool_ci.pNext = NULL;
1894 ds_pool_ci.count = 1;
1895 ds_pool_ci.pTypeCount = &ds_type_count;
1896
1897 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001898 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, &ds_pool);
Tobin Ehlis20693172015-09-17 08:46:18 -06001899 ASSERT_VK_SUCCESS(err);
1900
1901 VkDescriptorSetLayoutBinding dsl_binding = {};
1902 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1903 dsl_binding.arraySize = 1;
1904 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1905 dsl_binding.pImmutableSamplers = NULL;
1906
1907 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1908 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1909 ds_layout_ci.pNext = NULL;
1910 ds_layout_ci.count = 1;
1911 ds_layout_ci.pBinding = &dsl_binding;
1912
1913 VkDescriptorSetLayout ds_layout;
1914 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1915 ASSERT_VK_SUCCESS(err);
1916
1917 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001918 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis20693172015-09-17 08:46:18 -06001919 ASSERT_VK_SUCCESS(err);
1920
1921 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1922 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1923 pipeline_layout_ci.pNext = NULL;
1924 pipeline_layout_ci.descriptorSetCount = 1;
1925 pipeline_layout_ci.pSetLayouts = &ds_layout;
1926
1927 VkPipelineLayout pipeline_layout;
1928 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1929 ASSERT_VK_SUCCESS(err);
1930
1931 VkPipelineShaderStageCreateInfo shaderStages[3];
1932 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1933
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001934 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06001935 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001936 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
1937 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06001938
1939 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001940 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001941 shaderStages[0].shader = vs.handle();
1942 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001943 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001944 shaderStages[1].shader = tc.handle();
1945 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001946 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001947 shaderStages[2].shader = te.handle();
1948
1949 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1950 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1951 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1952
1953 VkPipelineTessellationStateCreateInfo tsCI = {};
1954 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1955 tsCI.patchControlPoints = 0; // This will cause an error
1956
1957 VkGraphicsPipelineCreateInfo gp_ci = {};
1958 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1959 gp_ci.pNext = NULL;
1960 gp_ci.stageCount = 3;
1961 gp_ci.pStages = shaderStages;
1962 gp_ci.pVertexInputState = NULL;
1963 gp_ci.pInputAssemblyState = &iaCI;
1964 gp_ci.pTessellationState = &tsCI;
1965 gp_ci.pViewportState = NULL;
1966 gp_ci.pRasterState = NULL;
1967 gp_ci.pMultisampleState = NULL;
1968 gp_ci.pDepthStencilState = NULL;
1969 gp_ci.pColorBlendState = NULL;
1970 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1971 gp_ci.layout = pipeline_layout;
1972 gp_ci.renderPass = renderPass();
1973
1974 VkPipelineCacheCreateInfo pc_ci = {};
1975 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1976 pc_ci.pNext = NULL;
1977 pc_ci.initialSize = 0;
1978 pc_ci.initialData = 0;
1979 pc_ci.maxSize = 0;
1980
1981 VkPipeline pipeline;
1982 VkPipelineCache pipelineCache;
1983
1984 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1985 ASSERT_VK_SUCCESS(err);
1986 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1987
1988 msgFlags = m_errorMonitor->GetState(&msgString);
1989 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Tess Gfx Pipeline w/ 0 patchControlPoints.";
1990 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ")) {
1991 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...' but instead '" << msgString.c_str() << "'";
1992 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001993
1994 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1995 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001996 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1997 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis20693172015-09-17 08:46:18 -06001998}
1999*/
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002000// Set scissor and viewport counts to different numbers
2001TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2002{
2003 // Attempt to Create Gfx Pipeline w/o a VS
2004 VkFlags msgFlags;
2005 std::string msgString;
2006 VkResult err;
2007
2008 ASSERT_NO_FATAL_FAILURE(InitState());
2009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2010 m_errorMonitor->ClearState();
2011
2012 VkDescriptorTypeCount ds_type_count = {};
2013 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2014 ds_type_count.count = 1;
2015
2016 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2017 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002018 ds_pool_ci.maxSets = 1;
2019 ds_pool_ci.count = 1;
2020 ds_pool_ci.pTypeCount = &ds_type_count;
2021
2022 VkDescriptorPool ds_pool;
2023 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2024 ASSERT_VK_SUCCESS(err);
2025
2026 VkDescriptorSetLayoutBinding dsl_binding = {};
2027 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2028 dsl_binding.arraySize = 1;
2029 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2030
2031 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2032 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2033 ds_layout_ci.count = 1;
2034 ds_layout_ci.pBinding = &dsl_binding;
2035
2036 VkDescriptorSetLayout ds_layout;
2037 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2038 ASSERT_VK_SUCCESS(err);
2039
2040 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002041 VkDescriptorSetAllocInfo alloc_info = {};
2042 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2043 alloc_info.count = 1;
2044 alloc_info.descriptorPool = ds_pool;
2045 alloc_info.pSetLayouts = &ds_layout;
2046 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002047 ASSERT_VK_SUCCESS(err);
2048
2049 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2050 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2051 pipeline_layout_ci.descriptorSetCount = 1;
2052 pipeline_layout_ci.pSetLayouts = &ds_layout;
2053
2054 VkPipelineLayout pipeline_layout;
2055 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2056 ASSERT_VK_SUCCESS(err);
2057
2058 VkViewport vp = {}; // Just need dummy vp to point to
2059
2060 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2061 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2062 vp_state_ci.scissorCount = 0;
2063 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2064 vp_state_ci.pViewports = &vp;
2065
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002066 VkPipelineShaderStageCreateInfo shaderStages[2];
2067 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002068
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002069 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2070 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 -06002071 // but add it to be able to run on more devices
2072 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002073 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002074 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002075
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002076 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002077 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002078 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002079
2080 VkGraphicsPipelineCreateInfo gp_ci = {};
2081 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002082 gp_ci.stageCount = 2;
2083 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002084 gp_ci.pViewportState = &vp_state_ci;
2085 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2086 gp_ci.layout = pipeline_layout;
2087 gp_ci.renderPass = renderPass();
2088
2089 VkPipelineCacheCreateInfo pc_ci = {};
2090 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2091
2092 VkPipeline pipeline;
2093 VkPipelineCache pipelineCache;
2094
2095 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2096 ASSERT_VK_SUCCESS(err);
2097 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2098
2099 msgFlags = m_errorMonitor->GetState(&msgString);
2100 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/ viewport and scissor count mismatch.";
2101 if (!strstr(msgString.c_str(),"Gfx Pipeline viewport count (1) must match scissor count (0).")) {
2102 FAIL() << "Error received was not 'Gfx Pipeline viewport count (1) must match scissor count (0).' but instead it was '" << msgString.c_str() << "'";
2103 }
2104
2105 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2106 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002107 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2108 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2109}
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002110// Don't set viewport state in PSO. This is an error b/c we always need this state
2111// for the counts even if the data is going to be set dynamically.
2112TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002113{
2114 // Attempt to Create Gfx Pipeline w/o a VS
2115 VkFlags msgFlags;
2116 std::string msgString;
2117 VkResult err;
2118
2119 ASSERT_NO_FATAL_FAILURE(InitState());
2120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2121 m_errorMonitor->ClearState();
2122
2123 VkDescriptorTypeCount ds_type_count = {};
2124 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2125 ds_type_count.count = 1;
2126
2127 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2128 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002129 ds_pool_ci.maxSets = 1;
2130 ds_pool_ci.count = 1;
2131 ds_pool_ci.pTypeCount = &ds_type_count;
2132
2133 VkDescriptorPool ds_pool;
2134 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2135 ASSERT_VK_SUCCESS(err);
2136
2137 VkDescriptorSetLayoutBinding dsl_binding = {};
2138 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2139 dsl_binding.arraySize = 1;
2140 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2141
2142 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2143 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2144 ds_layout_ci.count = 1;
2145 ds_layout_ci.pBinding = &dsl_binding;
2146
2147 VkDescriptorSetLayout ds_layout;
2148 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2149 ASSERT_VK_SUCCESS(err);
2150
2151 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002152 VkDescriptorSetAllocInfo alloc_info = {};
2153 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2154 alloc_info.count = 1;
2155 alloc_info.descriptorPool = ds_pool;
2156 alloc_info.pSetLayouts = &ds_layout;
2157 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002158 ASSERT_VK_SUCCESS(err);
2159
2160 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2161 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2162 pipeline_layout_ci.descriptorSetCount = 1;
2163 pipeline_layout_ci.pSetLayouts = &ds_layout;
2164
2165 VkPipelineLayout pipeline_layout;
2166 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2167 ASSERT_VK_SUCCESS(err);
2168
2169 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2170 // Set scissor as dynamic to avoid second error
2171 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2172 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2173 dyn_state_ci.dynamicStateCount = 1;
2174 dyn_state_ci.pDynamicStates = &sc_state;
2175
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002176 VkPipelineShaderStageCreateInfo shaderStages[2];
2177 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002178
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002179 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2180 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 -06002181 // but add it to be able to run on more devices
2182 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002183 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002184 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002185
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002186 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002187 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002188 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002189
2190 VkGraphicsPipelineCreateInfo gp_ci = {};
2191 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002192 gp_ci.stageCount = 2;
2193 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002194 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2195 gp_ci.pDynamicState = &dyn_state_ci;
2196 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2197 gp_ci.layout = pipeline_layout;
2198 gp_ci.renderPass = renderPass();
2199
2200 VkPipelineCacheCreateInfo pc_ci = {};
2201 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2202
2203 VkPipeline pipeline;
2204 VkPipelineCache pipelineCache;
2205
2206 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2207 ASSERT_VK_SUCCESS(err);
2208 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2209
2210 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002211 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o viewport state set.";
2212 if (!strstr(msgString.c_str(),"Gfx Pipeline pViewportState is null. Even if ")) {
2213 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 -06002214 }
2215
2216 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2217 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002218 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2219 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2220}
2221// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002222// Then run second test where dynamic scissor count doesn't match PSO scissor count
2223TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002224{
2225 VkFlags msgFlags;
2226 std::string msgString;
2227 VkResult err;
2228
2229 ASSERT_NO_FATAL_FAILURE(InitState());
2230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2231 m_errorMonitor->ClearState();
2232
2233 VkDescriptorTypeCount ds_type_count = {};
2234 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2235 ds_type_count.count = 1;
2236
2237 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2238 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002239 ds_pool_ci.maxSets = 1;
2240 ds_pool_ci.count = 1;
2241 ds_pool_ci.pTypeCount = &ds_type_count;
2242
2243 VkDescriptorPool ds_pool;
2244 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2245 ASSERT_VK_SUCCESS(err);
2246
2247 VkDescriptorSetLayoutBinding dsl_binding = {};
2248 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2249 dsl_binding.arraySize = 1;
2250 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2251
2252 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2253 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2254 ds_layout_ci.count = 1;
2255 ds_layout_ci.pBinding = &dsl_binding;
2256
2257 VkDescriptorSetLayout ds_layout;
2258 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2259 ASSERT_VK_SUCCESS(err);
2260
2261 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002262 VkDescriptorSetAllocInfo alloc_info = {};
2263 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2264 alloc_info.count = 1;
2265 alloc_info.descriptorPool = ds_pool;
2266 alloc_info.pSetLayouts = &ds_layout;
2267 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002268 ASSERT_VK_SUCCESS(err);
2269
2270 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2271 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2272 pipeline_layout_ci.descriptorSetCount = 1;
2273 pipeline_layout_ci.pSetLayouts = &ds_layout;
2274
2275 VkPipelineLayout pipeline_layout;
2276 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2277 ASSERT_VK_SUCCESS(err);
2278
2279 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2280 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2281 vp_state_ci.viewportCount = 1;
2282 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2283 vp_state_ci.scissorCount = 1;
2284 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2285
2286 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2287 // Set scissor as dynamic to avoid that error
2288 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2289 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2290 dyn_state_ci.dynamicStateCount = 1;
2291 dyn_state_ci.pDynamicStates = &sc_state;
2292
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002293 VkPipelineShaderStageCreateInfo shaderStages[2];
2294 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002295
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002296 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2297 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 -06002298 // but add it to be able to run on more devices
2299 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002300 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002301 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002302
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002303 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002304 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002305 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002306
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002307 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2308 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2309 vi_ci.pNext = nullptr;
2310 vi_ci.bindingCount = 0;
2311 vi_ci.pVertexBindingDescriptions = nullptr;
2312 vi_ci.attributeCount = 0;
2313 vi_ci.pVertexAttributeDescriptions = nullptr;
2314
2315 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2316 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2317 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2318
2319 VkPipelineRasterStateCreateInfo rs_ci = {};
2320 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2321 rs_ci.pNext = nullptr;
2322
2323 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2324 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2325 cb_ci.pNext = nullptr;
2326
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002327 VkGraphicsPipelineCreateInfo gp_ci = {};
2328 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002329 gp_ci.stageCount = 2;
2330 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002331 gp_ci.pVertexInputState = &vi_ci;
2332 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002333 gp_ci.pViewportState = &vp_state_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002334 gp_ci.pRasterState = &rs_ci;
2335 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002336 gp_ci.pDynamicState = &dyn_state_ci;
2337 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2338 gp_ci.layout = pipeline_layout;
2339 gp_ci.renderPass = renderPass();
2340
2341 VkPipelineCacheCreateInfo pc_ci = {};
2342 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2343
2344 VkPipeline pipeline;
2345 VkPipelineCache pipelineCache;
2346
2347 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2348 ASSERT_VK_SUCCESS(err);
2349 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2350
2351 msgFlags = m_errorMonitor->GetState(&msgString);
2352 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2353 if (!strstr(msgString.c_str(),"Gfx Pipeline viewportCount is 1, but pViewports is NULL. ")) {
2354 FAIL() << "Error received was not 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...' but instead it was '" << msgString.c_str() << "'";
2355 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002356 m_errorMonitor->ClearState();
2357 // Now hit second fail case where we set scissor w/ different count than PSO
2358 // First need to successfully create the PSO from above by setting pViewports
2359 VkViewport vp = {}; // Just need dummy vp to point to
2360 vp_state_ci.pViewports = &vp;
2361 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2362 ASSERT_VK_SUCCESS(err);
2363 BeginCommandBuffer();
2364 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2365 VkRect2D scissors[2] = {}; // don't care about data
2366 // Count of 2 doesn't match PSO count of 1
2367 vkCmdSetScissor(m_cmdBuffer->GetBufferHandle(), 2, scissors);
2368 Draw(1, 0, 0, 0);
2369
2370 msgFlags = m_errorMonitor->GetState(&msgString);
2371 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic scissorCount different from PSO scissorCount.";
2372 if (!strstr(msgString.c_str(),"Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.")) {
2373 FAIL() << "Error received was not 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...' but instead it was '" << msgString.c_str() << "'";
2374 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002375
2376 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2377 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002378 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2379 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2380}
2381// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002382// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2383TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002384{
2385 VkFlags msgFlags;
2386 std::string msgString;
2387 VkResult err;
2388
2389 ASSERT_NO_FATAL_FAILURE(InitState());
2390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2391 m_errorMonitor->ClearState();
2392
2393 VkDescriptorTypeCount ds_type_count = {};
2394 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2395 ds_type_count.count = 1;
2396
2397 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2398 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002399 ds_pool_ci.maxSets = 1;
2400 ds_pool_ci.count = 1;
2401 ds_pool_ci.pTypeCount = &ds_type_count;
2402
2403 VkDescriptorPool ds_pool;
2404 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2405 ASSERT_VK_SUCCESS(err);
2406
2407 VkDescriptorSetLayoutBinding dsl_binding = {};
2408 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2409 dsl_binding.arraySize = 1;
2410 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2411
2412 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2413 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2414 ds_layout_ci.count = 1;
2415 ds_layout_ci.pBinding = &dsl_binding;
2416
2417 VkDescriptorSetLayout ds_layout;
2418 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2419 ASSERT_VK_SUCCESS(err);
2420
2421 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002422 VkDescriptorSetAllocInfo alloc_info = {};
2423 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2424 alloc_info.count = 1;
2425 alloc_info.descriptorPool = ds_pool;
2426 alloc_info.pSetLayouts = &ds_layout;
2427 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002428 ASSERT_VK_SUCCESS(err);
2429
2430 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2431 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2432 pipeline_layout_ci.descriptorSetCount = 1;
2433 pipeline_layout_ci.pSetLayouts = &ds_layout;
2434
2435 VkPipelineLayout pipeline_layout;
2436 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2437 ASSERT_VK_SUCCESS(err);
2438
2439 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2440 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2441 vp_state_ci.scissorCount = 1;
2442 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2443 vp_state_ci.viewportCount = 1;
2444 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2445
2446 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2447 // Set scissor as dynamic to avoid that error
2448 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2449 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2450 dyn_state_ci.dynamicStateCount = 1;
2451 dyn_state_ci.pDynamicStates = &vp_state;
2452
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002453 VkPipelineShaderStageCreateInfo shaderStages[2];
2454 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002455
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002456 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2457 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 -06002458 // but add it to be able to run on more devices
2459 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002460 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002461 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002462
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002463 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002464 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002465 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002466
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002467 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2468 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2469 vi_ci.pNext = nullptr;
2470 vi_ci.bindingCount = 0;
2471 vi_ci.pVertexBindingDescriptions = nullptr;
2472 vi_ci.attributeCount = 0;
2473 vi_ci.pVertexAttributeDescriptions = nullptr;
2474
2475 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2476 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2477 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2478
2479 VkPipelineRasterStateCreateInfo rs_ci = {};
2480 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2481 rs_ci.pNext = nullptr;
2482
2483 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2484 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2485 cb_ci.pNext = nullptr;
2486
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002487 VkGraphicsPipelineCreateInfo gp_ci = {};
2488 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002489 gp_ci.stageCount = 2;
2490 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002491 gp_ci.pVertexInputState = &vi_ci;
2492 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002493 gp_ci.pViewportState = &vp_state_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002494 gp_ci.pRasterState = &rs_ci;
2495 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002496 gp_ci.pDynamicState = &dyn_state_ci;
2497 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2498 gp_ci.layout = pipeline_layout;
2499 gp_ci.renderPass = renderPass();
2500
2501 VkPipelineCacheCreateInfo pc_ci = {};
2502 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2503
2504 VkPipeline pipeline;
2505 VkPipelineCache pipelineCache;
2506
2507 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2508 ASSERT_VK_SUCCESS(err);
2509 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2510
2511 msgFlags = m_errorMonitor->GetState(&msgString);
2512 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2513 if (!strstr(msgString.c_str(),"Gfx Pipeline scissorCount is 1, but pScissors is NULL. ")) {
2514 FAIL() << "Error received was not 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...' but instead it was '" << msgString.c_str() << "'";
2515 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002516 m_errorMonitor->ClearState();
2517 // Now hit second fail case where we set scissor w/ different count than PSO
2518 // First need to successfully create the PSO from above by setting pViewports
2519 VkRect2D sc = {}; // Just need dummy vp to point to
2520 vp_state_ci.pScissors = &sc;
2521 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2522 ASSERT_VK_SUCCESS(err);
2523 BeginCommandBuffer();
2524 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2525 VkViewport viewports[2] = {}; // don't care about data
2526 // Count of 2 doesn't match PSO count of 1
2527 vkCmdSetViewport(m_cmdBuffer->GetBufferHandle(), 2, viewports);
2528 Draw(1, 0, 0, 0);
2529
2530 msgFlags = m_errorMonitor->GetState(&msgString);
2531 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic viewportCount different from PSO viewportCount.";
2532 if (!strstr(msgString.c_str(),"Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.")) {
2533 FAIL() << "Error received was not 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...' but instead it was '" << msgString.c_str() << "'";
2534 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002535
2536 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2537 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002538 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2539 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2540}
2541
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002542TEST_F(VkLayerTest, NullRenderPass)
2543{
2544 // Bind a NULL RenderPass
2545 VkFlags msgFlags;
2546 std::string msgString;
2547
2548 ASSERT_NO_FATAL_FAILURE(InitState());
2549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2550 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002551
Tony Barbour1490c912015-07-28 10:17:20 -06002552 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002553 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06002554 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002555
2556 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002557 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002558 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
2559 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2560 }
2561}
2562
Tobin Ehlis254eca02015-06-25 15:46:59 -06002563TEST_F(VkLayerTest, RenderPassWithinRenderPass)
2564{
2565 // Bind a BeginRenderPass within an active RenderPass
2566 VkFlags msgFlags;
2567 std::string msgString;
2568
2569 ASSERT_NO_FATAL_FAILURE(InitState());
2570 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2571 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002572
Tony Barbour1490c912015-07-28 10:17:20 -06002573 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002574 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002575 VkRenderPassBeginInfo rp_begin = {};
2576 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
2577 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002578 rp_begin.renderPass = renderPass();
2579 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002580
Tony Barbour1490c912015-07-28 10:17:20 -06002581 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002582
2583 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002584 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 -06002585 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2586 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002587 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002588}
2589
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002590TEST_F(VkLayerTest, FillBufferWithinRenderPass)
2591{
2592 // Call CmdFillBuffer within an active renderpass
2593 VkFlags msgFlags;
2594 std::string msgString;
2595
2596 ASSERT_NO_FATAL_FAILURE(InitState());
2597 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2598 m_errorMonitor->ClearState();
2599
2600 // Renderpass is started here
2601 BeginCommandBuffer();
2602
2603 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2604 vk_testing::Buffer destBuffer;
2605 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2606
2607 m_cmdBuffer->FillBuffer(destBuffer.handle(), 0, 4, 0x11111111);
2608
2609 msgFlags = m_errorMonitor->GetState(&msgString);
2610 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2611 "Did not receive error after calling CmdFillBuffer w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002612 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2613 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002614 }
2615}
2616
2617TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
2618{
2619 // Call CmdUpdateBuffer within an active renderpass
2620 VkFlags msgFlags;
2621 std::string msgString;
2622
2623 ASSERT_NO_FATAL_FAILURE(InitState());
2624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2625 m_errorMonitor->ClearState();
2626
2627 // Renderpass is started here
2628 BeginCommandBuffer();
2629
2630 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2631 vk_testing::Buffer destBuffer;
2632 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2633
2634 VkDeviceSize destOffset = 0;
2635 VkDeviceSize dataSize = 1024;
2636 const uint32_t *pData = NULL;
2637
2638 vkCmdUpdateBuffer(m_cmdBuffer->GetBufferHandle(), destBuffer.handle(), destOffset, dataSize, pData);
2639
2640 msgFlags = m_errorMonitor->GetState(&msgString);
2641 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2642 "Did not receive error after calling CmdUpdateBuffer w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002643 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2644 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002645 }
2646}
2647
2648TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
2649{
2650 // Call CmdClearColorImage within an active RenderPass
2651 VkFlags msgFlags;
2652 std::string msgString;
2653
2654 ASSERT_NO_FATAL_FAILURE(InitState());
2655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2656 m_errorMonitor->ClearState();
2657
2658 // Renderpass is started here
2659 BeginCommandBuffer();
2660
2661 VkClearColorValue clear_color = {0};
2662 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2663 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2664 const int32_t tex_width = 32;
2665 const int32_t tex_height = 32;
2666 VkImageCreateInfo image_create_info = {};
2667 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2668 image_create_info.pNext = NULL;
2669 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2670 image_create_info.format = tex_format;
2671 image_create_info.extent.width = tex_width;
2672 image_create_info.extent.height = tex_height;
2673 image_create_info.extent.depth = 1;
2674 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06002675 image_create_info.arrayLayers = 1;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002676 image_create_info.samples = 1;
2677 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2678 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2679
2680 vk_testing::Image destImage;
2681 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2682
2683 const VkImageSubresourceRange range =
2684 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
2685
2686 vkCmdClearColorImage(m_cmdBuffer->GetBufferHandle(),
2687 destImage.handle(),
2688 VK_IMAGE_LAYOUT_GENERAL,
2689 &clear_color,
2690 1,
2691 &range);
2692
2693 msgFlags = m_errorMonitor->GetState(&msgString);
2694 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2695 "Did not receive error after calling CmdClearColorImage w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002696 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2697 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002698 }
2699}
2700
2701TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
2702{
2703 // Call CmdClearDepthStencilImage within an active RenderPass
2704 VkFlags msgFlags;
2705 std::string msgString;
2706
2707 ASSERT_NO_FATAL_FAILURE(InitState());
2708 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2709 m_errorMonitor->ClearState();
2710
2711 // Renderpass is started here
2712 BeginCommandBuffer();
2713
2714 VkClearDepthStencilValue clear_value = {0};
2715 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2716 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
2717 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2718 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
2719 image_create_info.extent.width = 64;
2720 image_create_info.extent.height = 64;
2721 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2722 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2723
2724 vk_testing::Image destImage;
2725 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2726
2727 const VkImageSubresourceRange range =
2728 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
2729
2730 vkCmdClearDepthStencilImage(m_cmdBuffer->GetBufferHandle(),
2731 destImage.handle(),
2732 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2733 &clear_value,
2734 1,
2735 &range);
2736
2737 msgFlags = m_errorMonitor->GetState(&msgString);
2738 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2739 "Did not receive error after calling CmdClearDepthStencilImage w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002740 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2741 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002742 }
2743}
2744
2745TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
2746{
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002747 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002748 VkFlags msgFlags;
2749 std::string msgString;
2750 VkResult err;
2751
2752 ASSERT_NO_FATAL_FAILURE(InitState());
2753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2754 m_errorMonitor->ClearState();
2755
2756 // Start no RenderPass
2757 err = m_cmdBuffer->BeginCommandBuffer();
2758 ASSERT_VK_SUCCESS(err);
2759
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002760 VkClearAttachment color_attachment;
2761 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2762 color_attachment.clearValue.color.float32[0] = 0;
2763 color_attachment.clearValue.color.float32[1] = 0;
2764 color_attachment.clearValue.color.float32[2] = 0;
2765 color_attachment.clearValue.color.float32[3] = 0;
2766 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06002767 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002768 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(),
2769 1, &color_attachment,
2770 1, &clear_rect);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002771
2772 msgFlags = m_errorMonitor->GetState(&msgString);
2773 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002774 "Did not receive error after calling CmdClearAttachments outside of an active RenderPass.";
2775 if (!strstr(msgString.c_str(),"vkCmdClearAttachments: This call must be issued inside an active render pass")) {
2776 FAIL() << "Error received was not 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002777 }
2778}
2779
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002780TEST_F(VkLayerTest, InvalidDynamicStateObject)
2781{
2782 // Create a valid cmd buffer
2783 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002784 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
2785 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002786}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06002787
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002788TEST_F(VkLayerTest, IdxBufferAlignmentError)
2789{
2790 // Bind a BeginRenderPass within an active RenderPass
2791 VkFlags msgFlags;
2792 std::string msgString;
2793 VkResult err;
2794
2795 ASSERT_NO_FATAL_FAILURE(InitState());
2796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2797 m_errorMonitor->ClearState();
2798 uint32_t qfi = 0;
2799 VkBufferCreateInfo buffCI = {};
2800 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2801 buffCI.size = 1024;
2802 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
2803 buffCI.queueFamilyCount = 1;
2804 buffCI.pQueueFamilyIndices = &qfi;
2805
2806 VkBuffer ib;
2807 err = vkCreateBuffer(m_device->device(), &buffCI, &ib);
2808 ASSERT_VK_SUCCESS(err);
2809
2810 BeginCommandBuffer();
2811 ASSERT_VK_SUCCESS(err);
2812 //vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2813 // Should error before calling to driver so don't care about actual data
2814 vkCmdBindIndexBuffer(m_cmdBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
2815
2816 msgFlags = m_errorMonitor->GetState(&msgString);
2817 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2818 if (!strstr(msgString.c_str(),"vkCmdBindIndexBuffer() offset (0x7) does not fall on ")) {
2819 FAIL() << "Error received was not 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...' but instead '" << msgString.c_str() << "'";
2820 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002821
2822 vkDestroyBuffer(m_device->device(), ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002823}
2824
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002825TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2826{
2827 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
2828 VkFlags msgFlags;
2829 std::string msgString;
2830
2831 ASSERT_NO_FATAL_FAILURE(InitState());
2832 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2833 m_errorMonitor->ClearState();
2834
2835 BeginCommandBuffer();
2836 //ASSERT_VK_SUCCESS(err);
2837 VkCmdBuffer primCB = m_cmdBuffer->GetBufferHandle();
2838 vkCmdExecuteCommands(m_cmdBuffer->GetBufferHandle(), 1, &primCB);
2839
2840 msgFlags = m_errorMonitor->GetState(&msgString);
2841 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2842 if (!strstr(msgString.c_str(),"vkCmdExecuteCommands() called w/ Primary Cmd Buffer ")) {
2843 FAIL() << "Error received was not 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer ' but instead '" << msgString.c_str() << "'";
2844 }
2845}
2846
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002847TEST_F(VkLayerTest, DSTypeMismatch)
2848{
2849 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002850 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002851 std::string msgString;
2852 VkResult err;
2853
2854 ASSERT_NO_FATAL_FAILURE(InitState());
2855 m_errorMonitor->ClearState();
2856 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002857 VkDescriptorTypeCount ds_type_count = {};
2858 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2859 ds_type_count.count = 1;
2860
2861 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2862 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2863 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002864 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002865 ds_pool_ci.count = 1;
2866 ds_pool_ci.pTypeCount = &ds_type_count;
2867
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002868 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002869 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002870 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002871 VkDescriptorSetLayoutBinding dsl_binding = {};
2872 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2873 dsl_binding.arraySize = 1;
2874 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2875 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002876
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002877 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2878 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2879 ds_layout_ci.pNext = NULL;
2880 ds_layout_ci.count = 1;
2881 ds_layout_ci.pBinding = &dsl_binding;
2882
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002883 VkDescriptorSetLayout ds_layout;
2884 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2885 ASSERT_VK_SUCCESS(err);
2886
2887 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002888 VkDescriptorSetAllocInfo alloc_info = {};
2889 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2890 alloc_info.count = 1;
2891 alloc_info.descriptorPool = ds_pool;
2892 alloc_info.pSetLayouts = &ds_layout;
2893 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002894 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002895
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002896 VkSamplerCreateInfo sampler_ci = {};
2897 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2898 sampler_ci.pNext = NULL;
2899 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2900 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2901 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002902 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2903 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2904 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002905 sampler_ci.mipLodBias = 1.0;
2906 sampler_ci.maxAnisotropy = 1;
2907 sampler_ci.compareEnable = VK_FALSE;
2908 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2909 sampler_ci.minLod = 1.0;
2910 sampler_ci.maxLod = 1.0;
2911 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002912 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2913
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002914 VkSampler sampler;
2915 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2916 ASSERT_VK_SUCCESS(err);
2917
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06002918 VkDescriptorImageInfo info = {};
2919 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002920
2921 VkWriteDescriptorSet descriptor_write;
2922 memset(&descriptor_write, 0, sizeof(descriptor_write));
2923 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2924 descriptor_write.destSet = descriptorSet;
2925 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002926 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06002928 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002929
2930 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2931
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002932 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002933 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 -06002934 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 ")) {
2935 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 -06002936 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002937
2938 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06002939 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2940 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002941}
2942
2943TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2944{
2945 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002946 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002947 std::string msgString;
2948 VkResult err;
2949
2950 ASSERT_NO_FATAL_FAILURE(InitState());
2951 m_errorMonitor->ClearState();
2952 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002953 VkDescriptorTypeCount ds_type_count = {};
2954 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2955 ds_type_count.count = 1;
2956
2957 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2958 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2959 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002960 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002961 ds_pool_ci.count = 1;
2962 ds_pool_ci.pTypeCount = &ds_type_count;
2963
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002964 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002965 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002966 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002967
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002968 VkDescriptorSetLayoutBinding dsl_binding = {};
2969 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2970 dsl_binding.arraySize = 1;
2971 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2972 dsl_binding.pImmutableSamplers = NULL;
2973
2974 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2975 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2976 ds_layout_ci.pNext = NULL;
2977 ds_layout_ci.count = 1;
2978 ds_layout_ci.pBinding = &dsl_binding;
2979
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002980 VkDescriptorSetLayout ds_layout;
2981 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2982 ASSERT_VK_SUCCESS(err);
2983
2984 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002985 VkDescriptorSetAllocInfo alloc_info = {};
2986 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2987 alloc_info.count = 1;
2988 alloc_info.descriptorPool = ds_pool;
2989 alloc_info.pSetLayouts = &ds_layout;
2990 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002991 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002992
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002993 VkSamplerCreateInfo sampler_ci = {};
2994 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2995 sampler_ci.pNext = NULL;
2996 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2997 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2998 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002999 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3000 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3001 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003002 sampler_ci.mipLodBias = 1.0;
3003 sampler_ci.maxAnisotropy = 1;
3004 sampler_ci.compareEnable = VK_FALSE;
3005 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3006 sampler_ci.minLod = 1.0;
3007 sampler_ci.maxLod = 1.0;
3008 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003009 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003010
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003011 VkSampler sampler;
3012 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3013 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003014
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003015 VkDescriptorImageInfo info = {};
3016 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003017
3018 VkWriteDescriptorSet descriptor_write;
3019 memset(&descriptor_write, 0, sizeof(descriptor_write));
3020 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3021 descriptor_write.destSet = descriptorSet;
3022 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
3023 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003024 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003025 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003026 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003027
3028 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3029
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003030 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003031 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 +08003032 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
3033 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 -06003034 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003035
3036 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06003037 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3038 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003039}
3040
3041TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3042{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003043 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003044 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003045 std::string msgString;
3046 VkResult err;
3047
3048 ASSERT_NO_FATAL_FAILURE(InitState());
3049 m_errorMonitor->ClearState();
3050 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003051 VkDescriptorTypeCount ds_type_count = {};
3052 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3053 ds_type_count.count = 1;
3054
3055 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3056 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3057 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003058 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003059 ds_pool_ci.count = 1;
3060 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003061
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003062 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003063 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003064 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003065
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003066 VkDescriptorSetLayoutBinding dsl_binding = {};
3067 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3068 dsl_binding.arraySize = 1;
3069 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3070 dsl_binding.pImmutableSamplers = NULL;
3071
3072 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3073 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3074 ds_layout_ci.pNext = NULL;
3075 ds_layout_ci.count = 1;
3076 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003077 VkDescriptorSetLayout ds_layout;
3078 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3079 ASSERT_VK_SUCCESS(err);
3080
3081 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003082 VkDescriptorSetAllocInfo alloc_info = {};
3083 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3084 alloc_info.count = 1;
3085 alloc_info.descriptorPool = ds_pool;
3086 alloc_info.pSetLayouts = &ds_layout;
3087 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003088 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003089
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003090 VkSamplerCreateInfo sampler_ci = {};
3091 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3092 sampler_ci.pNext = NULL;
3093 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
3094 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
3095 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06003096 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3097 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3098 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003099 sampler_ci.mipLodBias = 1.0;
3100 sampler_ci.maxAnisotropy = 1;
3101 sampler_ci.compareEnable = VK_FALSE;
3102 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3103 sampler_ci.minLod = 1.0;
3104 sampler_ci.maxLod = 1.0;
3105 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003106 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003107
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003108 VkSampler sampler;
3109 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3110 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003111
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003112 VkDescriptorImageInfo info = {};
3113 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003114
3115 VkWriteDescriptorSet descriptor_write;
3116 memset(&descriptor_write, 0, sizeof(descriptor_write));
3117 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3118 descriptor_write.destSet = descriptorSet;
3119 descriptor_write.destBinding = 2;
3120 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003121 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003122 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003123 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003124
3125 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3126
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003127 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003128 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 -06003129 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
3130 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
3131 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003132
3133 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06003134 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3135 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003136}
3137
3138TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3139{
3140 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003141 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003142 std::string msgString;
3143 VkResult err;
3144
3145 ASSERT_NO_FATAL_FAILURE(InitState());
3146 m_errorMonitor->ClearState();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003147
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003148 VkDescriptorTypeCount ds_type_count = {};
3149 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3150 ds_type_count.count = 1;
3151
3152 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3153 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3154 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003155 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003156 ds_pool_ci.count = 1;
3157 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003158
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003159 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003160 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003161 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003162 VkDescriptorSetLayoutBinding dsl_binding = {};
3163 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3164 dsl_binding.arraySize = 1;
3165 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3166 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003167
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003168 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3169 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3170 ds_layout_ci.pNext = NULL;
3171 ds_layout_ci.count = 1;
3172 ds_layout_ci.pBinding = &dsl_binding;
3173
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003174 VkDescriptorSetLayout ds_layout;
3175 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3176 ASSERT_VK_SUCCESS(err);
3177
3178 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003179 VkDescriptorSetAllocInfo alloc_info = {};
3180 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3181 alloc_info.count = 1;
3182 alloc_info.descriptorPool = ds_pool;
3183 alloc_info.pSetLayouts = &ds_layout;
3184 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003185 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003186
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003187 VkSamplerCreateInfo sampler_ci = {};
3188 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3189 sampler_ci.pNext = NULL;
3190 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
3191 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
3192 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06003193 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3194 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3195 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003196 sampler_ci.mipLodBias = 1.0;
3197 sampler_ci.maxAnisotropy = 1;
3198 sampler_ci.compareEnable = VK_FALSE;
3199 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3200 sampler_ci.minLod = 1.0;
3201 sampler_ci.maxLod = 1.0;
3202 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003203 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003204 VkSampler sampler;
3205 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3206 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003207
3208
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003209 VkDescriptorImageInfo info = {};
3210 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003211
3212 VkWriteDescriptorSet descriptor_write;
3213 memset(&descriptor_write, 0, sizeof(descriptor_write));
3214 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
3215 descriptor_write.destSet = descriptorSet;
3216 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003217 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003218 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003219 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003220
3221 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3222
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003223 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003224 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 -06003225 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
3226 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
3227 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003228
3229 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06003230 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3231 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003232}
3233
Tobin Ehlisb46be812015-10-23 16:00:08 -06003234TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3235{
3236 // Create a single Sampler descriptor and send it an invalid Sampler
3237 VkFlags msgFlags;
3238 std::string msgString;
3239 VkResult err;
3240
3241 ASSERT_NO_FATAL_FAILURE(InitState());
3242 m_errorMonitor->ClearState();
3243 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
3244 VkDescriptorTypeCount ds_type_count = {};
3245 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3246 ds_type_count.count = 1;
3247
3248 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3249 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3250 ds_pool_ci.pNext = NULL;
3251 ds_pool_ci.maxSets = 1;
3252 ds_pool_ci.count = 1;
3253 ds_pool_ci.pTypeCount = &ds_type_count;
3254
3255 VkDescriptorPool ds_pool;
3256 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
3257 ASSERT_VK_SUCCESS(err);
3258
3259 VkDescriptorSetLayoutBinding dsl_binding = {};
3260 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3261 dsl_binding.arraySize = 1;
3262 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3263 dsl_binding.pImmutableSamplers = NULL;
3264
3265 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3266 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3267 ds_layout_ci.pNext = NULL;
3268 ds_layout_ci.count = 1;
3269 ds_layout_ci.pBinding = &dsl_binding;
3270 VkDescriptorSetLayout ds_layout;
3271 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3272 ASSERT_VK_SUCCESS(err);
3273
3274 VkDescriptorSet descriptorSet;
3275 VkDescriptorSetAllocInfo alloc_info = {};
3276 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3277 alloc_info.count = 1;
3278 alloc_info.descriptorPool = ds_pool;
3279 alloc_info.pSetLayouts = &ds_layout;
3280 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3281 ASSERT_VK_SUCCESS(err);
3282
3283 VkSampler sampler;
3284 sampler.handle = 0xbaadbeef; // Sampler with invalid handle
3285
3286 VkDescriptorImageInfo descriptor_info;
3287 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3288 descriptor_info.sampler = sampler;
3289
3290 VkWriteDescriptorSet descriptor_write;
3291 memset(&descriptor_write, 0, sizeof(descriptor_write));
3292 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3293 descriptor_write.destSet = descriptorSet;
3294 descriptor_write.destBinding = 0;
3295 descriptor_write.count = 1;
3296 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3297 descriptor_write.pImageInfo = &descriptor_info;
3298
3299 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3300
3301 msgFlags = m_errorMonitor->GetState(&msgString);
3302 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid VkSampler.";
3303 if (!strstr(msgString.c_str(),"Attempt to update descriptor with invalid sampler 0xbaadbeef")) {
3304 FAIL() << "Error received was not 'Attempt to update descriptor with invalid sampler...' but instead '" << msgString.c_str() << "'";
3305 }
3306
3307 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3308 vkDestroyDescriptorPool(m_device->device(), ds_pool);
3309}
3310
3311TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3312{
3313 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
3314 VkFlags msgFlags;
3315 std::string msgString;
3316 VkResult err;
3317
3318 ASSERT_NO_FATAL_FAILURE(InitState());
3319 m_errorMonitor->ClearState();
3320 VkDescriptorTypeCount ds_type_count = {};
3321 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3322 ds_type_count.count = 1;
3323
3324 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3325 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3326 ds_pool_ci.pNext = NULL;
3327 ds_pool_ci.maxSets = 1;
3328 ds_pool_ci.count = 1;
3329 ds_pool_ci.pTypeCount = &ds_type_count;
3330
3331 VkDescriptorPool ds_pool;
3332 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
3333 ASSERT_VK_SUCCESS(err);
3334
3335 VkDescriptorSetLayoutBinding dsl_binding = {};
3336 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3337 dsl_binding.arraySize = 1;
3338 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3339 dsl_binding.pImmutableSamplers = NULL;
3340
3341 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3342 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3343 ds_layout_ci.pNext = NULL;
3344 ds_layout_ci.count = 1;
3345 ds_layout_ci.pBinding = &dsl_binding;
3346 VkDescriptorSetLayout ds_layout;
3347 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3348 ASSERT_VK_SUCCESS(err);
3349
3350 VkDescriptorSet descriptorSet;
3351 VkDescriptorSetAllocInfo alloc_info = {};
3352 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3353 alloc_info.count = 1;
3354 alloc_info.descriptorPool = ds_pool;
3355 alloc_info.pSetLayouts = &ds_layout;
3356 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3357 ASSERT_VK_SUCCESS(err);
3358
3359 VkSamplerCreateInfo sampler_ci = {};
3360 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3361 sampler_ci.pNext = NULL;
3362 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
3363 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
3364 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
3365 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3366 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3367 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
3368 sampler_ci.mipLodBias = 1.0;
3369 sampler_ci.maxAnisotropy = 1;
3370 sampler_ci.compareEnable = VK_FALSE;
3371 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3372 sampler_ci.minLod = 1.0;
3373 sampler_ci.maxLod = 1.0;
3374 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3375 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3376
3377 VkSampler sampler;
3378 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3379 ASSERT_VK_SUCCESS(err);
3380
3381 VkImageView view;
3382 view.handle = 0xbaadbeef; // invalid imageView object
3383
3384 VkDescriptorImageInfo descriptor_info;
3385 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3386 descriptor_info.sampler = sampler;
3387 descriptor_info.imageView = view;
3388
3389 VkWriteDescriptorSet descriptor_write;
3390 memset(&descriptor_write, 0, sizeof(descriptor_write));
3391 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3392 descriptor_write.destSet = descriptorSet;
3393 descriptor_write.destBinding = 0;
3394 descriptor_write.count = 1;
3395 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3396 descriptor_write.pImageInfo = &descriptor_info;
3397
3398 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3399
3400 msgFlags = m_errorMonitor->GetState(&msgString);
3401 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid VkImageView.";
3402 if (!strstr(msgString.c_str(),"Attempt to update descriptor with invalid imageView 0xbaadbeef")) {
3403 FAIL() << "Error received was not 'Attempt to update descriptor with invalid imageView...' but instead '" << msgString.c_str() << "'";
3404 }
3405
3406 vkDestroySampler(m_device->device(), sampler);
3407 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3408 vkDestroyDescriptorPool(m_device->device(), ds_pool);
3409}
3410
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003411TEST_F(VkLayerTest, NumSamplesMismatch)
3412{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003413 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003414 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003415 std::string msgString;
3416 VkResult err;
3417
3418 ASSERT_NO_FATAL_FAILURE(InitState());
3419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3420 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003421 VkDescriptorTypeCount ds_type_count = {};
3422 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3423 ds_type_count.count = 1;
3424
3425 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003426 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3427 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003428 ds_pool_ci.maxSets = 1;
3429 ds_pool_ci.count = 1;
3430 ds_pool_ci.pTypeCount = &ds_type_count;
3431
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003432 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003433 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003434 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003435
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003436 VkDescriptorSetLayoutBinding dsl_binding = {};
3437 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3438 dsl_binding.arraySize = 1;
3439 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3440 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003441
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003442 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3443 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3444 ds_layout_ci.pNext = NULL;
3445 ds_layout_ci.count = 1;
3446 ds_layout_ci.pBinding = &dsl_binding;
3447
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003448 VkDescriptorSetLayout ds_layout;
3449 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3450 ASSERT_VK_SUCCESS(err);
3451
3452 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003453 VkDescriptorSetAllocInfo alloc_info = {};
3454 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3455 alloc_info.count = 1;
3456 alloc_info.descriptorPool = ds_pool;
3457 alloc_info.pSetLayouts = &ds_layout;
3458 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003459 ASSERT_VK_SUCCESS(err);
3460
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003461 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3462 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3463 pipe_ms_state_ci.pNext = NULL;
3464 pipe_ms_state_ci.rasterSamples = 4;
3465 pipe_ms_state_ci.sampleShadingEnable = 0;
3466 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003467 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003468
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003469 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3470 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3471 pipeline_layout_ci.pNext = NULL;
3472 pipeline_layout_ci.descriptorSetCount = 1;
3473 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003474
3475 VkPipelineLayout pipeline_layout;
3476 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3477 ASSERT_VK_SUCCESS(err);
3478
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003479 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3480 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 -06003481 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003482 VkPipelineObj pipe(m_device);
3483 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003484 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003485 pipe.SetMSAA(&pipe_ms_state_ci);
3486 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003487
Tony Barbour1490c912015-07-28 10:17:20 -06003488 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06003489 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003490
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003491 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003492 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 -06003493 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
3494 FAIL() << "Error received was not 'Num samples mismatch!...'";
3495 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003496
3497 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003498 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3499 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003500}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003501
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003502TEST_F(VkLayerTest, ClearCmdNoDraw)
3503{
3504 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
3505 VkFlags msgFlags;
3506 std::string msgString;
3507 VkResult err;
3508
3509 ASSERT_NO_FATAL_FAILURE(InitState());
3510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3511 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003512
3513 VkDescriptorTypeCount ds_type_count = {};
3514 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3515 ds_type_count.count = 1;
3516
3517 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3518 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3519 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003520 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003521 ds_pool_ci.count = 1;
3522 ds_pool_ci.pTypeCount = &ds_type_count;
3523
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003524 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003525 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003526 ASSERT_VK_SUCCESS(err);
3527
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003528 VkDescriptorSetLayoutBinding dsl_binding = {};
3529 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3530 dsl_binding.arraySize = 1;
3531 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3532 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003533
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003534 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3535 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3536 ds_layout_ci.pNext = NULL;
3537 ds_layout_ci.count = 1;
3538 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003539
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003540 VkDescriptorSetLayout ds_layout;
3541 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3542 ASSERT_VK_SUCCESS(err);
3543
3544 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003545 VkDescriptorSetAllocInfo alloc_info = {};
3546 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3547 alloc_info.count = 1;
3548 alloc_info.descriptorPool = ds_pool;
3549 alloc_info.pSetLayouts = &ds_layout;
3550 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003551 ASSERT_VK_SUCCESS(err);
3552
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003553 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3554 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3555 pipe_ms_state_ci.pNext = NULL;
3556 pipe_ms_state_ci.rasterSamples = 4;
3557 pipe_ms_state_ci.sampleShadingEnable = 0;
3558 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003559 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003560
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003561 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3562 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3563 pipeline_layout_ci.pNext = NULL;
3564 pipeline_layout_ci.descriptorSetCount = 1;
3565 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003566
3567 VkPipelineLayout pipeline_layout;
3568 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3569 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003570
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003571 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3572 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 -06003573 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003574 VkPipelineObj pipe(m_device);
3575 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003576 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003577 pipe.SetMSAA(&pipe_ms_state_ci);
3578 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003579
3580 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003581
3582 m_errorMonitor->ClearState();
3583 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3584 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003585 VkClearAttachment color_attachment;
3586 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3587 color_attachment.clearValue.color.float32[0] = 1.0;
3588 color_attachment.clearValue.color.float32[1] = 1.0;
3589 color_attachment.clearValue.color.float32[2] = 1.0;
3590 color_attachment.clearValue.color.float32[3] = 1.0;
3591 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06003592 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003593
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003594 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003595 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003596 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 -06003597 if (!strstr(msgString.c_str(),"vkCmdClearAttachments() issued on CB object ")) {
3598 FAIL() << "Error received was not 'vkCmdClearAttachments() issued on CB object...'";
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003599 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003600
3601 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003602 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3603 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003604}
3605
Tobin Ehlise4076782015-06-24 15:53:07 -06003606TEST_F(VkLayerTest, VtxBufferBadIndex)
3607{
3608 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
3609 VkFlags msgFlags;
3610 std::string msgString;
3611 VkResult err;
3612
3613 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003614 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06003615 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3616 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003617
3618 VkDescriptorTypeCount ds_type_count = {};
3619 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3620 ds_type_count.count = 1;
3621
3622 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3623 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3624 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003625 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003626 ds_pool_ci.count = 1;
3627 ds_pool_ci.pTypeCount = &ds_type_count;
3628
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003629 VkDescriptorPool ds_pool;
3630 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003631 ASSERT_VK_SUCCESS(err);
3632
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003633 VkDescriptorSetLayoutBinding dsl_binding = {};
3634 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3635 dsl_binding.arraySize = 1;
3636 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3637 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003638
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003639 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3640 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3641 ds_layout_ci.pNext = NULL;
3642 ds_layout_ci.count = 1;
3643 ds_layout_ci.pBinding = &dsl_binding;
3644
Tobin Ehlise4076782015-06-24 15:53:07 -06003645 VkDescriptorSetLayout ds_layout;
3646 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3647 ASSERT_VK_SUCCESS(err);
3648
3649 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003650 VkDescriptorSetAllocInfo alloc_info = {};
3651 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3652 alloc_info.count = 1;
3653 alloc_info.descriptorPool = ds_pool;
3654 alloc_info.pSetLayouts = &ds_layout;
3655 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06003656 ASSERT_VK_SUCCESS(err);
3657
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003658 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3659 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3660 pipe_ms_state_ci.pNext = NULL;
3661 pipe_ms_state_ci.rasterSamples = 1;
3662 pipe_ms_state_ci.sampleShadingEnable = 0;
3663 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003664 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003665
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003666 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3667 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3668 pipeline_layout_ci.pNext = NULL;
3669 pipeline_layout_ci.descriptorSetCount = 1;
3670 pipeline_layout_ci.pSetLayouts = &ds_layout;
3671 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06003672
Tobin Ehlise4076782015-06-24 15:53:07 -06003673 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3674 ASSERT_VK_SUCCESS(err);
3675
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003676 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3677 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 -06003678 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003679 VkPipelineObj pipe(m_device);
3680 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003681 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003682 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003683 pipe.SetViewport(m_viewports);
3684 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003685 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003686
3687 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06003688 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06003689 // Don't care about actual data, just need to get to draw to flag error
3690 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3691 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3692 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003693 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06003694
3695 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003696 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 -06003697 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 -06003698 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 -06003699 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003700
3701 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003702 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3703 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003704}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003705#endif // DRAW_STATE_TESTS
3706
Tobin Ehlis57e6a612015-05-26 16:11:58 -06003707#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06003708#if GTEST_IS_THREADSAFE
3709struct thread_data_struct {
3710 VkCmdBuffer cmdBuffer;
3711 VkEvent event;
3712 bool bailout;
3713};
3714
3715extern "C" void *AddToCommandBuffer(void *arg)
3716{
3717 struct thread_data_struct *data = (struct thread_data_struct *) arg;
3718 std::string msgString;
3719
3720 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06003721 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06003722 if (data->bailout) {
3723 break;
3724 }
3725 }
3726 return NULL;
3727}
3728
3729TEST_F(VkLayerTest, ThreadCmdBufferCollision)
3730{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003731 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06003732 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003733 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06003734
3735 ASSERT_NO_FATAL_FAILURE(InitState());
3736 ASSERT_NO_FATAL_FAILURE(InitViewport());
3737 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3738
Mike Stroyan09aae812015-05-12 16:00:45 -06003739 m_errorMonitor->ClearState();
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003740
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003741 // Calls AllocCommandBuffers
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003742 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
3743
3744 // Avoid creating RenderPass
3745 cmdBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003746
3747 VkEventCreateInfo event_info;
3748 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06003749 VkResult err;
3750
3751 memset(&event_info, 0, sizeof(event_info));
3752 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3753
3754 err = vkCreateEvent(device(), &event_info, &event);
3755 ASSERT_VK_SUCCESS(err);
3756
Mike Stroyan09aae812015-05-12 16:00:45 -06003757 err = vkResetEvent(device(), event);
3758 ASSERT_VK_SUCCESS(err);
3759
3760 struct thread_data_struct data;
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003761 data.cmdBuffer = cmdBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06003762 data.event = event;
3763 data.bailout = false;
3764 m_errorMonitor->SetBailout(&data.bailout);
3765 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003766 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06003767 // Add many entries to command buffer from this thread at the same time.
3768 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003769
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003770 test_platform_thread_join(thread, NULL);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003771 cmdBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003772
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003773 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003774 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 -06003775 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05003776 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06003777 }
3778
Mike Stroyan2237f522015-08-18 14:40:24 -06003779 vkDestroyEvent(device(), event);
Mike Stroyan09aae812015-05-12 16:00:45 -06003780}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003781#endif // GTEST_IS_THREADSAFE
3782#endif // THREADING_TESTS
3783
Chris Forbes5af3bf22015-05-25 11:13:08 +12003784#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003785TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
3786{
3787 VkFlags msgFlags;
3788 std::string msgString;
3789 ASSERT_NO_FATAL_FAILURE(InitState());
3790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3791
3792 m_errorMonitor->ClearState();
3793
3794 VkShaderModule module;
3795 VkShaderModuleCreateInfo moduleCreateInfo;
3796 struct icd_spv_header spv;
3797
3798 spv.magic = ICD_SPV_MAGIC;
3799 spv.version = ICD_SPV_VERSION;
3800 spv.gen_magic = 0;
3801
3802 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3803 moduleCreateInfo.pNext = NULL;
3804 moduleCreateInfo.pCode = &spv;
3805 moduleCreateInfo.codeSize = 4;
3806 moduleCreateInfo.flags = 0;
3807 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3808
3809 msgFlags = m_errorMonitor->GetState(&msgString);
3810
Chris Forbes96b81762015-09-18 11:40:23 +12003811 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003812 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3813 FAIL() << "Incorrect warning: " << msgString;
3814 }
3815}
3816
3817TEST_F(VkLayerTest, InvalidSPIRVMagic)
3818{
3819 VkFlags msgFlags;
3820 std::string msgString;
3821 ASSERT_NO_FATAL_FAILURE(InitState());
3822 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3823
3824 m_errorMonitor->ClearState();
3825
3826 VkShaderModule module;
3827 VkShaderModuleCreateInfo moduleCreateInfo;
3828 struct icd_spv_header spv;
3829
3830 spv.magic = ~ICD_SPV_MAGIC;
3831 spv.version = ICD_SPV_VERSION;
3832 spv.gen_magic = 0;
3833
3834 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3835 moduleCreateInfo.pNext = NULL;
3836 moduleCreateInfo.pCode = &spv;
3837 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3838 moduleCreateInfo.flags = 0;
3839 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3840
3841 msgFlags = m_errorMonitor->GetState(&msgString);
3842
Chris Forbes96b81762015-09-18 11:40:23 +12003843 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003844 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3845 FAIL() << "Incorrect warning: " << msgString;
3846 }
3847}
3848
3849TEST_F(VkLayerTest, InvalidSPIRVVersion)
3850{
3851 VkFlags msgFlags;
3852 std::string msgString;
3853 ASSERT_NO_FATAL_FAILURE(InitState());
3854 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3855
3856 m_errorMonitor->ClearState();
3857
3858 VkShaderModule module;
3859 VkShaderModuleCreateInfo moduleCreateInfo;
3860 struct icd_spv_header spv;
3861
3862 spv.magic = ICD_SPV_MAGIC;
3863 spv.version = ~ICD_SPV_VERSION;
3864 spv.gen_magic = 0;
3865
3866 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3867 moduleCreateInfo.pNext = NULL;
3868
3869 moduleCreateInfo.pCode = &spv;
3870 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3871 moduleCreateInfo.flags = 0;
3872 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3873
3874 msgFlags = m_errorMonitor->GetState(&msgString);
3875
Chris Forbes96b81762015-09-18 11:40:23 +12003876 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003877 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3878 FAIL() << "Incorrect warning: " << msgString;
3879 }
3880}
3881
Chris Forbes5af3bf22015-05-25 11:13:08 +12003882TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
3883{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003884 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12003885 std::string msgString;
3886 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12003888
3889 char const *vsSource =
3890 "#version 140\n"
3891 "#extension GL_ARB_separate_shader_objects: require\n"
3892 "#extension GL_ARB_shading_language_420pack: require\n"
3893 "\n"
3894 "layout(location=0) out float x;\n"
3895 "void main(){\n"
3896 " gl_Position = vec4(1);\n"
3897 " x = 0;\n"
3898 "}\n";
3899 char const *fsSource =
3900 "#version 140\n"
3901 "#extension GL_ARB_separate_shader_objects: require\n"
3902 "#extension GL_ARB_shading_language_420pack: require\n"
3903 "\n"
3904 "layout(location=0) out vec4 color;\n"
3905 "void main(){\n"
3906 " color = vec4(1);\n"
3907 "}\n";
3908
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003909 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3910 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003911
3912 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003913 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12003914 pipe.AddShader(&vs);
3915 pipe.AddShader(&fs);
3916
Chris Forbes5af3bf22015-05-25 11:13:08 +12003917 VkDescriptorSetObj descriptorSet(m_device);
3918 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003919 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003920
3921 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003922 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12003923
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003924 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003925
Cody Northrop1684adb2015-08-05 11:15:02 -06003926 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003927 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
3928 FAIL() << "Incorrect warning: " << msgString;
3929 }
3930}
Chris Forbes5af3bf22015-05-25 11:13:08 +12003931
Chris Forbes3c10b852015-05-25 11:13:13 +12003932TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
3933{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003934 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12003935 std::string msgString;
3936 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003937 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12003938
3939 char const *vsSource =
3940 "#version 140\n"
3941 "#extension GL_ARB_separate_shader_objects: require\n"
3942 "#extension GL_ARB_shading_language_420pack: require\n"
3943 "\n"
3944 "void main(){\n"
3945 " gl_Position = vec4(1);\n"
3946 "}\n";
3947 char const *fsSource =
3948 "#version 140\n"
3949 "#extension GL_ARB_separate_shader_objects: require\n"
3950 "#extension GL_ARB_shading_language_420pack: require\n"
3951 "\n"
3952 "layout(location=0) in float x;\n"
3953 "layout(location=0) out vec4 color;\n"
3954 "void main(){\n"
3955 " color = vec4(x);\n"
3956 "}\n";
3957
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003958 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3959 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes3c10b852015-05-25 11:13:13 +12003960
3961 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003962 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12003963 pipe.AddShader(&vs);
3964 pipe.AddShader(&fs);
3965
Chris Forbes3c10b852015-05-25 11:13:13 +12003966 VkDescriptorSetObj descriptorSet(m_device);
3967 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003968 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12003969
3970 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003971 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12003972
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003973 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12003974
Cody Northrop1684adb2015-08-05 11:15:02 -06003975 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12003976 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
3977 FAIL() << "Incorrect error: " << msgString;
3978 }
3979}
3980
Chris Forbescc281692015-05-25 11:13:17 +12003981TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
3982{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003983 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12003984 std::string msgString;
3985 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12003987
3988 char const *vsSource =
3989 "#version 140\n"
3990 "#extension GL_ARB_separate_shader_objects: require\n"
3991 "#extension GL_ARB_shading_language_420pack: require\n"
3992 "\n"
3993 "layout(location=0) out int x;\n"
3994 "void main(){\n"
3995 " x = 0;\n"
3996 " gl_Position = vec4(1);\n"
3997 "}\n";
3998 char const *fsSource =
3999 "#version 140\n"
4000 "#extension GL_ARB_separate_shader_objects: require\n"
4001 "#extension GL_ARB_shading_language_420pack: require\n"
4002 "\n"
4003 "layout(location=0) in float x;\n" /* VS writes int */
4004 "layout(location=0) out vec4 color;\n"
4005 "void main(){\n"
4006 " color = vec4(x);\n"
4007 "}\n";
4008
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004009 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4010 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbescc281692015-05-25 11:13:17 +12004011
4012 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004013 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12004014 pipe.AddShader(&vs);
4015 pipe.AddShader(&fs);
4016
Chris Forbescc281692015-05-25 11:13:17 +12004017 VkDescriptorSetObj descriptorSet(m_device);
4018 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004019 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12004020
4021 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004022 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12004023
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004024 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12004025
Cody Northrop1684adb2015-08-05 11:15:02 -06004026 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12004027 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
4028 FAIL() << "Incorrect error: " << msgString;
4029 }
4030}
4031
Chris Forbes8291c052015-05-25 11:13:28 +12004032TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4033{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004034 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12004035 std::string msgString;
4036 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12004038
4039 VkVertexInputBindingDescription input_binding;
4040 memset(&input_binding, 0, sizeof(input_binding));
4041
4042 VkVertexInputAttributeDescription input_attrib;
4043 memset(&input_attrib, 0, sizeof(input_attrib));
4044 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4045
4046 char const *vsSource =
4047 "#version 140\n"
4048 "#extension GL_ARB_separate_shader_objects: require\n"
4049 "#extension GL_ARB_shading_language_420pack: require\n"
4050 "\n"
4051 "void main(){\n"
4052 " gl_Position = vec4(1);\n"
4053 "}\n";
4054 char const *fsSource =
4055 "#version 140\n"
4056 "#extension GL_ARB_separate_shader_objects: require\n"
4057 "#extension GL_ARB_shading_language_420pack: require\n"
4058 "\n"
4059 "layout(location=0) out vec4 color;\n"
4060 "void main(){\n"
4061 " color = vec4(1);\n"
4062 "}\n";
4063
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004064 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4065 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes8291c052015-05-25 11:13:28 +12004066
4067 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004068 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12004069 pipe.AddShader(&vs);
4070 pipe.AddShader(&fs);
4071
4072 pipe.AddVertexInputBindings(&input_binding, 1);
4073 pipe.AddVertexInputAttribs(&input_attrib, 1);
4074
Chris Forbes8291c052015-05-25 11:13:28 +12004075 VkDescriptorSetObj descriptorSet(m_device);
4076 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004077 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12004078
4079 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004080 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12004081
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004082 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12004083
Cody Northrop1684adb2015-08-05 11:15:02 -06004084 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12004085 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
4086 FAIL() << "Incorrect warning: " << msgString;
4087 }
4088}
4089
Chris Forbes37367e62015-05-25 11:13:29 +12004090TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4091{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004092 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12004093 std::string msgString;
4094 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12004096
4097 char const *vsSource =
4098 "#version 140\n"
4099 "#extension GL_ARB_separate_shader_objects: require\n"
4100 "#extension GL_ARB_shading_language_420pack: require\n"
4101 "\n"
4102 "layout(location=0) in vec4 x;\n" /* not provided */
4103 "void main(){\n"
4104 " gl_Position = x;\n"
4105 "}\n";
4106 char const *fsSource =
4107 "#version 140\n"
4108 "#extension GL_ARB_separate_shader_objects: require\n"
4109 "#extension GL_ARB_shading_language_420pack: require\n"
4110 "\n"
4111 "layout(location=0) out vec4 color;\n"
4112 "void main(){\n"
4113 " color = vec4(1);\n"
4114 "}\n";
4115
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004116 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4117 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes37367e62015-05-25 11:13:29 +12004118
4119 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004120 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12004121 pipe.AddShader(&vs);
4122 pipe.AddShader(&fs);
4123
Chris Forbes37367e62015-05-25 11:13:29 +12004124 VkDescriptorSetObj descriptorSet(m_device);
4125 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004126 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12004127
4128 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004129 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12004130
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004131 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12004132
Cody Northrop1684adb2015-08-05 11:15:02 -06004133 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12004134 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
4135 FAIL() << "Incorrect warning: " << msgString;
4136 }
4137}
4138
Chris Forbesa4b02322015-05-25 11:13:31 +12004139TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4140{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004141 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12004142 std::string msgString;
4143 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12004145
4146 VkVertexInputBindingDescription input_binding;
4147 memset(&input_binding, 0, sizeof(input_binding));
4148
4149 VkVertexInputAttributeDescription input_attrib;
4150 memset(&input_attrib, 0, sizeof(input_attrib));
4151 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4152
4153 char const *vsSource =
4154 "#version 140\n"
4155 "#extension GL_ARB_separate_shader_objects: require\n"
4156 "#extension GL_ARB_shading_language_420pack: require\n"
4157 "\n"
4158 "layout(location=0) in int x;\n" /* attrib provided float */
4159 "void main(){\n"
4160 " gl_Position = vec4(x);\n"
4161 "}\n";
4162 char const *fsSource =
4163 "#version 140\n"
4164 "#extension GL_ARB_separate_shader_objects: require\n"
4165 "#extension GL_ARB_shading_language_420pack: require\n"
4166 "\n"
4167 "layout(location=0) out vec4 color;\n"
4168 "void main(){\n"
4169 " color = vec4(1);\n"
4170 "}\n";
4171
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004172 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4173 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa4b02322015-05-25 11:13:31 +12004174
4175 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004176 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12004177 pipe.AddShader(&vs);
4178 pipe.AddShader(&fs);
4179
4180 pipe.AddVertexInputBindings(&input_binding, 1);
4181 pipe.AddVertexInputAttribs(&input_attrib, 1);
4182
Chris Forbesa4b02322015-05-25 11:13:31 +12004183 VkDescriptorSetObj descriptorSet(m_device);
4184 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004185 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12004186
4187 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004188 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12004189
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004190 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12004191
Cody Northrop1684adb2015-08-05 11:15:02 -06004192 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12004193 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
4194 FAIL() << "Incorrect error: " << msgString;
4195 }
4196}
4197
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004198TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
4199{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004200 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004201 std::string msgString;
4202 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004203 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004204
4205 /* Two binding descriptions for binding 0 */
4206 VkVertexInputBindingDescription input_bindings[2];
4207 memset(input_bindings, 0, sizeof(input_bindings));
4208
4209 VkVertexInputAttributeDescription input_attrib;
4210 memset(&input_attrib, 0, sizeof(input_attrib));
4211 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4212
4213 char const *vsSource =
4214 "#version 140\n"
4215 "#extension GL_ARB_separate_shader_objects: require\n"
4216 "#extension GL_ARB_shading_language_420pack: require\n"
4217 "\n"
4218 "layout(location=0) in float x;\n" /* attrib provided float */
4219 "void main(){\n"
4220 " gl_Position = vec4(x);\n"
4221 "}\n";
4222 char const *fsSource =
4223 "#version 140\n"
4224 "#extension GL_ARB_separate_shader_objects: require\n"
4225 "#extension GL_ARB_shading_language_420pack: require\n"
4226 "\n"
4227 "layout(location=0) out vec4 color;\n"
4228 "void main(){\n"
4229 " color = vec4(1);\n"
4230 "}\n";
4231
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004232 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4233 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004234
4235 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004236 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004237 pipe.AddShader(&vs);
4238 pipe.AddShader(&fs);
4239
4240 pipe.AddVertexInputBindings(input_bindings, 2);
4241 pipe.AddVertexInputAttribs(&input_attrib, 1);
4242
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004243 VkDescriptorSetObj descriptorSet(m_device);
4244 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004245 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004246
4247 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004248 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004249
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004250 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004251
Cody Northrop1684adb2015-08-05 11:15:02 -06004252 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004253 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
4254 FAIL() << "Incorrect error: " << msgString;
4255 }
4256}
Chris Forbes4c948702015-05-25 11:13:32 +12004257
Chris Forbesc12ef122015-05-25 11:13:40 +12004258/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
4259 * rejects it. */
4260
4261TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
4262{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004263 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12004264 std::string msgString;
4265 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12004266
4267 char const *vsSource =
4268 "#version 140\n"
4269 "#extension GL_ARB_separate_shader_objects: require\n"
4270 "#extension GL_ARB_shading_language_420pack: require\n"
4271 "\n"
4272 "void main(){\n"
4273 " gl_Position = vec4(1);\n"
4274 "}\n";
4275 char const *fsSource =
4276 "#version 140\n"
4277 "#extension GL_ARB_separate_shader_objects: require\n"
4278 "#extension GL_ARB_shading_language_420pack: require\n"
4279 "\n"
4280 "void main(){\n"
4281 "}\n";
4282
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004283 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4284 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc12ef122015-05-25 11:13:40 +12004285
4286 VkPipelineObj pipe(m_device);
4287 pipe.AddShader(&vs);
4288 pipe.AddShader(&fs);
4289
Chia-I Wuc278df82015-07-07 11:50:03 +08004290 /* set up CB 0, not written */
4291 pipe.AddColorAttachment();
4292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12004293
Chris Forbesc12ef122015-05-25 11:13:40 +12004294 VkDescriptorSetObj descriptorSet(m_device);
4295 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004296 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12004297
4298 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004299 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12004300
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004301 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12004302
Cody Northrop1684adb2015-08-05 11:15:02 -06004303 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12004304 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
4305 FAIL() << "Incorrect error: " << msgString;
4306 }
4307}
4308
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004309TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
4310{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004311 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004312 std::string msgString;
4313 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004314
4315 char const *vsSource =
4316 "#version 140\n"
4317 "#extension GL_ARB_separate_shader_objects: require\n"
4318 "#extension GL_ARB_shading_language_420pack: require\n"
4319 "\n"
4320 "void main(){\n"
4321 " gl_Position = vec4(1);\n"
4322 "}\n";
4323 char const *fsSource =
4324 "#version 140\n"
4325 "#extension GL_ARB_separate_shader_objects: require\n"
4326 "#extension GL_ARB_shading_language_420pack: require\n"
4327 "\n"
4328 "layout(location=0) out vec4 x;\n"
4329 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4330 "void main(){\n"
4331 " x = vec4(1);\n"
4332 " y = vec4(1);\n"
4333 "}\n";
4334
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004335 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4336 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004337
4338 VkPipelineObj pipe(m_device);
4339 pipe.AddShader(&vs);
4340 pipe.AddShader(&fs);
4341
Chia-I Wuc278df82015-07-07 11:50:03 +08004342 /* set up CB 0, not written */
4343 pipe.AddColorAttachment();
4344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004345 /* FS writes CB 1, but we don't configure it */
4346
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004347 VkDescriptorSetObj descriptorSet(m_device);
4348 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004349 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004350
4351 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004352 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004353
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004354 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004355
Cody Northrop1684adb2015-08-05 11:15:02 -06004356 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004357 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
4358 FAIL() << "Incorrect warning: " << msgString;
4359 }
4360}
4361
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004362TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4363{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004364 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004365 std::string msgString;
4366 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004367
4368 char const *vsSource =
4369 "#version 140\n"
4370 "#extension GL_ARB_separate_shader_objects: require\n"
4371 "#extension GL_ARB_shading_language_420pack: require\n"
4372 "\n"
4373 "void main(){\n"
4374 " gl_Position = vec4(1);\n"
4375 "}\n";
4376 char const *fsSource =
4377 "#version 140\n"
4378 "#extension GL_ARB_separate_shader_objects: require\n"
4379 "#extension GL_ARB_shading_language_420pack: require\n"
4380 "\n"
4381 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4382 "void main(){\n"
4383 " x = ivec4(1);\n"
4384 "}\n";
4385
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004386 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4387 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004388
4389 VkPipelineObj pipe(m_device);
4390 pipe.AddShader(&vs);
4391 pipe.AddShader(&fs);
4392
Chia-I Wuc278df82015-07-07 11:50:03 +08004393 /* set up CB 0; type is UNORM by default */
4394 pipe.AddColorAttachment();
4395 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004396
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004397 VkDescriptorSetObj descriptorSet(m_device);
4398 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004399 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004400
4401 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004402 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004403
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004404 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004405
Cody Northrop1684adb2015-08-05 11:15:02 -06004406 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004407 if (!strstr(msgString.c_str(),"does not match FS output type")) {
4408 FAIL() << "Incorrect error: " << msgString;
4409 }
4410}
Chris Forbesc2050732015-06-05 14:43:36 +12004411
Chris Forbes76ce7882015-08-14 12:04:59 +12004412TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4413{
4414 VkFlags msgFlags;
4415 std::string msgString;
4416 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12004417
4418 char const *vsSource =
4419 "#version 140\n"
4420 "#extension GL_ARB_separate_shader_objects: require\n"
4421 "#extension GL_ARB_shading_language_420pack: require\n"
4422 "\n"
4423 "void main(){\n"
4424 " gl_Position = vec4(1);\n"
4425 "}\n";
4426 char const *fsSource =
4427 "#version 140\n"
4428 "#extension GL_ARB_separate_shader_objects: require\n"
4429 "#extension GL_ARB_shading_language_420pack: require\n"
4430 "\n"
4431 "layout(location=0) out vec4 x;\n"
4432 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4433 "void main(){\n"
4434 " x = vec4(bar.y);\n"
4435 "}\n";
4436
4437 m_errorMonitor->ClearState();
4438
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004439 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4440 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes76ce7882015-08-14 12:04:59 +12004441
4442
4443 VkPipelineObj pipe(m_device);
4444 pipe.AddShader(&vs);
4445 pipe.AddShader(&fs);
4446
4447 /* set up CB 0; type is UNORM by default */
4448 pipe.AddColorAttachment();
4449 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4450
4451 VkDescriptorSetObj descriptorSet(m_device);
4452 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
4453
4454 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4455
4456 /* should have generated an error -- pipeline layout does not
4457 * provide a uniform buffer in 0.0
4458 */
4459 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -06004460 ASSERT_TRUE((msgFlags & VK_DBG_REPORT_ERROR_BIT) == VK_DBG_REPORT_ERROR_BIT);
Chris Forbes76ce7882015-08-14 12:04:59 +12004461 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
4462 FAIL() << "Incorrect error: " << msgString;
4463 }
4464}
4465
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004466#endif // SHADER_CHECKER_TESTS
4467
4468#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004469TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4470{
4471 VkFlags msgFlags;
4472 std::string msgString;
4473
4474 ASSERT_NO_FATAL_FAILURE(InitState());
4475 m_errorMonitor->ClearState();
4476
4477 // Create an image
4478 VkImage image;
4479
4480 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4481 const int32_t tex_width = 32;
4482 const int32_t tex_height = 32;
4483
4484 VkImageCreateInfo image_create_info = {};
4485 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4486 image_create_info.pNext = NULL;
4487 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4488 image_create_info.format = tex_format;
4489 image_create_info.extent.width = tex_width;
4490 image_create_info.extent.height = tex_height;
4491 image_create_info.extent.depth = 1;
4492 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004493 image_create_info.arrayLayers = 1;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004494 image_create_info.samples = 1;
4495 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4496 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4497 image_create_info.flags = 0;
4498
4499 // Introduce error by sending down a bogus width extent
4500 image_create_info.extent.width = 65536;
4501 vkCreateImage(m_device->device(), &image_create_info, &image);
4502
4503 msgFlags = m_errorMonitor->GetState(&msgString);
4504 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4505 "with extents outside the queried limits";
4506 if (!strstr(msgString.c_str(),"CreateImage extents exceed allowable limits for format")) {
4507 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4508 }
4509}
4510
4511TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4512{
4513 VkFlags msgFlags;
4514 std::string msgString;
4515
4516 ASSERT_NO_FATAL_FAILURE(InitState());
4517 m_errorMonitor->ClearState();
4518
4519 // Create an image
4520 VkImage image;
4521
4522 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4523 const int32_t tex_width = 32;
4524 const int32_t tex_height = 32;
4525
4526 VkImageCreateInfo image_create_info = {};
4527 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4528 image_create_info.pNext = NULL;
4529 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4530 image_create_info.format = tex_format;
4531 image_create_info.extent.width = tex_width;
4532 image_create_info.extent.height = tex_height;
4533 image_create_info.extent.depth = 1;
4534 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004535 image_create_info.arrayLayers = 1;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004536 image_create_info.samples = 1;
4537 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4538 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4539 image_create_info.flags = 0;
4540
4541 // Introduce error by sending down individually allowable values that result in a surface size
4542 // exceeding the device maximum
4543 image_create_info.extent.width = 8192;
4544 image_create_info.extent.height = 8192;
4545 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004546 image_create_info.arrayLayers = 4;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004547 image_create_info.samples = 2;
4548 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
4549 vkCreateImage(m_device->device(), &image_create_info, &image);
4550
4551 msgFlags = m_errorMonitor->GetState(&msgString);
4552 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4553 "with resource size exceeding queried limit";
4554 if (!strstr(msgString.c_str(),"CreateImage resource size exceeds allowable maximum")) {
4555 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4556 }
4557}
4558
Mike Stroyan43909d82015-09-25 13:39:21 -06004559TEST_F(VkLayerTest, UpdateBufferAlignment)
4560{
4561 VkFlags msgFlags;
4562 std::string msgString;
4563 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4564
4565 ASSERT_NO_FATAL_FAILURE(InitState());
4566
4567 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4568 vk_testing::Buffer buffer;
4569 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4570
4571 BeginCommandBuffer();
4572 // Introduce failure by using offset that is not multiple of 4
4573 m_cmdBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
4574 msgFlags = m_errorMonitor->GetState(&msgString);
4575 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad offset";
4576 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4577 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4578 }
4579 // Introduce failure by using size that is not multiple of 4
4580 m_cmdBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
4581 msgFlags = m_errorMonitor->GetState(&msgString);
4582 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad size";
4583 if (!strstr(msgString.c_str(),"dataSize, is not a multiple of 4")) {
4584 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4585 }
4586 EndCommandBuffer();
4587}
4588
4589TEST_F(VkLayerTest, FillBufferAlignment)
4590{
4591 VkFlags msgFlags;
4592 std::string msgString;
4593
4594 ASSERT_NO_FATAL_FAILURE(InitState());
4595
4596 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4597 vk_testing::Buffer buffer;
4598 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4599
4600 BeginCommandBuffer();
4601 // Introduce failure by using offset that is not multiple of 4
4602 m_cmdBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
4603 msgFlags = m_errorMonitor->GetState(&msgString);
4604 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad offset";
4605 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4606 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4607 }
4608 // Introduce failure by using size that is not multiple of 4
4609 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
4610 msgFlags = m_errorMonitor->GetState(&msgString);
4611 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad size";
4612 if (!strstr(msgString.c_str(),"fillSize, is not a multiple of 4")) {
4613 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize fillSize, is not a multiple of 4'";
4614 }
4615 EndCommandBuffer();
4616}
4617
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004618#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004619
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004620#if IMAGE_TESTS
4621TEST_F(VkLayerTest, InvalidImageView)
4622{
4623 VkFlags msgFlags;
4624 std::string msgString;
4625 VkResult err;
4626
4627 ASSERT_NO_FATAL_FAILURE(InitState());
4628 m_errorMonitor->ClearState();
4629
Mike Stroyan43909d82015-09-25 13:39:21 -06004630 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004631 VkImage image;
4632
4633 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4634 const int32_t tex_width = 32;
4635 const int32_t tex_height = 32;
4636
4637 VkImageCreateInfo image_create_info = {};
4638 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4639 image_create_info.pNext = NULL;
4640 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4641 image_create_info.format = tex_format;
4642 image_create_info.extent.width = tex_width;
4643 image_create_info.extent.height = tex_height;
4644 image_create_info.extent.depth = 1;
4645 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004646 image_create_info.arrayLayers = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004647 image_create_info.samples = 1;
4648 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4649 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4650 image_create_info.flags = 0;
4651
4652 err = vkCreateImage(m_device->device(), &image_create_info, &image);
4653 ASSERT_VK_SUCCESS(err);
4654
4655 VkImageViewCreateInfo image_view_create_info = {};
4656 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4657 image_view_create_info.image = image;
4658 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4659 image_view_create_info.format = tex_format;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004660 image_view_create_info.subresourceRange.numLayers = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004661 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004662 image_view_create_info.subresourceRange.numLevels = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004663 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004664
4665 VkImageView view;
4666 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
4667
4668 msgFlags = m_errorMonitor->GetState(&msgString);
4669 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an invalid ImageView";
4670 if (!strstr(msgString.c_str(),"vkCreateImageView called with baseMipLevel 10 ")) {
Mike Stroyan43909d82015-09-25 13:39:21 -06004671 FAIL() << "Error received was not 'vkCreateImageView called with baseMipLevel 10...' but instead '" << msgString.c_str() << "'";
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004672 }
4673}
Mike Stroyan43909d82015-09-25 13:39:21 -06004674
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004675TEST_F(VkLayerTest, InvalidImageViewAspect)
4676{
4677 VkFlags msgFlags;
4678 std::string msgString;
4679 VkResult err;
4680
4681 ASSERT_NO_FATAL_FAILURE(InitState());
4682 m_errorMonitor->ClearState();
4683
4684 // Create an image and try to create a view with an invalid aspectMask
4685 VkImage image;
4686
4687 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4688 const int32_t tex_width = 32;
4689 const int32_t tex_height = 32;
4690
4691 VkImageCreateInfo image_create_info = {};
4692 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4693 image_create_info.pNext = NULL;
4694 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4695 image_create_info.format = tex_format;
4696 image_create_info.extent.width = tex_width;
4697 image_create_info.extent.height = tex_height;
4698 image_create_info.extent.depth = 1;
4699 image_create_info.mipLevels = 1;
4700 image_create_info.samples = 1;
4701 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4702 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4703 image_create_info.flags = 0;
4704
4705 err = vkCreateImage(m_device->device(), &image_create_info, &image);
4706 ASSERT_VK_SUCCESS(err);
4707
4708 VkImageViewCreateInfo image_view_create_info = {};
4709 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4710 image_view_create_info.image = image;
4711 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4712 image_view_create_info.format = tex_format;
4713 image_view_create_info.subresourceRange.baseMipLevel = 0;
4714 image_view_create_info.subresourceRange.numLevels = 1;
4715 // Cause an error by setting an invalid image aspect
4716 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
4717
4718 VkImageView view;
4719 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
4720
4721 msgFlags = m_errorMonitor->GetState(&msgString);
4722 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error when specifying an invalid ImageView aspect";
4723 if (!strstr(msgString.c_str(),"vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set")) {
4724 FAIL() << "Error received was not 'VkCreateImageView: Color image formats must have ...' but instead '" << msgString.c_str() << "'";
4725 }
4726}
4727
Mike Stroyan43909d82015-09-25 13:39:21 -06004728TEST_F(VkLayerTest, CopyImageTypeMismatch)
4729{
4730 VkFlags msgFlags;
4731 std::string msgString;
4732 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004733 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004734
4735 ASSERT_NO_FATAL_FAILURE(InitState());
4736 m_errorMonitor->ClearState();
4737
4738 // Create two images of different types and try to copy between them
4739 VkImage srcImage;
4740 VkImage destImage;
4741 VkDeviceMemory srcMem;
4742 VkDeviceMemory destMem;
4743 VkMemoryRequirements memReqs;
4744
4745 VkImageCreateInfo image_create_info = {};
4746 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4747 image_create_info.pNext = NULL;
4748 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4749 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4750 image_create_info.extent.width = 32;
4751 image_create_info.extent.height = 32;
4752 image_create_info.extent.depth = 1;
4753 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004754 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06004755 image_create_info.samples = 1;
4756 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4757 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4758 image_create_info.flags = 0;
4759
4760 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4761 ASSERT_VK_SUCCESS(err);
4762
4763 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4764 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4765
4766 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4767 ASSERT_VK_SUCCESS(err);
4768
4769 // Allocate memory
4770 VkMemoryAllocInfo memAlloc = {};
4771 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4772 memAlloc.pNext = NULL;
4773 memAlloc.allocationSize = 0;
4774 memAlloc.memoryTypeIndex = 0;
4775
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004776 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004777 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004778 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4779 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004780 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4781 ASSERT_VK_SUCCESS(err);
4782
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004783 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004784 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004785 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06004786 ASSERT_VK_SUCCESS(err);
4787 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4788 ASSERT_VK_SUCCESS(err);
4789
4790 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4791 ASSERT_VK_SUCCESS(err);
4792 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4793 ASSERT_VK_SUCCESS(err);
4794
4795 BeginCommandBuffer();
4796 VkImageCopy copyRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004797 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004798 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004799 copyRegion.srcSubresource.baseArrayLayer = 0;
4800 copyRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004801 copyRegion.srcOffset.x = 0;
4802 copyRegion.srcOffset.y = 0;
4803 copyRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004804 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004805 copyRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004806 copyRegion.destSubresource.baseArrayLayer = 0;
4807 copyRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004808 copyRegion.destOffset.x = 0;
4809 copyRegion.destOffset.y = 0;
4810 copyRegion.destOffset.z = 0;
4811 copyRegion.extent.width = 1;
4812 copyRegion.extent.height = 1;
4813 copyRegion.extent.depth = 1;
4814 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4815 EndCommandBuffer();
4816
4817 msgFlags = m_errorMonitor->GetState(&msgString);
4818 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4819 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4820 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4821 }
4822
4823 vkDestroyImage(m_device->device(), srcImage);
4824 vkDestroyImage(m_device->device(), destImage);
4825 vkFreeMemory(m_device->device(), srcMem);
4826 vkFreeMemory(m_device->device(), destMem);
4827}
4828
4829TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
4830{
4831 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
4832}
4833
4834TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
4835{
4836 VkFlags msgFlags;
4837 std::string msgString;
4838 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004839 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004840
4841 ASSERT_NO_FATAL_FAILURE(InitState());
4842 m_errorMonitor->ClearState();
4843
4844 // Create two images of different types and try to copy between them
4845 VkImage srcImage;
4846 VkImage destImage;
4847 VkDeviceMemory srcMem;
4848 VkDeviceMemory destMem;
4849 VkMemoryRequirements memReqs;
4850
4851 VkImageCreateInfo image_create_info = {};
4852 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4853 image_create_info.pNext = NULL;
4854 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4855 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4856 image_create_info.extent.width = 32;
4857 image_create_info.extent.height = 32;
4858 image_create_info.extent.depth = 1;
4859 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004860 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06004861 image_create_info.samples = 1;
4862 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4863 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4864 image_create_info.flags = 0;
4865
4866 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4867 ASSERT_VK_SUCCESS(err);
4868
4869 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4870 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4871
4872 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4873 ASSERT_VK_SUCCESS(err);
4874
4875 // Allocate memory
4876 VkMemoryAllocInfo memAlloc = {};
4877 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4878 memAlloc.pNext = NULL;
4879 memAlloc.allocationSize = 0;
4880 memAlloc.memoryTypeIndex = 0;
4881
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004882 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004883 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004884 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4885 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004886 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4887 ASSERT_VK_SUCCESS(err);
4888
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004889 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004890 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004891 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4892 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004893 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4894 ASSERT_VK_SUCCESS(err);
4895
4896 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4897 ASSERT_VK_SUCCESS(err);
4898 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4899 ASSERT_VK_SUCCESS(err);
4900
4901 BeginCommandBuffer();
4902 VkImageCopy copyRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004903 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004904 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004905 copyRegion.srcSubresource.baseArrayLayer = 0;
4906 copyRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004907 copyRegion.srcOffset.x = 0;
4908 copyRegion.srcOffset.y = 0;
4909 copyRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004910 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004911 copyRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004912 copyRegion.destSubresource.baseArrayLayer = 0;
4913 copyRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004914 copyRegion.destOffset.x = 0;
4915 copyRegion.destOffset.y = 0;
4916 copyRegion.destOffset.z = 0;
4917 copyRegion.extent.width = 1;
4918 copyRegion.extent.height = 1;
4919 copyRegion.extent.depth = 1;
4920 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4921 EndCommandBuffer();
4922
4923 msgFlags = m_errorMonitor->GetState(&msgString);
4924 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4925 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4926 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4927 }
4928
4929 vkDestroyImage(m_device->device(), srcImage);
4930 vkDestroyImage(m_device->device(), destImage);
4931 vkFreeMemory(m_device->device(), srcMem);
4932 vkFreeMemory(m_device->device(), destMem);
4933}
4934
4935TEST_F(VkLayerTest, ResolveImageLowSampleCount)
4936{
4937 VkFlags msgFlags;
4938 std::string msgString;
4939 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004940 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004941
4942 ASSERT_NO_FATAL_FAILURE(InitState());
4943 m_errorMonitor->ClearState();
4944
4945 // Create two images of sample count 1 and try to Resolve between them
4946 VkImage srcImage;
4947 VkImage destImage;
4948 VkDeviceMemory srcMem;
4949 VkDeviceMemory destMem;
4950 VkMemoryRequirements memReqs;
4951
4952 VkImageCreateInfo image_create_info = {};
4953 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4954 image_create_info.pNext = NULL;
4955 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4956 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4957 image_create_info.extent.width = 32;
4958 image_create_info.extent.height = 1;
4959 image_create_info.extent.depth = 1;
4960 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004961 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06004962 image_create_info.samples = 1;
4963 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4964 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4965 image_create_info.flags = 0;
4966
4967 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4968 ASSERT_VK_SUCCESS(err);
4969
4970 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4971 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4972
4973 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4974 ASSERT_VK_SUCCESS(err);
4975
4976 // Allocate memory
4977 VkMemoryAllocInfo memAlloc = {};
4978 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4979 memAlloc.pNext = NULL;
4980 memAlloc.allocationSize = 0;
4981 memAlloc.memoryTypeIndex = 0;
4982
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004983 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004984 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004985 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4986 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004987 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4988 ASSERT_VK_SUCCESS(err);
4989
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004990 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004991 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004992 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4993 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004994 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4995 ASSERT_VK_SUCCESS(err);
4996
4997 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4998 ASSERT_VK_SUCCESS(err);
4999 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
5000 ASSERT_VK_SUCCESS(err);
5001
5002 BeginCommandBuffer();
5003 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5004 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5005 //VK_IMAGE_LAYOUT_GENERAL = 1,
5006 VkImageResolve resolveRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005007 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005008 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005009 resolveRegion.srcSubresource.baseArrayLayer = 0;
5010 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005011 resolveRegion.srcOffset.x = 0;
5012 resolveRegion.srcOffset.y = 0;
5013 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005014 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005015 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005016 resolveRegion.destSubresource.baseArrayLayer = 0;
5017 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005018 resolveRegion.destOffset.x = 0;
5019 resolveRegion.destOffset.y = 0;
5020 resolveRegion.destOffset.z = 0;
5021 resolveRegion.extent.width = 1;
5022 resolveRegion.extent.height = 1;
5023 resolveRegion.extent.depth = 1;
5024 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
5025 EndCommandBuffer();
5026
5027 msgFlags = m_errorMonitor->GetState(&msgString);
5028 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
5029 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with source sample count less than 2.")) {
5030 FAIL() << "Error received was not 'vkCmdResolveImage called with source sample count less than 2.' but instead '" << msgString.c_str() << "'";
5031 }
5032
5033 vkDestroyImage(m_device->device(), srcImage);
5034 vkDestroyImage(m_device->device(), destImage);
5035 vkFreeMemory(m_device->device(), srcMem);
5036 vkFreeMemory(m_device->device(), destMem);
5037}
5038
5039TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5040{
5041 VkFlags msgFlags;
5042 std::string msgString;
5043 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005044 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005045
5046 ASSERT_NO_FATAL_FAILURE(InitState());
5047 m_errorMonitor->ClearState();
5048
5049 // Create two images of sample count 2 and try to Resolve between them
5050 VkImage srcImage;
5051 VkImage destImage;
5052 VkDeviceMemory srcMem;
5053 VkDeviceMemory destMem;
5054 VkMemoryRequirements memReqs;
5055
5056 VkImageCreateInfo image_create_info = {};
5057 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5058 image_create_info.pNext = NULL;
5059 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5060 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5061 image_create_info.extent.width = 32;
5062 image_create_info.extent.height = 1;
5063 image_create_info.extent.depth = 1;
5064 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005065 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06005066 image_create_info.samples = 2;
5067 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5068 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
5069 image_create_info.flags = 0;
5070
5071 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
5072 ASSERT_VK_SUCCESS(err);
5073
5074 image_create_info.imageType = VK_IMAGE_TYPE_1D;
5075 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
5076
5077 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
5078 ASSERT_VK_SUCCESS(err);
5079
5080 // Allocate memory
5081 VkMemoryAllocInfo memAlloc = {};
5082 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5083 memAlloc.pNext = NULL;
5084 memAlloc.allocationSize = 0;
5085 memAlloc.memoryTypeIndex = 0;
5086
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005087 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005088 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005089 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5090 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06005091 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
5092 ASSERT_VK_SUCCESS(err);
5093
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005094 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005095 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005096 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5097 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06005098 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
5099 ASSERT_VK_SUCCESS(err);
5100
5101 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5102 ASSERT_VK_SUCCESS(err);
5103 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
5104 ASSERT_VK_SUCCESS(err);
5105
5106 BeginCommandBuffer();
5107 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5108 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5109 //VK_IMAGE_LAYOUT_GENERAL = 1,
5110 VkImageResolve resolveRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005111 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005112 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005113 resolveRegion.srcSubresource.baseArrayLayer = 0;
5114 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005115 resolveRegion.srcOffset.x = 0;
5116 resolveRegion.srcOffset.y = 0;
5117 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005118 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005119 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005120 resolveRegion.destSubresource.baseArrayLayer = 0;
5121 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005122 resolveRegion.destOffset.x = 0;
5123 resolveRegion.destOffset.y = 0;
5124 resolveRegion.destOffset.z = 0;
5125 resolveRegion.extent.width = 1;
5126 resolveRegion.extent.height = 1;
5127 resolveRegion.extent.depth = 1;
5128 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
5129 EndCommandBuffer();
5130
5131 msgFlags = m_errorMonitor->GetState(&msgString);
5132 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
5133 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with dest sample count greater than 1.")) {
5134 FAIL() << "Error received was not 'vkCmdResolveImage called with dest sample count greater than 1.' but instead '" << msgString.c_str() << "'";
5135 }
5136
5137 vkDestroyImage(m_device->device(), srcImage);
5138 vkDestroyImage(m_device->device(), destImage);
5139 vkFreeMemory(m_device->device(), srcMem);
5140 vkFreeMemory(m_device->device(), destMem);
5141}
5142
5143TEST_F(VkLayerTest, ResolveImageFormatMismatch)
5144{
5145 VkFlags msgFlags;
5146 std::string msgString;
5147 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005148 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005149
5150 ASSERT_NO_FATAL_FAILURE(InitState());
5151 m_errorMonitor->ClearState();
5152
5153 // Create two images of different types and try to copy between them
5154 VkImage srcImage;
5155 VkImage destImage;
5156 VkDeviceMemory srcMem;
5157 VkDeviceMemory destMem;
5158 VkMemoryRequirements memReqs;
5159
5160 VkImageCreateInfo image_create_info = {};
5161 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5162 image_create_info.pNext = NULL;
5163 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5164 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5165 image_create_info.extent.width = 32;
5166 image_create_info.extent.height = 1;
5167 image_create_info.extent.depth = 1;
5168 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005169 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06005170 image_create_info.samples = 2;
5171 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5172 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
5173 image_create_info.flags = 0;
5174
5175 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
5176 ASSERT_VK_SUCCESS(err);
5177
5178 image_create_info.format = VK_FORMAT_B8G8R8_SRGB;
5179 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
5180 image_create_info.samples = 1;
5181
5182 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
5183 ASSERT_VK_SUCCESS(err);
5184
5185 // Allocate memory
5186 VkMemoryAllocInfo memAlloc = {};
5187 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5188 memAlloc.pNext = NULL;
5189 memAlloc.allocationSize = 0;
5190 memAlloc.memoryTypeIndex = 0;
5191
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005192 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005193 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005194 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5195 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06005196 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
5197 ASSERT_VK_SUCCESS(err);
5198
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005199 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005200 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005201 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5202 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06005203 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
5204 ASSERT_VK_SUCCESS(err);
5205
5206 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5207 ASSERT_VK_SUCCESS(err);
5208 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
5209 ASSERT_VK_SUCCESS(err);
5210
5211 BeginCommandBuffer();
5212 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5213 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5214 //VK_IMAGE_LAYOUT_GENERAL = 1,
5215 VkImageResolve resolveRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005216 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005217 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005218 resolveRegion.srcSubresource.baseArrayLayer = 0;
5219 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005220 resolveRegion.srcOffset.x = 0;
5221 resolveRegion.srcOffset.y = 0;
5222 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005223 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005224 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005225 resolveRegion.destSubresource.baseArrayLayer = 0;
5226 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005227 resolveRegion.destOffset.x = 0;
5228 resolveRegion.destOffset.y = 0;
5229 resolveRegion.destOffset.z = 0;
5230 resolveRegion.extent.width = 1;
5231 resolveRegion.extent.height = 1;
5232 resolveRegion.extent.depth = 1;
5233 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
5234 EndCommandBuffer();
5235
5236 msgFlags = m_errorMonitor->GetState(&msgString);
5237 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage format mismatch";
5238 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest formats.")) {
5239 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest formats.' but instead '" << msgString.c_str() << "'";
5240 }
5241
5242 vkDestroyImage(m_device->device(), srcImage);
5243 vkDestroyImage(m_device->device(), destImage);
5244 vkFreeMemory(m_device->device(), srcMem);
5245 vkFreeMemory(m_device->device(), destMem);
5246}
5247
5248TEST_F(VkLayerTest, ResolveImageTypeMismatch)
5249{
5250 VkFlags msgFlags;
5251 std::string msgString;
5252 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005253 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005254
5255 ASSERT_NO_FATAL_FAILURE(InitState());
5256 m_errorMonitor->ClearState();
5257
5258 // Create two images of different types and try to copy between them
5259 VkImage srcImage;
5260 VkImage destImage;
5261 VkDeviceMemory srcMem;
5262 VkDeviceMemory destMem;
5263 VkMemoryRequirements memReqs;
5264
5265 VkImageCreateInfo image_create_info = {};
5266 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5267 image_create_info.pNext = NULL;
5268 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5269 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5270 image_create_info.extent.width = 32;
5271 image_create_info.extent.height = 1;
5272 image_create_info.extent.depth = 1;
5273 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005274 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06005275 image_create_info.samples = 2;
5276 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5277 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
5278 image_create_info.flags = 0;
5279
5280 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
5281 ASSERT_VK_SUCCESS(err);
5282
5283 image_create_info.imageType = VK_IMAGE_TYPE_1D;
5284 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
5285 image_create_info.samples = 1;
5286
5287 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
5288 ASSERT_VK_SUCCESS(err);
5289
5290 // Allocate memory
5291 VkMemoryAllocInfo memAlloc = {};
5292 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5293 memAlloc.pNext = NULL;
5294 memAlloc.allocationSize = 0;
5295 memAlloc.memoryTypeIndex = 0;
5296
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005297 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005298 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005299 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5300 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06005301 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
5302 ASSERT_VK_SUCCESS(err);
5303
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005304 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005305 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005306 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5307 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06005308 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
5309 ASSERT_VK_SUCCESS(err);
5310
5311 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5312 ASSERT_VK_SUCCESS(err);
5313 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
5314 ASSERT_VK_SUCCESS(err);
5315
5316 BeginCommandBuffer();
5317 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5318 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5319 //VK_IMAGE_LAYOUT_GENERAL = 1,
5320 VkImageResolve resolveRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005321 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005322 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005323 resolveRegion.srcSubresource.baseArrayLayer = 0;
5324 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005325 resolveRegion.srcOffset.x = 0;
5326 resolveRegion.srcOffset.y = 0;
5327 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005328 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005329 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005330 resolveRegion.destSubresource.baseArrayLayer = 0;
5331 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005332 resolveRegion.destOffset.x = 0;
5333 resolveRegion.destOffset.y = 0;
5334 resolveRegion.destOffset.z = 0;
5335 resolveRegion.extent.width = 1;
5336 resolveRegion.extent.height = 1;
5337 resolveRegion.extent.depth = 1;
5338 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
5339 EndCommandBuffer();
5340
5341 msgFlags = m_errorMonitor->GetState(&msgString);
5342 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
5343 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest image types.")) {
5344 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest image types.' but instead '" << msgString.c_str() << "'";
5345 }
5346
5347 vkDestroyImage(m_device->device(), srcImage);
5348 vkDestroyImage(m_device->device(), destImage);
5349 vkFreeMemory(m_device->device(), srcMem);
5350 vkFreeMemory(m_device->device(), destMem);
5351}
Tobin Ehlisb46be812015-10-23 16:00:08 -06005352
5353TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
5354{
5355 // Create a single Image descriptor and cause it to first hit an error due
5356 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
5357 // The image format check comes 2nd in validation so we trigger it first,
5358 // then when we cause aspect fail next, bad format check will be preempted
5359 VkFlags msgFlags;
5360 std::string msgString;
5361 VkResult err;
5362
5363 ASSERT_NO_FATAL_FAILURE(InitState());
5364 m_errorMonitor->ClearState();
5365 VkDescriptorTypeCount ds_type_count = {};
5366 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5367 ds_type_count.count = 1;
5368
5369 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5370 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5371 ds_pool_ci.pNext = NULL;
5372 ds_pool_ci.maxSets = 1;
5373 ds_pool_ci.count = 1;
5374 ds_pool_ci.pTypeCount = &ds_type_count;
5375
5376 VkDescriptorPool ds_pool;
5377 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
5378 ASSERT_VK_SUCCESS(err);
5379
5380 VkDescriptorSetLayoutBinding dsl_binding = {};
5381 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5382 dsl_binding.arraySize = 1;
5383 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5384 dsl_binding.pImmutableSamplers = NULL;
5385
5386 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5387 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5388 ds_layout_ci.pNext = NULL;
5389 ds_layout_ci.count = 1;
5390 ds_layout_ci.pBinding = &dsl_binding;
5391 VkDescriptorSetLayout ds_layout;
5392 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
5393 ASSERT_VK_SUCCESS(err);
5394
5395 VkDescriptorSet descriptorSet;
5396 VkDescriptorSetAllocInfo alloc_info = {};
5397 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
5398 alloc_info.count = 1;
5399 alloc_info.descriptorPool = ds_pool;
5400 alloc_info.pSetLayouts = &ds_layout;
5401 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5402 ASSERT_VK_SUCCESS(err);
5403
5404 VkImage image_bad;
5405 VkImage image_good;
5406 // One bad format and one good format for Color attachment
5407 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
5408 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
5409 const int32_t tex_width = 32;
5410 const int32_t tex_height = 32;
5411
5412 VkImageCreateInfo image_create_info = {};
5413 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5414 image_create_info.pNext = NULL;
5415 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5416 image_create_info.format = tex_format_bad;
5417 image_create_info.extent.width = tex_width;
5418 image_create_info.extent.height = tex_height;
5419 image_create_info.extent.depth = 1;
5420 image_create_info.mipLevels = 1;
5421 image_create_info.arrayLayers = 1;
5422 image_create_info.samples = 1;
5423 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5424 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
5425 image_create_info.flags = 0;
5426
5427 err = vkCreateImage(m_device->device(), &image_create_info, &image_bad);
5428 ASSERT_VK_SUCCESS(err);
5429 image_create_info.format = tex_format_good;
5430 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
5431 err = vkCreateImage(m_device->device(), &image_create_info, &image_good);
5432 ASSERT_VK_SUCCESS(err);
5433
5434 VkImageViewCreateInfo image_view_create_info = {};
5435 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5436 image_view_create_info.image = image_bad;
5437 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5438 image_view_create_info.format = tex_format_bad;
5439 image_view_create_info.subresourceRange.baseArrayLayer = 0;
5440 image_view_create_info.subresourceRange.baseMipLevel = 0;
5441 image_view_create_info.subresourceRange.numLayers = 1;
5442 image_view_create_info.subresourceRange.numLevels = 1;
5443 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5444
5445 VkImageView view;
5446 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
5447 msgFlags = m_errorMonitor->GetState(&msgString);
5448 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating ImageView for DS image w/ COLOR aspect bit set.";
5449 if (!strstr(msgString.c_str(),"Combination depth/stencil image formats can have only the ")) {
5450 FAIL() << "Error received was not 'Combination depth/stencil image formats can have only the....' but instead '" << msgString.c_str() << "'";
5451 }
5452
5453 vkDestroyImage(m_device->device(), image_bad);
5454 vkDestroyImage(m_device->device(), image_good);
5455 vkDestroyImageView(m_device->device(), view);
5456 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
5457 vkDestroyDescriptorPool(m_device->device(), ds_pool);
5458}
5459
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005460#endif // IMAGE_TESTS
5461
Tony Barbour30486ea2015-04-07 13:44:53 -06005462int main(int argc, char **argv) {
5463 int result;
5464
5465 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06005466 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06005467
5468 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
5469
5470 result = RUN_ALL_TESTS();
5471
Tony Barbour01999182015-04-09 12:58:51 -06005472 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06005473 return result;
5474}