blob: e28cf5fbbf9e80f18c775d74e670d631c86b2d6e [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;
Tony Barboureb254902015-07-15 12:50:33 -0600564 image_create_info.samples = 1;
565 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
566 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
567 image_create_info.flags = 0;
Mark 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,
639// .samples = 1,
640// .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;
Tony Barboureb254902015-07-15 12:50:33 -0600711 image_create_info.samples = 1;
712 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
713 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
714 image_create_info.flags = 0;
Mark 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,
846 .samples = 1,
847 .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 = {};
901 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
902 dsl_binding.arraySize = 1;
903 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
904 dsl_binding.pImmutableSamplers = NULL;
905
906 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
907 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
908 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800909 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +0800910 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600911
912 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800913 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600914 ASSERT_VK_SUCCESS(err);
915
916 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800917 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600918 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800919 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600920 alloc_info.descriptorPool = ds_pool;
921 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800922 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600923 ASSERT_VK_SUCCESS(err);
924
925 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
926 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
927 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800928 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600929 pipeline_layout_ci.pSetLayouts = &ds_layout;
930
931 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800932 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600933 ASSERT_VK_SUCCESS(err);
934
935 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
936
937 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800938 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600939
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600940 if (!m_errorMonitor->DesiredMsgFound()) {
941 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be'" << endl;
942 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisec598302015-09-15 15:02:17 -0600943 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600944
Chia-I Wuf7458c52015-10-26 21:10:41 +0800945 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
946 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
947 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -0600948}
949
950TEST_F(VkLayerTest, BindInvalidMemory)
951{
Tobin Ehlisec598302015-09-15 15:02:17 -0600952 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600953 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -0600954
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600955 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
956 "Invalid VkDeviceMemory Object ");
957
Tobin Ehlisec598302015-09-15 15:02:17 -0600958 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -0600959
960 // Create an image, allocate memory, free it, and then try to bind it
961 VkImage image;
962 VkDeviceMemory mem;
963 VkMemoryRequirements mem_reqs;
964
965 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
966 const int32_t tex_width = 32;
967 const int32_t tex_height = 32;
968
969 VkImageCreateInfo image_create_info = {};
970 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
971 image_create_info.pNext = NULL;
972 image_create_info.imageType = VK_IMAGE_TYPE_2D;
973 image_create_info.format = tex_format;
974 image_create_info.extent.width = tex_width;
975 image_create_info.extent.height = tex_height;
976 image_create_info.extent.depth = 1;
977 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600978 image_create_info.arrayLayers = 1;
Tobin Ehlisec598302015-09-15 15:02:17 -0600979 image_create_info.samples = 1;
980 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
981 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
982 image_create_info.flags = 0;
983
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800984 VkMemoryAllocateInfo mem_alloc = {};
Tobin Ehlisec598302015-09-15 15:02:17 -0600985 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
986 mem_alloc.pNext = NULL;
987 mem_alloc.allocationSize = 0;
988 mem_alloc.memoryTypeIndex = 0;
989
Chia-I Wuf7458c52015-10-26 21:10:41 +0800990 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -0600991 ASSERT_VK_SUCCESS(err);
992
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600993 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlisec598302015-09-15 15:02:17 -0600994 image,
995 &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -0600996
997 mem_alloc.allocationSize = mem_reqs.size;
998
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600999 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1000 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001001
1002 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001003 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001004 ASSERT_VK_SUCCESS(err);
1005
1006 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001007 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001008
1009 // Try to bind free memory that has been freed
1010 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1011 // This may very well return an error.
1012 (void)err;
1013
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001014 if (!m_errorMonitor->DesiredMsgFound()) {
1015 FAIL() << "Did not receive Error 'Invalid VkDeviceMemory Object 0x<handle>'";
1016 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisec598302015-09-15 15:02:17 -06001017 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001018
Chia-I Wuf7458c52015-10-26 21:10:41 +08001019 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001020}
1021
1022TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
1023{
Tobin Ehlisec598302015-09-15 15:02:17 -06001024 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001025 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06001026
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001027 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Invalid VkImage Object ");
1028
Tobin Ehlisec598302015-09-15 15:02:17 -06001029 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06001030
1031 // Create an image object, allocate memory, destroy the object and then try to bind it
1032 VkImage image;
1033 VkDeviceMemory mem;
1034 VkMemoryRequirements mem_reqs;
1035
1036 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1037 const int32_t tex_width = 32;
1038 const int32_t tex_height = 32;
1039
1040 VkImageCreateInfo image_create_info = {};
1041 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1042 image_create_info.pNext = NULL;
1043 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1044 image_create_info.format = tex_format;
1045 image_create_info.extent.width = tex_width;
1046 image_create_info.extent.height = tex_height;
1047 image_create_info.extent.depth = 1;
1048 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06001049 image_create_info.arrayLayers = 1;
Tobin Ehlisec598302015-09-15 15:02:17 -06001050 image_create_info.samples = 1;
1051 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1052 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1053 image_create_info.flags = 0;
1054
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001055 VkMemoryAllocateInfo mem_alloc = {};
Tobin Ehlisec598302015-09-15 15:02:17 -06001056 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1057 mem_alloc.pNext = NULL;
1058 mem_alloc.allocationSize = 0;
1059 mem_alloc.memoryTypeIndex = 0;
1060
Chia-I Wuf7458c52015-10-26 21:10:41 +08001061 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06001062 ASSERT_VK_SUCCESS(err);
1063
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001064 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlisec598302015-09-15 15:02:17 -06001065 image,
1066 &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06001067
1068 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001069 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1070 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001071
1072 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001073 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001074 ASSERT_VK_SUCCESS(err);
1075
1076 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001077 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001078 ASSERT_VK_SUCCESS(err);
1079
1080 // Now Try to bind memory to this destroyed object
1081 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1082 // This may very well return an error.
1083 (void) err;
1084
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001085 if (!m_errorMonitor->DesiredMsgFound()) {
1086 FAIL() << "Did not receive Error 'Invalid VkImage Object 0x<handle>'";
1087 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001088 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001089
Chia-I Wuf7458c52015-10-26 21:10:41 +08001090 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001091}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001092
1093TEST_F(VkLayerTest, InvalidBufferViewObject)
1094{
1095 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001096 VkResult err;
1097
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001098 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1099 "Invalid VkBufferView Object 0xbaadbeef");
1100
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001101 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001102 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001103 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001104 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001105
1106 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1107 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1108 ds_pool_ci.pNext = NULL;
1109 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001110 ds_pool_ci.poolSizeCount = 1;
1111 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001112
1113 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001114 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001115 ASSERT_VK_SUCCESS(err);
1116
1117 VkDescriptorSetLayoutBinding dsl_binding = {};
1118 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1119 dsl_binding.arraySize = 1;
1120 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1121 dsl_binding.pImmutableSamplers = NULL;
1122
1123 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1124 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1125 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001126 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001127 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001128 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001129 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001130 ASSERT_VK_SUCCESS(err);
1131
1132 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001133 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001134 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001135 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001136 alloc_info.descriptorPool = ds_pool;
1137 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001138 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001139 ASSERT_VK_SUCCESS(err);
1140
Chia-I Wue2fc5522015-10-26 20:04:44 +08001141 VkBufferView view = (VkBufferView) 0xbaadbeef; // invalid bufferView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001142
1143 VkWriteDescriptorSet descriptor_write;
1144 memset(&descriptor_write, 0, sizeof(descriptor_write));
1145 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001146 descriptor_write.dstSet = descriptorSet;
1147 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001148 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001149 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1150 descriptor_write.pTexelBufferView = &view;
1151
1152 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1153
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001154 if (!m_errorMonitor->DesiredMsgFound()) {
1155 FAIL() << "Did nto receive Error 'Invalid VkBufferView Object 0xbaadbeef'";
1156 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001157 }
1158
Chia-I Wuf7458c52015-10-26 21:10:41 +08001159 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1160 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001161}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001162#endif // OBJ_TRACKER_TESTS
1163
Tobin Ehlis0788f522015-05-26 16:11:58 -06001164#if DRAW_STATE_TESTS
Tobin Ehlis963a4042015-09-29 08:18:34 -06001165TEST_F(VkLayerTest, LineWidthStateNotBound)
1166{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001167 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1168 "Dynamic line width state not set for this command buffer");
1169
Tobin Ehlis963a4042015-09-29 08:18:34 -06001170 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1171
1172 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1173
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001174 if (!m_errorMonitor->DesiredMsgFound()) {
1175 FAIL() << "Did not receive Error 'Dynamic line width state not set for this command buffer'";
1176 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001177 }
1178}
1179
1180TEST_F(VkLayerTest, DepthBiasStateNotBound)
1181{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001182 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1183 "Dynamic depth bias state not set for this command buffer");
1184
Tobin Ehlis963a4042015-09-29 08:18:34 -06001185 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1186
1187 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1188
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001189 if (!m_errorMonitor->DesiredMsgFound()) {
1190 FAIL() << "Did not receive Error 'Dynamic depth bias state not set for this command buffer'";
1191 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001192 }
1193}
1194
Cody Northrop4063c9a2015-10-27 16:54:28 -06001195// Disable these two tests until we can sort out how to track multiple layer errors
Tobin Ehlis963a4042015-09-29 08:18:34 -06001196TEST_F(VkLayerTest, ViewportStateNotBound)
1197{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001198 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1199 "Dynamic viewport state not set for this command buffer");
1200
Tobin Ehlis963a4042015-09-29 08:18:34 -06001201 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1202
1203 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1204
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001205 if (!m_errorMonitor->DesiredMsgFound()) {
1206 FAIL() << "Did not recieve Error 'Dynamic scissor state not set for this command buffer'";
1207 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001208 }
1209}
1210
1211TEST_F(VkLayerTest, ScissorStateNotBound)
1212{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001213 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1214 "Dynamic scissor state not set for this command buffer");
1215
Tobin Ehlis963a4042015-09-29 08:18:34 -06001216 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1217
1218 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1219
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001220 if (!m_errorMonitor->DesiredMsgFound()) {
1221 FAIL() << "Did not recieve Error ' Expected: 'Dynamic scissor state not set for this command buffer'";
1222 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001223 }
1224}
1225
Tobin Ehlis963a4042015-09-29 08:18:34 -06001226TEST_F(VkLayerTest, BlendStateNotBound)
1227{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001228 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1229 "Dynamic blend object state not set for this command buffer");
1230
Tobin Ehlis963a4042015-09-29 08:18:34 -06001231 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1232
1233 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1234
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001235 if (!m_errorMonitor->DesiredMsgFound()) {
1236 FAIL() << "Did not recieve Error 'Dynamic blend object state not set for this command buffer'";
1237 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001238 }
1239}
1240
1241TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1242{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001243 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1244 "Dynamic depth bounds state not set for this command buffer");
1245
Tobin Ehlis963a4042015-09-29 08:18:34 -06001246 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1247
1248 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1249
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001250 if (!m_errorMonitor->DesiredMsgFound()) {
1251 FAIL() << "Did not receive Error 'Dynamic depth bounds state not set for this command buffer'";
1252 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001253 }
1254}
1255
1256TEST_F(VkLayerTest, StencilReadMaskNotSet)
1257{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001258 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1259 "Dynamic stencil read mask state not set for this command buffer");
1260
Tobin Ehlis963a4042015-09-29 08:18:34 -06001261 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001262
Tobin Ehlis963a4042015-09-29 08:18:34 -06001263 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1264
1265 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1266
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001267 if (!m_errorMonitor->DesiredMsgFound()) {
1268 FAIL() << "Did not receive Error 'Dynamic stencil read mask state not set for this command buffer'";
1269 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001270 }
1271}
1272
1273TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1274{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001275 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1276 "Dynamic stencil write mask state not set for this command buffer");
1277
Tobin Ehlis963a4042015-09-29 08:18:34 -06001278 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001279
Tobin Ehlis963a4042015-09-29 08:18:34 -06001280 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1281
1282 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1283
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001284 if (!m_errorMonitor->DesiredMsgFound()) {
1285 FAIL() << "Did not receive Error 'Dynamic stencil write mask state not set for this command buffer'";
1286 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001287 }
1288}
1289
1290TEST_F(VkLayerTest, StencilReferenceNotSet)
1291{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001292 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1293 "Dynamic stencil reference state not set for this command buffer");
1294
Tobin Ehlis963a4042015-09-29 08:18:34 -06001295 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1296
1297 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1298
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001299 if (!m_errorMonitor->DesiredMsgFound()) {
1300 FAIL() << "Did not receive Error 'Dynamic stencil reference state not set for this command buffer'";
1301 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001302 }
1303}
1304
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001305TEST_F(VkLayerTest, CommandBufferTwoSubmits)
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001306{
1307 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001308
1309 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1310 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001311
1312 VkFenceCreateInfo fenceInfo = {};
1313 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1314 fenceInfo.pNext = NULL;
1315 fenceInfo.flags = 0;
1316
1317 ASSERT_NO_FATAL_FAILURE(InitState());
1318 ASSERT_NO_FATAL_FAILURE(InitViewport());
1319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1320
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001321 // We luck out b/c by default the framework creates CB w/ the VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001322 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001323 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001324 EndCommandBuffer();
1325
1326 testFence.init(*m_device, fenceInfo);
1327
1328 // Bypass framework since it does the waits automatically
1329 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001330 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001331 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1332 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001333 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001334 submit_info.pWaitSemaphores = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001335 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001336 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001337 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001338 submit_info.pSignalSemaphores = NULL;
1339
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001340 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001341 ASSERT_VK_SUCCESS( err );
1342
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001343 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001344 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001345
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001346 if (!m_errorMonitor->DesiredMsgFound()) {
1347 FAIL() << "Did not receive Error 'CB (0xaddress) was created w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
1348 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001349 }
1350}
1351
Tobin Ehlis502480b2015-06-24 15:53:07 -06001352TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001353{
1354 // Initiate Draw w/o a PSO bound
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001355 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001356
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001357 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1358 "Incorrectly binding graphics pipeline ");
1359
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001360 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001362
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001363 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001364 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001365 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001366
1367 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1368 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1369 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001370 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001371 ds_pool_ci.poolSizeCount = 1;
1372 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001373
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001374 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001375 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001376 ASSERT_VK_SUCCESS(err);
1377
1378 VkDescriptorSetLayoutBinding dsl_binding = {};
1379 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1380 dsl_binding.arraySize = 1;
1381 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1382 dsl_binding.pImmutableSamplers = NULL;
1383
1384 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1385 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1386 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001387 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001388 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001389
1390 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001391 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001392 ASSERT_VK_SUCCESS(err);
1393
1394 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001395 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001396 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001397 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001398 alloc_info.descriptorPool = ds_pool;
1399 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001400 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001401 ASSERT_VK_SUCCESS(err);
1402 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1403 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1404 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001405 pipe_ms_state_ci.rasterizationSamples = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001406 pipe_ms_state_ci.sampleShadingEnable = 0;
1407 pipe_ms_state_ci.minSampleShading = 1.0;
1408 pipe_ms_state_ci.pSampleMask = NULL;
1409
1410 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1411 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1412 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001413 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001414 pipeline_layout_ci.pSetLayouts = &ds_layout;
1415 VkPipelineLayout pipeline_layout;
1416
Chia-I Wuf7458c52015-10-26 21:10:41 +08001417 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001418 ASSERT_VK_SUCCESS(err);
1419
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001420 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1421 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001422 // but add it to be able to run on more devices
1423 VkPipelineObj pipe(m_device);
1424 pipe.AddShader(&vs);
1425 pipe.AddShader(&fs);
1426 pipe.SetMSAA(&pipe_ms_state_ci);
1427 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001428
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001429 // Calls AllocateCommandBuffers
1430 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
1431 VkCommandBufferBeginInfo cmd_buf_info = {};
1432 memset(&cmd_buf_info, 0, sizeof(VkCommandBufferBeginInfo));
1433 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001434 cmd_buf_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001435 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001436
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001437 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
1438 vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001439
1440 if (!m_errorMonitor->DesiredMsgFound()) {
1441 FAIL() << "Did not receive Error 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass'";
1442 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001443 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001444
Chia-I Wuf7458c52015-10-26 21:10:41 +08001445 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1446 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1447 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001448}
1449
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001450TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1451{
1452 // Initiate Draw w/o a PSO bound
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001453 VkResult err;
1454
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001455 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1456 "Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
1457
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001458 ASSERT_NO_FATAL_FAILURE(InitState());
1459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001460
1461 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001462 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001463 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001464 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001465
1466 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1467 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1468 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001469 ds_pool_ci.flags = 0;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001470 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001471 ds_pool_ci.poolSizeCount = 1;
1472 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001473
1474 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001475 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001476 ASSERT_VK_SUCCESS(err);
1477
1478 VkDescriptorSetLayoutBinding dsl_binding = {};
1479 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1480 dsl_binding.arraySize = 1;
1481 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1482 dsl_binding.pImmutableSamplers = NULL;
1483
1484 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1485 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1486 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001487 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001488 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001489
1490 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001491 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001492 ASSERT_VK_SUCCESS(err);
1493
1494 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001495 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001496 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001497 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001498 alloc_info.descriptorPool = ds_pool;
1499 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001500 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001501
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001502 if (!m_errorMonitor->DesiredMsgFound()) {
1503 FAIL() << "Did not receive Error 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...'";
1504 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001505 }
1506
Chia-I Wuf7458c52015-10-26 21:10:41 +08001507 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1508 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001509}
1510
Tobin Ehlise735c692015-10-08 13:13:50 -06001511TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1512{
Tobin Ehlise735c692015-10-08 13:13:50 -06001513 VkResult err;
1514
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001515 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1516 "It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
1517
Tobin Ehlise735c692015-10-08 13:13:50 -06001518 ASSERT_NO_FATAL_FAILURE(InitState());
1519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06001520
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001521 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise735c692015-10-08 13:13:50 -06001522 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001523 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06001524
1525 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1526 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1527 ds_pool_ci.pNext = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06001528 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001529 ds_pool_ci.poolSizeCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001530 ds_pool_ci.flags = 0;
1531 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1532 // app can only call vkResetDescriptorPool on this pool.;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001533 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06001534
1535 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001536 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06001537 ASSERT_VK_SUCCESS(err);
1538
1539 VkDescriptorSetLayoutBinding dsl_binding = {};
1540 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1541 dsl_binding.arraySize = 1;
1542 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1543 dsl_binding.pImmutableSamplers = NULL;
1544
1545 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1546 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1547 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001548 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001549 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06001550
1551 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001552 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06001553 ASSERT_VK_SUCCESS(err);
1554
1555 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001556 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001557 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001558 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001559 alloc_info.descriptorPool = ds_pool;
1560 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001561 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06001562 ASSERT_VK_SUCCESS(err);
1563
1564 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001565 if (!m_errorMonitor->DesiredMsgFound()) {
1566 FAIL() << "Did not receive Error 'It is invalid to call vkFreeDescriptorSets() with a pool created with...'";
1567 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise735c692015-10-08 13:13:50 -06001568 }
1569
Chia-I Wuf7458c52015-10-26 21:10:41 +08001570 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1571 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06001572}
1573
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001574TEST_F(VkLayerTest, InvalidDescriptorPool)
1575{
1576 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1577 // The DS check for this is after driver has been called to validate DS internal data struct
1578 // Attempt to clear DS Pool with bad object
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001579/*
1580 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1581 "Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call");
1582
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001583 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1584 vkResetDescriptorPool(device(), badPool);
1585
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001586 if (!m_errorMonitor->DesiredMsgFound()) {
1587 FAIL() << "Did not receive Error 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1588 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001589 }*/
1590}
1591
1592TEST_F(VkLayerTest, InvalidDescriptorSet)
1593{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001594 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1595 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001596 // Create a valid cmd buffer
1597 // call vkCmdBindDescriptorSets w/ false DS
1598}
1599
1600TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1601{
1602 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1603 // The DS check for this is after driver has been called to validate DS internal data struct
1604}
1605
1606TEST_F(VkLayerTest, InvalidPipeline)
1607{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001608 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1609 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001610 // Create a valid cmd buffer
1611 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001612//
1613// m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1614// "Attempt to bind Pipeline ");
Tobin Ehlis502480b2015-06-24 15:53:07 -06001615//
1616// ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001617// VkCommandBufferObj commandBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001618// BeginCommandBuffer();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001619// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001620// vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001621//
1622// if (!m_errorMonitor->DesiredMsgFound()) {
1623// FAIL() << "Did not receive Error 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1624// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001625// }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001626}
1627
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001628TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001629{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001630 // Create and update CommandBuffer then call QueueSubmit w/o calling End on CommandBuffer
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001631 VkResult err;
1632
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001633 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
1634 " bound but it was never updated. ");
1635
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001636 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06001637 ASSERT_NO_FATAL_FAILURE(InitViewport());
1638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001639 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06001640 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001641 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001642
1643 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1644 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1645 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001646 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001647 ds_pool_ci.poolSizeCount = 1;
1648 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06001649
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001650 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001651 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001652 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001653
Tony Barboureb254902015-07-15 12:50:33 -06001654 VkDescriptorSetLayoutBinding dsl_binding = {};
1655 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1656 dsl_binding.arraySize = 1;
1657 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1658 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001659
Tony Barboureb254902015-07-15 12:50:33 -06001660 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1661 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1662 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001663 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001664 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001665 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001666 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001667 ASSERT_VK_SUCCESS(err);
1668
1669 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001670 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001671 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001672 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001673 alloc_info.descriptorPool = ds_pool;
1674 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001675 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001676 ASSERT_VK_SUCCESS(err);
1677
Tony Barboureb254902015-07-15 12:50:33 -06001678 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1679 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1680 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001681 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001682 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001683
1684 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001685 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001686 ASSERT_VK_SUCCESS(err);
1687
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001688 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001689 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
1690 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001691
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001692 VkPipelineObj pipe(m_device);
1693 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06001694 pipe.AddShader(&fs);
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001695 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001696
1697 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001698 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1699 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001700
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001701 if (!m_errorMonitor->DesiredMsgFound()) {
1702 FAIL() << "Did not recieve Warning 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1703 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001704 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001705
Chia-I Wuf7458c52015-10-26 21:10:41 +08001706 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1707 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1708 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001709}
1710
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001711TEST_F(VkLayerTest, NoBeginCommandBuffer)
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001712{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001713
1714 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1715 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001716
1717 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001718 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001719 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001720 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001721
1722 if (!m_errorMonitor->DesiredMsgFound()) {
1723 FAIL() << "Did not recieve Error 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1724 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001725 }
1726}
1727
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001728TEST_F(VkLayerTest, PrimaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001729{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001730
1731 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1732 "may not specify framebuffer or renderpass parameters");
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001733
1734 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001735
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001736 // Calls AllocateCommandBuffers
1737 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001738
1739 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001740 VkCommandBufferBeginInfo cmd_buf_info = {};
1741 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06001742 cmd_buf_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001743 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northropb4569702015-08-04 17:35:57 -06001744 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1745 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1746
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001747
1748 // The error should be caught by validation of the BeginCommandBuffer call
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001749 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001750
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001751 if (!m_errorMonitor->DesiredMsgFound()) {
1752 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1753 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001754 }
1755}
1756
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001757TEST_F(VkLayerTest, SecondaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001758{
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001759 VkResult err;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001760 VkCommandBuffer draw_cmd;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001761
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001762 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1763 "must specify framebuffer and renderpass parameters");
1764
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001765 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001766
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001767 VkCommandBufferAllocateInfo cmd = {};
1768 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOC_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06001769 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001770 cmd.commandPool = m_commandPool;
1771 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001772 cmd.bufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06001773
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001774 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06001775 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001776
1777 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001778 VkCommandBufferBeginInfo cmd_buf_info = {};
1779 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06001780 cmd_buf_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001781 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001782
1783 // The error should be caught by validation of the BeginCommandBuffer call
1784 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1785
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001786 if (!m_errorMonitor->DesiredMsgFound()) {
1787 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1788 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001789 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001790 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001791}
1792
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001793TEST_F(VkLayerTest, InvalidPipelineCreateState)
1794{
1795 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001796 VkResult err;
1797
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001798 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1799 "Invalid Pipeline CreateInfo State: Vtx Shader required");
1800
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001801 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001802 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001803
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001804 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06001805 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001806 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001807
1808 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1809 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1810 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001811 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001812 ds_pool_ci.poolSizeCount = 1;
1813 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001814
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001815 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001816 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001817 ASSERT_VK_SUCCESS(err);
1818
Tony Barboureb254902015-07-15 12:50:33 -06001819 VkDescriptorSetLayoutBinding dsl_binding = {};
1820 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1821 dsl_binding.arraySize = 1;
1822 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1823 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001824
Tony Barboureb254902015-07-15 12:50:33 -06001825 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1826 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1827 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001828 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001829 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06001830
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001831 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001832 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001833 ASSERT_VK_SUCCESS(err);
1834
1835 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001836 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001837 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001838 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001839 alloc_info.descriptorPool = ds_pool;
1840 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001841 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001842 ASSERT_VK_SUCCESS(err);
1843
Tony Barboureb254902015-07-15 12:50:33 -06001844 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1845 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001846 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001847 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001848
1849 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001850 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001851 ASSERT_VK_SUCCESS(err);
1852
Tobin Ehlise68360f2015-10-01 11:15:13 -06001853 VkViewport vp = {}; // Just need dummy vp to point to
1854 VkRect2D sc = {}; // dummy scissor to point to
1855
1856 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1857 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1858 vp_state_ci.scissorCount = 1;
1859 vp_state_ci.pScissors = &sc;
1860 vp_state_ci.viewportCount = 1;
1861 vp_state_ci.pViewports = &vp;
1862
Tony Barboureb254902015-07-15 12:50:33 -06001863 VkGraphicsPipelineCreateInfo gp_ci = {};
1864 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06001865 gp_ci.pViewportState = &vp_state_ci;
Tony Barboureb254902015-07-15 12:50:33 -06001866 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1867 gp_ci.layout = pipeline_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001868 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06001869
1870 VkPipelineCacheCreateInfo pc_ci = {};
1871 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001872 pc_ci.initialDataSize = 0;
1873 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001874
1875 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06001876 VkPipelineCache pipelineCache;
1877
Chia-I Wuf7458c52015-10-26 21:10:41 +08001878 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06001879 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08001880 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001881
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001882 if (!m_errorMonitor->DesiredMsgFound()) {
1883 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1884 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001885 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001886
Chia-I Wuf7458c52015-10-26 21:10:41 +08001887 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
1888 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1889 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1890 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001891}
Tobin Ehlis912df022015-09-17 08:46:18 -06001892/*// TODO : This test should be good, but needs Tess support in compiler to run
1893TEST_F(VkLayerTest, InvalidPatchControlPoints)
1894{
1895 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06001896 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001897
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001898 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1899 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ");
1900
Tobin Ehlis912df022015-09-17 08:46:18 -06001901 ASSERT_NO_FATAL_FAILURE(InitState());
1902 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06001903
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001904 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06001905 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001906 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06001907
1908 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1909 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1910 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001911 ds_pool_ci.poolSizeCount = 1;
1912 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06001913
1914 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001915 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06001916 ASSERT_VK_SUCCESS(err);
1917
1918 VkDescriptorSetLayoutBinding dsl_binding = {};
1919 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1920 dsl_binding.arraySize = 1;
1921 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1922 dsl_binding.pImmutableSamplers = NULL;
1923
1924 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1925 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1926 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001927 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001928 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06001929
1930 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001931 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06001932 ASSERT_VK_SUCCESS(err);
1933
1934 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001935 err = vkAllocateDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06001936 ASSERT_VK_SUCCESS(err);
1937
1938 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1939 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1940 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001941 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06001942 pipeline_layout_ci.pSetLayouts = &ds_layout;
1943
1944 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001945 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06001946 ASSERT_VK_SUCCESS(err);
1947
1948 VkPipelineShaderStageCreateInfo shaderStages[3];
1949 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1950
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001951 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06001952 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001953 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
1954 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06001955
1956 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001957 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001958 shaderStages[0].shader = vs.handle();
1959 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001960 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001961 shaderStages[1].shader = tc.handle();
1962 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001963 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001964 shaderStages[2].shader = te.handle();
1965
1966 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1967 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1968 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1969
1970 VkPipelineTessellationStateCreateInfo tsCI = {};
1971 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1972 tsCI.patchControlPoints = 0; // This will cause an error
1973
1974 VkGraphicsPipelineCreateInfo gp_ci = {};
1975 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1976 gp_ci.pNext = NULL;
1977 gp_ci.stageCount = 3;
1978 gp_ci.pStages = shaderStages;
1979 gp_ci.pVertexInputState = NULL;
1980 gp_ci.pInputAssemblyState = &iaCI;
1981 gp_ci.pTessellationState = &tsCI;
1982 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001983 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06001984 gp_ci.pMultisampleState = NULL;
1985 gp_ci.pDepthStencilState = NULL;
1986 gp_ci.pColorBlendState = NULL;
1987 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1988 gp_ci.layout = pipeline_layout;
1989 gp_ci.renderPass = renderPass();
1990
1991 VkPipelineCacheCreateInfo pc_ci = {};
1992 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1993 pc_ci.pNext = NULL;
1994 pc_ci.initialSize = 0;
1995 pc_ci.initialData = 0;
1996 pc_ci.maxSize = 0;
1997
1998 VkPipeline pipeline;
1999 VkPipelineCache pipelineCache;
2000
Chia-I Wuf7458c52015-10-26 21:10:41 +08002001 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06002002 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002003 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06002004
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002005 if (!m_errorMonitor->DesiredMsgFound()) {
2006 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...'";
2007 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis912df022015-09-17 08:46:18 -06002008 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002009
Chia-I Wuf7458c52015-10-26 21:10:41 +08002010 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2011 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2012 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2013 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06002014}
2015*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06002016// Set scissor and viewport counts to different numbers
2017TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2018{
2019 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlise68360f2015-10-01 11:15:13 -06002020 VkResult err;
2021
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002022 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2023 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2024
Tobin Ehlise68360f2015-10-01 11:15:13 -06002025 ASSERT_NO_FATAL_FAILURE(InitState());
2026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002027
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002028 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002029 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002030 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002031
2032 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2033 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002034 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002035 ds_pool_ci.poolSizeCount = 1;
2036 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002037
2038 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002039 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002040 ASSERT_VK_SUCCESS(err);
2041
2042 VkDescriptorSetLayoutBinding dsl_binding = {};
2043 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2044 dsl_binding.arraySize = 1;
2045 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2046
2047 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2048 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002049 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002050 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002051
2052 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002053 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002054 ASSERT_VK_SUCCESS(err);
2055
2056 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002057 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002058 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002059 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002060 alloc_info.descriptorPool = ds_pool;
2061 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002062 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002063 ASSERT_VK_SUCCESS(err);
2064
2065 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2066 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002067 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002068 pipeline_layout_ci.pSetLayouts = &ds_layout;
2069
2070 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002071 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002072 ASSERT_VK_SUCCESS(err);
2073
2074 VkViewport vp = {}; // Just need dummy vp to point to
2075
2076 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2077 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2078 vp_state_ci.scissorCount = 0;
2079 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2080 vp_state_ci.pViewports = &vp;
2081
Cody Northropeb3a6c12015-10-05 14:44:45 -06002082 VkPipelineShaderStageCreateInfo shaderStages[2];
2083 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002084
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002085 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2086 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northropeb3a6c12015-10-05 14:44:45 -06002087 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002088 shaderStages[0] = vs.GetStageCreateInfo();
2089 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002090
2091 VkGraphicsPipelineCreateInfo gp_ci = {};
2092 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002093 gp_ci.stageCount = 2;
2094 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002095 gp_ci.pViewportState = &vp_state_ci;
2096 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2097 gp_ci.layout = pipeline_layout;
2098 gp_ci.renderPass = renderPass();
2099
2100 VkPipelineCacheCreateInfo pc_ci = {};
2101 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2102
2103 VkPipeline pipeline;
2104 VkPipelineCache pipelineCache;
2105
Chia-I Wuf7458c52015-10-26 21:10:41 +08002106 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002107 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002108 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002110 if (!m_errorMonitor->DesiredMsgFound()) {
2111 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must match scissor count (0).'";
2112 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002113 }
2114
Chia-I Wuf7458c52015-10-26 21:10:41 +08002115 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2116 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2117 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2118 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002119}
Tobin Ehlisd332f282015-10-02 11:00:56 -06002120// Don't set viewport state in PSO. This is an error b/c we always need this state
2121// for the counts even if the data is going to be set dynamically.
2122TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002123{
2124 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlise68360f2015-10-01 11:15:13 -06002125 VkResult err;
2126
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002127 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2128 "Gfx Pipeline pViewportState is null. Even if ");
2129
Tobin Ehlise68360f2015-10-01 11:15:13 -06002130 ASSERT_NO_FATAL_FAILURE(InitState());
2131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002132
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002133 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002134 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002135 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002136
2137 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2138 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002139 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002140 ds_pool_ci.poolSizeCount = 1;
2141 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002142
2143 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002144 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002145 ASSERT_VK_SUCCESS(err);
2146
2147 VkDescriptorSetLayoutBinding dsl_binding = {};
2148 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2149 dsl_binding.arraySize = 1;
2150 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2151
2152 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2153 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002154 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002155 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002156
2157 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002158 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002159 ASSERT_VK_SUCCESS(err);
2160
2161 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002162 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002163 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002164 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002165 alloc_info.descriptorPool = ds_pool;
2166 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002167 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002168 ASSERT_VK_SUCCESS(err);
2169
2170 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2171 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002172 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002173 pipeline_layout_ci.pSetLayouts = &ds_layout;
2174
2175 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002176 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002177 ASSERT_VK_SUCCESS(err);
2178
2179 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2180 // Set scissor as dynamic to avoid second error
2181 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2182 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2183 dyn_state_ci.dynamicStateCount = 1;
2184 dyn_state_ci.pDynamicStates = &sc_state;
2185
Cody Northropeb3a6c12015-10-05 14:44:45 -06002186 VkPipelineShaderStageCreateInfo shaderStages[2];
2187 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002188
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002189 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2190 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 -06002191 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002192 shaderStages[0] = vs.GetStageCreateInfo();
2193 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002194
2195 VkGraphicsPipelineCreateInfo gp_ci = {};
2196 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002197 gp_ci.stageCount = 2;
2198 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002199 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2200 gp_ci.pDynamicState = &dyn_state_ci;
2201 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2202 gp_ci.layout = pipeline_layout;
2203 gp_ci.renderPass = renderPass();
2204
2205 VkPipelineCacheCreateInfo pc_ci = {};
2206 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2207
2208 VkPipeline pipeline;
2209 VkPipelineCache pipelineCache;
2210
Chia-I Wuf7458c52015-10-26 21:10:41 +08002211 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002212 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002213 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002214
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002215 if (!m_errorMonitor->DesiredMsgFound()) {
2216 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. Even if...'";
2217 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002218 }
2219
Chia-I Wuf7458c52015-10-26 21:10:41 +08002220 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2221 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2222 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2223 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002224}
2225// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002226// Then run second test where dynamic scissor count doesn't match PSO scissor count
2227TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002228{
Tobin Ehlise68360f2015-10-01 11:15:13 -06002229 VkResult err;
2230
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002231 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2232 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
2233
Tobin Ehlise68360f2015-10-01 11:15:13 -06002234 ASSERT_NO_FATAL_FAILURE(InitState());
2235 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002236
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002237 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002238 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002239 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002240
2241 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2242 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002243 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002244 ds_pool_ci.poolSizeCount = 1;
2245 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002246
2247 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002248 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002249 ASSERT_VK_SUCCESS(err);
2250
2251 VkDescriptorSetLayoutBinding dsl_binding = {};
2252 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2253 dsl_binding.arraySize = 1;
2254 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2255
2256 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2257 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002258 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002259 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002260
2261 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002262 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002263 ASSERT_VK_SUCCESS(err);
2264
2265 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002266 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002267 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002268 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002269 alloc_info.descriptorPool = ds_pool;
2270 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002271 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002272 ASSERT_VK_SUCCESS(err);
2273
2274 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2275 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002276 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002277 pipeline_layout_ci.pSetLayouts = &ds_layout;
2278
2279 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002280 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002281 ASSERT_VK_SUCCESS(err);
2282
2283 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2284 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2285 vp_state_ci.viewportCount = 1;
2286 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2287 vp_state_ci.scissorCount = 1;
2288 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2289
2290 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2291 // Set scissor as dynamic to avoid that error
2292 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2293 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2294 dyn_state_ci.dynamicStateCount = 1;
2295 dyn_state_ci.pDynamicStates = &sc_state;
2296
Cody Northropeb3a6c12015-10-05 14:44:45 -06002297 VkPipelineShaderStageCreateInfo shaderStages[2];
2298 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002299
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002300 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2301 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 -06002302 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002303 shaderStages[0] = vs.GetStageCreateInfo();
2304 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002305
Cody Northropf6622dc2015-10-06 10:33:21 -06002306 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2307 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2308 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002309 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002310 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002311 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002312 vi_ci.pVertexAttributeDescriptions = nullptr;
2313
2314 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2315 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2316 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2317
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002318 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002319 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06002320 rs_ci.pNext = nullptr;
2321
2322 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2323 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2324 cb_ci.pNext = nullptr;
2325
Tobin Ehlise68360f2015-10-01 11:15:13 -06002326 VkGraphicsPipelineCreateInfo gp_ci = {};
2327 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002328 gp_ci.stageCount = 2;
2329 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06002330 gp_ci.pVertexInputState = &vi_ci;
2331 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002332 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002333 gp_ci.pRasterizationState = &rs_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06002334 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002335 gp_ci.pDynamicState = &dyn_state_ci;
2336 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2337 gp_ci.layout = pipeline_layout;
2338 gp_ci.renderPass = renderPass();
2339
2340 VkPipelineCacheCreateInfo pc_ci = {};
2341 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2342
2343 VkPipeline pipeline;
2344 VkPipelineCache pipelineCache;
2345
Chia-I Wuf7458c52015-10-26 21:10:41 +08002346 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002347 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002348 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002349
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002350 if (!m_errorMonitor->DesiredMsgFound()) {
2351 FAIL() << "Did not recieve Error 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...'";
2352 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002353 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002354
2355
Tobin Ehlisd332f282015-10-02 11:00:56 -06002356 // Now hit second fail case where we set scissor w/ different count than PSO
2357 // First need to successfully create the PSO from above by setting pViewports
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002358 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2359 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.");
2360
Tobin Ehlisd332f282015-10-02 11:00:56 -06002361 VkViewport vp = {}; // Just need dummy vp to point to
2362 vp_state_ci.pViewports = &vp;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002363 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002364 ASSERT_VK_SUCCESS(err);
2365 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002366 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002367 VkRect2D scissors[2] = {}; // don't care about data
2368 // Count of 2 doesn't match PSO count of 1
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002369 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 2, scissors);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002370 Draw(1, 0, 0, 0);
2371
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002372 if (!m_errorMonitor->DesiredMsgFound()) {
2373 FAIL() << "Did not receive Error 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
2374 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd332f282015-10-02 11:00:56 -06002375 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06002376
Chia-I Wuf7458c52015-10-26 21:10:41 +08002377 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2378 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2379 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2380 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002381}
2382// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002383// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2384TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002385{
Tobin Ehlise68360f2015-10-01 11:15:13 -06002386 VkResult err;
2387
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002388 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2389 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
2390
Tobin Ehlise68360f2015-10-01 11:15:13 -06002391 ASSERT_NO_FATAL_FAILURE(InitState());
2392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002393
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002394 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002395 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002396 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002397
2398 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2399 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002400 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002401 ds_pool_ci.poolSizeCount = 1;
2402 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002403
2404 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002405 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002406 ASSERT_VK_SUCCESS(err);
2407
2408 VkDescriptorSetLayoutBinding dsl_binding = {};
2409 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2410 dsl_binding.arraySize = 1;
2411 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2412
2413 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2414 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002415 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002416 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002417
2418 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002419 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002420 ASSERT_VK_SUCCESS(err);
2421
2422 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002423 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002424 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002425 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002426 alloc_info.descriptorPool = ds_pool;
2427 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002428 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002429 ASSERT_VK_SUCCESS(err);
2430
2431 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2432 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002433 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002434 pipeline_layout_ci.pSetLayouts = &ds_layout;
2435
2436 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002437 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002438 ASSERT_VK_SUCCESS(err);
2439
2440 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2441 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2442 vp_state_ci.scissorCount = 1;
2443 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2444 vp_state_ci.viewportCount = 1;
2445 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2446
2447 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2448 // Set scissor as dynamic to avoid that error
2449 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2450 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2451 dyn_state_ci.dynamicStateCount = 1;
2452 dyn_state_ci.pDynamicStates = &vp_state;
2453
Cody Northropeb3a6c12015-10-05 14:44:45 -06002454 VkPipelineShaderStageCreateInfo shaderStages[2];
2455 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002456
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002457 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2458 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 -06002459 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002460 shaderStages[0] = vs.GetStageCreateInfo();
2461 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002462
Cody Northropf6622dc2015-10-06 10:33:21 -06002463 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2464 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2465 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002466 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002467 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002468 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002469 vi_ci.pVertexAttributeDescriptions = nullptr;
2470
2471 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2472 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2473 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2474
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002475 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002476 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06002477 rs_ci.pNext = nullptr;
2478
2479 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2480 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2481 cb_ci.pNext = nullptr;
2482
Tobin Ehlise68360f2015-10-01 11:15:13 -06002483 VkGraphicsPipelineCreateInfo gp_ci = {};
2484 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002485 gp_ci.stageCount = 2;
2486 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06002487 gp_ci.pVertexInputState = &vi_ci;
2488 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002489 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002490 gp_ci.pRasterizationState = &rs_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06002491 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002492 gp_ci.pDynamicState = &dyn_state_ci;
2493 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2494 gp_ci.layout = pipeline_layout;
2495 gp_ci.renderPass = renderPass();
2496
2497 VkPipelineCacheCreateInfo pc_ci = {};
2498 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2499
2500 VkPipeline pipeline;
2501 VkPipelineCache pipelineCache;
2502
Chia-I Wuf7458c52015-10-26 21:10:41 +08002503 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002504 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002505 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002506
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002507 if (!m_errorMonitor->DesiredMsgFound()) {
2508 FAIL() << "Did not recieve Error 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...'";
2509 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002510 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002511
Tobin Ehlisd332f282015-10-02 11:00:56 -06002512 // Now hit second fail case where we set scissor w/ different count than PSO
2513 // First need to successfully create the PSO from above by setting pViewports
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002514 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2515 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.");
2516
Tobin Ehlisd332f282015-10-02 11:00:56 -06002517 VkRect2D sc = {}; // Just need dummy vp to point to
2518 vp_state_ci.pScissors = &sc;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002519 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002520 ASSERT_VK_SUCCESS(err);
2521 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002522 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002523 VkViewport viewports[2] = {}; // don't care about data
2524 // Count of 2 doesn't match PSO count of 1
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002525 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002526 Draw(1, 0, 0, 0);
2527
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002528 if (!m_errorMonitor->DesiredMsgFound()) {
2529 FAIL() << "Did not receive Error 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...'";
2530 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd332f282015-10-02 11:00:56 -06002531 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06002532
Chia-I Wuf7458c52015-10-26 21:10:41 +08002533 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2534 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2535 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2536 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002537}
2538
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002539TEST_F(VkLayerTest, NullRenderPass)
2540{
2541 // Bind a NULL RenderPass
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002542 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2543 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002544
2545 ASSERT_NO_FATAL_FAILURE(InitState());
2546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002547
Tony Barbourfe3351b2015-07-28 10:17:20 -06002548 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002549 // Don't care about RenderPass handle b/c error should be flagged before that
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002550 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002551
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002552 if (!m_errorMonitor->DesiredMsgFound()) {
2553 FAIL() << "Did not receive Error 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2554 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002555 }
2556}
2557
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002558TEST_F(VkLayerTest, RenderPassWithinRenderPass)
2559{
2560 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002561 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2562 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002563
2564 ASSERT_NO_FATAL_FAILURE(InitState());
2565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002566
Tony Barbourfe3351b2015-07-28 10:17:20 -06002567 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002568 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barboureb254902015-07-15 12:50:33 -06002569 VkRenderPassBeginInfo rp_begin = {};
2570 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
2571 rp_begin.pNext = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002572 rp_begin.renderPass = renderPass();
2573 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002574
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002575 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002576
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002577 if (!m_errorMonitor->DesiredMsgFound()) {
2578 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2579 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002580 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002581}
2582
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002583TEST_F(VkLayerTest, FillBufferWithinRenderPass)
2584{
2585 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002586 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2587 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002588
2589 ASSERT_NO_FATAL_FAILURE(InitState());
2590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002591
2592 // Renderpass is started here
2593 BeginCommandBuffer();
2594
2595 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002596 vk_testing::Buffer dstBuffer;
2597 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002598
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002599 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002600
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002601 if (!m_errorMonitor->DesiredMsgFound()) {
2602 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2603 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002604 }
2605}
2606
2607TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
2608{
2609 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002610 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2611 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002612
2613 ASSERT_NO_FATAL_FAILURE(InitState());
2614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002615
2616 // Renderpass is started here
2617 BeginCommandBuffer();
2618
2619 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002620 vk_testing::Buffer dstBuffer;
2621 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002622
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002623 VkDeviceSize dstOffset = 0;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002624 VkDeviceSize dataSize = 1024;
2625 const uint32_t *pData = NULL;
2626
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002627 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002628
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002629 if (!m_errorMonitor->DesiredMsgFound()) {
2630 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2631 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002632 }
2633}
2634
2635TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
2636{
2637 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002638 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2639 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002640
2641 ASSERT_NO_FATAL_FAILURE(InitState());
2642 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002643
2644 // Renderpass is started here
2645 BeginCommandBuffer();
2646
2647 VkClearColorValue clear_color = {0};
2648 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2649 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2650 const int32_t tex_width = 32;
2651 const int32_t tex_height = 32;
2652 VkImageCreateInfo image_create_info = {};
2653 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2654 image_create_info.pNext = NULL;
2655 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2656 image_create_info.format = tex_format;
2657 image_create_info.extent.width = tex_width;
2658 image_create_info.extent.height = tex_height;
2659 image_create_info.extent.depth = 1;
2660 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06002661 image_create_info.arrayLayers = 1;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002662 image_create_info.samples = 1;
2663 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2664 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2665
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002666 vk_testing::Image dstImage;
2667 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002668
2669 const VkImageSubresourceRange range =
2670 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
2671
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002672 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(),
2673 dstImage.handle(),
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002674 VK_IMAGE_LAYOUT_GENERAL,
2675 &clear_color,
2676 1,
2677 &range);
2678
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002679 if (!m_errorMonitor->DesiredMsgFound()) {
2680 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2681 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002682 }
2683}
2684
2685TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
2686{
2687 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002688 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2689 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002690
2691 ASSERT_NO_FATAL_FAILURE(InitState());
2692 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002693
2694 // Renderpass is started here
2695 BeginCommandBuffer();
2696
2697 VkClearDepthStencilValue clear_value = {0};
2698 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2699 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
2700 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2701 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
2702 image_create_info.extent.width = 64;
2703 image_create_info.extent.height = 64;
2704 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2705 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2706
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002707 vk_testing::Image dstImage;
2708 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002709
2710 const VkImageSubresourceRange range =
2711 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
2712
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002713 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(),
2714 dstImage.handle(),
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002715 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2716 &clear_value,
2717 1,
2718 &range);
2719
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002720 if (!m_errorMonitor->DesiredMsgFound()) {
2721 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2722 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002723 }
2724}
2725
2726TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
2727{
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002728 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002729 VkResult err;
2730
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002731 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2732 "vkCmdClearAttachments: This call must be issued inside an active render pass");
2733
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002734 ASSERT_NO_FATAL_FAILURE(InitState());
2735 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002736
2737 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002738 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002739 ASSERT_VK_SUCCESS(err);
2740
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002741 VkClearAttachment color_attachment;
2742 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2743 color_attachment.clearValue.color.float32[0] = 0;
2744 color_attachment.clearValue.color.float32[1] = 0;
2745 color_attachment.clearValue.color.float32[2] = 0;
2746 color_attachment.clearValue.color.float32[3] = 0;
2747 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06002748 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002749 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(),
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002750 1, &color_attachment,
2751 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002752
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002753 if (!m_errorMonitor->DesiredMsgFound()) {
2754 FAIL() << "Did not receive Error 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
2755 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002756 }
2757}
2758
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002759TEST_F(VkLayerTest, InvalidDynamicStateObject)
2760{
2761 // Create a valid cmd buffer
2762 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002763 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
2764 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002765}
Tobin Ehlis1056d452015-05-27 14:55:35 -06002766
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002767TEST_F(VkLayerTest, IdxBufferAlignmentError)
2768{
2769 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002770 VkResult err;
2771
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002772 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2773 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
2774
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002775 ASSERT_NO_FATAL_FAILURE(InitState());
2776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002777 uint32_t qfi = 0;
2778 VkBufferCreateInfo buffCI = {};
2779 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2780 buffCI.size = 1024;
2781 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002782 buffCI.queueFamilyIndexCount = 1;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002783 buffCI.pQueueFamilyIndices = &qfi;
2784
2785 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002786 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002787 ASSERT_VK_SUCCESS(err);
2788
2789 BeginCommandBuffer();
2790 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002791 //vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002792 // Should error before calling to driver so don't care about actual data
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002793 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002794
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002795 if (!m_errorMonitor->DesiredMsgFound()) {
2796 FAIL() << "Did not receive Error 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...'";
2797 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002798 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002799
Chia-I Wuf7458c52015-10-26 21:10:41 +08002800 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002801}
2802
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06002803TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2804{
2805 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002806
2807 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2808 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06002809
2810 ASSERT_NO_FATAL_FAILURE(InitState());
2811 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06002812
2813 BeginCommandBuffer();
2814 //ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002815 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
2816 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06002817
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002818 if (!m_errorMonitor->DesiredMsgFound()) {
2819 FAIL() << "Did not receive Error 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer '";
2820 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06002821 }
2822}
2823
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002824TEST_F(VkLayerTest, DSTypeMismatch)
2825{
2826 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Tobin Ehlis3b780662015-05-28 12:11:26 -06002827 VkResult err;
2828
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002829 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2830 "Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ");
2831
Tobin Ehlis3b780662015-05-28 12:11:26 -06002832 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06002833 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002834 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06002835 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002836 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002837
2838 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2839 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2840 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002841 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002842 ds_pool_ci.poolSizeCount = 1;
2843 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06002844
Tobin Ehlis3b780662015-05-28 12:11:26 -06002845 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002846 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002847 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06002848 VkDescriptorSetLayoutBinding dsl_binding = {};
2849 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2850 dsl_binding.arraySize = 1;
2851 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2852 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002853
Tony Barboureb254902015-07-15 12:50:33 -06002854 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2855 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2856 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002857 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002858 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06002859
Tobin Ehlis3b780662015-05-28 12:11:26 -06002860 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002862 ASSERT_VK_SUCCESS(err);
2863
2864 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002865 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002866 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002867 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002868 alloc_info.descriptorPool = ds_pool;
2869 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002871 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002872
Tony Barboureb254902015-07-15 12:50:33 -06002873 VkSamplerCreateInfo sampler_ci = {};
2874 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2875 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08002876 sampler_ci.magFilter = VK_FILTER_NEAREST;
2877 sampler_ci.minFilter = VK_FILTER_NEAREST;
2878 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08002879 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2880 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2881 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06002882 sampler_ci.mipLodBias = 1.0;
2883 sampler_ci.maxAnisotropy = 1;
2884 sampler_ci.compareEnable = VK_FALSE;
2885 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2886 sampler_ci.minLod = 1.0;
2887 sampler_ci.maxLod = 1.0;
2888 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06002889 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2890
Tobin Ehlis3b780662015-05-28 12:11:26 -06002891 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002892 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002893 ASSERT_VK_SUCCESS(err);
2894
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002895 VkDescriptorImageInfo info = {};
2896 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002897
2898 VkWriteDescriptorSet descriptor_write;
2899 memset(&descriptor_write, 0, sizeof(descriptor_write));
2900 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002901 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002902 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002903 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002904 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002905 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002906
2907 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2908
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002909 if (!m_errorMonitor->DesiredMsgFound()) {
2910 FAIL() << "Did not receive Error 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...'";
2911 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06002912 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002913
Chia-I Wuf7458c52015-10-26 21:10:41 +08002914 vkDestroySampler(m_device->device(), sampler, NULL);
2915 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2916 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002917}
2918
2919TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2920{
2921 // For overlapping Update, have arrayIndex exceed that of layout
Tobin Ehlis3b780662015-05-28 12:11:26 -06002922 VkResult err;
2923
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002924 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2925 "Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding");
2926
Tobin Ehlis3b780662015-05-28 12:11:26 -06002927 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06002928 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002929 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06002930 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002931 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002932
2933 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2934 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2935 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002936 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002937 ds_pool_ci.poolSizeCount = 1;
2938 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06002939
Tobin Ehlis3b780662015-05-28 12:11:26 -06002940 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002941 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002942 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002943
Tony Barboureb254902015-07-15 12:50:33 -06002944 VkDescriptorSetLayoutBinding dsl_binding = {};
2945 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2946 dsl_binding.arraySize = 1;
2947 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2948 dsl_binding.pImmutableSamplers = NULL;
2949
2950 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2951 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2952 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002953 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002954 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06002955
Tobin Ehlis3b780662015-05-28 12:11:26 -06002956 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002957 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002958 ASSERT_VK_SUCCESS(err);
2959
2960 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002961 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002962 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002963 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002964 alloc_info.descriptorPool = ds_pool;
2965 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002966 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002967 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002968
Tony Barboureb254902015-07-15 12:50:33 -06002969 VkSamplerCreateInfo sampler_ci = {};
2970 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2971 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08002972 sampler_ci.magFilter = VK_FILTER_NEAREST;
2973 sampler_ci.minFilter = VK_FILTER_NEAREST;
2974 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08002975 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2976 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2977 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06002978 sampler_ci.mipLodBias = 1.0;
2979 sampler_ci.maxAnisotropy = 1;
2980 sampler_ci.compareEnable = VK_FALSE;
2981 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2982 sampler_ci.minLod = 1.0;
2983 sampler_ci.maxLod = 1.0;
2984 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06002985 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06002986
Tobin Ehlis3b780662015-05-28 12:11:26 -06002987 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002988 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002989 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002990
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002991 VkDescriptorImageInfo info = {};
2992 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002993
2994 VkWriteDescriptorSet descriptor_write;
2995 memset(&descriptor_write, 0, sizeof(descriptor_write));
2996 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002997 descriptor_write.dstSet = descriptorSet;
2998 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08002999 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003000 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003001 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003002 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003003
3004 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3005
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003006 if (!m_errorMonitor->DesiredMsgFound()) {
3007 FAIL() << "Did not receive Error 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
3008 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003009 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003010
Chia-I Wuf7458c52015-10-26 21:10:41 +08003011 vkDestroySampler(m_device->device(), sampler, NULL);
3012 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3013 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003014}
3015
3016TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3017{
Tobin Ehlis3b780662015-05-28 12:11:26 -06003018 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Tobin Ehlis3b780662015-05-28 12:11:26 -06003019 VkResult err;
3020
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003021 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3022 " does not have binding to match update binding ");
3023
Tobin Ehlis3b780662015-05-28 12:11:26 -06003024 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003025 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003026 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003027 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003028 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003029
3030 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3031 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3032 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003033 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003034 ds_pool_ci.poolSizeCount = 1;
3035 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003036
Tobin Ehlis3b780662015-05-28 12:11:26 -06003037 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003038 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003039 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003040
Tony Barboureb254902015-07-15 12:50:33 -06003041 VkDescriptorSetLayoutBinding dsl_binding = {};
3042 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3043 dsl_binding.arraySize = 1;
3044 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3045 dsl_binding.pImmutableSamplers = NULL;
3046
3047 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3048 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3049 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003050 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003051 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003052 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003053 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003054 ASSERT_VK_SUCCESS(err);
3055
3056 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003057 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003058 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003059 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003060 alloc_info.descriptorPool = ds_pool;
3061 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003062 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003063 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003064
Tony Barboureb254902015-07-15 12:50:33 -06003065 VkSamplerCreateInfo sampler_ci = {};
3066 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3067 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003068 sampler_ci.magFilter = VK_FILTER_NEAREST;
3069 sampler_ci.minFilter = VK_FILTER_NEAREST;
3070 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003071 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3072 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3073 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003074 sampler_ci.mipLodBias = 1.0;
3075 sampler_ci.maxAnisotropy = 1;
3076 sampler_ci.compareEnable = VK_FALSE;
3077 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3078 sampler_ci.minLod = 1.0;
3079 sampler_ci.maxLod = 1.0;
3080 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003081 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003082
Tobin Ehlis3b780662015-05-28 12:11:26 -06003083 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003084 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003085 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003086
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003087 VkDescriptorImageInfo info = {};
3088 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003089
3090 VkWriteDescriptorSet descriptor_write;
3091 memset(&descriptor_write, 0, sizeof(descriptor_write));
3092 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003093 descriptor_write.dstSet = descriptorSet;
3094 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003095 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003096 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003097 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003098 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003099
3100 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3101
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003102 if (!m_errorMonitor->DesiredMsgFound()) {
3103 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have binding to match update binding '";
3104 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003105 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003106
Chia-I Wuf7458c52015-10-26 21:10:41 +08003107 vkDestroySampler(m_device->device(), sampler, NULL);
3108 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3109 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003110}
3111
3112TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3113{
3114 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Tobin Ehlis3b780662015-05-28 12:11:26 -06003115 VkResult err;
3116
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003117 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3118 "Unexpected UPDATE struct of type ");
3119
Tobin Ehlis3b780662015-05-28 12:11:26 -06003120 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003121
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003122 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003123 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003124 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003125
3126 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3127 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3128 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003129 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003130 ds_pool_ci.poolSizeCount = 1;
3131 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003132
Tobin Ehlis3b780662015-05-28 12:11:26 -06003133 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003134 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003135 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06003136 VkDescriptorSetLayoutBinding dsl_binding = {};
3137 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3138 dsl_binding.arraySize = 1;
3139 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3140 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003141
Tony Barboureb254902015-07-15 12:50:33 -06003142 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3143 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3144 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003145 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003146 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003147
Tobin Ehlis3b780662015-05-28 12:11:26 -06003148 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003149 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003150 ASSERT_VK_SUCCESS(err);
3151
3152 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003153 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003154 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003155 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003156 alloc_info.descriptorPool = ds_pool;
3157 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003158 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003159 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003160
Tony Barboureb254902015-07-15 12:50:33 -06003161 VkSamplerCreateInfo sampler_ci = {};
3162 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3163 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003164 sampler_ci.magFilter = VK_FILTER_NEAREST;
3165 sampler_ci.minFilter = VK_FILTER_NEAREST;
3166 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003167 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3168 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3169 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003170 sampler_ci.mipLodBias = 1.0;
3171 sampler_ci.maxAnisotropy = 1;
3172 sampler_ci.compareEnable = VK_FALSE;
3173 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3174 sampler_ci.minLod = 1.0;
3175 sampler_ci.maxLod = 1.0;
3176 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003177 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003178 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003179 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003180 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003181
3182
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003183 VkDescriptorImageInfo info = {};
3184 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003185
3186 VkWriteDescriptorSet descriptor_write;
3187 memset(&descriptor_write, 0, sizeof(descriptor_write));
3188 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003189 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003190 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003191 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003192 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003193 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003194
3195 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3196
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003197 if (!m_errorMonitor->DesiredMsgFound()) {
3198 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
3199 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003200 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003201
Chia-I Wuf7458c52015-10-26 21:10:41 +08003202 vkDestroySampler(m_device->device(), sampler, NULL);
3203 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3204 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003205}
3206
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003207TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3208{
3209 // Create a single Sampler descriptor and send it an invalid Sampler
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003210 VkResult err;
3211
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003212 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3213 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
3214
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003215 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003216 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003217 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003218 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003219 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003220
3221 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3222 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3223 ds_pool_ci.pNext = NULL;
3224 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003225 ds_pool_ci.poolSizeCount = 1;
3226 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003227
3228 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003229 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003230 ASSERT_VK_SUCCESS(err);
3231
3232 VkDescriptorSetLayoutBinding dsl_binding = {};
3233 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3234 dsl_binding.arraySize = 1;
3235 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3236 dsl_binding.pImmutableSamplers = NULL;
3237
3238 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3239 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3240 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003241 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003242 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003243 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003244 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003245 ASSERT_VK_SUCCESS(err);
3246
3247 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003248 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003249 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003250 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003251 alloc_info.descriptorPool = ds_pool;
3252 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003253 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003254 ASSERT_VK_SUCCESS(err);
3255
Chia-I Wue2fc5522015-10-26 20:04:44 +08003256 VkSampler sampler = (VkSampler) 0xbaadbeef; // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003257
3258 VkDescriptorImageInfo descriptor_info;
3259 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3260 descriptor_info.sampler = sampler;
3261
3262 VkWriteDescriptorSet descriptor_write;
3263 memset(&descriptor_write, 0, sizeof(descriptor_write));
3264 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003265 descriptor_write.dstSet = descriptorSet;
3266 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003267 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003268 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3269 descriptor_write.pImageInfo = &descriptor_info;
3270
3271 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3272
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003273 if (!m_errorMonitor->DesiredMsgFound()) {
3274 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid sampler...'";
3275 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003276 }
3277
Chia-I Wuf7458c52015-10-26 21:10:41 +08003278 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3279 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003280}
3281
3282TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3283{
3284 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003285 VkResult err;
3286
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003287 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3288 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
3289
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003290 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003291 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003292 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003293 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003294
3295 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3296 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3297 ds_pool_ci.pNext = NULL;
3298 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003299 ds_pool_ci.poolSizeCount = 1;
3300 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003301
3302 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003303 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003304 ASSERT_VK_SUCCESS(err);
3305
3306 VkDescriptorSetLayoutBinding dsl_binding = {};
3307 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3308 dsl_binding.arraySize = 1;
3309 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3310 dsl_binding.pImmutableSamplers = NULL;
3311
3312 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3313 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3314 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003315 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003316 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003317 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003318 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003319 ASSERT_VK_SUCCESS(err);
3320
3321 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003322 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003323 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003324 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003325 alloc_info.descriptorPool = ds_pool;
3326 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003327 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003328 ASSERT_VK_SUCCESS(err);
3329
3330 VkSamplerCreateInfo sampler_ci = {};
3331 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3332 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003333 sampler_ci.magFilter = VK_FILTER_NEAREST;
3334 sampler_ci.minFilter = VK_FILTER_NEAREST;
3335 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003336 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3337 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3338 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003339 sampler_ci.mipLodBias = 1.0;
3340 sampler_ci.maxAnisotropy = 1;
3341 sampler_ci.compareEnable = VK_FALSE;
3342 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3343 sampler_ci.minLod = 1.0;
3344 sampler_ci.maxLod = 1.0;
3345 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3346 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3347
3348 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003349 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003350 ASSERT_VK_SUCCESS(err);
3351
Chia-I Wue2fc5522015-10-26 20:04:44 +08003352 VkImageView view = (VkImageView) 0xbaadbeef; // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003353
3354 VkDescriptorImageInfo descriptor_info;
3355 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3356 descriptor_info.sampler = sampler;
3357 descriptor_info.imageView = view;
3358
3359 VkWriteDescriptorSet descriptor_write;
3360 memset(&descriptor_write, 0, sizeof(descriptor_write));
3361 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003362 descriptor_write.dstSet = descriptorSet;
3363 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003364 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003365 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3366 descriptor_write.pImageInfo = &descriptor_info;
3367
3368 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3369
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003370 if (!m_errorMonitor->DesiredMsgFound()) {
3371 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid imageView...'";
3372 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003373 }
3374
Chia-I Wuf7458c52015-10-26 21:10:41 +08003375 vkDestroySampler(m_device->device(), sampler, NULL);
3376 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3377 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003378}
3379
Tobin Ehlis04356f92015-10-27 16:35:27 -06003380TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
3381{
3382 // 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 -06003383 VkResult err;
3384
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003385 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3386 "Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ");
3387
Tobin Ehlis04356f92015-10-27 16:35:27 -06003388 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis04356f92015-10-27 16:35:27 -06003389 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003390 VkDescriptorPoolSize ds_type_count[2] = {};
Tobin Ehlis04356f92015-10-27 16:35:27 -06003391 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003392 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003393 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003394 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003395
3396 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3397 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3398 ds_pool_ci.pNext = NULL;
3399 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003400 ds_pool_ci.poolSizeCount = 2;
3401 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003402
3403 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003404 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003405 ASSERT_VK_SUCCESS(err);
3406 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
3407 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3408 dsl_binding[0].arraySize = 1;
3409 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3410 dsl_binding[0].pImmutableSamplers = NULL;
3411 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3412 dsl_binding[1].arraySize = 1;
3413 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
3414 dsl_binding[1].pImmutableSamplers = NULL;
3415
3416 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3417 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3418 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003419 ds_layout_ci.bindingCount = 2;
Chia-I Wua745e512015-10-31 00:31:16 +08003420 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003421
3422 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003423 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003424 ASSERT_VK_SUCCESS(err);
3425
3426 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003427 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis04356f92015-10-27 16:35:27 -06003428 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003429 alloc_info.setLayoutCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003430 alloc_info.descriptorPool = ds_pool;
3431 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003432 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003433 ASSERT_VK_SUCCESS(err);
3434
3435 VkSamplerCreateInfo sampler_ci = {};
3436 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3437 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003438 sampler_ci.magFilter = VK_FILTER_NEAREST;
3439 sampler_ci.minFilter = VK_FILTER_NEAREST;
3440 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003441 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3442 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3443 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003444 sampler_ci.mipLodBias = 1.0;
3445 sampler_ci.maxAnisotropy = 1;
3446 sampler_ci.compareEnable = VK_FALSE;
3447 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3448 sampler_ci.minLod = 1.0;
3449 sampler_ci.maxLod = 1.0;
3450 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3451 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3452
3453 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003454 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003455 ASSERT_VK_SUCCESS(err);
3456
3457 VkDescriptorImageInfo info = {};
3458 info.sampler = sampler;
3459
3460 VkWriteDescriptorSet descriptor_write;
3461 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
3462 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003463 descriptor_write.dstSet = descriptorSet;
3464 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08003465 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003466 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3467 descriptor_write.pImageInfo = &info;
3468 // This write update should succeed
3469 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3470 // Now perform a copy update that fails due to type mismatch
3471 VkCopyDescriptorSet copy_ds_update;
3472 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3473 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3474 copy_ds_update.srcSet = descriptorSet;
3475 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003476 copy_ds_update.dstSet = descriptorSet;
3477 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08003478 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06003479 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3480
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003481 if (!m_errorMonitor->DesiredMsgFound()) {
3482 FAIL() << "Did not receive Error 'Copy descriptor update index 0, update count #1, has src update descriptor type_DESCRIPTOR_TYPE_SAMPLER'";
3483 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06003484 }
3485 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003486 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3487 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis04356f92015-10-27 16:35:27 -06003488 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3489 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3490 copy_ds_update.srcSet = descriptorSet;
3491 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003492 copy_ds_update.dstSet = descriptorSet;
3493 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003494 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06003495 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3496
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003497 if (!m_errorMonitor->DesiredMsgFound()) {
3498 FAIL() << "Did not receive Error 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...'";
3499 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06003500 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003501
Tobin Ehlis04356f92015-10-27 16:35:27 -06003502 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003503 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3504 "Copy descriptor src update is out of bounds for matching binding 1 ");
3505
Tobin Ehlis04356f92015-10-27 16:35:27 -06003506 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3507 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3508 copy_ds_update.srcSet = descriptorSet;
3509 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003510 copy_ds_update.dstSet = descriptorSet;
3511 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003512 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06003513 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3514
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003515 if (!m_errorMonitor->DesiredMsgFound()) {
3516 FAIL() << "Did not receive Error 'Copy descriptor src update is out of bounds for matching binding 1...'";
3517 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06003518 }
3519
Chia-I Wuf7458c52015-10-26 21:10:41 +08003520 vkDestroySampler(m_device->device(), sampler, NULL);
3521 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3522 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003523}
3524
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003525TEST_F(VkLayerTest, NumSamplesMismatch)
3526{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003527 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis3b780662015-05-28 12:11:26 -06003528 VkResult err;
3529
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003530 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3531 "Num samples mismatch! ");
3532
Tobin Ehlis3b780662015-05-28 12:11:26 -06003533 ASSERT_NO_FATAL_FAILURE(InitState());
3534 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003535 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003536 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003537 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003538
3539 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003540 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3541 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003542 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003543 ds_pool_ci.poolSizeCount = 1;
3544 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003545
Tobin Ehlis3b780662015-05-28 12:11:26 -06003546 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003547 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003548 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003549
Tony Barboureb254902015-07-15 12:50:33 -06003550 VkDescriptorSetLayoutBinding dsl_binding = {};
3551 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3552 dsl_binding.arraySize = 1;
3553 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3554 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003555
Tony Barboureb254902015-07-15 12:50:33 -06003556 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3557 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3558 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003559 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003560 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003561
Tobin Ehlis3b780662015-05-28 12:11:26 -06003562 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003563 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003564 ASSERT_VK_SUCCESS(err);
3565
3566 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003567 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003568 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003569 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003570 alloc_info.descriptorPool = ds_pool;
3571 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003572 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003573 ASSERT_VK_SUCCESS(err);
3574
Tony Barboureb254902015-07-15 12:50:33 -06003575 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3576 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3577 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003578 pipe_ms_state_ci.rasterizationSamples = 4;
Tony Barboureb254902015-07-15 12:50:33 -06003579 pipe_ms_state_ci.sampleShadingEnable = 0;
3580 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003581 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003582
Tony Barboureb254902015-07-15 12:50:33 -06003583 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3584 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3585 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003586 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003587 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003588
3589 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003590 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003591 ASSERT_VK_SUCCESS(err);
3592
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003593 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3594 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 -06003595 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003596 VkPipelineObj pipe(m_device);
3597 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003598 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003599 pipe.SetMSAA(&pipe_ms_state_ci);
3600 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003601
Tony Barbourfe3351b2015-07-28 10:17:20 -06003602 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003603 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003604
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003605 if (!m_errorMonitor->DesiredMsgFound()) {
3606 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
3607 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003608 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003609
Chia-I Wuf7458c52015-10-26 21:10:41 +08003610 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3611 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3612 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003613}
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003614
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003615TEST_F(VkLayerTest, ClearCmdNoDraw)
3616{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003617 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003618 VkResult err;
3619
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003620 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
3621 "vkCmdClearAttachments() issued on CB object ");
3622
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003623 ASSERT_NO_FATAL_FAILURE(InitState());
3624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06003625
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003626 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003627 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003628 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003629
3630 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3631 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3632 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003633 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003634 ds_pool_ci.poolSizeCount = 1;
3635 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06003636
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003637 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003638 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003639 ASSERT_VK_SUCCESS(err);
3640
Tony Barboureb254902015-07-15 12:50:33 -06003641 VkDescriptorSetLayoutBinding dsl_binding = {};
3642 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3643 dsl_binding.arraySize = 1;
3644 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3645 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003646
Tony Barboureb254902015-07-15 12:50:33 -06003647 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3648 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3649 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003650 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003651 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003652
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003653 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003654 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003655 ASSERT_VK_SUCCESS(err);
3656
3657 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003658 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003659 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003660 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003661 alloc_info.descriptorPool = ds_pool;
3662 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003663 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003664 ASSERT_VK_SUCCESS(err);
3665
Tony Barboureb254902015-07-15 12:50:33 -06003666 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3667 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3668 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003669 pipe_ms_state_ci.rasterizationSamples = 4;
Tony Barboureb254902015-07-15 12:50:33 -06003670 pipe_ms_state_ci.sampleShadingEnable = 0;
3671 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003672 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003673
Tony Barboureb254902015-07-15 12:50:33 -06003674 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3675 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3676 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003677 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003678 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003679
3680 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003681 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003682 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003683
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003684 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003685 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
3686 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3687
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003688 VkPipelineObj pipe(m_device);
3689 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003690 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003691 pipe.SetMSAA(&pipe_ms_state_ci);
3692 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003693
3694 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003695
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003696 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3697 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003698 VkClearAttachment color_attachment;
3699 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3700 color_attachment.clearValue.color.float32[0] = 1.0;
3701 color_attachment.clearValue.color.float32[1] = 1.0;
3702 color_attachment.clearValue.color.float32[2] = 1.0;
3703 color_attachment.clearValue.color.float32[3] = 1.0;
3704 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06003705 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003706
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003707 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003708
3709 if (!m_errorMonitor->DesiredMsgFound()) {
3710 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued on CB object...'";
3711 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003712 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003713
Chia-I Wuf7458c52015-10-26 21:10:41 +08003714 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3715 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3716 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003717}
3718
Tobin Ehlis502480b2015-06-24 15:53:07 -06003719TEST_F(VkLayerTest, VtxBufferBadIndex)
3720{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003721 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis502480b2015-06-24 15:53:07 -06003722 VkResult err;
3723
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003724 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3725 "Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.");
3726
Tobin Ehlis502480b2015-06-24 15:53:07 -06003727 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06003728 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06003729 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06003730
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003731 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003732 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003733 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003734
3735 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3736 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3737 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003738 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003739 ds_pool_ci.poolSizeCount = 1;
3740 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06003741
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003742 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003743 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003744 ASSERT_VK_SUCCESS(err);
3745
Tony Barboureb254902015-07-15 12:50:33 -06003746 VkDescriptorSetLayoutBinding dsl_binding = {};
3747 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3748 dsl_binding.arraySize = 1;
3749 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3750 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003751
Tony Barboureb254902015-07-15 12:50:33 -06003752 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3753 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3754 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003755 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003756 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003757
Tobin Ehlis502480b2015-06-24 15:53:07 -06003758 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003759 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003760 ASSERT_VK_SUCCESS(err);
3761
3762 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003763 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003764 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003765 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003766 alloc_info.descriptorPool = ds_pool;
3767 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003768 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003769 ASSERT_VK_SUCCESS(err);
3770
Tony Barboureb254902015-07-15 12:50:33 -06003771 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3772 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3773 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003774 pipe_ms_state_ci.rasterizationSamples = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003775 pipe_ms_state_ci.sampleShadingEnable = 0;
3776 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003777 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003778
Tony Barboureb254902015-07-15 12:50:33 -06003779 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3780 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3781 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003782 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003783 pipeline_layout_ci.pSetLayouts = &ds_layout;
3784 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003785
Chia-I Wuf7458c52015-10-26 21:10:41 +08003786 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003787 ASSERT_VK_SUCCESS(err);
3788
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003789 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3790 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 -06003791 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003792 VkPipelineObj pipe(m_device);
3793 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003794 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003795 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003796 pipe.SetViewport(m_viewports);
3797 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003798 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003799
3800 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003801 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06003802 // Don't care about actual data, just need to get to draw to flag error
3803 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3804 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3805 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003806 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003807
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003808 if (!m_errorMonitor->DesiredMsgFound()) {
3809 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
3810 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis502480b2015-06-24 15:53:07 -06003811 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003812
Chia-I Wuf7458c52015-10-26 21:10:41 +08003813 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3814 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3815 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003816}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003817#endif // DRAW_STATE_TESTS
3818
Tobin Ehlis0788f522015-05-26 16:11:58 -06003819#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06003820#if GTEST_IS_THREADSAFE
3821struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003822 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003823 VkEvent event;
3824 bool bailout;
3825};
3826
3827extern "C" void *AddToCommandBuffer(void *arg)
3828{
3829 struct thread_data_struct *data = (struct thread_data_struct *) arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003830
3831 for (int i = 0; i<10000; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003832 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003833 if (data->bailout) {
3834 break;
3835 }
3836 }
3837 return NULL;
3838}
3839
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003840TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyanaccf7692015-05-12 16:00:45 -06003841{
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003842 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003843
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003844 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "THREADING ERROR");
3845
Mike Stroyanaccf7692015-05-12 16:00:45 -06003846 ASSERT_NO_FATAL_FAILURE(InitState());
3847 ASSERT_NO_FATAL_FAILURE(InitViewport());
3848 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3849
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003850 // Calls AllocateCommandBuffers
3851 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003852
3853 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003854 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003855
3856 VkEventCreateInfo event_info;
3857 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003858 VkResult err;
3859
3860 memset(&event_info, 0, sizeof(event_info));
3861 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3862
Chia-I Wuf7458c52015-10-26 21:10:41 +08003863 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003864 ASSERT_VK_SUCCESS(err);
3865
Mike Stroyanaccf7692015-05-12 16:00:45 -06003866 err = vkResetEvent(device(), event);
3867 ASSERT_VK_SUCCESS(err);
3868
3869 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003870 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003871 data.event = event;
3872 data.bailout = false;
3873 m_errorMonitor->SetBailout(&data.bailout);
3874 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003875 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003876 // Add many entries to command buffer from this thread at the same time.
3877 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003878
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003879 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003880 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003881
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003882 if (!m_errorMonitor->DesiredMsgFound()) {
3883 FAIL() << "Did not receive Error 'THREADING ERROR' from using one VkCommandBufferObj in two threads";
3884 m_errorMonitor->DumpFailureMsgs();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003885 }
3886
Chia-I Wuf7458c52015-10-26 21:10:41 +08003887 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003888}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003889#endif // GTEST_IS_THREADSAFE
3890#endif // THREADING_TESTS
3891
Chris Forbes9f7ff632015-05-25 11:13:08 +12003892#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003893TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
3894{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003895 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3896 "Shader is not SPIR-V");
3897
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003898 ASSERT_NO_FATAL_FAILURE(InitState());
3899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3900
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003901 VkShaderModule module;
3902 VkShaderModuleCreateInfo moduleCreateInfo;
3903 struct icd_spv_header spv;
3904
3905 spv.magic = ICD_SPV_MAGIC;
3906 spv.version = ICD_SPV_VERSION;
3907 spv.gen_magic = 0;
3908
3909 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3910 moduleCreateInfo.pNext = NULL;
Chia-I Wu8094f192015-10-26 19:22:06 +08003911 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003912 moduleCreateInfo.codeSize = 4;
3913 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003914 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003915
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003916 if (!m_errorMonitor->DesiredMsgFound()) {
3917 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
3918 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003919 }
3920}
3921
3922TEST_F(VkLayerTest, InvalidSPIRVMagic)
3923{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003924 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3925 "Shader is not SPIR-V");
3926
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003927 ASSERT_NO_FATAL_FAILURE(InitState());
3928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3929
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003930 VkShaderModule module;
3931 VkShaderModuleCreateInfo moduleCreateInfo;
3932 struct icd_spv_header spv;
3933
3934 spv.magic = ~ICD_SPV_MAGIC;
3935 spv.version = ICD_SPV_VERSION;
3936 spv.gen_magic = 0;
3937
3938 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3939 moduleCreateInfo.pNext = NULL;
Chia-I Wu8094f192015-10-26 19:22:06 +08003940 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003941 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3942 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003943 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003944
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003945 if (!m_errorMonitor->DesiredMsgFound()) {
3946 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
3947 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003948 }
3949}
3950
3951TEST_F(VkLayerTest, InvalidSPIRVVersion)
3952{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003953 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3954 "Shader is not SPIR-V");
3955
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003956 ASSERT_NO_FATAL_FAILURE(InitState());
3957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3958
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003959 VkShaderModule module;
3960 VkShaderModuleCreateInfo moduleCreateInfo;
3961 struct icd_spv_header spv;
3962
3963 spv.magic = ICD_SPV_MAGIC;
3964 spv.version = ~ICD_SPV_VERSION;
3965 spv.gen_magic = 0;
3966
3967 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3968 moduleCreateInfo.pNext = NULL;
3969
Chia-I Wu8094f192015-10-26 19:22:06 +08003970 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003971 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3972 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003973 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003974
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003975 if (!m_errorMonitor->DesiredMsgFound()) {
3976 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
3977 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003978 }
3979}
3980
Chris Forbes9f7ff632015-05-25 11:13:08 +12003981TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
3982{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003983 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
3984 "not consumed by fragment shader");
3985
Chris Forbes9f7ff632015-05-25 11:13:08 +12003986 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12003988
3989 char const *vsSource =
3990 "#version 140\n"
3991 "#extension GL_ARB_separate_shader_objects: require\n"
3992 "#extension GL_ARB_shading_language_420pack: require\n"
3993 "\n"
3994 "layout(location=0) out float x;\n"
3995 "void main(){\n"
3996 " gl_Position = vec4(1);\n"
3997 " x = 0;\n"
3998 "}\n";
3999 char const *fsSource =
4000 "#version 140\n"
4001 "#extension GL_ARB_separate_shader_objects: require\n"
4002 "#extension GL_ARB_shading_language_420pack: require\n"
4003 "\n"
4004 "layout(location=0) out vec4 color;\n"
4005 "void main(){\n"
4006 " color = vec4(1);\n"
4007 "}\n";
4008
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004009 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4010 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004011
4012 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004013 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12004014 pipe.AddShader(&vs);
4015 pipe.AddShader(&fs);
4016
Chris Forbes9f7ff632015-05-25 11:13:08 +12004017 VkDescriptorSetObj descriptorSet(m_device);
4018 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004019 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004020
Tony Barbour5781e8f2015-08-04 16:23:11 -06004021 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12004022
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004023 if (!m_errorMonitor->DesiredMsgFound()) {
4024 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
4025 m_errorMonitor->DumpFailureMsgs();
Chris Forbes9f7ff632015-05-25 11:13:08 +12004026 }
4027}
Chris Forbes9f7ff632015-05-25 11:13:08 +12004028
Chris Forbes59cb88d2015-05-25 11:13:13 +12004029TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4030{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004031 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4032 "not written by vertex shader");
4033
Chris Forbes59cb88d2015-05-25 11:13:13 +12004034 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004035 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12004036
4037 char const *vsSource =
4038 "#version 140\n"
4039 "#extension GL_ARB_separate_shader_objects: require\n"
4040 "#extension GL_ARB_shading_language_420pack: require\n"
4041 "\n"
4042 "void main(){\n"
4043 " gl_Position = vec4(1);\n"
4044 "}\n";
4045 char const *fsSource =
4046 "#version 140\n"
4047 "#extension GL_ARB_separate_shader_objects: require\n"
4048 "#extension GL_ARB_shading_language_420pack: require\n"
4049 "\n"
4050 "layout(location=0) in float x;\n"
4051 "layout(location=0) out vec4 color;\n"
4052 "void main(){\n"
4053 " color = vec4(x);\n"
4054 "}\n";
4055
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004056 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4057 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004058
4059 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004060 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12004061 pipe.AddShader(&vs);
4062 pipe.AddShader(&fs);
4063
Chris Forbes59cb88d2015-05-25 11:13:13 +12004064 VkDescriptorSetObj descriptorSet(m_device);
4065 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004066 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004067
Tony Barbour5781e8f2015-08-04 16:23:11 -06004068 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12004069
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004070 if (!m_errorMonitor->DesiredMsgFound()) {
4071 FAIL() << "Did not receive Error 'not written by vertex shader'";
4072 m_errorMonitor->DumpFailureMsgs();
Chris Forbes59cb88d2015-05-25 11:13:13 +12004073 }
4074}
4075
Chris Forbesb56af562015-05-25 11:13:17 +12004076TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4077{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004078 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4079 "Type mismatch on location 0");
4080
Chris Forbesb56af562015-05-25 11:13:17 +12004081 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12004083
4084 char const *vsSource =
4085 "#version 140\n"
4086 "#extension GL_ARB_separate_shader_objects: require\n"
4087 "#extension GL_ARB_shading_language_420pack: require\n"
4088 "\n"
4089 "layout(location=0) out int x;\n"
4090 "void main(){\n"
4091 " x = 0;\n"
4092 " gl_Position = vec4(1);\n"
4093 "}\n";
4094 char const *fsSource =
4095 "#version 140\n"
4096 "#extension GL_ARB_separate_shader_objects: require\n"
4097 "#extension GL_ARB_shading_language_420pack: require\n"
4098 "\n"
4099 "layout(location=0) in float x;\n" /* VS writes int */
4100 "layout(location=0) out vec4 color;\n"
4101 "void main(){\n"
4102 " color = vec4(x);\n"
4103 "}\n";
4104
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004105 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4106 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12004107
4108 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004109 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12004110 pipe.AddShader(&vs);
4111 pipe.AddShader(&fs);
4112
Chris Forbesb56af562015-05-25 11:13:17 +12004113 VkDescriptorSetObj descriptorSet(m_device);
4114 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004115 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12004116
Tony Barbour5781e8f2015-08-04 16:23:11 -06004117 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12004118
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004119 if (!m_errorMonitor->DesiredMsgFound()) {
4120 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4121 m_errorMonitor->DumpFailureMsgs();
Chris Forbesb56af562015-05-25 11:13:17 +12004122 }
4123}
4124
Chris Forbesde136e02015-05-25 11:13:28 +12004125TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4126{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004127 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
4128 "location 0 not consumed by VS");
4129
Chris Forbesde136e02015-05-25 11:13:28 +12004130 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12004132
4133 VkVertexInputBindingDescription input_binding;
4134 memset(&input_binding, 0, sizeof(input_binding));
4135
4136 VkVertexInputAttributeDescription input_attrib;
4137 memset(&input_attrib, 0, sizeof(input_attrib));
4138 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4139
4140 char const *vsSource =
4141 "#version 140\n"
4142 "#extension GL_ARB_separate_shader_objects: require\n"
4143 "#extension GL_ARB_shading_language_420pack: require\n"
4144 "\n"
4145 "void main(){\n"
4146 " gl_Position = vec4(1);\n"
4147 "}\n";
4148 char const *fsSource =
4149 "#version 140\n"
4150 "#extension GL_ARB_separate_shader_objects: require\n"
4151 "#extension GL_ARB_shading_language_420pack: require\n"
4152 "\n"
4153 "layout(location=0) out vec4 color;\n"
4154 "void main(){\n"
4155 " color = vec4(1);\n"
4156 "}\n";
4157
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004158 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4159 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12004160
4161 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004162 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12004163 pipe.AddShader(&vs);
4164 pipe.AddShader(&fs);
4165
4166 pipe.AddVertexInputBindings(&input_binding, 1);
4167 pipe.AddVertexInputAttribs(&input_attrib, 1);
4168
Chris Forbesde136e02015-05-25 11:13:28 +12004169 VkDescriptorSetObj descriptorSet(m_device);
4170 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004171 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12004172
Tony Barbour5781e8f2015-08-04 16:23:11 -06004173 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12004174
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004175 if (!m_errorMonitor->DesiredMsgFound()) {
4176 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
4177 m_errorMonitor->DumpFailureMsgs();
Chris Forbesde136e02015-05-25 11:13:28 +12004178 }
4179}
4180
Chris Forbes62e8e502015-05-25 11:13:29 +12004181TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4182{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004183 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4184 "VS consumes input at location 0 but not provided");
4185
Chris Forbes62e8e502015-05-25 11:13:29 +12004186 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12004188
4189 char const *vsSource =
4190 "#version 140\n"
4191 "#extension GL_ARB_separate_shader_objects: require\n"
4192 "#extension GL_ARB_shading_language_420pack: require\n"
4193 "\n"
4194 "layout(location=0) in vec4 x;\n" /* not provided */
4195 "void main(){\n"
4196 " gl_Position = x;\n"
4197 "}\n";
4198 char const *fsSource =
4199 "#version 140\n"
4200 "#extension GL_ARB_separate_shader_objects: require\n"
4201 "#extension GL_ARB_shading_language_420pack: require\n"
4202 "\n"
4203 "layout(location=0) out vec4 color;\n"
4204 "void main(){\n"
4205 " color = vec4(1);\n"
4206 "}\n";
4207
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004208 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4209 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12004210
4211 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004212 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12004213 pipe.AddShader(&vs);
4214 pipe.AddShader(&fs);
4215
Chris Forbes62e8e502015-05-25 11:13:29 +12004216 VkDescriptorSetObj descriptorSet(m_device);
4217 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004218 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12004219
Tony Barbour5781e8f2015-08-04 16:23:11 -06004220 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12004221
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004222 if (!m_errorMonitor->DesiredMsgFound()) {
4223 FAIL() << "Did not receive Error 'VS consumes input at location 0 but not provided'";
4224 m_errorMonitor->DumpFailureMsgs();
Chris Forbes62e8e502015-05-25 11:13:29 +12004225 }
4226}
4227
Chris Forbesc97d98e2015-05-25 11:13:31 +12004228TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4229{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004230 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4231 "location 0 does not match VS input type");
4232
Chris Forbesc97d98e2015-05-25 11:13:31 +12004233 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004234 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12004235
4236 VkVertexInputBindingDescription input_binding;
4237 memset(&input_binding, 0, sizeof(input_binding));
4238
4239 VkVertexInputAttributeDescription input_attrib;
4240 memset(&input_attrib, 0, sizeof(input_attrib));
4241 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4242
4243 char const *vsSource =
4244 "#version 140\n"
4245 "#extension GL_ARB_separate_shader_objects: require\n"
4246 "#extension GL_ARB_shading_language_420pack: require\n"
4247 "\n"
4248 "layout(location=0) in int x;\n" /* attrib provided float */
4249 "void main(){\n"
4250 " gl_Position = vec4(x);\n"
4251 "}\n";
4252 char const *fsSource =
4253 "#version 140\n"
4254 "#extension GL_ARB_separate_shader_objects: require\n"
4255 "#extension GL_ARB_shading_language_420pack: require\n"
4256 "\n"
4257 "layout(location=0) out vec4 color;\n"
4258 "void main(){\n"
4259 " color = vec4(1);\n"
4260 "}\n";
4261
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004262 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4263 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12004264
4265 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004266 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12004267 pipe.AddShader(&vs);
4268 pipe.AddShader(&fs);
4269
4270 pipe.AddVertexInputBindings(&input_binding, 1);
4271 pipe.AddVertexInputAttribs(&input_attrib, 1);
4272
Chris Forbesc97d98e2015-05-25 11:13:31 +12004273 VkDescriptorSetObj descriptorSet(m_device);
4274 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004275 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12004276
Tony Barbour5781e8f2015-08-04 16:23:11 -06004277 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12004278
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004279 if (!m_errorMonitor->DesiredMsgFound()) {
4280 FAIL() << "Did not receive Error 'location 0 does not match VS input type'";
4281 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc97d98e2015-05-25 11:13:31 +12004282 }
4283}
4284
Chris Forbes280ba2c2015-06-12 11:16:41 +12004285TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
4286{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004287 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4288 "Duplicate vertex input binding descriptions for binding 0");
4289
Chris Forbes280ba2c2015-06-12 11:16:41 +12004290 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12004292
4293 /* Two binding descriptions for binding 0 */
4294 VkVertexInputBindingDescription input_bindings[2];
4295 memset(input_bindings, 0, sizeof(input_bindings));
4296
4297 VkVertexInputAttributeDescription input_attrib;
4298 memset(&input_attrib, 0, sizeof(input_attrib));
4299 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4300
4301 char const *vsSource =
4302 "#version 140\n"
4303 "#extension GL_ARB_separate_shader_objects: require\n"
4304 "#extension GL_ARB_shading_language_420pack: require\n"
4305 "\n"
4306 "layout(location=0) in float x;\n" /* attrib provided float */
4307 "void main(){\n"
4308 " gl_Position = vec4(x);\n"
4309 "}\n";
4310 char const *fsSource =
4311 "#version 140\n"
4312 "#extension GL_ARB_separate_shader_objects: require\n"
4313 "#extension GL_ARB_shading_language_420pack: require\n"
4314 "\n"
4315 "layout(location=0) out vec4 color;\n"
4316 "void main(){\n"
4317 " color = vec4(1);\n"
4318 "}\n";
4319
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004320 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4321 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12004322
4323 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004324 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12004325 pipe.AddShader(&vs);
4326 pipe.AddShader(&fs);
4327
4328 pipe.AddVertexInputBindings(input_bindings, 2);
4329 pipe.AddVertexInputAttribs(&input_attrib, 1);
4330
Chris Forbes280ba2c2015-06-12 11:16:41 +12004331 VkDescriptorSetObj descriptorSet(m_device);
4332 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004333 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12004334
Tony Barbour5781e8f2015-08-04 16:23:11 -06004335 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12004336
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004337 if (!m_errorMonitor->DesiredMsgFound()) {
4338 FAIL() << "Did not receive Error 'Duplicate vertex input binding descriptions for binding 0'";
4339 m_errorMonitor->DumpFailureMsgs();
Chris Forbes280ba2c2015-06-12 11:16:41 +12004340 }
4341}
Chris Forbes8f68b562015-05-25 11:13:32 +12004342
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004343/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
4344 * rejects it. */
4345
4346TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
4347{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004348 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4349 "Attachment 0 not written by FS");
4350
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004351 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004352
4353 char const *vsSource =
4354 "#version 140\n"
4355 "#extension GL_ARB_separate_shader_objects: require\n"
4356 "#extension GL_ARB_shading_language_420pack: require\n"
4357 "\n"
4358 "void main(){\n"
4359 " gl_Position = vec4(1);\n"
4360 "}\n";
4361 char const *fsSource =
4362 "#version 140\n"
4363 "#extension GL_ARB_separate_shader_objects: require\n"
4364 "#extension GL_ARB_shading_language_420pack: require\n"
4365 "\n"
4366 "void main(){\n"
4367 "}\n";
4368
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004369 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4370 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004371
4372 VkPipelineObj pipe(m_device);
4373 pipe.AddShader(&vs);
4374 pipe.AddShader(&fs);
4375
Chia-I Wu08accc62015-07-07 11:50:03 +08004376 /* set up CB 0, not written */
4377 pipe.AddColorAttachment();
4378 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004379
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004380 VkDescriptorSetObj descriptorSet(m_device);
4381 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004382 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004383
Tony Barbour5781e8f2015-08-04 16:23:11 -06004384 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004385
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004386 if (!m_errorMonitor->DesiredMsgFound()) {
4387 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
4388 m_errorMonitor->DumpFailureMsgs();
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004389 }
4390}
4391
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004392TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
4393{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004394 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
4395 "FS writes to output location 1 with no matching attachment");
4396
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004397 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004398
4399 char const *vsSource =
4400 "#version 140\n"
4401 "#extension GL_ARB_separate_shader_objects: require\n"
4402 "#extension GL_ARB_shading_language_420pack: require\n"
4403 "\n"
4404 "void main(){\n"
4405 " gl_Position = vec4(1);\n"
4406 "}\n";
4407 char const *fsSource =
4408 "#version 140\n"
4409 "#extension GL_ARB_separate_shader_objects: require\n"
4410 "#extension GL_ARB_shading_language_420pack: require\n"
4411 "\n"
4412 "layout(location=0) out vec4 x;\n"
4413 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4414 "void main(){\n"
4415 " x = vec4(1);\n"
4416 " y = vec4(1);\n"
4417 "}\n";
4418
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004419 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4420 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004421
4422 VkPipelineObj pipe(m_device);
4423 pipe.AddShader(&vs);
4424 pipe.AddShader(&fs);
4425
Chia-I Wu08accc62015-07-07 11:50:03 +08004426 /* set up CB 0, not written */
4427 pipe.AddColorAttachment();
4428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004429 /* FS writes CB 1, but we don't configure it */
4430
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004431 VkDescriptorSetObj descriptorSet(m_device);
4432 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004433 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004434
Tony Barbour5781e8f2015-08-04 16:23:11 -06004435 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004436
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004437 if (!m_errorMonitor->DesiredMsgFound()) {
4438 FAIL() << "Did not receive Error 'FS writes to output location 1 with no matching attachment'";
4439 m_errorMonitor->DumpFailureMsgs();
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004440 }
4441}
4442
Chris Forbesa36d69e2015-05-25 11:13:44 +12004443TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4444{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004445 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4446 "does not match FS output type");
4447
Chris Forbesa36d69e2015-05-25 11:13:44 +12004448 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004449
4450 char const *vsSource =
4451 "#version 140\n"
4452 "#extension GL_ARB_separate_shader_objects: require\n"
4453 "#extension GL_ARB_shading_language_420pack: require\n"
4454 "\n"
4455 "void main(){\n"
4456 " gl_Position = vec4(1);\n"
4457 "}\n";
4458 char const *fsSource =
4459 "#version 140\n"
4460 "#extension GL_ARB_separate_shader_objects: require\n"
4461 "#extension GL_ARB_shading_language_420pack: require\n"
4462 "\n"
4463 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4464 "void main(){\n"
4465 " x = ivec4(1);\n"
4466 "}\n";
4467
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004468 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4469 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004470
4471 VkPipelineObj pipe(m_device);
4472 pipe.AddShader(&vs);
4473 pipe.AddShader(&fs);
4474
Chia-I Wu08accc62015-07-07 11:50:03 +08004475 /* set up CB 0; type is UNORM by default */
4476 pipe.AddColorAttachment();
4477 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004478
Chris Forbesa36d69e2015-05-25 11:13:44 +12004479 VkDescriptorSetObj descriptorSet(m_device);
4480 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004481 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004482
Tony Barbour5781e8f2015-08-04 16:23:11 -06004483 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004484
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004485 if (!m_errorMonitor->DesiredMsgFound()) {
4486 FAIL() << "Did not receive Error 'does not match FS output type'";
4487 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa36d69e2015-05-25 11:13:44 +12004488 }
4489}
Chris Forbes7b1b8932015-06-05 14:43:36 +12004490
Chris Forbes556c76c2015-08-14 12:04:59 +12004491TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4492{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004493 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4494 "not declared in pipeline layout");
4495
Chris Forbes556c76c2015-08-14 12:04:59 +12004496 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12004497
4498 char const *vsSource =
4499 "#version 140\n"
4500 "#extension GL_ARB_separate_shader_objects: require\n"
4501 "#extension GL_ARB_shading_language_420pack: require\n"
4502 "\n"
4503 "void main(){\n"
4504 " gl_Position = vec4(1);\n"
4505 "}\n";
4506 char const *fsSource =
4507 "#version 140\n"
4508 "#extension GL_ARB_separate_shader_objects: require\n"
4509 "#extension GL_ARB_shading_language_420pack: require\n"
4510 "\n"
4511 "layout(location=0) out vec4 x;\n"
4512 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4513 "void main(){\n"
4514 " x = vec4(bar.y);\n"
4515 "}\n";
4516
Chris Forbes556c76c2015-08-14 12:04:59 +12004517
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004518 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4519 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12004520
Chris Forbes556c76c2015-08-14 12:04:59 +12004521 VkPipelineObj pipe(m_device);
4522 pipe.AddShader(&vs);
4523 pipe.AddShader(&fs);
4524
4525 /* set up CB 0; type is UNORM by default */
4526 pipe.AddColorAttachment();
4527 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4528
4529 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004530 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12004531
4532 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4533
4534 /* should have generated an error -- pipeline layout does not
4535 * provide a uniform buffer in 0.0
4536 */
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004537 if (!m_errorMonitor->DesiredMsgFound()) {
4538 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
4539 m_errorMonitor->DumpFailureMsgs();
Chris Forbes556c76c2015-08-14 12:04:59 +12004540 }
4541}
4542
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004543#endif // SHADER_CHECKER_TESTS
4544
4545#if DEVICE_LIMITS_TESTS
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004546TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4547{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004548 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4549 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004550
4551 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004552
4553 // Create an image
4554 VkImage image;
4555
4556 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4557 const int32_t tex_width = 32;
4558 const int32_t tex_height = 32;
4559
4560 VkImageCreateInfo image_create_info = {};
4561 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4562 image_create_info.pNext = NULL;
4563 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4564 image_create_info.format = tex_format;
4565 image_create_info.extent.width = tex_width;
4566 image_create_info.extent.height = tex_height;
4567 image_create_info.extent.depth = 1;
4568 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004569 image_create_info.arrayLayers = 1;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004570 image_create_info.samples = 1;
4571 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4572 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4573 image_create_info.flags = 0;
4574
4575 // Introduce error by sending down a bogus width extent
4576 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004577 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004578
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004579 if (!m_errorMonitor->DesiredMsgFound()) {
4580 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable limits for format'";
4581 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004582 }
4583}
4584
4585TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4586{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004587 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4588 "CreateImage resource size exceeds allowable maximum");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004589
4590 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004591
4592 // Create an image
4593 VkImage image;
4594
4595 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4596 const int32_t tex_width = 32;
4597 const int32_t tex_height = 32;
4598
4599 VkImageCreateInfo image_create_info = {};
4600 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4601 image_create_info.pNext = NULL;
4602 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4603 image_create_info.format = tex_format;
4604 image_create_info.extent.width = tex_width;
4605 image_create_info.extent.height = tex_height;
4606 image_create_info.extent.depth = 1;
4607 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004608 image_create_info.arrayLayers = 1;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004609 image_create_info.samples = 1;
4610 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4611 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4612 image_create_info.flags = 0;
4613
4614 // Introduce error by sending down individually allowable values that result in a surface size
4615 // exceeding the device maximum
4616 image_create_info.extent.width = 8192;
4617 image_create_info.extent.height = 8192;
4618 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004619 image_create_info.arrayLayers = 4;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004620 image_create_info.samples = 2;
4621 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004622 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004623
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004624 if (!m_errorMonitor->DesiredMsgFound()) {
4625 FAIL() << "Did not receive Error 'CreateImage resource size exceeds allowable maximum'";
4626 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004627 }
4628}
4629
Mike Stroyana3082432015-09-25 13:39:21 -06004630TEST_F(VkLayerTest, UpdateBufferAlignment)
4631{
Mike Stroyana3082432015-09-25 13:39:21 -06004632 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4633
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004634 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4635 "dstOffset, is not a multiple of 4");
4636
Mike Stroyana3082432015-09-25 13:39:21 -06004637 ASSERT_NO_FATAL_FAILURE(InitState());
4638
4639 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4640 vk_testing::Buffer buffer;
4641 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4642
4643 BeginCommandBuffer();
4644 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004645 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004646 if (!m_errorMonitor->DesiredMsgFound()) {
4647 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
4648 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06004649 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004650
Mike Stroyana3082432015-09-25 13:39:21 -06004651 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004652 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4653 "dataSize, is not a multiple of 4");
4654
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004655 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004656
4657 if (!m_errorMonitor->DesiredMsgFound()) {
4658 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4659 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06004660 }
4661 EndCommandBuffer();
4662}
4663
4664TEST_F(VkLayerTest, FillBufferAlignment)
4665{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004666 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4667 "dstOffset, is not a multiple of 4");
Mike Stroyana3082432015-09-25 13:39:21 -06004668
4669 ASSERT_NO_FATAL_FAILURE(InitState());
4670
4671 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4672 vk_testing::Buffer buffer;
4673 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4674
4675 BeginCommandBuffer();
4676 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004677 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004678 if (!m_errorMonitor->DesiredMsgFound()) {
4679 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
4680 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06004681 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004682
Mike Stroyana3082432015-09-25 13:39:21 -06004683 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004684 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4685 "size, is not a multiple of 4");
4686
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004687 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004688
4689 if (!m_errorMonitor->DesiredMsgFound()) {
4690 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
4691 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06004692 }
4693 EndCommandBuffer();
4694}
4695
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004696#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12004697
Tobin Ehliscde08892015-09-22 10:11:37 -06004698#if IMAGE_TESTS
4699TEST_F(VkLayerTest, InvalidImageView)
4700{
Tobin Ehliscde08892015-09-22 10:11:37 -06004701 VkResult err;
4702
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004703 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4704 "vkCreateImageView called with baseMipLevel 10 ");
4705
Tobin Ehliscde08892015-09-22 10:11:37 -06004706 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -06004707
Mike Stroyana3082432015-09-25 13:39:21 -06004708 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehliscde08892015-09-22 10:11:37 -06004709 VkImage image;
4710
4711 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4712 const int32_t tex_width = 32;
4713 const int32_t tex_height = 32;
4714
4715 VkImageCreateInfo image_create_info = {};
4716 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4717 image_create_info.pNext = NULL;
4718 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4719 image_create_info.format = tex_format;
4720 image_create_info.extent.width = tex_width;
4721 image_create_info.extent.height = tex_height;
4722 image_create_info.extent.depth = 1;
4723 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004724 image_create_info.arrayLayers = 1;
Tobin Ehliscde08892015-09-22 10:11:37 -06004725 image_create_info.samples = 1;
4726 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4727 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4728 image_create_info.flags = 0;
4729
Chia-I Wuf7458c52015-10-26 21:10:41 +08004730 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -06004731 ASSERT_VK_SUCCESS(err);
4732
4733 VkImageViewCreateInfo image_view_create_info = {};
4734 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4735 image_view_create_info.image = image;
4736 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4737 image_view_create_info.format = tex_format;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004738 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehliscde08892015-09-22 10:11:37 -06004739 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004740 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004741 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06004742
4743 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004744 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -06004745
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004746 if (!m_errorMonitor->DesiredMsgFound()) {
4747 FAIL() << "Did not receive Error 'vkCreateImageView called with baseMipLevel 10...'";
4748 m_errorMonitor->DumpFailureMsgs();
Tobin Ehliscde08892015-09-22 10:11:37 -06004749 }
4750}
Mike Stroyana3082432015-09-25 13:39:21 -06004751
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004752TEST_F(VkLayerTest, InvalidImageViewAspect)
4753{
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004754 VkResult err;
4755
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004756 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4757 "vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set");
4758
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004759 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004760
4761 // Create an image and try to create a view with an invalid aspectMask
4762 VkImage image;
4763
4764 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4765 const int32_t tex_width = 32;
4766 const int32_t tex_height = 32;
4767
4768 VkImageCreateInfo image_create_info = {};
4769 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4770 image_create_info.pNext = NULL;
4771 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4772 image_create_info.format = tex_format;
4773 image_create_info.extent.width = tex_width;
4774 image_create_info.extent.height = tex_height;
4775 image_create_info.extent.depth = 1;
4776 image_create_info.mipLevels = 1;
4777 image_create_info.samples = 1;
4778 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4779 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4780 image_create_info.flags = 0;
4781
Chia-I Wuf7458c52015-10-26 21:10:41 +08004782 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004783 ASSERT_VK_SUCCESS(err);
4784
4785 VkImageViewCreateInfo image_view_create_info = {};
4786 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4787 image_view_create_info.image = image;
4788 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4789 image_view_create_info.format = tex_format;
4790 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004791 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004792 // Cause an error by setting an invalid image aspect
4793 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
4794
4795 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004796 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004797
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004798 if (!m_errorMonitor->DesiredMsgFound()) {
4799 FAIL() << "Did not receive Error 'VkCreateImageView: Color image formats must have ...'";
4800 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004801 }
4802}
4803
Mike Stroyana3082432015-09-25 13:39:21 -06004804TEST_F(VkLayerTest, CopyImageTypeMismatch)
4805{
Mike Stroyana3082432015-09-25 13:39:21 -06004806 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004807 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004808
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004809 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4810 "vkCmdCopyImage called with unmatched source and dest image types");
4811
Mike Stroyana3082432015-09-25 13:39:21 -06004812 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06004813
4814 // Create two images of different types and try to copy between them
4815 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004816 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06004817 VkDeviceMemory srcMem;
4818 VkDeviceMemory destMem;
4819 VkMemoryRequirements memReqs;
4820
4821 VkImageCreateInfo image_create_info = {};
4822 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4823 image_create_info.pNext = NULL;
4824 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4825 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4826 image_create_info.extent.width = 32;
4827 image_create_info.extent.height = 32;
4828 image_create_info.extent.depth = 1;
4829 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004830 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004831 image_create_info.samples = 1;
4832 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004833 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004834 image_create_info.flags = 0;
4835
Chia-I Wuf7458c52015-10-26 21:10:41 +08004836 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06004837 ASSERT_VK_SUCCESS(err);
4838
4839 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004840 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004841
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004842 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06004843 ASSERT_VK_SUCCESS(err);
4844
4845 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004846 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06004847 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4848 memAlloc.pNext = NULL;
4849 memAlloc.allocationSize = 0;
4850 memAlloc.memoryTypeIndex = 0;
4851
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004852 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004853 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004854 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4855 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004856 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06004857 ASSERT_VK_SUCCESS(err);
4858
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004859 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004860 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004861 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06004862 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004863 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06004864 ASSERT_VK_SUCCESS(err);
4865
4866 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4867 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004868 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06004869 ASSERT_VK_SUCCESS(err);
4870
4871 BeginCommandBuffer();
4872 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08004873 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004874 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004875 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004876 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004877 copyRegion.srcOffset.x = 0;
4878 copyRegion.srcOffset.y = 0;
4879 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08004880 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004881 copyRegion.dstSubresource.mipLevel = 0;
4882 copyRegion.dstSubresource.baseArrayLayer = 0;
4883 copyRegion.dstSubresource.layerCount = 0;
4884 copyRegion.dstOffset.x = 0;
4885 copyRegion.dstOffset.y = 0;
4886 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004887 copyRegion.extent.width = 1;
4888 copyRegion.extent.height = 1;
4889 copyRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004890 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06004891 EndCommandBuffer();
4892
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004893 if (!m_errorMonitor->DesiredMsgFound()) {
4894 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
4895 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06004896 }
4897
Chia-I Wuf7458c52015-10-26 21:10:41 +08004898 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004899 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004900 vkFreeMemory(m_device->device(), srcMem, NULL);
4901 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06004902}
4903
4904TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
4905{
4906 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
4907}
4908
4909TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
4910{
Mike Stroyana3082432015-09-25 13:39:21 -06004911 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004912 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004913
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004914 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4915 "vkCmdCopyImage called with unmatched source and dest image types");
4916
Mike Stroyana3082432015-09-25 13:39:21 -06004917 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06004918
4919 // Create two images of different types and try to copy between them
4920 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004921 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06004922 VkDeviceMemory srcMem;
4923 VkDeviceMemory destMem;
4924 VkMemoryRequirements memReqs;
4925
4926 VkImageCreateInfo image_create_info = {};
4927 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4928 image_create_info.pNext = NULL;
4929 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4930 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4931 image_create_info.extent.width = 32;
4932 image_create_info.extent.height = 32;
4933 image_create_info.extent.depth = 1;
4934 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004935 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004936 image_create_info.samples = 1;
4937 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004938 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004939 image_create_info.flags = 0;
4940
Chia-I Wuf7458c52015-10-26 21:10:41 +08004941 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06004942 ASSERT_VK_SUCCESS(err);
4943
4944 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004945 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004946
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004947 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06004948 ASSERT_VK_SUCCESS(err);
4949
4950 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004951 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06004952 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4953 memAlloc.pNext = NULL;
4954 memAlloc.allocationSize = 0;
4955 memAlloc.memoryTypeIndex = 0;
4956
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004957 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004958 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004959 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4960 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004961 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06004962 ASSERT_VK_SUCCESS(err);
4963
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004964 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004965 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004966 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4967 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004968 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06004969 ASSERT_VK_SUCCESS(err);
4970
4971 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4972 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004973 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06004974 ASSERT_VK_SUCCESS(err);
4975
4976 BeginCommandBuffer();
4977 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08004978 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004979 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004980 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004981 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004982 copyRegion.srcOffset.x = 0;
4983 copyRegion.srcOffset.y = 0;
4984 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08004985 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004986 copyRegion.dstSubresource.mipLevel = 0;
4987 copyRegion.dstSubresource.baseArrayLayer = 0;
4988 copyRegion.dstSubresource.layerCount = 0;
4989 copyRegion.dstOffset.x = 0;
4990 copyRegion.dstOffset.y = 0;
4991 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004992 copyRegion.extent.width = 1;
4993 copyRegion.extent.height = 1;
4994 copyRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004995 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06004996 EndCommandBuffer();
4997
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004998 if (!m_errorMonitor->DesiredMsgFound()) {
4999 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5000 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005001 }
5002
Chia-I Wuf7458c52015-10-26 21:10:41 +08005003 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005004 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005005 vkFreeMemory(m_device->device(), srcMem, NULL);
5006 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005007}
5008
5009TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5010{
Mike Stroyana3082432015-09-25 13:39:21 -06005011 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005012 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005013
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005014 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5015 "vkCmdResolveImage called with source sample count less than 2.");
5016
Mike Stroyana3082432015-09-25 13:39:21 -06005017 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005018
5019 // Create two images of sample count 1 and try to Resolve between them
5020 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005021 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005022 VkDeviceMemory srcMem;
5023 VkDeviceMemory destMem;
5024 VkMemoryRequirements memReqs;
5025
5026 VkImageCreateInfo image_create_info = {};
5027 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5028 image_create_info.pNext = NULL;
5029 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5030 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5031 image_create_info.extent.width = 32;
5032 image_create_info.extent.height = 1;
5033 image_create_info.extent.depth = 1;
5034 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005035 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06005036 image_create_info.samples = 1;
5037 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005038 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005039 image_create_info.flags = 0;
5040
Chia-I Wuf7458c52015-10-26 21:10:41 +08005041 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005042 ASSERT_VK_SUCCESS(err);
5043
5044 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005045 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005046
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005047 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005048 ASSERT_VK_SUCCESS(err);
5049
5050 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005051 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06005052 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5053 memAlloc.pNext = NULL;
5054 memAlloc.allocationSize = 0;
5055 memAlloc.memoryTypeIndex = 0;
5056
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005057 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005058 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005059 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5060 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005061 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005062 ASSERT_VK_SUCCESS(err);
5063
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005064 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005065 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005066 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5067 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005068 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005069 ASSERT_VK_SUCCESS(err);
5070
5071 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5072 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005073 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005074 ASSERT_VK_SUCCESS(err);
5075
5076 BeginCommandBuffer();
5077 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5078 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5079 //VK_IMAGE_LAYOUT_GENERAL = 1,
5080 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005081 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005082 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005083 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005084 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005085 resolveRegion.srcOffset.x = 0;
5086 resolveRegion.srcOffset.y = 0;
5087 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005088 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005089 resolveRegion.dstSubresource.mipLevel = 0;
5090 resolveRegion.dstSubresource.baseArrayLayer = 0;
5091 resolveRegion.dstSubresource.layerCount = 0;
5092 resolveRegion.dstOffset.x = 0;
5093 resolveRegion.dstOffset.y = 0;
5094 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005095 resolveRegion.extent.width = 1;
5096 resolveRegion.extent.height = 1;
5097 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005098 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005099 EndCommandBuffer();
5100
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005101 if (!m_errorMonitor->DesiredMsgFound()) {
5102 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source sample count less than 2.'";
5103 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005104 }
5105
Chia-I Wuf7458c52015-10-26 21:10:41 +08005106 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005107 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005108 vkFreeMemory(m_device->device(), srcMem, NULL);
5109 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005110}
5111
5112TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5113{
Mike Stroyana3082432015-09-25 13:39:21 -06005114 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005115 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005116
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005117 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5118 "vkCmdResolveImage called with dest sample count greater than 1.");
5119
Mike Stroyana3082432015-09-25 13:39:21 -06005120 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005121
5122 // Create two images of sample count 2 and try to Resolve between them
5123 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005124 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005125 VkDeviceMemory srcMem;
5126 VkDeviceMemory destMem;
5127 VkMemoryRequirements memReqs;
5128
5129 VkImageCreateInfo image_create_info = {};
5130 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5131 image_create_info.pNext = NULL;
5132 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5133 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5134 image_create_info.extent.width = 32;
5135 image_create_info.extent.height = 1;
5136 image_create_info.extent.depth = 1;
5137 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005138 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06005139 image_create_info.samples = 2;
5140 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06005141 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005142 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005143 image_create_info.flags = 0;
5144
Chia-I Wuf7458c52015-10-26 21:10:41 +08005145 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005146 ASSERT_VK_SUCCESS(err);
5147
5148 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northrop72458c02015-10-27 13:50:04 -06005149 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005150 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005151
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005152 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005153 ASSERT_VK_SUCCESS(err);
5154
5155 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005156 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06005157 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5158 memAlloc.pNext = NULL;
5159 memAlloc.allocationSize = 0;
5160 memAlloc.memoryTypeIndex = 0;
5161
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005162 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005163 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005164 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5165 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005166 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005167 ASSERT_VK_SUCCESS(err);
5168
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005169 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005170 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005171 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5172 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005173 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005174 ASSERT_VK_SUCCESS(err);
5175
5176 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5177 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005178 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005179 ASSERT_VK_SUCCESS(err);
5180
5181 BeginCommandBuffer();
5182 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5183 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5184 //VK_IMAGE_LAYOUT_GENERAL = 1,
5185 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005186 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005187 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005188 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005189 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005190 resolveRegion.srcOffset.x = 0;
5191 resolveRegion.srcOffset.y = 0;
5192 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005193 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005194 resolveRegion.dstSubresource.mipLevel = 0;
5195 resolveRegion.dstSubresource.baseArrayLayer = 0;
5196 resolveRegion.dstSubresource.layerCount = 0;
5197 resolveRegion.dstOffset.x = 0;
5198 resolveRegion.dstOffset.y = 0;
5199 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005200 resolveRegion.extent.width = 1;
5201 resolveRegion.extent.height = 1;
5202 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005203 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005204 EndCommandBuffer();
5205
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005206 if (!m_errorMonitor->DesiredMsgFound()) {
5207 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest sample count greater than 1.'";
5208 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005209 }
5210
Chia-I Wuf7458c52015-10-26 21:10:41 +08005211 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005212 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005213 vkFreeMemory(m_device->device(), srcMem, NULL);
5214 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005215}
5216
5217TEST_F(VkLayerTest, ResolveImageFormatMismatch)
5218{
Mike Stroyana3082432015-09-25 13:39:21 -06005219 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005220 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005221
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005222 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5223 "vkCmdResolveImage called with unmatched source and dest formats.");
5224
Mike Stroyana3082432015-09-25 13:39:21 -06005225 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005226
5227 // Create two images of different types and try to copy between them
5228 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005229 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005230 VkDeviceMemory srcMem;
5231 VkDeviceMemory destMem;
5232 VkMemoryRequirements memReqs;
5233
5234 VkImageCreateInfo image_create_info = {};
5235 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5236 image_create_info.pNext = NULL;
5237 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5238 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5239 image_create_info.extent.width = 32;
5240 image_create_info.extent.height = 1;
5241 image_create_info.extent.depth = 1;
5242 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005243 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06005244 image_create_info.samples = 2;
5245 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06005246 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005247 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005248 image_create_info.flags = 0;
5249
Chia-I Wuf7458c52015-10-26 21:10:41 +08005250 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005251 ASSERT_VK_SUCCESS(err);
5252
Cody Northrop72458c02015-10-27 13:50:04 -06005253 // Set format to something other than source image
5254 image_create_info.format = VK_FORMAT_R32_SFLOAT;
5255 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005256 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005257 image_create_info.samples = 1;
5258
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005259 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005260 ASSERT_VK_SUCCESS(err);
5261
5262 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005263 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06005264 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5265 memAlloc.pNext = NULL;
5266 memAlloc.allocationSize = 0;
5267 memAlloc.memoryTypeIndex = 0;
5268
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005269 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005270 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005271 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5272 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005273 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005274 ASSERT_VK_SUCCESS(err);
5275
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005276 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005277 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005278 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5279 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005280 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005281 ASSERT_VK_SUCCESS(err);
5282
5283 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5284 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005285 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005286 ASSERT_VK_SUCCESS(err);
5287
5288 BeginCommandBuffer();
5289 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5290 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5291 //VK_IMAGE_LAYOUT_GENERAL = 1,
5292 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005293 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005294 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005295 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005296 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005297 resolveRegion.srcOffset.x = 0;
5298 resolveRegion.srcOffset.y = 0;
5299 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005300 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005301 resolveRegion.dstSubresource.mipLevel = 0;
5302 resolveRegion.dstSubresource.baseArrayLayer = 0;
5303 resolveRegion.dstSubresource.layerCount = 0;
5304 resolveRegion.dstOffset.x = 0;
5305 resolveRegion.dstOffset.y = 0;
5306 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005307 resolveRegion.extent.width = 1;
5308 resolveRegion.extent.height = 1;
5309 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005310 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005311 EndCommandBuffer();
5312
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005313 if (!m_errorMonitor->DesiredMsgFound()) {
5314 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest formats.'";
5315 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005316 }
5317
Chia-I Wuf7458c52015-10-26 21:10:41 +08005318 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005319 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005320 vkFreeMemory(m_device->device(), srcMem, NULL);
5321 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005322}
5323
5324TEST_F(VkLayerTest, ResolveImageTypeMismatch)
5325{
Mike Stroyana3082432015-09-25 13:39:21 -06005326 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005327 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005328
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005329 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5330 "vkCmdResolveImage called with unmatched source and dest image types.");
5331
Mike Stroyana3082432015-09-25 13:39:21 -06005332 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005333
5334 // Create two images of different types and try to copy between them
5335 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005336 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005337 VkDeviceMemory srcMem;
5338 VkDeviceMemory destMem;
5339 VkMemoryRequirements memReqs;
5340
5341 VkImageCreateInfo image_create_info = {};
5342 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5343 image_create_info.pNext = NULL;
5344 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5345 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5346 image_create_info.extent.width = 32;
5347 image_create_info.extent.height = 1;
5348 image_create_info.extent.depth = 1;
5349 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005350 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06005351 image_create_info.samples = 2;
5352 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06005353 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005354 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005355 image_create_info.flags = 0;
5356
Chia-I Wuf7458c52015-10-26 21:10:41 +08005357 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005358 ASSERT_VK_SUCCESS(err);
5359
5360 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northrop72458c02015-10-27 13:50:04 -06005361 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005362 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005363 image_create_info.samples = 1;
5364
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005365 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005366 ASSERT_VK_SUCCESS(err);
5367
5368 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005369 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06005370 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5371 memAlloc.pNext = NULL;
5372 memAlloc.allocationSize = 0;
5373 memAlloc.memoryTypeIndex = 0;
5374
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005375 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005376 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005377 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5378 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005379 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005380 ASSERT_VK_SUCCESS(err);
5381
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005382 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005383 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005384 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5385 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005386 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005387 ASSERT_VK_SUCCESS(err);
5388
5389 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5390 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005391 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005392 ASSERT_VK_SUCCESS(err);
5393
5394 BeginCommandBuffer();
5395 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5396 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5397 //VK_IMAGE_LAYOUT_GENERAL = 1,
5398 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005399 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005400 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005401 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005402 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005403 resolveRegion.srcOffset.x = 0;
5404 resolveRegion.srcOffset.y = 0;
5405 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005406 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005407 resolveRegion.dstSubresource.mipLevel = 0;
5408 resolveRegion.dstSubresource.baseArrayLayer = 0;
5409 resolveRegion.dstSubresource.layerCount = 0;
5410 resolveRegion.dstOffset.x = 0;
5411 resolveRegion.dstOffset.y = 0;
5412 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005413 resolveRegion.extent.width = 1;
5414 resolveRegion.extent.height = 1;
5415 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005416 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005417 EndCommandBuffer();
5418
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005419 if (!m_errorMonitor->DesiredMsgFound()) {
5420 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest image types.'";
5421 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005422 }
5423
Chia-I Wuf7458c52015-10-26 21:10:41 +08005424 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005425 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005426 vkFreeMemory(m_device->device(), srcMem, NULL);
5427 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005428}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005429
5430TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
5431{
5432 // Create a single Image descriptor and cause it to first hit an error due
5433 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
5434 // The image format check comes 2nd in validation so we trigger it first,
5435 // then when we cause aspect fail next, bad format check will be preempted
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005436 VkResult err;
5437
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005438 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5439 "Combination depth/stencil image formats can have only the ");
5440
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005441 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005442
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005443 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005444 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005445 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005446
5447 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5448 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5449 ds_pool_ci.pNext = NULL;
5450 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005451 ds_pool_ci.poolSizeCount = 1;
5452 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005453
5454 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005455 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005456 ASSERT_VK_SUCCESS(err);
5457
5458 VkDescriptorSetLayoutBinding dsl_binding = {};
5459 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5460 dsl_binding.arraySize = 1;
5461 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5462 dsl_binding.pImmutableSamplers = NULL;
5463
5464 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5465 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5466 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005467 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08005468 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005469 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005470 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005471 ASSERT_VK_SUCCESS(err);
5472
5473 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005474 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005475 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005476 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005477 alloc_info.descriptorPool = ds_pool;
5478 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005479 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005480 ASSERT_VK_SUCCESS(err);
5481
5482 VkImage image_bad;
5483 VkImage image_good;
5484 // One bad format and one good format for Color attachment
5485 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
5486 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
5487 const int32_t tex_width = 32;
5488 const int32_t tex_height = 32;
5489
5490 VkImageCreateInfo image_create_info = {};
5491 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5492 image_create_info.pNext = NULL;
5493 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5494 image_create_info.format = tex_format_bad;
5495 image_create_info.extent.width = tex_width;
5496 image_create_info.extent.height = tex_height;
5497 image_create_info.extent.depth = 1;
5498 image_create_info.mipLevels = 1;
5499 image_create_info.arrayLayers = 1;
5500 image_create_info.samples = 1;
5501 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5502 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
5503 image_create_info.flags = 0;
5504
Chia-I Wuf7458c52015-10-26 21:10:41 +08005505 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005506 ASSERT_VK_SUCCESS(err);
5507 image_create_info.format = tex_format_good;
5508 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005509 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005510 ASSERT_VK_SUCCESS(err);
5511
5512 VkImageViewCreateInfo image_view_create_info = {};
5513 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5514 image_view_create_info.image = image_bad;
5515 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5516 image_view_create_info.format = tex_format_bad;
5517 image_view_create_info.subresourceRange.baseArrayLayer = 0;
5518 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005519 image_view_create_info.subresourceRange.layerCount = 1;
5520 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005521 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5522
5523 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005524 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005525
5526 if (!m_errorMonitor->DesiredMsgFound()) {
5527 FAIL() << "Did not receive Error 'Combination depth-stencil image formats can have only the....'";
5528 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005529 }
5530
Chia-I Wuf7458c52015-10-26 21:10:41 +08005531 vkDestroyImage(m_device->device(), image_bad, NULL);
5532 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005533 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5534 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005535}
Tobin Ehliscde08892015-09-22 10:11:37 -06005536#endif // IMAGE_TESTS
5537
Tony Barbour300a6082015-04-07 13:44:53 -06005538int main(int argc, char **argv) {
5539 int result;
5540
5541 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06005542 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06005543
5544 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
5545
5546 result = RUN_ALL_TESTS();
5547
Tony Barbour6918cd52015-04-09 12:58:51 -06005548 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06005549 return result;
5550}