blob: 8101ff7c868df75dd1cc6262d85b1c57d29a8297 [file] [log] [blame]
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001#include <vulkan.h>
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002#include "vk_debug_report_lunarg.h"
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -06003#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004#include "vkrenderframework.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -06005#include "vk_layer_config.h"
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006#include "../icd/common/icd-spv.h"
Tony Barbour300a6082015-04-07 13:44:53 -06007
Mark Lobodzinski3780e142015-05-14 15:08:13 -05008#define GLM_FORCE_RADIANS
9#include "glm/glm.hpp"
10#include <glm/gtc/matrix_transform.hpp>
11
Tobin Ehlis0788f522015-05-26 16:11:58 -060012#define MEM_TRACKER_TESTS 1
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013
Tobin Ehlis0788f522015-05-26 16:11:58 -060014#define OBJ_TRACKER_TESTS 1
15#define DRAW_STATE_TESTS 1
16#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120017#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060018#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060019#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060020
Mark Lobodzinski3780e142015-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 Northrop271ba752015-08-26 10:01:32 -060034 BsoFailLineWidth = 0x00000001,
35 BsoFailDepthBias = 0x00000002,
Cody Northrop12365112015-08-17 11:10:49 -060036 BsoFailViewport = 0x00000004,
Tobin Ehlis963a4042015-09-29 08:18:34 -060037 BsoFailScissor = 0x00000008,
38 BsoFailBlend = 0x00000010,
39 BsoFailDepthBounds = 0x00000020,
40 BsoFailStencilReadMask = 0x00000040,
41 BsoFailStencilWriteMask = 0x00000080,
42 BsoFailStencilReference = 0x00000100,
Mark Lobodzinski3780e142015-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 Lobodzinski75a97e62015-06-02 09:41:30 -050052static const char bindStateVertShaderText[] =
Mark Lobodzinski3780e142015-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 Lobodzinski75a97e62015-06-02 09:41:30 -050062static const char bindStateFragShaderText[] =
Cody Northrop8a3bb132015-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 Lobodzinski3780e142015-05-14 15:08:13 -050071
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -060072static VkBool32 myDbgFunc(
Tony Barbour67e99152015-07-10 14:10:27 -060073 VkFlags msgFlags,
74 VkDbgObjectType objType,
75 uint64_t srcObject,
Courtney Goeltzenleuchterf579fa62015-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 Barbour300a6082015-04-07 13:44:53 -060081
Mark Lobodzinski8507f2f2015-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 Barbour300a6082015-04-07 13:44:53 -060092class ErrorMonitor {
93public:
Tony Barbour15524c32015-04-29 17:34:29 -060094 ErrorMonitor()
Tony Barbour300a6082015-04-07 13:44:53 -060095 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060096 test_platform_thread_create_mutex(&m_mutex);
97 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060098 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060099 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600100 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600101 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600102
103 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString)
Tony Barbour300a6082015-04-07 13:44:53 -0600104 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600105 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-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 Stroyan4268d1f2015-07-13 14:45:35 -0600112 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600113 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600114
115 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString)
Tony Barbour300a6082015-04-07 13:44:53 -0600116 {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600118 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600119 if (m_bailout != NULL) {
120 *m_bailout = true;
121 }
Mark Lobodzinski8507f2f2015-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 Stroyan4268d1f2015-07-13 14:45:35 -0600132 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600133 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600134 }
Mark Lobodzinski8507f2f2015-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 Stroyanaccf7692015-05-12 16:00:45 -0600151 void SetBailout(bool *bailout)
152 {
153 m_bailout = bailout;
Tony Barbour300a6082015-04-07 13:44:53 -0600154 }
155
Mark Lobodzinski8507f2f2015-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 Barbour300a6082015-04-07 13:44:53 -0600165private:
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600166 VkFlags m_msgFlags;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600167 string m_desiredMsg;
168 string m_failureMsg;
169 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600170 test_platform_thread_mutex m_mutex;
171 bool* m_bailout;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600172 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600173};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500174
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600175static VkBool32 myDbgFunc(
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600176 VkFlags msgFlags,
Tony Barbour67e99152015-07-10 14:10:27 -0600177 VkDbgObjectType objType,
178 uint64_t srcObject,
Courtney Goeltzenleuchterf579fa62015-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 Barbour300a6082015-04-07 13:44:53 -0600184{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600185 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600186 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600187 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600188 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600189 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600190}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500191
Tony Barbour6918cd52015-04-09 12:58:51 -0600192class VkLayerTest : public VkRenderFramework
Tony Barbour300a6082015-04-07 13:44:53 -0600193{
194public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800195 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
196 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500197 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800198 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600199 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800200 { GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour300a6082015-04-07 13:44:53 -0600201
Tony Barbourfe3351b2015-07-28 10:17:20 -0600202 /* Convenience functions that use built-in command buffer */
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800203 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
204 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600205 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800206 { m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
Courtney Goeltzenleuchter08c26372015-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 Wu3432a0c2015-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 Barbourfe3351b2015-07-28 10:17:20 -0600211 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800212 { m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600213 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800214 { m_commandBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour300a6082015-04-07 13:44:53 -0600215protected:
Tony Barbour6918cd52015-04-09 12:58:51 -0600216 ErrorMonitor *m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600217
218 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600219 std::vector<const char *> instance_layer_names;
220 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600221 std::vector<const char *> instance_extension_names;
222 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600223
Courtney Goeltzenleuchter05159a92015-07-30 11:32:46 -0600224 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-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 Wu3432a0c2015-10-27 18:04:07 +0800230 // Use Threading layer first to protect others from ThreadCommandBufferCollision test
Courtney Goeltzenleuchtercd69eee2015-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 Lobodzinski209b5292015-09-17 09:44:05 -0600236 instance_layer_names.push_back("DeviceLimits");
Tobin Ehliscde08892015-09-22 10:11:37 -0600237 instance_layer_names.push_back("Image");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600238
Courtney Goeltzenleuchtercd69eee2015-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 Lobodzinski209b5292015-09-17 09:44:05 -0600244 device_layer_names.push_back("DeviceLimits");
Tobin Ehliscde08892015-09-22 10:11:37 -0600245 device_layer_names.push_back("Image");
Tony Barbour300a6082015-04-07 13:44:53 -0600246
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600247 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600248 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800249 this->app_info.pApplicationName = "layer_tests";
250 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600251 this->app_info.pEngineName = "unittest";
252 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600253 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour300a6082015-04-07 13:44:53 -0600254
Tony Barbour15524c32015-04-29 17:34:29 -0600255 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-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 Barbour300a6082015-04-07 13:44:53 -0600259 }
260
261 virtual void TearDown() {
262 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600263 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600264 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600265 }
266};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500267
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800268VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour300a6082015-04-07 13:44:53 -0600269{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600270 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600271
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800272 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-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 Forbes76a5eeb2015-06-16 14:05:59 +1200278 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800279 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600280 }
281
282 return result;
283}
284
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800285VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour300a6082015-04-07 13:44:53 -0600286{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600287 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600288
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200289 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800290 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200291 }
Tony Barbour300a6082015-04-07 13:44:53 -0600292
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800293 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600294
295 return result;
296}
297
Mark Lobodzinski3780e142015-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 Goeltzenleuchterd2635502015-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 Lobodzinski3780e142015-05-14 15:08:13 -0500338
339 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800340 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500341 pipelineobj.AddShader(&vs);
342 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-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 Ehlisd332f282015-10-02 11:00:56 -0600349 // Viewport and scissors must stay in synch or other errors will occur than the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600350 if (failMask & BsoFailViewport) {
351 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600352 m_viewports.clear();
353 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600354 }
355 if (failMask & BsoFailScissor) {
356 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600357 m_scissors.clear();
358 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-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 Lobodzinski3780e142015-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 Barbourfe3351b2015-07-28 10:17:20 -0600380 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500381
Tony Barbourfe3351b2015-07-28 10:17:20 -0600382 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500383
384 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600385 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500386
387 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600388 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500389
Tony Barbourfe3351b2015-07-28 10:17:20 -0600390 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500391}
392
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800393void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500394{
395 if (m_depthStencil->Initialized()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800396 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500397 } else {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800398 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500399 }
400
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800401 commandBuffer->PrepareAttachments();
Cody Northrop82485a82015-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 Barboureb254902015-07-15 12:50:33 -0600404 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-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 Barboureb254902015-07-15 12:50:33 -0600409
410 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
411 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-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 Barboureb254902015-07-15 12:50:33 -0600420
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600421 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600422 pipelineobj.SetViewport(m_viewports);
423 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800424 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Cody Northrop29a08f22015-08-27 10:20:35 -0600425 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
426 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800427 commandBuffer->BindPipeline(pipelineobj);
428 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500429}
430
431// ********************************************************************************************************************
432// ********************************************************************************************************************
433// ********************************************************************************************************************
434// ********************************************************************************************************************
Tobin Ehlis0788f522015-05-26 16:11:58 -0600435#if MEM_TRACKER_TESTS
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800436TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500437{
438 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-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 Lobodzinski8507f2f2015-10-29 09:02:49 -0600444 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Resetting CB");
445
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500446 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-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 Lobodzinskiccb2b042015-05-19 10:28:29 -0500451
Tony Barbourfe3351b2015-07-28 10:17:20 -0600452 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800453 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600454 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-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 Goeltzenleuchter806c7002015-10-27 11:22:14 -0600460 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800461 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
462 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800463 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600464 submit_info.pWaitSemaphores = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800465 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800466 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800467 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600468 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600469
470 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500471 ASSERT_VK_SUCCESS( err );
472
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500473 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800474 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500475
Mark Lobodzinski8507f2f2015-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 Lobodzinskiccb2b042015-05-19 10:28:29 -0500479 }
480}
481
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800482TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500483{
484 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-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 Lobodzinski8507f2f2015-10-29 09:02:49 -0600490 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Calling vkBeginCommandBuffer() on active CB");
491
Mark Lobodzinskiccb2b042015-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 Barbourfe3351b2015-07-28 10:17:20 -0600496 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800497 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600498 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-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 Goeltzenleuchter806c7002015-10-27 11:22:14 -0600504 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800505 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
506 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800507 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600508 submit_info.pWaitSemaphores = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800509 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800510 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800511 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600512 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600513
514 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500515 ASSERT_VK_SUCCESS( err );
516
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600517
Chia-I Wu3432a0c2015-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 Lobodzinski5fcc4212015-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 Wu3432a0c2015-10-27 18:04:07 +0800526 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500527
Mark Lobodzinski8507f2f2015-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 Lobodzinskiccb2b042015-05-19 10:28:29 -0500532 }
533}
534
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500535TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
536{
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500537 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600538 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500539
Mark Lobodzinski8507f2f2015-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 Lobodzinski3780e142015-05-14 15:08:13 -0500543 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500544
545 // Create an image, allocate memory, free it, and then try to bind it
546 VkImage image;
Mark Lobodzinski23065352015-05-29 09:32:35 -0500547 VkDeviceMemory mem;
548 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-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 Lobodzinski3780e142015-05-14 15:08:13 -0500553
Tony Barboureb254902015-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 Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600563 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +0800564 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barboureb254902015-07-15 12:50:33 -0600565 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
566 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
567 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600568
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800569 VkMemoryAllocateInfo mem_alloc = {};
Tony Barboureb254902015-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 Lobodzinski3780e142015-05-14 15:08:13 -0500573 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -0600574 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500575
Chia-I Wuf7458c52015-10-26 21:10:41 +0800576 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500577 ASSERT_VK_SUCCESS(err);
578
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600579 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500580 image,
Mark Lobodzinski23065352015-05-29 09:32:35 -0500581 &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500582
Mark Lobodzinski23065352015-05-29 09:32:35 -0500583 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500584
Courtney Goeltzenleuchter1d2f0dd2015-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 Wuf7458c52015-10-26 21:10:41 +0800587 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -0600588 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -0600589 }
Mike Stroyan713b2d72015-08-04 10:49:29 -0600590
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500591 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800592 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500593 ASSERT_VK_SUCCESS(err);
594
595 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -0600596 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-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 Lobodzinski23065352015-05-29 09:32:35 -0500601 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500602
Mark Lobodzinski8507f2f2015-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 Lobodzinski3780e142015-05-14 15:08:13 -0500606 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600607
Chia-I Wuf7458c52015-10-26 21:10:41 +0800608 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500609}
610
Tobin Ehlis2717d132015-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 Ehlis2717d132015-07-10 18:25:07 -0600615// VkResult err;
616//
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600617// m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
618// "Freeing memory object while it still has references");
Tobin Ehlis2717d132015-07-10 18:25:07 -0600619//
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600620// ASSERT_NO_FATAL_FAILURE(InitState());
621
Tobin Ehlis2717d132015-07-10 18:25:07 -0600622// // Create an image, allocate memory, free it, and then try to bind it
623// VkImage image;
624// VkDeviceMemory mem;
625// VkMemoryRequirements mem_reqs;
626//
627// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
628// const int32_t tex_width = 32;
629// const int32_t tex_height = 32;
630//
631// const VkImageCreateInfo image_create_info = {
632// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
633// .pNext = NULL,
634// .imageType = VK_IMAGE_TYPE_2D,
635// .format = tex_format,
636// .extent = { tex_width, tex_height, 1 },
637// .mipLevels = 1,
638// .arraySize = 1,
Chia-I Wu5c17c962015-10-31 00:31:16 +0800639// .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlis2717d132015-07-10 18:25:07 -0600640// .tiling = VK_IMAGE_TILING_LINEAR,
641// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
642// .flags = 0,
643// };
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800644// VkMemoryAllocateInfo mem_alloc = {
Tobin Ehlis2717d132015-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 Wuf7458c52015-10-26 21:10:41 +0800651// err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis2717d132015-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 Wu3432a0c2015-10-27 18:04:07 +0800665// err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis2717d132015-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 Wuf7458c52015-10-26 21:10:41 +0800673// vkFreeMemory(m_device->device(), mem, NULL);
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600674//
Mark Lobodzinski8507f2f2015-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 Ehlis2717d132015-07-10 18:25:07 -0600678// }
679//}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500680
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500681TEST_F(VkLayerTest, RebindMemory)
682{
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500683 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600684 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500685
Mark Lobodzinski8507f2f2015-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 Lobodzinski944aab12015-06-05 13:59:04 -0500689 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-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 Lobodzinski944aab12015-06-05 13:59:04 -0500700
Tony Barboureb254902015-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 Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600710 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +0800711 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barboureb254902015-07-15 12:50:33 -0600712 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
713 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
714 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500715
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800716 VkMemoryAllocateInfo mem_alloc = {};
Tony Barboureb254902015-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 Wuf7458c52015-10-26 21:10:41 +0800724 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500725 ASSERT_VK_SUCCESS(err);
726
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600727 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500728 image,
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500729 &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500730
731 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600732 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
733 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500734
735 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800736 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500737 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800738 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500739 ASSERT_VK_SUCCESS(err);
740
741 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -0600742 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-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 Barbour67e99152015-07-10 14:10:27 -0600746 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500747
Mark Lobodzinski8507f2f2015-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 Lobodzinski944aab12015-06-05 13:59:04 -0500751 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600752
Chia-I Wuf7458c52015-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 Lobodzinski944aab12015-06-05 13:59:04 -0500756}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500757
Tony Barbour0b4d9562015-04-09 10:48:04 -0600758TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour300a6082015-04-07 13:44:53 -0600759{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600760 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-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 Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600764
765 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-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 Barbour300a6082015-04-07 13:44:53 -0600769
Tony Barbour300a6082015-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 Barbourfe3351b2015-07-28 10:17:20 -0600774 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800775 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600776 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600777
778 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600779
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600780 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800781 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
782 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800783 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600784 submit_info.pWaitSemaphores = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800785 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800786 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800787 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600788 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600789
790 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600791 vkQueueWaitIdle(m_device->m_queue );
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600792
Mark Lobodzinski8507f2f2015-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 Barbour0b4d9562015-04-09 10:48:04 -0600796 }
Tony Barbour0b4d9562015-04-09 10:48:04 -0600797}
798
799TEST_F(VkLayerTest, ResetUnsignaledFence)
800{
801 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600802 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600803 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
804 fenceInfo.pNext = NULL;
805
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600806 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
807 "submitted to VkResetFences in UNSIGNALED STATE");
808
Tony Barbour0b4d9562015-04-09 10:48:04 -0600809 ASSERT_NO_FATAL_FAILURE(InitState());
810 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +0800811 VkFence fences[1] = {testFence.handle()};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600812 vkResetFences(m_device->device(), 1, fences);
Tony Barbour300a6082015-04-07 13:44:53 -0600813
Mark Lobodzinski8507f2f2015-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 Barbour300a6082015-04-07 13:44:53 -0600818}
Tobin Ehlis41376e12015-07-03 08:45:14 -0600819
Chia-I Wu08accc62015-07-07 11:50:03 +0800820/* TODO: Update for changes due to bug-14075 tiling across render passes */
821#if 0
Tobin Ehlis41376e12015-07-03 08:45:14 -0600822TEST_F(VkLayerTest, InvalidUsageBits)
823{
824 // Initiate Draw w/o a PSO bound
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600825
826 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
827 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -0600828
829 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800830 VkCommandBufferObj commandBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600831 BeginCommandBuffer();
Tobin Ehlis41376e12015-07-03 08:45:14 -0600832
833 const VkExtent3D e3d = {
834 .width = 128,
835 .height = 128,
836 .depth = 1,
837 };
838 const VkImageCreateInfo ici = {
839 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
840 .pNext = NULL,
841 .imageType = VK_IMAGE_TYPE_2D,
842 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
843 .extent = e3d,
844 .mipLevels = 1,
845 .arraySize = 1,
Chia-I Wu5c17c962015-10-31 00:31:16 +0800846 .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600847 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -0600848 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlis41376e12015-07-03 08:45:14 -0600849 .flags = 0,
850 };
851
852 VkImage dsi;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800853 vkCreateImage(m_device->device(), &ici, NULL, &dsi);
Tobin Ehlis41376e12015-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 Goeltzenleuchter4a261892015-09-10 16:38:41 -0600860 .baseArrayLayer = 0,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600861 .arraySize = 1,
862 .flags = 0,
863 };
Chia-I Wuf7458c52015-10-26 21:10:41 +0800864 vkCreateDepthStencilView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600865
866 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis41376e12015-07-03 08:45:14 -0600867 FAIL() << "Error received was not 'Invalid usage flag for image...'";
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600868 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis41376e12015-07-03 08:45:14 -0600869 }
870}
Mark Lobodzinski209b5292015-09-17 09:44:05 -0600871#endif // 0
872#endif // MEM_TRACKER_TESTS
873
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600874#if OBJ_TRACKER_TESTS
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600875TEST_F(VkLayerTest, PipelineNotBound)
876{
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600877 VkResult err;
878
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600879 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
880 "Invalid VkPipeline Object ");
881
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600882 ASSERT_NO_FATAL_FAILURE(InitState());
883 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600884
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800885 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600886 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800887 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-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 Goeltzenleuchterfe908d32015-09-16 16:12:45 -0600892 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800893 ds_pool_ci.poolSizeCount = 1;
894 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600895
896 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800897 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600898 ASSERT_VK_SUCCESS(err);
899
900 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +0800901 dsl_binding.binding = 0;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600902 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
903 dsl_binding.arraySize = 1;
904 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
905 dsl_binding.pImmutableSamplers = NULL;
906
907 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
908 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
909 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800910 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +0800911 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600912
913 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800914 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600915 ASSERT_VK_SUCCESS(err);
916
917 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800918 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600919 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800920 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600921 alloc_info.descriptorPool = ds_pool;
922 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800923 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600924 ASSERT_VK_SUCCESS(err);
925
926 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
927 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
928 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800929 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600930 pipeline_layout_ci.pSetLayouts = &ds_layout;
931
932 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800933 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600934 ASSERT_VK_SUCCESS(err);
935
936 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
937
938 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800939 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600940
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600941 if (!m_errorMonitor->DesiredMsgFound()) {
942 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be'" << endl;
943 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisec598302015-09-15 15:02:17 -0600944 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600945
Chia-I Wuf7458c52015-10-26 21:10:41 +0800946 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
947 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
948 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -0600949}
950
951TEST_F(VkLayerTest, BindInvalidMemory)
952{
Tobin Ehlisec598302015-09-15 15:02:17 -0600953 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600954 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -0600955
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600956 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
957 "Invalid VkDeviceMemory Object ");
958
Tobin Ehlisec598302015-09-15 15:02:17 -0600959 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -0600960
961 // Create an image, allocate memory, free it, and then try to bind it
962 VkImage image;
963 VkDeviceMemory mem;
964 VkMemoryRequirements mem_reqs;
965
966 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
967 const int32_t tex_width = 32;
968 const int32_t tex_height = 32;
969
970 VkImageCreateInfo image_create_info = {};
971 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
972 image_create_info.pNext = NULL;
973 image_create_info.imageType = VK_IMAGE_TYPE_2D;
974 image_create_info.format = tex_format;
975 image_create_info.extent.width = tex_width;
976 image_create_info.extent.height = tex_height;
977 image_create_info.extent.depth = 1;
978 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600979 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +0800980 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisec598302015-09-15 15:02:17 -0600981 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
982 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
983 image_create_info.flags = 0;
984
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800985 VkMemoryAllocateInfo mem_alloc = {};
Tobin Ehlisec598302015-09-15 15:02:17 -0600986 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
987 mem_alloc.pNext = NULL;
988 mem_alloc.allocationSize = 0;
989 mem_alloc.memoryTypeIndex = 0;
990
Chia-I Wuf7458c52015-10-26 21:10:41 +0800991 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -0600992 ASSERT_VK_SUCCESS(err);
993
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600994 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlisec598302015-09-15 15:02:17 -0600995 image,
996 &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -0600997
998 mem_alloc.allocationSize = mem_reqs.size;
999
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001000 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1001 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001002
1003 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001004 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001005 ASSERT_VK_SUCCESS(err);
1006
1007 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001008 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001009
1010 // Try to bind free memory that has been freed
1011 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1012 // This may very well return an error.
1013 (void)err;
1014
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001015 if (!m_errorMonitor->DesiredMsgFound()) {
1016 FAIL() << "Did not receive Error 'Invalid VkDeviceMemory Object 0x<handle>'";
1017 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisec598302015-09-15 15:02:17 -06001018 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001019
Chia-I Wuf7458c52015-10-26 21:10:41 +08001020 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001021}
1022
1023TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
1024{
Tobin Ehlisec598302015-09-15 15:02:17 -06001025 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001026 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06001027
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001028 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Invalid VkImage Object ");
1029
Tobin Ehlisec598302015-09-15 15:02:17 -06001030 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06001031
1032 // Create an image object, allocate memory, destroy the object and then try to bind it
1033 VkImage image;
1034 VkDeviceMemory mem;
1035 VkMemoryRequirements mem_reqs;
1036
1037 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1038 const int32_t tex_width = 32;
1039 const int32_t tex_height = 32;
1040
1041 VkImageCreateInfo image_create_info = {};
1042 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1043 image_create_info.pNext = NULL;
1044 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1045 image_create_info.format = tex_format;
1046 image_create_info.extent.width = tex_width;
1047 image_create_info.extent.height = tex_height;
1048 image_create_info.extent.depth = 1;
1049 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06001050 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001051 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisec598302015-09-15 15:02:17 -06001052 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1053 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1054 image_create_info.flags = 0;
1055
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001056 VkMemoryAllocateInfo mem_alloc = {};
Tobin Ehlisec598302015-09-15 15:02:17 -06001057 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1058 mem_alloc.pNext = NULL;
1059 mem_alloc.allocationSize = 0;
1060 mem_alloc.memoryTypeIndex = 0;
1061
Chia-I Wuf7458c52015-10-26 21:10:41 +08001062 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06001063 ASSERT_VK_SUCCESS(err);
1064
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001065 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlisec598302015-09-15 15:02:17 -06001066 image,
1067 &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06001068
1069 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001070 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1071 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001072
1073 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001074 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001075 ASSERT_VK_SUCCESS(err);
1076
1077 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001078 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001079 ASSERT_VK_SUCCESS(err);
1080
1081 // Now Try to bind memory to this destroyed object
1082 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1083 // This may very well return an error.
1084 (void) err;
1085
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001086 if (!m_errorMonitor->DesiredMsgFound()) {
1087 FAIL() << "Did not receive Error 'Invalid VkImage Object 0x<handle>'";
1088 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001089 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001090
Chia-I Wuf7458c52015-10-26 21:10:41 +08001091 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001092}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001093
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001094#endif // OBJ_TRACKER_TESTS
1095
Tobin Ehlis0788f522015-05-26 16:11:58 -06001096#if DRAW_STATE_TESTS
Tobin Ehlis963a4042015-09-29 08:18:34 -06001097TEST_F(VkLayerTest, LineWidthStateNotBound)
1098{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001099 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1100 "Dynamic line width state not set for this command buffer");
1101
Tobin Ehlis963a4042015-09-29 08:18:34 -06001102 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1103
1104 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1105
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001106 if (!m_errorMonitor->DesiredMsgFound()) {
1107 FAIL() << "Did not receive Error 'Dynamic line width state not set for this command buffer'";
1108 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001109 }
1110}
1111
1112TEST_F(VkLayerTest, DepthBiasStateNotBound)
1113{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001114 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1115 "Dynamic depth bias state not set for this command buffer");
1116
Tobin Ehlis963a4042015-09-29 08:18:34 -06001117 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1118
1119 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1120
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001121 if (!m_errorMonitor->DesiredMsgFound()) {
1122 FAIL() << "Did not receive Error 'Dynamic depth bias state not set for this command buffer'";
1123 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001124 }
1125}
1126
Cody Northrop4063c9a2015-10-27 16:54:28 -06001127// Disable these two tests until we can sort out how to track multiple layer errors
Tobin Ehlis963a4042015-09-29 08:18:34 -06001128TEST_F(VkLayerTest, ViewportStateNotBound)
1129{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001130 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1131 "Dynamic viewport state not set for this command buffer");
1132
Tobin Ehlis963a4042015-09-29 08:18:34 -06001133 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1134
1135 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1136
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001137 if (!m_errorMonitor->DesiredMsgFound()) {
1138 FAIL() << "Did not recieve Error 'Dynamic scissor state not set for this command buffer'";
1139 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001140 }
1141}
1142
1143TEST_F(VkLayerTest, ScissorStateNotBound)
1144{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001145 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1146 "Dynamic scissor state not set for this command buffer");
1147
Tobin Ehlis963a4042015-09-29 08:18:34 -06001148 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1149
1150 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1151
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001152 if (!m_errorMonitor->DesiredMsgFound()) {
1153 FAIL() << "Did not recieve Error ' Expected: 'Dynamic scissor state not set for this command buffer'";
1154 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001155 }
1156}
1157
Tobin Ehlis963a4042015-09-29 08:18:34 -06001158TEST_F(VkLayerTest, BlendStateNotBound)
1159{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001160 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1161 "Dynamic blend object state not set for this command buffer");
1162
Tobin Ehlis963a4042015-09-29 08:18:34 -06001163 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1164
1165 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1166
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001167 if (!m_errorMonitor->DesiredMsgFound()) {
1168 FAIL() << "Did not recieve Error 'Dynamic blend object state not set for this command buffer'";
1169 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001170 }
1171}
1172
1173TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1174{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001175 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1176 "Dynamic depth bounds state not set for this command buffer");
1177
Tobin Ehlis963a4042015-09-29 08:18:34 -06001178 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1179
1180 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1181
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001182 if (!m_errorMonitor->DesiredMsgFound()) {
1183 FAIL() << "Did not receive Error 'Dynamic depth bounds state not set for this command buffer'";
1184 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001185 }
1186}
1187
1188TEST_F(VkLayerTest, StencilReadMaskNotSet)
1189{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001190 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1191 "Dynamic stencil read mask state not set for this command buffer");
1192
Tobin Ehlis963a4042015-09-29 08:18:34 -06001193 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001194
Tobin Ehlis963a4042015-09-29 08:18:34 -06001195 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1196
1197 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1198
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001199 if (!m_errorMonitor->DesiredMsgFound()) {
1200 FAIL() << "Did not receive Error 'Dynamic stencil read mask state not set for this command buffer'";
1201 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001202 }
1203}
1204
1205TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1206{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001207 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1208 "Dynamic stencil write mask state not set for this command buffer");
1209
Tobin Ehlis963a4042015-09-29 08:18:34 -06001210 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001211
Tobin Ehlis963a4042015-09-29 08:18:34 -06001212 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1213
1214 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1215
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001216 if (!m_errorMonitor->DesiredMsgFound()) {
1217 FAIL() << "Did not receive Error 'Dynamic stencil write mask state not set for this command buffer'";
1218 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001219 }
1220}
1221
1222TEST_F(VkLayerTest, StencilReferenceNotSet)
1223{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001224 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1225 "Dynamic stencil reference state not set for this command buffer");
1226
Tobin Ehlis963a4042015-09-29 08:18:34 -06001227 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1228
1229 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1230
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001231 if (!m_errorMonitor->DesiredMsgFound()) {
1232 FAIL() << "Did not receive Error 'Dynamic stencil reference state not set for this command buffer'";
1233 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001234 }
1235}
1236
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001237TEST_F(VkLayerTest, CommandBufferTwoSubmits)
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001238{
1239 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001240
1241 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1242 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001243
1244 VkFenceCreateInfo fenceInfo = {};
1245 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1246 fenceInfo.pNext = NULL;
1247 fenceInfo.flags = 0;
1248
1249 ASSERT_NO_FATAL_FAILURE(InitState());
1250 ASSERT_NO_FATAL_FAILURE(InitViewport());
1251 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1252
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001253 // We luck out b/c by default the framework creates CB w/ the VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001254 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001255 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001256 EndCommandBuffer();
1257
1258 testFence.init(*m_device, fenceInfo);
1259
1260 // Bypass framework since it does the waits automatically
1261 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001262 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001263 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1264 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001265 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001266 submit_info.pWaitSemaphores = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001267 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001268 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001269 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001270 submit_info.pSignalSemaphores = NULL;
1271
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001272 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001273 ASSERT_VK_SUCCESS( err );
1274
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001275 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001276 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001277
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001278 if (!m_errorMonitor->DesiredMsgFound()) {
1279 FAIL() << "Did not receive Error 'CB (0xaddress) was created w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
1280 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001281 }
1282}
1283
Tobin Ehlis502480b2015-06-24 15:53:07 -06001284TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001285{
1286 // Initiate Draw w/o a PSO bound
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001287 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001288
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001289 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1290 "Incorrectly binding graphics pipeline ");
1291
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001292 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001293 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001294
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001295 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001296 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001297 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001298
1299 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1300 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1301 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001302 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001303 ds_pool_ci.poolSizeCount = 1;
1304 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001305
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001306 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001307 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001308 ASSERT_VK_SUCCESS(err);
1309
1310 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001311 dsl_binding.binding = 0;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001312 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1313 dsl_binding.arraySize = 1;
1314 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1315 dsl_binding.pImmutableSamplers = NULL;
1316
1317 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1318 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1319 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001320 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001321 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001322
1323 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001324 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001325 ASSERT_VK_SUCCESS(err);
1326
1327 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001328 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001329 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001330 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001331 alloc_info.descriptorPool = ds_pool;
1332 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001333 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001334 ASSERT_VK_SUCCESS(err);
1335 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1336 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1337 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001338 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001339 pipe_ms_state_ci.sampleShadingEnable = 0;
1340 pipe_ms_state_ci.minSampleShading = 1.0;
1341 pipe_ms_state_ci.pSampleMask = NULL;
1342
1343 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1344 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1345 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001346 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001347 pipeline_layout_ci.pSetLayouts = &ds_layout;
1348 VkPipelineLayout pipeline_layout;
1349
Chia-I Wuf7458c52015-10-26 21:10:41 +08001350 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001351 ASSERT_VK_SUCCESS(err);
1352
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001353 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1354 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001355 // but add it to be able to run on more devices
1356 VkPipelineObj pipe(m_device);
1357 pipe.AddShader(&vs);
1358 pipe.AddShader(&fs);
1359 pipe.SetMSAA(&pipe_ms_state_ci);
1360 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001361
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001362 // Calls AllocateCommandBuffers
1363 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
1364 VkCommandBufferBeginInfo cmd_buf_info = {};
1365 memset(&cmd_buf_info, 0, sizeof(VkCommandBufferBeginInfo));
1366 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001367 cmd_buf_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001368 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001369
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001370 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
1371 vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001372
1373 if (!m_errorMonitor->DesiredMsgFound()) {
1374 FAIL() << "Did not receive Error 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass'";
1375 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001376 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001377
Chia-I Wuf7458c52015-10-26 21:10:41 +08001378 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1379 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1380 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001381}
1382
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001383TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1384{
1385 // Initiate Draw w/o a PSO bound
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001386 VkResult err;
1387
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001388 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1389 "Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
1390
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001391 ASSERT_NO_FATAL_FAILURE(InitState());
1392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001393
1394 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001395 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001396 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001397 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001398
1399 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1400 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1401 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001402 ds_pool_ci.flags = 0;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001403 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001404 ds_pool_ci.poolSizeCount = 1;
1405 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001406
1407 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001408 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001409 ASSERT_VK_SUCCESS(err);
1410
1411 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001412 dsl_binding.binding = 0;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001413 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1414 dsl_binding.arraySize = 1;
1415 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1416 dsl_binding.pImmutableSamplers = NULL;
1417
1418 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1419 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1420 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001421 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001422 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001423
1424 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001425 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001426 ASSERT_VK_SUCCESS(err);
1427
1428 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001429 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001430 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001431 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001432 alloc_info.descriptorPool = ds_pool;
1433 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001434 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001435
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001436 if (!m_errorMonitor->DesiredMsgFound()) {
1437 FAIL() << "Did not receive Error 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...'";
1438 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001439 }
1440
Chia-I Wuf7458c52015-10-26 21:10:41 +08001441 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1442 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001443}
1444
Tobin Ehlise735c692015-10-08 13:13:50 -06001445TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1446{
Tobin Ehlise735c692015-10-08 13:13:50 -06001447 VkResult err;
1448
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001449 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1450 "It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
1451
Tobin Ehlise735c692015-10-08 13:13:50 -06001452 ASSERT_NO_FATAL_FAILURE(InitState());
1453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06001454
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001455 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise735c692015-10-08 13:13:50 -06001456 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001457 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06001458
1459 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1460 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1461 ds_pool_ci.pNext = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06001462 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001463 ds_pool_ci.poolSizeCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001464 ds_pool_ci.flags = 0;
1465 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1466 // app can only call vkResetDescriptorPool on this pool.;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001467 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06001468
1469 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001470 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06001471 ASSERT_VK_SUCCESS(err);
1472
1473 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001474 dsl_binding.binding = 0;
Tobin Ehlise735c692015-10-08 13:13:50 -06001475 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1476 dsl_binding.arraySize = 1;
1477 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1478 dsl_binding.pImmutableSamplers = NULL;
1479
1480 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1481 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1482 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001483 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001484 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06001485
1486 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001487 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06001488 ASSERT_VK_SUCCESS(err);
1489
1490 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001491 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001492 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001493 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001494 alloc_info.descriptorPool = ds_pool;
1495 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001496 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06001497 ASSERT_VK_SUCCESS(err);
1498
1499 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001500 if (!m_errorMonitor->DesiredMsgFound()) {
1501 FAIL() << "Did not receive Error 'It is invalid to call vkFreeDescriptorSets() with a pool created with...'";
1502 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise735c692015-10-08 13:13:50 -06001503 }
1504
Chia-I Wuf7458c52015-10-26 21:10:41 +08001505 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1506 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06001507}
1508
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001509TEST_F(VkLayerTest, InvalidDescriptorPool)
1510{
1511 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1512 // The DS check for this is after driver has been called to validate DS internal data struct
1513 // Attempt to clear DS Pool with bad object
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001514/*
1515 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1516 "Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call");
1517
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001518 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1519 vkResetDescriptorPool(device(), badPool);
1520
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001521 if (!m_errorMonitor->DesiredMsgFound()) {
1522 FAIL() << "Did not receive Error 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1523 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001524 }*/
1525}
1526
1527TEST_F(VkLayerTest, InvalidDescriptorSet)
1528{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001529 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1530 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001531 // Create a valid cmd buffer
1532 // call vkCmdBindDescriptorSets w/ false DS
1533}
1534
1535TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1536{
1537 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1538 // The DS check for this is after driver has been called to validate DS internal data struct
1539}
1540
1541TEST_F(VkLayerTest, InvalidPipeline)
1542{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001543 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1544 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001545 // Create a valid cmd buffer
1546 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001547//
1548// m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1549// "Attempt to bind Pipeline ");
Tobin Ehlis502480b2015-06-24 15:53:07 -06001550//
1551// ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001552// VkCommandBufferObj commandBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001553// BeginCommandBuffer();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001554// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001555// vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001556//
1557// if (!m_errorMonitor->DesiredMsgFound()) {
1558// FAIL() << "Did not receive Error 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1559// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001560// }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001561}
1562
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001563TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001564{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001565 // Create and update CommandBuffer then call QueueSubmit w/o calling End on CommandBuffer
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001566 VkResult err;
1567
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001568 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
1569 " bound but it was never updated. ");
1570
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001571 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06001572 ASSERT_NO_FATAL_FAILURE(InitViewport());
1573 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001574 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06001575 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001576 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001577
1578 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1579 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1580 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001581 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001582 ds_pool_ci.poolSizeCount = 1;
1583 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06001584
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001585 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001586 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001587 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001588
Tony Barboureb254902015-07-15 12:50:33 -06001589 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001590 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001591 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1592 dsl_binding.arraySize = 1;
1593 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1594 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001595
Tony Barboureb254902015-07-15 12:50:33 -06001596 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1597 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1598 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001599 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001600 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001601 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001602 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001603 ASSERT_VK_SUCCESS(err);
1604
1605 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001606 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001607 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001608 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001609 alloc_info.descriptorPool = ds_pool;
1610 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001611 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001612 ASSERT_VK_SUCCESS(err);
1613
Tony Barboureb254902015-07-15 12:50:33 -06001614 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1615 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1616 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001617 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001618 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001619
1620 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001621 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001622 ASSERT_VK_SUCCESS(err);
1623
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001624 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001625 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
1626 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001627
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001628 VkPipelineObj pipe(m_device);
1629 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06001630 pipe.AddShader(&fs);
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001631 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001632
1633 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001634 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1635 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001636
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001637 if (!m_errorMonitor->DesiredMsgFound()) {
1638 FAIL() << "Did not recieve Warning 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1639 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001640 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001641
Chia-I Wuf7458c52015-10-26 21:10:41 +08001642 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1643 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1644 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001645}
1646
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001647TEST_F(VkLayerTest, InvalidBufferViewObject)
1648{
1649 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
1650 VkResult err;
1651
1652 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1653 "Attempt to update descriptor with invalid bufferView ");
1654
1655 ASSERT_NO_FATAL_FAILURE(InitState());
1656 VkDescriptorPoolSize ds_type_count = {};
1657 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1658 ds_type_count.descriptorCount = 1;
1659
1660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1662 ds_pool_ci.pNext = NULL;
1663 ds_pool_ci.maxSets = 1;
1664 ds_pool_ci.poolSizeCount = 1;
1665 ds_pool_ci.pPoolSizes = &ds_type_count;
1666
1667 VkDescriptorPool ds_pool;
1668 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1669 ASSERT_VK_SUCCESS(err);
1670
1671 VkDescriptorSetLayoutBinding dsl_binding = {};
1672 dsl_binding.binding = 0;
1673 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1674 dsl_binding.arraySize = 1;
1675 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1676 dsl_binding.pImmutableSamplers = NULL;
1677
1678 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1679 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1680 ds_layout_ci.pNext = NULL;
1681 ds_layout_ci.bindingCount = 1;
1682 ds_layout_ci.pBinding = &dsl_binding;
1683 VkDescriptorSetLayout ds_layout;
1684 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1685 ASSERT_VK_SUCCESS(err);
1686
1687 VkDescriptorSet descriptorSet;
1688 VkDescriptorSetAllocateInfo alloc_info = {};
1689 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1690 alloc_info.setLayoutCount = 1;
1691 alloc_info.descriptorPool = ds_pool;
1692 alloc_info.pSetLayouts = &ds_layout;
1693 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1694 ASSERT_VK_SUCCESS(err);
1695
1696 VkBufferView view = (VkBufferView) 0xbaadbeef; // invalid bufferView object
1697
1698 VkWriteDescriptorSet descriptor_write;
1699 memset(&descriptor_write, 0, sizeof(descriptor_write));
1700 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1701 descriptor_write.dstSet = descriptorSet;
1702 descriptor_write.dstBinding = 0;
1703 descriptor_write.descriptorCount = 1;
1704 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1705 descriptor_write.pTexelBufferView = &view;
1706
1707 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1708
1709 if (!m_errorMonitor->DesiredMsgFound()) {
1710 FAIL() << "Did not receive Error 'Invalid VkBufferView Object 0xbaadbeef'";
1711 m_errorMonitor->DumpFailureMsgs();
1712 }
1713
1714 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1715 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1716}
1717
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001718TEST_F(VkLayerTest, NoBeginCommandBuffer)
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001719{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001720
1721 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1722 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001723
1724 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001725 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001726 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001727 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001728
1729 if (!m_errorMonitor->DesiredMsgFound()) {
1730 FAIL() << "Did not recieve Error 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1731 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001732 }
1733}
1734
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001735TEST_F(VkLayerTest, PrimaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001736{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001737
1738 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1739 "may not specify framebuffer or renderpass parameters");
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001740
1741 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001742
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001743 // Calls AllocateCommandBuffers
1744 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001745
1746 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001747 VkCommandBufferBeginInfo cmd_buf_info = {};
1748 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06001749 cmd_buf_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001750 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northropb4569702015-08-04 17:35:57 -06001751 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1752 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1753
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001754
1755 // The error should be caught by validation of the BeginCommandBuffer call
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001756 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001757
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001758 if (!m_errorMonitor->DesiredMsgFound()) {
1759 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1760 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001761 }
1762}
1763
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001764TEST_F(VkLayerTest, SecondaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001765{
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001766 VkResult err;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001767 VkCommandBuffer draw_cmd;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001768
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001769 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1770 "must specify framebuffer and renderpass parameters");
1771
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001772 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001773
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001774 VkCommandBufferAllocateInfo cmd = {};
1775 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOC_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06001776 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001777 cmd.commandPool = m_commandPool;
1778 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001779 cmd.bufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06001780
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001781 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06001782 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001783
1784 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001785 VkCommandBufferBeginInfo cmd_buf_info = {};
1786 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06001787 cmd_buf_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001788 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001789
1790 // The error should be caught by validation of the BeginCommandBuffer call
1791 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1792
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001793 if (!m_errorMonitor->DesiredMsgFound()) {
1794 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1795 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001796 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001797 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001798}
1799
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001800TEST_F(VkLayerTest, InvalidPipelineCreateState)
1801{
1802 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001803 VkResult err;
1804
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001805 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1806 "Invalid Pipeline CreateInfo State: Vtx Shader required");
1807
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001808 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001809 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001810
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001811 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06001812 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001813 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001814
1815 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1816 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1817 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001818 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001819 ds_pool_ci.poolSizeCount = 1;
1820 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001821
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001822 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001823 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001824 ASSERT_VK_SUCCESS(err);
1825
Tony Barboureb254902015-07-15 12:50:33 -06001826 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001827 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001828 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1829 dsl_binding.arraySize = 1;
1830 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1831 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001832
Tony Barboureb254902015-07-15 12:50:33 -06001833 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1834 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1835 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001836 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001837 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06001838
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001839 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001840 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001841 ASSERT_VK_SUCCESS(err);
1842
1843 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001844 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001845 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001846 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001847 alloc_info.descriptorPool = ds_pool;
1848 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001849 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001850 ASSERT_VK_SUCCESS(err);
1851
Tony Barboureb254902015-07-15 12:50:33 -06001852 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1853 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001854 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001855 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001856
1857 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001858 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001859 ASSERT_VK_SUCCESS(err);
1860
Tobin Ehlise68360f2015-10-01 11:15:13 -06001861 VkViewport vp = {}; // Just need dummy vp to point to
1862 VkRect2D sc = {}; // dummy scissor to point to
1863
1864 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1865 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1866 vp_state_ci.scissorCount = 1;
1867 vp_state_ci.pScissors = &sc;
1868 vp_state_ci.viewportCount = 1;
1869 vp_state_ci.pViewports = &vp;
1870
Tony Barboureb254902015-07-15 12:50:33 -06001871 VkGraphicsPipelineCreateInfo gp_ci = {};
1872 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06001873 gp_ci.pViewportState = &vp_state_ci;
Tony Barboureb254902015-07-15 12:50:33 -06001874 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1875 gp_ci.layout = pipeline_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001876 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06001877
1878 VkPipelineCacheCreateInfo pc_ci = {};
1879 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001880 pc_ci.initialDataSize = 0;
1881 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001882
1883 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06001884 VkPipelineCache pipelineCache;
1885
Chia-I Wuf7458c52015-10-26 21:10:41 +08001886 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06001887 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08001888 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001889
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001890 if (!m_errorMonitor->DesiredMsgFound()) {
1891 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1892 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001893 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001894
Chia-I Wuf7458c52015-10-26 21:10:41 +08001895 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
1896 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1897 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1898 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001899}
Tobin Ehlis912df022015-09-17 08:46:18 -06001900/*// TODO : This test should be good, but needs Tess support in compiler to run
1901TEST_F(VkLayerTest, InvalidPatchControlPoints)
1902{
1903 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06001904 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001905
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001906 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1907 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ");
1908
Tobin Ehlis912df022015-09-17 08:46:18 -06001909 ASSERT_NO_FATAL_FAILURE(InitState());
1910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06001911
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001912 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06001913 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001914 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06001915
1916 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1917 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1918 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001919 ds_pool_ci.poolSizeCount = 1;
1920 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06001921
1922 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001923 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06001924 ASSERT_VK_SUCCESS(err);
1925
1926 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001927 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06001928 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1929 dsl_binding.arraySize = 1;
1930 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1931 dsl_binding.pImmutableSamplers = NULL;
1932
1933 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1934 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1935 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001936 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001937 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06001938
1939 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001940 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06001941 ASSERT_VK_SUCCESS(err);
1942
1943 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001944 err = vkAllocateDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06001945 ASSERT_VK_SUCCESS(err);
1946
1947 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1948 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1949 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001950 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06001951 pipeline_layout_ci.pSetLayouts = &ds_layout;
1952
1953 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001954 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06001955 ASSERT_VK_SUCCESS(err);
1956
1957 VkPipelineShaderStageCreateInfo shaderStages[3];
1958 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1959
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001960 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06001961 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001962 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
1963 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06001964
1965 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001966 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001967 shaderStages[0].shader = vs.handle();
1968 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001969 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001970 shaderStages[1].shader = tc.handle();
1971 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001972 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001973 shaderStages[2].shader = te.handle();
1974
1975 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1976 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001977 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06001978
1979 VkPipelineTessellationStateCreateInfo tsCI = {};
1980 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1981 tsCI.patchControlPoints = 0; // This will cause an error
1982
1983 VkGraphicsPipelineCreateInfo gp_ci = {};
1984 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1985 gp_ci.pNext = NULL;
1986 gp_ci.stageCount = 3;
1987 gp_ci.pStages = shaderStages;
1988 gp_ci.pVertexInputState = NULL;
1989 gp_ci.pInputAssemblyState = &iaCI;
1990 gp_ci.pTessellationState = &tsCI;
1991 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001992 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06001993 gp_ci.pMultisampleState = NULL;
1994 gp_ci.pDepthStencilState = NULL;
1995 gp_ci.pColorBlendState = NULL;
1996 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1997 gp_ci.layout = pipeline_layout;
1998 gp_ci.renderPass = renderPass();
1999
2000 VkPipelineCacheCreateInfo pc_ci = {};
2001 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2002 pc_ci.pNext = NULL;
2003 pc_ci.initialSize = 0;
2004 pc_ci.initialData = 0;
2005 pc_ci.maxSize = 0;
2006
2007 VkPipeline pipeline;
2008 VkPipelineCache pipelineCache;
2009
Chia-I Wuf7458c52015-10-26 21:10:41 +08002010 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06002011 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002012 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06002013
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002014 if (!m_errorMonitor->DesiredMsgFound()) {
2015 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...'";
2016 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis912df022015-09-17 08:46:18 -06002017 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002018
Chia-I Wuf7458c52015-10-26 21:10:41 +08002019 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2020 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2021 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2022 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06002023}
2024*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06002025// Set scissor and viewport counts to different numbers
2026TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2027{
2028 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlise68360f2015-10-01 11:15:13 -06002029 VkResult err;
2030
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002031 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2032 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2033
Tobin Ehlise68360f2015-10-01 11:15:13 -06002034 ASSERT_NO_FATAL_FAILURE(InitState());
2035 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002036
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002037 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002038 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002039 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002040
2041 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2042 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002043 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002044 ds_pool_ci.poolSizeCount = 1;
2045 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002046
2047 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002048 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002049 ASSERT_VK_SUCCESS(err);
2050
2051 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002052 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002053 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2054 dsl_binding.arraySize = 1;
2055 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2056
2057 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2058 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002059 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002060 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002061
2062 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002063 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002064 ASSERT_VK_SUCCESS(err);
2065
2066 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002067 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002068 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002069 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002070 alloc_info.descriptorPool = ds_pool;
2071 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002072 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002073 ASSERT_VK_SUCCESS(err);
2074
2075 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2076 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002077 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002078 pipeline_layout_ci.pSetLayouts = &ds_layout;
2079
2080 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002081 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002082 ASSERT_VK_SUCCESS(err);
2083
2084 VkViewport vp = {}; // Just need dummy vp to point to
2085
2086 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2087 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2088 vp_state_ci.scissorCount = 0;
2089 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2090 vp_state_ci.pViewports = &vp;
2091
Cody Northropeb3a6c12015-10-05 14:44:45 -06002092 VkPipelineShaderStageCreateInfo shaderStages[2];
2093 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002094
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002095 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2096 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northropeb3a6c12015-10-05 14:44:45 -06002097 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002098 shaderStages[0] = vs.GetStageCreateInfo();
2099 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002100
2101 VkGraphicsPipelineCreateInfo gp_ci = {};
2102 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002103 gp_ci.stageCount = 2;
2104 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002105 gp_ci.pViewportState = &vp_state_ci;
2106 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2107 gp_ci.layout = pipeline_layout;
2108 gp_ci.renderPass = renderPass();
2109
2110 VkPipelineCacheCreateInfo pc_ci = {};
2111 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2112
2113 VkPipeline pipeline;
2114 VkPipelineCache pipelineCache;
2115
Chia-I Wuf7458c52015-10-26 21:10:41 +08002116 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002117 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002118 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002119
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002120 if (!m_errorMonitor->DesiredMsgFound()) {
2121 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must match scissor count (0).'";
2122 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002123 }
2124
Chia-I Wuf7458c52015-10-26 21:10:41 +08002125 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2126 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2127 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2128 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002129}
Tobin Ehlisd332f282015-10-02 11:00:56 -06002130// Don't set viewport state in PSO. This is an error b/c we always need this state
2131// for the counts even if the data is going to be set dynamically.
2132TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002133{
2134 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlise68360f2015-10-01 11:15:13 -06002135 VkResult err;
2136
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002137 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2138 "Gfx Pipeline pViewportState is null. Even if ");
2139
Tobin Ehlise68360f2015-10-01 11:15:13 -06002140 ASSERT_NO_FATAL_FAILURE(InitState());
2141 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002142
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002143 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002144 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002145 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002146
2147 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2148 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002149 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002150 ds_pool_ci.poolSizeCount = 1;
2151 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002152
2153 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002154 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002155 ASSERT_VK_SUCCESS(err);
2156
2157 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002158 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002159 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2160 dsl_binding.arraySize = 1;
2161 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2162
2163 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2164 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002165 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002166 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002167
2168 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002169 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002170 ASSERT_VK_SUCCESS(err);
2171
2172 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002173 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002174 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002175 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002176 alloc_info.descriptorPool = ds_pool;
2177 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002178 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002179 ASSERT_VK_SUCCESS(err);
2180
2181 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2182 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002183 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002184 pipeline_layout_ci.pSetLayouts = &ds_layout;
2185
2186 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002187 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002188 ASSERT_VK_SUCCESS(err);
2189
2190 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2191 // Set scissor as dynamic to avoid second error
2192 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2193 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2194 dyn_state_ci.dynamicStateCount = 1;
2195 dyn_state_ci.pDynamicStates = &sc_state;
2196
Cody Northropeb3a6c12015-10-05 14:44:45 -06002197 VkPipelineShaderStageCreateInfo shaderStages[2];
2198 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002199
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002200 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2201 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northropeb3a6c12015-10-05 14:44:45 -06002202 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002203 shaderStages[0] = vs.GetStageCreateInfo();
2204 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002205
2206 VkGraphicsPipelineCreateInfo gp_ci = {};
2207 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002208 gp_ci.stageCount = 2;
2209 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002210 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2211 gp_ci.pDynamicState = &dyn_state_ci;
2212 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2213 gp_ci.layout = pipeline_layout;
2214 gp_ci.renderPass = renderPass();
2215
2216 VkPipelineCacheCreateInfo pc_ci = {};
2217 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2218
2219 VkPipeline pipeline;
2220 VkPipelineCache pipelineCache;
2221
Chia-I Wuf7458c52015-10-26 21:10:41 +08002222 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002223 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002224 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002225
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002226 if (!m_errorMonitor->DesiredMsgFound()) {
2227 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. Even if...'";
2228 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002229 }
2230
Chia-I Wuf7458c52015-10-26 21:10:41 +08002231 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2232 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2233 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2234 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002235}
2236// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002237// Then run second test where dynamic scissor count doesn't match PSO scissor count
2238TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002239{
Tobin Ehlise68360f2015-10-01 11:15:13 -06002240 VkResult err;
2241
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002242 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2243 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
2244
Tobin Ehlise68360f2015-10-01 11:15:13 -06002245 ASSERT_NO_FATAL_FAILURE(InitState());
2246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002247
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002248 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002249 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002250 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002251
2252 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2253 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002254 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002255 ds_pool_ci.poolSizeCount = 1;
2256 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002257
2258 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002259 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002260 ASSERT_VK_SUCCESS(err);
2261
2262 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002263 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002264 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2265 dsl_binding.arraySize = 1;
2266 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2267
2268 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2269 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002270 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002271 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002272
2273 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002274 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002275 ASSERT_VK_SUCCESS(err);
2276
2277 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002278 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002279 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002280 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002281 alloc_info.descriptorPool = ds_pool;
2282 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002283 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002284 ASSERT_VK_SUCCESS(err);
2285
2286 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2287 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002288 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002289 pipeline_layout_ci.pSetLayouts = &ds_layout;
2290
2291 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002292 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002293 ASSERT_VK_SUCCESS(err);
2294
2295 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2296 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2297 vp_state_ci.viewportCount = 1;
2298 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2299 vp_state_ci.scissorCount = 1;
2300 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2301
2302 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2303 // Set scissor as dynamic to avoid that error
2304 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2305 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2306 dyn_state_ci.dynamicStateCount = 1;
2307 dyn_state_ci.pDynamicStates = &sc_state;
2308
Cody Northropeb3a6c12015-10-05 14:44:45 -06002309 VkPipelineShaderStageCreateInfo shaderStages[2];
2310 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002311
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002312 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2313 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northropeb3a6c12015-10-05 14:44:45 -06002314 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002315 shaderStages[0] = vs.GetStageCreateInfo();
2316 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002317
Cody Northropf6622dc2015-10-06 10:33:21 -06002318 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2319 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2320 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002321 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002322 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002323 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002324 vi_ci.pVertexAttributeDescriptions = nullptr;
2325
2326 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2327 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2328 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2329
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002330 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002331 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06002332 rs_ci.pNext = nullptr;
2333
2334 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2335 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2336 cb_ci.pNext = nullptr;
2337
Tobin Ehlise68360f2015-10-01 11:15:13 -06002338 VkGraphicsPipelineCreateInfo gp_ci = {};
2339 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002340 gp_ci.stageCount = 2;
2341 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06002342 gp_ci.pVertexInputState = &vi_ci;
2343 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002344 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002345 gp_ci.pRasterizationState = &rs_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06002346 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002347 gp_ci.pDynamicState = &dyn_state_ci;
2348 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2349 gp_ci.layout = pipeline_layout;
2350 gp_ci.renderPass = renderPass();
2351
2352 VkPipelineCacheCreateInfo pc_ci = {};
2353 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2354
2355 VkPipeline pipeline;
2356 VkPipelineCache pipelineCache;
2357
Chia-I Wuf7458c52015-10-26 21:10:41 +08002358 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002359 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002360 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002361
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002362 if (!m_errorMonitor->DesiredMsgFound()) {
2363 FAIL() << "Did not recieve Error 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...'";
2364 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002365 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002366
2367
Tobin Ehlisd332f282015-10-02 11:00:56 -06002368 // Now hit second fail case where we set scissor w/ different count than PSO
2369 // First need to successfully create the PSO from above by setting pViewports
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002370 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2371 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.");
2372
Tobin Ehlisd332f282015-10-02 11:00:56 -06002373 VkViewport vp = {}; // Just need dummy vp to point to
2374 vp_state_ci.pViewports = &vp;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002375 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002376 ASSERT_VK_SUCCESS(err);
2377 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002378 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002379 VkRect2D scissors[2] = {}; // don't care about data
2380 // Count of 2 doesn't match PSO count of 1
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002381 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 2, scissors);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002382 Draw(1, 0, 0, 0);
2383
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002384 if (!m_errorMonitor->DesiredMsgFound()) {
2385 FAIL() << "Did not receive Error 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
2386 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd332f282015-10-02 11:00:56 -06002387 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06002388
Chia-I Wuf7458c52015-10-26 21:10:41 +08002389 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2390 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2391 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2392 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002393}
2394// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002395// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2396TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002397{
Tobin Ehlise68360f2015-10-01 11:15:13 -06002398 VkResult err;
2399
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002400 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2401 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
2402
Tobin Ehlise68360f2015-10-01 11:15:13 -06002403 ASSERT_NO_FATAL_FAILURE(InitState());
2404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002405
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002406 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002407 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002408 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002409
2410 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2411 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002412 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002413 ds_pool_ci.poolSizeCount = 1;
2414 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002415
2416 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002417 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002418 ASSERT_VK_SUCCESS(err);
2419
2420 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002421 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002422 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2423 dsl_binding.arraySize = 1;
2424 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2425
2426 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2427 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002428 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002429 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002430
2431 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002432 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002433 ASSERT_VK_SUCCESS(err);
2434
2435 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002436 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002437 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002438 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002439 alloc_info.descriptorPool = ds_pool;
2440 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002441 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002442 ASSERT_VK_SUCCESS(err);
2443
2444 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2445 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002446 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002447 pipeline_layout_ci.pSetLayouts = &ds_layout;
2448
2449 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002450 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002451 ASSERT_VK_SUCCESS(err);
2452
2453 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2454 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2455 vp_state_ci.scissorCount = 1;
2456 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2457 vp_state_ci.viewportCount = 1;
2458 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2459
2460 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2461 // Set scissor as dynamic to avoid that error
2462 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2463 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2464 dyn_state_ci.dynamicStateCount = 1;
2465 dyn_state_ci.pDynamicStates = &vp_state;
2466
Cody Northropeb3a6c12015-10-05 14:44:45 -06002467 VkPipelineShaderStageCreateInfo shaderStages[2];
2468 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002469
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002470 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2471 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northropeb3a6c12015-10-05 14:44:45 -06002472 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002473 shaderStages[0] = vs.GetStageCreateInfo();
2474 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002475
Cody Northropf6622dc2015-10-06 10:33:21 -06002476 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2477 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2478 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002479 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002480 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002481 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002482 vi_ci.pVertexAttributeDescriptions = nullptr;
2483
2484 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2485 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2486 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2487
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002488 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002489 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06002490 rs_ci.pNext = nullptr;
2491
2492 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2493 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2494 cb_ci.pNext = nullptr;
2495
Tobin Ehlise68360f2015-10-01 11:15:13 -06002496 VkGraphicsPipelineCreateInfo gp_ci = {};
2497 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002498 gp_ci.stageCount = 2;
2499 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06002500 gp_ci.pVertexInputState = &vi_ci;
2501 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002502 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002503 gp_ci.pRasterizationState = &rs_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06002504 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002505 gp_ci.pDynamicState = &dyn_state_ci;
2506 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2507 gp_ci.layout = pipeline_layout;
2508 gp_ci.renderPass = renderPass();
2509
2510 VkPipelineCacheCreateInfo pc_ci = {};
2511 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2512
2513 VkPipeline pipeline;
2514 VkPipelineCache pipelineCache;
2515
Chia-I Wuf7458c52015-10-26 21:10:41 +08002516 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002517 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002518 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002519
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002520 if (!m_errorMonitor->DesiredMsgFound()) {
2521 FAIL() << "Did not recieve Error 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...'";
2522 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002523 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002524
Tobin Ehlisd332f282015-10-02 11:00:56 -06002525 // Now hit second fail case where we set scissor w/ different count than PSO
2526 // First need to successfully create the PSO from above by setting pViewports
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002527 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2528 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.");
2529
Tobin Ehlisd332f282015-10-02 11:00:56 -06002530 VkRect2D sc = {}; // Just need dummy vp to point to
2531 vp_state_ci.pScissors = &sc;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002532 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002533 ASSERT_VK_SUCCESS(err);
2534 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002535 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002536 VkViewport viewports[2] = {}; // don't care about data
2537 // Count of 2 doesn't match PSO count of 1
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002538 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002539 Draw(1, 0, 0, 0);
2540
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002541 if (!m_errorMonitor->DesiredMsgFound()) {
2542 FAIL() << "Did not receive Error 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...'";
2543 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd332f282015-10-02 11:00:56 -06002544 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06002545
Chia-I Wuf7458c52015-10-26 21:10:41 +08002546 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2547 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2548 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2549 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002550}
2551
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002552TEST_F(VkLayerTest, NullRenderPass)
2553{
2554 // Bind a NULL RenderPass
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002555 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2556 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002557
2558 ASSERT_NO_FATAL_FAILURE(InitState());
2559 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002560
Tony Barbourfe3351b2015-07-28 10:17:20 -06002561 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002562 // Don't care about RenderPass handle b/c error should be flagged before that
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002563 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002564
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002565 if (!m_errorMonitor->DesiredMsgFound()) {
2566 FAIL() << "Did not receive Error 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2567 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002568 }
2569}
2570
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002571TEST_F(VkLayerTest, RenderPassWithinRenderPass)
2572{
2573 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002574 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2575 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002576
2577 ASSERT_NO_FATAL_FAILURE(InitState());
2578 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002579
Tony Barbourfe3351b2015-07-28 10:17:20 -06002580 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002581 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barboureb254902015-07-15 12:50:33 -06002582 VkRenderPassBeginInfo rp_begin = {};
2583 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
2584 rp_begin.pNext = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002585 rp_begin.renderPass = renderPass();
2586 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002587
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002588 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002589
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002590 if (!m_errorMonitor->DesiredMsgFound()) {
2591 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2592 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002593 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002594}
2595
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002596TEST_F(VkLayerTest, FillBufferWithinRenderPass)
2597{
2598 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002599 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2600 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002601
2602 ASSERT_NO_FATAL_FAILURE(InitState());
2603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002604
2605 // Renderpass is started here
2606 BeginCommandBuffer();
2607
2608 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002609 vk_testing::Buffer dstBuffer;
2610 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002611
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002612 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002613
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002614 if (!m_errorMonitor->DesiredMsgFound()) {
2615 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2616 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002617 }
2618}
2619
2620TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
2621{
2622 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002623 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2624 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002625
2626 ASSERT_NO_FATAL_FAILURE(InitState());
2627 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002628
2629 // Renderpass is started here
2630 BeginCommandBuffer();
2631
2632 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002633 vk_testing::Buffer dstBuffer;
2634 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002635
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002636 VkDeviceSize dstOffset = 0;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002637 VkDeviceSize dataSize = 1024;
2638 const uint32_t *pData = NULL;
2639
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002640 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002641
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002642 if (!m_errorMonitor->DesiredMsgFound()) {
2643 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2644 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002645 }
2646}
2647
2648TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
2649{
2650 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002651 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2652 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002653
2654 ASSERT_NO_FATAL_FAILURE(InitState());
2655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002656
2657 // Renderpass is started here
2658 BeginCommandBuffer();
2659
2660 VkClearColorValue clear_color = {0};
2661 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2662 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2663 const int32_t tex_width = 32;
2664 const int32_t tex_height = 32;
2665 VkImageCreateInfo image_create_info = {};
2666 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2667 image_create_info.pNext = NULL;
2668 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2669 image_create_info.format = tex_format;
2670 image_create_info.extent.width = tex_width;
2671 image_create_info.extent.height = tex_height;
2672 image_create_info.extent.depth = 1;
2673 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06002674 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08002675 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002676 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2677 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2678
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002679 vk_testing::Image dstImage;
2680 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002681
2682 const VkImageSubresourceRange range =
2683 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
2684
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002685 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(),
2686 dstImage.handle(),
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002687 VK_IMAGE_LAYOUT_GENERAL,
2688 &clear_color,
2689 1,
2690 &range);
2691
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002692 if (!m_errorMonitor->DesiredMsgFound()) {
2693 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2694 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002695 }
2696}
2697
2698TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
2699{
2700 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002701 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2702 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002703
2704 ASSERT_NO_FATAL_FAILURE(InitState());
2705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002706
2707 // Renderpass is started here
2708 BeginCommandBuffer();
2709
2710 VkClearDepthStencilValue clear_value = {0};
2711 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2712 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
2713 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2714 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
2715 image_create_info.extent.width = 64;
2716 image_create_info.extent.height = 64;
2717 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2718 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2719
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002720 vk_testing::Image dstImage;
2721 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002722
2723 const VkImageSubresourceRange range =
2724 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
2725
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002726 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(),
2727 dstImage.handle(),
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002728 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2729 &clear_value,
2730 1,
2731 &range);
2732
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002733 if (!m_errorMonitor->DesiredMsgFound()) {
2734 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2735 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002736 }
2737}
2738
2739TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
2740{
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002741 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002742 VkResult err;
2743
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002744 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2745 "vkCmdClearAttachments: This call must be issued inside an active render pass");
2746
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002747 ASSERT_NO_FATAL_FAILURE(InitState());
2748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002749
2750 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002751 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002752 ASSERT_VK_SUCCESS(err);
2753
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002754 VkClearAttachment color_attachment;
2755 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2756 color_attachment.clearValue.color.float32[0] = 0;
2757 color_attachment.clearValue.color.float32[1] = 0;
2758 color_attachment.clearValue.color.float32[2] = 0;
2759 color_attachment.clearValue.color.float32[3] = 0;
2760 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06002761 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002762 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(),
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002763 1, &color_attachment,
2764 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002765
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002766 if (!m_errorMonitor->DesiredMsgFound()) {
2767 FAIL() << "Did not receive Error 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
2768 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002769 }
2770}
2771
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002772TEST_F(VkLayerTest, InvalidDynamicStateObject)
2773{
2774 // Create a valid cmd buffer
2775 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002776 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
2777 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002778}
Tobin Ehlis1056d452015-05-27 14:55:35 -06002779
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002780TEST_F(VkLayerTest, IdxBufferAlignmentError)
2781{
2782 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002783 VkResult err;
2784
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002785 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2786 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
2787
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002788 ASSERT_NO_FATAL_FAILURE(InitState());
2789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002790 uint32_t qfi = 0;
2791 VkBufferCreateInfo buffCI = {};
2792 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2793 buffCI.size = 1024;
2794 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002795 buffCI.queueFamilyIndexCount = 1;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002796 buffCI.pQueueFamilyIndices = &qfi;
2797
2798 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002799 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002800 ASSERT_VK_SUCCESS(err);
2801
2802 BeginCommandBuffer();
2803 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002804 //vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002805 // Should error before calling to driver so don't care about actual data
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002806 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002807
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002808 if (!m_errorMonitor->DesiredMsgFound()) {
2809 FAIL() << "Did not receive Error 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...'";
2810 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002811 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002812
Chia-I Wuf7458c52015-10-26 21:10:41 +08002813 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002814}
2815
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06002816TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2817{
2818 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002819
2820 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2821 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06002822
2823 ASSERT_NO_FATAL_FAILURE(InitState());
2824 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06002825
2826 BeginCommandBuffer();
2827 //ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002828 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
2829 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06002830
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002831 if (!m_errorMonitor->DesiredMsgFound()) {
2832 FAIL() << "Did not receive Error 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer '";
2833 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06002834 }
2835}
2836
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002837TEST_F(VkLayerTest, DSTypeMismatch)
2838{
2839 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Tobin Ehlis3b780662015-05-28 12:11:26 -06002840 VkResult err;
2841
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002842 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2843 "Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ");
2844
Tobin Ehlis3b780662015-05-28 12:11:26 -06002845 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06002846 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002847 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06002848 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002849 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002850
2851 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2852 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2853 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002854 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002855 ds_pool_ci.poolSizeCount = 1;
2856 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06002857
Tobin Ehlis3b780662015-05-28 12:11:26 -06002858 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002859 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002860 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06002861 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002862 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002863 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2864 dsl_binding.arraySize = 1;
2865 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2866 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002867
Tony Barboureb254902015-07-15 12:50:33 -06002868 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2869 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2870 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002871 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002872 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06002873
Tobin Ehlis3b780662015-05-28 12:11:26 -06002874 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002875 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002876 ASSERT_VK_SUCCESS(err);
2877
2878 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002879 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002880 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002881 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002882 alloc_info.descriptorPool = ds_pool;
2883 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002884 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002885 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002886
Tony Barboureb254902015-07-15 12:50:33 -06002887 VkSamplerCreateInfo sampler_ci = {};
2888 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2889 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08002890 sampler_ci.magFilter = VK_FILTER_NEAREST;
2891 sampler_ci.minFilter = VK_FILTER_NEAREST;
2892 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08002893 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2894 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2895 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06002896 sampler_ci.mipLodBias = 1.0;
2897 sampler_ci.maxAnisotropy = 1;
2898 sampler_ci.compareEnable = VK_FALSE;
2899 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2900 sampler_ci.minLod = 1.0;
2901 sampler_ci.maxLod = 1.0;
2902 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06002903 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2904
Tobin Ehlis3b780662015-05-28 12:11:26 -06002905 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002906 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002907 ASSERT_VK_SUCCESS(err);
2908
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002909 VkDescriptorImageInfo info = {};
2910 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002911
2912 VkWriteDescriptorSet descriptor_write;
2913 memset(&descriptor_write, 0, sizeof(descriptor_write));
2914 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002915 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002916 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002917 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002918 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002919 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002920
2921 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2922
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002923 if (!m_errorMonitor->DesiredMsgFound()) {
2924 FAIL() << "Did not receive Error 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...'";
2925 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06002926 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002927
Chia-I Wuf7458c52015-10-26 21:10:41 +08002928 vkDestroySampler(m_device->device(), sampler, NULL);
2929 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2930 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002931}
2932
2933TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2934{
2935 // For overlapping Update, have arrayIndex exceed that of layout
Tobin Ehlis3b780662015-05-28 12:11:26 -06002936 VkResult err;
2937
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002938 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2939 "Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding");
2940
Tobin Ehlis3b780662015-05-28 12:11:26 -06002941 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06002942 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002943 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06002944 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002945 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002946
2947 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2948 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2949 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002950 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002951 ds_pool_ci.poolSizeCount = 1;
2952 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06002953
Tobin Ehlis3b780662015-05-28 12:11:26 -06002954 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002955 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002956 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002957
Tony Barboureb254902015-07-15 12:50:33 -06002958 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002959 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002960 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2961 dsl_binding.arraySize = 1;
2962 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2963 dsl_binding.pImmutableSamplers = NULL;
2964
2965 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2966 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2967 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002968 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002969 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06002970
Tobin Ehlis3b780662015-05-28 12:11:26 -06002971 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002972 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002973 ASSERT_VK_SUCCESS(err);
2974
2975 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002976 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002977 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002978 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002979 alloc_info.descriptorPool = ds_pool;
2980 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002981 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002982 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002983
Tony Barboureb254902015-07-15 12:50:33 -06002984 VkSamplerCreateInfo sampler_ci = {};
2985 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2986 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08002987 sampler_ci.magFilter = VK_FILTER_NEAREST;
2988 sampler_ci.minFilter = VK_FILTER_NEAREST;
2989 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08002990 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2991 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2992 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06002993 sampler_ci.mipLodBias = 1.0;
2994 sampler_ci.maxAnisotropy = 1;
2995 sampler_ci.compareEnable = VK_FALSE;
2996 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2997 sampler_ci.minLod = 1.0;
2998 sampler_ci.maxLod = 1.0;
2999 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003000 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003001
Tobin Ehlis3b780662015-05-28 12:11:26 -06003002 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003003 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003004 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003005
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003006 VkDescriptorImageInfo info = {};
3007 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003008
3009 VkWriteDescriptorSet descriptor_write;
3010 memset(&descriptor_write, 0, sizeof(descriptor_write));
3011 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003012 descriptor_write.dstSet = descriptorSet;
3013 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08003014 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003015 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003016 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003017 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003018
3019 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3020
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003021 if (!m_errorMonitor->DesiredMsgFound()) {
3022 FAIL() << "Did not receive Error 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
3023 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003024 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003025
Chia-I Wuf7458c52015-10-26 21:10:41 +08003026 vkDestroySampler(m_device->device(), sampler, NULL);
3027 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3028 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003029}
3030
3031TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3032{
Tobin Ehlis3b780662015-05-28 12:11:26 -06003033 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Tobin Ehlis3b780662015-05-28 12:11:26 -06003034 VkResult err;
3035
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003036 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3037 " does not have binding to match update binding ");
3038
Tobin Ehlis3b780662015-05-28 12:11:26 -06003039 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003040 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003041 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003042 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003043 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003044
3045 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3046 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3047 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003048 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003049 ds_pool_ci.poolSizeCount = 1;
3050 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003051
Tobin Ehlis3b780662015-05-28 12:11:26 -06003052 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003053 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003054 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003055
Tony Barboureb254902015-07-15 12:50:33 -06003056 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003057 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003058 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3059 dsl_binding.arraySize = 1;
3060 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3061 dsl_binding.pImmutableSamplers = NULL;
3062
3063 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3064 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3065 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003066 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003067 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003068 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003069 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003070 ASSERT_VK_SUCCESS(err);
3071
3072 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003073 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003074 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003075 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003076 alloc_info.descriptorPool = ds_pool;
3077 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003078 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003079 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003080
Tony Barboureb254902015-07-15 12:50:33 -06003081 VkSamplerCreateInfo sampler_ci = {};
3082 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3083 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003084 sampler_ci.magFilter = VK_FILTER_NEAREST;
3085 sampler_ci.minFilter = VK_FILTER_NEAREST;
3086 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003087 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3088 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3089 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003090 sampler_ci.mipLodBias = 1.0;
3091 sampler_ci.maxAnisotropy = 1;
3092 sampler_ci.compareEnable = VK_FALSE;
3093 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3094 sampler_ci.minLod = 1.0;
3095 sampler_ci.maxLod = 1.0;
3096 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003097 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003098
Tobin Ehlis3b780662015-05-28 12:11:26 -06003099 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003100 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003101 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003102
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003103 VkDescriptorImageInfo info = {};
3104 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003105
3106 VkWriteDescriptorSet descriptor_write;
3107 memset(&descriptor_write, 0, sizeof(descriptor_write));
3108 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003109 descriptor_write.dstSet = descriptorSet;
3110 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003111 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003112 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003113 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003114 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003115
3116 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3117
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003118 if (!m_errorMonitor->DesiredMsgFound()) {
3119 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have binding to match update binding '";
3120 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003121 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003122
Chia-I Wuf7458c52015-10-26 21:10:41 +08003123 vkDestroySampler(m_device->device(), sampler, NULL);
3124 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3125 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003126}
3127
3128TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3129{
3130 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Tobin Ehlis3b780662015-05-28 12:11:26 -06003131 VkResult err;
3132
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003133 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3134 "Unexpected UPDATE struct of type ");
3135
Tobin Ehlis3b780662015-05-28 12:11:26 -06003136 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003137
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003138 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003139 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003140 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003141
3142 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3143 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3144 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003145 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003146 ds_pool_ci.poolSizeCount = 1;
3147 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003148
Tobin Ehlis3b780662015-05-28 12:11:26 -06003149 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003150 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003151 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06003152 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003153 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003154 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3155 dsl_binding.arraySize = 1;
3156 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3157 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003158
Tony Barboureb254902015-07-15 12:50:33 -06003159 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3160 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3161 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003162 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003163 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003164
Tobin Ehlis3b780662015-05-28 12:11:26 -06003165 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003166 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003167 ASSERT_VK_SUCCESS(err);
3168
3169 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003170 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003171 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003172 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003173 alloc_info.descriptorPool = ds_pool;
3174 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003175 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003176 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003177
Tony Barboureb254902015-07-15 12:50:33 -06003178 VkSamplerCreateInfo sampler_ci = {};
3179 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3180 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003181 sampler_ci.magFilter = VK_FILTER_NEAREST;
3182 sampler_ci.minFilter = VK_FILTER_NEAREST;
3183 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003184 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3185 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3186 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003187 sampler_ci.mipLodBias = 1.0;
3188 sampler_ci.maxAnisotropy = 1;
3189 sampler_ci.compareEnable = VK_FALSE;
3190 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3191 sampler_ci.minLod = 1.0;
3192 sampler_ci.maxLod = 1.0;
3193 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003194 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003195 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003196 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003197 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003198
3199
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003200 VkDescriptorImageInfo info = {};
3201 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003202
3203 VkWriteDescriptorSet descriptor_write;
3204 memset(&descriptor_write, 0, sizeof(descriptor_write));
3205 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003206 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003207 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003208 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003209 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003210 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003211
3212 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3213
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003214 if (!m_errorMonitor->DesiredMsgFound()) {
3215 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
3216 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003217 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003218
Chia-I Wuf7458c52015-10-26 21:10:41 +08003219 vkDestroySampler(m_device->device(), sampler, NULL);
3220 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3221 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003222}
3223
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003224TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3225{
3226 // Create a single Sampler descriptor and send it an invalid Sampler
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003227 VkResult err;
3228
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003229 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3230 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
3231
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003232 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003233 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003234 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003235 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003236 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003237
3238 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3239 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3240 ds_pool_ci.pNext = NULL;
3241 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003242 ds_pool_ci.poolSizeCount = 1;
3243 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003244
3245 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003246 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003247 ASSERT_VK_SUCCESS(err);
3248
3249 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003250 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003251 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3252 dsl_binding.arraySize = 1;
3253 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3254 dsl_binding.pImmutableSamplers = NULL;
3255
3256 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3257 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3258 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003259 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003260 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003261 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003262 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003263 ASSERT_VK_SUCCESS(err);
3264
3265 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003266 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003267 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003268 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003269 alloc_info.descriptorPool = ds_pool;
3270 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003271 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003272 ASSERT_VK_SUCCESS(err);
3273
Chia-I Wue2fc5522015-10-26 20:04:44 +08003274 VkSampler sampler = (VkSampler) 0xbaadbeef; // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003275
3276 VkDescriptorImageInfo descriptor_info;
3277 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3278 descriptor_info.sampler = sampler;
3279
3280 VkWriteDescriptorSet descriptor_write;
3281 memset(&descriptor_write, 0, sizeof(descriptor_write));
3282 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003283 descriptor_write.dstSet = descriptorSet;
3284 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003285 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003286 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3287 descriptor_write.pImageInfo = &descriptor_info;
3288
3289 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3290
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003291 if (!m_errorMonitor->DesiredMsgFound()) {
3292 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid sampler...'";
3293 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003294 }
3295
Chia-I Wuf7458c52015-10-26 21:10:41 +08003296 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3297 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003298}
3299
3300TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3301{
3302 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003303 VkResult err;
3304
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003305 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3306 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
3307
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003308 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003309 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003310 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003311 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003312
3313 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3314 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3315 ds_pool_ci.pNext = NULL;
3316 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003317 ds_pool_ci.poolSizeCount = 1;
3318 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003319
3320 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003321 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003322 ASSERT_VK_SUCCESS(err);
3323
3324 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003325 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003326 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3327 dsl_binding.arraySize = 1;
3328 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3329 dsl_binding.pImmutableSamplers = NULL;
3330
3331 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3332 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3333 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003334 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003335 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003336 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003337 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003338 ASSERT_VK_SUCCESS(err);
3339
3340 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003341 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003342 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003343 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003344 alloc_info.descriptorPool = ds_pool;
3345 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003346 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003347 ASSERT_VK_SUCCESS(err);
3348
3349 VkSamplerCreateInfo sampler_ci = {};
3350 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3351 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003352 sampler_ci.magFilter = VK_FILTER_NEAREST;
3353 sampler_ci.minFilter = VK_FILTER_NEAREST;
3354 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003355 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3356 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3357 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003358 sampler_ci.mipLodBias = 1.0;
3359 sampler_ci.maxAnisotropy = 1;
3360 sampler_ci.compareEnable = VK_FALSE;
3361 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3362 sampler_ci.minLod = 1.0;
3363 sampler_ci.maxLod = 1.0;
3364 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3365 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3366
3367 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003368 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003369 ASSERT_VK_SUCCESS(err);
3370
Chia-I Wue2fc5522015-10-26 20:04:44 +08003371 VkImageView view = (VkImageView) 0xbaadbeef; // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003372
3373 VkDescriptorImageInfo descriptor_info;
3374 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3375 descriptor_info.sampler = sampler;
3376 descriptor_info.imageView = view;
3377
3378 VkWriteDescriptorSet descriptor_write;
3379 memset(&descriptor_write, 0, sizeof(descriptor_write));
3380 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003381 descriptor_write.dstSet = descriptorSet;
3382 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003383 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003384 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3385 descriptor_write.pImageInfo = &descriptor_info;
3386
3387 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3388
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003389 if (!m_errorMonitor->DesiredMsgFound()) {
3390 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid imageView...'";
3391 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003392 }
3393
Chia-I Wuf7458c52015-10-26 21:10:41 +08003394 vkDestroySampler(m_device->device(), sampler, NULL);
3395 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3396 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003397}
3398
Tobin Ehlis04356f92015-10-27 16:35:27 -06003399TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
3400{
3401 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update into the other
Tobin Ehlis04356f92015-10-27 16:35:27 -06003402 VkResult err;
3403
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003404 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3405 "Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ");
3406
Tobin Ehlis04356f92015-10-27 16:35:27 -06003407 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis04356f92015-10-27 16:35:27 -06003408 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003409 VkDescriptorPoolSize ds_type_count[2] = {};
Tobin Ehlis04356f92015-10-27 16:35:27 -06003410 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003411 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003412 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003413 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003414
3415 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3416 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3417 ds_pool_ci.pNext = NULL;
3418 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003419 ds_pool_ci.poolSizeCount = 2;
3420 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003421
3422 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003423 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003424 ASSERT_VK_SUCCESS(err);
3425 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003426 dsl_binding[0].binding = 0;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003427 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3428 dsl_binding[0].arraySize = 1;
3429 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3430 dsl_binding[0].pImmutableSamplers = NULL;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003431 dsl_binding[1].binding = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003432 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3433 dsl_binding[1].arraySize = 1;
3434 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
3435 dsl_binding[1].pImmutableSamplers = NULL;
3436
3437 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3438 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3439 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003440 ds_layout_ci.bindingCount = 2;
Chia-I Wua745e512015-10-31 00:31:16 +08003441 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003442
3443 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003444 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003445 ASSERT_VK_SUCCESS(err);
3446
3447 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003448 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis04356f92015-10-27 16:35:27 -06003449 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003450 alloc_info.setLayoutCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003451 alloc_info.descriptorPool = ds_pool;
3452 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003453 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003454 ASSERT_VK_SUCCESS(err);
3455
3456 VkSamplerCreateInfo sampler_ci = {};
3457 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3458 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003459 sampler_ci.magFilter = VK_FILTER_NEAREST;
3460 sampler_ci.minFilter = VK_FILTER_NEAREST;
3461 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003462 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3463 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3464 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003465 sampler_ci.mipLodBias = 1.0;
3466 sampler_ci.maxAnisotropy = 1;
3467 sampler_ci.compareEnable = VK_FALSE;
3468 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3469 sampler_ci.minLod = 1.0;
3470 sampler_ci.maxLod = 1.0;
3471 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3472 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3473
3474 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003475 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003476 ASSERT_VK_SUCCESS(err);
3477
3478 VkDescriptorImageInfo info = {};
3479 info.sampler = sampler;
3480
3481 VkWriteDescriptorSet descriptor_write;
3482 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
3483 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003484 descriptor_write.dstSet = descriptorSet;
3485 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08003486 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003487 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3488 descriptor_write.pImageInfo = &info;
3489 // This write update should succeed
3490 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3491 // Now perform a copy update that fails due to type mismatch
3492 VkCopyDescriptorSet copy_ds_update;
3493 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3494 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3495 copy_ds_update.srcSet = descriptorSet;
3496 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003497 copy_ds_update.dstSet = descriptorSet;
3498 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08003499 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06003500 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3501
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003502 if (!m_errorMonitor->DesiredMsgFound()) {
3503 FAIL() << "Did not receive Error 'Copy descriptor update index 0, update count #1, has src update descriptor type_DESCRIPTOR_TYPE_SAMPLER'";
3504 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06003505 }
3506 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003507 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3508 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis04356f92015-10-27 16:35:27 -06003509 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3510 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3511 copy_ds_update.srcSet = descriptorSet;
3512 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003513 copy_ds_update.dstSet = descriptorSet;
3514 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003515 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06003516 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3517
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003518 if (!m_errorMonitor->DesiredMsgFound()) {
3519 FAIL() << "Did not receive Error 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...'";
3520 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06003521 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003522
Tobin Ehlis04356f92015-10-27 16:35:27 -06003523 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003524 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3525 "Copy descriptor src update is out of bounds for matching binding 1 ");
3526
Tobin Ehlis04356f92015-10-27 16:35:27 -06003527 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3528 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3529 copy_ds_update.srcSet = descriptorSet;
3530 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003531 copy_ds_update.dstSet = descriptorSet;
3532 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003533 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06003534 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3535
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003536 if (!m_errorMonitor->DesiredMsgFound()) {
3537 FAIL() << "Did not receive Error 'Copy descriptor src update is out of bounds for matching binding 1...'";
3538 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06003539 }
3540
Chia-I Wuf7458c52015-10-26 21:10:41 +08003541 vkDestroySampler(m_device->device(), sampler, NULL);
3542 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3543 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003544}
3545
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003546TEST_F(VkLayerTest, NumSamplesMismatch)
3547{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003548 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis3b780662015-05-28 12:11:26 -06003549 VkResult err;
3550
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003551 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3552 "Num samples mismatch! ");
3553
Tobin Ehlis3b780662015-05-28 12:11:26 -06003554 ASSERT_NO_FATAL_FAILURE(InitState());
3555 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003556 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003557 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003558 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003559
3560 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003561 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3562 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003563 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003564 ds_pool_ci.poolSizeCount = 1;
3565 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003566
Tobin Ehlis3b780662015-05-28 12:11:26 -06003567 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003568 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003569 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003570
Tony Barboureb254902015-07-15 12:50:33 -06003571 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003572 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003573 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3574 dsl_binding.arraySize = 1;
3575 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3576 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003577
Tony Barboureb254902015-07-15 12:50:33 -06003578 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3579 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3580 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003581 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003582 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003583
Tobin Ehlis3b780662015-05-28 12:11:26 -06003584 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003585 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003586 ASSERT_VK_SUCCESS(err);
3587
3588 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003589 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003590 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003591 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003592 alloc_info.descriptorPool = ds_pool;
3593 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003594 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003595 ASSERT_VK_SUCCESS(err);
3596
Tony Barboureb254902015-07-15 12:50:33 -06003597 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3598 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3599 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08003600 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06003601 pipe_ms_state_ci.sampleShadingEnable = 0;
3602 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003603 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003604
Tony Barboureb254902015-07-15 12:50:33 -06003605 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3606 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3607 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003608 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003609 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003610
3611 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003612 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003613 ASSERT_VK_SUCCESS(err);
3614
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003615 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3616 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour1c94d372015-08-06 11:21:08 -06003617 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003618 VkPipelineObj pipe(m_device);
3619 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003620 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003621 pipe.SetMSAA(&pipe_ms_state_ci);
3622 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003623
Tony Barbourfe3351b2015-07-28 10:17:20 -06003624 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003625 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003626
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003627 if (!m_errorMonitor->DesiredMsgFound()) {
3628 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
3629 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003630 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003631
Chia-I Wuf7458c52015-10-26 21:10:41 +08003632 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3633 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3634 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003635}
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003636
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003637TEST_F(VkLayerTest, ClearCmdNoDraw)
3638{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003639 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003640 VkResult err;
3641
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003642 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
3643 "vkCmdClearAttachments() issued on CB object ");
3644
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003645 ASSERT_NO_FATAL_FAILURE(InitState());
3646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06003647
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003648 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003649 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003650 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003651
3652 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3653 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3654 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003655 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003656 ds_pool_ci.poolSizeCount = 1;
3657 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06003658
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003659 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003660 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003661 ASSERT_VK_SUCCESS(err);
3662
Tony Barboureb254902015-07-15 12:50:33 -06003663 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003664 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003665 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3666 dsl_binding.arraySize = 1;
3667 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3668 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003669
Tony Barboureb254902015-07-15 12:50:33 -06003670 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3671 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3672 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003673 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003674 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003675
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003676 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003677 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003678 ASSERT_VK_SUCCESS(err);
3679
3680 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003681 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003682 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003683 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003684 alloc_info.descriptorPool = ds_pool;
3685 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003686 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003687 ASSERT_VK_SUCCESS(err);
3688
Tony Barboureb254902015-07-15 12:50:33 -06003689 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3690 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3691 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08003692 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06003693 pipe_ms_state_ci.sampleShadingEnable = 0;
3694 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003695 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003696
Tony Barboureb254902015-07-15 12:50:33 -06003697 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3698 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3699 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003700 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003701 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003702
3703 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003704 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003705 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003706
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003707 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003708 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
3709 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3710
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003711 VkPipelineObj pipe(m_device);
3712 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003713 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003714 pipe.SetMSAA(&pipe_ms_state_ci);
3715 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003716
3717 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003718
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003719 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3720 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003721 VkClearAttachment color_attachment;
3722 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3723 color_attachment.clearValue.color.float32[0] = 1.0;
3724 color_attachment.clearValue.color.float32[1] = 1.0;
3725 color_attachment.clearValue.color.float32[2] = 1.0;
3726 color_attachment.clearValue.color.float32[3] = 1.0;
3727 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06003728 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003729
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003730 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003731
3732 if (!m_errorMonitor->DesiredMsgFound()) {
3733 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued on CB object...'";
3734 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003735 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003736
Chia-I Wuf7458c52015-10-26 21:10:41 +08003737 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3738 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3739 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003740}
3741
Tobin Ehlis502480b2015-06-24 15:53:07 -06003742TEST_F(VkLayerTest, VtxBufferBadIndex)
3743{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003744 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis502480b2015-06-24 15:53:07 -06003745 VkResult err;
3746
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003747 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3748 "Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.");
3749
Tobin Ehlis502480b2015-06-24 15:53:07 -06003750 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06003751 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06003752 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06003753
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003754 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003755 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003756 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003757
3758 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3759 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3760 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003761 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003762 ds_pool_ci.poolSizeCount = 1;
3763 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06003764
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003765 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003766 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003767 ASSERT_VK_SUCCESS(err);
3768
Tony Barboureb254902015-07-15 12:50:33 -06003769 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003770 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003771 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3772 dsl_binding.arraySize = 1;
3773 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3774 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003775
Tony Barboureb254902015-07-15 12:50:33 -06003776 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3777 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3778 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003779 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003780 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003781
Tobin Ehlis502480b2015-06-24 15:53:07 -06003782 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003783 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003784 ASSERT_VK_SUCCESS(err);
3785
3786 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003787 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003788 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003789 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003790 alloc_info.descriptorPool = ds_pool;
3791 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003792 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003793 ASSERT_VK_SUCCESS(err);
3794
Tony Barboureb254902015-07-15 12:50:33 -06003795 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3796 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3797 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08003798 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06003799 pipe_ms_state_ci.sampleShadingEnable = 0;
3800 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003801 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003802
Tony Barboureb254902015-07-15 12:50:33 -06003803 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3804 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3805 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003806 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003807 pipeline_layout_ci.pSetLayouts = &ds_layout;
3808 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003809
Chia-I Wuf7458c52015-10-26 21:10:41 +08003810 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003811 ASSERT_VK_SUCCESS(err);
3812
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003813 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3814 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour1c94d372015-08-06 11:21:08 -06003815 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003816 VkPipelineObj pipe(m_device);
3817 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003818 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003819 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003820 pipe.SetViewport(m_viewports);
3821 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003822 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003823
3824 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003825 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06003826 // Don't care about actual data, just need to get to draw to flag error
3827 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3828 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3829 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003830 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003831
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003832 if (!m_errorMonitor->DesiredMsgFound()) {
3833 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
3834 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis502480b2015-06-24 15:53:07 -06003835 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003836
Chia-I Wuf7458c52015-10-26 21:10:41 +08003837 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3838 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3839 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003840}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003841#endif // DRAW_STATE_TESTS
3842
Tobin Ehlis0788f522015-05-26 16:11:58 -06003843#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06003844#if GTEST_IS_THREADSAFE
3845struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003846 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003847 VkEvent event;
3848 bool bailout;
3849};
3850
3851extern "C" void *AddToCommandBuffer(void *arg)
3852{
3853 struct thread_data_struct *data = (struct thread_data_struct *) arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003854
3855 for (int i = 0; i<10000; i++) {
Chia-I Wu89d0f942015-10-31 00:31:16 +08003856 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003857 if (data->bailout) {
3858 break;
3859 }
3860 }
3861 return NULL;
3862}
3863
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003864TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyanaccf7692015-05-12 16:00:45 -06003865{
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003866 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003867
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003868 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "THREADING ERROR");
3869
Mike Stroyanaccf7692015-05-12 16:00:45 -06003870 ASSERT_NO_FATAL_FAILURE(InitState());
3871 ASSERT_NO_FATAL_FAILURE(InitViewport());
3872 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3873
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003874 // Calls AllocateCommandBuffers
3875 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003876
3877 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003878 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003879
3880 VkEventCreateInfo event_info;
3881 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003882 VkResult err;
3883
3884 memset(&event_info, 0, sizeof(event_info));
3885 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3886
Chia-I Wuf7458c52015-10-26 21:10:41 +08003887 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003888 ASSERT_VK_SUCCESS(err);
3889
Mike Stroyanaccf7692015-05-12 16:00:45 -06003890 err = vkResetEvent(device(), event);
3891 ASSERT_VK_SUCCESS(err);
3892
3893 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003894 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003895 data.event = event;
3896 data.bailout = false;
3897 m_errorMonitor->SetBailout(&data.bailout);
3898 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003899 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003900 // Add many entries to command buffer from this thread at the same time.
3901 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003902
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003903 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003904 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003905
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003906 if (!m_errorMonitor->DesiredMsgFound()) {
3907 FAIL() << "Did not receive Error 'THREADING ERROR' from using one VkCommandBufferObj in two threads";
3908 m_errorMonitor->DumpFailureMsgs();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003909 }
3910
Chia-I Wuf7458c52015-10-26 21:10:41 +08003911 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003912}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003913#endif // GTEST_IS_THREADSAFE
3914#endif // THREADING_TESTS
3915
Chris Forbes9f7ff632015-05-25 11:13:08 +12003916#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003917TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
3918{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003919 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3920 "Shader is not SPIR-V");
3921
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003922 ASSERT_NO_FATAL_FAILURE(InitState());
3923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3924
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003925 VkShaderModule module;
3926 VkShaderModuleCreateInfo moduleCreateInfo;
3927 struct icd_spv_header spv;
3928
3929 spv.magic = ICD_SPV_MAGIC;
3930 spv.version = ICD_SPV_VERSION;
3931 spv.gen_magic = 0;
3932
3933 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3934 moduleCreateInfo.pNext = NULL;
Chia-I Wu8094f192015-10-26 19:22:06 +08003935 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003936 moduleCreateInfo.codeSize = 4;
3937 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003938 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003939
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003940 if (!m_errorMonitor->DesiredMsgFound()) {
3941 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
3942 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003943 }
3944}
3945
3946TEST_F(VkLayerTest, InvalidSPIRVMagic)
3947{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003948 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3949 "Shader is not SPIR-V");
3950
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003951 ASSERT_NO_FATAL_FAILURE(InitState());
3952 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3953
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003954 VkShaderModule module;
3955 VkShaderModuleCreateInfo moduleCreateInfo;
3956 struct icd_spv_header spv;
3957
3958 spv.magic = ~ICD_SPV_MAGIC;
3959 spv.version = ICD_SPV_VERSION;
3960 spv.gen_magic = 0;
3961
3962 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3963 moduleCreateInfo.pNext = NULL;
Chia-I Wu8094f192015-10-26 19:22:06 +08003964 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003965 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3966 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003967 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003968
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003969 if (!m_errorMonitor->DesiredMsgFound()) {
3970 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
3971 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003972 }
3973}
3974
3975TEST_F(VkLayerTest, InvalidSPIRVVersion)
3976{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003977 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3978 "Shader is not SPIR-V");
3979
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003980 ASSERT_NO_FATAL_FAILURE(InitState());
3981 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3982
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003983 VkShaderModule module;
3984 VkShaderModuleCreateInfo moduleCreateInfo;
3985 struct icd_spv_header spv;
3986
3987 spv.magic = ICD_SPV_MAGIC;
3988 spv.version = ~ICD_SPV_VERSION;
3989 spv.gen_magic = 0;
3990
3991 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3992 moduleCreateInfo.pNext = NULL;
3993
Chia-I Wu8094f192015-10-26 19:22:06 +08003994 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003995 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3996 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003997 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003998
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003999 if (!m_errorMonitor->DesiredMsgFound()) {
4000 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4001 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004002 }
4003}
4004
Chris Forbes9f7ff632015-05-25 11:13:08 +12004005TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
4006{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004007 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
4008 "not consumed by fragment shader");
4009
Chris Forbes9f7ff632015-05-25 11:13:08 +12004010 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12004012
4013 char const *vsSource =
4014 "#version 140\n"
4015 "#extension GL_ARB_separate_shader_objects: require\n"
4016 "#extension GL_ARB_shading_language_420pack: require\n"
4017 "\n"
4018 "layout(location=0) out float x;\n"
4019 "void main(){\n"
4020 " gl_Position = vec4(1);\n"
4021 " x = 0;\n"
4022 "}\n";
4023 char const *fsSource =
4024 "#version 140\n"
4025 "#extension GL_ARB_separate_shader_objects: require\n"
4026 "#extension GL_ARB_shading_language_420pack: require\n"
4027 "\n"
4028 "layout(location=0) out vec4 color;\n"
4029 "void main(){\n"
4030 " color = vec4(1);\n"
4031 "}\n";
4032
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004033 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4034 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004035
4036 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004037 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12004038 pipe.AddShader(&vs);
4039 pipe.AddShader(&fs);
4040
Chris Forbes9f7ff632015-05-25 11:13:08 +12004041 VkDescriptorSetObj descriptorSet(m_device);
4042 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004043 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004044
Tony Barbour5781e8f2015-08-04 16:23:11 -06004045 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12004046
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004047 if (!m_errorMonitor->DesiredMsgFound()) {
4048 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
4049 m_errorMonitor->DumpFailureMsgs();
Chris Forbes9f7ff632015-05-25 11:13:08 +12004050 }
4051}
Chris Forbes9f7ff632015-05-25 11:13:08 +12004052
Chris Forbes59cb88d2015-05-25 11:13:13 +12004053TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4054{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004055 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4056 "not written by vertex shader");
4057
Chris Forbes59cb88d2015-05-25 11:13:13 +12004058 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12004060
4061 char const *vsSource =
4062 "#version 140\n"
4063 "#extension GL_ARB_separate_shader_objects: require\n"
4064 "#extension GL_ARB_shading_language_420pack: require\n"
4065 "\n"
4066 "void main(){\n"
4067 " gl_Position = vec4(1);\n"
4068 "}\n";
4069 char const *fsSource =
4070 "#version 140\n"
4071 "#extension GL_ARB_separate_shader_objects: require\n"
4072 "#extension GL_ARB_shading_language_420pack: require\n"
4073 "\n"
4074 "layout(location=0) in float x;\n"
4075 "layout(location=0) out vec4 color;\n"
4076 "void main(){\n"
4077 " color = vec4(x);\n"
4078 "}\n";
4079
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004080 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4081 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004082
4083 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004084 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12004085 pipe.AddShader(&vs);
4086 pipe.AddShader(&fs);
4087
Chris Forbes59cb88d2015-05-25 11:13:13 +12004088 VkDescriptorSetObj descriptorSet(m_device);
4089 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004090 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004091
Tony Barbour5781e8f2015-08-04 16:23:11 -06004092 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12004093
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004094 if (!m_errorMonitor->DesiredMsgFound()) {
4095 FAIL() << "Did not receive Error 'not written by vertex shader'";
4096 m_errorMonitor->DumpFailureMsgs();
Chris Forbes59cb88d2015-05-25 11:13:13 +12004097 }
4098}
4099
Chris Forbesb56af562015-05-25 11:13:17 +12004100TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4101{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004102 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4103 "Type mismatch on location 0");
4104
Chris Forbesb56af562015-05-25 11:13:17 +12004105 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12004107
4108 char const *vsSource =
4109 "#version 140\n"
4110 "#extension GL_ARB_separate_shader_objects: require\n"
4111 "#extension GL_ARB_shading_language_420pack: require\n"
4112 "\n"
4113 "layout(location=0) out int x;\n"
4114 "void main(){\n"
4115 " x = 0;\n"
4116 " gl_Position = vec4(1);\n"
4117 "}\n";
4118 char const *fsSource =
4119 "#version 140\n"
4120 "#extension GL_ARB_separate_shader_objects: require\n"
4121 "#extension GL_ARB_shading_language_420pack: require\n"
4122 "\n"
4123 "layout(location=0) in float x;\n" /* VS writes int */
4124 "layout(location=0) out vec4 color;\n"
4125 "void main(){\n"
4126 " color = vec4(x);\n"
4127 "}\n";
4128
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004129 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4130 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12004131
4132 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004133 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12004134 pipe.AddShader(&vs);
4135 pipe.AddShader(&fs);
4136
Chris Forbesb56af562015-05-25 11:13:17 +12004137 VkDescriptorSetObj descriptorSet(m_device);
4138 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004139 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12004140
Tony Barbour5781e8f2015-08-04 16:23:11 -06004141 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12004142
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004143 if (!m_errorMonitor->DesiredMsgFound()) {
4144 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4145 m_errorMonitor->DumpFailureMsgs();
Chris Forbesb56af562015-05-25 11:13:17 +12004146 }
4147}
4148
Chris Forbesde136e02015-05-25 11:13:28 +12004149TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4150{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004151 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
4152 "location 0 not consumed by VS");
4153
Chris Forbesde136e02015-05-25 11:13:28 +12004154 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004155 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12004156
4157 VkVertexInputBindingDescription input_binding;
4158 memset(&input_binding, 0, sizeof(input_binding));
4159
4160 VkVertexInputAttributeDescription input_attrib;
4161 memset(&input_attrib, 0, sizeof(input_attrib));
4162 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4163
4164 char const *vsSource =
4165 "#version 140\n"
4166 "#extension GL_ARB_separate_shader_objects: require\n"
4167 "#extension GL_ARB_shading_language_420pack: require\n"
4168 "\n"
4169 "void main(){\n"
4170 " gl_Position = vec4(1);\n"
4171 "}\n";
4172 char const *fsSource =
4173 "#version 140\n"
4174 "#extension GL_ARB_separate_shader_objects: require\n"
4175 "#extension GL_ARB_shading_language_420pack: require\n"
4176 "\n"
4177 "layout(location=0) out vec4 color;\n"
4178 "void main(){\n"
4179 " color = vec4(1);\n"
4180 "}\n";
4181
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004182 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4183 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12004184
4185 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004186 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12004187 pipe.AddShader(&vs);
4188 pipe.AddShader(&fs);
4189
4190 pipe.AddVertexInputBindings(&input_binding, 1);
4191 pipe.AddVertexInputAttribs(&input_attrib, 1);
4192
Chris Forbesde136e02015-05-25 11:13:28 +12004193 VkDescriptorSetObj descriptorSet(m_device);
4194 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004195 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12004196
Tony Barbour5781e8f2015-08-04 16:23:11 -06004197 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12004198
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004199 if (!m_errorMonitor->DesiredMsgFound()) {
4200 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
4201 m_errorMonitor->DumpFailureMsgs();
Chris Forbesde136e02015-05-25 11:13:28 +12004202 }
4203}
4204
Chris Forbes62e8e502015-05-25 11:13:29 +12004205TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4206{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004207 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4208 "VS consumes input at location 0 but not provided");
4209
Chris Forbes62e8e502015-05-25 11:13:29 +12004210 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004211 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12004212
4213 char const *vsSource =
4214 "#version 140\n"
4215 "#extension GL_ARB_separate_shader_objects: require\n"
4216 "#extension GL_ARB_shading_language_420pack: require\n"
4217 "\n"
4218 "layout(location=0) in vec4 x;\n" /* not provided */
4219 "void main(){\n"
4220 " gl_Position = x;\n"
4221 "}\n";
4222 char const *fsSource =
4223 "#version 140\n"
4224 "#extension GL_ARB_separate_shader_objects: require\n"
4225 "#extension GL_ARB_shading_language_420pack: require\n"
4226 "\n"
4227 "layout(location=0) out vec4 color;\n"
4228 "void main(){\n"
4229 " color = vec4(1);\n"
4230 "}\n";
4231
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004232 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4233 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12004234
4235 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004236 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12004237 pipe.AddShader(&vs);
4238 pipe.AddShader(&fs);
4239
Chris Forbes62e8e502015-05-25 11:13:29 +12004240 VkDescriptorSetObj descriptorSet(m_device);
4241 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004242 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12004243
Tony Barbour5781e8f2015-08-04 16:23:11 -06004244 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12004245
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004246 if (!m_errorMonitor->DesiredMsgFound()) {
4247 FAIL() << "Did not receive Error 'VS consumes input at location 0 but not provided'";
4248 m_errorMonitor->DumpFailureMsgs();
Chris Forbes62e8e502015-05-25 11:13:29 +12004249 }
4250}
4251
Chris Forbesc97d98e2015-05-25 11:13:31 +12004252TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4253{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004254 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4255 "location 0 does not match VS input type");
4256
Chris Forbesc97d98e2015-05-25 11:13:31 +12004257 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004258 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12004259
4260 VkVertexInputBindingDescription input_binding;
4261 memset(&input_binding, 0, sizeof(input_binding));
4262
4263 VkVertexInputAttributeDescription input_attrib;
4264 memset(&input_attrib, 0, sizeof(input_attrib));
4265 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4266
4267 char const *vsSource =
4268 "#version 140\n"
4269 "#extension GL_ARB_separate_shader_objects: require\n"
4270 "#extension GL_ARB_shading_language_420pack: require\n"
4271 "\n"
4272 "layout(location=0) in int x;\n" /* attrib provided float */
4273 "void main(){\n"
4274 " gl_Position = vec4(x);\n"
4275 "}\n";
4276 char const *fsSource =
4277 "#version 140\n"
4278 "#extension GL_ARB_separate_shader_objects: require\n"
4279 "#extension GL_ARB_shading_language_420pack: require\n"
4280 "\n"
4281 "layout(location=0) out vec4 color;\n"
4282 "void main(){\n"
4283 " color = vec4(1);\n"
4284 "}\n";
4285
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004286 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4287 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12004288
4289 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004290 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12004291 pipe.AddShader(&vs);
4292 pipe.AddShader(&fs);
4293
4294 pipe.AddVertexInputBindings(&input_binding, 1);
4295 pipe.AddVertexInputAttribs(&input_attrib, 1);
4296
Chris Forbesc97d98e2015-05-25 11:13:31 +12004297 VkDescriptorSetObj descriptorSet(m_device);
4298 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004299 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12004300
Tony Barbour5781e8f2015-08-04 16:23:11 -06004301 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12004302
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004303 if (!m_errorMonitor->DesiredMsgFound()) {
4304 FAIL() << "Did not receive Error 'location 0 does not match VS input type'";
4305 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc97d98e2015-05-25 11:13:31 +12004306 }
4307}
4308
Chris Forbes280ba2c2015-06-12 11:16:41 +12004309TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
4310{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004311 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4312 "Duplicate vertex input binding descriptions for binding 0");
4313
Chris Forbes280ba2c2015-06-12 11:16:41 +12004314 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004315 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12004316
4317 /* Two binding descriptions for binding 0 */
4318 VkVertexInputBindingDescription input_bindings[2];
4319 memset(input_bindings, 0, sizeof(input_bindings));
4320
4321 VkVertexInputAttributeDescription input_attrib;
4322 memset(&input_attrib, 0, sizeof(input_attrib));
4323 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4324
4325 char const *vsSource =
4326 "#version 140\n"
4327 "#extension GL_ARB_separate_shader_objects: require\n"
4328 "#extension GL_ARB_shading_language_420pack: require\n"
4329 "\n"
4330 "layout(location=0) in float x;\n" /* attrib provided float */
4331 "void main(){\n"
4332 " gl_Position = vec4(x);\n"
4333 "}\n";
4334 char const *fsSource =
4335 "#version 140\n"
4336 "#extension GL_ARB_separate_shader_objects: require\n"
4337 "#extension GL_ARB_shading_language_420pack: require\n"
4338 "\n"
4339 "layout(location=0) out vec4 color;\n"
4340 "void main(){\n"
4341 " color = vec4(1);\n"
4342 "}\n";
4343
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004344 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4345 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12004346
4347 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004348 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12004349 pipe.AddShader(&vs);
4350 pipe.AddShader(&fs);
4351
4352 pipe.AddVertexInputBindings(input_bindings, 2);
4353 pipe.AddVertexInputAttribs(&input_attrib, 1);
4354
Chris Forbes280ba2c2015-06-12 11:16:41 +12004355 VkDescriptorSetObj descriptorSet(m_device);
4356 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004357 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12004358
Tony Barbour5781e8f2015-08-04 16:23:11 -06004359 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12004360
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004361 if (!m_errorMonitor->DesiredMsgFound()) {
4362 FAIL() << "Did not receive Error 'Duplicate vertex input binding descriptions for binding 0'";
4363 m_errorMonitor->DumpFailureMsgs();
Chris Forbes280ba2c2015-06-12 11:16:41 +12004364 }
4365}
Chris Forbes8f68b562015-05-25 11:13:32 +12004366
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004367/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
4368 * rejects it. */
4369
4370TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
4371{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004372 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4373 "Attachment 0 not written by FS");
4374
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004375 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004376
4377 char const *vsSource =
4378 "#version 140\n"
4379 "#extension GL_ARB_separate_shader_objects: require\n"
4380 "#extension GL_ARB_shading_language_420pack: require\n"
4381 "\n"
4382 "void main(){\n"
4383 " gl_Position = vec4(1);\n"
4384 "}\n";
4385 char const *fsSource =
4386 "#version 140\n"
4387 "#extension GL_ARB_separate_shader_objects: require\n"
4388 "#extension GL_ARB_shading_language_420pack: require\n"
4389 "\n"
4390 "void main(){\n"
4391 "}\n";
4392
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004393 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4394 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004395
4396 VkPipelineObj pipe(m_device);
4397 pipe.AddShader(&vs);
4398 pipe.AddShader(&fs);
4399
Chia-I Wu08accc62015-07-07 11:50:03 +08004400 /* set up CB 0, not written */
4401 pipe.AddColorAttachment();
4402 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004403
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004404 VkDescriptorSetObj descriptorSet(m_device);
4405 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004406 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004407
Tony Barbour5781e8f2015-08-04 16:23:11 -06004408 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004409
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004410 if (!m_errorMonitor->DesiredMsgFound()) {
4411 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
4412 m_errorMonitor->DumpFailureMsgs();
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004413 }
4414}
4415
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004416TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
4417{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004418 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
4419 "FS writes to output location 1 with no matching attachment");
4420
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004421 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004422
4423 char const *vsSource =
4424 "#version 140\n"
4425 "#extension GL_ARB_separate_shader_objects: require\n"
4426 "#extension GL_ARB_shading_language_420pack: require\n"
4427 "\n"
4428 "void main(){\n"
4429 " gl_Position = vec4(1);\n"
4430 "}\n";
4431 char const *fsSource =
4432 "#version 140\n"
4433 "#extension GL_ARB_separate_shader_objects: require\n"
4434 "#extension GL_ARB_shading_language_420pack: require\n"
4435 "\n"
4436 "layout(location=0) out vec4 x;\n"
4437 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4438 "void main(){\n"
4439 " x = vec4(1);\n"
4440 " y = vec4(1);\n"
4441 "}\n";
4442
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004443 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4444 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004445
4446 VkPipelineObj pipe(m_device);
4447 pipe.AddShader(&vs);
4448 pipe.AddShader(&fs);
4449
Chia-I Wu08accc62015-07-07 11:50:03 +08004450 /* set up CB 0, not written */
4451 pipe.AddColorAttachment();
4452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004453 /* FS writes CB 1, but we don't configure it */
4454
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004455 VkDescriptorSetObj descriptorSet(m_device);
4456 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004457 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004458
Tony Barbour5781e8f2015-08-04 16:23:11 -06004459 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004460
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004461 if (!m_errorMonitor->DesiredMsgFound()) {
4462 FAIL() << "Did not receive Error 'FS writes to output location 1 with no matching attachment'";
4463 m_errorMonitor->DumpFailureMsgs();
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004464 }
4465}
4466
Chris Forbesa36d69e2015-05-25 11:13:44 +12004467TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4468{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004469 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4470 "does not match FS output type");
4471
Chris Forbesa36d69e2015-05-25 11:13:44 +12004472 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004473
4474 char const *vsSource =
4475 "#version 140\n"
4476 "#extension GL_ARB_separate_shader_objects: require\n"
4477 "#extension GL_ARB_shading_language_420pack: require\n"
4478 "\n"
4479 "void main(){\n"
4480 " gl_Position = vec4(1);\n"
4481 "}\n";
4482 char const *fsSource =
4483 "#version 140\n"
4484 "#extension GL_ARB_separate_shader_objects: require\n"
4485 "#extension GL_ARB_shading_language_420pack: require\n"
4486 "\n"
4487 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4488 "void main(){\n"
4489 " x = ivec4(1);\n"
4490 "}\n";
4491
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004492 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4493 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004494
4495 VkPipelineObj pipe(m_device);
4496 pipe.AddShader(&vs);
4497 pipe.AddShader(&fs);
4498
Chia-I Wu08accc62015-07-07 11:50:03 +08004499 /* set up CB 0; type is UNORM by default */
4500 pipe.AddColorAttachment();
4501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004502
Chris Forbesa36d69e2015-05-25 11:13:44 +12004503 VkDescriptorSetObj descriptorSet(m_device);
4504 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004505 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004506
Tony Barbour5781e8f2015-08-04 16:23:11 -06004507 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004508
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004509 if (!m_errorMonitor->DesiredMsgFound()) {
4510 FAIL() << "Did not receive Error 'does not match FS output type'";
4511 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa36d69e2015-05-25 11:13:44 +12004512 }
4513}
Chris Forbes7b1b8932015-06-05 14:43:36 +12004514
Chris Forbes556c76c2015-08-14 12:04:59 +12004515TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4516{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004517 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4518 "not declared in pipeline layout");
4519
Chris Forbes556c76c2015-08-14 12:04:59 +12004520 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12004521
4522 char const *vsSource =
4523 "#version 140\n"
4524 "#extension GL_ARB_separate_shader_objects: require\n"
4525 "#extension GL_ARB_shading_language_420pack: require\n"
4526 "\n"
4527 "void main(){\n"
4528 " gl_Position = vec4(1);\n"
4529 "}\n";
4530 char const *fsSource =
4531 "#version 140\n"
4532 "#extension GL_ARB_separate_shader_objects: require\n"
4533 "#extension GL_ARB_shading_language_420pack: require\n"
4534 "\n"
4535 "layout(location=0) out vec4 x;\n"
4536 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4537 "void main(){\n"
4538 " x = vec4(bar.y);\n"
4539 "}\n";
4540
Chris Forbes556c76c2015-08-14 12:04:59 +12004541
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004542 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4543 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12004544
Chris Forbes556c76c2015-08-14 12:04:59 +12004545 VkPipelineObj pipe(m_device);
4546 pipe.AddShader(&vs);
4547 pipe.AddShader(&fs);
4548
4549 /* set up CB 0; type is UNORM by default */
4550 pipe.AddColorAttachment();
4551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4552
4553 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004554 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12004555
4556 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4557
4558 /* should have generated an error -- pipeline layout does not
4559 * provide a uniform buffer in 0.0
4560 */
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004561 if (!m_errorMonitor->DesiredMsgFound()) {
4562 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
4563 m_errorMonitor->DumpFailureMsgs();
Chris Forbes556c76c2015-08-14 12:04:59 +12004564 }
4565}
4566
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004567#endif // SHADER_CHECKER_TESTS
4568
4569#if DEVICE_LIMITS_TESTS
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004570TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4571{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004572 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4573 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004574
4575 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004576
4577 // Create an image
4578 VkImage image;
4579
4580 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4581 const int32_t tex_width = 32;
4582 const int32_t tex_height = 32;
4583
4584 VkImageCreateInfo image_create_info = {};
4585 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4586 image_create_info.pNext = NULL;
4587 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4588 image_create_info.format = tex_format;
4589 image_create_info.extent.width = tex_width;
4590 image_create_info.extent.height = tex_height;
4591 image_create_info.extent.depth = 1;
4592 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004593 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004594 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004595 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4596 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4597 image_create_info.flags = 0;
4598
4599 // Introduce error by sending down a bogus width extent
4600 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004601 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004602
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004603 if (!m_errorMonitor->DesiredMsgFound()) {
4604 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable limits for format'";
4605 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004606 }
4607}
4608
4609TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4610{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004611 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4612 "CreateImage resource size exceeds allowable maximum");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004613
4614 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004615
4616 // Create an image
4617 VkImage image;
4618
4619 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4620 const int32_t tex_width = 32;
4621 const int32_t tex_height = 32;
4622
4623 VkImageCreateInfo image_create_info = {};
4624 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4625 image_create_info.pNext = NULL;
4626 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4627 image_create_info.format = tex_format;
4628 image_create_info.extent.width = tex_width;
4629 image_create_info.extent.height = tex_height;
4630 image_create_info.extent.depth = 1;
4631 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004632 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004633 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004634 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4635 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4636 image_create_info.flags = 0;
4637
4638 // Introduce error by sending down individually allowable values that result in a surface size
4639 // exceeding the device maximum
4640 image_create_info.extent.width = 8192;
4641 image_create_info.extent.height = 8192;
4642 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004643 image_create_info.arrayLayers = 4;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004644 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004645 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004646 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004647
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004648 if (!m_errorMonitor->DesiredMsgFound()) {
4649 FAIL() << "Did not receive Error 'CreateImage resource size exceeds allowable maximum'";
4650 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004651 }
4652}
4653
Mike Stroyana3082432015-09-25 13:39:21 -06004654TEST_F(VkLayerTest, UpdateBufferAlignment)
4655{
Mike Stroyana3082432015-09-25 13:39:21 -06004656 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4657
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004658 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4659 "dstOffset, is not a multiple of 4");
4660
Mike Stroyana3082432015-09-25 13:39:21 -06004661 ASSERT_NO_FATAL_FAILURE(InitState());
4662
4663 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4664 vk_testing::Buffer buffer;
4665 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4666
4667 BeginCommandBuffer();
4668 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004669 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004670 if (!m_errorMonitor->DesiredMsgFound()) {
4671 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
4672 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06004673 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004674
Mike Stroyana3082432015-09-25 13:39:21 -06004675 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004676 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4677 "dataSize, is not a multiple of 4");
4678
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004679 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004680
4681 if (!m_errorMonitor->DesiredMsgFound()) {
4682 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4683 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06004684 }
4685 EndCommandBuffer();
4686}
4687
4688TEST_F(VkLayerTest, FillBufferAlignment)
4689{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004690 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4691 "dstOffset, is not a multiple of 4");
Mike Stroyana3082432015-09-25 13:39:21 -06004692
4693 ASSERT_NO_FATAL_FAILURE(InitState());
4694
4695 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4696 vk_testing::Buffer buffer;
4697 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4698
4699 BeginCommandBuffer();
4700 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004701 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004702 if (!m_errorMonitor->DesiredMsgFound()) {
4703 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
4704 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06004705 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004706
Mike Stroyana3082432015-09-25 13:39:21 -06004707 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004708 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4709 "size, is not a multiple of 4");
4710
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004711 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004712
4713 if (!m_errorMonitor->DesiredMsgFound()) {
4714 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
4715 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06004716 }
4717 EndCommandBuffer();
4718}
4719
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004720#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12004721
Tobin Ehliscde08892015-09-22 10:11:37 -06004722#if IMAGE_TESTS
4723TEST_F(VkLayerTest, InvalidImageView)
4724{
Tobin Ehliscde08892015-09-22 10:11:37 -06004725 VkResult err;
4726
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004727 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4728 "vkCreateImageView called with baseMipLevel 10 ");
4729
Tobin Ehliscde08892015-09-22 10:11:37 -06004730 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -06004731
Mike Stroyana3082432015-09-25 13:39:21 -06004732 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehliscde08892015-09-22 10:11:37 -06004733 VkImage image;
4734
4735 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4736 const int32_t tex_width = 32;
4737 const int32_t tex_height = 32;
4738
4739 VkImageCreateInfo image_create_info = {};
4740 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4741 image_create_info.pNext = NULL;
4742 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4743 image_create_info.format = tex_format;
4744 image_create_info.extent.width = tex_width;
4745 image_create_info.extent.height = tex_height;
4746 image_create_info.extent.depth = 1;
4747 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004748 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004749 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06004750 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4751 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4752 image_create_info.flags = 0;
4753
Chia-I Wuf7458c52015-10-26 21:10:41 +08004754 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -06004755 ASSERT_VK_SUCCESS(err);
4756
4757 VkImageViewCreateInfo image_view_create_info = {};
4758 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4759 image_view_create_info.image = image;
4760 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4761 image_view_create_info.format = tex_format;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004762 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehliscde08892015-09-22 10:11:37 -06004763 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004764 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004765 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06004766
4767 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004768 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -06004769
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004770 if (!m_errorMonitor->DesiredMsgFound()) {
4771 FAIL() << "Did not receive Error 'vkCreateImageView called with baseMipLevel 10...'";
4772 m_errorMonitor->DumpFailureMsgs();
Tobin Ehliscde08892015-09-22 10:11:37 -06004773 }
4774}
Mike Stroyana3082432015-09-25 13:39:21 -06004775
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004776TEST_F(VkLayerTest, InvalidImageViewAspect)
4777{
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004778 VkResult err;
4779
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004780 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4781 "vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set");
4782
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004783 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004784
4785 // Create an image and try to create a view with an invalid aspectMask
4786 VkImage image;
4787
4788 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4789 const int32_t tex_width = 32;
4790 const int32_t tex_height = 32;
4791
4792 VkImageCreateInfo image_create_info = {};
4793 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4794 image_create_info.pNext = NULL;
4795 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4796 image_create_info.format = tex_format;
4797 image_create_info.extent.width = tex_width;
4798 image_create_info.extent.height = tex_height;
4799 image_create_info.extent.depth = 1;
4800 image_create_info.mipLevels = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004801 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004802 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4803 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4804 image_create_info.flags = 0;
4805
Chia-I Wuf7458c52015-10-26 21:10:41 +08004806 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004807 ASSERT_VK_SUCCESS(err);
4808
4809 VkImageViewCreateInfo image_view_create_info = {};
4810 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4811 image_view_create_info.image = image;
4812 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4813 image_view_create_info.format = tex_format;
4814 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004815 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004816 // Cause an error by setting an invalid image aspect
4817 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
4818
4819 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004820 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004821
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004822 if (!m_errorMonitor->DesiredMsgFound()) {
4823 FAIL() << "Did not receive Error 'VkCreateImageView: Color image formats must have ...'";
4824 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004825 }
4826}
4827
Mike Stroyana3082432015-09-25 13:39:21 -06004828TEST_F(VkLayerTest, CopyImageTypeMismatch)
4829{
Mike Stroyana3082432015-09-25 13:39:21 -06004830 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004831 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004832
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004833 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4834 "vkCmdCopyImage called with unmatched source and dest image types");
4835
Mike Stroyana3082432015-09-25 13:39:21 -06004836 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06004837
4838 // Create two images of different types and try to copy between them
4839 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004840 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06004841 VkDeviceMemory srcMem;
4842 VkDeviceMemory destMem;
4843 VkMemoryRequirements memReqs;
4844
4845 VkImageCreateInfo image_create_info = {};
4846 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4847 image_create_info.pNext = NULL;
4848 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4849 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4850 image_create_info.extent.width = 32;
4851 image_create_info.extent.height = 32;
4852 image_create_info.extent.depth = 1;
4853 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004854 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004855 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004856 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004857 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004858 image_create_info.flags = 0;
4859
Chia-I Wuf7458c52015-10-26 21:10:41 +08004860 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06004861 ASSERT_VK_SUCCESS(err);
4862
4863 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004864 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004865
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004866 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06004867 ASSERT_VK_SUCCESS(err);
4868
4869 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004870 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06004871 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4872 memAlloc.pNext = NULL;
4873 memAlloc.allocationSize = 0;
4874 memAlloc.memoryTypeIndex = 0;
4875
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004876 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004877 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004878 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4879 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004880 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06004881 ASSERT_VK_SUCCESS(err);
4882
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004883 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004884 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004885 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06004886 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004887 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06004888 ASSERT_VK_SUCCESS(err);
4889
4890 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4891 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004892 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06004893 ASSERT_VK_SUCCESS(err);
4894
4895 BeginCommandBuffer();
4896 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08004897 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004898 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004899 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004900 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004901 copyRegion.srcOffset.x = 0;
4902 copyRegion.srcOffset.y = 0;
4903 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08004904 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004905 copyRegion.dstSubresource.mipLevel = 0;
4906 copyRegion.dstSubresource.baseArrayLayer = 0;
4907 copyRegion.dstSubresource.layerCount = 0;
4908 copyRegion.dstOffset.x = 0;
4909 copyRegion.dstOffset.y = 0;
4910 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004911 copyRegion.extent.width = 1;
4912 copyRegion.extent.height = 1;
4913 copyRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004914 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06004915 EndCommandBuffer();
4916
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004917 if (!m_errorMonitor->DesiredMsgFound()) {
4918 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
4919 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06004920 }
4921
Chia-I Wuf7458c52015-10-26 21:10:41 +08004922 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004923 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004924 vkFreeMemory(m_device->device(), srcMem, NULL);
4925 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06004926}
4927
4928TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
4929{
4930 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
4931}
4932
4933TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
4934{
Mike Stroyana3082432015-09-25 13:39:21 -06004935 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004936 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004937
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004938 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4939 "vkCmdCopyImage called with unmatched source and dest image types");
4940
Mike Stroyana3082432015-09-25 13:39:21 -06004941 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06004942
4943 // Create two images of different types and try to copy between them
4944 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004945 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06004946 VkDeviceMemory srcMem;
4947 VkDeviceMemory destMem;
4948 VkMemoryRequirements memReqs;
4949
4950 VkImageCreateInfo image_create_info = {};
4951 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4952 image_create_info.pNext = NULL;
4953 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4954 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4955 image_create_info.extent.width = 32;
4956 image_create_info.extent.height = 32;
4957 image_create_info.extent.depth = 1;
4958 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004959 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004960 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004961 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004962 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004963 image_create_info.flags = 0;
4964
Chia-I Wuf7458c52015-10-26 21:10:41 +08004965 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06004966 ASSERT_VK_SUCCESS(err);
4967
4968 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004969 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004970
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004971 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06004972 ASSERT_VK_SUCCESS(err);
4973
4974 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004975 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06004976 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4977 memAlloc.pNext = NULL;
4978 memAlloc.allocationSize = 0;
4979 memAlloc.memoryTypeIndex = 0;
4980
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004981 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004982 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004983 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4984 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004985 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06004986 ASSERT_VK_SUCCESS(err);
4987
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004988 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004989 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004990 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4991 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004992 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06004993 ASSERT_VK_SUCCESS(err);
4994
4995 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4996 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004997 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06004998 ASSERT_VK_SUCCESS(err);
4999
5000 BeginCommandBuffer();
5001 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005002 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005003 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005004 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005005 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005006 copyRegion.srcOffset.x = 0;
5007 copyRegion.srcOffset.y = 0;
5008 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005009 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005010 copyRegion.dstSubresource.mipLevel = 0;
5011 copyRegion.dstSubresource.baseArrayLayer = 0;
5012 copyRegion.dstSubresource.layerCount = 0;
5013 copyRegion.dstOffset.x = 0;
5014 copyRegion.dstOffset.y = 0;
5015 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005016 copyRegion.extent.width = 1;
5017 copyRegion.extent.height = 1;
5018 copyRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005019 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005020 EndCommandBuffer();
5021
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005022 if (!m_errorMonitor->DesiredMsgFound()) {
5023 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5024 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005025 }
5026
Chia-I Wuf7458c52015-10-26 21:10:41 +08005027 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005028 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005029 vkFreeMemory(m_device->device(), srcMem, NULL);
5030 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005031}
5032
5033TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5034{
Mike Stroyana3082432015-09-25 13:39:21 -06005035 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005036 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005037
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005038 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5039 "vkCmdResolveImage called with source sample count less than 2.");
5040
Mike Stroyana3082432015-09-25 13:39:21 -06005041 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005042
5043 // Create two images of sample count 1 and try to Resolve between them
5044 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005045 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005046 VkDeviceMemory srcMem;
5047 VkDeviceMemory destMem;
5048 VkMemoryRequirements memReqs;
5049
5050 VkImageCreateInfo image_create_info = {};
5051 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5052 image_create_info.pNext = NULL;
5053 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5054 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5055 image_create_info.extent.width = 32;
5056 image_create_info.extent.height = 1;
5057 image_create_info.extent.depth = 1;
5058 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005059 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005060 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005061 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005062 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005063 image_create_info.flags = 0;
5064
Chia-I Wuf7458c52015-10-26 21:10:41 +08005065 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005066 ASSERT_VK_SUCCESS(err);
5067
5068 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005069 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005070
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005071 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005072 ASSERT_VK_SUCCESS(err);
5073
5074 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005075 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06005076 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5077 memAlloc.pNext = NULL;
5078 memAlloc.allocationSize = 0;
5079 memAlloc.memoryTypeIndex = 0;
5080
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005081 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005082 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005083 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5084 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005085 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005086 ASSERT_VK_SUCCESS(err);
5087
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005088 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005089 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005090 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5091 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005092 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005093 ASSERT_VK_SUCCESS(err);
5094
5095 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5096 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005097 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005098 ASSERT_VK_SUCCESS(err);
5099
5100 BeginCommandBuffer();
5101 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5102 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5103 //VK_IMAGE_LAYOUT_GENERAL = 1,
5104 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005105 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005106 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005107 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005108 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005109 resolveRegion.srcOffset.x = 0;
5110 resolveRegion.srcOffset.y = 0;
5111 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005112 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005113 resolveRegion.dstSubresource.mipLevel = 0;
5114 resolveRegion.dstSubresource.baseArrayLayer = 0;
5115 resolveRegion.dstSubresource.layerCount = 0;
5116 resolveRegion.dstOffset.x = 0;
5117 resolveRegion.dstOffset.y = 0;
5118 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005119 resolveRegion.extent.width = 1;
5120 resolveRegion.extent.height = 1;
5121 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005122 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005123 EndCommandBuffer();
5124
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005125 if (!m_errorMonitor->DesiredMsgFound()) {
5126 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source sample count less than 2.'";
5127 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005128 }
5129
Chia-I Wuf7458c52015-10-26 21:10:41 +08005130 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005131 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005132 vkFreeMemory(m_device->device(), srcMem, NULL);
5133 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005134}
5135
5136TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5137{
Mike Stroyana3082432015-09-25 13:39:21 -06005138 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005139 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005140
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005141 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5142 "vkCmdResolveImage called with dest sample count greater than 1.");
5143
Mike Stroyana3082432015-09-25 13:39:21 -06005144 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005145
5146 // Create two images of sample count 2 and try to Resolve between them
5147 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005148 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005149 VkDeviceMemory srcMem;
5150 VkDeviceMemory destMem;
5151 VkMemoryRequirements memReqs;
5152
5153 VkImageCreateInfo image_create_info = {};
5154 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5155 image_create_info.pNext = NULL;
5156 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5157 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5158 image_create_info.extent.width = 32;
5159 image_create_info.extent.height = 1;
5160 image_create_info.extent.depth = 1;
5161 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005162 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005163 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005164 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06005165 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005166 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005167 image_create_info.flags = 0;
5168
Chia-I Wuf7458c52015-10-26 21:10:41 +08005169 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005170 ASSERT_VK_SUCCESS(err);
5171
5172 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northrop72458c02015-10-27 13:50:04 -06005173 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005174 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005175
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005176 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005177 ASSERT_VK_SUCCESS(err);
5178
5179 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005180 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06005181 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5182 memAlloc.pNext = NULL;
5183 memAlloc.allocationSize = 0;
5184 memAlloc.memoryTypeIndex = 0;
5185
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005186 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005187 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005188 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5189 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005190 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005191 ASSERT_VK_SUCCESS(err);
5192
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005193 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005194 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005195 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5196 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005197 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005198 ASSERT_VK_SUCCESS(err);
5199
5200 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5201 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005202 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005203 ASSERT_VK_SUCCESS(err);
5204
5205 BeginCommandBuffer();
5206 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5207 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5208 //VK_IMAGE_LAYOUT_GENERAL = 1,
5209 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005210 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005211 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005212 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005213 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005214 resolveRegion.srcOffset.x = 0;
5215 resolveRegion.srcOffset.y = 0;
5216 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005217 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005218 resolveRegion.dstSubresource.mipLevel = 0;
5219 resolveRegion.dstSubresource.baseArrayLayer = 0;
5220 resolveRegion.dstSubresource.layerCount = 0;
5221 resolveRegion.dstOffset.x = 0;
5222 resolveRegion.dstOffset.y = 0;
5223 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005224 resolveRegion.extent.width = 1;
5225 resolveRegion.extent.height = 1;
5226 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005227 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005228 EndCommandBuffer();
5229
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005230 if (!m_errorMonitor->DesiredMsgFound()) {
5231 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest sample count greater than 1.'";
5232 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005233 }
5234
Chia-I Wuf7458c52015-10-26 21:10:41 +08005235 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005236 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005237 vkFreeMemory(m_device->device(), srcMem, NULL);
5238 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005239}
5240
5241TEST_F(VkLayerTest, ResolveImageFormatMismatch)
5242{
Mike Stroyana3082432015-09-25 13:39:21 -06005243 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005244 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005245
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005246 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5247 "vkCmdResolveImage called with unmatched source and dest formats.");
5248
Mike Stroyana3082432015-09-25 13:39:21 -06005249 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005250
5251 // Create two images of different types and try to copy between them
5252 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005253 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005254 VkDeviceMemory srcMem;
5255 VkDeviceMemory destMem;
5256 VkMemoryRequirements memReqs;
5257
5258 VkImageCreateInfo image_create_info = {};
5259 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5260 image_create_info.pNext = NULL;
5261 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5262 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5263 image_create_info.extent.width = 32;
5264 image_create_info.extent.height = 1;
5265 image_create_info.extent.depth = 1;
5266 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005267 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005268 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005269 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06005270 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005271 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005272 image_create_info.flags = 0;
5273
Chia-I Wuf7458c52015-10-26 21:10:41 +08005274 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005275 ASSERT_VK_SUCCESS(err);
5276
Cody Northrop72458c02015-10-27 13:50:04 -06005277 // Set format to something other than source image
5278 image_create_info.format = VK_FORMAT_R32_SFLOAT;
5279 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005280 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005281 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005282
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005283 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005284 ASSERT_VK_SUCCESS(err);
5285
5286 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005287 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06005288 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5289 memAlloc.pNext = NULL;
5290 memAlloc.allocationSize = 0;
5291 memAlloc.memoryTypeIndex = 0;
5292
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005293 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005294 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005295 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5296 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005297 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005298 ASSERT_VK_SUCCESS(err);
5299
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005300 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005301 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005302 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5303 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005304 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005305 ASSERT_VK_SUCCESS(err);
5306
5307 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5308 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005309 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005310 ASSERT_VK_SUCCESS(err);
5311
5312 BeginCommandBuffer();
5313 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5314 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5315 //VK_IMAGE_LAYOUT_GENERAL = 1,
5316 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005317 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005318 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005319 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005320 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005321 resolveRegion.srcOffset.x = 0;
5322 resolveRegion.srcOffset.y = 0;
5323 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005324 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005325 resolveRegion.dstSubresource.mipLevel = 0;
5326 resolveRegion.dstSubresource.baseArrayLayer = 0;
5327 resolveRegion.dstSubresource.layerCount = 0;
5328 resolveRegion.dstOffset.x = 0;
5329 resolveRegion.dstOffset.y = 0;
5330 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005331 resolveRegion.extent.width = 1;
5332 resolveRegion.extent.height = 1;
5333 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005334 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005335 EndCommandBuffer();
5336
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005337 if (!m_errorMonitor->DesiredMsgFound()) {
5338 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest formats.'";
5339 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005340 }
5341
Chia-I Wuf7458c52015-10-26 21:10:41 +08005342 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005343 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005344 vkFreeMemory(m_device->device(), srcMem, NULL);
5345 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005346}
5347
5348TEST_F(VkLayerTest, ResolveImageTypeMismatch)
5349{
Mike Stroyana3082432015-09-25 13:39:21 -06005350 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005351 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005352
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005353 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5354 "vkCmdResolveImage called with unmatched source and dest image types.");
5355
Mike Stroyana3082432015-09-25 13:39:21 -06005356 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005357
5358 // Create two images of different types and try to copy between them
5359 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005360 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005361 VkDeviceMemory srcMem;
5362 VkDeviceMemory destMem;
5363 VkMemoryRequirements memReqs;
5364
5365 VkImageCreateInfo image_create_info = {};
5366 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5367 image_create_info.pNext = NULL;
5368 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5369 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5370 image_create_info.extent.width = 32;
5371 image_create_info.extent.height = 1;
5372 image_create_info.extent.depth = 1;
5373 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005374 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005375 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005376 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06005377 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005378 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005379 image_create_info.flags = 0;
5380
Chia-I Wuf7458c52015-10-26 21:10:41 +08005381 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005382 ASSERT_VK_SUCCESS(err);
5383
5384 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northrop72458c02015-10-27 13:50:04 -06005385 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005386 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005387 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005388
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005389 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005390 ASSERT_VK_SUCCESS(err);
5391
5392 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005393 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06005394 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5395 memAlloc.pNext = NULL;
5396 memAlloc.allocationSize = 0;
5397 memAlloc.memoryTypeIndex = 0;
5398
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005399 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005400 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005401 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5402 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005403 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005404 ASSERT_VK_SUCCESS(err);
5405
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005406 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005407 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005408 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5409 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005410 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005411 ASSERT_VK_SUCCESS(err);
5412
5413 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5414 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005415 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005416 ASSERT_VK_SUCCESS(err);
5417
5418 BeginCommandBuffer();
5419 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5420 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5421 //VK_IMAGE_LAYOUT_GENERAL = 1,
5422 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005423 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005424 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005425 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005426 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005427 resolveRegion.srcOffset.x = 0;
5428 resolveRegion.srcOffset.y = 0;
5429 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005430 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005431 resolveRegion.dstSubresource.mipLevel = 0;
5432 resolveRegion.dstSubresource.baseArrayLayer = 0;
5433 resolveRegion.dstSubresource.layerCount = 0;
5434 resolveRegion.dstOffset.x = 0;
5435 resolveRegion.dstOffset.y = 0;
5436 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005437 resolveRegion.extent.width = 1;
5438 resolveRegion.extent.height = 1;
5439 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005440 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005441 EndCommandBuffer();
5442
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005443 if (!m_errorMonitor->DesiredMsgFound()) {
5444 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest image types.'";
5445 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005446 }
5447
Chia-I Wuf7458c52015-10-26 21:10:41 +08005448 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005449 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005450 vkFreeMemory(m_device->device(), srcMem, NULL);
5451 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005452}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005453
5454TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
5455{
5456 // Create a single Image descriptor and cause it to first hit an error due
5457 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
5458 // The image format check comes 2nd in validation so we trigger it first,
5459 // then when we cause aspect fail next, bad format check will be preempted
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005460 VkResult err;
5461
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005462 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5463 "Combination depth/stencil image formats can have only the ");
5464
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005465 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005466
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005467 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005468 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005469 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005470
5471 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5472 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5473 ds_pool_ci.pNext = NULL;
5474 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005475 ds_pool_ci.poolSizeCount = 1;
5476 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005477
5478 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005479 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005480 ASSERT_VK_SUCCESS(err);
5481
5482 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08005483 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005484 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5485 dsl_binding.arraySize = 1;
5486 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5487 dsl_binding.pImmutableSamplers = NULL;
5488
5489 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5490 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5491 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005492 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08005493 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005494 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005495 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005496 ASSERT_VK_SUCCESS(err);
5497
5498 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005499 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005500 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005501 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005502 alloc_info.descriptorPool = ds_pool;
5503 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005504 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005505 ASSERT_VK_SUCCESS(err);
5506
5507 VkImage image_bad;
5508 VkImage image_good;
5509 // One bad format and one good format for Color attachment
5510 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
5511 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
5512 const int32_t tex_width = 32;
5513 const int32_t tex_height = 32;
5514
5515 VkImageCreateInfo image_create_info = {};
5516 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5517 image_create_info.pNext = NULL;
5518 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5519 image_create_info.format = tex_format_bad;
5520 image_create_info.extent.width = tex_width;
5521 image_create_info.extent.height = tex_height;
5522 image_create_info.extent.depth = 1;
5523 image_create_info.mipLevels = 1;
5524 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005525 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005526 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5527 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
5528 image_create_info.flags = 0;
5529
Chia-I Wuf7458c52015-10-26 21:10:41 +08005530 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005531 ASSERT_VK_SUCCESS(err);
5532 image_create_info.format = tex_format_good;
5533 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005534 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005535 ASSERT_VK_SUCCESS(err);
5536
5537 VkImageViewCreateInfo image_view_create_info = {};
5538 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5539 image_view_create_info.image = image_bad;
5540 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5541 image_view_create_info.format = tex_format_bad;
5542 image_view_create_info.subresourceRange.baseArrayLayer = 0;
5543 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005544 image_view_create_info.subresourceRange.layerCount = 1;
5545 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005546 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5547
5548 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005549 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005550
5551 if (!m_errorMonitor->DesiredMsgFound()) {
5552 FAIL() << "Did not receive Error 'Combination depth-stencil image formats can have only the....'";
5553 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005554 }
5555
Chia-I Wuf7458c52015-10-26 21:10:41 +08005556 vkDestroyImage(m_device->device(), image_bad, NULL);
5557 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005558 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5559 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005560}
Tobin Ehliscde08892015-09-22 10:11:37 -06005561#endif // IMAGE_TESTS
5562
Tony Barbour300a6082015-04-07 13:44:53 -06005563int main(int argc, char **argv) {
5564 int result;
5565
5566 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06005567 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06005568
5569 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
5570
5571 result = RUN_ALL_TESTS();
5572
Tony Barbour6918cd52015-04-09 12:58:51 -06005573 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06005574 return result;
5575}