blob: c01d1a96b4704147d5c10ac0939695f5fd424d11 [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
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -060013
Tobin Ehlis57e6a612015-05-26 16:11:58 -060014#define OBJ_TRACKER_TESTS 1
15#define DRAW_STATE_TESTS 1
16#define THREADING_TESTS 1
Chris Forbes5af3bf22015-05-25 11:13:08 +120017#define SHADER_CHECKER_TESTS 1
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -060018#define DEVICE_LIMITS_TESTS 1
Tobin Ehlis342b9bf2015-09-22 10:11:37 -060019#define IMAGE_TESTS 1
Tobin Ehlis57e6a612015-05-26 16:11:58 -060020
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050021//--------------------------------------------------------------------------------------
22// Mesh and VertexFormat Data
23//--------------------------------------------------------------------------------------
24struct Vertex
25{
26 float posX, posY, posZ, posW; // Position data
27 float r, g, b, a; // Color
28};
29
30#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
31
32typedef enum _BsoFailSelect {
33 BsoFailNone = 0x00000000,
Cody Northrope4bc6942015-08-26 10:01:32 -060034 BsoFailLineWidth = 0x00000001,
35 BsoFailDepthBias = 0x00000002,
Cody Northropf5bd2252015-08-17 11:10:49 -060036 BsoFailViewport = 0x00000004,
Tobin Ehlisf6cb4672015-09-29 08:18:34 -060037 BsoFailScissor = 0x00000008,
38 BsoFailBlend = 0x00000010,
39 BsoFailDepthBounds = 0x00000020,
40 BsoFailStencilReadMask = 0x00000040,
41 BsoFailStencilWriteMask = 0x00000080,
42 BsoFailStencilReference = 0x00000100,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050043} BsoFailSelect;
44
45struct vktriangle_vs_uniform {
46 // Must start with MVP
47 float mvp[4][4];
48 float position[3][4];
49 float color[3][4];
50};
51
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050052static const char bindStateVertShaderText[] =
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050053 "#version 130\n"
54 "vec2 vertices[3];\n"
55 "void main() {\n"
56 " vertices[0] = vec2(-1.0, -1.0);\n"
57 " vertices[1] = vec2( 1.0, -1.0);\n"
58 " vertices[2] = vec2( 0.0, 1.0);\n"
59 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
60 "}\n";
61
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050062static const char bindStateFragShaderText[] =
Cody Northrop74a2d2c2015-06-16 17:32:04 -060063 "#version 140\n"
64 "#extension GL_ARB_separate_shader_objects: require\n"
65 "#extension GL_ARB_shading_language_420pack: require\n"
66 "\n"
67 "layout(location = 0) out vec4 uFragColor;\n"
68 "void main(){\n"
69 " uFragColor = vec4(0,1,0,1);\n"
70 "}\n";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050071
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -060072static VkBool32 myDbgFunc(
Tony Barboure84a8d62015-07-10 14:10:27 -060073 VkFlags msgFlags,
74 VkDbgObjectType objType,
75 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060076 size_t location,
77 int32_t msgCode,
78 const char* pLayerPrefix,
79 const char* pMsg,
80 void* pUserData);
Tony Barbour30486ea2015-04-07 13:44:53 -060081
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -060082// ********************************************************
83// ErrorMonitor Usage:
84//
85// Call SetDesiredFailureMsg with a string to be compared against all
86// encountered log messages. Passing NULL will match all log messages.
87// logMsg will return true for skipCall only if msg is matched or NULL.
88//
89// Call DesiredMsgFound to determine if the desired failure message
90// was encountered.
91
Tony Barbour30486ea2015-04-07 13:44:53 -060092class ErrorMonitor {
93public:
Tony Barbour0c1bdc62015-04-29 17:34:29 -060094 ErrorMonitor()
Tony Barbour30486ea2015-04-07 13:44:53 -060095 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060096 test_platform_thread_create_mutex(&m_mutex);
97 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060098 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -060099 m_bailout = NULL;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600100 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -0600101 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600102
103 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600104 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600105 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600106 m_desiredMsg.clear();
107 m_failureMsg.clear();
108 m_otherMsgs.clear();
109 m_desiredMsg = msgString;
110 m_msgFound = VK_FALSE;
111 m_msgFlags = msgFlags;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600112 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -0600113 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600114
115 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600116 {
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600117 VkBool32 result = VK_FALSE;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600118 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600119 if (m_bailout != NULL) {
120 *m_bailout = true;
121 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600122 string errorString(msgString);
123 if (msgFlags & m_msgFlags) {
124 if (errorString.find(m_desiredMsg) != string::npos) {
125 m_failureMsg = errorString;
126 m_msgFound = VK_TRUE;
127 result = VK_TRUE;
128 } else {
129 m_otherMsgs.push_back(errorString);
130 }
131 }
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600132 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600133 return result;
Mike Stroyan09aae812015-05-12 16:00:45 -0600134 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600135
136 vector<string> GetOtherFailureMsgs(void)
137 {
138 return m_otherMsgs;
139 }
140
141 string GetFailureMsg(void)
142 {
143 return m_failureMsg;
144 }
145
146 VkBool32 DesiredMsgFound(void)
147 {
148 return m_msgFound;
149 }
150
Mike Stroyan09aae812015-05-12 16:00:45 -0600151 void SetBailout(bool *bailout)
152 {
153 m_bailout = bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600154 }
155
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600156 void DumpFailureMsgs(void)
157 {
158 vector<string> otherMsgs = GetOtherFailureMsgs();
159 cout << "Other error messages logged for this test were:" << endl;
160 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
161 cout << " " << *iter << endl;
162 }
163 }
164
Tony Barbour30486ea2015-04-07 13:44:53 -0600165private:
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600166 VkFlags m_msgFlags;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600167 string m_desiredMsg;
168 string m_failureMsg;
169 vector<string> m_otherMsgs;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600170 test_platform_thread_mutex m_mutex;
171 bool* m_bailout;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600172 VkBool32 m_msgFound;
Tony Barbour30486ea2015-04-07 13:44:53 -0600173};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500174
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600175static VkBool32 myDbgFunc(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600176 VkFlags msgFlags,
Tony Barboure84a8d62015-07-10 14:10:27 -0600177 VkDbgObjectType objType,
178 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600179 size_t location,
180 int32_t msgCode,
181 const char* pLayerPrefix,
182 const char* pMsg,
183 void* pUserData)
Tony Barbour30486ea2015-04-07 13:44:53 -0600184{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600185 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600186 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600187 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600188 }
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600189 return false;
Tony Barbour30486ea2015-04-07 13:44:53 -0600190}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500191
Tony Barbour01999182015-04-09 12:58:51 -0600192class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600193{
194public:
Chia-I Wu1f851912015-10-27 18:04:07 +0800195 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
196 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500197 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
Chia-I Wu1f851912015-10-27 18:04:07 +0800198 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbour1490c912015-07-28 10:17:20 -0600199 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Chia-I Wu1f851912015-10-27 18:04:07 +0800200 { GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600201
Tony Barbour1490c912015-07-28 10:17:20 -0600202 /* Convenience functions that use built-in command buffer */
Chia-I Wu1f851912015-10-27 18:04:07 +0800203 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
204 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600205 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Chia-I Wu1f851912015-10-27 18:04:07 +0800206 { m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600207 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
Chia-I Wu1f851912015-10-27 18:04:07 +0800208 { m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); }
209 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
210 void QueueCommandBuffer(const VkFence& fence) { m_commandBuffer->QueueCommandBuffer(fence); }
Tony Barbour1490c912015-07-28 10:17:20 -0600211 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
Chia-I Wu1f851912015-10-27 18:04:07 +0800212 { m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
Tony Barbour1490c912015-07-28 10:17:20 -0600213 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
Chia-I Wu1f851912015-10-27 18:04:07 +0800214 { m_commandBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600215protected:
Tony Barbour01999182015-04-09 12:58:51 -0600216 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600217
218 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600219 std::vector<const char *> instance_layer_names;
220 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600221 std::vector<const char *> instance_extension_names;
222 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600223
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600224 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600225 /*
226 * Since CreateDbgMsgCallback is an instance level extension call
227 * any extension / layer that utilizes that feature also needs
228 * to be enabled at create instance time.
229 */
Chia-I Wu1f851912015-10-27 18:04:07 +0800230 // Use Threading layer first to protect others from ThreadCommandBufferCollision test
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600231 instance_layer_names.push_back("Threading");
232 instance_layer_names.push_back("ObjectTracker");
233 instance_layer_names.push_back("MemTracker");
234 instance_layer_names.push_back("DrawState");
235 instance_layer_names.push_back("ShaderChecker");
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600236 instance_layer_names.push_back("DeviceLimits");
Tobin Ehlis342b9bf2015-09-22 10:11:37 -0600237 instance_layer_names.push_back("Image");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600238
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600239 device_layer_names.push_back("Threading");
240 device_layer_names.push_back("ObjectTracker");
241 device_layer_names.push_back("MemTracker");
242 device_layer_names.push_back("DrawState");
243 device_layer_names.push_back("ShaderChecker");
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600244 device_layer_names.push_back("DeviceLimits");
Tobin Ehlis342b9bf2015-09-22 10:11:37 -0600245 device_layer_names.push_back("Image");
Tony Barbour30486ea2015-04-07 13:44:53 -0600246
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600247 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600248 this->app_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +0800249 this->app_info.pApplicationName = "layer_tests";
250 this->app_info.applicationVersion = 1;
Tony Barbour30486ea2015-04-07 13:44:53 -0600251 this->app_info.pEngineName = "unittest";
252 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600253 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600254
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600255 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600256 InitFramework(instance_layer_names, device_layer_names,
257 instance_extension_names, device_extension_names,
258 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600259 }
260
261 virtual void TearDown() {
262 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600263 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600264 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600265 }
266};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500267
Chia-I Wu1f851912015-10-27 18:04:07 +0800268VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600269{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600270 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600271
Chia-I Wu1f851912015-10-27 18:04:07 +0800272 result = commandBuffer.BeginCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600273
274 /*
275 * For render test all drawing happens in a single render pass
276 * on a single command buffer.
277 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200278 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800279 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600280 }
281
282 return result;
283}
284
Chia-I Wu1f851912015-10-27 18:04:07 +0800285VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600286{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600287 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600288
Chris Forbesfe133ef2015-06-16 14:05:59 +1200289 if (renderPass()) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800290 commandBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200291 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600292
Chia-I Wu1f851912015-10-27 18:04:07 +0800293 result = commandBuffer.EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600294
295 return result;
296}
297
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500298void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
299{
300 // Create identity matrix
301 int i;
302 struct vktriangle_vs_uniform data;
303
304 glm::mat4 Projection = glm::mat4(1.0f);
305 glm::mat4 View = glm::mat4(1.0f);
306 glm::mat4 Model = glm::mat4(1.0f);
307 glm::mat4 MVP = Projection * View * Model;
308 const int matrixSize = sizeof(MVP);
309 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
310
311 memcpy(&data.mvp, &MVP[0][0], matrixSize);
312
313 static const Vertex tri_data[] =
314 {
315 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
316 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
317 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
318 };
319
320 for (i=0; i<3; i++) {
321 data.position[i][0] = tri_data[i].posX;
322 data.position[i][1] = tri_data[i].posY;
323 data.position[i][2] = tri_data[i].posZ;
324 data.position[i][3] = tri_data[i].posW;
325 data.color[i][0] = tri_data[i].r;
326 data.color[i][1] = tri_data[i].g;
327 data.color[i][2] = tri_data[i].b;
328 data.color[i][3] = tri_data[i].a;
329 }
330
331 ASSERT_NO_FATAL_FAILURE(InitState());
332 ASSERT_NO_FATAL_FAILURE(InitViewport());
333
334 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
335
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600336 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
337 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500338
339 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800340 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500341 pipelineobj.AddShader(&vs);
342 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600343 if (failMask & BsoFailLineWidth) {
344 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
345 }
346 if (failMask & BsoFailDepthBias) {
347 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
348 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600349 // Viewport and scissors must stay in synch or other errors will occur than the ones we want
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600350 if (failMask & BsoFailViewport) {
351 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600352 m_viewports.clear();
353 m_scissors.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600354 }
355 if (failMask & BsoFailScissor) {
356 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600357 m_scissors.clear();
358 m_viewports.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600359 }
360 if (failMask & BsoFailBlend) {
361 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
362 }
363 if (failMask & BsoFailDepthBounds) {
364 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
365 }
366 if (failMask & BsoFailStencilReadMask) {
367 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
368 }
369 if (failMask & BsoFailStencilWriteMask) {
370 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
371 }
372 if (failMask & BsoFailStencilReference) {
373 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
374 }
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500375
376 VkDescriptorSetObj descriptorSet(m_device);
377 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
378
379 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600380 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500381
Tony Barbour1490c912015-07-28 10:17:20 -0600382 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500383
384 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600385 Draw(3, 1, 0, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500386
387 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600388 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500389
Tony Barbour1490c912015-07-28 10:17:20 -0600390 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500391}
392
Chia-I Wu1f851912015-10-27 18:04:07 +0800393void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500394{
395 if (m_depthStencil->Initialized()) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800396 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500397 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +0800398 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500399 }
400
Chia-I Wu1f851912015-10-27 18:04:07 +0800401 commandBuffer->PrepareAttachments();
Cody Northrop2605cb02015-08-18 15:21:16 -0600402 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
403 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600404 VkStencilOpState stencil = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +0800405 stencil.failOp = VK_STENCIL_OP_KEEP;
406 stencil.passOp = VK_STENCIL_OP_KEEP;
407 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
408 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600409
410 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
411 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600412 ds_ci.pNext = NULL;
413 ds_ci.depthTestEnable = VK_FALSE;
414 ds_ci.depthWriteEnable = VK_TRUE;
415 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
416 ds_ci.depthBoundsTestEnable = VK_FALSE;
417 ds_ci.stencilTestEnable = VK_TRUE;
418 ds_ci.front = stencil;
419 ds_ci.back = stencil;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600420
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600421 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600422 pipelineobj.SetViewport(m_viewports);
423 pipelineobj.SetScissor(m_scissors);
Chia-I Wu1f851912015-10-27 18:04:07 +0800424 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600425 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
426 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +0800427 commandBuffer->BindPipeline(pipelineobj);
428 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500429}
430
431// ********************************************************************************************************************
432// ********************************************************************************************************************
433// ********************************************************************************************************************
434// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600435#if MEM_TRACKER_TESTS
Chia-I Wu1f851912015-10-27 18:04:07 +0800436TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinski81078192015-05-19 10:28:29 -0500437{
438 vk_testing::Fence testFence;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500439 VkFenceCreateInfo fenceInfo = {};
440 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
441 fenceInfo.pNext = NULL;
442 fenceInfo.flags = 0;
443
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600444 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Resetting CB");
445
Mark Lobodzinski81078192015-05-19 10:28:29 -0500446 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600447
448 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
449 vk_testing::Buffer buffer;
450 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500451
Tony Barbour1490c912015-07-28 10:17:20 -0600452 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800453 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbour1490c912015-07-28 10:17:20 -0600454 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500455
456 testFence.init(*m_device, fenceInfo);
457
458 // Bypass framework since it does the waits automatically
459 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600460 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800461 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
462 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800463 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600464 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800465 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800466 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800467 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600468 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600469
470 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500471 ASSERT_VK_SUCCESS( err );
472
Mark Lobodzinski81078192015-05-19 10:28:29 -0500473 // Introduce failure by calling begin again before checking fence
Chia-I Wu1f851912015-10-27 18:04:07 +0800474 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500475
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600476 if (!m_errorMonitor->DesiredMsgFound()) {
477 FAIL() << "Did not receive Error 'Resetting CB (0xaddress) before it has completed. You must check CB flag before.'";
478 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500479 }
480}
481
Chia-I Wu1f851912015-10-27 18:04:07 +0800482TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinski81078192015-05-19 10:28:29 -0500483{
484 vk_testing::Fence testFence;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500485 VkFenceCreateInfo fenceInfo = {};
486 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
487 fenceInfo.pNext = NULL;
488 fenceInfo.flags = 0;
489
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600490 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Calling vkBeginCommandBuffer() on active CB");
491
Mark Lobodzinski81078192015-05-19 10:28:29 -0500492 ASSERT_NO_FATAL_FAILURE(InitState());
493 ASSERT_NO_FATAL_FAILURE(InitViewport());
494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
495
Tony Barbour1490c912015-07-28 10:17:20 -0600496 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800497 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -0600498 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500499
500 testFence.init(*m_device, fenceInfo);
501
502 // Bypass framework since it does the waits automatically
503 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600504 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800505 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
506 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800507 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600508 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800509 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800510 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800511 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600512 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600513
514 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500515 ASSERT_VK_SUCCESS( err );
516
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600517
Chia-I Wu1f851912015-10-27 18:04:07 +0800518 VkCommandBufferBeginInfo info = {};
519 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
520 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600521 info.renderPass = VK_NULL_HANDLE;
522 info.subpass = 0;
523 info.framebuffer = VK_NULL_HANDLE;
524
525 // Introduce failure by calling BCB again before checking fence
Chia-I Wu1f851912015-10-27 18:04:07 +0800526 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500527
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600528 if (!m_errorMonitor->DesiredMsgFound()) {
529 FAIL() << "Did not receive Error 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
530 m_errorMonitor->DumpFailureMsgs();
531
Mark Lobodzinski81078192015-05-19 10:28:29 -0500532 }
533}
534
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500535TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
536{
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500537 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600538 bool pass;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500539
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600540 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
541 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
542
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500543 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500544
545 // Create an image, allocate memory, free it, and then try to bind it
546 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500547 VkDeviceMemory mem;
548 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500549
550 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
551 const int32_t tex_width = 32;
552 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500553
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600554 VkImageCreateInfo image_create_info = {};
555 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
556 image_create_info.pNext = NULL;
557 image_create_info.imageType = VK_IMAGE_TYPE_2D;
558 image_create_info.format = tex_format;
559 image_create_info.extent.width = tex_width;
560 image_create_info.extent.height = tex_height;
561 image_create_info.extent.depth = 1;
562 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600563 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800564 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600565 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
566 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
567 image_create_info.flags = 0;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600568
Chia-I Wu1f851912015-10-27 18:04:07 +0800569 VkMemoryAllocateInfo mem_alloc = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600570 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
571 mem_alloc.pNext = NULL;
572 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500573 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600574 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500575
Chia-I Wu69f40122015-10-26 21:10:41 +0800576 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500577 ASSERT_VK_SUCCESS(err);
578
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600579 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500580 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500581 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500582
Mark Lobodzinski23182612015-05-29 09:32:35 -0500583 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500584
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600585 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
586 if(!pass) { // If we can't find any unmappable memory this test doesn't make sense
Chia-I Wu69f40122015-10-26 21:10:41 +0800587 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour49a3b652015-08-04 16:13:01 -0600588 return;
Mike Stroyan2237f522015-08-18 14:40:24 -0600589 }
Mike Stroyand72da752015-08-04 10:49:29 -0600590
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500591 // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +0800592 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500593 ASSERT_VK_SUCCESS(err);
594
595 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600596 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500597 ASSERT_VK_SUCCESS(err);
598
599 // Map memory as if to initialize the image
600 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500601 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500602
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600603 if (!m_errorMonitor->DesiredMsgFound()) {
604 FAIL() << "Did not receive Error 'Error received did not match expected error message from vkMapMemory in MemTracker'";
605 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500606 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600607
Chia-I Wu69f40122015-10-26 21:10:41 +0800608 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500609}
610
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600611// TODO : Is this test still valid. Not sure it is with updates to memory binding model
612// Verify and delete the test of fix the check
613//TEST_F(VkLayerTest, FreeBoundMemory)
614//{
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600615// VkResult err;
616//
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600617// m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
618// "Freeing memory object while it still has references");
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600619//
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600620// ASSERT_NO_FATAL_FAILURE(InitState());
621
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600622// // Create an image, allocate memory, free it, and then try to bind it
623// VkImage image;
624// VkDeviceMemory mem;
625// VkMemoryRequirements mem_reqs;
626//
627// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
628// const int32_t tex_width = 32;
629// const int32_t tex_height = 32;
630//
631// const VkImageCreateInfo image_create_info = {
632// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
633// .pNext = NULL,
634// .imageType = VK_IMAGE_TYPE_2D,
635// .format = tex_format,
636// .extent = { tex_width, tex_height, 1 },
637// .mipLevels = 1,
638// .arraySize = 1,
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800639// .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600640// .tiling = VK_IMAGE_TILING_LINEAR,
641// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
642// .flags = 0,
643// };
Chia-I Wu1f851912015-10-27 18:04:07 +0800644// VkMemoryAllocateInfo mem_alloc = {
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600645// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
646// .pNext = NULL,
647// .allocationSize = 0,
648// .memoryTypeIndex = 0,
649// };
650//
Chia-I Wu69f40122015-10-26 21:10:41 +0800651// err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600652// ASSERT_VK_SUCCESS(err);
653//
654// err = vkGetImageMemoryRequirements(m_device->device(),
655// image,
656// &mem_reqs);
657// ASSERT_VK_SUCCESS(err);
658//
659// mem_alloc.allocationSize = mem_reqs.size;
660//
661// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
662// ASSERT_VK_SUCCESS(err);
663//
664// // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +0800665// err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600666// ASSERT_VK_SUCCESS(err);
667//
668// // Bind memory to Image object
669// err = vkBindImageMemory(m_device->device(), image, mem, 0);
670// ASSERT_VK_SUCCESS(err);
671//
672// // Introduce validation failure, free memory while still bound to object
Chia-I Wu69f40122015-10-26 21:10:41 +0800673// vkFreeMemory(m_device->device(), mem, NULL);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600674//
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600675// if (!m_errorMonitor->DesiredMsgFound()) {
676// FAIL() << "Did not receive Warning 'Freeing memory object while it still has references'");
677// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600678// }
679//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500680
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500681TEST_F(VkLayerTest, RebindMemory)
682{
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500683 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600684 bool pass;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500685
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600686 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
687 "which has already been bound to mem object");
688
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500689 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500690
691 // Create an image, allocate memory, free it, and then try to bind it
692 VkImage image;
693 VkDeviceMemory mem1;
694 VkDeviceMemory mem2;
695 VkMemoryRequirements mem_reqs;
696
697 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
698 const int32_t tex_width = 32;
699 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500700
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600701 VkImageCreateInfo image_create_info = {};
702 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
703 image_create_info.pNext = NULL;
704 image_create_info.imageType = VK_IMAGE_TYPE_2D;
705 image_create_info.format = tex_format;
706 image_create_info.extent.width = tex_width;
707 image_create_info.extent.height = tex_height;
708 image_create_info.extent.depth = 1;
709 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600710 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800711 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600712 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
713 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
714 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500715
Chia-I Wu1f851912015-10-27 18:04:07 +0800716 VkMemoryAllocateInfo mem_alloc = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600717 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
718 mem_alloc.pNext = NULL;
719 mem_alloc.allocationSize = 0;
720 mem_alloc.memoryTypeIndex = 0;
721
722 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
723 mem_alloc.memoryTypeIndex = 1;
Chia-I Wu69f40122015-10-26 21:10:41 +0800724 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500725 ASSERT_VK_SUCCESS(err);
726
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600727 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500728 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500729 &mem_reqs);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500730
731 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600732 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
733 ASSERT_TRUE(pass);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500734
735 // allocate 2 memory objects
Chia-I Wu1f851912015-10-27 18:04:07 +0800736 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500737 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +0800738 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500739 ASSERT_VK_SUCCESS(err);
740
741 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600742 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500743 ASSERT_VK_SUCCESS(err);
744
745 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600746 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500747
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600748 if (!m_errorMonitor->DesiredMsgFound()) {
749 FAIL() << "Did not receive Error when rebinding memory to an object";
750 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500751 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600752
Chia-I Wu69f40122015-10-26 21:10:41 +0800753 vkDestroyImage(m_device->device(), image, NULL);
754 vkFreeMemory(m_device->device(), mem1, NULL);
755 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500756}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500757
Tony Barbour8508b8e2015-04-09 10:48:04 -0600758TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600759{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600760 vk_testing::Fence testFence;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600761
762 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
763 "submitted in SIGNALED state. Fences must be reset before being submitted");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600764
765 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600766 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
767 fenceInfo.pNext = NULL;
768 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600769
Tony Barbour30486ea2015-04-07 13:44:53 -0600770 ASSERT_NO_FATAL_FAILURE(InitState());
771 ASSERT_NO_FATAL_FAILURE(InitViewport());
772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
773
Tony Barbour1490c912015-07-28 10:17:20 -0600774 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800775 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -0600776 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600777
778 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600779
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600780 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800781 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
782 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800783 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600784 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800785 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800786 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800787 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600788 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600789
790 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600791 vkQueueWaitIdle(m_device->m_queue );
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600792
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600793 if (!m_errorMonitor->DesiredMsgFound()) {
794 FAIL() << "Did not receive Error 'VkQueueSubmit with fence in SIGNALED_STATE'";
795 m_errorMonitor->DumpFailureMsgs();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600796 }
Tony Barbour8508b8e2015-04-09 10:48:04 -0600797}
798
799TEST_F(VkLayerTest, ResetUnsignaledFence)
800{
801 vk_testing::Fence testFence;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600802 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600803 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
804 fenceInfo.pNext = NULL;
805
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600806 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
807 "submitted to VkResetFences in UNSIGNALED STATE");
808
Tony Barbour8508b8e2015-04-09 10:48:04 -0600809 ASSERT_NO_FATAL_FAILURE(InitState());
810 testFence.init(*m_device, fenceInfo);
Chia-I Wua4992342015-07-03 11:45:55 +0800811 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600812 vkResetFences(m_device->device(), 1, fences);
Tony Barbour30486ea2015-04-07 13:44:53 -0600813
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600814 if (!m_errorMonitor->DesiredMsgFound()) {
815 FAIL() << "Did not receive Error 'VkResetFences with fence in UNSIGNALED_STATE'";
816 m_errorMonitor->DumpFailureMsgs();
817 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600818}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600819
Chia-I Wuc278df82015-07-07 11:50:03 +0800820/* TODO: Update for changes due to bug-14075 tiling across render passes */
821#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600822TEST_F(VkLayerTest, InvalidUsageBits)
823{
824 // Initiate Draw w/o a PSO bound
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600825
826 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
827 "Invalid usage flag for image ");
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600828
829 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +0800830 VkCommandBufferObj commandBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600831 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600832
833 const VkExtent3D e3d = {
834 .width = 128,
835 .height = 128,
836 .depth = 1,
837 };
838 const VkImageCreateInfo ici = {
839 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
840 .pNext = NULL,
841 .imageType = VK_IMAGE_TYPE_2D,
842 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
843 .extent = e3d,
844 .mipLevels = 1,
845 .arraySize = 1,
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800846 .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600847 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchterc3b8eea2015-09-10 14:14:11 -0600848 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600849 .flags = 0,
850 };
851
852 VkImage dsi;
Chia-I Wu69f40122015-10-26 21:10:41 +0800853 vkCreateImage(m_device->device(), &ici, NULL, &dsi);
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600854 VkDepthStencilView dsv;
855 const VkDepthStencilViewCreateInfo dsvci = {
856 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
857 .pNext = NULL,
858 .image = dsi,
859 .mipLevel = 0,
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -0600860 .baseArrayLayer = 0,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600861 .arraySize = 1,
862 .flags = 0,
863 };
Chia-I Wu69f40122015-10-26 21:10:41 +0800864 vkCreateDepthStencilView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600865
866 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600867 FAIL() << "Error received was not 'Invalid usage flag for image...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600868 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600869 }
870}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600871#endif // 0
872#endif // MEM_TRACKER_TESTS
873
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600874#if OBJ_TRACKER_TESTS
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600875TEST_F(VkLayerTest, PipelineNotBound)
876{
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600877 VkResult err;
878
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600879 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
880 "Invalid VkPipeline Object ");
881
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600882 ASSERT_NO_FATAL_FAILURE(InitState());
883 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600884
Chia-I Wuc51b1212015-10-27 19:25:11 +0800885 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600886 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +0800887 ds_type_count.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600888
889 VkDescriptorPoolCreateInfo ds_pool_ci = {};
890 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
891 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600892 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +0800893 ds_pool_ci.poolSizeCount = 1;
894 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600895
896 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +0800897 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600898 ASSERT_VK_SUCCESS(err);
899
900 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +0800901 dsl_binding.binding = 0;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600902 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
903 dsl_binding.arraySize = 1;
904 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
905 dsl_binding.pImmutableSamplers = NULL;
906
907 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
908 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
909 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800910 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +0800911 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600912
913 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +0800914 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600915 ASSERT_VK_SUCCESS(err);
916
917 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +0800918 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -0600919 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +0800920 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -0600921 alloc_info.descriptorPool = ds_pool;
922 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +0800923 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600924 ASSERT_VK_SUCCESS(err);
925
926 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
927 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
928 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800929 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600930 pipeline_layout_ci.pSetLayouts = &ds_layout;
931
932 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +0800933 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600934 ASSERT_VK_SUCCESS(err);
935
936 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
937
938 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800939 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600940
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600941 if (!m_errorMonitor->DesiredMsgFound()) {
942 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be'" << endl;
943 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600944 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600945
Chia-I Wu69f40122015-10-26 21:10:41 +0800946 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
947 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
948 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600949}
950
951TEST_F(VkLayerTest, BindInvalidMemory)
952{
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600953 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600954 bool pass;
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600955
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600956 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
957 "Invalid VkDeviceMemory Object ");
958
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600959 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600960
961 // Create an image, allocate memory, free it, and then try to bind it
962 VkImage image;
963 VkDeviceMemory mem;
964 VkMemoryRequirements mem_reqs;
965
966 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
967 const int32_t tex_width = 32;
968 const int32_t tex_height = 32;
969
970 VkImageCreateInfo image_create_info = {};
971 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
972 image_create_info.pNext = NULL;
973 image_create_info.imageType = VK_IMAGE_TYPE_2D;
974 image_create_info.format = tex_format;
975 image_create_info.extent.width = tex_width;
976 image_create_info.extent.height = tex_height;
977 image_create_info.extent.depth = 1;
978 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600979 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800980 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600981 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
982 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
983 image_create_info.flags = 0;
984
Chia-I Wu1f851912015-10-27 18:04:07 +0800985 VkMemoryAllocateInfo mem_alloc = {};
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600986 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
987 mem_alloc.pNext = NULL;
988 mem_alloc.allocationSize = 0;
989 mem_alloc.memoryTypeIndex = 0;
990
Chia-I Wu69f40122015-10-26 21:10:41 +0800991 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600992 ASSERT_VK_SUCCESS(err);
993
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600994 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600995 image,
996 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600997
998 mem_alloc.allocationSize = mem_reqs.size;
999
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001000 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1001 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001002
1003 // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08001004 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001005 ASSERT_VK_SUCCESS(err);
1006
1007 // Introduce validation failure, free memory before binding
Chia-I Wu69f40122015-10-26 21:10:41 +08001008 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001009
1010 // Try to bind free memory that has been freed
1011 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1012 // This may very well return an error.
1013 (void)err;
1014
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001015 if (!m_errorMonitor->DesiredMsgFound()) {
1016 FAIL() << "Did not receive Error 'Invalid VkDeviceMemory Object 0x<handle>'";
1017 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001018 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001019
Chia-I Wu69f40122015-10-26 21:10:41 +08001020 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001021}
1022
1023TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
1024{
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001025 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001026 bool pass;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001027
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001028 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Invalid VkImage Object ");
1029
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001030 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001031
1032 // Create an image object, allocate memory, destroy the object and then try to bind it
1033 VkImage image;
1034 VkDeviceMemory mem;
1035 VkMemoryRequirements mem_reqs;
1036
1037 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1038 const int32_t tex_width = 32;
1039 const int32_t tex_height = 32;
1040
1041 VkImageCreateInfo image_create_info = {};
1042 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1043 image_create_info.pNext = NULL;
1044 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1045 image_create_info.format = tex_format;
1046 image_create_info.extent.width = tex_width;
1047 image_create_info.extent.height = tex_height;
1048 image_create_info.extent.depth = 1;
1049 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06001050 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001051 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001052 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1053 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1054 image_create_info.flags = 0;
1055
Chia-I Wu1f851912015-10-27 18:04:07 +08001056 VkMemoryAllocateInfo mem_alloc = {};
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001057 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1058 mem_alloc.pNext = NULL;
1059 mem_alloc.allocationSize = 0;
1060 mem_alloc.memoryTypeIndex = 0;
1061
Chia-I Wu69f40122015-10-26 21:10:41 +08001062 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001063 ASSERT_VK_SUCCESS(err);
1064
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06001065 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001066 image,
1067 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001068
1069 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001070 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1071 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001072
1073 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08001074 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001075 ASSERT_VK_SUCCESS(err);
1076
1077 // Introduce validation failure, destroy Image object before binding
Chia-I Wu69f40122015-10-26 21:10:41 +08001078 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001079 ASSERT_VK_SUCCESS(err);
1080
1081 // Now Try to bind memory to this destroyed object
1082 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1083 // This may very well return an error.
1084 (void) err;
1085
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001086 if (!m_errorMonitor->DesiredMsgFound()) {
1087 FAIL() << "Did not receive Error 'Invalid VkImage Object 0x<handle>'";
1088 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001089 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001090
Chia-I Wu69f40122015-10-26 21:10:41 +08001091 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001092}
Tobin Ehlisb46be812015-10-23 16:00:08 -06001093
1094TEST_F(VkLayerTest, InvalidBufferViewObject)
1095{
1096 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Tobin Ehlisb46be812015-10-23 16:00:08 -06001097 VkResult err;
1098
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001099 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1100 "Invalid VkBufferView Object 0xbaadbeef");
1101
Tobin Ehlisb46be812015-10-23 16:00:08 -06001102 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wuc51b1212015-10-27 19:25:11 +08001103 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06001104 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001105 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06001106
1107 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1108 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1109 ds_pool_ci.pNext = NULL;
1110 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001111 ds_pool_ci.poolSizeCount = 1;
1112 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06001113
1114 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001115 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001116 ASSERT_VK_SUCCESS(err);
1117
1118 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001119 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06001120 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1121 dsl_binding.arraySize = 1;
1122 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1123 dsl_binding.pImmutableSamplers = NULL;
1124
1125 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1126 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1127 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001128 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001129 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06001130 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001131 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001132 ASSERT_VK_SUCCESS(err);
1133
1134 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001135 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06001136 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001137 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06001138 alloc_info.descriptorPool = ds_pool;
1139 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001140 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001141 ASSERT_VK_SUCCESS(err);
1142
Chia-I Wue420a332015-10-26 20:04:44 +08001143 VkBufferView view = (VkBufferView) 0xbaadbeef; // invalid bufferView object
Tobin Ehlisb46be812015-10-23 16:00:08 -06001144
1145 VkWriteDescriptorSet descriptor_write;
1146 memset(&descriptor_write, 0, sizeof(descriptor_write));
1147 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08001148 descriptor_write.dstSet = descriptorSet;
1149 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08001150 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06001151 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1152 descriptor_write.pTexelBufferView = &view;
1153
1154 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1155
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001156 if (!m_errorMonitor->DesiredMsgFound()) {
1157 FAIL() << "Did nto receive Error 'Invalid VkBufferView Object 0xbaadbeef'";
1158 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06001159 }
1160
Chia-I Wu69f40122015-10-26 21:10:41 +08001161 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1162 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001163}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001164#endif // OBJ_TRACKER_TESTS
1165
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001166#if DRAW_STATE_TESTS
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001167TEST_F(VkLayerTest, LineWidthStateNotBound)
1168{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001169 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1170 "Dynamic line width state not set for this command buffer");
1171
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001172 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1173
1174 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1175
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001176 if (!m_errorMonitor->DesiredMsgFound()) {
1177 FAIL() << "Did not receive Error 'Dynamic line width state not set for this command buffer'";
1178 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001179 }
1180}
1181
1182TEST_F(VkLayerTest, DepthBiasStateNotBound)
1183{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001184 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1185 "Dynamic depth bias state not set for this command buffer");
1186
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001187 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1188
1189 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1190
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001191 if (!m_errorMonitor->DesiredMsgFound()) {
1192 FAIL() << "Did not receive Error 'Dynamic depth bias state not set for this command buffer'";
1193 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001194 }
1195}
1196
Cody Northropbca3bcd2015-10-27 16:54:28 -06001197// Disable these two tests until we can sort out how to track multiple layer errors
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001198TEST_F(VkLayerTest, ViewportStateNotBound)
1199{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001200 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1201 "Dynamic viewport state not set for this command buffer");
1202
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001203 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1204
1205 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1206
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001207 if (!m_errorMonitor->DesiredMsgFound()) {
1208 FAIL() << "Did not recieve Error 'Dynamic scissor state not set for this command buffer'";
1209 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001210 }
1211}
1212
1213TEST_F(VkLayerTest, ScissorStateNotBound)
1214{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001215 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1216 "Dynamic scissor state not set for this command buffer");
1217
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001218 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1219
1220 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1221
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001222 if (!m_errorMonitor->DesiredMsgFound()) {
1223 FAIL() << "Did not recieve Error ' Expected: 'Dynamic scissor state not set for this command buffer'";
1224 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001225 }
1226}
1227
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001228TEST_F(VkLayerTest, BlendStateNotBound)
1229{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001230 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1231 "Dynamic blend object state not set for this command buffer");
1232
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001233 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1234
1235 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1236
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001237 if (!m_errorMonitor->DesiredMsgFound()) {
1238 FAIL() << "Did not recieve Error 'Dynamic blend object state not set for this command buffer'";
1239 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001240 }
1241}
1242
1243TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1244{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001245 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1246 "Dynamic depth bounds state not set for this command buffer");
1247
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001248 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1249
1250 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1251
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001252 if (!m_errorMonitor->DesiredMsgFound()) {
1253 FAIL() << "Did not receive Error 'Dynamic depth bounds state not set for this command buffer'";
1254 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001255 }
1256}
1257
1258TEST_F(VkLayerTest, StencilReadMaskNotSet)
1259{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001260 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1261 "Dynamic stencil read mask state not set for this command buffer");
1262
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001263 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001264
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001265 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1266
1267 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1268
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001269 if (!m_errorMonitor->DesiredMsgFound()) {
1270 FAIL() << "Did not receive Error 'Dynamic stencil read mask state not set for this command buffer'";
1271 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001272 }
1273}
1274
1275TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1276{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001277 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1278 "Dynamic stencil write mask state not set for this command buffer");
1279
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001280 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001281
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001282 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1283
1284 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1285
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001286 if (!m_errorMonitor->DesiredMsgFound()) {
1287 FAIL() << "Did not receive Error 'Dynamic stencil write mask state not set for this command buffer'";
1288 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001289 }
1290}
1291
1292TEST_F(VkLayerTest, StencilReferenceNotSet)
1293{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001294 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1295 "Dynamic stencil reference state not set for this command buffer");
1296
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001297 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1298
1299 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1300
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001301 if (!m_errorMonitor->DesiredMsgFound()) {
1302 FAIL() << "Did not receive Error 'Dynamic stencil reference state not set for this command buffer'";
1303 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001304 }
1305}
1306
Chia-I Wu1f851912015-10-27 18:04:07 +08001307TEST_F(VkLayerTest, CommandBufferTwoSubmits)
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001308{
1309 vk_testing::Fence testFence;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001310
1311 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1312 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted");
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001313
1314 VkFenceCreateInfo fenceInfo = {};
1315 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1316 fenceInfo.pNext = NULL;
1317 fenceInfo.flags = 0;
1318
1319 ASSERT_NO_FATAL_FAILURE(InitState());
1320 ASSERT_NO_FATAL_FAILURE(InitViewport());
1321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1322
Chia-I Wu1f851912015-10-27 18:04:07 +08001323 // We luck out b/c by default the framework creates CB w/ the VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001324 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08001325 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001326 EndCommandBuffer();
1327
1328 testFence.init(*m_device, fenceInfo);
1329
1330 // Bypass framework since it does the waits automatically
1331 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001332 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +08001333 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1334 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001335 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001336 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001337 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08001338 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +08001339 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001340 submit_info.pSignalSemaphores = NULL;
1341
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001342 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001343 ASSERT_VK_SUCCESS( err );
1344
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001345 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001346 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001347
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001348 if (!m_errorMonitor->DesiredMsgFound()) {
1349 FAIL() << "Did not receive Error 'CB (0xaddress) was created w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
1350 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001351 }
1352}
1353
Tobin Ehlise4076782015-06-24 15:53:07 -06001354TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001355{
1356 // Initiate Draw w/o a PSO bound
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001357 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001358
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001359 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1360 "Incorrectly binding graphics pipeline ");
1361
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001362 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001363 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001364
Chia-I Wuc51b1212015-10-27 19:25:11 +08001365 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001366 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001367 ds_type_count.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001368
1369 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1370 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1371 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001372 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001373 ds_pool_ci.poolSizeCount = 1;
1374 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001375
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001376 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001377 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001378 ASSERT_VK_SUCCESS(err);
1379
1380 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001381 dsl_binding.binding = 0;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001382 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1383 dsl_binding.arraySize = 1;
1384 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1385 dsl_binding.pImmutableSamplers = NULL;
1386
1387 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1388 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1389 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001390 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001391 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001392
1393 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001394 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001395 ASSERT_VK_SUCCESS(err);
1396
1397 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001398 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001399 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001400 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001401 alloc_info.descriptorPool = ds_pool;
1402 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001403 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001404 ASSERT_VK_SUCCESS(err);
1405 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1406 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1407 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001408 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001409 pipe_ms_state_ci.sampleShadingEnable = 0;
1410 pipe_ms_state_ci.minSampleShading = 1.0;
1411 pipe_ms_state_ci.pSampleMask = NULL;
1412
1413 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1414 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1415 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001416 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001417 pipeline_layout_ci.pSetLayouts = &ds_layout;
1418 VkPipelineLayout pipeline_layout;
1419
Chia-I Wu69f40122015-10-26 21:10:41 +08001420 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001421 ASSERT_VK_SUCCESS(err);
1422
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001423 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1424 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 -06001425 // but add it to be able to run on more devices
1426 VkPipelineObj pipe(m_device);
1427 pipe.AddShader(&vs);
1428 pipe.AddShader(&fs);
1429 pipe.SetMSAA(&pipe_ms_state_ci);
1430 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001431
Chia-I Wu1f851912015-10-27 18:04:07 +08001432 // Calls AllocateCommandBuffers
1433 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
1434 VkCommandBufferBeginInfo cmd_buf_info = {};
1435 memset(&cmd_buf_info, 0, sizeof(VkCommandBufferBeginInfo));
1436 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001437 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001438 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001439
Chia-I Wu1f851912015-10-27 18:04:07 +08001440 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
1441 vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001442
1443 if (!m_errorMonitor->DesiredMsgFound()) {
1444 FAIL() << "Did not receive Error 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass'";
1445 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001446 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001447
Chia-I Wu69f40122015-10-26 21:10:41 +08001448 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1449 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1450 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001451}
1452
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001453TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1454{
1455 // Initiate Draw w/o a PSO bound
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001456 VkResult err;
1457
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001458 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1459 "Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
1460
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001461 ASSERT_NO_FATAL_FAILURE(InitState());
1462 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001463
1464 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
Chia-I Wuc51b1212015-10-27 19:25:11 +08001465 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001466 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001467 ds_type_count.descriptorCount = 1;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001468
1469 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1470 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1471 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001472 ds_pool_ci.flags = 0;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001473 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001474 ds_pool_ci.poolSizeCount = 1;
1475 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001476
1477 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001478 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001479 ASSERT_VK_SUCCESS(err);
1480
1481 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001482 dsl_binding.binding = 0;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001483 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1484 dsl_binding.arraySize = 1;
1485 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1486 dsl_binding.pImmutableSamplers = NULL;
1487
1488 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1489 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1490 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001491 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001492 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001493
1494 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001495 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001496 ASSERT_VK_SUCCESS(err);
1497
1498 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001499 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001500 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001501 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001502 alloc_info.descriptorPool = ds_pool;
1503 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001504 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001505
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001506 if (!m_errorMonitor->DesiredMsgFound()) {
1507 FAIL() << "Did not receive Error 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...'";
1508 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001509 }
1510
Chia-I Wu69f40122015-10-26 21:10:41 +08001511 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1512 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001513}
1514
Tobin Ehlis3c543112015-10-08 13:13:50 -06001515TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1516{
Tobin Ehlis3c543112015-10-08 13:13:50 -06001517 VkResult err;
1518
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001519 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1520 "It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
1521
Tobin Ehlis3c543112015-10-08 13:13:50 -06001522 ASSERT_NO_FATAL_FAILURE(InitState());
1523 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis3c543112015-10-08 13:13:50 -06001524
Chia-I Wuc51b1212015-10-27 19:25:11 +08001525 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis3c543112015-10-08 13:13:50 -06001526 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001527 ds_type_count.descriptorCount = 1;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001528
1529 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1530 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1531 ds_pool_ci.pNext = NULL;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001532 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001533 ds_pool_ci.poolSizeCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001534 ds_pool_ci.flags = 0;
1535 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1536 // app can only call vkResetDescriptorPool on this pool.;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001537 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001538
1539 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001540 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001541 ASSERT_VK_SUCCESS(err);
1542
1543 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001544 dsl_binding.binding = 0;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001545 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1546 dsl_binding.arraySize = 1;
1547 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1548 dsl_binding.pImmutableSamplers = NULL;
1549
1550 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1551 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1552 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001553 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001554 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001555
1556 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001557 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001558 ASSERT_VK_SUCCESS(err);
1559
1560 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001561 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001562 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001563 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001564 alloc_info.descriptorPool = ds_pool;
1565 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001566 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001567 ASSERT_VK_SUCCESS(err);
1568
1569 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001570 if (!m_errorMonitor->DesiredMsgFound()) {
1571 FAIL() << "Did not receive Error 'It is invalid to call vkFreeDescriptorSets() with a pool created with...'";
1572 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3c543112015-10-08 13:13:50 -06001573 }
1574
Chia-I Wu69f40122015-10-26 21:10:41 +08001575 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1576 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001577}
1578
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001579TEST_F(VkLayerTest, InvalidDescriptorPool)
1580{
1581 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1582 // The DS check for this is after driver has been called to validate DS internal data struct
1583 // Attempt to clear DS Pool with bad object
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001584/*
1585 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1586 "Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call");
1587
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001588 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1589 vkResetDescriptorPool(device(), badPool);
1590
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001591 if (!m_errorMonitor->DesiredMsgFound()) {
1592 FAIL() << "Did not receive Error 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1593 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001594 }*/
1595}
1596
1597TEST_F(VkLayerTest, InvalidDescriptorSet)
1598{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001599 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1600 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001601 // Create a valid cmd buffer
1602 // call vkCmdBindDescriptorSets w/ false DS
1603}
1604
1605TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1606{
1607 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1608 // The DS check for this is after driver has been called to validate DS internal data struct
1609}
1610
1611TEST_F(VkLayerTest, InvalidPipeline)
1612{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001613 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1614 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001615 // Create a valid cmd buffer
1616 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001617//
1618// m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1619// "Attempt to bind Pipeline ");
Tobin Ehlise4076782015-06-24 15:53:07 -06001620//
1621// ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +08001622// VkCommandBufferObj commandBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001623// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001624// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Chia-I Wu1f851912015-10-27 18:04:07 +08001625// vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001626//
1627// if (!m_errorMonitor->DesiredMsgFound()) {
1628// FAIL() << "Did not receive Error 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1629// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -06001630// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001631}
1632
Tobin Ehlis254eca02015-06-25 15:46:59 -06001633TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001634{
Chia-I Wu1f851912015-10-27 18:04:07 +08001635 // Create and update CommandBuffer then call QueueSubmit w/o calling End on CommandBuffer
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001636 VkResult err;
1637
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001638 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
1639 " bound but it was never updated. ");
1640
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001641 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001642 ASSERT_NO_FATAL_FAILURE(InitViewport());
1643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08001644 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001645 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001646 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001647
1648 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1649 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1650 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001651 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001652 ds_pool_ci.poolSizeCount = 1;
1653 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001654
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001655 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001656 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001657 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001658
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001659 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001660 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001661 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1662 dsl_binding.arraySize = 1;
1663 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1664 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001665
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001666 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1667 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1668 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001669 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001670 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001671 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001672 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001673 ASSERT_VK_SUCCESS(err);
1674
1675 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001676 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001677 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001678 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001679 alloc_info.descriptorPool = ds_pool;
1680 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001681 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001682 ASSERT_VK_SUCCESS(err);
1683
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001684 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1685 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1686 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001687 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001688 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001689
1690 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001691 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001692 ASSERT_VK_SUCCESS(err);
1693
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001694 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001695 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
1696 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001697
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001698 VkPipelineObj pipe(m_device);
1699 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001700 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001701 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001702
1703 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08001704 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1705 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001706
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001707 if (!m_errorMonitor->DesiredMsgFound()) {
1708 FAIL() << "Did not recieve Warning 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1709 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001710 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001711
Chia-I Wu69f40122015-10-26 21:10:41 +08001712 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1713 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1714 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001715}
1716
Chia-I Wu1f851912015-10-27 18:04:07 +08001717TEST_F(VkLayerTest, NoBeginCommandBuffer)
Tobin Ehlis254eca02015-06-25 15:46:59 -06001718{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001719
1720 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1721 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlis254eca02015-06-25 15:46:59 -06001722
1723 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +08001724 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001725 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu1f851912015-10-27 18:04:07 +08001726 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001727
1728 if (!m_errorMonitor->DesiredMsgFound()) {
1729 FAIL() << "Did not recieve Error 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1730 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001731 }
1732}
1733
Chia-I Wu1f851912015-10-27 18:04:07 +08001734TEST_F(VkLayerTest, PrimaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001735{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001736
1737 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1738 "may not specify framebuffer or renderpass parameters");
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001739
1740 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001741
Chia-I Wu1f851912015-10-27 18:04:07 +08001742 // Calls AllocateCommandBuffers
1743 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001744
1745 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Chia-I Wu1f851912015-10-27 18:04:07 +08001746 VkCommandBufferBeginInfo cmd_buf_info = {};
1747 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06001748 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001749 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northrop10d8f982015-08-04 17:35:57 -06001750 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1751 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1752
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001753
1754 // The error should be caught by validation of the BeginCommandBuffer call
Chia-I Wu1f851912015-10-27 18:04:07 +08001755 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001756
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001757 if (!m_errorMonitor->DesiredMsgFound()) {
1758 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1759 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001760 }
1761}
1762
Chia-I Wu1f851912015-10-27 18:04:07 +08001763TEST_F(VkLayerTest, SecondaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001764{
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001765 VkResult err;
Chia-I Wu1f851912015-10-27 18:04:07 +08001766 VkCommandBuffer draw_cmd;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001767
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001768 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1769 "must specify framebuffer and renderpass parameters");
1770
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001771 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001772
Chia-I Wu1f851912015-10-27 18:04:07 +08001773 VkCommandBufferAllocateInfo cmd = {};
1774 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOC_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06001775 cmd.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001776 cmd.commandPool = m_commandPool;
1777 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Chia-I Wu763a7492015-10-26 20:48:51 +08001778 cmd.bufferCount = 1;
Cody Northrop10d8f982015-08-04 17:35:57 -06001779
Chia-I Wu1f851912015-10-27 18:04:07 +08001780 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06001781 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001782
1783 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu1f851912015-10-27 18:04:07 +08001784 VkCommandBufferBeginInfo cmd_buf_info = {};
1785 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06001786 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001787 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001788
1789 // The error should be caught by validation of the BeginCommandBuffer call
1790 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1791
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001792 if (!m_errorMonitor->DesiredMsgFound()) {
1793 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1794 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001795 }
Chia-I Wu1f851912015-10-27 18:04:07 +08001796 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001797}
1798
Tobin Ehlis254eca02015-06-25 15:46:59 -06001799TEST_F(VkLayerTest, InvalidPipelineCreateState)
1800{
1801 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis254eca02015-06-25 15:46:59 -06001802 VkResult err;
1803
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001804 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1805 "Invalid Pipeline CreateInfo State: Vtx Shader required");
1806
Tobin Ehlis254eca02015-06-25 15:46:59 -06001807 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001808 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001809
Chia-I Wuc51b1212015-10-27 19:25:11 +08001810 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001811 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001812 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001813
1814 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1815 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1816 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001817 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001818 ds_pool_ci.poolSizeCount = 1;
1819 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001820
Tobin Ehlis254eca02015-06-25 15:46:59 -06001821 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001822 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001823 ASSERT_VK_SUCCESS(err);
1824
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001825 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001826 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001827 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1828 dsl_binding.arraySize = 1;
1829 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1830 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001831
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001832 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1833 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1834 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001835 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001836 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001837
Tobin Ehlis254eca02015-06-25 15:46:59 -06001838 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001839 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001840 ASSERT_VK_SUCCESS(err);
1841
1842 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001843 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001844 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001845 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001846 alloc_info.descriptorPool = ds_pool;
1847 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001848 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001849 ASSERT_VK_SUCCESS(err);
1850
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001851 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1852 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001853 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001854 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001855
1856 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001857 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001858 ASSERT_VK_SUCCESS(err);
1859
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001860 VkViewport vp = {}; // Just need dummy vp to point to
1861 VkRect2D sc = {}; // dummy scissor to point to
1862
1863 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1864 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1865 vp_state_ci.scissorCount = 1;
1866 vp_state_ci.pScissors = &sc;
1867 vp_state_ci.viewportCount = 1;
1868 vp_state_ci.pViewports = &vp;
1869
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001870 VkGraphicsPipelineCreateInfo gp_ci = {};
1871 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001872 gp_ci.pViewportState = &vp_state_ci;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001873 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1874 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001875 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001876
1877 VkPipelineCacheCreateInfo pc_ci = {};
1878 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Chia-I Wu7e470702015-10-26 17:24:52 +08001879 pc_ci.initialDataSize = 0;
1880 pc_ci.pInitialData = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001881
1882 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001883 VkPipelineCache pipelineCache;
1884
Chia-I Wu69f40122015-10-26 21:10:41 +08001885 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001886 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08001887 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001888
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001889 if (!m_errorMonitor->DesiredMsgFound()) {
1890 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1891 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001892 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001893
Chia-I Wu69f40122015-10-26 21:10:41 +08001894 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
1895 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1896 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1897 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001898}
Tobin Ehlis20693172015-09-17 08:46:18 -06001899/*// TODO : This test should be good, but needs Tess support in compiler to run
1900TEST_F(VkLayerTest, InvalidPatchControlPoints)
1901{
1902 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis20693172015-09-17 08:46:18 -06001903 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001904
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001905 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1906 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ");
1907
Tobin Ehlis20693172015-09-17 08:46:18 -06001908 ASSERT_NO_FATAL_FAILURE(InitState());
1909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis20693172015-09-17 08:46:18 -06001910
Chia-I Wuc51b1212015-10-27 19:25:11 +08001911 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis20693172015-09-17 08:46:18 -06001912 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001913 ds_type_count.descriptorCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06001914
1915 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1916 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1917 ds_pool_ci.pNext = NULL;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001918 ds_pool_ci.poolSizeCount = 1;
1919 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis20693172015-09-17 08:46:18 -06001920
1921 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001922 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis20693172015-09-17 08:46:18 -06001923 ASSERT_VK_SUCCESS(err);
1924
1925 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001926 dsl_binding.binding = 0;
Tobin Ehlis20693172015-09-17 08:46:18 -06001927 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1928 dsl_binding.arraySize = 1;
1929 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1930 dsl_binding.pImmutableSamplers = NULL;
1931
1932 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1933 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1934 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001935 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001936 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis20693172015-09-17 08:46:18 -06001937
1938 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001939 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06001940 ASSERT_VK_SUCCESS(err);
1941
1942 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001943 err = vkAllocateDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis20693172015-09-17 08:46:18 -06001944 ASSERT_VK_SUCCESS(err);
1945
1946 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1947 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1948 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001949 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06001950 pipeline_layout_ci.pSetLayouts = &ds_layout;
1951
1952 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001953 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06001954 ASSERT_VK_SUCCESS(err);
1955
1956 VkPipelineShaderStageCreateInfo shaderStages[3];
1957 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1958
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001959 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06001960 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001961 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
1962 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06001963
1964 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001965 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001966 shaderStages[0].shader = vs.handle();
1967 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001968 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001969 shaderStages[1].shader = tc.handle();
1970 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001971 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001972 shaderStages[2].shader = te.handle();
1973
1974 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1975 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08001976 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis20693172015-09-17 08:46:18 -06001977
1978 VkPipelineTessellationStateCreateInfo tsCI = {};
1979 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1980 tsCI.patchControlPoints = 0; // This will cause an error
1981
1982 VkGraphicsPipelineCreateInfo gp_ci = {};
1983 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1984 gp_ci.pNext = NULL;
1985 gp_ci.stageCount = 3;
1986 gp_ci.pStages = shaderStages;
1987 gp_ci.pVertexInputState = NULL;
1988 gp_ci.pInputAssemblyState = &iaCI;
1989 gp_ci.pTessellationState = &tsCI;
1990 gp_ci.pViewportState = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001991 gp_ci.pRasterizationState = NULL;
Tobin Ehlis20693172015-09-17 08:46:18 -06001992 gp_ci.pMultisampleState = NULL;
1993 gp_ci.pDepthStencilState = NULL;
1994 gp_ci.pColorBlendState = NULL;
1995 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1996 gp_ci.layout = pipeline_layout;
1997 gp_ci.renderPass = renderPass();
1998
1999 VkPipelineCacheCreateInfo pc_ci = {};
2000 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2001 pc_ci.pNext = NULL;
2002 pc_ci.initialSize = 0;
2003 pc_ci.initialData = 0;
2004 pc_ci.maxSize = 0;
2005
2006 VkPipeline pipeline;
2007 VkPipelineCache pipelineCache;
2008
Chia-I Wu69f40122015-10-26 21:10:41 +08002009 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis20693172015-09-17 08:46:18 -06002010 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002011 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis20693172015-09-17 08:46:18 -06002012
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002013 if (!m_errorMonitor->DesiredMsgFound()) {
2014 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...'";
2015 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis20693172015-09-17 08:46:18 -06002016 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002017
Chia-I Wu69f40122015-10-26 21:10:41 +08002018 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2019 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2020 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2021 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis20693172015-09-17 08:46:18 -06002022}
2023*/
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002024// Set scissor and viewport counts to different numbers
2025TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2026{
2027 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002028 VkResult err;
2029
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002030 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2031 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2032
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002033 ASSERT_NO_FATAL_FAILURE(InitState());
2034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002035
Chia-I Wuc51b1212015-10-27 19:25:11 +08002036 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002037 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002038 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002039
2040 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2041 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002042 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002043 ds_pool_ci.poolSizeCount = 1;
2044 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002045
2046 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002047 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002048 ASSERT_VK_SUCCESS(err);
2049
2050 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002051 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002052 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2053 dsl_binding.arraySize = 1;
2054 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2055
2056 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2057 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002058 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002059 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002060
2061 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002062 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002063 ASSERT_VK_SUCCESS(err);
2064
2065 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002066 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002067 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002068 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002069 alloc_info.descriptorPool = ds_pool;
2070 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002071 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002072 ASSERT_VK_SUCCESS(err);
2073
2074 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2075 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002076 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002077 pipeline_layout_ci.pSetLayouts = &ds_layout;
2078
2079 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002080 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002081 ASSERT_VK_SUCCESS(err);
2082
2083 VkViewport vp = {}; // Just need dummy vp to point to
2084
2085 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2086 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2087 vp_state_ci.scissorCount = 0;
2088 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2089 vp_state_ci.pViewports = &vp;
2090
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002091 VkPipelineShaderStageCreateInfo shaderStages[2];
2092 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002093
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002094 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2095 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 -06002096 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002097 shaderStages[0] = vs.GetStageCreateInfo();
2098 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002099
2100 VkGraphicsPipelineCreateInfo gp_ci = {};
2101 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002102 gp_ci.stageCount = 2;
2103 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002104 gp_ci.pViewportState = &vp_state_ci;
2105 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2106 gp_ci.layout = pipeline_layout;
2107 gp_ci.renderPass = renderPass();
2108
2109 VkPipelineCacheCreateInfo pc_ci = {};
2110 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2111
2112 VkPipeline pipeline;
2113 VkPipelineCache pipelineCache;
2114
Chia-I Wu69f40122015-10-26 21:10:41 +08002115 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002116 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002117 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002118
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002119 if (!m_errorMonitor->DesiredMsgFound()) {
2120 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must match scissor count (0).'";
2121 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002122 }
2123
Chia-I Wu69f40122015-10-26 21:10:41 +08002124 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2125 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2126 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2127 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002128}
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002129// Don't set viewport state in PSO. This is an error b/c we always need this state
2130// for the counts even if the data is going to be set dynamically.
2131TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002132{
2133 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002134 VkResult err;
2135
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002136 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2137 "Gfx Pipeline pViewportState is null. Even if ");
2138
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002139 ASSERT_NO_FATAL_FAILURE(InitState());
2140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002141
Chia-I Wuc51b1212015-10-27 19:25:11 +08002142 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002143 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002144 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002145
2146 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2147 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002148 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002149 ds_pool_ci.poolSizeCount = 1;
2150 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002151
2152 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002153 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002154 ASSERT_VK_SUCCESS(err);
2155
2156 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002157 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002158 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2159 dsl_binding.arraySize = 1;
2160 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2161
2162 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2163 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002164 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002165 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002166
2167 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002168 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002169 ASSERT_VK_SUCCESS(err);
2170
2171 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002172 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002173 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002174 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002175 alloc_info.descriptorPool = ds_pool;
2176 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002177 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002178 ASSERT_VK_SUCCESS(err);
2179
2180 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2181 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002182 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002183 pipeline_layout_ci.pSetLayouts = &ds_layout;
2184
2185 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002186 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002187 ASSERT_VK_SUCCESS(err);
2188
2189 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2190 // Set scissor as dynamic to avoid second error
2191 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2192 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2193 dyn_state_ci.dynamicStateCount = 1;
2194 dyn_state_ci.pDynamicStates = &sc_state;
2195
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002196 VkPipelineShaderStageCreateInfo shaderStages[2];
2197 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002198
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002199 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2200 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 -06002201 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002202 shaderStages[0] = vs.GetStageCreateInfo();
2203 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002204
2205 VkGraphicsPipelineCreateInfo gp_ci = {};
2206 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002207 gp_ci.stageCount = 2;
2208 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002209 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2210 gp_ci.pDynamicState = &dyn_state_ci;
2211 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2212 gp_ci.layout = pipeline_layout;
2213 gp_ci.renderPass = renderPass();
2214
2215 VkPipelineCacheCreateInfo pc_ci = {};
2216 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2217
2218 VkPipeline pipeline;
2219 VkPipelineCache pipelineCache;
2220
Chia-I Wu69f40122015-10-26 21:10:41 +08002221 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002222 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002223 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002224
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002225 if (!m_errorMonitor->DesiredMsgFound()) {
2226 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. Even if...'";
2227 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002228 }
2229
Chia-I Wu69f40122015-10-26 21:10:41 +08002230 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2231 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2232 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2233 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002234}
2235// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002236// Then run second test where dynamic scissor count doesn't match PSO scissor count
2237TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002238{
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002239 VkResult err;
2240
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002241 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2242 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
2243
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002244 ASSERT_NO_FATAL_FAILURE(InitState());
2245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002246
Chia-I Wuc51b1212015-10-27 19:25:11 +08002247 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002248 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002249 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002250
2251 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2252 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002253 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002254 ds_pool_ci.poolSizeCount = 1;
2255 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002256
2257 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002258 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002259 ASSERT_VK_SUCCESS(err);
2260
2261 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002262 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002263 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2264 dsl_binding.arraySize = 1;
2265 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2266
2267 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2268 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002269 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002270 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002271
2272 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002273 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002274 ASSERT_VK_SUCCESS(err);
2275
2276 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002277 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002278 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002279 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002280 alloc_info.descriptorPool = ds_pool;
2281 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002282 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002283 ASSERT_VK_SUCCESS(err);
2284
2285 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2286 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002287 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002288 pipeline_layout_ci.pSetLayouts = &ds_layout;
2289
2290 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002291 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002292 ASSERT_VK_SUCCESS(err);
2293
2294 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2295 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2296 vp_state_ci.viewportCount = 1;
2297 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2298 vp_state_ci.scissorCount = 1;
2299 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2300
2301 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2302 // Set scissor as dynamic to avoid that error
2303 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2304 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2305 dyn_state_ci.dynamicStateCount = 1;
2306 dyn_state_ci.pDynamicStates = &sc_state;
2307
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002308 VkPipelineShaderStageCreateInfo shaderStages[2];
2309 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002310
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002311 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2312 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 -06002313 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002314 shaderStages[0] = vs.GetStageCreateInfo();
2315 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002316
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002317 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2318 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2319 vi_ci.pNext = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002320 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002321 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002322 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002323 vi_ci.pVertexAttributeDescriptions = nullptr;
2324
2325 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2326 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2327 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2328
Chia-I Wu1f851912015-10-27 18:04:07 +08002329 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +08002330 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002331 rs_ci.pNext = nullptr;
2332
2333 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2334 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2335 cb_ci.pNext = nullptr;
2336
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002337 VkGraphicsPipelineCreateInfo gp_ci = {};
2338 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002339 gp_ci.stageCount = 2;
2340 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002341 gp_ci.pVertexInputState = &vi_ci;
2342 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002343 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu1f851912015-10-27 18:04:07 +08002344 gp_ci.pRasterizationState = &rs_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002345 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002346 gp_ci.pDynamicState = &dyn_state_ci;
2347 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2348 gp_ci.layout = pipeline_layout;
2349 gp_ci.renderPass = renderPass();
2350
2351 VkPipelineCacheCreateInfo pc_ci = {};
2352 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2353
2354 VkPipeline pipeline;
2355 VkPipelineCache pipelineCache;
2356
Chia-I Wu69f40122015-10-26 21:10:41 +08002357 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002358 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002359 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002360
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002361 if (!m_errorMonitor->DesiredMsgFound()) {
2362 FAIL() << "Did not recieve Error 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...'";
2363 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002364 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002365
2366
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002367 // Now hit second fail case where we set scissor w/ different count than PSO
2368 // First need to successfully create the PSO from above by setting pViewports
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002369 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2370 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.");
2371
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002372 VkViewport vp = {}; // Just need dummy vp to point to
2373 vp_state_ci.pViewports = &vp;
Chia-I Wu69f40122015-10-26 21:10:41 +08002374 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002375 ASSERT_VK_SUCCESS(err);
2376 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08002377 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002378 VkRect2D scissors[2] = {}; // don't care about data
2379 // Count of 2 doesn't match PSO count of 1
Chia-I Wu1f851912015-10-27 18:04:07 +08002380 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 2, scissors);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002381 Draw(1, 0, 0, 0);
2382
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002383 if (!m_errorMonitor->DesiredMsgFound()) {
2384 FAIL() << "Did not receive Error 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
2385 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002386 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002387
Chia-I Wu69f40122015-10-26 21:10:41 +08002388 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2389 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2390 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2391 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002392}
2393// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002394// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2395TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002396{
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002397 VkResult err;
2398
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002399 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2400 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
2401
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002402 ASSERT_NO_FATAL_FAILURE(InitState());
2403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002404
Chia-I Wuc51b1212015-10-27 19:25:11 +08002405 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002406 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002407 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002408
2409 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2410 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002411 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002412 ds_pool_ci.poolSizeCount = 1;
2413 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002414
2415 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002416 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002417 ASSERT_VK_SUCCESS(err);
2418
2419 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002420 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002421 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2422 dsl_binding.arraySize = 1;
2423 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2424
2425 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2426 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002427 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002428 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002429
2430 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002431 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002432 ASSERT_VK_SUCCESS(err);
2433
2434 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002435 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002436 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002437 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002438 alloc_info.descriptorPool = ds_pool;
2439 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002440 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002441 ASSERT_VK_SUCCESS(err);
2442
2443 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2444 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002445 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002446 pipeline_layout_ci.pSetLayouts = &ds_layout;
2447
2448 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002449 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002450 ASSERT_VK_SUCCESS(err);
2451
2452 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2453 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2454 vp_state_ci.scissorCount = 1;
2455 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2456 vp_state_ci.viewportCount = 1;
2457 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2458
2459 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2460 // Set scissor as dynamic to avoid that error
2461 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2462 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2463 dyn_state_ci.dynamicStateCount = 1;
2464 dyn_state_ci.pDynamicStates = &vp_state;
2465
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002466 VkPipelineShaderStageCreateInfo shaderStages[2];
2467 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002468
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002469 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2470 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 -06002471 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002472 shaderStages[0] = vs.GetStageCreateInfo();
2473 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002474
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002475 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2476 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2477 vi_ci.pNext = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002478 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002479 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002480 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002481 vi_ci.pVertexAttributeDescriptions = nullptr;
2482
2483 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2484 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2485 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2486
Chia-I Wu1f851912015-10-27 18:04:07 +08002487 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +08002488 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002489 rs_ci.pNext = nullptr;
2490
2491 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2492 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2493 cb_ci.pNext = nullptr;
2494
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002495 VkGraphicsPipelineCreateInfo gp_ci = {};
2496 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002497 gp_ci.stageCount = 2;
2498 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002499 gp_ci.pVertexInputState = &vi_ci;
2500 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002501 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu1f851912015-10-27 18:04:07 +08002502 gp_ci.pRasterizationState = &rs_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002503 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002504 gp_ci.pDynamicState = &dyn_state_ci;
2505 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2506 gp_ci.layout = pipeline_layout;
2507 gp_ci.renderPass = renderPass();
2508
2509 VkPipelineCacheCreateInfo pc_ci = {};
2510 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2511
2512 VkPipeline pipeline;
2513 VkPipelineCache pipelineCache;
2514
Chia-I Wu69f40122015-10-26 21:10:41 +08002515 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002516 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002517 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002518
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002519 if (!m_errorMonitor->DesiredMsgFound()) {
2520 FAIL() << "Did not recieve Error 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...'";
2521 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002522 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002523
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002524 // Now hit second fail case where we set scissor w/ different count than PSO
2525 // First need to successfully create the PSO from above by setting pViewports
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002526 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2527 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.");
2528
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002529 VkRect2D sc = {}; // Just need dummy vp to point to
2530 vp_state_ci.pScissors = &sc;
Chia-I Wu69f40122015-10-26 21:10:41 +08002531 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002532 ASSERT_VK_SUCCESS(err);
2533 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08002534 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002535 VkViewport viewports[2] = {}; // don't care about data
2536 // Count of 2 doesn't match PSO count of 1
Chia-I Wu1f851912015-10-27 18:04:07 +08002537 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 2, viewports);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002538 Draw(1, 0, 0, 0);
2539
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002540 if (!m_errorMonitor->DesiredMsgFound()) {
2541 FAIL() << "Did not receive Error 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...'";
2542 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002543 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002544
Chia-I Wu69f40122015-10-26 21:10:41 +08002545 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2546 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2547 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2548 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002549}
2550
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002551TEST_F(VkLayerTest, NullRenderPass)
2552{
2553 // Bind a NULL RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002554 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2555 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002556
2557 ASSERT_NO_FATAL_FAILURE(InitState());
2558 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002559
Tony Barbour1490c912015-07-28 10:17:20 -06002560 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002561 // Don't care about RenderPass handle b/c error should be flagged before that
Chia-I Wuc51b1212015-10-27 19:25:11 +08002562 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002563
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002564 if (!m_errorMonitor->DesiredMsgFound()) {
2565 FAIL() << "Did not receive Error 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2566 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002567 }
2568}
2569
Tobin Ehlis254eca02015-06-25 15:46:59 -06002570TEST_F(VkLayerTest, RenderPassWithinRenderPass)
2571{
2572 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002573 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2574 "It is invalid to issue this call inside an active render pass");
Tobin Ehlis254eca02015-06-25 15:46:59 -06002575
2576 ASSERT_NO_FATAL_FAILURE(InitState());
2577 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06002578
Tony Barbour1490c912015-07-28 10:17:20 -06002579 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002580 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002581 VkRenderPassBeginInfo rp_begin = {};
2582 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
2583 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002584 rp_begin.renderPass = renderPass();
2585 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002586
Chia-I Wuc51b1212015-10-27 19:25:11 +08002587 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002588
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002589 if (!m_errorMonitor->DesiredMsgFound()) {
2590 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2591 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002592 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002593}
2594
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002595TEST_F(VkLayerTest, FillBufferWithinRenderPass)
2596{
2597 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002598 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2599 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002600
2601 ASSERT_NO_FATAL_FAILURE(InitState());
2602 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002603
2604 // Renderpass is started here
2605 BeginCommandBuffer();
2606
2607 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08002608 vk_testing::Buffer dstBuffer;
2609 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002610
Chia-I Wu1f851912015-10-27 18:04:07 +08002611 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002612
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002613 if (!m_errorMonitor->DesiredMsgFound()) {
2614 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2615 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002616 }
2617}
2618
2619TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
2620{
2621 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002622 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2623 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002624
2625 ASSERT_NO_FATAL_FAILURE(InitState());
2626 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002627
2628 // Renderpass is started here
2629 BeginCommandBuffer();
2630
2631 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08002632 vk_testing::Buffer dstBuffer;
2633 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002634
Chia-I Wu1f851912015-10-27 18:04:07 +08002635 VkDeviceSize dstOffset = 0;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002636 VkDeviceSize dataSize = 1024;
2637 const uint32_t *pData = NULL;
2638
Chia-I Wu1f851912015-10-27 18:04:07 +08002639 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002640
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002641 if (!m_errorMonitor->DesiredMsgFound()) {
2642 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2643 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002644 }
2645}
2646
2647TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
2648{
2649 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002650 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2651 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002652
2653 ASSERT_NO_FATAL_FAILURE(InitState());
2654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002655
2656 // Renderpass is started here
2657 BeginCommandBuffer();
2658
2659 VkClearColorValue clear_color = {0};
2660 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2661 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2662 const int32_t tex_width = 32;
2663 const int32_t tex_height = 32;
2664 VkImageCreateInfo image_create_info = {};
2665 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2666 image_create_info.pNext = NULL;
2667 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2668 image_create_info.format = tex_format;
2669 image_create_info.extent.width = tex_width;
2670 image_create_info.extent.height = tex_height;
2671 image_create_info.extent.depth = 1;
2672 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06002673 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08002674 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002675 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2676 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2677
Chia-I Wu1f851912015-10-27 18:04:07 +08002678 vk_testing::Image dstImage;
2679 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002680
2681 const VkImageSubresourceRange range =
2682 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
2683
Chia-I Wu1f851912015-10-27 18:04:07 +08002684 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(),
2685 dstImage.handle(),
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002686 VK_IMAGE_LAYOUT_GENERAL,
2687 &clear_color,
2688 1,
2689 &range);
2690
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002691 if (!m_errorMonitor->DesiredMsgFound()) {
2692 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2693 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002694 }
2695}
2696
2697TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
2698{
2699 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002700 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2701 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002702
2703 ASSERT_NO_FATAL_FAILURE(InitState());
2704 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002705
2706 // Renderpass is started here
2707 BeginCommandBuffer();
2708
2709 VkClearDepthStencilValue clear_value = {0};
2710 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2711 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
2712 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2713 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
2714 image_create_info.extent.width = 64;
2715 image_create_info.extent.height = 64;
2716 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2717 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2718
Chia-I Wu1f851912015-10-27 18:04:07 +08002719 vk_testing::Image dstImage;
2720 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002721
2722 const VkImageSubresourceRange range =
2723 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
2724
Chia-I Wu1f851912015-10-27 18:04:07 +08002725 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(),
2726 dstImage.handle(),
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002727 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2728 &clear_value,
2729 1,
2730 &range);
2731
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002732 if (!m_errorMonitor->DesiredMsgFound()) {
2733 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2734 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002735 }
2736}
2737
2738TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
2739{
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002740 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002741 VkResult err;
2742
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002743 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2744 "vkCmdClearAttachments: This call must be issued inside an active render pass");
2745
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002746 ASSERT_NO_FATAL_FAILURE(InitState());
2747 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002748
2749 // Start no RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08002750 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002751 ASSERT_VK_SUCCESS(err);
2752
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002753 VkClearAttachment color_attachment;
2754 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2755 color_attachment.clearValue.color.float32[0] = 0;
2756 color_attachment.clearValue.color.float32[1] = 0;
2757 color_attachment.clearValue.color.float32[2] = 0;
2758 color_attachment.clearValue.color.float32[3] = 0;
2759 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06002760 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Chia-I Wu1f851912015-10-27 18:04:07 +08002761 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(),
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002762 1, &color_attachment,
2763 1, &clear_rect);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002764
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002765 if (!m_errorMonitor->DesiredMsgFound()) {
2766 FAIL() << "Did not receive Error 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
2767 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002768 }
2769}
2770
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002771TEST_F(VkLayerTest, InvalidDynamicStateObject)
2772{
2773 // Create a valid cmd buffer
2774 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002775 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
2776 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002777}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06002778
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002779TEST_F(VkLayerTest, IdxBufferAlignmentError)
2780{
2781 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002782 VkResult err;
2783
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002784 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2785 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
2786
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002787 ASSERT_NO_FATAL_FAILURE(InitState());
2788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002789 uint32_t qfi = 0;
2790 VkBufferCreateInfo buffCI = {};
2791 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2792 buffCI.size = 1024;
2793 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
Chia-I Wu763a7492015-10-26 20:48:51 +08002794 buffCI.queueFamilyIndexCount = 1;
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002795 buffCI.pQueueFamilyIndices = &qfi;
2796
2797 VkBuffer ib;
Chia-I Wu69f40122015-10-26 21:10:41 +08002798 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002799 ASSERT_VK_SUCCESS(err);
2800
2801 BeginCommandBuffer();
2802 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08002803 //vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002804 // Should error before calling to driver so don't care about actual data
Chia-I Wu1f851912015-10-27 18:04:07 +08002805 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002806
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002807 if (!m_errorMonitor->DesiredMsgFound()) {
2808 FAIL() << "Did not receive Error 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...'";
2809 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002810 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002811
Chia-I Wu69f40122015-10-26 21:10:41 +08002812 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002813}
2814
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002815TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2816{
2817 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002818
2819 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2820 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002821
2822 ASSERT_NO_FATAL_FAILURE(InitState());
2823 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002824
2825 BeginCommandBuffer();
2826 //ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08002827 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
2828 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002829
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002830 if (!m_errorMonitor->DesiredMsgFound()) {
2831 FAIL() << "Did not receive Error 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer '";
2832 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002833 }
2834}
2835
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002836TEST_F(VkLayerTest, DSTypeMismatch)
2837{
2838 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002839 VkResult err;
2840
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002841 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2842 "Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ");
2843
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002844 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002845 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08002846 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002847 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002848 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002849
2850 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2851 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2852 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002853 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002854 ds_pool_ci.poolSizeCount = 1;
2855 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002856
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002857 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002858 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002859 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002860 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002861 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002862 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2863 dsl_binding.arraySize = 1;
2864 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2865 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002866
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002867 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2868 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2869 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002870 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002871 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002872
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002873 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002874 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002875 ASSERT_VK_SUCCESS(err);
2876
2877 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002878 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002879 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002880 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002881 alloc_info.descriptorPool = ds_pool;
2882 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002883 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002884 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002885
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002886 VkSamplerCreateInfo sampler_ci = {};
2887 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2888 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08002889 sampler_ci.magFilter = VK_FILTER_NEAREST;
2890 sampler_ci.minFilter = VK_FILTER_NEAREST;
2891 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08002892 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2893 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2894 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002895 sampler_ci.mipLodBias = 1.0;
2896 sampler_ci.maxAnisotropy = 1;
2897 sampler_ci.compareEnable = VK_FALSE;
2898 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2899 sampler_ci.minLod = 1.0;
2900 sampler_ci.maxLod = 1.0;
2901 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002902 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2903
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002904 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08002905 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002906 ASSERT_VK_SUCCESS(err);
2907
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06002908 VkDescriptorImageInfo info = {};
2909 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002910
2911 VkWriteDescriptorSet descriptor_write;
2912 memset(&descriptor_write, 0, sizeof(descriptor_write));
2913 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08002914 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08002915 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002916 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002917 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06002918 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002919
2920 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2921
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002922 if (!m_errorMonitor->DesiredMsgFound()) {
2923 FAIL() << "Did not receive Error 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...'";
2924 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002925 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002926
Chia-I Wu69f40122015-10-26 21:10:41 +08002927 vkDestroySampler(m_device->device(), sampler, NULL);
2928 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2929 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002930}
2931
2932TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2933{
2934 // For overlapping Update, have arrayIndex exceed that of layout
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002935 VkResult err;
2936
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002937 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2938 "Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding");
2939
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002940 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002941 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08002942 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002943 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002944 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002945
2946 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2947 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2948 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002949 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002950 ds_pool_ci.poolSizeCount = 1;
2951 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002952
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002953 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002954 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002955 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002956
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002957 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002958 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002959 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2960 dsl_binding.arraySize = 1;
2961 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2962 dsl_binding.pImmutableSamplers = NULL;
2963
2964 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2965 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2966 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002967 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002968 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002969
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002970 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002971 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002972 ASSERT_VK_SUCCESS(err);
2973
2974 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002975 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002976 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002977 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002978 alloc_info.descriptorPool = ds_pool;
2979 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002980 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002981 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002982
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002983 VkSamplerCreateInfo sampler_ci = {};
2984 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2985 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08002986 sampler_ci.magFilter = VK_FILTER_NEAREST;
2987 sampler_ci.minFilter = VK_FILTER_NEAREST;
2988 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08002989 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2990 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2991 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002992 sampler_ci.mipLodBias = 1.0;
2993 sampler_ci.maxAnisotropy = 1;
2994 sampler_ci.compareEnable = VK_FALSE;
2995 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2996 sampler_ci.minLod = 1.0;
2997 sampler_ci.maxLod = 1.0;
2998 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002999 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003000
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003001 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003002 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003003 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003004
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003005 VkDescriptorImageInfo info = {};
3006 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003007
3008 VkWriteDescriptorSet descriptor_write;
3009 memset(&descriptor_write, 0, sizeof(descriptor_write));
3010 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003011 descriptor_write.dstSet = descriptorSet;
3012 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wu763a7492015-10-26 20:48:51 +08003013 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003014 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003015 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003016 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003017
3018 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3019
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003020 if (!m_errorMonitor->DesiredMsgFound()) {
3021 FAIL() << "Did not receive Error 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
3022 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003023 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003024
Chia-I Wu69f40122015-10-26 21:10:41 +08003025 vkDestroySampler(m_device->device(), sampler, NULL);
3026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3027 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003028}
3029
3030TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3031{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003032 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003033 VkResult err;
3034
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003035 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3036 " does not have binding to match update binding ");
3037
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003038 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003039 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003040 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003041 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003042 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003043
3044 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3045 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3046 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003047 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003048 ds_pool_ci.poolSizeCount = 1;
3049 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003050
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003051 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003052 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003053 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003054
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003055 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003056 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003057 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3058 dsl_binding.arraySize = 1;
3059 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3060 dsl_binding.pImmutableSamplers = NULL;
3061
3062 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3063 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3064 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003065 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003066 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003067 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003068 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003069 ASSERT_VK_SUCCESS(err);
3070
3071 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003072 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003073 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003074 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003075 alloc_info.descriptorPool = ds_pool;
3076 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003077 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003078 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003079
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003080 VkSamplerCreateInfo sampler_ci = {};
3081 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3082 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003083 sampler_ci.magFilter = VK_FILTER_NEAREST;
3084 sampler_ci.minFilter = VK_FILTER_NEAREST;
3085 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003086 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3087 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3088 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003089 sampler_ci.mipLodBias = 1.0;
3090 sampler_ci.maxAnisotropy = 1;
3091 sampler_ci.compareEnable = VK_FALSE;
3092 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3093 sampler_ci.minLod = 1.0;
3094 sampler_ci.maxLod = 1.0;
3095 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003096 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003097
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003098 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003099 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003100 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003101
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003102 VkDescriptorImageInfo info = {};
3103 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003104
3105 VkWriteDescriptorSet descriptor_write;
3106 memset(&descriptor_write, 0, sizeof(descriptor_write));
3107 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003108 descriptor_write.dstSet = descriptorSet;
3109 descriptor_write.dstBinding = 2;
Chia-I Wu763a7492015-10-26 20:48:51 +08003110 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003111 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003112 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003113 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003114
3115 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3116
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003117 if (!m_errorMonitor->DesiredMsgFound()) {
3118 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have binding to match update binding '";
3119 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003120 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003121
Chia-I Wu69f40122015-10-26 21:10:41 +08003122 vkDestroySampler(m_device->device(), sampler, NULL);
3123 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3124 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003125}
3126
3127TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3128{
3129 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003130 VkResult err;
3131
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003132 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3133 "Unexpected UPDATE struct of type ");
3134
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003135 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003136
Chia-I Wuc51b1212015-10-27 19:25:11 +08003137 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003138 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003139 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003140
3141 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3142 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3143 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003144 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003145 ds_pool_ci.poolSizeCount = 1;
3146 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003147
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003148 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003149 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003150 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003151 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003152 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003153 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3154 dsl_binding.arraySize = 1;
3155 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3156 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003157
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003158 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3159 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3160 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003161 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003162 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003163
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003164 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003165 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003166 ASSERT_VK_SUCCESS(err);
3167
3168 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003169 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003170 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003171 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003172 alloc_info.descriptorPool = ds_pool;
3173 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003174 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003175 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003176
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003177 VkSamplerCreateInfo sampler_ci = {};
3178 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3179 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003180 sampler_ci.magFilter = VK_FILTER_NEAREST;
3181 sampler_ci.minFilter = VK_FILTER_NEAREST;
3182 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003183 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3184 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3185 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003186 sampler_ci.mipLodBias = 1.0;
3187 sampler_ci.maxAnisotropy = 1;
3188 sampler_ci.compareEnable = VK_FALSE;
3189 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3190 sampler_ci.minLod = 1.0;
3191 sampler_ci.maxLod = 1.0;
3192 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003193 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003194 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003195 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003196 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003197
3198
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003199 VkDescriptorImageInfo info = {};
3200 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003201
3202 VkWriteDescriptorSet descriptor_write;
3203 memset(&descriptor_write, 0, sizeof(descriptor_write));
3204 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu1f851912015-10-27 18:04:07 +08003205 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003206 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003207 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003208 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003209 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003210
3211 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3212
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003213 if (!m_errorMonitor->DesiredMsgFound()) {
3214 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
3215 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003216 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003217
Chia-I Wu69f40122015-10-26 21:10:41 +08003218 vkDestroySampler(m_device->device(), sampler, NULL);
3219 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3220 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003221}
3222
Tobin Ehlisb46be812015-10-23 16:00:08 -06003223TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3224{
3225 // Create a single Sampler descriptor and send it an invalid Sampler
Tobin Ehlisb46be812015-10-23 16:00:08 -06003226 VkResult err;
3227
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003228 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3229 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
3230
Tobin Ehlisb46be812015-10-23 16:00:08 -06003231 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb46be812015-10-23 16:00:08 -06003232 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
Chia-I Wuc51b1212015-10-27 19:25:11 +08003233 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003234 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003235 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003236
3237 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3238 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3239 ds_pool_ci.pNext = NULL;
3240 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003241 ds_pool_ci.poolSizeCount = 1;
3242 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003243
3244 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003245 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003246 ASSERT_VK_SUCCESS(err);
3247
3248 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003249 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003250 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3251 dsl_binding.arraySize = 1;
3252 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3253 dsl_binding.pImmutableSamplers = NULL;
3254
3255 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3256 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3257 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003258 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003259 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003260 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003261 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003262 ASSERT_VK_SUCCESS(err);
3263
3264 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003265 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003266 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003267 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003268 alloc_info.descriptorPool = ds_pool;
3269 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003270 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003271 ASSERT_VK_SUCCESS(err);
3272
Chia-I Wue420a332015-10-26 20:04:44 +08003273 VkSampler sampler = (VkSampler) 0xbaadbeef; // Sampler with invalid handle
Tobin Ehlisb46be812015-10-23 16:00:08 -06003274
3275 VkDescriptorImageInfo descriptor_info;
3276 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3277 descriptor_info.sampler = sampler;
3278
3279 VkWriteDescriptorSet descriptor_write;
3280 memset(&descriptor_write, 0, sizeof(descriptor_write));
3281 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003282 descriptor_write.dstSet = descriptorSet;
3283 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003284 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003285 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3286 descriptor_write.pImageInfo = &descriptor_info;
3287
3288 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3289
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003290 if (!m_errorMonitor->DesiredMsgFound()) {
3291 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid sampler...'";
3292 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003293 }
3294
Chia-I Wu69f40122015-10-26 21:10:41 +08003295 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3296 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003297}
3298
3299TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3300{
3301 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
Tobin Ehlisb46be812015-10-23 16:00:08 -06003302 VkResult err;
3303
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003304 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3305 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
3306
Tobin Ehlisb46be812015-10-23 16:00:08 -06003307 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wuc51b1212015-10-27 19:25:11 +08003308 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003309 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003310 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003311
3312 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3313 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3314 ds_pool_ci.pNext = NULL;
3315 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003316 ds_pool_ci.poolSizeCount = 1;
3317 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003318
3319 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003320 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003321 ASSERT_VK_SUCCESS(err);
3322
3323 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003324 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003325 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3326 dsl_binding.arraySize = 1;
3327 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3328 dsl_binding.pImmutableSamplers = NULL;
3329
3330 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3331 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3332 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003333 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003334 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003335 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003336 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003337 ASSERT_VK_SUCCESS(err);
3338
3339 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003340 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003341 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003342 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003343 alloc_info.descriptorPool = ds_pool;
3344 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003345 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003346 ASSERT_VK_SUCCESS(err);
3347
3348 VkSamplerCreateInfo sampler_ci = {};
3349 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3350 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003351 sampler_ci.magFilter = VK_FILTER_NEAREST;
3352 sampler_ci.minFilter = VK_FILTER_NEAREST;
3353 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003354 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3355 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3356 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003357 sampler_ci.mipLodBias = 1.0;
3358 sampler_ci.maxAnisotropy = 1;
3359 sampler_ci.compareEnable = VK_FALSE;
3360 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3361 sampler_ci.minLod = 1.0;
3362 sampler_ci.maxLod = 1.0;
3363 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3364 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3365
3366 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003367 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003368 ASSERT_VK_SUCCESS(err);
3369
Chia-I Wue420a332015-10-26 20:04:44 +08003370 VkImageView view = (VkImageView) 0xbaadbeef; // invalid imageView object
Tobin Ehlisb46be812015-10-23 16:00:08 -06003371
3372 VkDescriptorImageInfo descriptor_info;
3373 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3374 descriptor_info.sampler = sampler;
3375 descriptor_info.imageView = view;
3376
3377 VkWriteDescriptorSet descriptor_write;
3378 memset(&descriptor_write, 0, sizeof(descriptor_write));
3379 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003380 descriptor_write.dstSet = descriptorSet;
3381 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003382 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003383 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3384 descriptor_write.pImageInfo = &descriptor_info;
3385
3386 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3387
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003388 if (!m_errorMonitor->DesiredMsgFound()) {
3389 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid imageView...'";
3390 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003391 }
3392
Chia-I Wu69f40122015-10-26 21:10:41 +08003393 vkDestroySampler(m_device->device(), sampler, NULL);
3394 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3395 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003396}
3397
Tobin Ehlis3e676262015-10-27 16:35:27 -06003398TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
3399{
3400 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update into the other
Tobin Ehlis3e676262015-10-27 16:35:27 -06003401 VkResult err;
3402
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003403 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3404 "Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ");
3405
Tobin Ehlis3e676262015-10-27 16:35:27 -06003406 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3e676262015-10-27 16:35:27 -06003407 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003408 VkDescriptorPoolSize ds_type_count[2] = {};
Tobin Ehlis3e676262015-10-27 16:35:27 -06003409 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003410 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003411 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003412 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003413
3414 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3415 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3416 ds_pool_ci.pNext = NULL;
3417 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003418 ds_pool_ci.poolSizeCount = 2;
3419 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003420
3421 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003422 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003423 ASSERT_VK_SUCCESS(err);
3424 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003425 dsl_binding[0].binding = 0;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003426 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3427 dsl_binding[0].arraySize = 1;
3428 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3429 dsl_binding[0].pImmutableSamplers = NULL;
Chia-I Wub5689ee2015-10-31 00:31:16 +08003430 dsl_binding[1].binding = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003431 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3432 dsl_binding[1].arraySize = 1;
3433 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
3434 dsl_binding[1].pImmutableSamplers = NULL;
3435
3436 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3437 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3438 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003439 ds_layout_ci.bindingCount = 2;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003440 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003441
3442 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003443 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003444 ASSERT_VK_SUCCESS(err);
3445
3446 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003447 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis3e676262015-10-27 16:35:27 -06003448 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003449 alloc_info.setLayoutCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003450 alloc_info.descriptorPool = ds_pool;
3451 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003452 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003453 ASSERT_VK_SUCCESS(err);
3454
3455 VkSamplerCreateInfo sampler_ci = {};
3456 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3457 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003458 sampler_ci.magFilter = VK_FILTER_NEAREST;
3459 sampler_ci.minFilter = VK_FILTER_NEAREST;
3460 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003461 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3462 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3463 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003464 sampler_ci.mipLodBias = 1.0;
3465 sampler_ci.maxAnisotropy = 1;
3466 sampler_ci.compareEnable = VK_FALSE;
3467 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3468 sampler_ci.minLod = 1.0;
3469 sampler_ci.maxLod = 1.0;
3470 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3471 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3472
3473 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003474 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003475 ASSERT_VK_SUCCESS(err);
3476
3477 VkDescriptorImageInfo info = {};
3478 info.sampler = sampler;
3479
3480 VkWriteDescriptorSet descriptor_write;
3481 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
3482 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003483 descriptor_write.dstSet = descriptorSet;
3484 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wu763a7492015-10-26 20:48:51 +08003485 descriptor_write.descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003486 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3487 descriptor_write.pImageInfo = &info;
3488 // This write update should succeed
3489 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3490 // Now perform a copy update that fails due to type mismatch
3491 VkCopyDescriptorSet copy_ds_update;
3492 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3493 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3494 copy_ds_update.srcSet = descriptorSet;
3495 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu1f851912015-10-27 18:04:07 +08003496 copy_ds_update.dstSet = descriptorSet;
3497 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wu763a7492015-10-26 20:48:51 +08003498 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06003499 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3500
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003501 if (!m_errorMonitor->DesiredMsgFound()) {
3502 FAIL() << "Did not receive Error 'Copy descriptor update index 0, update count #1, has src update descriptor type_DESCRIPTOR_TYPE_SAMPLER'";
3503 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003504 }
3505 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003506 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3507 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis3e676262015-10-27 16:35:27 -06003508 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3509 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3510 copy_ds_update.srcSet = descriptorSet;
3511 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu1f851912015-10-27 18:04:07 +08003512 copy_ds_update.dstSet = descriptorSet;
3513 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003514 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06003515 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3516
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003517 if (!m_errorMonitor->DesiredMsgFound()) {
3518 FAIL() << "Did not receive Error 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...'";
3519 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003520 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003521
Tobin Ehlis3e676262015-10-27 16:35:27 -06003522 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003523 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3524 "Copy descriptor src update is out of bounds for matching binding 1 ");
3525
Tobin Ehlis3e676262015-10-27 16:35:27 -06003526 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3527 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3528 copy_ds_update.srcSet = descriptorSet;
3529 copy_ds_update.srcBinding = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08003530 copy_ds_update.dstSet = descriptorSet;
3531 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003532 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis3e676262015-10-27 16:35:27 -06003533 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3534
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003535 if (!m_errorMonitor->DesiredMsgFound()) {
3536 FAIL() << "Did not receive Error 'Copy descriptor src update is out of bounds for matching binding 1...'";
3537 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003538 }
3539
Chia-I Wu69f40122015-10-26 21:10:41 +08003540 vkDestroySampler(m_device->device(), sampler, NULL);
3541 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3542 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003543}
3544
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003545TEST_F(VkLayerTest, NumSamplesMismatch)
3546{
Chia-I Wu1f851912015-10-27 18:04:07 +08003547 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003548 VkResult err;
3549
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003550 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3551 "Num samples mismatch! ");
3552
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003553 ASSERT_NO_FATAL_FAILURE(InitState());
3554 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08003555 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003556 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003557 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003558
3559 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003560 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3561 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003562 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003563 ds_pool_ci.poolSizeCount = 1;
3564 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003565
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003566 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003567 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003568 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003569
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003570 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003571 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003572 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3573 dsl_binding.arraySize = 1;
3574 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3575 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003576
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003577 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3578 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3579 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003580 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003581 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003582
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003583 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003584 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003585 ASSERT_VK_SUCCESS(err);
3586
3587 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003588 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003589 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003590 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003591 alloc_info.descriptorPool = ds_pool;
3592 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003593 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003594 ASSERT_VK_SUCCESS(err);
3595
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003596 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3597 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3598 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08003599 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003600 pipe_ms_state_ci.sampleShadingEnable = 0;
3601 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003602 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003603
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003604 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3605 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3606 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003607 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003608 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003609
3610 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003611 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003612 ASSERT_VK_SUCCESS(err);
3613
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003614 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3615 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 -06003616 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003617 VkPipelineObj pipe(m_device);
3618 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003619 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003620 pipe.SetMSAA(&pipe_ms_state_ci);
3621 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003622
Tony Barbour1490c912015-07-28 10:17:20 -06003623 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08003624 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003625
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003626 if (!m_errorMonitor->DesiredMsgFound()) {
3627 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
3628 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003629 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003630
Chia-I Wu69f40122015-10-26 21:10:41 +08003631 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3632 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3633 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003634}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003635
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003636TEST_F(VkLayerTest, ClearCmdNoDraw)
3637{
Chia-I Wu1f851912015-10-27 18:04:07 +08003638 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003639 VkResult err;
3640
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003641 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
3642 "vkCmdClearAttachments() issued on CB object ");
3643
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003644 ASSERT_NO_FATAL_FAILURE(InitState());
3645 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003646
Chia-I Wuc51b1212015-10-27 19:25:11 +08003647 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003648 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003649 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003650
3651 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3652 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3653 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003654 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003655 ds_pool_ci.poolSizeCount = 1;
3656 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003657
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003658 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003659 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003660 ASSERT_VK_SUCCESS(err);
3661
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003662 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003663 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003664 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3665 dsl_binding.arraySize = 1;
3666 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3667 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003668
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003669 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3670 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3671 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003672 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003673 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003674
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003675 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003676 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003677 ASSERT_VK_SUCCESS(err);
3678
3679 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003680 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003681 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003682 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003683 alloc_info.descriptorPool = ds_pool;
3684 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003685 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003686 ASSERT_VK_SUCCESS(err);
3687
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003688 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3689 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3690 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08003691 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003692 pipe_ms_state_ci.sampleShadingEnable = 0;
3693 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003694 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003695
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003696 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3697 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3698 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003699 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003700 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003701
3702 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003703 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003704 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003705
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003706 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003707 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
3708 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3709
Tony Barbourd7d828b2015-08-06 10:16:07 -06003710 VkPipelineObj pipe(m_device);
3711 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003712 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003713 pipe.SetMSAA(&pipe_ms_state_ci);
3714 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003715
3716 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003717
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003718 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3719 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003720 VkClearAttachment color_attachment;
3721 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3722 color_attachment.clearValue.color.float32[0] = 1.0;
3723 color_attachment.clearValue.color.float32[1] = 1.0;
3724 color_attachment.clearValue.color.float32[2] = 1.0;
3725 color_attachment.clearValue.color.float32[3] = 1.0;
3726 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06003727 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003728
Chia-I Wu1f851912015-10-27 18:04:07 +08003729 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003730
3731 if (!m_errorMonitor->DesiredMsgFound()) {
3732 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued on CB object...'";
3733 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003734 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003735
Chia-I Wu69f40122015-10-26 21:10:41 +08003736 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3737 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3738 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003739}
3740
Tobin Ehlise4076782015-06-24 15:53:07 -06003741TEST_F(VkLayerTest, VtxBufferBadIndex)
3742{
Chia-I Wu1f851912015-10-27 18:04:07 +08003743 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlise4076782015-06-24 15:53:07 -06003744 VkResult err;
3745
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003746 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3747 "Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.");
3748
Tobin Ehlise4076782015-06-24 15:53:07 -06003749 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003750 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06003751 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003752
Chia-I Wuc51b1212015-10-27 19:25:11 +08003753 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003754 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003755 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003756
3757 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3758 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3759 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003760 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003761 ds_pool_ci.poolSizeCount = 1;
3762 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003763
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003764 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003765 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003766 ASSERT_VK_SUCCESS(err);
3767
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003768 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003769 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003770 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3771 dsl_binding.arraySize = 1;
3772 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3773 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003774
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003775 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3776 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3777 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003778 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003779 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003780
Tobin Ehlise4076782015-06-24 15:53:07 -06003781 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003782 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06003783 ASSERT_VK_SUCCESS(err);
3784
3785 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003786 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003787 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003788 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003789 alloc_info.descriptorPool = ds_pool;
3790 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003791 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06003792 ASSERT_VK_SUCCESS(err);
3793
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003794 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3795 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3796 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08003797 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003798 pipe_ms_state_ci.sampleShadingEnable = 0;
3799 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003800 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003801
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003802 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3803 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3804 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003805 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003806 pipeline_layout_ci.pSetLayouts = &ds_layout;
3807 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06003808
Chia-I Wu69f40122015-10-26 21:10:41 +08003809 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06003810 ASSERT_VK_SUCCESS(err);
3811
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003812 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3813 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 -06003814 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003815 VkPipelineObj pipe(m_device);
3816 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003817 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003818 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003819 pipe.SetViewport(m_viewports);
3820 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003821 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003822
3823 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08003824 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06003825 // Don't care about actual data, just need to get to draw to flag error
3826 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3827 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3828 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003829 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06003830
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003831 if (!m_errorMonitor->DesiredMsgFound()) {
3832 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
3833 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -06003834 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003835
Chia-I Wu69f40122015-10-26 21:10:41 +08003836 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3837 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3838 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06003839}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003840#endif // DRAW_STATE_TESTS
3841
Tobin Ehlis57e6a612015-05-26 16:11:58 -06003842#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06003843#if GTEST_IS_THREADSAFE
3844struct thread_data_struct {
Chia-I Wu1f851912015-10-27 18:04:07 +08003845 VkCommandBuffer commandBuffer;
Mike Stroyan09aae812015-05-12 16:00:45 -06003846 VkEvent event;
3847 bool bailout;
3848};
3849
3850extern "C" void *AddToCommandBuffer(void *arg)
3851{
3852 struct thread_data_struct *data = (struct thread_data_struct *) arg;
Mike Stroyan09aae812015-05-12 16:00:45 -06003853
3854 for (int i = 0; i<10000; i++) {
Chia-I Wucba6cea2015-10-31 00:31:16 +08003855 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyan09aae812015-05-12 16:00:45 -06003856 if (data->bailout) {
3857 break;
3858 }
3859 }
3860 return NULL;
3861}
3862
Chia-I Wu1f851912015-10-27 18:04:07 +08003863TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyan09aae812015-05-12 16:00:45 -06003864{
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003865 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06003866
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003867 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "THREADING ERROR");
3868
Mike Stroyan09aae812015-05-12 16:00:45 -06003869 ASSERT_NO_FATAL_FAILURE(InitState());
3870 ASSERT_NO_FATAL_FAILURE(InitViewport());
3871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3872
Chia-I Wu1f851912015-10-27 18:04:07 +08003873 // Calls AllocateCommandBuffers
3874 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003875
3876 // Avoid creating RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08003877 commandBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003878
3879 VkEventCreateInfo event_info;
3880 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06003881 VkResult err;
3882
3883 memset(&event_info, 0, sizeof(event_info));
3884 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3885
Chia-I Wu69f40122015-10-26 21:10:41 +08003886 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyan09aae812015-05-12 16:00:45 -06003887 ASSERT_VK_SUCCESS(err);
3888
Mike Stroyan09aae812015-05-12 16:00:45 -06003889 err = vkResetEvent(device(), event);
3890 ASSERT_VK_SUCCESS(err);
3891
3892 struct thread_data_struct data;
Chia-I Wu1f851912015-10-27 18:04:07 +08003893 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06003894 data.event = event;
3895 data.bailout = false;
3896 m_errorMonitor->SetBailout(&data.bailout);
3897 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003898 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06003899 // Add many entries to command buffer from this thread at the same time.
3900 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003901
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003902 test_platform_thread_join(thread, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08003903 commandBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003904
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003905 if (!m_errorMonitor->DesiredMsgFound()) {
3906 FAIL() << "Did not receive Error 'THREADING ERROR' from using one VkCommandBufferObj in two threads";
3907 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan09aae812015-05-12 16:00:45 -06003908 }
3909
Chia-I Wu69f40122015-10-26 21:10:41 +08003910 vkDestroyEvent(device(), event, NULL);
Mike Stroyan09aae812015-05-12 16:00:45 -06003911}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003912#endif // GTEST_IS_THREADSAFE
3913#endif // THREADING_TESTS
3914
Chris Forbes5af3bf22015-05-25 11:13:08 +12003915#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003916TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
3917{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003918 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3919 "Shader is not SPIR-V");
3920
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003921 ASSERT_NO_FATAL_FAILURE(InitState());
3922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3923
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003924 VkShaderModule module;
3925 VkShaderModuleCreateInfo moduleCreateInfo;
3926 struct icd_spv_header spv;
3927
3928 spv.magic = ICD_SPV_MAGIC;
3929 spv.version = ICD_SPV_VERSION;
3930 spv.gen_magic = 0;
3931
3932 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3933 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08003934 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003935 moduleCreateInfo.codeSize = 4;
3936 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08003937 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003938
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003939 if (!m_errorMonitor->DesiredMsgFound()) {
3940 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
3941 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003942 }
3943}
3944
3945TEST_F(VkLayerTest, InvalidSPIRVMagic)
3946{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003947 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3948 "Shader is not SPIR-V");
3949
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003950 ASSERT_NO_FATAL_FAILURE(InitState());
3951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3952
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003953 VkShaderModule module;
3954 VkShaderModuleCreateInfo moduleCreateInfo;
3955 struct icd_spv_header spv;
3956
3957 spv.magic = ~ICD_SPV_MAGIC;
3958 spv.version = ICD_SPV_VERSION;
3959 spv.gen_magic = 0;
3960
3961 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3962 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08003963 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003964 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3965 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08003966 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003967
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003968 if (!m_errorMonitor->DesiredMsgFound()) {
3969 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
3970 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003971 }
3972}
3973
3974TEST_F(VkLayerTest, InvalidSPIRVVersion)
3975{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003976 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3977 "Shader is not SPIR-V");
3978
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003979 ASSERT_NO_FATAL_FAILURE(InitState());
3980 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3981
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003982 VkShaderModule module;
3983 VkShaderModuleCreateInfo moduleCreateInfo;
3984 struct icd_spv_header spv;
3985
3986 spv.magic = ICD_SPV_MAGIC;
3987 spv.version = ~ICD_SPV_VERSION;
3988 spv.gen_magic = 0;
3989
3990 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3991 moduleCreateInfo.pNext = NULL;
3992
Chia-I Wu036b1612015-10-26 19:22:06 +08003993 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003994 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3995 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08003996 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003997
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003998 if (!m_errorMonitor->DesiredMsgFound()) {
3999 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4000 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004001 }
4002}
4003
Chris Forbes5af3bf22015-05-25 11:13:08 +12004004TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
4005{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004006 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
4007 "not consumed by fragment shader");
4008
Chris Forbes5af3bf22015-05-25 11:13:08 +12004009 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004011
4012 char const *vsSource =
4013 "#version 140\n"
4014 "#extension GL_ARB_separate_shader_objects: require\n"
4015 "#extension GL_ARB_shading_language_420pack: require\n"
4016 "\n"
4017 "layout(location=0) out float x;\n"
4018 "void main(){\n"
4019 " gl_Position = vec4(1);\n"
4020 " x = 0;\n"
4021 "}\n";
4022 char const *fsSource =
4023 "#version 140\n"
4024 "#extension GL_ARB_separate_shader_objects: require\n"
4025 "#extension GL_ARB_shading_language_420pack: require\n"
4026 "\n"
4027 "layout(location=0) out vec4 color;\n"
4028 "void main(){\n"
4029 " color = vec4(1);\n"
4030 "}\n";
4031
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004032 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4033 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004034
4035 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004036 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004037 pipe.AddShader(&vs);
4038 pipe.AddShader(&fs);
4039
Chris Forbes5af3bf22015-05-25 11:13:08 +12004040 VkDescriptorSetObj descriptorSet(m_device);
4041 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004042 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004043
Tony Barboured132432015-08-04 16:23:11 -06004044 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004045
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004046 if (!m_errorMonitor->DesiredMsgFound()) {
4047 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
4048 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004049 }
4050}
Chris Forbes5af3bf22015-05-25 11:13:08 +12004051
Chris Forbes3c10b852015-05-25 11:13:13 +12004052TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4053{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004054 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4055 "not written by vertex shader");
4056
Chris Forbes3c10b852015-05-25 11:13:13 +12004057 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004058 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12004059
4060 char const *vsSource =
4061 "#version 140\n"
4062 "#extension GL_ARB_separate_shader_objects: require\n"
4063 "#extension GL_ARB_shading_language_420pack: require\n"
4064 "\n"
4065 "void main(){\n"
4066 " gl_Position = vec4(1);\n"
4067 "}\n";
4068 char const *fsSource =
4069 "#version 140\n"
4070 "#extension GL_ARB_separate_shader_objects: require\n"
4071 "#extension GL_ARB_shading_language_420pack: require\n"
4072 "\n"
4073 "layout(location=0) in float x;\n"
4074 "layout(location=0) out vec4 color;\n"
4075 "void main(){\n"
4076 " color = vec4(x);\n"
4077 "}\n";
4078
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004079 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4080 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes3c10b852015-05-25 11:13:13 +12004081
4082 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004083 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12004084 pipe.AddShader(&vs);
4085 pipe.AddShader(&fs);
4086
Chris Forbes3c10b852015-05-25 11:13:13 +12004087 VkDescriptorSetObj descriptorSet(m_device);
4088 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004089 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12004090
Tony Barboured132432015-08-04 16:23:11 -06004091 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12004092
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004093 if (!m_errorMonitor->DesiredMsgFound()) {
4094 FAIL() << "Did not receive Error 'not written by vertex shader'";
4095 m_errorMonitor->DumpFailureMsgs();
Chris Forbes3c10b852015-05-25 11:13:13 +12004096 }
4097}
4098
Chris Forbescc281692015-05-25 11:13:17 +12004099TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4100{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004101 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4102 "Type mismatch on location 0");
4103
Chris Forbescc281692015-05-25 11:13:17 +12004104 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12004106
4107 char const *vsSource =
4108 "#version 140\n"
4109 "#extension GL_ARB_separate_shader_objects: require\n"
4110 "#extension GL_ARB_shading_language_420pack: require\n"
4111 "\n"
4112 "layout(location=0) out int x;\n"
4113 "void main(){\n"
4114 " x = 0;\n"
4115 " gl_Position = vec4(1);\n"
4116 "}\n";
4117 char const *fsSource =
4118 "#version 140\n"
4119 "#extension GL_ARB_separate_shader_objects: require\n"
4120 "#extension GL_ARB_shading_language_420pack: require\n"
4121 "\n"
4122 "layout(location=0) in float x;\n" /* VS writes int */
4123 "layout(location=0) out vec4 color;\n"
4124 "void main(){\n"
4125 " color = vec4(x);\n"
4126 "}\n";
4127
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004128 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4129 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbescc281692015-05-25 11:13:17 +12004130
4131 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004132 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12004133 pipe.AddShader(&vs);
4134 pipe.AddShader(&fs);
4135
Chris Forbescc281692015-05-25 11:13:17 +12004136 VkDescriptorSetObj descriptorSet(m_device);
4137 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004138 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12004139
Tony Barboured132432015-08-04 16:23:11 -06004140 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12004141
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004142 if (!m_errorMonitor->DesiredMsgFound()) {
4143 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4144 m_errorMonitor->DumpFailureMsgs();
Chris Forbescc281692015-05-25 11:13:17 +12004145 }
4146}
4147
Chris Forbes8291c052015-05-25 11:13:28 +12004148TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4149{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004150 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
4151 "location 0 not consumed by VS");
4152
Chris Forbes8291c052015-05-25 11:13:28 +12004153 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12004155
4156 VkVertexInputBindingDescription input_binding;
4157 memset(&input_binding, 0, sizeof(input_binding));
4158
4159 VkVertexInputAttributeDescription input_attrib;
4160 memset(&input_attrib, 0, sizeof(input_attrib));
4161 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4162
4163 char const *vsSource =
4164 "#version 140\n"
4165 "#extension GL_ARB_separate_shader_objects: require\n"
4166 "#extension GL_ARB_shading_language_420pack: require\n"
4167 "\n"
4168 "void main(){\n"
4169 " gl_Position = vec4(1);\n"
4170 "}\n";
4171 char const *fsSource =
4172 "#version 140\n"
4173 "#extension GL_ARB_separate_shader_objects: require\n"
4174 "#extension GL_ARB_shading_language_420pack: require\n"
4175 "\n"
4176 "layout(location=0) out vec4 color;\n"
4177 "void main(){\n"
4178 " color = vec4(1);\n"
4179 "}\n";
4180
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004181 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4182 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes8291c052015-05-25 11:13:28 +12004183
4184 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004185 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12004186 pipe.AddShader(&vs);
4187 pipe.AddShader(&fs);
4188
4189 pipe.AddVertexInputBindings(&input_binding, 1);
4190 pipe.AddVertexInputAttribs(&input_attrib, 1);
4191
Chris Forbes8291c052015-05-25 11:13:28 +12004192 VkDescriptorSetObj descriptorSet(m_device);
4193 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004194 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12004195
Tony Barboured132432015-08-04 16:23:11 -06004196 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12004197
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004198 if (!m_errorMonitor->DesiredMsgFound()) {
4199 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
4200 m_errorMonitor->DumpFailureMsgs();
Chris Forbes8291c052015-05-25 11:13:28 +12004201 }
4202}
4203
Chris Forbes37367e62015-05-25 11:13:29 +12004204TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4205{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004206 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4207 "VS consumes input at location 0 but not provided");
4208
Chris Forbes37367e62015-05-25 11:13:29 +12004209 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004210 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12004211
4212 char const *vsSource =
4213 "#version 140\n"
4214 "#extension GL_ARB_separate_shader_objects: require\n"
4215 "#extension GL_ARB_shading_language_420pack: require\n"
4216 "\n"
4217 "layout(location=0) in vec4 x;\n" /* not provided */
4218 "void main(){\n"
4219 " gl_Position = x;\n"
4220 "}\n";
4221 char const *fsSource =
4222 "#version 140\n"
4223 "#extension GL_ARB_separate_shader_objects: require\n"
4224 "#extension GL_ARB_shading_language_420pack: require\n"
4225 "\n"
4226 "layout(location=0) out vec4 color;\n"
4227 "void main(){\n"
4228 " color = vec4(1);\n"
4229 "}\n";
4230
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004231 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4232 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes37367e62015-05-25 11:13:29 +12004233
4234 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004235 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12004236 pipe.AddShader(&vs);
4237 pipe.AddShader(&fs);
4238
Chris Forbes37367e62015-05-25 11:13:29 +12004239 VkDescriptorSetObj descriptorSet(m_device);
4240 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004241 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12004242
Tony Barboured132432015-08-04 16:23:11 -06004243 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12004244
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004245 if (!m_errorMonitor->DesiredMsgFound()) {
4246 FAIL() << "Did not receive Error 'VS consumes input at location 0 but not provided'";
4247 m_errorMonitor->DumpFailureMsgs();
Chris Forbes37367e62015-05-25 11:13:29 +12004248 }
4249}
4250
Chris Forbesa4b02322015-05-25 11:13:31 +12004251TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4252{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004253 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4254 "location 0 does not match VS input type");
4255
Chris Forbesa4b02322015-05-25 11:13:31 +12004256 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004257 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12004258
4259 VkVertexInputBindingDescription input_binding;
4260 memset(&input_binding, 0, sizeof(input_binding));
4261
4262 VkVertexInputAttributeDescription input_attrib;
4263 memset(&input_attrib, 0, sizeof(input_attrib));
4264 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4265
4266 char const *vsSource =
4267 "#version 140\n"
4268 "#extension GL_ARB_separate_shader_objects: require\n"
4269 "#extension GL_ARB_shading_language_420pack: require\n"
4270 "\n"
4271 "layout(location=0) in int x;\n" /* attrib provided float */
4272 "void main(){\n"
4273 " gl_Position = vec4(x);\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 "layout(location=0) out vec4 color;\n"
4281 "void main(){\n"
4282 " color = vec4(1);\n"
4283 "}\n";
4284
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004285 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4286 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa4b02322015-05-25 11:13:31 +12004287
4288 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004289 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12004290 pipe.AddShader(&vs);
4291 pipe.AddShader(&fs);
4292
4293 pipe.AddVertexInputBindings(&input_binding, 1);
4294 pipe.AddVertexInputAttribs(&input_attrib, 1);
4295
Chris Forbesa4b02322015-05-25 11:13:31 +12004296 VkDescriptorSetObj descriptorSet(m_device);
4297 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004298 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12004299
Tony Barboured132432015-08-04 16:23:11 -06004300 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12004301
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004302 if (!m_errorMonitor->DesiredMsgFound()) {
4303 FAIL() << "Did not receive Error 'location 0 does not match VS input type'";
4304 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa4b02322015-05-25 11:13:31 +12004305 }
4306}
4307
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004308TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
4309{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004310 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4311 "Duplicate vertex input binding descriptions for binding 0");
4312
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004313 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004315
4316 /* Two binding descriptions for binding 0 */
4317 VkVertexInputBindingDescription input_bindings[2];
4318 memset(input_bindings, 0, sizeof(input_bindings));
4319
4320 VkVertexInputAttributeDescription input_attrib;
4321 memset(&input_attrib, 0, sizeof(input_attrib));
4322 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4323
4324 char const *vsSource =
4325 "#version 140\n"
4326 "#extension GL_ARB_separate_shader_objects: require\n"
4327 "#extension GL_ARB_shading_language_420pack: require\n"
4328 "\n"
4329 "layout(location=0) in float x;\n" /* attrib provided float */
4330 "void main(){\n"
4331 " gl_Position = vec4(x);\n"
4332 "}\n";
4333 char const *fsSource =
4334 "#version 140\n"
4335 "#extension GL_ARB_separate_shader_objects: require\n"
4336 "#extension GL_ARB_shading_language_420pack: require\n"
4337 "\n"
4338 "layout(location=0) out vec4 color;\n"
4339 "void main(){\n"
4340 " color = vec4(1);\n"
4341 "}\n";
4342
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004343 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4344 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004345
4346 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004347 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004348 pipe.AddShader(&vs);
4349 pipe.AddShader(&fs);
4350
4351 pipe.AddVertexInputBindings(input_bindings, 2);
4352 pipe.AddVertexInputAttribs(&input_attrib, 1);
4353
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004354 VkDescriptorSetObj descriptorSet(m_device);
4355 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004356 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004357
Tony Barboured132432015-08-04 16:23:11 -06004358 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004359
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004360 if (!m_errorMonitor->DesiredMsgFound()) {
4361 FAIL() << "Did not receive Error 'Duplicate vertex input binding descriptions for binding 0'";
4362 m_errorMonitor->DumpFailureMsgs();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004363 }
4364}
Chris Forbes4c948702015-05-25 11:13:32 +12004365
Chris Forbesc12ef122015-05-25 11:13:40 +12004366/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
4367 * rejects it. */
4368
4369TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
4370{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004371 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4372 "Attachment 0 not written by FS");
4373
Chris Forbesc12ef122015-05-25 11:13:40 +12004374 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12004375
4376 char const *vsSource =
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 "void main(){\n"
4382 " gl_Position = vec4(1);\n"
4383 "}\n";
4384 char const *fsSource =
4385 "#version 140\n"
4386 "#extension GL_ARB_separate_shader_objects: require\n"
4387 "#extension GL_ARB_shading_language_420pack: require\n"
4388 "\n"
4389 "void main(){\n"
4390 "}\n";
4391
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004392 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4393 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc12ef122015-05-25 11:13:40 +12004394
4395 VkPipelineObj pipe(m_device);
4396 pipe.AddShader(&vs);
4397 pipe.AddShader(&fs);
4398
Chia-I Wuc278df82015-07-07 11:50:03 +08004399 /* set up CB 0, not written */
4400 pipe.AddColorAttachment();
4401 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12004402
Chris Forbesc12ef122015-05-25 11:13:40 +12004403 VkDescriptorSetObj descriptorSet(m_device);
4404 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004405 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12004406
Tony Barboured132432015-08-04 16:23:11 -06004407 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12004408
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004409 if (!m_errorMonitor->DesiredMsgFound()) {
4410 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
4411 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc12ef122015-05-25 11:13:40 +12004412 }
4413}
4414
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004415TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
4416{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004417 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
4418 "FS writes to output location 1 with no matching attachment");
4419
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004420 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004421
4422 char const *vsSource =
4423 "#version 140\n"
4424 "#extension GL_ARB_separate_shader_objects: require\n"
4425 "#extension GL_ARB_shading_language_420pack: require\n"
4426 "\n"
4427 "void main(){\n"
4428 " gl_Position = vec4(1);\n"
4429 "}\n";
4430 char const *fsSource =
4431 "#version 140\n"
4432 "#extension GL_ARB_separate_shader_objects: require\n"
4433 "#extension GL_ARB_shading_language_420pack: require\n"
4434 "\n"
4435 "layout(location=0) out vec4 x;\n"
4436 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4437 "void main(){\n"
4438 " x = vec4(1);\n"
4439 " y = vec4(1);\n"
4440 "}\n";
4441
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004442 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4443 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004444
4445 VkPipelineObj pipe(m_device);
4446 pipe.AddShader(&vs);
4447 pipe.AddShader(&fs);
4448
Chia-I Wuc278df82015-07-07 11:50:03 +08004449 /* set up CB 0, not written */
4450 pipe.AddColorAttachment();
4451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004452 /* FS writes CB 1, but we don't configure it */
4453
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004454 VkDescriptorSetObj descriptorSet(m_device);
4455 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004456 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004457
Tony Barboured132432015-08-04 16:23:11 -06004458 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004459
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004460 if (!m_errorMonitor->DesiredMsgFound()) {
4461 FAIL() << "Did not receive Error 'FS writes to output location 1 with no matching attachment'";
4462 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004463 }
4464}
4465
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004466TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4467{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004468 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4469 "does not match FS output type");
4470
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004471 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004472
4473 char const *vsSource =
4474 "#version 140\n"
4475 "#extension GL_ARB_separate_shader_objects: require\n"
4476 "#extension GL_ARB_shading_language_420pack: require\n"
4477 "\n"
4478 "void main(){\n"
4479 " gl_Position = vec4(1);\n"
4480 "}\n";
4481 char const *fsSource =
4482 "#version 140\n"
4483 "#extension GL_ARB_separate_shader_objects: require\n"
4484 "#extension GL_ARB_shading_language_420pack: require\n"
4485 "\n"
4486 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4487 "void main(){\n"
4488 " x = ivec4(1);\n"
4489 "}\n";
4490
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004491 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4492 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004493
4494 VkPipelineObj pipe(m_device);
4495 pipe.AddShader(&vs);
4496 pipe.AddShader(&fs);
4497
Chia-I Wuc278df82015-07-07 11:50:03 +08004498 /* set up CB 0; type is UNORM by default */
4499 pipe.AddColorAttachment();
4500 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004501
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004502 VkDescriptorSetObj descriptorSet(m_device);
4503 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004504 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004505
Tony Barboured132432015-08-04 16:23:11 -06004506 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004507
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004508 if (!m_errorMonitor->DesiredMsgFound()) {
4509 FAIL() << "Did not receive Error 'does not match FS output type'";
4510 m_errorMonitor->DumpFailureMsgs();
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004511 }
4512}
Chris Forbesc2050732015-06-05 14:43:36 +12004513
Chris Forbes76ce7882015-08-14 12:04:59 +12004514TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4515{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004516 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4517 "not declared in pipeline layout");
4518
Chris Forbes76ce7882015-08-14 12:04:59 +12004519 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12004520
4521 char const *vsSource =
4522 "#version 140\n"
4523 "#extension GL_ARB_separate_shader_objects: require\n"
4524 "#extension GL_ARB_shading_language_420pack: require\n"
4525 "\n"
4526 "void main(){\n"
4527 " gl_Position = vec4(1);\n"
4528 "}\n";
4529 char const *fsSource =
4530 "#version 140\n"
4531 "#extension GL_ARB_separate_shader_objects: require\n"
4532 "#extension GL_ARB_shading_language_420pack: require\n"
4533 "\n"
4534 "layout(location=0) out vec4 x;\n"
4535 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4536 "void main(){\n"
4537 " x = vec4(bar.y);\n"
4538 "}\n";
4539
Chris Forbes76ce7882015-08-14 12:04:59 +12004540
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004541 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4542 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes76ce7882015-08-14 12:04:59 +12004543
Chris Forbes76ce7882015-08-14 12:04:59 +12004544 VkPipelineObj pipe(m_device);
4545 pipe.AddShader(&vs);
4546 pipe.AddShader(&fs);
4547
4548 /* set up CB 0; type is UNORM by default */
4549 pipe.AddColorAttachment();
4550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4551
4552 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1f851912015-10-27 18:04:07 +08004553 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes76ce7882015-08-14 12:04:59 +12004554
4555 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4556
4557 /* should have generated an error -- pipeline layout does not
4558 * provide a uniform buffer in 0.0
4559 */
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004560 if (!m_errorMonitor->DesiredMsgFound()) {
4561 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
4562 m_errorMonitor->DumpFailureMsgs();
Chris Forbes76ce7882015-08-14 12:04:59 +12004563 }
4564}
4565
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004566#endif // SHADER_CHECKER_TESTS
4567
4568#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004569TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4570{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004571 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4572 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004573
4574 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004575
4576 // Create an image
4577 VkImage image;
4578
4579 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4580 const int32_t tex_width = 32;
4581 const int32_t tex_height = 32;
4582
4583 VkImageCreateInfo image_create_info = {};
4584 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4585 image_create_info.pNext = NULL;
4586 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4587 image_create_info.format = tex_format;
4588 image_create_info.extent.width = tex_width;
4589 image_create_info.extent.height = tex_height;
4590 image_create_info.extent.depth = 1;
4591 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004592 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004593 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004594 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4595 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4596 image_create_info.flags = 0;
4597
4598 // Introduce error by sending down a bogus width extent
4599 image_create_info.extent.width = 65536;
Chia-I Wu69f40122015-10-26 21:10:41 +08004600 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004601
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004602 if (!m_errorMonitor->DesiredMsgFound()) {
4603 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable limits for format'";
4604 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004605 }
4606}
4607
4608TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4609{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004610 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4611 "CreateImage resource size exceeds allowable maximum");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004612
4613 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004614
4615 // Create an image
4616 VkImage image;
4617
4618 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4619 const int32_t tex_width = 32;
4620 const int32_t tex_height = 32;
4621
4622 VkImageCreateInfo image_create_info = {};
4623 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4624 image_create_info.pNext = NULL;
4625 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4626 image_create_info.format = tex_format;
4627 image_create_info.extent.width = tex_width;
4628 image_create_info.extent.height = tex_height;
4629 image_create_info.extent.depth = 1;
4630 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004631 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004632 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004633 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4634 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4635 image_create_info.flags = 0;
4636
4637 // Introduce error by sending down individually allowable values that result in a surface size
4638 // exceeding the device maximum
4639 image_create_info.extent.width = 8192;
4640 image_create_info.extent.height = 8192;
4641 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004642 image_create_info.arrayLayers = 4;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004643 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004644 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
Chia-I Wu69f40122015-10-26 21:10:41 +08004645 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004646
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004647 if (!m_errorMonitor->DesiredMsgFound()) {
4648 FAIL() << "Did not receive Error 'CreateImage resource size exceeds allowable maximum'";
4649 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004650 }
4651}
4652
Mike Stroyan43909d82015-09-25 13:39:21 -06004653TEST_F(VkLayerTest, UpdateBufferAlignment)
4654{
Mike Stroyan43909d82015-09-25 13:39:21 -06004655 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4656
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004657 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4658 "dstOffset, is not a multiple of 4");
4659
Mike Stroyan43909d82015-09-25 13:39:21 -06004660 ASSERT_NO_FATAL_FAILURE(InitState());
4661
4662 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4663 vk_testing::Buffer buffer;
4664 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4665
4666 BeginCommandBuffer();
4667 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08004668 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004669 if (!m_errorMonitor->DesiredMsgFound()) {
4670 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
4671 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004672 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004673
Mike Stroyan43909d82015-09-25 13:39:21 -06004674 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004675 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4676 "dataSize, is not a multiple of 4");
4677
Chia-I Wu1f851912015-10-27 18:04:07 +08004678 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004679
4680 if (!m_errorMonitor->DesiredMsgFound()) {
4681 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4682 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004683 }
4684 EndCommandBuffer();
4685}
4686
4687TEST_F(VkLayerTest, FillBufferAlignment)
4688{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004689 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4690 "dstOffset, is not a multiple of 4");
Mike Stroyan43909d82015-09-25 13:39:21 -06004691
4692 ASSERT_NO_FATAL_FAILURE(InitState());
4693
4694 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4695 vk_testing::Buffer buffer;
4696 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4697
4698 BeginCommandBuffer();
4699 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08004700 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004701 if (!m_errorMonitor->DesiredMsgFound()) {
4702 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
4703 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004704 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004705
Mike Stroyan43909d82015-09-25 13:39:21 -06004706 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004707 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4708 "size, is not a multiple of 4");
4709
Chia-I Wu1f851912015-10-27 18:04:07 +08004710 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004711
4712 if (!m_errorMonitor->DesiredMsgFound()) {
4713 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
4714 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004715 }
4716 EndCommandBuffer();
4717}
4718
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004719#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004720
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004721#if IMAGE_TESTS
4722TEST_F(VkLayerTest, InvalidImageView)
4723{
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004724 VkResult err;
4725
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004726 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4727 "vkCreateImageView called with baseMipLevel 10 ");
4728
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004729 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004730
Mike Stroyan43909d82015-09-25 13:39:21 -06004731 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004732 VkImage image;
4733
4734 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4735 const int32_t tex_width = 32;
4736 const int32_t tex_height = 32;
4737
4738 VkImageCreateInfo image_create_info = {};
4739 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4740 image_create_info.pNext = NULL;
4741 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4742 image_create_info.format = tex_format;
4743 image_create_info.extent.width = tex_width;
4744 image_create_info.extent.height = tex_height;
4745 image_create_info.extent.depth = 1;
4746 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004747 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004748 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004749 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4750 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4751 image_create_info.flags = 0;
4752
Chia-I Wu69f40122015-10-26 21:10:41 +08004753 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004754 ASSERT_VK_SUCCESS(err);
4755
4756 VkImageViewCreateInfo image_view_create_info = {};
4757 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4758 image_view_create_info.image = image;
4759 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4760 image_view_create_info.format = tex_format;
Chia-I Wu1f851912015-10-27 18:04:07 +08004761 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004762 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu1f851912015-10-27 18:04:07 +08004763 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004764 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004765
4766 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08004767 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004768
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004769 if (!m_errorMonitor->DesiredMsgFound()) {
4770 FAIL() << "Did not receive Error 'vkCreateImageView called with baseMipLevel 10...'";
4771 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004772 }
4773}
Mike Stroyan43909d82015-09-25 13:39:21 -06004774
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004775TEST_F(VkLayerTest, InvalidImageViewAspect)
4776{
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004777 VkResult err;
4778
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004779 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4780 "vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set");
4781
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004782 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004783
4784 // Create an image and try to create a view with an invalid aspectMask
4785 VkImage image;
4786
4787 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4788 const int32_t tex_width = 32;
4789 const int32_t tex_height = 32;
4790
4791 VkImageCreateInfo image_create_info = {};
4792 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4793 image_create_info.pNext = NULL;
4794 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4795 image_create_info.format = tex_format;
4796 image_create_info.extent.width = tex_width;
4797 image_create_info.extent.height = tex_height;
4798 image_create_info.extent.depth = 1;
4799 image_create_info.mipLevels = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004800 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004801 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4802 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4803 image_create_info.flags = 0;
4804
Chia-I Wu69f40122015-10-26 21:10:41 +08004805 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004806 ASSERT_VK_SUCCESS(err);
4807
4808 VkImageViewCreateInfo image_view_create_info = {};
4809 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4810 image_view_create_info.image = image;
4811 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4812 image_view_create_info.format = tex_format;
4813 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08004814 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004815 // Cause an error by setting an invalid image aspect
4816 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
4817
4818 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08004819 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004820
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004821 if (!m_errorMonitor->DesiredMsgFound()) {
4822 FAIL() << "Did not receive Error 'VkCreateImageView: Color image formats must have ...'";
4823 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004824 }
4825}
4826
Mike Stroyan43909d82015-09-25 13:39:21 -06004827TEST_F(VkLayerTest, CopyImageTypeMismatch)
4828{
Mike Stroyan43909d82015-09-25 13:39:21 -06004829 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004830 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004831
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004832 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4833 "vkCmdCopyImage called with unmatched source and dest image types");
4834
Mike Stroyan43909d82015-09-25 13:39:21 -06004835 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06004836
4837 // Create two images of different types and try to copy between them
4838 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08004839 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06004840 VkDeviceMemory srcMem;
4841 VkDeviceMemory destMem;
4842 VkMemoryRequirements memReqs;
4843
4844 VkImageCreateInfo image_create_info = {};
4845 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4846 image_create_info.pNext = NULL;
4847 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4848 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4849 image_create_info.extent.width = 32;
4850 image_create_info.extent.height = 32;
4851 image_create_info.extent.depth = 1;
4852 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004853 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004854 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004855 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08004856 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004857 image_create_info.flags = 0;
4858
Chia-I Wu69f40122015-10-26 21:10:41 +08004859 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06004860 ASSERT_VK_SUCCESS(err);
4861
4862 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08004863 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004864
Chia-I Wu1f851912015-10-27 18:04:07 +08004865 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06004866 ASSERT_VK_SUCCESS(err);
4867
4868 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08004869 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06004870 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4871 memAlloc.pNext = NULL;
4872 memAlloc.allocationSize = 0;
4873 memAlloc.memoryTypeIndex = 0;
4874
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004875 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004876 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004877 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4878 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08004879 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06004880 ASSERT_VK_SUCCESS(err);
4881
Chia-I Wu1f851912015-10-27 18:04:07 +08004882 vkGetImageMemoryRequirements(m_device->device(), dstImage, &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);
Mike Stroyan43909d82015-09-25 13:39:21 -06004885 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08004886 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06004887 ASSERT_VK_SUCCESS(err);
4888
4889 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4890 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08004891 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06004892 ASSERT_VK_SUCCESS(err);
4893
4894 BeginCommandBuffer();
4895 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08004896 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004897 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004898 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08004899 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004900 copyRegion.srcOffset.x = 0;
4901 copyRegion.srcOffset.y = 0;
4902 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08004903 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08004904 copyRegion.dstSubresource.mipLevel = 0;
4905 copyRegion.dstSubresource.baseArrayLayer = 0;
4906 copyRegion.dstSubresource.layerCount = 0;
4907 copyRegion.dstOffset.x = 0;
4908 copyRegion.dstOffset.y = 0;
4909 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004910 copyRegion.extent.width = 1;
4911 copyRegion.extent.height = 1;
4912 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08004913 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06004914 EndCommandBuffer();
4915
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004916 if (!m_errorMonitor->DesiredMsgFound()) {
4917 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
4918 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004919 }
4920
Chia-I Wu69f40122015-10-26 21:10:41 +08004921 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08004922 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08004923 vkFreeMemory(m_device->device(), srcMem, NULL);
4924 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06004925}
4926
4927TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
4928{
4929 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
4930}
4931
4932TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
4933{
Mike Stroyan43909d82015-09-25 13:39:21 -06004934 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004935 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004936
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004937 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4938 "vkCmdCopyImage called with unmatched source and dest image types");
4939
Mike Stroyan43909d82015-09-25 13:39:21 -06004940 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06004941
4942 // Create two images of different types and try to copy between them
4943 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08004944 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06004945 VkDeviceMemory srcMem;
4946 VkDeviceMemory destMem;
4947 VkMemoryRequirements memReqs;
4948
4949 VkImageCreateInfo image_create_info = {};
4950 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4951 image_create_info.pNext = NULL;
4952 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4953 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4954 image_create_info.extent.width = 32;
4955 image_create_info.extent.height = 32;
4956 image_create_info.extent.depth = 1;
4957 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004958 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004959 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004960 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08004961 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004962 image_create_info.flags = 0;
4963
Chia-I Wu69f40122015-10-26 21:10:41 +08004964 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06004965 ASSERT_VK_SUCCESS(err);
4966
4967 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08004968 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004969
Chia-I Wu1f851912015-10-27 18:04:07 +08004970 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06004971 ASSERT_VK_SUCCESS(err);
4972
4973 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08004974 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06004975 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4976 memAlloc.pNext = NULL;
4977 memAlloc.allocationSize = 0;
4978 memAlloc.memoryTypeIndex = 0;
4979
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004980 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004981 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004982 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4983 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08004984 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06004985 ASSERT_VK_SUCCESS(err);
4986
Chia-I Wu1f851912015-10-27 18:04:07 +08004987 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004988 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004989 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4990 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08004991 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06004992 ASSERT_VK_SUCCESS(err);
4993
4994 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4995 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08004996 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06004997 ASSERT_VK_SUCCESS(err);
4998
4999 BeginCommandBuffer();
5000 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005001 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005002 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005003 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005004 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005005 copyRegion.srcOffset.x = 0;
5006 copyRegion.srcOffset.y = 0;
5007 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005008 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005009 copyRegion.dstSubresource.mipLevel = 0;
5010 copyRegion.dstSubresource.baseArrayLayer = 0;
5011 copyRegion.dstSubresource.layerCount = 0;
5012 copyRegion.dstOffset.x = 0;
5013 copyRegion.dstOffset.y = 0;
5014 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005015 copyRegion.extent.width = 1;
5016 copyRegion.extent.height = 1;
5017 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005018 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005019 EndCommandBuffer();
5020
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005021 if (!m_errorMonitor->DesiredMsgFound()) {
5022 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5023 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005024 }
5025
Chia-I Wu69f40122015-10-26 21:10:41 +08005026 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005027 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005028 vkFreeMemory(m_device->device(), srcMem, NULL);
5029 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005030}
5031
5032TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5033{
Mike Stroyan43909d82015-09-25 13:39:21 -06005034 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005035 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005036
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005037 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5038 "vkCmdResolveImage called with source sample count less than 2.");
5039
Mike Stroyan43909d82015-09-25 13:39:21 -06005040 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005041
5042 // Create two images of sample count 1 and try to Resolve between them
5043 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005044 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005045 VkDeviceMemory srcMem;
5046 VkDeviceMemory destMem;
5047 VkMemoryRequirements memReqs;
5048
5049 VkImageCreateInfo image_create_info = {};
5050 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5051 image_create_info.pNext = NULL;
5052 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5053 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5054 image_create_info.extent.width = 32;
5055 image_create_info.extent.height = 1;
5056 image_create_info.extent.depth = 1;
5057 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005058 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005059 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005060 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005061 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005062 image_create_info.flags = 0;
5063
Chia-I Wu69f40122015-10-26 21:10:41 +08005064 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005065 ASSERT_VK_SUCCESS(err);
5066
5067 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005068 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005069
Chia-I Wu1f851912015-10-27 18:04:07 +08005070 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005071 ASSERT_VK_SUCCESS(err);
5072
5073 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005074 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06005075 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5076 memAlloc.pNext = NULL;
5077 memAlloc.allocationSize = 0;
5078 memAlloc.memoryTypeIndex = 0;
5079
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005080 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005081 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005082 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5083 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005084 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005085 ASSERT_VK_SUCCESS(err);
5086
Chia-I Wu1f851912015-10-27 18:04:07 +08005087 vkGetImageMemoryRequirements(m_device->device(), dstImage, &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);
Chia-I Wu1f851912015-10-27 18:04:07 +08005091 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005092 ASSERT_VK_SUCCESS(err);
5093
5094 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5095 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005096 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005097 ASSERT_VK_SUCCESS(err);
5098
5099 BeginCommandBuffer();
5100 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5101 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5102 //VK_IMAGE_LAYOUT_GENERAL = 1,
5103 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005104 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005105 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005106 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005107 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005108 resolveRegion.srcOffset.x = 0;
5109 resolveRegion.srcOffset.y = 0;
5110 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005111 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005112 resolveRegion.dstSubresource.mipLevel = 0;
5113 resolveRegion.dstSubresource.baseArrayLayer = 0;
5114 resolveRegion.dstSubresource.layerCount = 0;
5115 resolveRegion.dstOffset.x = 0;
5116 resolveRegion.dstOffset.y = 0;
5117 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005118 resolveRegion.extent.width = 1;
5119 resolveRegion.extent.height = 1;
5120 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005121 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005122 EndCommandBuffer();
5123
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005124 if (!m_errorMonitor->DesiredMsgFound()) {
5125 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source sample count less than 2.'";
5126 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005127 }
5128
Chia-I Wu69f40122015-10-26 21:10:41 +08005129 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005130 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005131 vkFreeMemory(m_device->device(), srcMem, NULL);
5132 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005133}
5134
5135TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5136{
Mike Stroyan43909d82015-09-25 13:39:21 -06005137 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005138 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005139
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005140 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5141 "vkCmdResolveImage called with dest sample count greater than 1.");
5142
Mike Stroyan43909d82015-09-25 13:39:21 -06005143 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005144
5145 // Create two images of sample count 2 and try to Resolve between them
5146 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005147 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005148 VkDeviceMemory srcMem;
5149 VkDeviceMemory destMem;
5150 VkMemoryRequirements memReqs;
5151
5152 VkImageCreateInfo image_create_info = {};
5153 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5154 image_create_info.pNext = NULL;
5155 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5156 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5157 image_create_info.extent.width = 32;
5158 image_create_info.extent.height = 1;
5159 image_create_info.extent.depth = 1;
5160 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005161 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005162 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005163 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005164 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005165 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005166 image_create_info.flags = 0;
5167
Chia-I Wu69f40122015-10-26 21:10:41 +08005168 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005169 ASSERT_VK_SUCCESS(err);
5170
5171 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005172 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005173 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005174
Chia-I Wu1f851912015-10-27 18:04:07 +08005175 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005176 ASSERT_VK_SUCCESS(err);
5177
5178 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005179 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06005180 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5181 memAlloc.pNext = NULL;
5182 memAlloc.allocationSize = 0;
5183 memAlloc.memoryTypeIndex = 0;
5184
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005185 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005186 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005187 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5188 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005189 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005190 ASSERT_VK_SUCCESS(err);
5191
Chia-I Wu1f851912015-10-27 18:04:07 +08005192 vkGetImageMemoryRequirements(m_device->device(), dstImage, &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);
Chia-I Wu1f851912015-10-27 18:04:07 +08005196 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005197 ASSERT_VK_SUCCESS(err);
5198
5199 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5200 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005201 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005202 ASSERT_VK_SUCCESS(err);
5203
5204 BeginCommandBuffer();
5205 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5206 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5207 //VK_IMAGE_LAYOUT_GENERAL = 1,
5208 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005209 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005210 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005211 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005212 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005213 resolveRegion.srcOffset.x = 0;
5214 resolveRegion.srcOffset.y = 0;
5215 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005216 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005217 resolveRegion.dstSubresource.mipLevel = 0;
5218 resolveRegion.dstSubresource.baseArrayLayer = 0;
5219 resolveRegion.dstSubresource.layerCount = 0;
5220 resolveRegion.dstOffset.x = 0;
5221 resolveRegion.dstOffset.y = 0;
5222 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005223 resolveRegion.extent.width = 1;
5224 resolveRegion.extent.height = 1;
5225 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005226 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005227 EndCommandBuffer();
5228
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005229 if (!m_errorMonitor->DesiredMsgFound()) {
5230 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest sample count greater than 1.'";
5231 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005232 }
5233
Chia-I Wu69f40122015-10-26 21:10:41 +08005234 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005235 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005236 vkFreeMemory(m_device->device(), srcMem, NULL);
5237 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005238}
5239
5240TEST_F(VkLayerTest, ResolveImageFormatMismatch)
5241{
Mike Stroyan43909d82015-09-25 13:39:21 -06005242 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005243 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005244
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005245 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5246 "vkCmdResolveImage called with unmatched source and dest formats.");
5247
Mike Stroyan43909d82015-09-25 13:39:21 -06005248 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005249
5250 // Create two images of different types and try to copy between them
5251 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005252 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005253 VkDeviceMemory srcMem;
5254 VkDeviceMemory destMem;
5255 VkMemoryRequirements memReqs;
5256
5257 VkImageCreateInfo image_create_info = {};
5258 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5259 image_create_info.pNext = NULL;
5260 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5261 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5262 image_create_info.extent.width = 32;
5263 image_create_info.extent.height = 1;
5264 image_create_info.extent.depth = 1;
5265 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005266 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005267 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005268 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005269 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005270 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005271 image_create_info.flags = 0;
5272
Chia-I Wu69f40122015-10-26 21:10:41 +08005273 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005274 ASSERT_VK_SUCCESS(err);
5275
Cody Northropb3bf94f2015-10-27 13:50:04 -06005276 // Set format to something other than source image
5277 image_create_info.format = VK_FORMAT_R32_SFLOAT;
5278 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005279 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005280 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005281
Chia-I Wu1f851912015-10-27 18:04:07 +08005282 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005283 ASSERT_VK_SUCCESS(err);
5284
5285 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005286 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06005287 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5288 memAlloc.pNext = NULL;
5289 memAlloc.allocationSize = 0;
5290 memAlloc.memoryTypeIndex = 0;
5291
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005292 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005293 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005294 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5295 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005296 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005297 ASSERT_VK_SUCCESS(err);
5298
Chia-I Wu1f851912015-10-27 18:04:07 +08005299 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005300 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005301 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5302 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005303 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005304 ASSERT_VK_SUCCESS(err);
5305
5306 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5307 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005308 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005309 ASSERT_VK_SUCCESS(err);
5310
5311 BeginCommandBuffer();
5312 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5313 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5314 //VK_IMAGE_LAYOUT_GENERAL = 1,
5315 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005316 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005317 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005318 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005319 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005320 resolveRegion.srcOffset.x = 0;
5321 resolveRegion.srcOffset.y = 0;
5322 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005323 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005324 resolveRegion.dstSubresource.mipLevel = 0;
5325 resolveRegion.dstSubresource.baseArrayLayer = 0;
5326 resolveRegion.dstSubresource.layerCount = 0;
5327 resolveRegion.dstOffset.x = 0;
5328 resolveRegion.dstOffset.y = 0;
5329 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005330 resolveRegion.extent.width = 1;
5331 resolveRegion.extent.height = 1;
5332 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005333 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005334 EndCommandBuffer();
5335
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005336 if (!m_errorMonitor->DesiredMsgFound()) {
5337 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest formats.'";
5338 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005339 }
5340
Chia-I Wu69f40122015-10-26 21:10:41 +08005341 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005342 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005343 vkFreeMemory(m_device->device(), srcMem, NULL);
5344 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005345}
5346
5347TEST_F(VkLayerTest, ResolveImageTypeMismatch)
5348{
Mike Stroyan43909d82015-09-25 13:39:21 -06005349 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005350 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005351
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005352 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5353 "vkCmdResolveImage called with unmatched source and dest image types.");
5354
Mike Stroyan43909d82015-09-25 13:39:21 -06005355 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005356
5357 // Create two images of different types and try to copy between them
5358 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005359 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005360 VkDeviceMemory srcMem;
5361 VkDeviceMemory destMem;
5362 VkMemoryRequirements memReqs;
5363
5364 VkImageCreateInfo image_create_info = {};
5365 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5366 image_create_info.pNext = NULL;
5367 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5368 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5369 image_create_info.extent.width = 32;
5370 image_create_info.extent.height = 1;
5371 image_create_info.extent.depth = 1;
5372 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005373 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005374 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005375 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005376 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005377 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005378 image_create_info.flags = 0;
5379
Chia-I Wu69f40122015-10-26 21:10:41 +08005380 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005381 ASSERT_VK_SUCCESS(err);
5382
5383 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005384 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005385 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005386 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005387
Chia-I Wu1f851912015-10-27 18:04:07 +08005388 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005389 ASSERT_VK_SUCCESS(err);
5390
5391 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005392 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06005393 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5394 memAlloc.pNext = NULL;
5395 memAlloc.allocationSize = 0;
5396 memAlloc.memoryTypeIndex = 0;
5397
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005398 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005399 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005400 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5401 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005402 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005403 ASSERT_VK_SUCCESS(err);
5404
Chia-I Wu1f851912015-10-27 18:04:07 +08005405 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005406 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005407 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5408 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005409 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005410 ASSERT_VK_SUCCESS(err);
5411
5412 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5413 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005414 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005415 ASSERT_VK_SUCCESS(err);
5416
5417 BeginCommandBuffer();
5418 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5419 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5420 //VK_IMAGE_LAYOUT_GENERAL = 1,
5421 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005422 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005423 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005424 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005425 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005426 resolveRegion.srcOffset.x = 0;
5427 resolveRegion.srcOffset.y = 0;
5428 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005429 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005430 resolveRegion.dstSubresource.mipLevel = 0;
5431 resolveRegion.dstSubresource.baseArrayLayer = 0;
5432 resolveRegion.dstSubresource.layerCount = 0;
5433 resolveRegion.dstOffset.x = 0;
5434 resolveRegion.dstOffset.y = 0;
5435 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005436 resolveRegion.extent.width = 1;
5437 resolveRegion.extent.height = 1;
5438 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005439 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005440 EndCommandBuffer();
5441
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005442 if (!m_errorMonitor->DesiredMsgFound()) {
5443 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest image types.'";
5444 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005445 }
5446
Chia-I Wu69f40122015-10-26 21:10:41 +08005447 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005448 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005449 vkFreeMemory(m_device->device(), srcMem, NULL);
5450 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005451}
Tobin Ehlisb46be812015-10-23 16:00:08 -06005452
5453TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
5454{
5455 // Create a single Image descriptor and cause it to first hit an error due
5456 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
5457 // The image format check comes 2nd in validation so we trigger it first,
5458 // then when we cause aspect fail next, bad format check will be preempted
Tobin Ehlisb46be812015-10-23 16:00:08 -06005459 VkResult err;
5460
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005461 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5462 "Combination depth/stencil image formats can have only the ");
5463
Tobin Ehlisb46be812015-10-23 16:00:08 -06005464 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005465
Chia-I Wuc51b1212015-10-27 19:25:11 +08005466 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06005467 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu763a7492015-10-26 20:48:51 +08005468 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005469
5470 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5471 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5472 ds_pool_ci.pNext = NULL;
5473 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08005474 ds_pool_ci.poolSizeCount = 1;
5475 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005476
5477 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08005478 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005479 ASSERT_VK_SUCCESS(err);
5480
5481 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08005482 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005483 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5484 dsl_binding.arraySize = 1;
5485 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5486 dsl_binding.pImmutableSamplers = NULL;
5487
5488 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5489 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5490 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08005491 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08005492 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005493 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08005494 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005495 ASSERT_VK_SUCCESS(err);
5496
5497 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08005498 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06005499 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08005500 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005501 alloc_info.descriptorPool = ds_pool;
5502 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08005503 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005504 ASSERT_VK_SUCCESS(err);
5505
5506 VkImage image_bad;
5507 VkImage image_good;
5508 // One bad format and one good format for Color attachment
5509 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
5510 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
5511 const int32_t tex_width = 32;
5512 const int32_t tex_height = 32;
5513
5514 VkImageCreateInfo image_create_info = {};
5515 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5516 image_create_info.pNext = NULL;
5517 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5518 image_create_info.format = tex_format_bad;
5519 image_create_info.extent.width = tex_width;
5520 image_create_info.extent.height = tex_height;
5521 image_create_info.extent.depth = 1;
5522 image_create_info.mipLevels = 1;
5523 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005524 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005525 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5526 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
5527 image_create_info.flags = 0;
5528
Chia-I Wu69f40122015-10-26 21:10:41 +08005529 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005530 ASSERT_VK_SUCCESS(err);
5531 image_create_info.format = tex_format_good;
5532 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu69f40122015-10-26 21:10:41 +08005533 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005534 ASSERT_VK_SUCCESS(err);
5535
5536 VkImageViewCreateInfo image_view_create_info = {};
5537 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5538 image_view_create_info.image = image_bad;
5539 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5540 image_view_create_info.format = tex_format_bad;
5541 image_view_create_info.subresourceRange.baseArrayLayer = 0;
5542 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005543 image_view_create_info.subresourceRange.layerCount = 1;
5544 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005545 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5546
5547 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08005548 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005549
5550 if (!m_errorMonitor->DesiredMsgFound()) {
5551 FAIL() << "Did not receive Error 'Combination depth-stencil image formats can have only the....'";
5552 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06005553 }
5554
Chia-I Wu69f40122015-10-26 21:10:41 +08005555 vkDestroyImage(m_device->device(), image_bad, NULL);
5556 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005557 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5558 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005559}
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005560#endif // IMAGE_TESTS
5561
Tony Barbour30486ea2015-04-07 13:44:53 -06005562int main(int argc, char **argv) {
5563 int result;
5564
5565 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06005566 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06005567
5568 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
5569
5570 result = RUN_ALL_TESTS();
5571
Tony Barbour01999182015-04-09 12:58:51 -06005572 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06005573 return result;
5574}