blob: 07842c716ec8b123a03d1a6814e764136628005b [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;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600564 image_create_info.samples = 1;
565 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,
639// .samples = 1,
640// .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;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600711 image_create_info.samples = 1;
712 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,
846 .samples = 1,
847 .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 = {};
901 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
902 dsl_binding.arraySize = 1;
903 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
904 dsl_binding.pImmutableSamplers = NULL;
905
906 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
907 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
908 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800909 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +0800910 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600911
912 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +0800913 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600914 ASSERT_VK_SUCCESS(err);
915
916 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +0800917 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -0600918 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +0800919 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -0600920 alloc_info.descriptorPool = ds_pool;
921 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +0800922 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600923 ASSERT_VK_SUCCESS(err);
924
925 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
926 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
927 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800928 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600929 pipeline_layout_ci.pSetLayouts = &ds_layout;
930
931 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +0800932 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600933 ASSERT_VK_SUCCESS(err);
934
935 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
936
937 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800938 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600939
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600940 if (!m_errorMonitor->DesiredMsgFound()) {
941 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be'" << endl;
942 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600943 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600944
Chia-I Wu69f40122015-10-26 21:10:41 +0800945 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
946 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
947 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600948}
949
950TEST_F(VkLayerTest, BindInvalidMemory)
951{
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600952 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600953 bool pass;
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600954
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600955 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
956 "Invalid VkDeviceMemory Object ");
957
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600958 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600959
960 // Create an image, allocate memory, free it, and then try to bind it
961 VkImage image;
962 VkDeviceMemory mem;
963 VkMemoryRequirements mem_reqs;
964
965 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
966 const int32_t tex_width = 32;
967 const int32_t tex_height = 32;
968
969 VkImageCreateInfo image_create_info = {};
970 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
971 image_create_info.pNext = NULL;
972 image_create_info.imageType = VK_IMAGE_TYPE_2D;
973 image_create_info.format = tex_format;
974 image_create_info.extent.width = tex_width;
975 image_create_info.extent.height = tex_height;
976 image_create_info.extent.depth = 1;
977 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600978 image_create_info.arrayLayers = 1;
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600979 image_create_info.samples = 1;
980 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
981 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
982 image_create_info.flags = 0;
983
Chia-I Wu1f851912015-10-27 18:04:07 +0800984 VkMemoryAllocateInfo mem_alloc = {};
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600985 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
986 mem_alloc.pNext = NULL;
987 mem_alloc.allocationSize = 0;
988 mem_alloc.memoryTypeIndex = 0;
989
Chia-I Wu69f40122015-10-26 21:10:41 +0800990 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600991 ASSERT_VK_SUCCESS(err);
992
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600993 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600994 image,
995 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600996
997 mem_alloc.allocationSize = mem_reqs.size;
998
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600999 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1000 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001001
1002 // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08001003 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001004 ASSERT_VK_SUCCESS(err);
1005
1006 // Introduce validation failure, free memory before binding
Chia-I Wu69f40122015-10-26 21:10:41 +08001007 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001008
1009 // Try to bind free memory that has been freed
1010 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1011 // This may very well return an error.
1012 (void)err;
1013
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001014 if (!m_errorMonitor->DesiredMsgFound()) {
1015 FAIL() << "Did not receive Error 'Invalid VkDeviceMemory Object 0x<handle>'";
1016 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001017 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001018
Chia-I Wu69f40122015-10-26 21:10:41 +08001019 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001020}
1021
1022TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
1023{
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001024 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001025 bool pass;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001026
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001027 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Invalid VkImage Object ");
1028
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001029 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001030
1031 // Create an image object, allocate memory, destroy the object and then try to bind it
1032 VkImage image;
1033 VkDeviceMemory mem;
1034 VkMemoryRequirements mem_reqs;
1035
1036 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1037 const int32_t tex_width = 32;
1038 const int32_t tex_height = 32;
1039
1040 VkImageCreateInfo image_create_info = {};
1041 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1042 image_create_info.pNext = NULL;
1043 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1044 image_create_info.format = tex_format;
1045 image_create_info.extent.width = tex_width;
1046 image_create_info.extent.height = tex_height;
1047 image_create_info.extent.depth = 1;
1048 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06001049 image_create_info.arrayLayers = 1;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001050 image_create_info.samples = 1;
1051 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1052 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1053 image_create_info.flags = 0;
1054
Chia-I Wu1f851912015-10-27 18:04:07 +08001055 VkMemoryAllocateInfo mem_alloc = {};
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001056 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1057 mem_alloc.pNext = NULL;
1058 mem_alloc.allocationSize = 0;
1059 mem_alloc.memoryTypeIndex = 0;
1060
Chia-I Wu69f40122015-10-26 21:10:41 +08001061 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001062 ASSERT_VK_SUCCESS(err);
1063
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06001064 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001065 image,
1066 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001067
1068 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001069 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1070 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001071
1072 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08001073 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001074 ASSERT_VK_SUCCESS(err);
1075
1076 // Introduce validation failure, destroy Image object before binding
Chia-I Wu69f40122015-10-26 21:10:41 +08001077 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001078 ASSERT_VK_SUCCESS(err);
1079
1080 // Now Try to bind memory to this destroyed object
1081 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1082 // This may very well return an error.
1083 (void) err;
1084
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001085 if (!m_errorMonitor->DesiredMsgFound()) {
1086 FAIL() << "Did not receive Error 'Invalid VkImage Object 0x<handle>'";
1087 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001088 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001089
Chia-I Wu69f40122015-10-26 21:10:41 +08001090 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001091}
Tobin Ehlisb46be812015-10-23 16:00:08 -06001092
1093TEST_F(VkLayerTest, InvalidBufferViewObject)
1094{
1095 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Tobin Ehlisb46be812015-10-23 16:00:08 -06001096 VkResult err;
1097
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001098 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1099 "Invalid VkBufferView Object 0xbaadbeef");
1100
Tobin Ehlisb46be812015-10-23 16:00:08 -06001101 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wuc51b1212015-10-27 19:25:11 +08001102 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06001103 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001104 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06001105
1106 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1107 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1108 ds_pool_ci.pNext = NULL;
1109 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001110 ds_pool_ci.poolSizeCount = 1;
1111 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06001112
1113 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001114 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001115 ASSERT_VK_SUCCESS(err);
1116
1117 VkDescriptorSetLayoutBinding dsl_binding = {};
1118 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1119 dsl_binding.arraySize = 1;
1120 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1121 dsl_binding.pImmutableSamplers = NULL;
1122
1123 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1124 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1125 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001126 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001127 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06001128 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001129 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001130 ASSERT_VK_SUCCESS(err);
1131
1132 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001133 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06001134 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001135 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06001136 alloc_info.descriptorPool = ds_pool;
1137 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001138 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001139 ASSERT_VK_SUCCESS(err);
1140
Chia-I Wue420a332015-10-26 20:04:44 +08001141 VkBufferView view = (VkBufferView) 0xbaadbeef; // invalid bufferView object
Tobin Ehlisb46be812015-10-23 16:00:08 -06001142
1143 VkWriteDescriptorSet descriptor_write;
1144 memset(&descriptor_write, 0, sizeof(descriptor_write));
1145 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08001146 descriptor_write.dstSet = descriptorSet;
1147 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08001148 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06001149 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1150 descriptor_write.pTexelBufferView = &view;
1151
1152 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1153
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001154 if (!m_errorMonitor->DesiredMsgFound()) {
1155 FAIL() << "Did nto receive Error 'Invalid VkBufferView Object 0xbaadbeef'";
1156 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06001157 }
1158
Chia-I Wu69f40122015-10-26 21:10:41 +08001159 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1160 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06001161}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001162#endif // OBJ_TRACKER_TESTS
1163
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001164#if DRAW_STATE_TESTS
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001165TEST_F(VkLayerTest, LineWidthStateNotBound)
1166{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001167 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1168 "Dynamic line width state not set for this command buffer");
1169
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001170 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1171
1172 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1173
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001174 if (!m_errorMonitor->DesiredMsgFound()) {
1175 FAIL() << "Did not receive Error 'Dynamic line width state not set for this command buffer'";
1176 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001177 }
1178}
1179
1180TEST_F(VkLayerTest, DepthBiasStateNotBound)
1181{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001182 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1183 "Dynamic depth bias state not set for this command buffer");
1184
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001185 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1186
1187 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1188
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001189 if (!m_errorMonitor->DesiredMsgFound()) {
1190 FAIL() << "Did not receive Error 'Dynamic depth bias state not set for this command buffer'";
1191 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001192 }
1193}
1194
Cody Northropbca3bcd2015-10-27 16:54:28 -06001195// Disable these two tests until we can sort out how to track multiple layer errors
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001196TEST_F(VkLayerTest, ViewportStateNotBound)
1197{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001198 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1199 "Dynamic viewport state not set for this command buffer");
1200
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001201 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1202
1203 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1204
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001205 if (!m_errorMonitor->DesiredMsgFound()) {
1206 FAIL() << "Did not recieve Error 'Dynamic scissor state not set for this command buffer'";
1207 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001208 }
1209}
1210
1211TEST_F(VkLayerTest, ScissorStateNotBound)
1212{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001213 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1214 "Dynamic scissor state not set for this command buffer");
1215
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001216 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1217
1218 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1219
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001220 if (!m_errorMonitor->DesiredMsgFound()) {
1221 FAIL() << "Did not recieve Error ' Expected: 'Dynamic scissor state not set for this command buffer'";
1222 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001223 }
1224}
1225
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001226TEST_F(VkLayerTest, BlendStateNotBound)
1227{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001228 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1229 "Dynamic blend object state not set for this command buffer");
1230
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001231 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1232
1233 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1234
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001235 if (!m_errorMonitor->DesiredMsgFound()) {
1236 FAIL() << "Did not recieve Error 'Dynamic blend object state not set for this command buffer'";
1237 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001238 }
1239}
1240
1241TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1242{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001243 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1244 "Dynamic depth bounds state not set for this command buffer");
1245
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001246 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1247
1248 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1249
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001250 if (!m_errorMonitor->DesiredMsgFound()) {
1251 FAIL() << "Did not receive Error 'Dynamic depth bounds state not set for this command buffer'";
1252 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001253 }
1254}
1255
1256TEST_F(VkLayerTest, StencilReadMaskNotSet)
1257{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001258 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1259 "Dynamic stencil read mask state not set for this command buffer");
1260
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001261 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001262
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001263 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1264
1265 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1266
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001267 if (!m_errorMonitor->DesiredMsgFound()) {
1268 FAIL() << "Did not receive Error 'Dynamic stencil read mask state not set for this command buffer'";
1269 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001270 }
1271}
1272
1273TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1274{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001275 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1276 "Dynamic stencil write mask state not set for this command buffer");
1277
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001278 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001279
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001280 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1281
1282 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1283
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001284 if (!m_errorMonitor->DesiredMsgFound()) {
1285 FAIL() << "Did not receive Error 'Dynamic stencil write mask state not set for this command buffer'";
1286 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001287 }
1288}
1289
1290TEST_F(VkLayerTest, StencilReferenceNotSet)
1291{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001292 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1293 "Dynamic stencil reference state not set for this command buffer");
1294
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001295 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1296
1297 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1298
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001299 if (!m_errorMonitor->DesiredMsgFound()) {
1300 FAIL() << "Did not receive Error 'Dynamic stencil reference state not set for this command buffer'";
1301 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001302 }
1303}
1304
Chia-I Wu1f851912015-10-27 18:04:07 +08001305TEST_F(VkLayerTest, CommandBufferTwoSubmits)
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001306{
1307 vk_testing::Fence testFence;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001308
1309 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1310 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted");
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001311
1312 VkFenceCreateInfo fenceInfo = {};
1313 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1314 fenceInfo.pNext = NULL;
1315 fenceInfo.flags = 0;
1316
1317 ASSERT_NO_FATAL_FAILURE(InitState());
1318 ASSERT_NO_FATAL_FAILURE(InitViewport());
1319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1320
Chia-I Wu1f851912015-10-27 18:04:07 +08001321 // 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 -06001322 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08001323 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001324 EndCommandBuffer();
1325
1326 testFence.init(*m_device, fenceInfo);
1327
1328 // Bypass framework since it does the waits automatically
1329 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001330 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +08001331 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1332 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001333 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001334 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001335 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08001336 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +08001337 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001338 submit_info.pSignalSemaphores = NULL;
1339
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001340 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001341 ASSERT_VK_SUCCESS( err );
1342
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001343 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001344 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001345
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001346 if (!m_errorMonitor->DesiredMsgFound()) {
1347 FAIL() << "Did not receive Error 'CB (0xaddress) was created w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
1348 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001349 }
1350}
1351
Tobin Ehlise4076782015-06-24 15:53:07 -06001352TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001353{
1354 // Initiate Draw w/o a PSO bound
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001355 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001356
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001357 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1358 "Incorrectly binding graphics pipeline ");
1359
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001360 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001362
Chia-I Wuc51b1212015-10-27 19:25:11 +08001363 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001364 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001365 ds_type_count.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001366
1367 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1368 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1369 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001370 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001371 ds_pool_ci.poolSizeCount = 1;
1372 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001373
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001374 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001375 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001376 ASSERT_VK_SUCCESS(err);
1377
1378 VkDescriptorSetLayoutBinding dsl_binding = {};
1379 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1380 dsl_binding.arraySize = 1;
1381 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1382 dsl_binding.pImmutableSamplers = NULL;
1383
1384 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1385 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1386 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001387 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001388 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001389
1390 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001391 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001392 ASSERT_VK_SUCCESS(err);
1393
1394 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001395 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001396 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001397 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001398 alloc_info.descriptorPool = ds_pool;
1399 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001400 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001401 ASSERT_VK_SUCCESS(err);
1402 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1403 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1404 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001405 pipe_ms_state_ci.rasterizationSamples = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001406 pipe_ms_state_ci.sampleShadingEnable = 0;
1407 pipe_ms_state_ci.minSampleShading = 1.0;
1408 pipe_ms_state_ci.pSampleMask = NULL;
1409
1410 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1411 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1412 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001413 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001414 pipeline_layout_ci.pSetLayouts = &ds_layout;
1415 VkPipelineLayout pipeline_layout;
1416
Chia-I Wu69f40122015-10-26 21:10:41 +08001417 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001418 ASSERT_VK_SUCCESS(err);
1419
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001420 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1421 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 -06001422 // but add it to be able to run on more devices
1423 VkPipelineObj pipe(m_device);
1424 pipe.AddShader(&vs);
1425 pipe.AddShader(&fs);
1426 pipe.SetMSAA(&pipe_ms_state_ci);
1427 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001428
Chia-I Wu1f851912015-10-27 18:04:07 +08001429 // Calls AllocateCommandBuffers
1430 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
1431 VkCommandBufferBeginInfo cmd_buf_info = {};
1432 memset(&cmd_buf_info, 0, sizeof(VkCommandBufferBeginInfo));
1433 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001434 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001435 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001436
Chia-I Wu1f851912015-10-27 18:04:07 +08001437 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
1438 vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001439
1440 if (!m_errorMonitor->DesiredMsgFound()) {
1441 FAIL() << "Did not receive Error 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass'";
1442 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001443 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001444
Chia-I Wu69f40122015-10-26 21:10:41 +08001445 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1446 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1447 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001448}
1449
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001450TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1451{
1452 // Initiate Draw w/o a PSO bound
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001453 VkResult err;
1454
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001455 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1456 "Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
1457
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001458 ASSERT_NO_FATAL_FAILURE(InitState());
1459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001460
1461 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
Chia-I Wuc51b1212015-10-27 19:25:11 +08001462 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001463 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001464 ds_type_count.descriptorCount = 1;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001465
1466 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1467 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1468 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001469 ds_pool_ci.flags = 0;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001470 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001471 ds_pool_ci.poolSizeCount = 1;
1472 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001473
1474 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001475 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001476 ASSERT_VK_SUCCESS(err);
1477
1478 VkDescriptorSetLayoutBinding dsl_binding = {};
1479 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1480 dsl_binding.arraySize = 1;
1481 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1482 dsl_binding.pImmutableSamplers = NULL;
1483
1484 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1485 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1486 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001487 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001488 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001489
1490 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001491 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001492 ASSERT_VK_SUCCESS(err);
1493
1494 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001495 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001496 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001497 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001498 alloc_info.descriptorPool = ds_pool;
1499 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001500 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001501
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001502 if (!m_errorMonitor->DesiredMsgFound()) {
1503 FAIL() << "Did not receive Error 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...'";
1504 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001505 }
1506
Chia-I Wu69f40122015-10-26 21:10:41 +08001507 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1508 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001509}
1510
Tobin Ehlis3c543112015-10-08 13:13:50 -06001511TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1512{
Tobin Ehlis3c543112015-10-08 13:13:50 -06001513 VkResult err;
1514
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001515 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1516 "It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
1517
Tobin Ehlis3c543112015-10-08 13:13:50 -06001518 ASSERT_NO_FATAL_FAILURE(InitState());
1519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis3c543112015-10-08 13:13:50 -06001520
Chia-I Wuc51b1212015-10-27 19:25:11 +08001521 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis3c543112015-10-08 13:13:50 -06001522 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001523 ds_type_count.descriptorCount = 1;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001524
1525 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1526 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1527 ds_pool_ci.pNext = NULL;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001528 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001529 ds_pool_ci.poolSizeCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001530 ds_pool_ci.flags = 0;
1531 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1532 // app can only call vkResetDescriptorPool on this pool.;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001533 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001534
1535 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001536 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001537 ASSERT_VK_SUCCESS(err);
1538
1539 VkDescriptorSetLayoutBinding dsl_binding = {};
1540 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1541 dsl_binding.arraySize = 1;
1542 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1543 dsl_binding.pImmutableSamplers = NULL;
1544
1545 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1546 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1547 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001548 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001549 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001550
1551 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001552 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001553 ASSERT_VK_SUCCESS(err);
1554
1555 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001556 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001557 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001558 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001559 alloc_info.descriptorPool = ds_pool;
1560 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001561 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001562 ASSERT_VK_SUCCESS(err);
1563
1564 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001565 if (!m_errorMonitor->DesiredMsgFound()) {
1566 FAIL() << "Did not receive Error 'It is invalid to call vkFreeDescriptorSets() with a pool created with...'";
1567 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3c543112015-10-08 13:13:50 -06001568 }
1569
Chia-I Wu69f40122015-10-26 21:10:41 +08001570 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1571 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001572}
1573
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001574TEST_F(VkLayerTest, InvalidDescriptorPool)
1575{
1576 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1577 // The DS check for this is after driver has been called to validate DS internal data struct
1578 // Attempt to clear DS Pool with bad object
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001579/*
1580 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1581 "Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call");
1582
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001583 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1584 vkResetDescriptorPool(device(), badPool);
1585
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001586 if (!m_errorMonitor->DesiredMsgFound()) {
1587 FAIL() << "Did not receive Error 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1588 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001589 }*/
1590}
1591
1592TEST_F(VkLayerTest, InvalidDescriptorSet)
1593{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001594 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1595 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001596 // Create a valid cmd buffer
1597 // call vkCmdBindDescriptorSets w/ false DS
1598}
1599
1600TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1601{
1602 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1603 // The DS check for this is after driver has been called to validate DS internal data struct
1604}
1605
1606TEST_F(VkLayerTest, InvalidPipeline)
1607{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001608 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1609 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001610 // Create a valid cmd buffer
1611 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001612//
1613// m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1614// "Attempt to bind Pipeline ");
Tobin Ehlise4076782015-06-24 15:53:07 -06001615//
1616// ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +08001617// VkCommandBufferObj commandBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001618// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001619// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Chia-I Wu1f851912015-10-27 18:04:07 +08001620// vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001621//
1622// if (!m_errorMonitor->DesiredMsgFound()) {
1623// FAIL() << "Did not receive Error 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1624// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -06001625// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001626}
1627
Tobin Ehlis254eca02015-06-25 15:46:59 -06001628TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001629{
Chia-I Wu1f851912015-10-27 18:04:07 +08001630 // Create and update CommandBuffer then call QueueSubmit w/o calling End on CommandBuffer
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001631 VkResult err;
1632
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001633 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
1634 " bound but it was never updated. ");
1635
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001636 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001637 ASSERT_NO_FATAL_FAILURE(InitViewport());
1638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08001639 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001640 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001641 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001642
1643 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1644 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1645 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001646 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001647 ds_pool_ci.poolSizeCount = 1;
1648 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001649
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001650 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001651 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001652 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001653
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001654 VkDescriptorSetLayoutBinding dsl_binding = {};
1655 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1656 dsl_binding.arraySize = 1;
1657 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1658 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001659
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001660 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1661 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1662 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001663 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001664 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001665 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001666 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001667 ASSERT_VK_SUCCESS(err);
1668
1669 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001670 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001671 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001672 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001673 alloc_info.descriptorPool = ds_pool;
1674 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001675 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001676 ASSERT_VK_SUCCESS(err);
1677
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001678 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1679 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1680 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001681 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001682 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001683
1684 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001685 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001686 ASSERT_VK_SUCCESS(err);
1687
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001688 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001689 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
1690 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001691
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001692 VkPipelineObj pipe(m_device);
1693 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001694 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001695 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001696
1697 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08001698 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1699 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001700
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001701 if (!m_errorMonitor->DesiredMsgFound()) {
1702 FAIL() << "Did not recieve Warning 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1703 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001704 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001705
Chia-I Wu69f40122015-10-26 21:10:41 +08001706 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1707 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1708 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001709}
1710
Chia-I Wu1f851912015-10-27 18:04:07 +08001711TEST_F(VkLayerTest, NoBeginCommandBuffer)
Tobin Ehlis254eca02015-06-25 15:46:59 -06001712{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001713
1714 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1715 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlis254eca02015-06-25 15:46:59 -06001716
1717 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +08001718 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001719 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu1f851912015-10-27 18:04:07 +08001720 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001721
1722 if (!m_errorMonitor->DesiredMsgFound()) {
1723 FAIL() << "Did not recieve Error 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1724 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001725 }
1726}
1727
Chia-I Wu1f851912015-10-27 18:04:07 +08001728TEST_F(VkLayerTest, PrimaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001729{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001730
1731 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1732 "may not specify framebuffer or renderpass parameters");
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001733
1734 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001735
Chia-I Wu1f851912015-10-27 18:04:07 +08001736 // Calls AllocateCommandBuffers
1737 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001738
1739 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Chia-I Wu1f851912015-10-27 18:04:07 +08001740 VkCommandBufferBeginInfo cmd_buf_info = {};
1741 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06001742 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001743 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northrop10d8f982015-08-04 17:35:57 -06001744 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1745 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1746
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001747
1748 // The error should be caught by validation of the BeginCommandBuffer call
Chia-I Wu1f851912015-10-27 18:04:07 +08001749 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001750
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001751 if (!m_errorMonitor->DesiredMsgFound()) {
1752 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1753 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001754 }
1755}
1756
Chia-I Wu1f851912015-10-27 18:04:07 +08001757TEST_F(VkLayerTest, SecondaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001758{
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001759 VkResult err;
Chia-I Wu1f851912015-10-27 18:04:07 +08001760 VkCommandBuffer draw_cmd;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001761
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001762 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1763 "must specify framebuffer and renderpass parameters");
1764
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001765 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001766
Chia-I Wu1f851912015-10-27 18:04:07 +08001767 VkCommandBufferAllocateInfo cmd = {};
1768 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOC_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06001769 cmd.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001770 cmd.commandPool = m_commandPool;
1771 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Chia-I Wu763a7492015-10-26 20:48:51 +08001772 cmd.bufferCount = 1;
Cody Northrop10d8f982015-08-04 17:35:57 -06001773
Chia-I Wu1f851912015-10-27 18:04:07 +08001774 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06001775 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001776
1777 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu1f851912015-10-27 18:04:07 +08001778 VkCommandBufferBeginInfo cmd_buf_info = {};
1779 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06001780 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001781 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001782
1783 // The error should be caught by validation of the BeginCommandBuffer call
1784 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1785
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001786 if (!m_errorMonitor->DesiredMsgFound()) {
1787 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1788 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001789 }
Chia-I Wu1f851912015-10-27 18:04:07 +08001790 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001791}
1792
Tobin Ehlis254eca02015-06-25 15:46:59 -06001793TEST_F(VkLayerTest, InvalidPipelineCreateState)
1794{
1795 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis254eca02015-06-25 15:46:59 -06001796 VkResult err;
1797
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001798 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1799 "Invalid Pipeline CreateInfo State: Vtx Shader required");
1800
Tobin Ehlis254eca02015-06-25 15:46:59 -06001801 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001802 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001803
Chia-I Wuc51b1212015-10-27 19:25:11 +08001804 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001805 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001806 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001807
1808 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1809 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1810 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001811 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001812 ds_pool_ci.poolSizeCount = 1;
1813 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001814
Tobin Ehlis254eca02015-06-25 15:46:59 -06001815 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001816 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001817 ASSERT_VK_SUCCESS(err);
1818
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001819 VkDescriptorSetLayoutBinding dsl_binding = {};
1820 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1821 dsl_binding.arraySize = 1;
1822 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1823 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001824
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001825 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1826 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1827 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001828 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001829 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001830
Tobin Ehlis254eca02015-06-25 15:46:59 -06001831 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001832 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001833 ASSERT_VK_SUCCESS(err);
1834
1835 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001836 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001837 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001838 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001839 alloc_info.descriptorPool = ds_pool;
1840 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001841 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001842 ASSERT_VK_SUCCESS(err);
1843
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001844 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1845 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001846 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001847 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001848
1849 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001850 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001851 ASSERT_VK_SUCCESS(err);
1852
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001853 VkViewport vp = {}; // Just need dummy vp to point to
1854 VkRect2D sc = {}; // dummy scissor to point to
1855
1856 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1857 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1858 vp_state_ci.scissorCount = 1;
1859 vp_state_ci.pScissors = &sc;
1860 vp_state_ci.viewportCount = 1;
1861 vp_state_ci.pViewports = &vp;
1862
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001863 VkGraphicsPipelineCreateInfo gp_ci = {};
1864 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001865 gp_ci.pViewportState = &vp_state_ci;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001866 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1867 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001868 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001869
1870 VkPipelineCacheCreateInfo pc_ci = {};
1871 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Chia-I Wu7e470702015-10-26 17:24:52 +08001872 pc_ci.initialDataSize = 0;
1873 pc_ci.pInitialData = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001874
1875 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001876 VkPipelineCache pipelineCache;
1877
Chia-I Wu69f40122015-10-26 21:10:41 +08001878 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001879 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08001880 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001881
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001882 if (!m_errorMonitor->DesiredMsgFound()) {
1883 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1884 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001885 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001886
Chia-I Wu69f40122015-10-26 21:10:41 +08001887 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
1888 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1889 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1890 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001891}
Tobin Ehlis20693172015-09-17 08:46:18 -06001892/*// TODO : This test should be good, but needs Tess support in compiler to run
1893TEST_F(VkLayerTest, InvalidPatchControlPoints)
1894{
1895 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis20693172015-09-17 08:46:18 -06001896 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001897
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001898 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1899 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ");
1900
Tobin Ehlis20693172015-09-17 08:46:18 -06001901 ASSERT_NO_FATAL_FAILURE(InitState());
1902 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis20693172015-09-17 08:46:18 -06001903
Chia-I Wuc51b1212015-10-27 19:25:11 +08001904 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis20693172015-09-17 08:46:18 -06001905 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001906 ds_type_count.descriptorCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06001907
1908 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1909 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1910 ds_pool_ci.pNext = NULL;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001911 ds_pool_ci.poolSizeCount = 1;
1912 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis20693172015-09-17 08:46:18 -06001913
1914 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001915 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 -06001916 ASSERT_VK_SUCCESS(err);
1917
1918 VkDescriptorSetLayoutBinding dsl_binding = {};
1919 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1920 dsl_binding.arraySize = 1;
1921 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1922 dsl_binding.pImmutableSamplers = NULL;
1923
1924 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1925 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1926 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001927 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001928 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis20693172015-09-17 08:46:18 -06001929
1930 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001931 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06001932 ASSERT_VK_SUCCESS(err);
1933
1934 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001935 err = vkAllocateDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis20693172015-09-17 08:46:18 -06001936 ASSERT_VK_SUCCESS(err);
1937
1938 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1939 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1940 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001941 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06001942 pipeline_layout_ci.pSetLayouts = &ds_layout;
1943
1944 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001945 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06001946 ASSERT_VK_SUCCESS(err);
1947
1948 VkPipelineShaderStageCreateInfo shaderStages[3];
1949 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1950
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001951 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06001952 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001953 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
1954 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06001955
1956 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001957 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001958 shaderStages[0].shader = vs.handle();
1959 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001960 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001961 shaderStages[1].shader = tc.handle();
1962 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001963 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001964 shaderStages[2].shader = te.handle();
1965
1966 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1967 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1968 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1969
1970 VkPipelineTessellationStateCreateInfo tsCI = {};
1971 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1972 tsCI.patchControlPoints = 0; // This will cause an error
1973
1974 VkGraphicsPipelineCreateInfo gp_ci = {};
1975 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1976 gp_ci.pNext = NULL;
1977 gp_ci.stageCount = 3;
1978 gp_ci.pStages = shaderStages;
1979 gp_ci.pVertexInputState = NULL;
1980 gp_ci.pInputAssemblyState = &iaCI;
1981 gp_ci.pTessellationState = &tsCI;
1982 gp_ci.pViewportState = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001983 gp_ci.pRasterizationState = NULL;
Tobin Ehlis20693172015-09-17 08:46:18 -06001984 gp_ci.pMultisampleState = NULL;
1985 gp_ci.pDepthStencilState = NULL;
1986 gp_ci.pColorBlendState = NULL;
1987 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1988 gp_ci.layout = pipeline_layout;
1989 gp_ci.renderPass = renderPass();
1990
1991 VkPipelineCacheCreateInfo pc_ci = {};
1992 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1993 pc_ci.pNext = NULL;
1994 pc_ci.initialSize = 0;
1995 pc_ci.initialData = 0;
1996 pc_ci.maxSize = 0;
1997
1998 VkPipeline pipeline;
1999 VkPipelineCache pipelineCache;
2000
Chia-I Wu69f40122015-10-26 21:10:41 +08002001 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis20693172015-09-17 08:46:18 -06002002 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002003 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis20693172015-09-17 08:46:18 -06002004
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002005 if (!m_errorMonitor->DesiredMsgFound()) {
2006 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...'";
2007 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis20693172015-09-17 08:46:18 -06002008 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002009
Chia-I Wu69f40122015-10-26 21:10:41 +08002010 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2011 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2012 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2013 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis20693172015-09-17 08:46:18 -06002014}
2015*/
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002016// Set scissor and viewport counts to different numbers
2017TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2018{
2019 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002020 VkResult err;
2021
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002022 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2023 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2024
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002025 ASSERT_NO_FATAL_FAILURE(InitState());
2026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002027
Chia-I Wuc51b1212015-10-27 19:25:11 +08002028 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002029 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002030 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002031
2032 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2033 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002034 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002035 ds_pool_ci.poolSizeCount = 1;
2036 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002037
2038 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002039 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002040 ASSERT_VK_SUCCESS(err);
2041
2042 VkDescriptorSetLayoutBinding dsl_binding = {};
2043 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2044 dsl_binding.arraySize = 1;
2045 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2046
2047 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2048 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002049 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002050 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002051
2052 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002053 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002054 ASSERT_VK_SUCCESS(err);
2055
2056 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002057 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002058 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002059 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002060 alloc_info.descriptorPool = ds_pool;
2061 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002062 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002063 ASSERT_VK_SUCCESS(err);
2064
2065 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2066 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002067 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002068 pipeline_layout_ci.pSetLayouts = &ds_layout;
2069
2070 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002071 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002072 ASSERT_VK_SUCCESS(err);
2073
2074 VkViewport vp = {}; // Just need dummy vp to point to
2075
2076 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2077 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2078 vp_state_ci.scissorCount = 0;
2079 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2080 vp_state_ci.pViewports = &vp;
2081
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002082 VkPipelineShaderStageCreateInfo shaderStages[2];
2083 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002084
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002085 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2086 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 -06002087 // but add it to be able to run on more devices
2088 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002089 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002090
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002091 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002092 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002093
2094 VkGraphicsPipelineCreateInfo gp_ci = {};
2095 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002096 gp_ci.stageCount = 2;
2097 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002098 gp_ci.pViewportState = &vp_state_ci;
2099 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2100 gp_ci.layout = pipeline_layout;
2101 gp_ci.renderPass = renderPass();
2102
2103 VkPipelineCacheCreateInfo pc_ci = {};
2104 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2105
2106 VkPipeline pipeline;
2107 VkPipelineCache pipelineCache;
2108
Chia-I Wu69f40122015-10-26 21:10:41 +08002109 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002110 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002111 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002112
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002113 if (!m_errorMonitor->DesiredMsgFound()) {
2114 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must match scissor count (0).'";
2115 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002116 }
2117
Chia-I Wu69f40122015-10-26 21:10:41 +08002118 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2119 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2120 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2121 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002122}
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002123// Don't set viewport state in PSO. This is an error b/c we always need this state
2124// for the counts even if the data is going to be set dynamically.
2125TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002126{
2127 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002128 VkResult err;
2129
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002130 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2131 "Gfx Pipeline pViewportState is null. Even if ");
2132
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002133 ASSERT_NO_FATAL_FAILURE(InitState());
2134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002135
Chia-I Wuc51b1212015-10-27 19:25:11 +08002136 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002137 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002138 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002139
2140 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2141 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002142 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002143 ds_pool_ci.poolSizeCount = 1;
2144 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002145
2146 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002147 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002148 ASSERT_VK_SUCCESS(err);
2149
2150 VkDescriptorSetLayoutBinding dsl_binding = {};
2151 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2152 dsl_binding.arraySize = 1;
2153 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2154
2155 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2156 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002157 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002158 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002159
2160 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002161 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002162 ASSERT_VK_SUCCESS(err);
2163
2164 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002165 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002166 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002167 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002168 alloc_info.descriptorPool = ds_pool;
2169 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002170 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002171 ASSERT_VK_SUCCESS(err);
2172
2173 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2174 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002175 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002176 pipeline_layout_ci.pSetLayouts = &ds_layout;
2177
2178 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002179 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002180 ASSERT_VK_SUCCESS(err);
2181
2182 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2183 // Set scissor as dynamic to avoid second error
2184 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2185 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2186 dyn_state_ci.dynamicStateCount = 1;
2187 dyn_state_ci.pDynamicStates = &sc_state;
2188
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002189 VkPipelineShaderStageCreateInfo shaderStages[2];
2190 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002191
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002192 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2193 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 -06002194 // but add it to be able to run on more devices
2195 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002196 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002197
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002198 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002199 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002200
2201 VkGraphicsPipelineCreateInfo gp_ci = {};
2202 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002203 gp_ci.stageCount = 2;
2204 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002205 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2206 gp_ci.pDynamicState = &dyn_state_ci;
2207 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2208 gp_ci.layout = pipeline_layout;
2209 gp_ci.renderPass = renderPass();
2210
2211 VkPipelineCacheCreateInfo pc_ci = {};
2212 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2213
2214 VkPipeline pipeline;
2215 VkPipelineCache pipelineCache;
2216
Chia-I Wu69f40122015-10-26 21:10:41 +08002217 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002218 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002219 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002220
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002221 if (!m_errorMonitor->DesiredMsgFound()) {
2222 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. Even if...'";
2223 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002224 }
2225
Chia-I Wu69f40122015-10-26 21:10:41 +08002226 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2227 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2228 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2229 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002230}
2231// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002232// Then run second test where dynamic scissor count doesn't match PSO scissor count
2233TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002234{
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002235 VkResult err;
2236
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002237 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2238 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
2239
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002240 ASSERT_NO_FATAL_FAILURE(InitState());
2241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002242
Chia-I Wuc51b1212015-10-27 19:25:11 +08002243 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002244 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002245 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002246
2247 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2248 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002249 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002250 ds_pool_ci.poolSizeCount = 1;
2251 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002252
2253 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002254 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002255 ASSERT_VK_SUCCESS(err);
2256
2257 VkDescriptorSetLayoutBinding dsl_binding = {};
2258 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2259 dsl_binding.arraySize = 1;
2260 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2261
2262 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2263 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002264 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002265 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002266
2267 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002268 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002269 ASSERT_VK_SUCCESS(err);
2270
2271 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002272 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002273 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002274 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002275 alloc_info.descriptorPool = ds_pool;
2276 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002277 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002278 ASSERT_VK_SUCCESS(err);
2279
2280 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2281 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002282 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002283 pipeline_layout_ci.pSetLayouts = &ds_layout;
2284
2285 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002286 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002287 ASSERT_VK_SUCCESS(err);
2288
2289 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2290 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2291 vp_state_ci.viewportCount = 1;
2292 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2293 vp_state_ci.scissorCount = 1;
2294 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2295
2296 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2297 // Set scissor as dynamic to avoid that error
2298 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2299 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2300 dyn_state_ci.dynamicStateCount = 1;
2301 dyn_state_ci.pDynamicStates = &sc_state;
2302
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002303 VkPipelineShaderStageCreateInfo shaderStages[2];
2304 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002305
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002306 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2307 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 -06002308 // but add it to be able to run on more devices
2309 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002310 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002311
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002312 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002313 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002314
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002315 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2316 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2317 vi_ci.pNext = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002318 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002319 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002320 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002321 vi_ci.pVertexAttributeDescriptions = nullptr;
2322
2323 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2324 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2325 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2326
Chia-I Wu1f851912015-10-27 18:04:07 +08002327 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +08002328 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002329 rs_ci.pNext = nullptr;
2330
2331 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2332 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2333 cb_ci.pNext = nullptr;
2334
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002335 VkGraphicsPipelineCreateInfo gp_ci = {};
2336 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002337 gp_ci.stageCount = 2;
2338 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002339 gp_ci.pVertexInputState = &vi_ci;
2340 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002341 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu1f851912015-10-27 18:04:07 +08002342 gp_ci.pRasterizationState = &rs_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002343 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002344 gp_ci.pDynamicState = &dyn_state_ci;
2345 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2346 gp_ci.layout = pipeline_layout;
2347 gp_ci.renderPass = renderPass();
2348
2349 VkPipelineCacheCreateInfo pc_ci = {};
2350 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2351
2352 VkPipeline pipeline;
2353 VkPipelineCache pipelineCache;
2354
Chia-I Wu69f40122015-10-26 21:10:41 +08002355 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002356 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002357 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002358
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002359 if (!m_errorMonitor->DesiredMsgFound()) {
2360 FAIL() << "Did not recieve Error 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...'";
2361 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002362 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002363
2364
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002365 // Now hit second fail case where we set scissor w/ different count than PSO
2366 // First need to successfully create the PSO from above by setting pViewports
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002367 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2368 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.");
2369
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002370 VkViewport vp = {}; // Just need dummy vp to point to
2371 vp_state_ci.pViewports = &vp;
Chia-I Wu69f40122015-10-26 21:10:41 +08002372 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002373 ASSERT_VK_SUCCESS(err);
2374 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08002375 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002376 VkRect2D scissors[2] = {}; // don't care about data
2377 // Count of 2 doesn't match PSO count of 1
Chia-I Wu1f851912015-10-27 18:04:07 +08002378 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 2, scissors);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002379 Draw(1, 0, 0, 0);
2380
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002381 if (!m_errorMonitor->DesiredMsgFound()) {
2382 FAIL() << "Did not receive Error 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
2383 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002384 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002385
Chia-I Wu69f40122015-10-26 21:10:41 +08002386 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2387 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2388 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2389 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002390}
2391// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002392// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2393TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002394{
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002395 VkResult err;
2396
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002397 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2398 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
2399
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002400 ASSERT_NO_FATAL_FAILURE(InitState());
2401 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002402
Chia-I Wuc51b1212015-10-27 19:25:11 +08002403 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002404 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002405 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002406
2407 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2408 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002409 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002410 ds_pool_ci.poolSizeCount = 1;
2411 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002412
2413 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002414 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002415 ASSERT_VK_SUCCESS(err);
2416
2417 VkDescriptorSetLayoutBinding dsl_binding = {};
2418 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2419 dsl_binding.arraySize = 1;
2420 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2421
2422 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2423 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002424 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002425 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002426
2427 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002428 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002429 ASSERT_VK_SUCCESS(err);
2430
2431 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002432 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002433 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002434 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002435 alloc_info.descriptorPool = ds_pool;
2436 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002437 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002438 ASSERT_VK_SUCCESS(err);
2439
2440 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2441 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002442 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002443 pipeline_layout_ci.pSetLayouts = &ds_layout;
2444
2445 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002446 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002447 ASSERT_VK_SUCCESS(err);
2448
2449 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2450 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2451 vp_state_ci.scissorCount = 1;
2452 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2453 vp_state_ci.viewportCount = 1;
2454 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2455
2456 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2457 // Set scissor as dynamic to avoid that error
2458 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2459 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2460 dyn_state_ci.dynamicStateCount = 1;
2461 dyn_state_ci.pDynamicStates = &vp_state;
2462
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002463 VkPipelineShaderStageCreateInfo shaderStages[2];
2464 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002465
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002466 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2467 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 -06002468 // but add it to be able to run on more devices
2469 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002470 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002471
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002472 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002473 shaderStages[1].shader = fs.handle();
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;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002674 image_create_info.samples = 1;
2675 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 = {};
2861 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2862 dsl_binding.arraySize = 1;
2863 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2864 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002865
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002866 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2867 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2868 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002869 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002870 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002871
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002872 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002873 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002874 ASSERT_VK_SUCCESS(err);
2875
2876 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002877 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002878 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002879 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002880 alloc_info.descriptorPool = ds_pool;
2881 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002882 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002883 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002884
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002885 VkSamplerCreateInfo sampler_ci = {};
2886 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2887 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08002888 sampler_ci.magFilter = VK_FILTER_NEAREST;
2889 sampler_ci.minFilter = VK_FILTER_NEAREST;
2890 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08002891 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2892 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2893 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002894 sampler_ci.mipLodBias = 1.0;
2895 sampler_ci.maxAnisotropy = 1;
2896 sampler_ci.compareEnable = VK_FALSE;
2897 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2898 sampler_ci.minLod = 1.0;
2899 sampler_ci.maxLod = 1.0;
2900 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002901 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2902
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002903 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08002904 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002905 ASSERT_VK_SUCCESS(err);
2906
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06002907 VkDescriptorImageInfo info = {};
2908 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002909
2910 VkWriteDescriptorSet descriptor_write;
2911 memset(&descriptor_write, 0, sizeof(descriptor_write));
2912 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08002913 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08002914 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002915 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002916 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06002917 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002918
2919 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2920
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002921 if (!m_errorMonitor->DesiredMsgFound()) {
2922 FAIL() << "Did not receive Error 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...'";
2923 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002924 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002925
Chia-I Wu69f40122015-10-26 21:10:41 +08002926 vkDestroySampler(m_device->device(), sampler, NULL);
2927 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2928 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002929}
2930
2931TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2932{
2933 // For overlapping Update, have arrayIndex exceed that of layout
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002934 VkResult err;
2935
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002936 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2937 "Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding");
2938
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002939 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002940 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08002941 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002942 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002943 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002944
2945 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2946 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2947 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002948 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002949 ds_pool_ci.poolSizeCount = 1;
2950 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002951
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002952 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002953 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002954 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002955
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002956 VkDescriptorSetLayoutBinding dsl_binding = {};
2957 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2958 dsl_binding.arraySize = 1;
2959 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2960 dsl_binding.pImmutableSamplers = NULL;
2961
2962 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2963 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2964 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002965 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002966 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002967
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002968 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002969 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002970 ASSERT_VK_SUCCESS(err);
2971
2972 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002973 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002974 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002975 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002976 alloc_info.descriptorPool = ds_pool;
2977 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002978 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002979 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002980
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002981 VkSamplerCreateInfo sampler_ci = {};
2982 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2983 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08002984 sampler_ci.magFilter = VK_FILTER_NEAREST;
2985 sampler_ci.minFilter = VK_FILTER_NEAREST;
2986 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08002987 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2988 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2989 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002990 sampler_ci.mipLodBias = 1.0;
2991 sampler_ci.maxAnisotropy = 1;
2992 sampler_ci.compareEnable = VK_FALSE;
2993 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2994 sampler_ci.minLod = 1.0;
2995 sampler_ci.maxLod = 1.0;
2996 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002997 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002998
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002999 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003000 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003001 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003002
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003003 VkDescriptorImageInfo info = {};
3004 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003005
3006 VkWriteDescriptorSet descriptor_write;
3007 memset(&descriptor_write, 0, sizeof(descriptor_write));
3008 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003009 descriptor_write.dstSet = descriptorSet;
3010 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wu763a7492015-10-26 20:48:51 +08003011 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003012 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003013 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003014 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003015
3016 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3017
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003018 if (!m_errorMonitor->DesiredMsgFound()) {
3019 FAIL() << "Did not receive Error 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
3020 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003021 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003022
Chia-I Wu69f40122015-10-26 21:10:41 +08003023 vkDestroySampler(m_device->device(), sampler, NULL);
3024 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3025 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003026}
3027
3028TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3029{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003030 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003031 VkResult err;
3032
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003033 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3034 " does not have binding to match update binding ");
3035
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003036 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003037 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003038 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003039 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003040 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003041
3042 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3043 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3044 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003045 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003046 ds_pool_ci.poolSizeCount = 1;
3047 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003048
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003049 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003050 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003051 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003052
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003053 VkDescriptorSetLayoutBinding dsl_binding = {};
3054 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3055 dsl_binding.arraySize = 1;
3056 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3057 dsl_binding.pImmutableSamplers = NULL;
3058
3059 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3060 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3061 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003062 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003063 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003064 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003065 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003066 ASSERT_VK_SUCCESS(err);
3067
3068 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003069 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003070 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003071 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003072 alloc_info.descriptorPool = ds_pool;
3073 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003074 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003075 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003076
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003077 VkSamplerCreateInfo sampler_ci = {};
3078 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3079 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003080 sampler_ci.magFilter = VK_FILTER_NEAREST;
3081 sampler_ci.minFilter = VK_FILTER_NEAREST;
3082 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003083 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3084 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3085 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003086 sampler_ci.mipLodBias = 1.0;
3087 sampler_ci.maxAnisotropy = 1;
3088 sampler_ci.compareEnable = VK_FALSE;
3089 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3090 sampler_ci.minLod = 1.0;
3091 sampler_ci.maxLod = 1.0;
3092 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003093 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003094
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003095 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003096 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003097 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003098
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003099 VkDescriptorImageInfo info = {};
3100 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003101
3102 VkWriteDescriptorSet descriptor_write;
3103 memset(&descriptor_write, 0, sizeof(descriptor_write));
3104 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003105 descriptor_write.dstSet = descriptorSet;
3106 descriptor_write.dstBinding = 2;
Chia-I Wu763a7492015-10-26 20:48:51 +08003107 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003108 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003109 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003110 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003111
3112 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3113
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003114 if (!m_errorMonitor->DesiredMsgFound()) {
3115 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have binding to match update binding '";
3116 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003117 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003118
Chia-I Wu69f40122015-10-26 21:10:41 +08003119 vkDestroySampler(m_device->device(), sampler, NULL);
3120 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3121 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003122}
3123
3124TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3125{
3126 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003127 VkResult err;
3128
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003129 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3130 "Unexpected UPDATE struct of type ");
3131
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003132 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003133
Chia-I Wuc51b1212015-10-27 19:25:11 +08003134 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003135 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003136 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003137
3138 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3139 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3140 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003141 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003142 ds_pool_ci.poolSizeCount = 1;
3143 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003144
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003145 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003146 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003147 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003148 VkDescriptorSetLayoutBinding dsl_binding = {};
3149 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3150 dsl_binding.arraySize = 1;
3151 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3152 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003153
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003154 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3155 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3156 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003157 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003158 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003159
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003160 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003161 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003162 ASSERT_VK_SUCCESS(err);
3163
3164 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003165 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003166 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003167 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003168 alloc_info.descriptorPool = ds_pool;
3169 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003170 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003171 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003172
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003173 VkSamplerCreateInfo sampler_ci = {};
3174 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3175 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003176 sampler_ci.magFilter = VK_FILTER_NEAREST;
3177 sampler_ci.minFilter = VK_FILTER_NEAREST;
3178 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003179 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3180 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3181 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003182 sampler_ci.mipLodBias = 1.0;
3183 sampler_ci.maxAnisotropy = 1;
3184 sampler_ci.compareEnable = VK_FALSE;
3185 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3186 sampler_ci.minLod = 1.0;
3187 sampler_ci.maxLod = 1.0;
3188 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003189 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003190 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003191 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003192 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003193
3194
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003195 VkDescriptorImageInfo info = {};
3196 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003197
3198 VkWriteDescriptorSet descriptor_write;
3199 memset(&descriptor_write, 0, sizeof(descriptor_write));
3200 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu1f851912015-10-27 18:04:07 +08003201 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003202 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003203 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003204 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003205 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003206
3207 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3208
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003209 if (!m_errorMonitor->DesiredMsgFound()) {
3210 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
3211 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003212 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003213
Chia-I Wu69f40122015-10-26 21:10:41 +08003214 vkDestroySampler(m_device->device(), sampler, NULL);
3215 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3216 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003217}
3218
Tobin Ehlisb46be812015-10-23 16:00:08 -06003219TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3220{
3221 // Create a single Sampler descriptor and send it an invalid Sampler
Tobin Ehlisb46be812015-10-23 16:00:08 -06003222 VkResult err;
3223
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003224 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3225 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
3226
Tobin Ehlisb46be812015-10-23 16:00:08 -06003227 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb46be812015-10-23 16:00:08 -06003228 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
Chia-I Wuc51b1212015-10-27 19:25:11 +08003229 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003230 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003231 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003232
3233 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3234 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3235 ds_pool_ci.pNext = NULL;
3236 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003237 ds_pool_ci.poolSizeCount = 1;
3238 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003239
3240 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003241 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003242 ASSERT_VK_SUCCESS(err);
3243
3244 VkDescriptorSetLayoutBinding dsl_binding = {};
3245 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3246 dsl_binding.arraySize = 1;
3247 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3248 dsl_binding.pImmutableSamplers = NULL;
3249
3250 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3251 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3252 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003253 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003254 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003255 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003256 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003257 ASSERT_VK_SUCCESS(err);
3258
3259 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003260 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003261 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003262 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003263 alloc_info.descriptorPool = ds_pool;
3264 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003265 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003266 ASSERT_VK_SUCCESS(err);
3267
Chia-I Wue420a332015-10-26 20:04:44 +08003268 VkSampler sampler = (VkSampler) 0xbaadbeef; // Sampler with invalid handle
Tobin Ehlisb46be812015-10-23 16:00:08 -06003269
3270 VkDescriptorImageInfo descriptor_info;
3271 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3272 descriptor_info.sampler = sampler;
3273
3274 VkWriteDescriptorSet descriptor_write;
3275 memset(&descriptor_write, 0, sizeof(descriptor_write));
3276 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003277 descriptor_write.dstSet = descriptorSet;
3278 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003279 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003280 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3281 descriptor_write.pImageInfo = &descriptor_info;
3282
3283 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3284
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003285 if (!m_errorMonitor->DesiredMsgFound()) {
3286 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid sampler...'";
3287 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003288 }
3289
Chia-I Wu69f40122015-10-26 21:10:41 +08003290 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3291 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003292}
3293
3294TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3295{
3296 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
Tobin Ehlisb46be812015-10-23 16:00:08 -06003297 VkResult err;
3298
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003299 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3300 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
3301
Tobin Ehlisb46be812015-10-23 16:00:08 -06003302 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wuc51b1212015-10-27 19:25:11 +08003303 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003304 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003305 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003306
3307 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3308 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3309 ds_pool_ci.pNext = NULL;
3310 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003311 ds_pool_ci.poolSizeCount = 1;
3312 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003313
3314 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003315 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003316 ASSERT_VK_SUCCESS(err);
3317
3318 VkDescriptorSetLayoutBinding dsl_binding = {};
3319 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3320 dsl_binding.arraySize = 1;
3321 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3322 dsl_binding.pImmutableSamplers = NULL;
3323
3324 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3325 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3326 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003327 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003328 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003329 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003330 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003331 ASSERT_VK_SUCCESS(err);
3332
3333 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003334 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003335 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003336 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003337 alloc_info.descriptorPool = ds_pool;
3338 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003339 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003340 ASSERT_VK_SUCCESS(err);
3341
3342 VkSamplerCreateInfo sampler_ci = {};
3343 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3344 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003345 sampler_ci.magFilter = VK_FILTER_NEAREST;
3346 sampler_ci.minFilter = VK_FILTER_NEAREST;
3347 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003348 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3349 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3350 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003351 sampler_ci.mipLodBias = 1.0;
3352 sampler_ci.maxAnisotropy = 1;
3353 sampler_ci.compareEnable = VK_FALSE;
3354 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3355 sampler_ci.minLod = 1.0;
3356 sampler_ci.maxLod = 1.0;
3357 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3358 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3359
3360 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003361 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003362 ASSERT_VK_SUCCESS(err);
3363
Chia-I Wue420a332015-10-26 20:04:44 +08003364 VkImageView view = (VkImageView) 0xbaadbeef; // invalid imageView object
Tobin Ehlisb46be812015-10-23 16:00:08 -06003365
3366 VkDescriptorImageInfo descriptor_info;
3367 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3368 descriptor_info.sampler = sampler;
3369 descriptor_info.imageView = view;
3370
3371 VkWriteDescriptorSet descriptor_write;
3372 memset(&descriptor_write, 0, sizeof(descriptor_write));
3373 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003374 descriptor_write.dstSet = descriptorSet;
3375 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003376 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003377 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3378 descriptor_write.pImageInfo = &descriptor_info;
3379
3380 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3381
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003382 if (!m_errorMonitor->DesiredMsgFound()) {
3383 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid imageView...'";
3384 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003385 }
3386
Chia-I Wu69f40122015-10-26 21:10:41 +08003387 vkDestroySampler(m_device->device(), sampler, NULL);
3388 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3389 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003390}
3391
Tobin Ehlis3e676262015-10-27 16:35:27 -06003392TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
3393{
3394 // 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 -06003395 VkResult err;
3396
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003397 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3398 "Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ");
3399
Tobin Ehlis3e676262015-10-27 16:35:27 -06003400 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3e676262015-10-27 16:35:27 -06003401 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003402 VkDescriptorPoolSize ds_type_count[2] = {};
Tobin Ehlis3e676262015-10-27 16:35:27 -06003403 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003404 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003405 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003406 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003407
3408 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3409 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3410 ds_pool_ci.pNext = NULL;
3411 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003412 ds_pool_ci.poolSizeCount = 2;
3413 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003414
3415 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003416 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003417 ASSERT_VK_SUCCESS(err);
3418 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
3419 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3420 dsl_binding[0].arraySize = 1;
3421 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3422 dsl_binding[0].pImmutableSamplers = NULL;
3423 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3424 dsl_binding[1].arraySize = 1;
3425 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
3426 dsl_binding[1].pImmutableSamplers = NULL;
3427
3428 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3429 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3430 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003431 ds_layout_ci.bindingCount = 2;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003432 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003433
3434 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003435 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003436 ASSERT_VK_SUCCESS(err);
3437
3438 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003439 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis3e676262015-10-27 16:35:27 -06003440 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003441 alloc_info.setLayoutCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003442 alloc_info.descriptorPool = ds_pool;
3443 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003444 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003445 ASSERT_VK_SUCCESS(err);
3446
3447 VkSamplerCreateInfo sampler_ci = {};
3448 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3449 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003450 sampler_ci.magFilter = VK_FILTER_NEAREST;
3451 sampler_ci.minFilter = VK_FILTER_NEAREST;
3452 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003453 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3454 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3455 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003456 sampler_ci.mipLodBias = 1.0;
3457 sampler_ci.maxAnisotropy = 1;
3458 sampler_ci.compareEnable = VK_FALSE;
3459 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3460 sampler_ci.minLod = 1.0;
3461 sampler_ci.maxLod = 1.0;
3462 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3463 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3464
3465 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003466 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003467 ASSERT_VK_SUCCESS(err);
3468
3469 VkDescriptorImageInfo info = {};
3470 info.sampler = sampler;
3471
3472 VkWriteDescriptorSet descriptor_write;
3473 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
3474 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003475 descriptor_write.dstSet = descriptorSet;
3476 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wu763a7492015-10-26 20:48:51 +08003477 descriptor_write.descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003478 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3479 descriptor_write.pImageInfo = &info;
3480 // This write update should succeed
3481 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3482 // Now perform a copy update that fails due to type mismatch
3483 VkCopyDescriptorSet copy_ds_update;
3484 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3485 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3486 copy_ds_update.srcSet = descriptorSet;
3487 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu1f851912015-10-27 18:04:07 +08003488 copy_ds_update.dstSet = descriptorSet;
3489 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wu763a7492015-10-26 20:48:51 +08003490 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06003491 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3492
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003493 if (!m_errorMonitor->DesiredMsgFound()) {
3494 FAIL() << "Did not receive Error 'Copy descriptor update index 0, update count #1, has src update descriptor type_DESCRIPTOR_TYPE_SAMPLER'";
3495 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003496 }
3497 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003498 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3499 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis3e676262015-10-27 16:35:27 -06003500 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3501 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3502 copy_ds_update.srcSet = descriptorSet;
3503 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu1f851912015-10-27 18:04:07 +08003504 copy_ds_update.dstSet = descriptorSet;
3505 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003506 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06003507 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3508
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003509 if (!m_errorMonitor->DesiredMsgFound()) {
3510 FAIL() << "Did not receive Error 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...'";
3511 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003512 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003513
Tobin Ehlis3e676262015-10-27 16:35:27 -06003514 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003515 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3516 "Copy descriptor src update is out of bounds for matching binding 1 ");
3517
Tobin Ehlis3e676262015-10-27 16:35:27 -06003518 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3519 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3520 copy_ds_update.srcSet = descriptorSet;
3521 copy_ds_update.srcBinding = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08003522 copy_ds_update.dstSet = descriptorSet;
3523 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003524 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis3e676262015-10-27 16:35:27 -06003525 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3526
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003527 if (!m_errorMonitor->DesiredMsgFound()) {
3528 FAIL() << "Did not receive Error 'Copy descriptor src update is out of bounds for matching binding 1...'";
3529 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003530 }
3531
Chia-I Wu69f40122015-10-26 21:10:41 +08003532 vkDestroySampler(m_device->device(), sampler, NULL);
3533 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3534 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003535}
3536
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003537TEST_F(VkLayerTest, NumSamplesMismatch)
3538{
Chia-I Wu1f851912015-10-27 18:04:07 +08003539 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003540 VkResult err;
3541
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003542 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3543 "Num samples mismatch! ");
3544
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003545 ASSERT_NO_FATAL_FAILURE(InitState());
3546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08003547 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003548 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003549 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003550
3551 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003552 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3553 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003554 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003555 ds_pool_ci.poolSizeCount = 1;
3556 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003557
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003558 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003559 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003560 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003561
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003562 VkDescriptorSetLayoutBinding dsl_binding = {};
3563 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3564 dsl_binding.arraySize = 1;
3565 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3566 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003567
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003568 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3569 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3570 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003571 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003572 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003573
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003574 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003575 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003576 ASSERT_VK_SUCCESS(err);
3577
3578 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003579 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003580 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003581 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003582 alloc_info.descriptorPool = ds_pool;
3583 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003584 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003585 ASSERT_VK_SUCCESS(err);
3586
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003587 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3588 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3589 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08003590 pipe_ms_state_ci.rasterizationSamples = 4;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003591 pipe_ms_state_ci.sampleShadingEnable = 0;
3592 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003593 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003594
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003595 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3596 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3597 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003598 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003599 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003600
3601 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003602 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003603 ASSERT_VK_SUCCESS(err);
3604
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003605 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3606 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 -06003607 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003608 VkPipelineObj pipe(m_device);
3609 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003610 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003611 pipe.SetMSAA(&pipe_ms_state_ci);
3612 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003613
Tony Barbour1490c912015-07-28 10:17:20 -06003614 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08003615 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003616
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003617 if (!m_errorMonitor->DesiredMsgFound()) {
3618 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
3619 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003620 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003621
Chia-I Wu69f40122015-10-26 21:10:41 +08003622 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3623 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3624 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003625}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003626
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003627TEST_F(VkLayerTest, ClearCmdNoDraw)
3628{
Chia-I Wu1f851912015-10-27 18:04:07 +08003629 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003630 VkResult err;
3631
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003632 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
3633 "vkCmdClearAttachments() issued on CB object ");
3634
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003635 ASSERT_NO_FATAL_FAILURE(InitState());
3636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003637
Chia-I Wuc51b1212015-10-27 19:25:11 +08003638 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003639 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003640 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003641
3642 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3643 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3644 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003645 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003646 ds_pool_ci.poolSizeCount = 1;
3647 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003648
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003649 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003650 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003651 ASSERT_VK_SUCCESS(err);
3652
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003653 VkDescriptorSetLayoutBinding dsl_binding = {};
3654 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3655 dsl_binding.arraySize = 1;
3656 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3657 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003658
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003659 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3660 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3661 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003662 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003663 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003664
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003665 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003666 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003667 ASSERT_VK_SUCCESS(err);
3668
3669 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003670 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003671 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003672 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003673 alloc_info.descriptorPool = ds_pool;
3674 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003675 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003676 ASSERT_VK_SUCCESS(err);
3677
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003678 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3679 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3680 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08003681 pipe_ms_state_ci.rasterizationSamples = 4;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003682 pipe_ms_state_ci.sampleShadingEnable = 0;
3683 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003684 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003685
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003686 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3687 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3688 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003689 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003690 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003691
3692 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003693 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003694 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003695
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003696 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003697 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
3698 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3699
Tony Barbourd7d828b2015-08-06 10:16:07 -06003700 VkPipelineObj pipe(m_device);
3701 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003702 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003703 pipe.SetMSAA(&pipe_ms_state_ci);
3704 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003705
3706 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003707
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003708 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3709 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003710 VkClearAttachment color_attachment;
3711 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3712 color_attachment.clearValue.color.float32[0] = 1.0;
3713 color_attachment.clearValue.color.float32[1] = 1.0;
3714 color_attachment.clearValue.color.float32[2] = 1.0;
3715 color_attachment.clearValue.color.float32[3] = 1.0;
3716 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06003717 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003718
Chia-I Wu1f851912015-10-27 18:04:07 +08003719 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003720
3721 if (!m_errorMonitor->DesiredMsgFound()) {
3722 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued on CB object...'";
3723 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003724 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003725
Chia-I Wu69f40122015-10-26 21:10:41 +08003726 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3727 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3728 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003729}
3730
Tobin Ehlise4076782015-06-24 15:53:07 -06003731TEST_F(VkLayerTest, VtxBufferBadIndex)
3732{
Chia-I Wu1f851912015-10-27 18:04:07 +08003733 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlise4076782015-06-24 15:53:07 -06003734 VkResult err;
3735
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003736 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3737 "Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.");
3738
Tobin Ehlise4076782015-06-24 15:53:07 -06003739 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003740 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06003741 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003742
Chia-I Wuc51b1212015-10-27 19:25:11 +08003743 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003744 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003745 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003746
3747 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3748 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3749 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003750 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003751 ds_pool_ci.poolSizeCount = 1;
3752 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003753
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003754 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003755 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003756 ASSERT_VK_SUCCESS(err);
3757
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003758 VkDescriptorSetLayoutBinding dsl_binding = {};
3759 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3760 dsl_binding.arraySize = 1;
3761 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3762 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003763
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003764 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3765 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3766 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003767 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003768 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003769
Tobin Ehlise4076782015-06-24 15:53:07 -06003770 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003771 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06003772 ASSERT_VK_SUCCESS(err);
3773
3774 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003775 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003776 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003777 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003778 alloc_info.descriptorPool = ds_pool;
3779 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003780 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06003781 ASSERT_VK_SUCCESS(err);
3782
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003783 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3784 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3785 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08003786 pipe_ms_state_ci.rasterizationSamples = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003787 pipe_ms_state_ci.sampleShadingEnable = 0;
3788 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003789 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003790
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003791 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3792 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3793 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003794 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003795 pipeline_layout_ci.pSetLayouts = &ds_layout;
3796 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06003797
Chia-I Wu69f40122015-10-26 21:10:41 +08003798 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06003799 ASSERT_VK_SUCCESS(err);
3800
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003801 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3802 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 -06003803 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003804 VkPipelineObj pipe(m_device);
3805 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003806 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003807 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003808 pipe.SetViewport(m_viewports);
3809 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003810 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003811
3812 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08003813 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06003814 // Don't care about actual data, just need to get to draw to flag error
3815 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3816 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3817 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003818 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06003819
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003820 if (!m_errorMonitor->DesiredMsgFound()) {
3821 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
3822 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -06003823 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003824
Chia-I Wu69f40122015-10-26 21:10:41 +08003825 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3826 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3827 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06003828}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003829#endif // DRAW_STATE_TESTS
3830
Tobin Ehlis57e6a612015-05-26 16:11:58 -06003831#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06003832#if GTEST_IS_THREADSAFE
3833struct thread_data_struct {
Chia-I Wu1f851912015-10-27 18:04:07 +08003834 VkCommandBuffer commandBuffer;
Mike Stroyan09aae812015-05-12 16:00:45 -06003835 VkEvent event;
3836 bool bailout;
3837};
3838
3839extern "C" void *AddToCommandBuffer(void *arg)
3840{
3841 struct thread_data_struct *data = (struct thread_data_struct *) arg;
Mike Stroyan09aae812015-05-12 16:00:45 -06003842
3843 for (int i = 0; i<10000; i++) {
Chia-I Wu1f851912015-10-27 18:04:07 +08003844 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06003845 if (data->bailout) {
3846 break;
3847 }
3848 }
3849 return NULL;
3850}
3851
Chia-I Wu1f851912015-10-27 18:04:07 +08003852TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyan09aae812015-05-12 16:00:45 -06003853{
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003854 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06003855
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003856 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "THREADING ERROR");
3857
Mike Stroyan09aae812015-05-12 16:00:45 -06003858 ASSERT_NO_FATAL_FAILURE(InitState());
3859 ASSERT_NO_FATAL_FAILURE(InitViewport());
3860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3861
Chia-I Wu1f851912015-10-27 18:04:07 +08003862 // Calls AllocateCommandBuffers
3863 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003864
3865 // Avoid creating RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08003866 commandBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003867
3868 VkEventCreateInfo event_info;
3869 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06003870 VkResult err;
3871
3872 memset(&event_info, 0, sizeof(event_info));
3873 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3874
Chia-I Wu69f40122015-10-26 21:10:41 +08003875 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyan09aae812015-05-12 16:00:45 -06003876 ASSERT_VK_SUCCESS(err);
3877
Mike Stroyan09aae812015-05-12 16:00:45 -06003878 err = vkResetEvent(device(), event);
3879 ASSERT_VK_SUCCESS(err);
3880
3881 struct thread_data_struct data;
Chia-I Wu1f851912015-10-27 18:04:07 +08003882 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06003883 data.event = event;
3884 data.bailout = false;
3885 m_errorMonitor->SetBailout(&data.bailout);
3886 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003887 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06003888 // Add many entries to command buffer from this thread at the same time.
3889 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003890
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003891 test_platform_thread_join(thread, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08003892 commandBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003893
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003894 if (!m_errorMonitor->DesiredMsgFound()) {
3895 FAIL() << "Did not receive Error 'THREADING ERROR' from using one VkCommandBufferObj in two threads";
3896 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan09aae812015-05-12 16:00:45 -06003897 }
3898
Chia-I Wu69f40122015-10-26 21:10:41 +08003899 vkDestroyEvent(device(), event, NULL);
Mike Stroyan09aae812015-05-12 16:00:45 -06003900}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003901#endif // GTEST_IS_THREADSAFE
3902#endif // THREADING_TESTS
3903
Chris Forbes5af3bf22015-05-25 11:13:08 +12003904#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003905TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
3906{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003907 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3908 "Shader is not SPIR-V");
3909
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003910 ASSERT_NO_FATAL_FAILURE(InitState());
3911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3912
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003913 VkShaderModule module;
3914 VkShaderModuleCreateInfo moduleCreateInfo;
3915 struct icd_spv_header spv;
3916
3917 spv.magic = ICD_SPV_MAGIC;
3918 spv.version = ICD_SPV_VERSION;
3919 spv.gen_magic = 0;
3920
3921 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3922 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08003923 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003924 moduleCreateInfo.codeSize = 4;
3925 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08003926 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003927
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003928 if (!m_errorMonitor->DesiredMsgFound()) {
3929 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
3930 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003931 }
3932}
3933
3934TEST_F(VkLayerTest, InvalidSPIRVMagic)
3935{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003936 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3937 "Shader is not SPIR-V");
3938
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003939 ASSERT_NO_FATAL_FAILURE(InitState());
3940 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3941
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003942 VkShaderModule module;
3943 VkShaderModuleCreateInfo moduleCreateInfo;
3944 struct icd_spv_header spv;
3945
3946 spv.magic = ~ICD_SPV_MAGIC;
3947 spv.version = ICD_SPV_VERSION;
3948 spv.gen_magic = 0;
3949
3950 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3951 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08003952 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003953 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3954 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08003955 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003956
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003957 if (!m_errorMonitor->DesiredMsgFound()) {
3958 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
3959 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003960 }
3961}
3962
3963TEST_F(VkLayerTest, InvalidSPIRVVersion)
3964{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003965 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3966 "Shader is not SPIR-V");
3967
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003968 ASSERT_NO_FATAL_FAILURE(InitState());
3969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3970
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003971 VkShaderModule module;
3972 VkShaderModuleCreateInfo moduleCreateInfo;
3973 struct icd_spv_header spv;
3974
3975 spv.magic = ICD_SPV_MAGIC;
3976 spv.version = ~ICD_SPV_VERSION;
3977 spv.gen_magic = 0;
3978
3979 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3980 moduleCreateInfo.pNext = NULL;
3981
Chia-I Wu036b1612015-10-26 19:22:06 +08003982 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003983 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3984 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08003985 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003986
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003987 if (!m_errorMonitor->DesiredMsgFound()) {
3988 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
3989 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003990 }
3991}
3992
Chris Forbes5af3bf22015-05-25 11:13:08 +12003993TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
3994{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003995 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
3996 "not consumed by fragment shader");
3997
Chris Forbes5af3bf22015-05-25 11:13:08 +12003998 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004000
4001 char const *vsSource =
4002 "#version 140\n"
4003 "#extension GL_ARB_separate_shader_objects: require\n"
4004 "#extension GL_ARB_shading_language_420pack: require\n"
4005 "\n"
4006 "layout(location=0) out float x;\n"
4007 "void main(){\n"
4008 " gl_Position = vec4(1);\n"
4009 " x = 0;\n"
4010 "}\n";
4011 char const *fsSource =
4012 "#version 140\n"
4013 "#extension GL_ARB_separate_shader_objects: require\n"
4014 "#extension GL_ARB_shading_language_420pack: require\n"
4015 "\n"
4016 "layout(location=0) out vec4 color;\n"
4017 "void main(){\n"
4018 " color = vec4(1);\n"
4019 "}\n";
4020
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004021 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4022 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004023
4024 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004025 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004026 pipe.AddShader(&vs);
4027 pipe.AddShader(&fs);
4028
Chris Forbes5af3bf22015-05-25 11:13:08 +12004029 VkDescriptorSetObj descriptorSet(m_device);
4030 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004031 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004032
Tony Barboured132432015-08-04 16:23:11 -06004033 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004034
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004035 if (!m_errorMonitor->DesiredMsgFound()) {
4036 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
4037 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004038 }
4039}
Chris Forbes5af3bf22015-05-25 11:13:08 +12004040
Chris Forbes3c10b852015-05-25 11:13:13 +12004041TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4042{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004043 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4044 "not written by vertex shader");
4045
Chris Forbes3c10b852015-05-25 11:13:13 +12004046 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004047 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12004048
4049 char const *vsSource =
4050 "#version 140\n"
4051 "#extension GL_ARB_separate_shader_objects: require\n"
4052 "#extension GL_ARB_shading_language_420pack: require\n"
4053 "\n"
4054 "void main(){\n"
4055 " gl_Position = vec4(1);\n"
4056 "}\n";
4057 char const *fsSource =
4058 "#version 140\n"
4059 "#extension GL_ARB_separate_shader_objects: require\n"
4060 "#extension GL_ARB_shading_language_420pack: require\n"
4061 "\n"
4062 "layout(location=0) in float x;\n"
4063 "layout(location=0) out vec4 color;\n"
4064 "void main(){\n"
4065 " color = vec4(x);\n"
4066 "}\n";
4067
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004068 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4069 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes3c10b852015-05-25 11:13:13 +12004070
4071 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004072 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12004073 pipe.AddShader(&vs);
4074 pipe.AddShader(&fs);
4075
Chris Forbes3c10b852015-05-25 11:13:13 +12004076 VkDescriptorSetObj descriptorSet(m_device);
4077 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004078 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12004079
Tony Barboured132432015-08-04 16:23:11 -06004080 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12004081
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004082 if (!m_errorMonitor->DesiredMsgFound()) {
4083 FAIL() << "Did not receive Error 'not written by vertex shader'";
4084 m_errorMonitor->DumpFailureMsgs();
Chris Forbes3c10b852015-05-25 11:13:13 +12004085 }
4086}
4087
Chris Forbescc281692015-05-25 11:13:17 +12004088TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4089{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004090 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4091 "Type mismatch on location 0");
4092
Chris Forbescc281692015-05-25 11:13:17 +12004093 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004094 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12004095
4096 char const *vsSource =
4097 "#version 140\n"
4098 "#extension GL_ARB_separate_shader_objects: require\n"
4099 "#extension GL_ARB_shading_language_420pack: require\n"
4100 "\n"
4101 "layout(location=0) out int x;\n"
4102 "void main(){\n"
4103 " x = 0;\n"
4104 " gl_Position = vec4(1);\n"
4105 "}\n";
4106 char const *fsSource =
4107 "#version 140\n"
4108 "#extension GL_ARB_separate_shader_objects: require\n"
4109 "#extension GL_ARB_shading_language_420pack: require\n"
4110 "\n"
4111 "layout(location=0) in float x;\n" /* VS writes int */
4112 "layout(location=0) out vec4 color;\n"
4113 "void main(){\n"
4114 " color = vec4(x);\n"
4115 "}\n";
4116
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004117 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4118 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbescc281692015-05-25 11:13:17 +12004119
4120 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004121 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12004122 pipe.AddShader(&vs);
4123 pipe.AddShader(&fs);
4124
Chris Forbescc281692015-05-25 11:13:17 +12004125 VkDescriptorSetObj descriptorSet(m_device);
4126 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004127 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12004128
Tony Barboured132432015-08-04 16:23:11 -06004129 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12004130
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004131 if (!m_errorMonitor->DesiredMsgFound()) {
4132 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4133 m_errorMonitor->DumpFailureMsgs();
Chris Forbescc281692015-05-25 11:13:17 +12004134 }
4135}
4136
Chris Forbes8291c052015-05-25 11:13:28 +12004137TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4138{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004139 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
4140 "location 0 not consumed by VS");
4141
Chris Forbes8291c052015-05-25 11:13:28 +12004142 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12004144
4145 VkVertexInputBindingDescription input_binding;
4146 memset(&input_binding, 0, sizeof(input_binding));
4147
4148 VkVertexInputAttributeDescription input_attrib;
4149 memset(&input_attrib, 0, sizeof(input_attrib));
4150 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4151
4152 char const *vsSource =
4153 "#version 140\n"
4154 "#extension GL_ARB_separate_shader_objects: require\n"
4155 "#extension GL_ARB_shading_language_420pack: require\n"
4156 "\n"
4157 "void main(){\n"
4158 " gl_Position = vec4(1);\n"
4159 "}\n";
4160 char const *fsSource =
4161 "#version 140\n"
4162 "#extension GL_ARB_separate_shader_objects: require\n"
4163 "#extension GL_ARB_shading_language_420pack: require\n"
4164 "\n"
4165 "layout(location=0) out vec4 color;\n"
4166 "void main(){\n"
4167 " color = vec4(1);\n"
4168 "}\n";
4169
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004170 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4171 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes8291c052015-05-25 11:13:28 +12004172
4173 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004174 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12004175 pipe.AddShader(&vs);
4176 pipe.AddShader(&fs);
4177
4178 pipe.AddVertexInputBindings(&input_binding, 1);
4179 pipe.AddVertexInputAttribs(&input_attrib, 1);
4180
Chris Forbes8291c052015-05-25 11:13:28 +12004181 VkDescriptorSetObj descriptorSet(m_device);
4182 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004183 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12004184
Tony Barboured132432015-08-04 16:23:11 -06004185 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12004186
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004187 if (!m_errorMonitor->DesiredMsgFound()) {
4188 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
4189 m_errorMonitor->DumpFailureMsgs();
Chris Forbes8291c052015-05-25 11:13:28 +12004190 }
4191}
4192
Chris Forbes37367e62015-05-25 11:13:29 +12004193TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4194{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004195 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4196 "VS consumes input at location 0 but not provided");
4197
Chris Forbes37367e62015-05-25 11:13:29 +12004198 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004199 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12004200
4201 char const *vsSource =
4202 "#version 140\n"
4203 "#extension GL_ARB_separate_shader_objects: require\n"
4204 "#extension GL_ARB_shading_language_420pack: require\n"
4205 "\n"
4206 "layout(location=0) in vec4 x;\n" /* not provided */
4207 "void main(){\n"
4208 " gl_Position = x;\n"
4209 "}\n";
4210 char const *fsSource =
4211 "#version 140\n"
4212 "#extension GL_ARB_separate_shader_objects: require\n"
4213 "#extension GL_ARB_shading_language_420pack: require\n"
4214 "\n"
4215 "layout(location=0) out vec4 color;\n"
4216 "void main(){\n"
4217 " color = vec4(1);\n"
4218 "}\n";
4219
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004220 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4221 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes37367e62015-05-25 11:13:29 +12004222
4223 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004224 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12004225 pipe.AddShader(&vs);
4226 pipe.AddShader(&fs);
4227
Chris Forbes37367e62015-05-25 11:13:29 +12004228 VkDescriptorSetObj descriptorSet(m_device);
4229 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004230 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12004231
Tony Barboured132432015-08-04 16:23:11 -06004232 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12004233
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004234 if (!m_errorMonitor->DesiredMsgFound()) {
4235 FAIL() << "Did not receive Error 'VS consumes input at location 0 but not provided'";
4236 m_errorMonitor->DumpFailureMsgs();
Chris Forbes37367e62015-05-25 11:13:29 +12004237 }
4238}
4239
Chris Forbesa4b02322015-05-25 11:13:31 +12004240TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4241{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004242 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4243 "location 0 does not match VS input type");
4244
Chris Forbesa4b02322015-05-25 11:13:31 +12004245 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12004247
4248 VkVertexInputBindingDescription input_binding;
4249 memset(&input_binding, 0, sizeof(input_binding));
4250
4251 VkVertexInputAttributeDescription input_attrib;
4252 memset(&input_attrib, 0, sizeof(input_attrib));
4253 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4254
4255 char const *vsSource =
4256 "#version 140\n"
4257 "#extension GL_ARB_separate_shader_objects: require\n"
4258 "#extension GL_ARB_shading_language_420pack: require\n"
4259 "\n"
4260 "layout(location=0) in int x;\n" /* attrib provided float */
4261 "void main(){\n"
4262 " gl_Position = vec4(x);\n"
4263 "}\n";
4264 char const *fsSource =
4265 "#version 140\n"
4266 "#extension GL_ARB_separate_shader_objects: require\n"
4267 "#extension GL_ARB_shading_language_420pack: require\n"
4268 "\n"
4269 "layout(location=0) out vec4 color;\n"
4270 "void main(){\n"
4271 " color = vec4(1);\n"
4272 "}\n";
4273
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004274 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4275 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa4b02322015-05-25 11:13:31 +12004276
4277 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004278 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12004279 pipe.AddShader(&vs);
4280 pipe.AddShader(&fs);
4281
4282 pipe.AddVertexInputBindings(&input_binding, 1);
4283 pipe.AddVertexInputAttribs(&input_attrib, 1);
4284
Chris Forbesa4b02322015-05-25 11:13:31 +12004285 VkDescriptorSetObj descriptorSet(m_device);
4286 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004287 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12004288
Tony Barboured132432015-08-04 16:23:11 -06004289 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12004290
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004291 if (!m_errorMonitor->DesiredMsgFound()) {
4292 FAIL() << "Did not receive Error 'location 0 does not match VS input type'";
4293 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa4b02322015-05-25 11:13:31 +12004294 }
4295}
4296
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004297TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
4298{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004299 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4300 "Duplicate vertex input binding descriptions for binding 0");
4301
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004302 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004304
4305 /* Two binding descriptions for binding 0 */
4306 VkVertexInputBindingDescription input_bindings[2];
4307 memset(input_bindings, 0, sizeof(input_bindings));
4308
4309 VkVertexInputAttributeDescription input_attrib;
4310 memset(&input_attrib, 0, sizeof(input_attrib));
4311 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4312
4313 char const *vsSource =
4314 "#version 140\n"
4315 "#extension GL_ARB_separate_shader_objects: require\n"
4316 "#extension GL_ARB_shading_language_420pack: require\n"
4317 "\n"
4318 "layout(location=0) in float x;\n" /* attrib provided float */
4319 "void main(){\n"
4320 " gl_Position = vec4(x);\n"
4321 "}\n";
4322 char const *fsSource =
4323 "#version 140\n"
4324 "#extension GL_ARB_separate_shader_objects: require\n"
4325 "#extension GL_ARB_shading_language_420pack: require\n"
4326 "\n"
4327 "layout(location=0) out vec4 color;\n"
4328 "void main(){\n"
4329 " color = vec4(1);\n"
4330 "}\n";
4331
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004332 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4333 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004334
4335 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004336 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004337 pipe.AddShader(&vs);
4338 pipe.AddShader(&fs);
4339
4340 pipe.AddVertexInputBindings(input_bindings, 2);
4341 pipe.AddVertexInputAttribs(&input_attrib, 1);
4342
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004343 VkDescriptorSetObj descriptorSet(m_device);
4344 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004345 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004346
Tony Barboured132432015-08-04 16:23:11 -06004347 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004348
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004349 if (!m_errorMonitor->DesiredMsgFound()) {
4350 FAIL() << "Did not receive Error 'Duplicate vertex input binding descriptions for binding 0'";
4351 m_errorMonitor->DumpFailureMsgs();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004352 }
4353}
Chris Forbes4c948702015-05-25 11:13:32 +12004354
Chris Forbesc12ef122015-05-25 11:13:40 +12004355/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
4356 * rejects it. */
4357
4358TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
4359{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004360 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4361 "Attachment 0 not written by FS");
4362
Chris Forbesc12ef122015-05-25 11:13:40 +12004363 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12004364
4365 char const *vsSource =
4366 "#version 140\n"
4367 "#extension GL_ARB_separate_shader_objects: require\n"
4368 "#extension GL_ARB_shading_language_420pack: require\n"
4369 "\n"
4370 "void main(){\n"
4371 " gl_Position = vec4(1);\n"
4372 "}\n";
4373 char const *fsSource =
4374 "#version 140\n"
4375 "#extension GL_ARB_separate_shader_objects: require\n"
4376 "#extension GL_ARB_shading_language_420pack: require\n"
4377 "\n"
4378 "void main(){\n"
4379 "}\n";
4380
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004381 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4382 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc12ef122015-05-25 11:13:40 +12004383
4384 VkPipelineObj pipe(m_device);
4385 pipe.AddShader(&vs);
4386 pipe.AddShader(&fs);
4387
Chia-I Wuc278df82015-07-07 11:50:03 +08004388 /* set up CB 0, not written */
4389 pipe.AddColorAttachment();
4390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12004391
Chris Forbesc12ef122015-05-25 11:13:40 +12004392 VkDescriptorSetObj descriptorSet(m_device);
4393 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004394 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12004395
Tony Barboured132432015-08-04 16:23:11 -06004396 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12004397
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004398 if (!m_errorMonitor->DesiredMsgFound()) {
4399 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
4400 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc12ef122015-05-25 11:13:40 +12004401 }
4402}
4403
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004404TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
4405{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004406 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
4407 "FS writes to output location 1 with no matching attachment");
4408
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004409 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004410
4411 char const *vsSource =
4412 "#version 140\n"
4413 "#extension GL_ARB_separate_shader_objects: require\n"
4414 "#extension GL_ARB_shading_language_420pack: require\n"
4415 "\n"
4416 "void main(){\n"
4417 " gl_Position = vec4(1);\n"
4418 "}\n";
4419 char const *fsSource =
4420 "#version 140\n"
4421 "#extension GL_ARB_separate_shader_objects: require\n"
4422 "#extension GL_ARB_shading_language_420pack: require\n"
4423 "\n"
4424 "layout(location=0) out vec4 x;\n"
4425 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4426 "void main(){\n"
4427 " x = vec4(1);\n"
4428 " y = vec4(1);\n"
4429 "}\n";
4430
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004431 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4432 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004433
4434 VkPipelineObj pipe(m_device);
4435 pipe.AddShader(&vs);
4436 pipe.AddShader(&fs);
4437
Chia-I Wuc278df82015-07-07 11:50:03 +08004438 /* set up CB 0, not written */
4439 pipe.AddColorAttachment();
4440 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004441 /* FS writes CB 1, but we don't configure it */
4442
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004443 VkDescriptorSetObj descriptorSet(m_device);
4444 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004445 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004446
Tony Barboured132432015-08-04 16:23:11 -06004447 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004448
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004449 if (!m_errorMonitor->DesiredMsgFound()) {
4450 FAIL() << "Did not receive Error 'FS writes to output location 1 with no matching attachment'";
4451 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004452 }
4453}
4454
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004455TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4456{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004457 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4458 "does not match FS output type");
4459
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004460 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004461
4462 char const *vsSource =
4463 "#version 140\n"
4464 "#extension GL_ARB_separate_shader_objects: require\n"
4465 "#extension GL_ARB_shading_language_420pack: require\n"
4466 "\n"
4467 "void main(){\n"
4468 " gl_Position = vec4(1);\n"
4469 "}\n";
4470 char const *fsSource =
4471 "#version 140\n"
4472 "#extension GL_ARB_separate_shader_objects: require\n"
4473 "#extension GL_ARB_shading_language_420pack: require\n"
4474 "\n"
4475 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4476 "void main(){\n"
4477 " x = ivec4(1);\n"
4478 "}\n";
4479
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004480 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4481 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004482
4483 VkPipelineObj pipe(m_device);
4484 pipe.AddShader(&vs);
4485 pipe.AddShader(&fs);
4486
Chia-I Wuc278df82015-07-07 11:50:03 +08004487 /* set up CB 0; type is UNORM by default */
4488 pipe.AddColorAttachment();
4489 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004490
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004491 VkDescriptorSetObj descriptorSet(m_device);
4492 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004493 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004494
Tony Barboured132432015-08-04 16:23:11 -06004495 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004496
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004497 if (!m_errorMonitor->DesiredMsgFound()) {
4498 FAIL() << "Did not receive Error 'does not match FS output type'";
4499 m_errorMonitor->DumpFailureMsgs();
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004500 }
4501}
Chris Forbesc2050732015-06-05 14:43:36 +12004502
Chris Forbes76ce7882015-08-14 12:04:59 +12004503TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4504{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004505 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4506 "not declared in pipeline layout");
4507
Chris Forbes76ce7882015-08-14 12:04:59 +12004508 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12004509
4510 char const *vsSource =
4511 "#version 140\n"
4512 "#extension GL_ARB_separate_shader_objects: require\n"
4513 "#extension GL_ARB_shading_language_420pack: require\n"
4514 "\n"
4515 "void main(){\n"
4516 " gl_Position = vec4(1);\n"
4517 "}\n";
4518 char const *fsSource =
4519 "#version 140\n"
4520 "#extension GL_ARB_separate_shader_objects: require\n"
4521 "#extension GL_ARB_shading_language_420pack: require\n"
4522 "\n"
4523 "layout(location=0) out vec4 x;\n"
4524 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4525 "void main(){\n"
4526 " x = vec4(bar.y);\n"
4527 "}\n";
4528
Chris Forbes76ce7882015-08-14 12:04:59 +12004529
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004530 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4531 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes76ce7882015-08-14 12:04:59 +12004532
Chris Forbes76ce7882015-08-14 12:04:59 +12004533 VkPipelineObj pipe(m_device);
4534 pipe.AddShader(&vs);
4535 pipe.AddShader(&fs);
4536
4537 /* set up CB 0; type is UNORM by default */
4538 pipe.AddColorAttachment();
4539 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4540
4541 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1f851912015-10-27 18:04:07 +08004542 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes76ce7882015-08-14 12:04:59 +12004543
4544 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4545
4546 /* should have generated an error -- pipeline layout does not
4547 * provide a uniform buffer in 0.0
4548 */
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004549 if (!m_errorMonitor->DesiredMsgFound()) {
4550 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
4551 m_errorMonitor->DumpFailureMsgs();
Chris Forbes76ce7882015-08-14 12:04:59 +12004552 }
4553}
4554
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004555#endif // SHADER_CHECKER_TESTS
4556
4557#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004558TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4559{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004560 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4561 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004562
4563 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004564
4565 // Create an image
4566 VkImage image;
4567
4568 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4569 const int32_t tex_width = 32;
4570 const int32_t tex_height = 32;
4571
4572 VkImageCreateInfo image_create_info = {};
4573 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4574 image_create_info.pNext = NULL;
4575 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4576 image_create_info.format = tex_format;
4577 image_create_info.extent.width = tex_width;
4578 image_create_info.extent.height = tex_height;
4579 image_create_info.extent.depth = 1;
4580 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004581 image_create_info.arrayLayers = 1;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004582 image_create_info.samples = 1;
4583 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4584 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4585 image_create_info.flags = 0;
4586
4587 // Introduce error by sending down a bogus width extent
4588 image_create_info.extent.width = 65536;
Chia-I Wu69f40122015-10-26 21:10:41 +08004589 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004590
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004591 if (!m_errorMonitor->DesiredMsgFound()) {
4592 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable limits for format'";
4593 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004594 }
4595}
4596
4597TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4598{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004599 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4600 "CreateImage resource size exceeds allowable maximum");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004601
4602 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004603
4604 // Create an image
4605 VkImage image;
4606
4607 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4608 const int32_t tex_width = 32;
4609 const int32_t tex_height = 32;
4610
4611 VkImageCreateInfo image_create_info = {};
4612 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4613 image_create_info.pNext = NULL;
4614 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4615 image_create_info.format = tex_format;
4616 image_create_info.extent.width = tex_width;
4617 image_create_info.extent.height = tex_height;
4618 image_create_info.extent.depth = 1;
4619 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004620 image_create_info.arrayLayers = 1;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004621 image_create_info.samples = 1;
4622 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4623 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4624 image_create_info.flags = 0;
4625
4626 // Introduce error by sending down individually allowable values that result in a surface size
4627 // exceeding the device maximum
4628 image_create_info.extent.width = 8192;
4629 image_create_info.extent.height = 8192;
4630 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004631 image_create_info.arrayLayers = 4;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004632 image_create_info.samples = 2;
4633 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
Chia-I Wu69f40122015-10-26 21:10:41 +08004634 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004635
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004636 if (!m_errorMonitor->DesiredMsgFound()) {
4637 FAIL() << "Did not receive Error 'CreateImage resource size exceeds allowable maximum'";
4638 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004639 }
4640}
4641
Mike Stroyan43909d82015-09-25 13:39:21 -06004642TEST_F(VkLayerTest, UpdateBufferAlignment)
4643{
Mike Stroyan43909d82015-09-25 13:39:21 -06004644 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4645
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004646 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4647 "dstOffset, is not a multiple of 4");
4648
Mike Stroyan43909d82015-09-25 13:39:21 -06004649 ASSERT_NO_FATAL_FAILURE(InitState());
4650
4651 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4652 vk_testing::Buffer buffer;
4653 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4654
4655 BeginCommandBuffer();
4656 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08004657 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004658 if (!m_errorMonitor->DesiredMsgFound()) {
4659 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
4660 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004661 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004662
Mike Stroyan43909d82015-09-25 13:39:21 -06004663 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004664 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4665 "dataSize, is not a multiple of 4");
4666
Chia-I Wu1f851912015-10-27 18:04:07 +08004667 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004668
4669 if (!m_errorMonitor->DesiredMsgFound()) {
4670 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4671 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004672 }
4673 EndCommandBuffer();
4674}
4675
4676TEST_F(VkLayerTest, FillBufferAlignment)
4677{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004678 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4679 "dstOffset, is not a multiple of 4");
Mike Stroyan43909d82015-09-25 13:39:21 -06004680
4681 ASSERT_NO_FATAL_FAILURE(InitState());
4682
4683 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4684 vk_testing::Buffer buffer;
4685 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4686
4687 BeginCommandBuffer();
4688 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08004689 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004690 if (!m_errorMonitor->DesiredMsgFound()) {
4691 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
4692 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004693 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004694
Mike Stroyan43909d82015-09-25 13:39:21 -06004695 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004696 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4697 "size, is not a multiple of 4");
4698
Chia-I Wu1f851912015-10-27 18:04:07 +08004699 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004700
4701 if (!m_errorMonitor->DesiredMsgFound()) {
4702 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
4703 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004704 }
4705 EndCommandBuffer();
4706}
4707
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004708#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004709
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004710#if IMAGE_TESTS
4711TEST_F(VkLayerTest, InvalidImageView)
4712{
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004713 VkResult err;
4714
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004715 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4716 "vkCreateImageView called with baseMipLevel 10 ");
4717
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004718 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004719
Mike Stroyan43909d82015-09-25 13:39:21 -06004720 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004721 VkImage image;
4722
4723 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4724 const int32_t tex_width = 32;
4725 const int32_t tex_height = 32;
4726
4727 VkImageCreateInfo image_create_info = {};
4728 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4729 image_create_info.pNext = NULL;
4730 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4731 image_create_info.format = tex_format;
4732 image_create_info.extent.width = tex_width;
4733 image_create_info.extent.height = tex_height;
4734 image_create_info.extent.depth = 1;
4735 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004736 image_create_info.arrayLayers = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004737 image_create_info.samples = 1;
4738 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4739 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4740 image_create_info.flags = 0;
4741
Chia-I Wu69f40122015-10-26 21:10:41 +08004742 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004743 ASSERT_VK_SUCCESS(err);
4744
4745 VkImageViewCreateInfo image_view_create_info = {};
4746 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4747 image_view_create_info.image = image;
4748 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4749 image_view_create_info.format = tex_format;
Chia-I Wu1f851912015-10-27 18:04:07 +08004750 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004751 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu1f851912015-10-27 18:04:07 +08004752 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004753 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004754
4755 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08004756 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004757
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004758 if (!m_errorMonitor->DesiredMsgFound()) {
4759 FAIL() << "Did not receive Error 'vkCreateImageView called with baseMipLevel 10...'";
4760 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004761 }
4762}
Mike Stroyan43909d82015-09-25 13:39:21 -06004763
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004764TEST_F(VkLayerTest, InvalidImageViewAspect)
4765{
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004766 VkResult err;
4767
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004768 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4769 "vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set");
4770
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004771 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004772
4773 // Create an image and try to create a view with an invalid aspectMask
4774 VkImage image;
4775
4776 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4777 const int32_t tex_width = 32;
4778 const int32_t tex_height = 32;
4779
4780 VkImageCreateInfo image_create_info = {};
4781 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4782 image_create_info.pNext = NULL;
4783 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4784 image_create_info.format = tex_format;
4785 image_create_info.extent.width = tex_width;
4786 image_create_info.extent.height = tex_height;
4787 image_create_info.extent.depth = 1;
4788 image_create_info.mipLevels = 1;
4789 image_create_info.samples = 1;
4790 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4791 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4792 image_create_info.flags = 0;
4793
Chia-I Wu69f40122015-10-26 21:10:41 +08004794 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004795 ASSERT_VK_SUCCESS(err);
4796
4797 VkImageViewCreateInfo image_view_create_info = {};
4798 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4799 image_view_create_info.image = image;
4800 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4801 image_view_create_info.format = tex_format;
4802 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08004803 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004804 // Cause an error by setting an invalid image aspect
4805 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
4806
4807 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08004808 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004809
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004810 if (!m_errorMonitor->DesiredMsgFound()) {
4811 FAIL() << "Did not receive Error 'VkCreateImageView: Color image formats must have ...'";
4812 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004813 }
4814}
4815
Mike Stroyan43909d82015-09-25 13:39:21 -06004816TEST_F(VkLayerTest, CopyImageTypeMismatch)
4817{
Mike Stroyan43909d82015-09-25 13:39:21 -06004818 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004819 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004820
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004821 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4822 "vkCmdCopyImage called with unmatched source and dest image types");
4823
Mike Stroyan43909d82015-09-25 13:39:21 -06004824 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06004825
4826 // Create two images of different types and try to copy between them
4827 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08004828 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06004829 VkDeviceMemory srcMem;
4830 VkDeviceMemory destMem;
4831 VkMemoryRequirements memReqs;
4832
4833 VkImageCreateInfo image_create_info = {};
4834 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4835 image_create_info.pNext = NULL;
4836 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4837 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4838 image_create_info.extent.width = 32;
4839 image_create_info.extent.height = 32;
4840 image_create_info.extent.depth = 1;
4841 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004842 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06004843 image_create_info.samples = 1;
4844 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08004845 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004846 image_create_info.flags = 0;
4847
Chia-I Wu69f40122015-10-26 21:10:41 +08004848 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06004849 ASSERT_VK_SUCCESS(err);
4850
4851 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08004852 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004853
Chia-I Wu1f851912015-10-27 18:04:07 +08004854 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06004855 ASSERT_VK_SUCCESS(err);
4856
4857 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08004858 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06004859 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4860 memAlloc.pNext = NULL;
4861 memAlloc.allocationSize = 0;
4862 memAlloc.memoryTypeIndex = 0;
4863
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004864 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004865 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004866 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4867 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08004868 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06004869 ASSERT_VK_SUCCESS(err);
4870
Chia-I Wu1f851912015-10-27 18:04:07 +08004871 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004872 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004873 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06004874 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08004875 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06004876 ASSERT_VK_SUCCESS(err);
4877
4878 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4879 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08004880 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06004881 ASSERT_VK_SUCCESS(err);
4882
4883 BeginCommandBuffer();
4884 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08004885 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004886 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004887 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08004888 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004889 copyRegion.srcOffset.x = 0;
4890 copyRegion.srcOffset.y = 0;
4891 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08004892 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08004893 copyRegion.dstSubresource.mipLevel = 0;
4894 copyRegion.dstSubresource.baseArrayLayer = 0;
4895 copyRegion.dstSubresource.layerCount = 0;
4896 copyRegion.dstOffset.x = 0;
4897 copyRegion.dstOffset.y = 0;
4898 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004899 copyRegion.extent.width = 1;
4900 copyRegion.extent.height = 1;
4901 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08004902 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06004903 EndCommandBuffer();
4904
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004905 if (!m_errorMonitor->DesiredMsgFound()) {
4906 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
4907 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004908 }
4909
Chia-I Wu69f40122015-10-26 21:10:41 +08004910 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08004911 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08004912 vkFreeMemory(m_device->device(), srcMem, NULL);
4913 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06004914}
4915
4916TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
4917{
4918 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
4919}
4920
4921TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
4922{
Mike Stroyan43909d82015-09-25 13:39:21 -06004923 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004924 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004925
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004926 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4927 "vkCmdCopyImage called with unmatched source and dest image types");
4928
Mike Stroyan43909d82015-09-25 13:39:21 -06004929 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06004930
4931 // Create two images of different types and try to copy between them
4932 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08004933 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06004934 VkDeviceMemory srcMem;
4935 VkDeviceMemory destMem;
4936 VkMemoryRequirements memReqs;
4937
4938 VkImageCreateInfo image_create_info = {};
4939 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4940 image_create_info.pNext = NULL;
4941 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4942 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4943 image_create_info.extent.width = 32;
4944 image_create_info.extent.height = 32;
4945 image_create_info.extent.depth = 1;
4946 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004947 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06004948 image_create_info.samples = 1;
4949 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08004950 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004951 image_create_info.flags = 0;
4952
Chia-I Wu69f40122015-10-26 21:10:41 +08004953 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06004954 ASSERT_VK_SUCCESS(err);
4955
4956 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08004957 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004958
Chia-I Wu1f851912015-10-27 18:04:07 +08004959 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06004960 ASSERT_VK_SUCCESS(err);
4961
4962 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08004963 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06004964 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4965 memAlloc.pNext = NULL;
4966 memAlloc.allocationSize = 0;
4967 memAlloc.memoryTypeIndex = 0;
4968
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004969 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004970 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004971 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4972 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08004973 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06004974 ASSERT_VK_SUCCESS(err);
4975
Chia-I Wu1f851912015-10-27 18:04:07 +08004976 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004977 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004978 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4979 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08004980 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06004981 ASSERT_VK_SUCCESS(err);
4982
4983 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4984 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08004985 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06004986 ASSERT_VK_SUCCESS(err);
4987
4988 BeginCommandBuffer();
4989 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08004990 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004991 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004992 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08004993 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004994 copyRegion.srcOffset.x = 0;
4995 copyRegion.srcOffset.y = 0;
4996 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08004997 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08004998 copyRegion.dstSubresource.mipLevel = 0;
4999 copyRegion.dstSubresource.baseArrayLayer = 0;
5000 copyRegion.dstSubresource.layerCount = 0;
5001 copyRegion.dstOffset.x = 0;
5002 copyRegion.dstOffset.y = 0;
5003 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005004 copyRegion.extent.width = 1;
5005 copyRegion.extent.height = 1;
5006 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005007 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005008 EndCommandBuffer();
5009
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005010 if (!m_errorMonitor->DesiredMsgFound()) {
5011 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5012 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005013 }
5014
Chia-I Wu69f40122015-10-26 21:10:41 +08005015 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005016 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005017 vkFreeMemory(m_device->device(), srcMem, NULL);
5018 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005019}
5020
5021TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5022{
Mike Stroyan43909d82015-09-25 13:39:21 -06005023 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005024 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005025
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005026 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5027 "vkCmdResolveImage called with source sample count less than 2.");
5028
Mike Stroyan43909d82015-09-25 13:39:21 -06005029 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005030
5031 // Create two images of sample count 1 and try to Resolve between them
5032 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005033 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005034 VkDeviceMemory srcMem;
5035 VkDeviceMemory destMem;
5036 VkMemoryRequirements memReqs;
5037
5038 VkImageCreateInfo image_create_info = {};
5039 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5040 image_create_info.pNext = NULL;
5041 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5042 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5043 image_create_info.extent.width = 32;
5044 image_create_info.extent.height = 1;
5045 image_create_info.extent.depth = 1;
5046 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005047 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06005048 image_create_info.samples = 1;
5049 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005050 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005051 image_create_info.flags = 0;
5052
Chia-I Wu69f40122015-10-26 21:10:41 +08005053 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005054 ASSERT_VK_SUCCESS(err);
5055
5056 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005057 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005058
Chia-I Wu1f851912015-10-27 18:04:07 +08005059 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005060 ASSERT_VK_SUCCESS(err);
5061
5062 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005063 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06005064 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5065 memAlloc.pNext = NULL;
5066 memAlloc.allocationSize = 0;
5067 memAlloc.memoryTypeIndex = 0;
5068
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005069 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005070 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005071 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5072 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005073 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005074 ASSERT_VK_SUCCESS(err);
5075
Chia-I Wu1f851912015-10-27 18:04:07 +08005076 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005077 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005078 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5079 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005080 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005081 ASSERT_VK_SUCCESS(err);
5082
5083 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5084 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005085 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005086 ASSERT_VK_SUCCESS(err);
5087
5088 BeginCommandBuffer();
5089 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5090 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5091 //VK_IMAGE_LAYOUT_GENERAL = 1,
5092 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005093 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005094 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005095 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005096 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005097 resolveRegion.srcOffset.x = 0;
5098 resolveRegion.srcOffset.y = 0;
5099 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005100 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005101 resolveRegion.dstSubresource.mipLevel = 0;
5102 resolveRegion.dstSubresource.baseArrayLayer = 0;
5103 resolveRegion.dstSubresource.layerCount = 0;
5104 resolveRegion.dstOffset.x = 0;
5105 resolveRegion.dstOffset.y = 0;
5106 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005107 resolveRegion.extent.width = 1;
5108 resolveRegion.extent.height = 1;
5109 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005110 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005111 EndCommandBuffer();
5112
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005113 if (!m_errorMonitor->DesiredMsgFound()) {
5114 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source sample count less than 2.'";
5115 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005116 }
5117
Chia-I Wu69f40122015-10-26 21:10:41 +08005118 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005119 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005120 vkFreeMemory(m_device->device(), srcMem, NULL);
5121 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005122}
5123
5124TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5125{
Mike Stroyan43909d82015-09-25 13:39:21 -06005126 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005127 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005128
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005129 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5130 "vkCmdResolveImage called with dest sample count greater than 1.");
5131
Mike Stroyan43909d82015-09-25 13:39:21 -06005132 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005133
5134 // Create two images of sample count 2 and try to Resolve between them
5135 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005136 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005137 VkDeviceMemory srcMem;
5138 VkDeviceMemory destMem;
5139 VkMemoryRequirements memReqs;
5140
5141 VkImageCreateInfo image_create_info = {};
5142 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5143 image_create_info.pNext = NULL;
5144 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5145 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5146 image_create_info.extent.width = 32;
5147 image_create_info.extent.height = 1;
5148 image_create_info.extent.depth = 1;
5149 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005150 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06005151 image_create_info.samples = 2;
5152 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005153 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005154 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005155 image_create_info.flags = 0;
5156
Chia-I Wu69f40122015-10-26 21:10:41 +08005157 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005158 ASSERT_VK_SUCCESS(err);
5159
5160 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005161 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005162 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005163
Chia-I Wu1f851912015-10-27 18:04:07 +08005164 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005165 ASSERT_VK_SUCCESS(err);
5166
5167 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005168 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06005169 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5170 memAlloc.pNext = NULL;
5171 memAlloc.allocationSize = 0;
5172 memAlloc.memoryTypeIndex = 0;
5173
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005174 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005175 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005176 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5177 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005178 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005179 ASSERT_VK_SUCCESS(err);
5180
Chia-I Wu1f851912015-10-27 18:04:07 +08005181 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005182 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005183 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5184 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005185 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005186 ASSERT_VK_SUCCESS(err);
5187
5188 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5189 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005190 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005191 ASSERT_VK_SUCCESS(err);
5192
5193 BeginCommandBuffer();
5194 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5195 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5196 //VK_IMAGE_LAYOUT_GENERAL = 1,
5197 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005198 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005199 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005200 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005201 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005202 resolveRegion.srcOffset.x = 0;
5203 resolveRegion.srcOffset.y = 0;
5204 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005205 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005206 resolveRegion.dstSubresource.mipLevel = 0;
5207 resolveRegion.dstSubresource.baseArrayLayer = 0;
5208 resolveRegion.dstSubresource.layerCount = 0;
5209 resolveRegion.dstOffset.x = 0;
5210 resolveRegion.dstOffset.y = 0;
5211 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005212 resolveRegion.extent.width = 1;
5213 resolveRegion.extent.height = 1;
5214 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005215 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005216 EndCommandBuffer();
5217
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005218 if (!m_errorMonitor->DesiredMsgFound()) {
5219 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest sample count greater than 1.'";
5220 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005221 }
5222
Chia-I Wu69f40122015-10-26 21:10:41 +08005223 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005224 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005225 vkFreeMemory(m_device->device(), srcMem, NULL);
5226 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005227}
5228
5229TEST_F(VkLayerTest, ResolveImageFormatMismatch)
5230{
Mike Stroyan43909d82015-09-25 13:39:21 -06005231 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005232 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005233
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005234 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5235 "vkCmdResolveImage called with unmatched source and dest formats.");
5236
Mike Stroyan43909d82015-09-25 13:39:21 -06005237 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005238
5239 // Create two images of different types and try to copy between them
5240 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005241 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005242 VkDeviceMemory srcMem;
5243 VkDeviceMemory destMem;
5244 VkMemoryRequirements memReqs;
5245
5246 VkImageCreateInfo image_create_info = {};
5247 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5248 image_create_info.pNext = NULL;
5249 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5250 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5251 image_create_info.extent.width = 32;
5252 image_create_info.extent.height = 1;
5253 image_create_info.extent.depth = 1;
5254 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005255 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06005256 image_create_info.samples = 2;
5257 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005258 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005259 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005260 image_create_info.flags = 0;
5261
Chia-I Wu69f40122015-10-26 21:10:41 +08005262 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005263 ASSERT_VK_SUCCESS(err);
5264
Cody Northropb3bf94f2015-10-27 13:50:04 -06005265 // Set format to something other than source image
5266 image_create_info.format = VK_FORMAT_R32_SFLOAT;
5267 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005268 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005269 image_create_info.samples = 1;
5270
Chia-I Wu1f851912015-10-27 18:04:07 +08005271 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005272 ASSERT_VK_SUCCESS(err);
5273
5274 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005275 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06005276 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5277 memAlloc.pNext = NULL;
5278 memAlloc.allocationSize = 0;
5279 memAlloc.memoryTypeIndex = 0;
5280
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005281 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005282 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005283 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5284 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005285 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005286 ASSERT_VK_SUCCESS(err);
5287
Chia-I Wu1f851912015-10-27 18:04:07 +08005288 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005289 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005290 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5291 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005292 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005293 ASSERT_VK_SUCCESS(err);
5294
5295 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5296 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005297 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005298 ASSERT_VK_SUCCESS(err);
5299
5300 BeginCommandBuffer();
5301 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5302 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5303 //VK_IMAGE_LAYOUT_GENERAL = 1,
5304 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005305 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005306 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005307 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005308 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005309 resolveRegion.srcOffset.x = 0;
5310 resolveRegion.srcOffset.y = 0;
5311 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005312 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005313 resolveRegion.dstSubresource.mipLevel = 0;
5314 resolveRegion.dstSubresource.baseArrayLayer = 0;
5315 resolveRegion.dstSubresource.layerCount = 0;
5316 resolveRegion.dstOffset.x = 0;
5317 resolveRegion.dstOffset.y = 0;
5318 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005319 resolveRegion.extent.width = 1;
5320 resolveRegion.extent.height = 1;
5321 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005322 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005323 EndCommandBuffer();
5324
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005325 if (!m_errorMonitor->DesiredMsgFound()) {
5326 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest formats.'";
5327 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005328 }
5329
Chia-I Wu69f40122015-10-26 21:10:41 +08005330 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005331 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005332 vkFreeMemory(m_device->device(), srcMem, NULL);
5333 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005334}
5335
5336TEST_F(VkLayerTest, ResolveImageTypeMismatch)
5337{
Mike Stroyan43909d82015-09-25 13:39:21 -06005338 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005339 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005340
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005341 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5342 "vkCmdResolveImage called with unmatched source and dest image types.");
5343
Mike Stroyan43909d82015-09-25 13:39:21 -06005344 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005345
5346 // Create two images of different types and try to copy between them
5347 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005348 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005349 VkDeviceMemory srcMem;
5350 VkDeviceMemory destMem;
5351 VkMemoryRequirements memReqs;
5352
5353 VkImageCreateInfo image_create_info = {};
5354 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5355 image_create_info.pNext = NULL;
5356 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5357 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5358 image_create_info.extent.width = 32;
5359 image_create_info.extent.height = 1;
5360 image_create_info.extent.depth = 1;
5361 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005362 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06005363 image_create_info.samples = 2;
5364 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005365 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005366 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005367 image_create_info.flags = 0;
5368
Chia-I Wu69f40122015-10-26 21:10:41 +08005369 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005370 ASSERT_VK_SUCCESS(err);
5371
5372 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005373 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005374 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005375 image_create_info.samples = 1;
5376
Chia-I Wu1f851912015-10-27 18:04:07 +08005377 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005378 ASSERT_VK_SUCCESS(err);
5379
5380 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005381 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06005382 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5383 memAlloc.pNext = NULL;
5384 memAlloc.allocationSize = 0;
5385 memAlloc.memoryTypeIndex = 0;
5386
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005387 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005388 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005389 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5390 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005391 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005392 ASSERT_VK_SUCCESS(err);
5393
Chia-I Wu1f851912015-10-27 18:04:07 +08005394 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005395 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005396 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5397 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005398 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005399 ASSERT_VK_SUCCESS(err);
5400
5401 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5402 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005403 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005404 ASSERT_VK_SUCCESS(err);
5405
5406 BeginCommandBuffer();
5407 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5408 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5409 //VK_IMAGE_LAYOUT_GENERAL = 1,
5410 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005411 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005412 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005413 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005414 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005415 resolveRegion.srcOffset.x = 0;
5416 resolveRegion.srcOffset.y = 0;
5417 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005418 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005419 resolveRegion.dstSubresource.mipLevel = 0;
5420 resolveRegion.dstSubresource.baseArrayLayer = 0;
5421 resolveRegion.dstSubresource.layerCount = 0;
5422 resolveRegion.dstOffset.x = 0;
5423 resolveRegion.dstOffset.y = 0;
5424 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005425 resolveRegion.extent.width = 1;
5426 resolveRegion.extent.height = 1;
5427 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005428 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005429 EndCommandBuffer();
5430
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005431 if (!m_errorMonitor->DesiredMsgFound()) {
5432 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest image types.'";
5433 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005434 }
5435
Chia-I Wu69f40122015-10-26 21:10:41 +08005436 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005437 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005438 vkFreeMemory(m_device->device(), srcMem, NULL);
5439 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005440}
Tobin Ehlisb46be812015-10-23 16:00:08 -06005441
5442TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
5443{
5444 // Create a single Image descriptor and cause it to first hit an error due
5445 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
5446 // The image format check comes 2nd in validation so we trigger it first,
5447 // then when we cause aspect fail next, bad format check will be preempted
Tobin Ehlisb46be812015-10-23 16:00:08 -06005448 VkResult err;
5449
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005450 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5451 "Combination depth/stencil image formats can have only the ");
5452
Tobin Ehlisb46be812015-10-23 16:00:08 -06005453 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005454
Chia-I Wuc51b1212015-10-27 19:25:11 +08005455 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06005456 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu763a7492015-10-26 20:48:51 +08005457 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005458
5459 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5460 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5461 ds_pool_ci.pNext = NULL;
5462 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08005463 ds_pool_ci.poolSizeCount = 1;
5464 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005465
5466 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08005467 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005468 ASSERT_VK_SUCCESS(err);
5469
5470 VkDescriptorSetLayoutBinding dsl_binding = {};
5471 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5472 dsl_binding.arraySize = 1;
5473 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5474 dsl_binding.pImmutableSamplers = NULL;
5475
5476 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5477 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5478 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08005479 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08005480 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005481 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08005482 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005483 ASSERT_VK_SUCCESS(err);
5484
5485 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08005486 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06005487 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08005488 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005489 alloc_info.descriptorPool = ds_pool;
5490 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08005491 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005492 ASSERT_VK_SUCCESS(err);
5493
5494 VkImage image_bad;
5495 VkImage image_good;
5496 // One bad format and one good format for Color attachment
5497 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
5498 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
5499 const int32_t tex_width = 32;
5500 const int32_t tex_height = 32;
5501
5502 VkImageCreateInfo image_create_info = {};
5503 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5504 image_create_info.pNext = NULL;
5505 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5506 image_create_info.format = tex_format_bad;
5507 image_create_info.extent.width = tex_width;
5508 image_create_info.extent.height = tex_height;
5509 image_create_info.extent.depth = 1;
5510 image_create_info.mipLevels = 1;
5511 image_create_info.arrayLayers = 1;
5512 image_create_info.samples = 1;
5513 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5514 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
5515 image_create_info.flags = 0;
5516
Chia-I Wu69f40122015-10-26 21:10:41 +08005517 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005518 ASSERT_VK_SUCCESS(err);
5519 image_create_info.format = tex_format_good;
5520 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu69f40122015-10-26 21:10:41 +08005521 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005522 ASSERT_VK_SUCCESS(err);
5523
5524 VkImageViewCreateInfo image_view_create_info = {};
5525 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5526 image_view_create_info.image = image_bad;
5527 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5528 image_view_create_info.format = tex_format_bad;
5529 image_view_create_info.subresourceRange.baseArrayLayer = 0;
5530 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005531 image_view_create_info.subresourceRange.layerCount = 1;
5532 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005533 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5534
5535 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08005536 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005537
5538 if (!m_errorMonitor->DesiredMsgFound()) {
5539 FAIL() << "Did not receive Error 'Combination depth-stencil image formats can have only the....'";
5540 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06005541 }
5542
Chia-I Wu69f40122015-10-26 21:10:41 +08005543 vkDestroyImage(m_device->device(), image_bad, NULL);
5544 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005545 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5546 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005547}
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005548#endif // IMAGE_TESTS
5549
Tony Barbour30486ea2015-04-07 13:44:53 -06005550int main(int argc, char **argv) {
5551 int result;
5552
5553 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06005554 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06005555
5556 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
5557
5558 result = RUN_ALL_TESTS();
5559
Tony Barbour01999182015-04-09 12:58:51 -06005560 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06005561 return result;
5562}