blob: 94ef3db7dcc8e6579f24b326f7b0157132af0128 [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
13#define OBJ_TRACKER_TESTS 1
14#define DRAW_STATE_TESTS 1
15#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120016#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060017#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060018#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060019
Mark Lobodzinski3780e142015-05-14 15:08:13 -050020//--------------------------------------------------------------------------------------
21// Mesh and VertexFormat Data
22//--------------------------------------------------------------------------------------
23struct Vertex
24{
25 float posX, posY, posZ, posW; // Position data
26 float r, g, b, a; // Color
27};
28
29#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
30
31typedef enum _BsoFailSelect {
32 BsoFailNone = 0x00000000,
Cody Northrop271ba752015-08-26 10:01:32 -060033 BsoFailLineWidth = 0x00000001,
34 BsoFailDepthBias = 0x00000002,
Cody Northrop12365112015-08-17 11:10:49 -060035 BsoFailViewport = 0x00000004,
Tobin Ehlis963a4042015-09-29 08:18:34 -060036 BsoFailScissor = 0x00000008,
37 BsoFailBlend = 0x00000010,
38 BsoFailDepthBounds = 0x00000020,
39 BsoFailStencilReadMask = 0x00000040,
40 BsoFailStencilWriteMask = 0x00000080,
41 BsoFailStencilReference = 0x00000100,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042} BsoFailSelect;
43
44struct vktriangle_vs_uniform {
45 // Must start with MVP
46 float mvp[4][4];
47 float position[3][4];
48 float color[3][4];
49};
50
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050051static const char bindStateVertShaderText[] =
Mark Lobodzinski3780e142015-05-14 15:08:13 -050052 "#version 130\n"
53 "vec2 vertices[3];\n"
54 "void main() {\n"
55 " vertices[0] = vec2(-1.0, -1.0);\n"
56 " vertices[1] = vec2( 1.0, -1.0);\n"
57 " vertices[2] = vec2( 0.0, 1.0);\n"
58 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
59 "}\n";
60
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050061static const char bindStateFragShaderText[] =
Cody Northrop8a3bb132015-06-16 17:32:04 -060062 "#version 140\n"
63 "#extension GL_ARB_separate_shader_objects: require\n"
64 "#extension GL_ARB_shading_language_420pack: require\n"
65 "\n"
66 "layout(location = 0) out vec4 uFragColor;\n"
67 "void main(){\n"
68 " uFragColor = vec4(0,1,0,1);\n"
69 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050070
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -060071static VkBool32 myDbgFunc(
Tony Barbour67e99152015-07-10 14:10:27 -060072 VkFlags msgFlags,
73 VkDbgObjectType objType,
74 uint64_t srcObject,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060075 size_t location,
76 int32_t msgCode,
77 const char* pLayerPrefix,
78 const char* pMsg,
79 void* pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -060080
81class ErrorMonitor {
82public:
Tony Barbour15524c32015-04-29 17:34:29 -060083 ErrorMonitor()
Tony Barbour300a6082015-04-07 13:44:53 -060084 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060085 test_platform_thread_create_mutex(&m_mutex);
86 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060087 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mike Stroyanaccf7692015-05-12 16:00:45 -060088 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -060089 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -060090 }
91 void ClearState()
92 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060093 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060094 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -060095 m_msgString.clear();
Mike Stroyan4268d1f2015-07-13 14:45:35 -060096 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -060097 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060098 VkFlags GetState(std::string *msgString)
Tony Barbour300a6082015-04-07 13:44:53 -060099 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600100 test_platform_thread_lock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600101 *msgString = m_msgString;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600102 test_platform_thread_unlock_mutex(&m_mutex);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600103 return m_msgFlags;
Tony Barbour300a6082015-04-07 13:44:53 -0600104 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600105 void SetState(VkFlags msgFlags, const char *msgString)
Tony Barbour300a6082015-04-07 13:44:53 -0600106 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600107 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600108 if (m_bailout != NULL) {
109 *m_bailout = true;
110 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600111 m_msgFlags = msgFlags;
Tony Barbour0b4d9562015-04-09 10:48:04 -0600112 m_msgString.reserve(strlen(msgString));
113 m_msgString = msgString;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600114 test_platform_thread_unlock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600115 }
116 void SetBailout(bool *bailout)
117 {
118 m_bailout = bailout;
Tony Barbour300a6082015-04-07 13:44:53 -0600119 }
120
121private:
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600122 VkFlags m_msgFlags;
123 std::string m_msgString;
124 test_platform_thread_mutex m_mutex;
125 bool* m_bailout;
Tony Barbour300a6082015-04-07 13:44:53 -0600126};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500127
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600128static VkBool32 myDbgFunc(
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600129 VkFlags msgFlags,
Tony Barbour67e99152015-07-10 14:10:27 -0600130 VkDbgObjectType objType,
131 uint64_t srcObject,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600132 size_t location,
133 int32_t msgCode,
134 const char* pLayerPrefix,
135 const char* pMsg,
136 void* pUserData)
Tony Barbour300a6082015-04-07 13:44:53 -0600137{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600138 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600139 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600140 errMonitor->SetState(msgFlags, pMsg);
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600141 return true;
Tony Barbour0b4d9562015-04-09 10:48:04 -0600142 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600143
144 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600145}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500146
Tony Barbour6918cd52015-04-09 12:58:51 -0600147class VkLayerTest : public VkRenderFramework
Tony Barbour300a6082015-04-07 13:44:53 -0600148{
149public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800150 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
151 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500152 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800153 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600154 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800155 { GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour300a6082015-04-07 13:44:53 -0600156
Tony Barbourfe3351b2015-07-28 10:17:20 -0600157 /* Convenience functions that use built-in command buffer */
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800158 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
159 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600160 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800161 { m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600162 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 +0800163 { m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); }
164 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
165 void QueueCommandBuffer(const VkFence& fence) { m_commandBuffer->QueueCommandBuffer(fence); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600166 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800167 { m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600168 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800169 { m_commandBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour300a6082015-04-07 13:44:53 -0600170protected:
Tony Barbour6918cd52015-04-09 12:58:51 -0600171 ErrorMonitor *m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600172
173 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600174 std::vector<const char *> instance_layer_names;
175 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600176 std::vector<const char *> instance_extension_names;
177 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600178
Courtney Goeltzenleuchter05159a92015-07-30 11:32:46 -0600179 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600180 /*
181 * Since CreateDbgMsgCallback is an instance level extension call
182 * any extension / layer that utilizes that feature also needs
183 * to be enabled at create instance time.
184 */
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800185 // Use Threading layer first to protect others from ThreadCommandBufferCollision test
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600186 instance_layer_names.push_back("Threading");
187 instance_layer_names.push_back("ObjectTracker");
188 instance_layer_names.push_back("MemTracker");
189 instance_layer_names.push_back("DrawState");
190 instance_layer_names.push_back("ShaderChecker");
Mark Lobodzinski209b5292015-09-17 09:44:05 -0600191 instance_layer_names.push_back("DeviceLimits");
Tobin Ehliscde08892015-09-22 10:11:37 -0600192 instance_layer_names.push_back("Image");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600193
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600194 device_layer_names.push_back("Threading");
195 device_layer_names.push_back("ObjectTracker");
196 device_layer_names.push_back("MemTracker");
197 device_layer_names.push_back("DrawState");
198 device_layer_names.push_back("ShaderChecker");
Mark Lobodzinski209b5292015-09-17 09:44:05 -0600199 device_layer_names.push_back("DeviceLimits");
Tobin Ehliscde08892015-09-22 10:11:37 -0600200 device_layer_names.push_back("Image");
Tony Barbour300a6082015-04-07 13:44:53 -0600201
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600202 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600203 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800204 this->app_info.pApplicationName = "layer_tests";
205 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600206 this->app_info.pEngineName = "unittest";
207 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600208 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour300a6082015-04-07 13:44:53 -0600209
Tony Barbour15524c32015-04-29 17:34:29 -0600210 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600211 InitFramework(instance_layer_names, device_layer_names,
212 instance_extension_names, device_extension_names,
213 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600214 }
215
216 virtual void TearDown() {
217 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600218 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600219 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600220 }
221};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500222
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800223VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour300a6082015-04-07 13:44:53 -0600224{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600225 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600226
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800227 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600228
229 /*
230 * For render test all drawing happens in a single render pass
231 * on a single command buffer.
232 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200233 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800234 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600235 }
236
237 return result;
238}
239
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800240VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour300a6082015-04-07 13:44:53 -0600241{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600242 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600243
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200244 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800245 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200246 }
Tony Barbour300a6082015-04-07 13:44:53 -0600247
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800248 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600249
250 return result;
251}
252
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500253void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
254{
255 // Create identity matrix
256 int i;
257 struct vktriangle_vs_uniform data;
258
259 glm::mat4 Projection = glm::mat4(1.0f);
260 glm::mat4 View = glm::mat4(1.0f);
261 glm::mat4 Model = glm::mat4(1.0f);
262 glm::mat4 MVP = Projection * View * Model;
263 const int matrixSize = sizeof(MVP);
264 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
265
266 memcpy(&data.mvp, &MVP[0][0], matrixSize);
267
268 static const Vertex tri_data[] =
269 {
270 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
271 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
272 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
273 };
274
275 for (i=0; i<3; i++) {
276 data.position[i][0] = tri_data[i].posX;
277 data.position[i][1] = tri_data[i].posY;
278 data.position[i][2] = tri_data[i].posZ;
279 data.position[i][3] = tri_data[i].posW;
280 data.color[i][0] = tri_data[i].r;
281 data.color[i][1] = tri_data[i].g;
282 data.color[i][2] = tri_data[i].b;
283 data.color[i][3] = tri_data[i].a;
284 }
285
286 ASSERT_NO_FATAL_FAILURE(InitState());
287 ASSERT_NO_FATAL_FAILURE(InitViewport());
288
289 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
290
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600291 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
292 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500293
294 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800295 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500296 pipelineobj.AddShader(&vs);
297 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600298 if (failMask & BsoFailLineWidth) {
299 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
300 }
301 if (failMask & BsoFailDepthBias) {
302 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
303 }
Tobin Ehlisd332f282015-10-02 11:00:56 -0600304 // Viewport and scissors must stay in synch or other errors will occur than the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600305 if (failMask & BsoFailViewport) {
306 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600307 m_viewports.clear();
308 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600309 }
310 if (failMask & BsoFailScissor) {
311 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600312 m_scissors.clear();
313 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600314 }
315 if (failMask & BsoFailBlend) {
316 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
317 }
318 if (failMask & BsoFailDepthBounds) {
319 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
320 }
321 if (failMask & BsoFailStencilReadMask) {
322 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
323 }
324 if (failMask & BsoFailStencilWriteMask) {
325 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
326 }
327 if (failMask & BsoFailStencilReference) {
328 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
329 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500330
331 VkDescriptorSetObj descriptorSet(m_device);
332 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
333
334 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600335 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500336
Tony Barbourfe3351b2015-07-28 10:17:20 -0600337 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500338
339 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600340 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500341
342 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600343 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500344
Tony Barbourfe3351b2015-07-28 10:17:20 -0600345 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500346}
347
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800348void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500349{
350 if (m_depthStencil->Initialized()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800351 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500352 } else {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800353 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500354 }
355
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800356 commandBuffer->PrepareAttachments();
Cody Northrop82485a82015-08-18 15:21:16 -0600357 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
358 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barboureb254902015-07-15 12:50:33 -0600359 VkStencilOpState stencil = {};
360 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600361 stencil.stencilPassOp = VK_STENCIL_OP_KEEP;
362 stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
363 stencil.stencilCompareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600364
365 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
366 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600367 ds_ci.pNext = NULL;
368 ds_ci.depthTestEnable = VK_FALSE;
369 ds_ci.depthWriteEnable = VK_TRUE;
370 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
371 ds_ci.depthBoundsTestEnable = VK_FALSE;
372 ds_ci.stencilTestEnable = VK_TRUE;
373 ds_ci.front = stencil;
374 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600375
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600376 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600377 pipelineobj.SetViewport(m_viewports);
378 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800379 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Cody Northrop29a08f22015-08-27 10:20:35 -0600380 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
381 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800382 commandBuffer->BindPipeline(pipelineobj);
383 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500384}
385
386// ********************************************************************************************************************
387// ********************************************************************************************************************
388// ********************************************************************************************************************
389// ********************************************************************************************************************
Tobin Ehlis0788f522015-05-26 16:11:58 -0600390#if MEM_TRACKER_TESTS
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800391TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500392{
393 vk_testing::Fence testFence;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600394 VkFlags msgFlags;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500395 std::string msgString;
396
397 VkFenceCreateInfo fenceInfo = {};
398 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
399 fenceInfo.pNext = NULL;
400 fenceInfo.flags = 0;
401
402 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -0600403
404 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
405 vk_testing::Buffer buffer;
406 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500407
Tony Barbourfe3351b2015-07-28 10:17:20 -0600408 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600410 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500411
412 testFence.init(*m_device, fenceInfo);
413
414 // Bypass framework since it does the waits automatically
415 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600416 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800417 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
418 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800419 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600420 submit_info.pWaitSemaphores = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800421 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800422 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800423 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600424 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600425
426 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500427 ASSERT_VK_SUCCESS( err );
428
429 m_errorMonitor->ClearState();
430 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800431 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500432
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600433 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600434 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling ResetCommandBuffer on an active Command Buffer";
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500435 if (!strstr(msgString.c_str(),"Resetting CB")) {
436 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
437 }
438}
439
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800440TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500441{
442 vk_testing::Fence testFence;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600443 VkFlags msgFlags;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500444 std::string msgString;
445
446 VkFenceCreateInfo fenceInfo = {};
447 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
448 fenceInfo.pNext = NULL;
449 fenceInfo.flags = 0;
450
451 ASSERT_NO_FATAL_FAILURE(InitState());
452 ASSERT_NO_FATAL_FAILURE(InitViewport());
453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
454
Tony Barbourfe3351b2015-07-28 10:17:20 -0600455 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800456 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600457 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500458
459 testFence.init(*m_device, fenceInfo);
460
461 // Bypass framework since it does the waits automatically
462 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600463 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800464 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
465 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800466 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600467 submit_info.pWaitSemaphores = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800468 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800469 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800470 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600471 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600472
473 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500474 ASSERT_VK_SUCCESS( err );
475
476 m_errorMonitor->ClearState();
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600477
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800478 VkCommandBufferBeginInfo info = {};
479 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
480 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600481 info.renderPass = VK_NULL_HANDLE;
482 info.subpass = 0;
483 info.framebuffer = VK_NULL_HANDLE;
484
485 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800486 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500487
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600488 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600489 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling BeginCommandBuffer on an active Command Buffer";
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500490 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
491 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
492 }
493}
494
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500495TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
496{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600497 VkFlags msgFlags;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500498 std::string msgString;
499 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600500 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500501
502 ASSERT_NO_FATAL_FAILURE(InitState());
503 m_errorMonitor->ClearState();
504
505 // Create an image, allocate memory, free it, and then try to bind it
506 VkImage image;
Mark Lobodzinski23065352015-05-29 09:32:35 -0500507 VkDeviceMemory mem;
508 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500509
510 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
511 const int32_t tex_width = 32;
512 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513
Tony Barboureb254902015-07-15 12:50:33 -0600514 VkImageCreateInfo image_create_info = {};
515 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
516 image_create_info.pNext = NULL;
517 image_create_info.imageType = VK_IMAGE_TYPE_2D;
518 image_create_info.format = tex_format;
519 image_create_info.extent.width = tex_width;
520 image_create_info.extent.height = tex_height;
521 image_create_info.extent.depth = 1;
522 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600523 image_create_info.arrayLayers = 1;
Tony Barboureb254902015-07-15 12:50:33 -0600524 image_create_info.samples = 1;
525 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
526 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
527 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600528
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800529 VkMemoryAllocateInfo mem_alloc = {};
Tony Barboureb254902015-07-15 12:50:33 -0600530 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
531 mem_alloc.pNext = NULL;
532 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500533 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -0600534 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500535
Chia-I Wuf7458c52015-10-26 21:10:41 +0800536 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500537 ASSERT_VK_SUCCESS(err);
538
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600539 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500540 image,
Mark Lobodzinski23065352015-05-29 09:32:35 -0500541 &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500542
Mark Lobodzinski23065352015-05-29 09:32:35 -0500543 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500544
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600545 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
546 if(!pass) { // If we can't find any unmappable memory this test doesn't make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +0800547 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -0600548 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -0600549 }
Mike Stroyan713b2d72015-08-04 10:49:29 -0600550
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500551 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800552 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500553 ASSERT_VK_SUCCESS(err);
554
555 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -0600556 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500557 ASSERT_VK_SUCCESS(err);
558
559 // Map memory as if to initialize the image
560 void *mappedAddress = NULL;
Mark Lobodzinski23065352015-05-29 09:32:35 -0500561 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500562
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600563 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600564 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to map memory not visible to CPU";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500565 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
566 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
567 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600568
Chia-I Wuf7458c52015-10-26 21:10:41 +0800569 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500570}
571
Tobin Ehlis2717d132015-07-10 18:25:07 -0600572// TODO : Is this test still valid. Not sure it is with updates to memory binding model
573// Verify and delete the test of fix the check
574//TEST_F(VkLayerTest, FreeBoundMemory)
575//{
576// VkFlags msgFlags;
577// std::string msgString;
578// VkResult err;
579//
580// ASSERT_NO_FATAL_FAILURE(InitState());
581// m_errorMonitor->ClearState();
582//
583// // Create an image, allocate memory, free it, and then try to bind it
584// VkImage image;
585// VkDeviceMemory mem;
586// VkMemoryRequirements mem_reqs;
587//
588// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
589// const int32_t tex_width = 32;
590// const int32_t tex_height = 32;
591//
592// const VkImageCreateInfo image_create_info = {
593// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
594// .pNext = NULL,
595// .imageType = VK_IMAGE_TYPE_2D,
596// .format = tex_format,
597// .extent = { tex_width, tex_height, 1 },
598// .mipLevels = 1,
599// .arraySize = 1,
600// .samples = 1,
601// .tiling = VK_IMAGE_TILING_LINEAR,
602// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
603// .flags = 0,
604// };
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800605// VkMemoryAllocateInfo mem_alloc = {
Tobin Ehlis2717d132015-07-10 18:25:07 -0600606// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
607// .pNext = NULL,
608// .allocationSize = 0,
609// .memoryTypeIndex = 0,
610// };
611//
Chia-I Wuf7458c52015-10-26 21:10:41 +0800612// err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis2717d132015-07-10 18:25:07 -0600613// ASSERT_VK_SUCCESS(err);
614//
615// err = vkGetImageMemoryRequirements(m_device->device(),
616// image,
617// &mem_reqs);
618// ASSERT_VK_SUCCESS(err);
619//
620// mem_alloc.allocationSize = mem_reqs.size;
621//
622// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
623// ASSERT_VK_SUCCESS(err);
624//
625// // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800626// err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis2717d132015-07-10 18:25:07 -0600627// ASSERT_VK_SUCCESS(err);
628//
629// // Bind memory to Image object
630// err = vkBindImageMemory(m_device->device(), image, mem, 0);
631// ASSERT_VK_SUCCESS(err);
632//
633// // Introduce validation failure, free memory while still bound to object
Chia-I Wuf7458c52015-10-26 21:10:41 +0800634// vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis2717d132015-07-10 18:25:07 -0600635// msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600636//
Cody Northropd2ad0342015-08-05 11:15:02 -0600637// ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an warning while tring to free bound memory";
Tobin Ehlis2717d132015-07-10 18:25:07 -0600638// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
639// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
640// }
641//}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500642
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500643TEST_F(VkLayerTest, RebindMemory)
644{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600645 VkFlags msgFlags;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500646 std::string msgString;
647 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600648 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500649
650 ASSERT_NO_FATAL_FAILURE(InitState());
651 m_errorMonitor->ClearState();
652
653 // Create an image, allocate memory, free it, and then try to bind it
654 VkImage image;
655 VkDeviceMemory mem1;
656 VkDeviceMemory mem2;
657 VkMemoryRequirements mem_reqs;
658
659 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
660 const int32_t tex_width = 32;
661 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500662
Tony Barboureb254902015-07-15 12:50:33 -0600663 VkImageCreateInfo image_create_info = {};
664 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
665 image_create_info.pNext = NULL;
666 image_create_info.imageType = VK_IMAGE_TYPE_2D;
667 image_create_info.format = tex_format;
668 image_create_info.extent.width = tex_width;
669 image_create_info.extent.height = tex_height;
670 image_create_info.extent.depth = 1;
671 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600672 image_create_info.arrayLayers = 1;
Tony Barboureb254902015-07-15 12:50:33 -0600673 image_create_info.samples = 1;
674 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
675 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
676 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500677
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800678 VkMemoryAllocateInfo mem_alloc = {};
Tony Barboureb254902015-07-15 12:50:33 -0600679 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
680 mem_alloc.pNext = NULL;
681 mem_alloc.allocationSize = 0;
682 mem_alloc.memoryTypeIndex = 0;
683
684 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
685 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800686 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500687 ASSERT_VK_SUCCESS(err);
688
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600689 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500690 image,
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500691 &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500692
693 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600694 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
695 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500696
697 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800698 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500699 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800700 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500701 ASSERT_VK_SUCCESS(err);
702
703 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -0600704 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500705 ASSERT_VK_SUCCESS(err);
706
707 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barbour67e99152015-07-10 14:10:27 -0600708 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500709
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600710 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600711 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to rebind an object";
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500712 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
713 FAIL() << "Error received did not match expected message when rebinding memory to an object";
714 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600715
Chia-I Wuf7458c52015-10-26 21:10:41 +0800716 vkDestroyImage(m_device->device(), image, NULL);
717 vkFreeMemory(m_device->device(), mem1, NULL);
718 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500719}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500720
Tony Barbour0b4d9562015-04-09 10:48:04 -0600721TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour300a6082015-04-07 13:44:53 -0600722{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600723 vk_testing::Fence testFence;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600724 VkFlags msgFlags;
Tony Barbour300a6082015-04-07 13:44:53 -0600725 std::string msgString;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600726
727 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600728 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
729 fenceInfo.pNext = NULL;
730 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -0600731
Tony Barbour300a6082015-04-07 13:44:53 -0600732 ASSERT_NO_FATAL_FAILURE(InitState());
733 ASSERT_NO_FATAL_FAILURE(InitViewport());
734 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
735
Tony Barbourfe3351b2015-07-28 10:17:20 -0600736 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800737 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600738 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600739
740 testFence.init(*m_device, fenceInfo);
741 m_errorMonitor->ClearState();
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600742
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600743 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800744 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
745 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800746 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600747 submit_info.pWaitSemaphores = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800748 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800749 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800750 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600751 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600752
753 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600754 vkQueueWaitIdle(m_device->m_queue );
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600755 msgFlags = m_errorMonitor->GetState(&msgString);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600756
Cody Northropd2ad0342015-08-05 11:15:02 -0600757 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err from using a fence in SIGNALED state in call to vkQueueSubmit";
Tony Barbour0b4d9562015-04-09 10:48:04 -0600758 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500759 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour0b4d9562015-04-09 10:48:04 -0600760 }
761
762}
763
764TEST_F(VkLayerTest, ResetUnsignaledFence)
765{
766 vk_testing::Fence testFence;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600767 VkFlags msgFlags;
Tony Barbour0b4d9562015-04-09 10:48:04 -0600768 std::string msgString;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600769 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600770 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
771 fenceInfo.pNext = NULL;
772
Tony Barbour0b4d9562015-04-09 10:48:04 -0600773 ASSERT_NO_FATAL_FAILURE(InitState());
774 testFence.init(*m_device, fenceInfo);
775 m_errorMonitor->ClearState();
Chia-I Wud9e8e822015-07-03 11:45:55 +0800776 VkFence fences[1] = {testFence.handle()};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600777 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600778 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisbcca3ce2015-10-01 10:14:48 -0600779 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_WARN_BIT)) << "Did not receive an error from submitting fence with UNSIGNALED state to vkResetFences";
Tony Barbour6918cd52015-04-09 12:58:51 -0600780 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500781 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour0b4d9562015-04-09 10:48:04 -0600782 }
Tony Barbour300a6082015-04-07 13:44:53 -0600783
784}
Tobin Ehlis41376e12015-07-03 08:45:14 -0600785
Chia-I Wu08accc62015-07-07 11:50:03 +0800786/* TODO: Update for changes due to bug-14075 tiling across render passes */
787#if 0
Tobin Ehlis41376e12015-07-03 08:45:14 -0600788TEST_F(VkLayerTest, InvalidUsageBits)
789{
790 // Initiate Draw w/o a PSO bound
791 VkFlags msgFlags;
792 std::string msgString;
793
794 ASSERT_NO_FATAL_FAILURE(InitState());
795 m_errorMonitor->ClearState();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800796 VkCommandBufferObj commandBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600797 BeginCommandBuffer();
Tobin Ehlis41376e12015-07-03 08:45:14 -0600798
799 const VkExtent3D e3d = {
800 .width = 128,
801 .height = 128,
802 .depth = 1,
803 };
804 const VkImageCreateInfo ici = {
805 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
806 .pNext = NULL,
807 .imageType = VK_IMAGE_TYPE_2D,
808 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
809 .extent = e3d,
810 .mipLevels = 1,
811 .arraySize = 1,
812 .samples = 1,
813 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -0600814 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlis41376e12015-07-03 08:45:14 -0600815 .flags = 0,
816 };
817
818 VkImage dsi;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800819 vkCreateImage(m_device->device(), &ici, NULL, &dsi);
Tobin Ehlis41376e12015-07-03 08:45:14 -0600820 VkDepthStencilView dsv;
821 const VkDepthStencilViewCreateInfo dsvci = {
822 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
823 .pNext = NULL,
824 .image = dsi,
825 .mipLevel = 0,
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600826 .baseArrayLayer = 0,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600827 .arraySize = 1,
828 .flags = 0,
829 };
Chia-I Wuf7458c52015-10-26 21:10:41 +0800830 vkCreateDepthStencilView(m_device->device(), &dsvci, NULL, &dsv);
Tobin Ehlis41376e12015-07-03 08:45:14 -0600831 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600832 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after attempting to create DSView w/ image lacking USAGE_DS_BIT flag";
Tobin Ehlis41376e12015-07-03 08:45:14 -0600833 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
834 FAIL() << "Error received was not 'Invalid usage flag for image...'";
835 }
836}
Mark Lobodzinski209b5292015-09-17 09:44:05 -0600837#endif // 0
838#endif // MEM_TRACKER_TESTS
839
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600840#if OBJ_TRACKER_TESTS
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600841TEST_F(VkLayerTest, PipelineNotBound)
842{
843 VkFlags msgFlags;
844 std::string msgString;
845 VkResult err;
846
847 ASSERT_NO_FATAL_FAILURE(InitState());
848 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
849 m_errorMonitor->ClearState();
850
851 VkDescriptorTypeCount ds_type_count = {};
852 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800853 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600854
855 VkDescriptorPoolCreateInfo ds_pool_ci = {};
856 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
857 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -0600858 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800859 ds_pool_ci.typeCount = 1;
860 ds_pool_ci.pTypeCounts = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600861
862 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800863 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600864 ASSERT_VK_SUCCESS(err);
865
866 VkDescriptorSetLayoutBinding dsl_binding = {};
867 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
868 dsl_binding.arraySize = 1;
869 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
870 dsl_binding.pImmutableSamplers = NULL;
871
872 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
873 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
874 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800875 ds_layout_ci.bindingCount = 1;
876 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600877
878 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800879 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600880 ASSERT_VK_SUCCESS(err);
881
882 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800883 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600884 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800885 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600886 alloc_info.descriptorPool = ds_pool;
887 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800888 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600889 ASSERT_VK_SUCCESS(err);
890
891 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
892 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
893 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800894 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600895 pipeline_layout_ci.pSetLayouts = &ds_layout;
896
897 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800898 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600899 ASSERT_VK_SUCCESS(err);
900
901 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
902
903 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800904 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600905
906 msgFlags = m_errorMonitor->GetState(&msgString);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800907 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CommandBuffer";
Tobin Ehlisec598302015-09-15 15:02:17 -0600908 if (!strstr(msgString.c_str(),"Invalid VkPipeline Object ")) {
909 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be' but instead it was '" << msgString.c_str() << "'";
910 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600911
Chia-I Wuf7458c52015-10-26 21:10:41 +0800912 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
913 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
914 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -0600915}
916
917TEST_F(VkLayerTest, BindInvalidMemory)
918{
919 VkFlags msgFlags;
920 std::string msgString;
921 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600922 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -0600923
924 ASSERT_NO_FATAL_FAILURE(InitState());
925 m_errorMonitor->ClearState();
926
927 // Create an image, allocate memory, free it, and then try to bind it
928 VkImage image;
929 VkDeviceMemory mem;
930 VkMemoryRequirements mem_reqs;
931
932 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
933 const int32_t tex_width = 32;
934 const int32_t tex_height = 32;
935
936 VkImageCreateInfo image_create_info = {};
937 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
938 image_create_info.pNext = NULL;
939 image_create_info.imageType = VK_IMAGE_TYPE_2D;
940 image_create_info.format = tex_format;
941 image_create_info.extent.width = tex_width;
942 image_create_info.extent.height = tex_height;
943 image_create_info.extent.depth = 1;
944 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600945 image_create_info.arrayLayers = 1;
Tobin Ehlisec598302015-09-15 15:02:17 -0600946 image_create_info.samples = 1;
947 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
948 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
949 image_create_info.flags = 0;
950
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800951 VkMemoryAllocateInfo mem_alloc = {};
Tobin Ehlisec598302015-09-15 15:02:17 -0600952 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
953 mem_alloc.pNext = NULL;
954 mem_alloc.allocationSize = 0;
955 mem_alloc.memoryTypeIndex = 0;
956
Chia-I Wuf7458c52015-10-26 21:10:41 +0800957 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -0600958 ASSERT_VK_SUCCESS(err);
959
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600960 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlisec598302015-09-15 15:02:17 -0600961 image,
962 &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -0600963
964 mem_alloc.allocationSize = mem_reqs.size;
965
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600966 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
967 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -0600968
969 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800970 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -0600971 ASSERT_VK_SUCCESS(err);
972
973 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +0800974 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -0600975
976 // Try to bind free memory that has been freed
977 err = vkBindImageMemory(m_device->device(), image, mem, 0);
978 // This may very well return an error.
979 (void)err;
980
981 msgFlags = m_errorMonitor->GetState(&msgString);
982 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to bind a freed memory object";
983 if (!strstr(msgString.c_str(),"Invalid VkDeviceMemory Object ")) {
984 FAIL() << "Error received from BindInvalidMemory was not 'Invalid VkDeviceMemory Object 0x<handle>' but instead '" << msgString.c_str() << "'";
985 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600986
Chia-I Wuf7458c52015-10-26 21:10:41 +0800987 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -0600988}
989
990TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
991{
992 VkFlags msgFlags;
993 std::string msgString;
994 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600995 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -0600996
997 ASSERT_NO_FATAL_FAILURE(InitState());
998 m_errorMonitor->ClearState();
999
1000 // Create an image object, allocate memory, destroy the object and then try to bind it
1001 VkImage image;
1002 VkDeviceMemory mem;
1003 VkMemoryRequirements mem_reqs;
1004
1005 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1006 const int32_t tex_width = 32;
1007 const int32_t tex_height = 32;
1008
1009 VkImageCreateInfo image_create_info = {};
1010 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1011 image_create_info.pNext = NULL;
1012 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1013 image_create_info.format = tex_format;
1014 image_create_info.extent.width = tex_width;
1015 image_create_info.extent.height = tex_height;
1016 image_create_info.extent.depth = 1;
1017 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06001018 image_create_info.arrayLayers = 1;
Tobin Ehlisec598302015-09-15 15:02:17 -06001019 image_create_info.samples = 1;
1020 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1021 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1022 image_create_info.flags = 0;
1023
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001024 VkMemoryAllocateInfo mem_alloc = {};
Tobin Ehlisec598302015-09-15 15:02:17 -06001025 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1026 mem_alloc.pNext = NULL;
1027 mem_alloc.allocationSize = 0;
1028 mem_alloc.memoryTypeIndex = 0;
1029
Chia-I Wuf7458c52015-10-26 21:10:41 +08001030 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06001031 ASSERT_VK_SUCCESS(err);
1032
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001033 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlisec598302015-09-15 15:02:17 -06001034 image,
1035 &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06001036
1037 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001038 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1039 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001040
1041 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001042 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001043 ASSERT_VK_SUCCESS(err);
1044
1045 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001046 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001047 ASSERT_VK_SUCCESS(err);
1048
1049 // Now Try to bind memory to this destroyed object
1050 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1051 // This may very well return an error.
1052 (void) err;
1053
1054 msgFlags = m_errorMonitor->GetState(&msgString);
1055 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while binding memory to a destroyed object";
1056 if (!strstr(msgString.c_str(),"Invalid VkImage Object ")) {
1057 FAIL() << "Error received from BindMemoryToDestroyedObject was not 'Invalid VkImage Object 0x<handle>' but rather '" << msgString.c_str() << "'";
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001058 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001059
Chia-I Wuf7458c52015-10-26 21:10:41 +08001060 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001061}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001062
1063TEST_F(VkLayerTest, InvalidBufferViewObject)
1064{
1065 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
1066 VkFlags msgFlags;
1067 std::string msgString;
1068 VkResult err;
1069
1070 ASSERT_NO_FATAL_FAILURE(InitState());
1071 m_errorMonitor->ClearState();
1072 VkDescriptorTypeCount ds_type_count = {};
1073 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001074 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001075
1076 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1077 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1078 ds_pool_ci.pNext = NULL;
1079 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001080 ds_pool_ci.typeCount = 1;
1081 ds_pool_ci.pTypeCounts = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001082
1083 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001084 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001085 ASSERT_VK_SUCCESS(err);
1086
1087 VkDescriptorSetLayoutBinding dsl_binding = {};
1088 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1089 dsl_binding.arraySize = 1;
1090 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1091 dsl_binding.pImmutableSamplers = NULL;
1092
1093 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1094 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1095 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001096 ds_layout_ci.bindingCount = 1;
1097 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001098 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001099 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001100 ASSERT_VK_SUCCESS(err);
1101
1102 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001103 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001104 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001105 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001106 alloc_info.descriptorPool = ds_pool;
1107 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001108 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001109 ASSERT_VK_SUCCESS(err);
1110
Chia-I Wue2fc5522015-10-26 20:04:44 +08001111 VkBufferView view = (VkBufferView) 0xbaadbeef; // invalid bufferView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001112
1113 VkWriteDescriptorSet descriptor_write;
1114 memset(&descriptor_write, 0, sizeof(descriptor_write));
1115 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001116 descriptor_write.dstSet = descriptorSet;
1117 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001118 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001119 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1120 descriptor_write.pTexelBufferView = &view;
1121
1122 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1123
1124 msgFlags = m_errorMonitor->GetState(&msgString);
1125 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid VkDescriptorBufferInfo.";
1126 if (!strstr(msgString.c_str(),"Invalid VkBufferView Object 0xbaadbeef")) {
1127 FAIL() << "Error received was not 'Invalid VkBufferView Object 0xbaadbeef' but instead '" << msgString.c_str() << "'";
1128 }
1129
Chia-I Wuf7458c52015-10-26 21:10:41 +08001130 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1131 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001132}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001133#endif // OBJ_TRACKER_TESTS
1134
Tobin Ehlis0788f522015-05-26 16:11:58 -06001135#if DRAW_STATE_TESTS
Tobin Ehlis963a4042015-09-29 08:18:34 -06001136TEST_F(VkLayerTest, LineWidthStateNotBound)
1137{
1138 VkFlags msgFlags;
1139 std::string msgString;
1140 m_errorMonitor->ClearState();
1141 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1142
1143 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1144
1145 msgFlags = m_errorMonitor->GetState(&msgString);
1146 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Line Width State Object";
1147 if (!strstr(msgString.c_str(),"Dynamic line width state not set for this command buffer")) {
1148 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic line width state not set for this command buffer'";
1149 }
1150}
1151
1152TEST_F(VkLayerTest, DepthBiasStateNotBound)
1153{
1154 VkFlags msgFlags;
1155 std::string msgString;
1156 m_errorMonitor->ClearState();
1157 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1158
1159 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1160
1161 msgFlags = m_errorMonitor->GetState(&msgString);
1162 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bias State Object";
1163 if (!strstr(msgString.c_str(),"Dynamic depth bias state not set for this command buffer")) {
1164 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bias state not set for this command buffer'";
1165 }
1166}
1167
Cody Northrop4063c9a2015-10-27 16:54:28 -06001168// Disable these two tests until we can sort out how to track multiple layer errors
1169#if 0
Tobin Ehlis963a4042015-09-29 08:18:34 -06001170TEST_F(VkLayerTest, ViewportStateNotBound)
1171{
1172 VkFlags msgFlags;
1173 std::string msgString;
1174 m_errorMonitor->ClearState();
1175 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1176
1177 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1178
1179 msgFlags = m_errorMonitor->GetState(&msgString);
1180 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06001181 // TODO : Viewport and scissor currently set as a pair in framework so scissor error masks viewport error
1182 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1183 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
Tobin Ehlis963a4042015-09-29 08:18:34 -06001184 }
1185}
1186
1187TEST_F(VkLayerTest, ScissorStateNotBound)
1188{
1189 VkFlags msgFlags;
1190 std::string msgString;
1191 m_errorMonitor->ClearState();
1192 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1193
1194 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1195
1196 msgFlags = m_errorMonitor->GetState(&msgString);
1197 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
1198 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1199 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
1200 }
1201}
Cody Northrop4063c9a2015-10-27 16:54:28 -06001202#endif
Tobin Ehlis963a4042015-09-29 08:18:34 -06001203
Tobin Ehlis963a4042015-09-29 08:18:34 -06001204TEST_F(VkLayerTest, BlendStateNotBound)
1205{
1206 VkFlags msgFlags;
1207 std::string msgString;
1208 m_errorMonitor->ClearState();
1209 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1210
1211 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1212
1213 msgFlags = m_errorMonitor->GetState(&msgString);
1214 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
1215 if (!strstr(msgString.c_str(),"Dynamic blend object state not set for this command buffer")) {
1216 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic blend object state not set for this command buffer'";
1217 }
1218}
1219
1220TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1221{
1222 VkFlags msgFlags;
1223 std::string msgString;
1224 m_errorMonitor->ClearState();
1225 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1226
1227 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1228
1229 msgFlags = m_errorMonitor->GetState(&msgString);
1230 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
1231 if (!strstr(msgString.c_str(),"Dynamic depth bounds state not set for this command buffer")) {
1232 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bounds state not set for this command buffer'";
1233 }
1234}
1235
1236TEST_F(VkLayerTest, StencilReadMaskNotSet)
1237{
1238 VkFlags msgFlags;
1239 std::string msgString;
1240 ASSERT_NO_FATAL_FAILURE(InitState());
1241 m_errorMonitor->ClearState();
1242 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1243
1244 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1245
1246 msgFlags = m_errorMonitor->GetState(&msgString);
1247 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Read Mask";
1248 if (!strstr(msgString.c_str(),"Dynamic stencil read mask state not set for this command buffer")) {
1249 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil read mask state not set for this command buffer'";
1250 }
1251}
1252
1253TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1254{
1255 VkFlags msgFlags;
1256 std::string msgString;
1257 ASSERT_NO_FATAL_FAILURE(InitState());
1258 m_errorMonitor->ClearState();
1259 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1260
1261 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1262
1263 msgFlags = m_errorMonitor->GetState(&msgString);
1264 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Write Mask";
1265 if (!strstr(msgString.c_str(),"Dynamic stencil write mask state not set for this command buffer")) {
1266 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil write mask state not set for this command buffer'";
1267 }
1268}
1269
1270TEST_F(VkLayerTest, StencilReferenceNotSet)
1271{
1272 VkFlags msgFlags;
1273 std::string msgString;
1274 m_errorMonitor->ClearState();
1275 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1276
1277 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1278
1279 msgFlags = m_errorMonitor->GetState(&msgString);
1280 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Reference";
1281 if (!strstr(msgString.c_str(),"Dynamic stencil reference state not set for this command buffer")) {
1282 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil reference state not set for this command buffer'";
1283 }
1284}
1285
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001286TEST_F(VkLayerTest, CommandBufferTwoSubmits)
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001287{
1288 vk_testing::Fence testFence;
1289 VkFlags msgFlags;
1290 std::string msgString;
1291
1292 VkFenceCreateInfo fenceInfo = {};
1293 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1294 fenceInfo.pNext = NULL;
1295 fenceInfo.flags = 0;
1296
1297 ASSERT_NO_FATAL_FAILURE(InitState());
1298 ASSERT_NO_FATAL_FAILURE(InitViewport());
1299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1300
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001301 // 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 -06001302 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001303 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001304 EndCommandBuffer();
1305
1306 testFence.init(*m_device, fenceInfo);
1307
1308 // Bypass framework since it does the waits automatically
1309 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001310 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001311 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1312 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001313 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001314 submit_info.pWaitSemaphores = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001315 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001316 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001317 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001318 submit_info.pSignalSemaphores = NULL;
1319
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001320 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001321 ASSERT_VK_SUCCESS( err );
1322
1323 m_errorMonitor->ClearState();
1324 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001325 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001326
1327 msgFlags = m_errorMonitor->GetState(&msgString);
1328 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after re-submitting Command Buffer that was created with one-time submit flag";
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001329 if (!strstr(msgString.c_str(),"was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted")) {
1330 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001331 }
1332}
1333
Tobin Ehlis502480b2015-06-24 15:53:07 -06001334TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001335{
1336 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001337 VkFlags msgFlags;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001338 std::string msgString;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001339 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001340
1341 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001342 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001343 m_errorMonitor->ClearState();
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001344
1345 VkDescriptorTypeCount ds_type_count = {};
1346 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001347 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001348
1349 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1350 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1351 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001352 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001353 ds_pool_ci.typeCount = 1;
1354 ds_pool_ci.pTypeCounts = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001355
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001356 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001357 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001358 ASSERT_VK_SUCCESS(err);
1359
1360 VkDescriptorSetLayoutBinding dsl_binding = {};
1361 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1362 dsl_binding.arraySize = 1;
1363 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1364 dsl_binding.pImmutableSamplers = NULL;
1365
1366 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1367 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1368 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001369 ds_layout_ci.bindingCount = 1;
1370 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001371
1372 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001373 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001374 ASSERT_VK_SUCCESS(err);
1375
1376 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001377 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001378 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001379 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001380 alloc_info.descriptorPool = ds_pool;
1381 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001382 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001383 ASSERT_VK_SUCCESS(err);
1384 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1385 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1386 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001387 pipe_ms_state_ci.rasterizationSamples = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001388 pipe_ms_state_ci.sampleShadingEnable = 0;
1389 pipe_ms_state_ci.minSampleShading = 1.0;
1390 pipe_ms_state_ci.pSampleMask = NULL;
1391
1392 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1393 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1394 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001395 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001396 pipeline_layout_ci.pSetLayouts = &ds_layout;
1397 VkPipelineLayout pipeline_layout;
1398
Chia-I Wuf7458c52015-10-26 21:10:41 +08001399 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001400 ASSERT_VK_SUCCESS(err);
1401
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001402 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1403 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 -06001404 // but add it to be able to run on more devices
1405 VkPipelineObj pipe(m_device);
1406 pipe.AddShader(&vs);
1407 pipe.AddShader(&fs);
1408 pipe.SetMSAA(&pipe_ms_state_ci);
1409 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1410 m_errorMonitor->ClearState();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001411 // Calls AllocateCommandBuffers
1412 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
1413 VkCommandBufferBeginInfo cmd_buf_info = {};
1414 memset(&cmd_buf_info, 0, sizeof(VkCommandBufferBeginInfo));
1415 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001416 cmd_buf_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001417 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001418
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001419 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
1420 vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001421 msgFlags = m_errorMonitor->GetState(&msgString);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001422 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding pipeline to CommandBuffer w/o active RenderPass";
Tobin Ehlis502480b2015-06-24 15:53:07 -06001423 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001424 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass' but rather '" << msgString.c_str() << "'";
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001425 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001426
Chia-I Wuf7458c52015-10-26 21:10:41 +08001427 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1428 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1429 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001430}
1431
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001432TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1433{
1434 // Initiate Draw w/o a PSO bound
1435 VkFlags msgFlags;
1436 std::string msgString;
1437 VkResult err;
1438
1439 ASSERT_NO_FATAL_FAILURE(InitState());
1440 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1441 m_errorMonitor->ClearState();
1442
1443 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
1444 VkDescriptorTypeCount ds_type_count = {};
1445 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001446 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001447
1448 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1449 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1450 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001451 ds_pool_ci.flags = 0;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001452 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001453 ds_pool_ci.typeCount = 1;
1454 ds_pool_ci.pTypeCounts = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001455
1456 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001457 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001458 ASSERT_VK_SUCCESS(err);
1459
1460 VkDescriptorSetLayoutBinding dsl_binding = {};
1461 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1462 dsl_binding.arraySize = 1;
1463 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1464 dsl_binding.pImmutableSamplers = NULL;
1465
1466 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1467 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1468 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001469 ds_layout_ci.bindingCount = 1;
1470 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001471
1472 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001473 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001474 ASSERT_VK_SUCCESS(err);
1475
1476 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001477 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001478 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001479 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001480 alloc_info.descriptorPool = ds_pool;
1481 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001482 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001483
1484 msgFlags = m_errorMonitor->GetState(&msgString);
1485 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after alloc descriptor from pool w/o requested type";
1486 if (!strstr(msgString.c_str(),"Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ")) {
1487 FAIL() << "Error received was not 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...' but rather '" << msgString.c_str() << "'";
1488 }
1489
Chia-I Wuf7458c52015-10-26 21:10:41 +08001490 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1491 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001492}
1493
Tobin Ehlise735c692015-10-08 13:13:50 -06001494TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1495{
1496 VkFlags msgFlags;
1497 std::string msgString;
1498 VkResult err;
1499
1500 ASSERT_NO_FATAL_FAILURE(InitState());
1501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1502 m_errorMonitor->ClearState();
1503
1504 VkDescriptorTypeCount ds_type_count = {};
1505 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001506 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06001507
1508 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1509 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1510 ds_pool_ci.pNext = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06001511 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001512 ds_pool_ci.typeCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001513 ds_pool_ci.flags = 0;
1514 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1515 // app can only call vkResetDescriptorPool on this pool.;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001516 ds_pool_ci.pTypeCounts = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06001517
1518 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001519 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06001520 ASSERT_VK_SUCCESS(err);
1521
1522 VkDescriptorSetLayoutBinding dsl_binding = {};
1523 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1524 dsl_binding.arraySize = 1;
1525 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1526 dsl_binding.pImmutableSamplers = NULL;
1527
1528 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1529 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1530 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001531 ds_layout_ci.bindingCount = 1;
1532 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06001533
1534 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001535 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06001536 ASSERT_VK_SUCCESS(err);
1537
1538 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001539 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001540 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001541 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001542 alloc_info.descriptorPool = ds_pool;
1543 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001544 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06001545 ASSERT_VK_SUCCESS(err);
1546
1547 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1548 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001549 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after freeing descriptor from non-free Pool";
1550
1551 if (!strstr(msgString.c_str(),"It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.")) {
Tobin Ehlise735c692015-10-08 13:13:50 -06001552 FAIL() << "Error received was not 'It is invalid to call vkFreeDescriptorSets() with a pool created with...' but instead it was '" << msgString.c_str() << "'";
1553 }
1554
Chia-I Wuf7458c52015-10-26 21:10:41 +08001555 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1556 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06001557}
1558
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001559TEST_F(VkLayerTest, InvalidDescriptorPool)
1560{
1561 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1562 // The DS check for this is after driver has been called to validate DS internal data struct
1563 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001564/* VkFlags msgFlags;
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001565 std::string msgString;
1566 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1567 vkResetDescriptorPool(device(), badPool);
1568
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001569 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001570 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Resetting an invalid DescriptorPool Object";
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001571 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1572 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1573 }*/
1574}
1575
1576TEST_F(VkLayerTest, InvalidDescriptorSet)
1577{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001578 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1579 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001580 // Create a valid cmd buffer
1581 // call vkCmdBindDescriptorSets w/ false DS
1582}
1583
1584TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1585{
1586 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1587 // The DS check for this is after driver has been called to validate DS internal data struct
1588}
1589
1590TEST_F(VkLayerTest, InvalidPipeline)
1591{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001592 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1593 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001594 // Create a valid cmd buffer
1595 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlis502480b2015-06-24 15:53:07 -06001596// VkFlags msgFlags;
1597// std::string msgString;
1598//
1599// ASSERT_NO_FATAL_FAILURE(InitState());
1600// m_errorMonitor->ClearState();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001601// VkCommandBufferObj commandBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001602// BeginCommandBuffer();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001603// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001604// vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlis502480b2015-06-24 15:53:07 -06001605// msgFlags = m_errorMonitor->GetState(&msgString);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001606// ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CommandBuffer";
Tobin Ehlis502480b2015-06-24 15:53:07 -06001607// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1608// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1609// }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001610}
1611
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001612TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001613{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001614 // Create and update CommandBuffer then call QueueSubmit w/o calling End on CommandBuffer
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001615 VkFlags msgFlags;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001616 std::string msgString;
1617 VkResult err;
1618
1619 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06001620 ASSERT_NO_FATAL_FAILURE(InitViewport());
1621 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001622 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06001623 VkDescriptorTypeCount ds_type_count = {};
1624 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001625 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001626
1627 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1628 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1629 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001630 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001631 ds_pool_ci.typeCount = 1;
1632 ds_pool_ci.pTypeCounts = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06001633
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001634 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001635 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001636 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001637
Tony Barboureb254902015-07-15 12:50:33 -06001638 VkDescriptorSetLayoutBinding dsl_binding = {};
1639 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1640 dsl_binding.arraySize = 1;
1641 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1642 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001643
Tony Barboureb254902015-07-15 12:50:33 -06001644 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1645 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1646 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001647 ds_layout_ci.bindingCount = 1;
1648 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001649 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001650 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001651 ASSERT_VK_SUCCESS(err);
1652
1653 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001654 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001655 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001656 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001657 alloc_info.descriptorPool = ds_pool;
1658 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001659 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001660 ASSERT_VK_SUCCESS(err);
1661
Tony Barboureb254902015-07-15 12:50:33 -06001662 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1663 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1664 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001665 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001666 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001667
1668 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001669 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001670 ASSERT_VK_SUCCESS(err);
1671
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001672 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1673 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 -06001674 // but add it to be able to run on more devices
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001675
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001676 VkPipelineObj pipe(m_device);
1677 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06001678 pipe.AddShader(&fs);
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001679 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001680
1681 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001682 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1683 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001684
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001685 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001686 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not warn after binding a DescriptorSet that was never updated.";
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001687 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1688 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1689 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001690
Chia-I Wuf7458c52015-10-26 21:10:41 +08001691 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1692 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1693 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001694}
1695
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001696TEST_F(VkLayerTest, NoBeginCommandBuffer)
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001697{
1698 VkFlags msgFlags;
1699 std::string msgString;
1700
1701 ASSERT_NO_FATAL_FAILURE(InitState());
1702 m_errorMonitor->ClearState();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001703 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001704 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001705 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001706 msgFlags = m_errorMonitor->GetState(&msgString);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001707 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after ending a CommandBuffer w/o calling BeginCommandBuffer()";
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001708 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1709 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1710 }
1711}
1712
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001713TEST_F(VkLayerTest, PrimaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001714{
1715 VkFlags msgFlags;
1716 std::string msgString;
1717
1718 ASSERT_NO_FATAL_FAILURE(InitState());
1719 m_errorMonitor->ClearState();
1720
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001721 // Calls AllocateCommandBuffers
1722 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001723
1724 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001725 VkCommandBufferBeginInfo cmd_buf_info = {};
1726 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06001727 cmd_buf_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001728 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northropb4569702015-08-04 17:35:57 -06001729 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1730 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1731
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001732
1733 // The error should be caught by validation of the BeginCommandBuffer call
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001734 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001735
1736 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001737 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing a non-NULL Framebuffer and Renderpass to BeginCommandBuffer()";
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001738 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001739 FAIL() << "Error received was not 'vkAllocateCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001740 }
1741}
1742
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001743TEST_F(VkLayerTest, SecondaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001744{
1745 VkFlags msgFlags;
1746 std::string msgString;
1747 VkResult err;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001748 VkCommandBuffer draw_cmd;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001749
1750 ASSERT_NO_FATAL_FAILURE(InitState());
1751 m_errorMonitor->ClearState();
1752
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001753 VkCommandBufferAllocateInfo cmd = {};
1754 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOC_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06001755 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001756 cmd.commandPool = m_commandPool;
1757 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001758 cmd.bufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06001759
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001760 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06001761 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001762
1763 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001764 VkCommandBufferBeginInfo cmd_buf_info = {};
1765 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06001766 cmd_buf_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001767 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001768
1769 // The error should be caught by validation of the BeginCommandBuffer call
1770 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1771
1772 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001773 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing NULL Framebuffer/Renderpass to BeginCommandBuffer()";
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001774 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001775 FAIL() << "Error received was not 'vkAllocateCommandBuffers(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001776 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001777 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001778}
1779
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001780TEST_F(VkLayerTest, InvalidPipelineCreateState)
1781{
1782 // Attempt to Create Gfx Pipeline w/o a VS
1783 VkFlags msgFlags;
1784 std::string msgString;
1785 VkResult err;
1786
1787 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001789 m_errorMonitor->ClearState();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001790
Tony Barboureb254902015-07-15 12:50:33 -06001791 VkDescriptorTypeCount ds_type_count = {};
1792 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001793 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001794
1795 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1796 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1797 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001798 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001799 ds_pool_ci.typeCount = 1;
1800 ds_pool_ci.pTypeCounts = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001801
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001802 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001803 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001804 ASSERT_VK_SUCCESS(err);
1805
Tony Barboureb254902015-07-15 12:50:33 -06001806 VkDescriptorSetLayoutBinding dsl_binding = {};
1807 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1808 dsl_binding.arraySize = 1;
1809 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1810 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001811
Tony Barboureb254902015-07-15 12:50:33 -06001812 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1813 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1814 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001815 ds_layout_ci.bindingCount = 1;
1816 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06001817
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001818 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001819 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001820 ASSERT_VK_SUCCESS(err);
1821
1822 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001823 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001824 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001825 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001826 alloc_info.descriptorPool = ds_pool;
1827 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001828 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001829 ASSERT_VK_SUCCESS(err);
1830
Tony Barboureb254902015-07-15 12:50:33 -06001831 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1832 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001833 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001834 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001835
1836 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001837 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001838 ASSERT_VK_SUCCESS(err);
1839
Tobin Ehlise68360f2015-10-01 11:15:13 -06001840 VkViewport vp = {}; // Just need dummy vp to point to
1841 VkRect2D sc = {}; // dummy scissor to point to
1842
1843 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1844 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1845 vp_state_ci.scissorCount = 1;
1846 vp_state_ci.pScissors = &sc;
1847 vp_state_ci.viewportCount = 1;
1848 vp_state_ci.pViewports = &vp;
1849
Tony Barboureb254902015-07-15 12:50:33 -06001850 VkGraphicsPipelineCreateInfo gp_ci = {};
1851 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06001852 gp_ci.pViewportState = &vp_state_ci;
Tony Barboureb254902015-07-15 12:50:33 -06001853 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1854 gp_ci.layout = pipeline_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001855 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06001856
1857 VkPipelineCacheCreateInfo pc_ci = {};
1858 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001859 pc_ci.initialDataSize = 0;
1860 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001861
1862 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06001863 VkPipelineCache pipelineCache;
1864
Chia-I Wuf7458c52015-10-26 21:10:41 +08001865 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06001866 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08001867 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001868
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001869 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001870 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o VS.";
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001871 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1872 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1873 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001874
Chia-I Wuf7458c52015-10-26 21:10:41 +08001875 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
1876 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1877 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1878 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001879}
Tobin Ehlis912df022015-09-17 08:46:18 -06001880/*// TODO : This test should be good, but needs Tess support in compiler to run
1881TEST_F(VkLayerTest, InvalidPatchControlPoints)
1882{
1883 // Attempt to Create Gfx Pipeline w/o a VS
1884 VkFlags msgFlags;
1885 std::string msgString;
1886 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001887
Tobin Ehlis912df022015-09-17 08:46:18 -06001888 ASSERT_NO_FATAL_FAILURE(InitState());
1889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1890 m_errorMonitor->ClearState();
1891
1892 VkDescriptorTypeCount ds_type_count = {};
1893 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001894 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06001895
1896 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1897 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1898 ds_pool_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001899 ds_pool_ci.typeCount = 1;
1900 ds_pool_ci.pTypeCounts = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06001901
1902 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001903 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 -06001904 ASSERT_VK_SUCCESS(err);
1905
1906 VkDescriptorSetLayoutBinding dsl_binding = {};
1907 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1908 dsl_binding.arraySize = 1;
1909 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1910 dsl_binding.pImmutableSamplers = NULL;
1911
1912 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1913 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1914 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001915 ds_layout_ci.bindingCount = 1;
1916 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06001917
1918 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001919 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06001920 ASSERT_VK_SUCCESS(err);
1921
1922 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001923 err = vkAllocateDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06001924 ASSERT_VK_SUCCESS(err);
1925
1926 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1927 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1928 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001929 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06001930 pipeline_layout_ci.pSetLayouts = &ds_layout;
1931
1932 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001933 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06001934 ASSERT_VK_SUCCESS(err);
1935
1936 VkPipelineShaderStageCreateInfo shaderStages[3];
1937 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1938
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001939 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06001940 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001941 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
1942 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06001943
1944 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001945 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001946 shaderStages[0].shader = vs.handle();
1947 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001948 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001949 shaderStages[1].shader = tc.handle();
1950 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001951 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001952 shaderStages[2].shader = te.handle();
1953
1954 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1955 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1956 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1957
1958 VkPipelineTessellationStateCreateInfo tsCI = {};
1959 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1960 tsCI.patchControlPoints = 0; // This will cause an error
1961
1962 VkGraphicsPipelineCreateInfo gp_ci = {};
1963 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1964 gp_ci.pNext = NULL;
1965 gp_ci.stageCount = 3;
1966 gp_ci.pStages = shaderStages;
1967 gp_ci.pVertexInputState = NULL;
1968 gp_ci.pInputAssemblyState = &iaCI;
1969 gp_ci.pTessellationState = &tsCI;
1970 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001971 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06001972 gp_ci.pMultisampleState = NULL;
1973 gp_ci.pDepthStencilState = NULL;
1974 gp_ci.pColorBlendState = NULL;
1975 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1976 gp_ci.layout = pipeline_layout;
1977 gp_ci.renderPass = renderPass();
1978
1979 VkPipelineCacheCreateInfo pc_ci = {};
1980 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1981 pc_ci.pNext = NULL;
1982 pc_ci.initialSize = 0;
1983 pc_ci.initialData = 0;
1984 pc_ci.maxSize = 0;
1985
1986 VkPipeline pipeline;
1987 VkPipelineCache pipelineCache;
1988
Chia-I Wuf7458c52015-10-26 21:10:41 +08001989 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06001990 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08001991 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06001992
1993 msgFlags = m_errorMonitor->GetState(&msgString);
1994 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Tess Gfx Pipeline w/ 0 patchControlPoints.";
1995 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ")) {
1996 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...' but instead '" << msgString.c_str() << "'";
1997 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001998
Chia-I Wuf7458c52015-10-26 21:10:41 +08001999 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2000 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2001 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2002 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06002003}
2004*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06002005// Set scissor and viewport counts to different numbers
2006TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2007{
2008 // Attempt to Create Gfx Pipeline w/o a VS
2009 VkFlags msgFlags;
2010 std::string msgString;
2011 VkResult err;
2012
2013 ASSERT_NO_FATAL_FAILURE(InitState());
2014 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2015 m_errorMonitor->ClearState();
2016
2017 VkDescriptorTypeCount ds_type_count = {};
2018 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002019 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002020
2021 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2022 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002023 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002024 ds_pool_ci.typeCount = 1;
2025 ds_pool_ci.pTypeCounts = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002026
2027 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002028 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002029 ASSERT_VK_SUCCESS(err);
2030
2031 VkDescriptorSetLayoutBinding dsl_binding = {};
2032 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2033 dsl_binding.arraySize = 1;
2034 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2035
2036 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2037 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002038 ds_layout_ci.bindingCount = 1;
2039 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002040
2041 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002042 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002043 ASSERT_VK_SUCCESS(err);
2044
2045 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002046 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002047 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002048 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002049 alloc_info.descriptorPool = ds_pool;
2050 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002051 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002052 ASSERT_VK_SUCCESS(err);
2053
2054 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2055 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002056 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002057 pipeline_layout_ci.pSetLayouts = &ds_layout;
2058
2059 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002060 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002061 ASSERT_VK_SUCCESS(err);
2062
2063 VkViewport vp = {}; // Just need dummy vp to point to
2064
2065 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2066 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2067 vp_state_ci.scissorCount = 0;
2068 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2069 vp_state_ci.pViewports = &vp;
2070
Cody Northropeb3a6c12015-10-05 14:44:45 -06002071 VkPipelineShaderStageCreateInfo shaderStages[2];
2072 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002073
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002074 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2075 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 -06002076 // but add it to be able to run on more devices
2077 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002078 shaderStages[0].shader = vs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002079
Cody Northropeb3a6c12015-10-05 14:44:45 -06002080 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002081 shaderStages[1].shader = fs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002082
2083 VkGraphicsPipelineCreateInfo gp_ci = {};
2084 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002085 gp_ci.stageCount = 2;
2086 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002087 gp_ci.pViewportState = &vp_state_ci;
2088 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2089 gp_ci.layout = pipeline_layout;
2090 gp_ci.renderPass = renderPass();
2091
2092 VkPipelineCacheCreateInfo pc_ci = {};
2093 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2094
2095 VkPipeline pipeline;
2096 VkPipelineCache pipelineCache;
2097
Chia-I Wuf7458c52015-10-26 21:10:41 +08002098 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002099 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002100 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002101
2102 msgFlags = m_errorMonitor->GetState(&msgString);
2103 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/ viewport and scissor count mismatch.";
2104 if (!strstr(msgString.c_str(),"Gfx Pipeline viewport count (1) must match scissor count (0).")) {
2105 FAIL() << "Error received was not 'Gfx Pipeline viewport count (1) must match scissor count (0).' but instead it was '" << msgString.c_str() << "'";
2106 }
2107
Chia-I Wuf7458c52015-10-26 21:10:41 +08002108 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2109 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2110 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2111 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002112}
Tobin Ehlisd332f282015-10-02 11:00:56 -06002113// Don't set viewport state in PSO. This is an error b/c we always need this state
2114// for the counts even if the data is going to be set dynamically.
2115TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002116{
2117 // Attempt to Create Gfx Pipeline w/o a VS
2118 VkFlags msgFlags;
2119 std::string msgString;
2120 VkResult err;
2121
2122 ASSERT_NO_FATAL_FAILURE(InitState());
2123 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2124 m_errorMonitor->ClearState();
2125
2126 VkDescriptorTypeCount ds_type_count = {};
2127 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002128 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002129
2130 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2131 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002132 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002133 ds_pool_ci.typeCount = 1;
2134 ds_pool_ci.pTypeCounts = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002135
2136 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002137 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002138 ASSERT_VK_SUCCESS(err);
2139
2140 VkDescriptorSetLayoutBinding dsl_binding = {};
2141 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2142 dsl_binding.arraySize = 1;
2143 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2144
2145 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2146 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002147 ds_layout_ci.bindingCount = 1;
2148 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002149
2150 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002151 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002152 ASSERT_VK_SUCCESS(err);
2153
2154 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002155 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002156 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002157 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002158 alloc_info.descriptorPool = ds_pool;
2159 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002160 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002161 ASSERT_VK_SUCCESS(err);
2162
2163 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2164 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002165 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002166 pipeline_layout_ci.pSetLayouts = &ds_layout;
2167
2168 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002169 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002170 ASSERT_VK_SUCCESS(err);
2171
2172 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2173 // Set scissor as dynamic to avoid second error
2174 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2175 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2176 dyn_state_ci.dynamicStateCount = 1;
2177 dyn_state_ci.pDynamicStates = &sc_state;
2178
Cody Northropeb3a6c12015-10-05 14:44:45 -06002179 VkPipelineShaderStageCreateInfo shaderStages[2];
2180 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002181
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002182 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2183 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 -06002184 // but add it to be able to run on more devices
2185 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002186 shaderStages[0].shader = vs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002187
Cody Northropeb3a6c12015-10-05 14:44:45 -06002188 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002189 shaderStages[1].shader = fs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002190
2191 VkGraphicsPipelineCreateInfo gp_ci = {};
2192 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002193 gp_ci.stageCount = 2;
2194 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002195 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2196 gp_ci.pDynamicState = &dyn_state_ci;
2197 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2198 gp_ci.layout = pipeline_layout;
2199 gp_ci.renderPass = renderPass();
2200
2201 VkPipelineCacheCreateInfo pc_ci = {};
2202 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2203
2204 VkPipeline pipeline;
2205 VkPipelineCache pipelineCache;
2206
Chia-I Wuf7458c52015-10-26 21:10:41 +08002207 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002208 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002209 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002210
2211 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002212 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o viewport state set.";
2213 if (!strstr(msgString.c_str(),"Gfx Pipeline pViewportState is null. Even if ")) {
2214 FAIL() << "Error received was not 'Gfx Pipeline pViewportState is null. Even if...' but instead it was '" << msgString.c_str() << "'";
Tobin Ehlise68360f2015-10-01 11:15:13 -06002215 }
2216
Chia-I Wuf7458c52015-10-26 21:10:41 +08002217 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2218 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2219 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2220 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002221}
2222// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002223// Then run second test where dynamic scissor count doesn't match PSO scissor count
2224TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002225{
2226 VkFlags msgFlags;
2227 std::string msgString;
2228 VkResult err;
2229
2230 ASSERT_NO_FATAL_FAILURE(InitState());
2231 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2232 m_errorMonitor->ClearState();
2233
2234 VkDescriptorTypeCount ds_type_count = {};
2235 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002236 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002237
2238 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2239 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002240 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002241 ds_pool_ci.typeCount = 1;
2242 ds_pool_ci.pTypeCounts = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002243
2244 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002245 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002246 ASSERT_VK_SUCCESS(err);
2247
2248 VkDescriptorSetLayoutBinding dsl_binding = {};
2249 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2250 dsl_binding.arraySize = 1;
2251 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2252
2253 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2254 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002255 ds_layout_ci.bindingCount = 1;
2256 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002257
2258 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002259 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002260 ASSERT_VK_SUCCESS(err);
2261
2262 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002263 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002264 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002265 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002266 alloc_info.descriptorPool = ds_pool;
2267 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002268 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002269 ASSERT_VK_SUCCESS(err);
2270
2271 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2272 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002273 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002274 pipeline_layout_ci.pSetLayouts = &ds_layout;
2275
2276 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002277 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002278 ASSERT_VK_SUCCESS(err);
2279
2280 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2281 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2282 vp_state_ci.viewportCount = 1;
2283 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2284 vp_state_ci.scissorCount = 1;
2285 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2286
2287 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2288 // Set scissor as dynamic to avoid that error
2289 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2290 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2291 dyn_state_ci.dynamicStateCount = 1;
2292 dyn_state_ci.pDynamicStates = &sc_state;
2293
Cody Northropeb3a6c12015-10-05 14:44:45 -06002294 VkPipelineShaderStageCreateInfo shaderStages[2];
2295 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002296
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002297 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2298 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 -06002299 // but add it to be able to run on more devices
2300 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002301 shaderStages[0].shader = vs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002302
Cody Northropeb3a6c12015-10-05 14:44:45 -06002303 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002304 shaderStages[1].shader = fs.handle();
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 = {};
Cody Northropf6622dc2015-10-06 10:33:21 -06002319 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2320 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
2350 msgFlags = m_errorMonitor->GetState(&msgString);
2351 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2352 if (!strstr(msgString.c_str(),"Gfx Pipeline viewportCount is 1, but pViewports is NULL. ")) {
2353 FAIL() << "Error received was not 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...' but instead it was '" << msgString.c_str() << "'";
2354 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002355 m_errorMonitor->ClearState();
2356 // 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
2358 VkViewport vp = {}; // Just need dummy vp to point to
2359 vp_state_ci.pViewports = &vp;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002360 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002361 ASSERT_VK_SUCCESS(err);
2362 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002363 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002364 VkRect2D scissors[2] = {}; // don't care about data
2365 // Count of 2 doesn't match PSO count of 1
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002366 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 2, scissors);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002367 Draw(1, 0, 0, 0);
2368
2369 msgFlags = m_errorMonitor->GetState(&msgString);
2370 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic scissorCount different from PSO scissorCount.";
2371 if (!strstr(msgString.c_str(),"Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.")) {
2372 FAIL() << "Error received was not 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...' but instead it was '" << msgString.c_str() << "'";
2373 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06002374
Chia-I Wuf7458c52015-10-26 21:10:41 +08002375 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2376 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2377 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2378 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002379}
2380// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002381// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2382TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002383{
2384 VkFlags msgFlags;
2385 std::string msgString;
2386 VkResult err;
2387
2388 ASSERT_NO_FATAL_FAILURE(InitState());
2389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2390 m_errorMonitor->ClearState();
2391
2392 VkDescriptorTypeCount ds_type_count = {};
2393 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002394 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002395
2396 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2397 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002398 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002399 ds_pool_ci.typeCount = 1;
2400 ds_pool_ci.pTypeCounts = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002401
2402 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002403 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002404 ASSERT_VK_SUCCESS(err);
2405
2406 VkDescriptorSetLayoutBinding dsl_binding = {};
2407 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2408 dsl_binding.arraySize = 1;
2409 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2410
2411 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2412 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002413 ds_layout_ci.bindingCount = 1;
2414 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002415
2416 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002417 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002418 ASSERT_VK_SUCCESS(err);
2419
2420 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002421 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002422 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002423 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002424 alloc_info.descriptorPool = ds_pool;
2425 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002426 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002427 ASSERT_VK_SUCCESS(err);
2428
2429 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2430 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002431 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002432 pipeline_layout_ci.pSetLayouts = &ds_layout;
2433
2434 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002435 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002436 ASSERT_VK_SUCCESS(err);
2437
2438 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2439 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2440 vp_state_ci.scissorCount = 1;
2441 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2442 vp_state_ci.viewportCount = 1;
2443 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2444
2445 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2446 // Set scissor as dynamic to avoid that error
2447 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2448 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2449 dyn_state_ci.dynamicStateCount = 1;
2450 dyn_state_ci.pDynamicStates = &vp_state;
2451
Cody Northropeb3a6c12015-10-05 14:44:45 -06002452 VkPipelineShaderStageCreateInfo shaderStages[2];
2453 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002454
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002455 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2456 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 -06002457 // but add it to be able to run on more devices
2458 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002459 shaderStages[0].shader = vs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002460
Cody Northropeb3a6c12015-10-05 14:44:45 -06002461 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002462 shaderStages[1].shader = fs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002463
Cody Northropf6622dc2015-10-06 10:33:21 -06002464 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2465 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2466 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002467 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002468 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002469 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002470 vi_ci.pVertexAttributeDescriptions = nullptr;
2471
2472 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2473 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2474 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2475
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002476 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Cody Northropf6622dc2015-10-06 10:33:21 -06002477 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2478 rs_ci.pNext = nullptr;
2479
2480 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2481 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2482 cb_ci.pNext = nullptr;
2483
Tobin Ehlise68360f2015-10-01 11:15:13 -06002484 VkGraphicsPipelineCreateInfo gp_ci = {};
2485 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002486 gp_ci.stageCount = 2;
2487 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06002488 gp_ci.pVertexInputState = &vi_ci;
2489 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002490 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002491 gp_ci.pRasterizationState = &rs_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06002492 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002493 gp_ci.pDynamicState = &dyn_state_ci;
2494 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2495 gp_ci.layout = pipeline_layout;
2496 gp_ci.renderPass = renderPass();
2497
2498 VkPipelineCacheCreateInfo pc_ci = {};
2499 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2500
2501 VkPipeline pipeline;
2502 VkPipelineCache pipelineCache;
2503
Chia-I Wuf7458c52015-10-26 21:10:41 +08002504 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002505 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002506 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002507
2508 msgFlags = m_errorMonitor->GetState(&msgString);
2509 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2510 if (!strstr(msgString.c_str(),"Gfx Pipeline scissorCount is 1, but pScissors is NULL. ")) {
2511 FAIL() << "Error received was not 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...' but instead it was '" << msgString.c_str() << "'";
2512 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002513 m_errorMonitor->ClearState();
2514 // Now hit second fail case where we set scissor w/ different count than PSO
2515 // First need to successfully create the PSO from above by setting pViewports
2516 VkRect2D sc = {}; // Just need dummy vp to point to
2517 vp_state_ci.pScissors = &sc;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002518 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002519 ASSERT_VK_SUCCESS(err);
2520 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002521 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002522 VkViewport viewports[2] = {}; // don't care about data
2523 // Count of 2 doesn't match PSO count of 1
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002524 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002525 Draw(1, 0, 0, 0);
2526
2527 msgFlags = m_errorMonitor->GetState(&msgString);
2528 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic viewportCount different from PSO viewportCount.";
2529 if (!strstr(msgString.c_str(),"Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.")) {
2530 FAIL() << "Error received was not 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...' but instead it was '" << msgString.c_str() << "'";
2531 }
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
2542 VkFlags msgFlags;
2543 std::string msgString;
2544
2545 ASSERT_NO_FATAL_FAILURE(InitState());
2546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2547 m_errorMonitor->ClearState();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002548
Tony Barbourfe3351b2015-07-28 10:17:20 -06002549 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002550 // Don't care about RenderPass handle b/c error should be flagged before that
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002551 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002552
2553 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002554 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002555 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
2556 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2557 }
2558}
2559
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002560TEST_F(VkLayerTest, RenderPassWithinRenderPass)
2561{
2562 // Bind a BeginRenderPass within an active RenderPass
2563 VkFlags msgFlags;
2564 std::string msgString;
2565
2566 ASSERT_NO_FATAL_FAILURE(InitState());
2567 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2568 m_errorMonitor->ClearState();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002569
Tony Barbourfe3351b2015-07-28 10:17:20 -06002570 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002571 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barboureb254902015-07-15 12:50:33 -06002572 VkRenderPassBeginInfo rp_begin = {};
2573 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
2574 rp_begin.pNext = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002575 rp_begin.renderPass = renderPass();
2576 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002577
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002578 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002579
2580 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002581 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002582 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2583 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002584 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002585}
2586
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002587TEST_F(VkLayerTest, FillBufferWithinRenderPass)
2588{
2589 // Call CmdFillBuffer within an active renderpass
2590 VkFlags msgFlags;
2591 std::string msgString;
2592
2593 ASSERT_NO_FATAL_FAILURE(InitState());
2594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2595 m_errorMonitor->ClearState();
2596
2597 // Renderpass is started here
2598 BeginCommandBuffer();
2599
2600 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002601 vk_testing::Buffer dstBuffer;
2602 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002603
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002604 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002605
2606 msgFlags = m_errorMonitor->GetState(&msgString);
2607 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2608 "Did not receive error after calling CmdFillBuffer w/i an active RenderPass.";
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002609 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2610 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002611 }
2612}
2613
2614TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
2615{
2616 // Call CmdUpdateBuffer within an active renderpass
2617 VkFlags msgFlags;
2618 std::string msgString;
2619
2620 ASSERT_NO_FATAL_FAILURE(InitState());
2621 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2622 m_errorMonitor->ClearState();
2623
2624 // Renderpass is started here
2625 BeginCommandBuffer();
2626
2627 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002628 vk_testing::Buffer dstBuffer;
2629 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002630
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002631 VkDeviceSize dstOffset = 0;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002632 VkDeviceSize dataSize = 1024;
2633 const uint32_t *pData = NULL;
2634
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002635 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002636
2637 msgFlags = m_errorMonitor->GetState(&msgString);
2638 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2639 "Did not receive error after calling CmdUpdateBuffer w/i an active RenderPass.";
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002640 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2641 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002642 }
2643}
2644
2645TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
2646{
2647 // Call CmdClearColorImage within an active RenderPass
2648 VkFlags msgFlags;
2649 std::string msgString;
2650
2651 ASSERT_NO_FATAL_FAILURE(InitState());
2652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2653 m_errorMonitor->ClearState();
2654
2655 // Renderpass is started here
2656 BeginCommandBuffer();
2657
2658 VkClearColorValue clear_color = {0};
2659 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2660 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2661 const int32_t tex_width = 32;
2662 const int32_t tex_height = 32;
2663 VkImageCreateInfo image_create_info = {};
2664 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2665 image_create_info.pNext = NULL;
2666 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2667 image_create_info.format = tex_format;
2668 image_create_info.extent.width = tex_width;
2669 image_create_info.extent.height = tex_height;
2670 image_create_info.extent.depth = 1;
2671 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06002672 image_create_info.arrayLayers = 1;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002673 image_create_info.samples = 1;
2674 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2675 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2676
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002677 vk_testing::Image dstImage;
2678 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002679
2680 const VkImageSubresourceRange range =
2681 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
2682
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002683 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(),
2684 dstImage.handle(),
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002685 VK_IMAGE_LAYOUT_GENERAL,
2686 &clear_color,
2687 1,
2688 &range);
2689
2690 msgFlags = m_errorMonitor->GetState(&msgString);
2691 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2692 "Did not receive error after calling CmdClearColorImage w/i an active RenderPass.";
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002693 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2694 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002695 }
2696}
2697
2698TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
2699{
2700 // Call CmdClearDepthStencilImage within an active RenderPass
2701 VkFlags msgFlags;
2702 std::string msgString;
2703
2704 ASSERT_NO_FATAL_FAILURE(InitState());
2705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2706 m_errorMonitor->ClearState();
2707
2708 // Renderpass is started here
2709 BeginCommandBuffer();
2710
2711 VkClearDepthStencilValue clear_value = {0};
2712 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2713 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
2714 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2715 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
2716 image_create_info.extent.width = 64;
2717 image_create_info.extent.height = 64;
2718 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2719 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2720
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002721 vk_testing::Image dstImage;
2722 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002723
2724 const VkImageSubresourceRange range =
2725 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
2726
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002727 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(),
2728 dstImage.handle(),
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002729 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2730 &clear_value,
2731 1,
2732 &range);
2733
2734 msgFlags = m_errorMonitor->GetState(&msgString);
2735 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2736 "Did not receive error after calling CmdClearDepthStencilImage w/i an active RenderPass.";
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002737 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2738 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002739 }
2740}
2741
2742TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
2743{
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002744 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002745 VkFlags msgFlags;
2746 std::string msgString;
2747 VkResult err;
2748
2749 ASSERT_NO_FATAL_FAILURE(InitState());
2750 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2751 m_errorMonitor->ClearState();
2752
2753 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002754 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002755 ASSERT_VK_SUCCESS(err);
2756
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002757 VkClearAttachment color_attachment;
2758 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2759 color_attachment.clearValue.color.float32[0] = 0;
2760 color_attachment.clearValue.color.float32[1] = 0;
2761 color_attachment.clearValue.color.float32[2] = 0;
2762 color_attachment.clearValue.color.float32[3] = 0;
2763 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06002764 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002765 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(),
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002766 1, &color_attachment,
2767 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002768
2769 msgFlags = m_errorMonitor->GetState(&msgString);
2770 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002771 "Did not receive error after calling CmdClearAttachments outside of an active RenderPass.";
2772 if (!strstr(msgString.c_str(),"vkCmdClearAttachments: This call must be issued inside an active render pass")) {
2773 FAIL() << "Error received was not 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002774 }
2775}
2776
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002777TEST_F(VkLayerTest, InvalidDynamicStateObject)
2778{
2779 // Create a valid cmd buffer
2780 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002781 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
2782 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002783}
Tobin Ehlis1056d452015-05-27 14:55:35 -06002784
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002785TEST_F(VkLayerTest, IdxBufferAlignmentError)
2786{
2787 // Bind a BeginRenderPass within an active RenderPass
2788 VkFlags msgFlags;
2789 std::string msgString;
2790 VkResult err;
2791
2792 ASSERT_NO_FATAL_FAILURE(InitState());
2793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2794 m_errorMonitor->ClearState();
2795 uint32_t qfi = 0;
2796 VkBufferCreateInfo buffCI = {};
2797 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2798 buffCI.size = 1024;
2799 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002800 buffCI.queueFamilyIndexCount = 1;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002801 buffCI.pQueueFamilyIndices = &qfi;
2802
2803 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002804 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002805 ASSERT_VK_SUCCESS(err);
2806
2807 BeginCommandBuffer();
2808 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002809 //vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002810 // Should error before calling to driver so don't care about actual data
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002811 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002812
2813 msgFlags = m_errorMonitor->GetState(&msgString);
2814 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2815 if (!strstr(msgString.c_str(),"vkCmdBindIndexBuffer() offset (0x7) does not fall on ")) {
2816 FAIL() << "Error received was not 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...' but instead '" << msgString.c_str() << "'";
2817 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002818
Chia-I Wuf7458c52015-10-26 21:10:41 +08002819 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002820}
2821
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06002822TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2823{
2824 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
2825 VkFlags msgFlags;
2826 std::string msgString;
2827
2828 ASSERT_NO_FATAL_FAILURE(InitState());
2829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2830 m_errorMonitor->ClearState();
2831
2832 BeginCommandBuffer();
2833 //ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002834 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
2835 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06002836
2837 msgFlags = m_errorMonitor->GetState(&msgString);
2838 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2839 if (!strstr(msgString.c_str(),"vkCmdExecuteCommands() called w/ Primary Cmd Buffer ")) {
2840 FAIL() << "Error received was not 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer ' but instead '" << msgString.c_str() << "'";
2841 }
2842}
2843
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002844TEST_F(VkLayerTest, DSTypeMismatch)
2845{
2846 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002847 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002848 std::string msgString;
2849 VkResult err;
2850
2851 ASSERT_NO_FATAL_FAILURE(InitState());
2852 m_errorMonitor->ClearState();
2853 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06002854 VkDescriptorTypeCount ds_type_count = {};
2855 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002856 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002857
2858 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2859 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2860 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002861 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002862 ds_pool_ci.typeCount = 1;
2863 ds_pool_ci.pTypeCounts = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06002864
Tobin Ehlis3b780662015-05-28 12:11:26 -06002865 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002866 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002867 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06002868 VkDescriptorSetLayoutBinding dsl_binding = {};
2869 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2870 dsl_binding.arraySize = 1;
2871 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2872 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002873
Tony Barboureb254902015-07-15 12:50:33 -06002874 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2875 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2876 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002877 ds_layout_ci.bindingCount = 1;
2878 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06002879
Tobin Ehlis3b780662015-05-28 12:11:26 -06002880 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002881 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002882 ASSERT_VK_SUCCESS(err);
2883
2884 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002885 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002886 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002887 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002888 alloc_info.descriptorPool = ds_pool;
2889 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002890 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002891 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002892
Tony Barboureb254902015-07-15 12:50:33 -06002893 VkSamplerCreateInfo sampler_ci = {};
2894 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2895 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08002896 sampler_ci.magFilter = VK_FILTER_NEAREST;
2897 sampler_ci.minFilter = VK_FILTER_NEAREST;
2898 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08002899 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2900 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2901 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06002902 sampler_ci.mipLodBias = 1.0;
2903 sampler_ci.maxAnisotropy = 1;
2904 sampler_ci.compareEnable = VK_FALSE;
2905 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2906 sampler_ci.minLod = 1.0;
2907 sampler_ci.maxLod = 1.0;
2908 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06002909 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2910
Tobin Ehlis3b780662015-05-28 12:11:26 -06002911 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002912 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002913 ASSERT_VK_SUCCESS(err);
2914
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002915 VkDescriptorImageInfo info = {};
2916 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002917
2918 VkWriteDescriptorSet descriptor_write;
2919 memset(&descriptor_write, 0, sizeof(descriptor_write));
2920 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002921 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002922 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002923 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002924 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002925 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002926
2927 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2928
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002929 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002930 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating BUFFER Descriptor w/ incorrect type of SAMPLER.";
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002931 if (!strstr(msgString.c_str(),"Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ")) {
2932 FAIL() << "Error received was not 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...' but instead '" << msgString.c_str() << "'";
Tobin Ehlis3b780662015-05-28 12:11:26 -06002933 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002934
Chia-I Wuf7458c52015-10-26 21:10:41 +08002935 vkDestroySampler(m_device->device(), sampler, NULL);
2936 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2937 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002938}
2939
2940TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2941{
2942 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002943 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002944 std::string msgString;
2945 VkResult err;
2946
2947 ASSERT_NO_FATAL_FAILURE(InitState());
2948 m_errorMonitor->ClearState();
2949 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06002950 VkDescriptorTypeCount ds_type_count = {};
2951 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002952 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002953
2954 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2955 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2956 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002957 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002958 ds_pool_ci.typeCount = 1;
2959 ds_pool_ci.pTypeCounts = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06002960
Tobin Ehlis3b780662015-05-28 12:11:26 -06002961 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002962 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002963 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002964
Tony Barboureb254902015-07-15 12:50:33 -06002965 VkDescriptorSetLayoutBinding dsl_binding = {};
2966 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2967 dsl_binding.arraySize = 1;
2968 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2969 dsl_binding.pImmutableSamplers = NULL;
2970
2971 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2972 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2973 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002974 ds_layout_ci.bindingCount = 1;
2975 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06002976
Tobin Ehlis3b780662015-05-28 12:11:26 -06002977 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002978 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002979 ASSERT_VK_SUCCESS(err);
2980
2981 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002982 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002983 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002984 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002985 alloc_info.descriptorPool = ds_pool;
2986 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002987 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002988 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002989
Tony Barboureb254902015-07-15 12:50:33 -06002990 VkSamplerCreateInfo sampler_ci = {};
2991 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2992 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08002993 sampler_ci.magFilter = VK_FILTER_NEAREST;
2994 sampler_ci.minFilter = VK_FILTER_NEAREST;
2995 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08002996 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2997 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2998 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06002999 sampler_ci.mipLodBias = 1.0;
3000 sampler_ci.maxAnisotropy = 1;
3001 sampler_ci.compareEnable = VK_FALSE;
3002 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3003 sampler_ci.minLod = 1.0;
3004 sampler_ci.maxLod = 1.0;
3005 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003006 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003007
Tobin Ehlis3b780662015-05-28 12:11:26 -06003008 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003009 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003010 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003011
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003012 VkDescriptorImageInfo info = {};
3013 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003014
3015 VkWriteDescriptorSet descriptor_write;
3016 memset(&descriptor_write, 0, sizeof(descriptor_write));
3017 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003018 descriptor_write.dstSet = descriptorSet;
3019 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08003020 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003021 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003022 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003023 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003024
3025 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3026
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003027 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003028 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ index out of bounds.";
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003029 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
3030 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
Tobin Ehlis3b780662015-05-28 12:11:26 -06003031 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003032
Chia-I Wuf7458c52015-10-26 21:10:41 +08003033 vkDestroySampler(m_device->device(), sampler, NULL);
3034 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3035 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003036}
3037
3038TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3039{
Tobin Ehlis3b780662015-05-28 12:11:26 -06003040 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003041 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003042 std::string msgString;
3043 VkResult err;
3044
3045 ASSERT_NO_FATAL_FAILURE(InitState());
3046 m_errorMonitor->ClearState();
3047 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06003048 VkDescriptorTypeCount ds_type_count = {};
3049 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003050 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003051
3052 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3053 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3054 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003055 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003056 ds_pool_ci.typeCount = 1;
3057 ds_pool_ci.pTypeCounts = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003058
Tobin Ehlis3b780662015-05-28 12:11:26 -06003059 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003060 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003061 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003062
Tony Barboureb254902015-07-15 12:50:33 -06003063 VkDescriptorSetLayoutBinding dsl_binding = {};
3064 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3065 dsl_binding.arraySize = 1;
3066 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3067 dsl_binding.pImmutableSamplers = NULL;
3068
3069 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3070 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3071 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003072 ds_layout_ci.bindingCount = 1;
3073 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003074 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003075 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003076 ASSERT_VK_SUCCESS(err);
3077
3078 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003079 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003080 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003081 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003082 alloc_info.descriptorPool = ds_pool;
3083 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003084 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003085 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003086
Tony Barboureb254902015-07-15 12:50:33 -06003087 VkSamplerCreateInfo sampler_ci = {};
3088 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3089 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003090 sampler_ci.magFilter = VK_FILTER_NEAREST;
3091 sampler_ci.minFilter = VK_FILTER_NEAREST;
3092 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003093 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3094 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3095 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003096 sampler_ci.mipLodBias = 1.0;
3097 sampler_ci.maxAnisotropy = 1;
3098 sampler_ci.compareEnable = VK_FALSE;
3099 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3100 sampler_ci.minLod = 1.0;
3101 sampler_ci.maxLod = 1.0;
3102 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003103 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003104
Tobin Ehlis3b780662015-05-28 12:11:26 -06003105 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003106 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003107 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003108
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003109 VkDescriptorImageInfo info = {};
3110 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003111
3112 VkWriteDescriptorSet descriptor_write;
3113 memset(&descriptor_write, 0, sizeof(descriptor_write));
3114 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003115 descriptor_write.dstSet = descriptorSet;
3116 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003117 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003118 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003119 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003120 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003121
3122 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3123
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003124 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003125 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ count too large for layout.";
Tobin Ehlis3b780662015-05-28 12:11:26 -06003126 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
3127 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
3128 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003129
Chia-I Wuf7458c52015-10-26 21:10:41 +08003130 vkDestroySampler(m_device->device(), sampler, NULL);
3131 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3132 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003133}
3134
3135TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3136{
3137 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003138 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003139 std::string msgString;
3140 VkResult err;
3141
3142 ASSERT_NO_FATAL_FAILURE(InitState());
3143 m_errorMonitor->ClearState();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003144
Tony Barboureb254902015-07-15 12:50:33 -06003145 VkDescriptorTypeCount ds_type_count = {};
3146 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003147 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003148
3149 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3150 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3151 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003152 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003153 ds_pool_ci.typeCount = 1;
3154 ds_pool_ci.pTypeCounts = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003155
Tobin Ehlis3b780662015-05-28 12:11:26 -06003156 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003157 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003158 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06003159 VkDescriptorSetLayoutBinding dsl_binding = {};
3160 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3161 dsl_binding.arraySize = 1;
3162 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3163 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003164
Tony Barboureb254902015-07-15 12:50:33 -06003165 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3166 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3167 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003168 ds_layout_ci.bindingCount = 1;
3169 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003170
Tobin Ehlis3b780662015-05-28 12:11:26 -06003171 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003172 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003173 ASSERT_VK_SUCCESS(err);
3174
3175 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003176 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003177 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003178 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003179 alloc_info.descriptorPool = ds_pool;
3180 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003181 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003182 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003183
Tony Barboureb254902015-07-15 12:50:33 -06003184 VkSamplerCreateInfo sampler_ci = {};
3185 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3186 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003187 sampler_ci.magFilter = VK_FILTER_NEAREST;
3188 sampler_ci.minFilter = VK_FILTER_NEAREST;
3189 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003190 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3191 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3192 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003193 sampler_ci.mipLodBias = 1.0;
3194 sampler_ci.maxAnisotropy = 1;
3195 sampler_ci.compareEnable = VK_FALSE;
3196 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3197 sampler_ci.minLod = 1.0;
3198 sampler_ci.maxLod = 1.0;
3199 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003200 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003201 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003202 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003203 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003204
3205
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003206 VkDescriptorImageInfo info = {};
3207 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003208
3209 VkWriteDescriptorSet descriptor_write;
3210 memset(&descriptor_write, 0, sizeof(descriptor_write));
3211 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003212 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003213 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003214 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003215 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003216 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003217
3218 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3219
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003220 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003221 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid struct type.";
Tobin Ehlis3b780662015-05-28 12:11:26 -06003222 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
3223 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
3224 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003225
Chia-I Wuf7458c52015-10-26 21:10:41 +08003226 vkDestroySampler(m_device->device(), sampler, NULL);
3227 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3228 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003229}
3230
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003231TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3232{
3233 // Create a single Sampler descriptor and send it an invalid Sampler
3234 VkFlags msgFlags;
3235 std::string msgString;
3236 VkResult err;
3237
3238 ASSERT_NO_FATAL_FAILURE(InitState());
3239 m_errorMonitor->ClearState();
3240 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
3241 VkDescriptorTypeCount ds_type_count = {};
3242 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003243 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003244
3245 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3246 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3247 ds_pool_ci.pNext = NULL;
3248 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003249 ds_pool_ci.typeCount = 1;
3250 ds_pool_ci.pTypeCounts = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003251
3252 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003253 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003254 ASSERT_VK_SUCCESS(err);
3255
3256 VkDescriptorSetLayoutBinding dsl_binding = {};
3257 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3258 dsl_binding.arraySize = 1;
3259 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3260 dsl_binding.pImmutableSamplers = NULL;
3261
3262 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3263 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3264 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003265 ds_layout_ci.bindingCount = 1;
3266 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003267 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003268 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003269 ASSERT_VK_SUCCESS(err);
3270
3271 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003272 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003273 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003274 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003275 alloc_info.descriptorPool = ds_pool;
3276 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003277 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003278 ASSERT_VK_SUCCESS(err);
3279
Chia-I Wue2fc5522015-10-26 20:04:44 +08003280 VkSampler sampler = (VkSampler) 0xbaadbeef; // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003281
3282 VkDescriptorImageInfo descriptor_info;
3283 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3284 descriptor_info.sampler = sampler;
3285
3286 VkWriteDescriptorSet descriptor_write;
3287 memset(&descriptor_write, 0, sizeof(descriptor_write));
3288 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003289 descriptor_write.dstSet = descriptorSet;
3290 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003291 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003292 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3293 descriptor_write.pImageInfo = &descriptor_info;
3294
3295 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3296
3297 msgFlags = m_errorMonitor->GetState(&msgString);
3298 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid VkSampler.";
3299 if (!strstr(msgString.c_str(),"Attempt to update descriptor with invalid sampler 0xbaadbeef")) {
3300 FAIL() << "Error received was not 'Attempt to update descriptor with invalid sampler...' but instead '" << msgString.c_str() << "'";
3301 }
3302
Chia-I Wuf7458c52015-10-26 21:10:41 +08003303 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3304 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003305}
3306
3307TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3308{
3309 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
3310 VkFlags msgFlags;
3311 std::string msgString;
3312 VkResult err;
3313
3314 ASSERT_NO_FATAL_FAILURE(InitState());
3315 m_errorMonitor->ClearState();
3316 VkDescriptorTypeCount ds_type_count = {};
3317 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003318 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003319
3320 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3321 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3322 ds_pool_ci.pNext = NULL;
3323 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003324 ds_pool_ci.typeCount = 1;
3325 ds_pool_ci.pTypeCounts = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003326
3327 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003328 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003329 ASSERT_VK_SUCCESS(err);
3330
3331 VkDescriptorSetLayoutBinding dsl_binding = {};
3332 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3333 dsl_binding.arraySize = 1;
3334 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3335 dsl_binding.pImmutableSamplers = NULL;
3336
3337 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3338 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3339 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003340 ds_layout_ci.bindingCount = 1;
3341 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003342 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003343 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003344 ASSERT_VK_SUCCESS(err);
3345
3346 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003347 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003348 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003349 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003350 alloc_info.descriptorPool = ds_pool;
3351 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003352 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003353 ASSERT_VK_SUCCESS(err);
3354
3355 VkSamplerCreateInfo sampler_ci = {};
3356 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3357 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003358 sampler_ci.magFilter = VK_FILTER_NEAREST;
3359 sampler_ci.minFilter = VK_FILTER_NEAREST;
3360 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003361 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3362 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3363 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003364 sampler_ci.mipLodBias = 1.0;
3365 sampler_ci.maxAnisotropy = 1;
3366 sampler_ci.compareEnable = VK_FALSE;
3367 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3368 sampler_ci.minLod = 1.0;
3369 sampler_ci.maxLod = 1.0;
3370 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3371 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3372
3373 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003374 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003375 ASSERT_VK_SUCCESS(err);
3376
Chia-I Wue2fc5522015-10-26 20:04:44 +08003377 VkImageView view = (VkImageView) 0xbaadbeef; // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003378
3379 VkDescriptorImageInfo descriptor_info;
3380 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3381 descriptor_info.sampler = sampler;
3382 descriptor_info.imageView = view;
3383
3384 VkWriteDescriptorSet descriptor_write;
3385 memset(&descriptor_write, 0, sizeof(descriptor_write));
3386 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003387 descriptor_write.dstSet = descriptorSet;
3388 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003389 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003390 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3391 descriptor_write.pImageInfo = &descriptor_info;
3392
3393 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3394
3395 msgFlags = m_errorMonitor->GetState(&msgString);
3396 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid VkImageView.";
3397 if (!strstr(msgString.c_str(),"Attempt to update descriptor with invalid imageView 0xbaadbeef")) {
3398 FAIL() << "Error received was not 'Attempt to update descriptor with invalid imageView...' but instead '" << msgString.c_str() << "'";
3399 }
3400
Chia-I Wuf7458c52015-10-26 21:10:41 +08003401 vkDestroySampler(m_device->device(), sampler, NULL);
3402 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3403 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003404}
3405
Tobin Ehlis04356f92015-10-27 16:35:27 -06003406TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
3407{
3408 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update into the other
3409 VkFlags msgFlags;
3410 std::string msgString;
3411 VkResult err;
3412
3413 ASSERT_NO_FATAL_FAILURE(InitState());
3414 m_errorMonitor->ClearState();
3415 //VkDescriptorSetObj descriptorSet(m_device);
3416 VkDescriptorTypeCount ds_type_count[2] = {};
3417 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003418 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003419 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003420 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003421
3422 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3423 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3424 ds_pool_ci.pNext = NULL;
3425 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003426 ds_pool_ci.typeCount = 2;
3427 ds_pool_ci.pTypeCounts = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003428
3429 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003430 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003431 ASSERT_VK_SUCCESS(err);
3432 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
3433 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3434 dsl_binding[0].arraySize = 1;
3435 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3436 dsl_binding[0].pImmutableSamplers = NULL;
3437 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3438 dsl_binding[1].arraySize = 1;
3439 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
3440 dsl_binding[1].pImmutableSamplers = NULL;
3441
3442 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3443 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3444 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003445 ds_layout_ci.bindingCount = 2;
3446 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003447
3448 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003449 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003450 ASSERT_VK_SUCCESS(err);
3451
3452 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003453 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis04356f92015-10-27 16:35:27 -06003454 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003455 alloc_info.setLayoutCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003456 alloc_info.descriptorPool = ds_pool;
3457 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003458 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003459 ASSERT_VK_SUCCESS(err);
3460
3461 VkSamplerCreateInfo sampler_ci = {};
3462 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3463 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003464 sampler_ci.magFilter = VK_FILTER_NEAREST;
3465 sampler_ci.minFilter = VK_FILTER_NEAREST;
3466 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003467 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3468 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3469 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003470 sampler_ci.mipLodBias = 1.0;
3471 sampler_ci.maxAnisotropy = 1;
3472 sampler_ci.compareEnable = VK_FALSE;
3473 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3474 sampler_ci.minLod = 1.0;
3475 sampler_ci.maxLod = 1.0;
3476 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3477 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3478
3479 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003480 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003481 ASSERT_VK_SUCCESS(err);
3482
3483 VkDescriptorImageInfo info = {};
3484 info.sampler = sampler;
3485
3486 VkWriteDescriptorSet descriptor_write;
3487 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
3488 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003489 descriptor_write.dstSet = descriptorSet;
3490 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08003491 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003492 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3493 descriptor_write.pImageInfo = &info;
3494 // This write update should succeed
3495 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3496 // Now perform a copy update that fails due to type mismatch
3497 VkCopyDescriptorSet copy_ds_update;
3498 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3499 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3500 copy_ds_update.srcSet = descriptorSet;
3501 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003502 copy_ds_update.dstSet = descriptorSet;
3503 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08003504 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06003505 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3506
3507 msgFlags = m_errorMonitor->GetState(&msgString);
3508 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after copying SAMPLER descriptor type to BUFFER descriptor type.";
3509 if (!strstr(msgString.c_str(),"Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ")) {
3510 FAIL() << "Error received was not 'Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER...' but instead '" << msgString.c_str() << "'";
3511 }
3512 // Now perform a copy update that fails due to binding out of bounds
3513 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3514 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3515 copy_ds_update.srcSet = descriptorSet;
3516 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003517 copy_ds_update.dstSet = descriptorSet;
3518 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003519 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06003520 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3521
3522 msgFlags = m_errorMonitor->GetState(&msgString);
3523 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after attempting descriptor copy update w/ bad srcBinding.";
3524 if (!strstr(msgString.c_str(),"Copy descriptor update 0 has srcBinding 3 which is out of bounds ")) {
3525 FAIL() << "Error received was not 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...' but instead '" << msgString.c_str() << "'";
3526 }
3527 // Now perform a copy update that fails due to binding out of bounds
3528 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3529 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3530 copy_ds_update.srcSet = descriptorSet;
3531 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003532 copy_ds_update.dstSet = descriptorSet;
3533 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003534 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06003535 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3536
3537 msgFlags = m_errorMonitor->GetState(&msgString);
3538 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after attempting descriptor copy update w/ count out of bounds for layout.";
3539 if (!strstr(msgString.c_str(),"Copy descriptor src update is out of bounds for matching binding 1 ")) {
3540 FAIL() << "Error received was not 'Copy descriptor src update is out of bounds for matching binding 1...' but instead '" << msgString.c_str() << "'";
3541 }
3542
Chia-I Wuf7458c52015-10-26 21:10:41 +08003543 vkDestroySampler(m_device->device(), sampler, NULL);
3544 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3545 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003546}
3547
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003548TEST_F(VkLayerTest, NumSamplesMismatch)
3549{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003550 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003551 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003552 std::string msgString;
3553 VkResult err;
3554
3555 ASSERT_NO_FATAL_FAILURE(InitState());
3556 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3557 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06003558 VkDescriptorTypeCount ds_type_count = {};
3559 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003560 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003561
3562 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003563 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3564 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003565 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003566 ds_pool_ci.typeCount = 1;
3567 ds_pool_ci.pTypeCounts = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003568
Tobin Ehlis3b780662015-05-28 12:11:26 -06003569 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003570 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003571 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003572
Tony Barboureb254902015-07-15 12:50:33 -06003573 VkDescriptorSetLayoutBinding dsl_binding = {};
3574 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3575 dsl_binding.arraySize = 1;
3576 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3577 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003578
Tony Barboureb254902015-07-15 12:50:33 -06003579 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3580 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3581 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003582 ds_layout_ci.bindingCount = 1;
3583 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003584
Tobin Ehlis3b780662015-05-28 12:11:26 -06003585 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003586 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003587 ASSERT_VK_SUCCESS(err);
3588
3589 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003590 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003591 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003592 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003593 alloc_info.descriptorPool = ds_pool;
3594 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003595 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003596 ASSERT_VK_SUCCESS(err);
3597
Tony Barboureb254902015-07-15 12:50:33 -06003598 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3599 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3600 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003601 pipe_ms_state_ci.rasterizationSamples = 4;
Tony Barboureb254902015-07-15 12:50:33 -06003602 pipe_ms_state_ci.sampleShadingEnable = 0;
3603 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003604 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003605
Tony Barboureb254902015-07-15 12:50:33 -06003606 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3607 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3608 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003609 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003610 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003611
3612 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003613 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003614 ASSERT_VK_SUCCESS(err);
3615
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003616 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3617 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 -06003618 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003619 VkPipelineObj pipe(m_device);
3620 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003621 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003622 pipe.SetMSAA(&pipe_ms_state_ci);
3623 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003624
Tony Barbourfe3351b2015-07-28 10:17:20 -06003625 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003626 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003627
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003628 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003629 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/ mismatched MSAA from PSO.";
Tobin Ehlis3b780662015-05-28 12:11:26 -06003630 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
3631 FAIL() << "Error received was not 'Num samples mismatch!...'";
3632 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003633
Chia-I Wuf7458c52015-10-26 21:10:41 +08003634 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3635 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3636 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003637}
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003638
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003639TEST_F(VkLayerTest, ClearCmdNoDraw)
3640{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003641 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003642 VkFlags msgFlags;
3643 std::string msgString;
3644 VkResult err;
3645
3646 ASSERT_NO_FATAL_FAILURE(InitState());
3647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3648 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06003649
3650 VkDescriptorTypeCount ds_type_count = {};
3651 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003652 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003653
3654 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3655 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3656 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003657 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003658 ds_pool_ci.typeCount = 1;
3659 ds_pool_ci.pTypeCounts = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06003660
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003661 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003662 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003663 ASSERT_VK_SUCCESS(err);
3664
Tony Barboureb254902015-07-15 12:50:33 -06003665 VkDescriptorSetLayoutBinding dsl_binding = {};
3666 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3667 dsl_binding.arraySize = 1;
3668 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3669 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003670
Tony Barboureb254902015-07-15 12:50:33 -06003671 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3672 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3673 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003674 ds_layout_ci.bindingCount = 1;
3675 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003676
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003677 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003678 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003679 ASSERT_VK_SUCCESS(err);
3680
3681 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003682 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003683 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003684 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003685 alloc_info.descriptorPool = ds_pool;
3686 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003687 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003688 ASSERT_VK_SUCCESS(err);
3689
Tony Barboureb254902015-07-15 12:50:33 -06003690 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3691 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3692 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003693 pipe_ms_state_ci.rasterizationSamples = 4;
Tony Barboureb254902015-07-15 12:50:33 -06003694 pipe_ms_state_ci.sampleShadingEnable = 0;
3695 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003696 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003697
Tony Barboureb254902015-07-15 12:50:33 -06003698 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3699 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3700 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003701 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003702 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003703
3704 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003705 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003706 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003707
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003708 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3709 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 -06003710 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003711 VkPipelineObj pipe(m_device);
3712 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003713 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003714 pipe.SetMSAA(&pipe_ms_state_ci);
3715 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003716
3717 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003718
3719 m_errorMonitor->ClearState();
3720 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3721 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003722 VkClearAttachment color_attachment;
3723 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3724 color_attachment.clearValue.color.float32[0] = 1.0;
3725 color_attachment.clearValue.color.float32[1] = 1.0;
3726 color_attachment.clearValue.color.float32[2] = 1.0;
3727 color_attachment.clearValue.color.float32[3] = 1.0;
3728 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06003729 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003730
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003731 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003732 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003733 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not receive error after issuing Clear Cmd on FB color attachment prior to Draw Cmd.";
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003734 if (!strstr(msgString.c_str(),"vkCmdClearAttachments() issued on CB object ")) {
3735 FAIL() << "Error received was not 'vkCmdClearAttachments() issued on CB object...'";
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003736 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003737
Chia-I Wuf7458c52015-10-26 21:10:41 +08003738 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3739 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3740 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003741}
3742
Tobin Ehlis502480b2015-06-24 15:53:07 -06003743TEST_F(VkLayerTest, VtxBufferBadIndex)
3744{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003745 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis502480b2015-06-24 15:53:07 -06003746 VkFlags msgFlags;
3747 std::string msgString;
3748 VkResult err;
3749
3750 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06003751 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06003752 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3753 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06003754
3755 VkDescriptorTypeCount ds_type_count = {};
3756 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003757 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003758
3759 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3760 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3761 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003762 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003763 ds_pool_ci.typeCount = 1;
3764 ds_pool_ci.pTypeCounts = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06003765
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003766 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003767 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003768 ASSERT_VK_SUCCESS(err);
3769
Tony Barboureb254902015-07-15 12:50:33 -06003770 VkDescriptorSetLayoutBinding dsl_binding = {};
3771 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3772 dsl_binding.arraySize = 1;
3773 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3774 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003775
Tony Barboureb254902015-07-15 12:50:33 -06003776 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3777 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3778 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003779 ds_layout_ci.bindingCount = 1;
3780 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003781
Tobin Ehlis502480b2015-06-24 15:53:07 -06003782 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003783 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003784 ASSERT_VK_SUCCESS(err);
3785
3786 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003787 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003788 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003789 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003790 alloc_info.descriptorPool = ds_pool;
3791 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003792 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003793 ASSERT_VK_SUCCESS(err);
3794
Tony Barboureb254902015-07-15 12:50:33 -06003795 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3796 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3797 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003798 pipe_ms_state_ci.rasterizationSamples = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003799 pipe_ms_state_ci.sampleShadingEnable = 0;
3800 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003801 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003802
Tony Barboureb254902015-07-15 12:50:33 -06003803 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3804 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3805 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003806 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003807 pipeline_layout_ci.pSetLayouts = &ds_layout;
3808 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003809
Chia-I Wuf7458c52015-10-26 21:10:41 +08003810 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003811 ASSERT_VK_SUCCESS(err);
3812
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003813 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3814 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour1c94d372015-08-06 11:21:08 -06003815 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003816 VkPipelineObj pipe(m_device);
3817 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003818 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003819 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003820 pipe.SetViewport(m_viewports);
3821 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003822 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003823
3824 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003825 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06003826 // Don't care about actual data, just need to get to draw to flag error
3827 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3828 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3829 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003830 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003831
3832 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003833 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06003834 if (!strstr(msgString.c_str(),"Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.")) {
Tobin Ehlisd332f282015-10-02 11:00:56 -06003835 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.' but instead was '" << msgString.c_str() << "'";
Tobin Ehlis502480b2015-06-24 15:53:07 -06003836 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003837
Chia-I Wuf7458c52015-10-26 21:10:41 +08003838 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3839 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3840 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003841}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003842#endif // DRAW_STATE_TESTS
3843
Tobin Ehlis0788f522015-05-26 16:11:58 -06003844#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06003845#if GTEST_IS_THREADSAFE
3846struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003847 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003848 VkEvent event;
3849 bool bailout;
3850};
3851
3852extern "C" void *AddToCommandBuffer(void *arg)
3853{
3854 struct thread_data_struct *data = (struct thread_data_struct *) arg;
3855 std::string msgString;
3856
3857 for (int i = 0; i<10000; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003858 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003859 if (data->bailout) {
3860 break;
3861 }
3862 }
3863 return NULL;
3864}
3865
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003866TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyanaccf7692015-05-12 16:00:45 -06003867{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003868 VkFlags msgFlags;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003869 std::string msgString;
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003870 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003871
3872 ASSERT_NO_FATAL_FAILURE(InitState());
3873 ASSERT_NO_FATAL_FAILURE(InitViewport());
3874 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3875
Mike Stroyanaccf7692015-05-12 16:00:45 -06003876 m_errorMonitor->ClearState();
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003877
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003878 // Calls AllocateCommandBuffers
3879 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003880
3881 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003882 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003883
3884 VkEventCreateInfo event_info;
3885 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003886 VkResult err;
3887
3888 memset(&event_info, 0, sizeof(event_info));
3889 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3890
Chia-I Wuf7458c52015-10-26 21:10:41 +08003891 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003892 ASSERT_VK_SUCCESS(err);
3893
Mike Stroyanaccf7692015-05-12 16:00:45 -06003894 err = vkResetEvent(device(), event);
3895 ASSERT_VK_SUCCESS(err);
3896
3897 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003898 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003899 data.event = event;
3900 data.bailout = false;
3901 m_errorMonitor->SetBailout(&data.bailout);
3902 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003903 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003904 // Add many entries to command buffer from this thread at the same time.
3905 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003906
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003907 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003908 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003909
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003910 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003911 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err from using one VkCommandBufferObj in two threads";
Mike Stroyanaccf7692015-05-12 16:00:45 -06003912 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -05003913 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyanaccf7692015-05-12 16:00:45 -06003914 }
3915
Chia-I Wuf7458c52015-10-26 21:10:41 +08003916 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003917}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003918#endif // GTEST_IS_THREADSAFE
3919#endif // THREADING_TESTS
3920
Chris Forbes9f7ff632015-05-25 11:13:08 +12003921#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003922TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
3923{
3924 VkFlags msgFlags;
3925 std::string msgString;
3926 ASSERT_NO_FATAL_FAILURE(InitState());
3927 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3928
3929 m_errorMonitor->ClearState();
3930
3931 VkShaderModule module;
3932 VkShaderModuleCreateInfo moduleCreateInfo;
3933 struct icd_spv_header spv;
3934
3935 spv.magic = ICD_SPV_MAGIC;
3936 spv.version = ICD_SPV_VERSION;
3937 spv.gen_magic = 0;
3938
3939 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3940 moduleCreateInfo.pNext = NULL;
Chia-I Wu8094f192015-10-26 19:22:06 +08003941 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003942 moduleCreateInfo.codeSize = 4;
3943 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003944 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003945
3946 msgFlags = m_errorMonitor->GetState(&msgString);
3947
Chris Forbes46794b82015-09-18 11:40:23 +12003948 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003949 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3950 FAIL() << "Incorrect warning: " << msgString;
3951 }
3952}
3953
3954TEST_F(VkLayerTest, InvalidSPIRVMagic)
3955{
3956 VkFlags msgFlags;
3957 std::string msgString;
3958 ASSERT_NO_FATAL_FAILURE(InitState());
3959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3960
3961 m_errorMonitor->ClearState();
3962
3963 VkShaderModule module;
3964 VkShaderModuleCreateInfo moduleCreateInfo;
3965 struct icd_spv_header spv;
3966
3967 spv.magic = ~ICD_SPV_MAGIC;
3968 spv.version = ICD_SPV_VERSION;
3969 spv.gen_magic = 0;
3970
3971 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3972 moduleCreateInfo.pNext = NULL;
Chia-I Wu8094f192015-10-26 19:22:06 +08003973 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003974 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3975 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003976 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003977
3978 msgFlags = m_errorMonitor->GetState(&msgString);
3979
Chris Forbes46794b82015-09-18 11:40:23 +12003980 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003981 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3982 FAIL() << "Incorrect warning: " << msgString;
3983 }
3984}
3985
3986TEST_F(VkLayerTest, InvalidSPIRVVersion)
3987{
3988 VkFlags msgFlags;
3989 std::string msgString;
3990 ASSERT_NO_FATAL_FAILURE(InitState());
3991 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3992
3993 m_errorMonitor->ClearState();
3994
3995 VkShaderModule module;
3996 VkShaderModuleCreateInfo moduleCreateInfo;
3997 struct icd_spv_header spv;
3998
3999 spv.magic = ICD_SPV_MAGIC;
4000 spv.version = ~ICD_SPV_VERSION;
4001 spv.gen_magic = 0;
4002
4003 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4004 moduleCreateInfo.pNext = NULL;
4005
Chia-I Wu8094f192015-10-26 19:22:06 +08004006 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004007 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4008 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004009 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004010
4011 msgFlags = m_errorMonitor->GetState(&msgString);
4012
Chris Forbes46794b82015-09-18 11:40:23 +12004013 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004014 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
4015 FAIL() << "Incorrect warning: " << msgString;
4016 }
4017}
4018
Chris Forbes9f7ff632015-05-25 11:13:08 +12004019TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
4020{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004021 VkFlags msgFlags;
Chris Forbes9f7ff632015-05-25 11:13:08 +12004022 std::string msgString;
4023 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004024 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12004025
4026 char const *vsSource =
4027 "#version 140\n"
4028 "#extension GL_ARB_separate_shader_objects: require\n"
4029 "#extension GL_ARB_shading_language_420pack: require\n"
4030 "\n"
4031 "layout(location=0) out float x;\n"
4032 "void main(){\n"
4033 " gl_Position = vec4(1);\n"
4034 " x = 0;\n"
4035 "}\n";
4036 char const *fsSource =
4037 "#version 140\n"
4038 "#extension GL_ARB_separate_shader_objects: require\n"
4039 "#extension GL_ARB_shading_language_420pack: require\n"
4040 "\n"
4041 "layout(location=0) out vec4 color;\n"
4042 "void main(){\n"
4043 " color = vec4(1);\n"
4044 "}\n";
4045
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004046 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4047 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004048
4049 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004050 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12004051 pipe.AddShader(&vs);
4052 pipe.AddShader(&fs);
4053
Chris Forbes9f7ff632015-05-25 11:13:08 +12004054 VkDescriptorSetObj descriptorSet(m_device);
4055 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004056 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004057
4058 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004059 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12004060
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004061 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004062
Cody Northropd2ad0342015-08-05 11:15:02 -06004063 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004064 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
4065 FAIL() << "Incorrect warning: " << msgString;
4066 }
4067}
Chris Forbes9f7ff632015-05-25 11:13:08 +12004068
Chris Forbes59cb88d2015-05-25 11:13:13 +12004069TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4070{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004071 VkFlags msgFlags;
Chris Forbes59cb88d2015-05-25 11:13:13 +12004072 std::string msgString;
4073 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004074 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12004075
4076 char const *vsSource =
4077 "#version 140\n"
4078 "#extension GL_ARB_separate_shader_objects: require\n"
4079 "#extension GL_ARB_shading_language_420pack: require\n"
4080 "\n"
4081 "void main(){\n"
4082 " gl_Position = vec4(1);\n"
4083 "}\n";
4084 char const *fsSource =
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) in float x;\n"
4090 "layout(location=0) out vec4 color;\n"
4091 "void main(){\n"
4092 " color = vec4(x);\n"
4093 "}\n";
4094
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004095 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4096 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004097
4098 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004099 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12004100 pipe.AddShader(&vs);
4101 pipe.AddShader(&fs);
4102
Chris Forbes59cb88d2015-05-25 11:13:13 +12004103 VkDescriptorSetObj descriptorSet(m_device);
4104 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004105 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004106
4107 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004108 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12004109
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004110 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004111
Cody Northropd2ad0342015-08-05 11:15:02 -06004112 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes59cb88d2015-05-25 11:13:13 +12004113 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
4114 FAIL() << "Incorrect error: " << msgString;
4115 }
4116}
4117
Chris Forbesb56af562015-05-25 11:13:17 +12004118TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4119{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004120 VkFlags msgFlags;
Chris Forbesb56af562015-05-25 11:13:17 +12004121 std::string msgString;
4122 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004123 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12004124
4125 char const *vsSource =
4126 "#version 140\n"
4127 "#extension GL_ARB_separate_shader_objects: require\n"
4128 "#extension GL_ARB_shading_language_420pack: require\n"
4129 "\n"
4130 "layout(location=0) out int x;\n"
4131 "void main(){\n"
4132 " x = 0;\n"
4133 " gl_Position = vec4(1);\n"
4134 "}\n";
4135 char const *fsSource =
4136 "#version 140\n"
4137 "#extension GL_ARB_separate_shader_objects: require\n"
4138 "#extension GL_ARB_shading_language_420pack: require\n"
4139 "\n"
4140 "layout(location=0) in float x;\n" /* VS writes int */
4141 "layout(location=0) out vec4 color;\n"
4142 "void main(){\n"
4143 " color = vec4(x);\n"
4144 "}\n";
4145
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004146 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4147 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12004148
4149 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004150 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12004151 pipe.AddShader(&vs);
4152 pipe.AddShader(&fs);
4153
Chris Forbesb56af562015-05-25 11:13:17 +12004154 VkDescriptorSetObj descriptorSet(m_device);
4155 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004156 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12004157
4158 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004159 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12004160
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004161 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesb56af562015-05-25 11:13:17 +12004162
Cody Northropd2ad0342015-08-05 11:15:02 -06004163 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesb56af562015-05-25 11:13:17 +12004164 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
4165 FAIL() << "Incorrect error: " << msgString;
4166 }
4167}
4168
Chris Forbesde136e02015-05-25 11:13:28 +12004169TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4170{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004171 VkFlags msgFlags;
Chris Forbesde136e02015-05-25 11:13:28 +12004172 std::string msgString;
4173 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004174 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12004175
4176 VkVertexInputBindingDescription input_binding;
4177 memset(&input_binding, 0, sizeof(input_binding));
4178
4179 VkVertexInputAttributeDescription input_attrib;
4180 memset(&input_attrib, 0, sizeof(input_attrib));
4181 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4182
4183 char const *vsSource =
4184 "#version 140\n"
4185 "#extension GL_ARB_separate_shader_objects: require\n"
4186 "#extension GL_ARB_shading_language_420pack: require\n"
4187 "\n"
4188 "void main(){\n"
4189 " gl_Position = vec4(1);\n"
4190 "}\n";
4191 char const *fsSource =
4192 "#version 140\n"
4193 "#extension GL_ARB_separate_shader_objects: require\n"
4194 "#extension GL_ARB_shading_language_420pack: require\n"
4195 "\n"
4196 "layout(location=0) out vec4 color;\n"
4197 "void main(){\n"
4198 " color = vec4(1);\n"
4199 "}\n";
4200
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004201 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4202 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12004203
4204 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004205 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12004206 pipe.AddShader(&vs);
4207 pipe.AddShader(&fs);
4208
4209 pipe.AddVertexInputBindings(&input_binding, 1);
4210 pipe.AddVertexInputAttribs(&input_attrib, 1);
4211
Chris Forbesde136e02015-05-25 11:13:28 +12004212 VkDescriptorSetObj descriptorSet(m_device);
4213 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004214 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12004215
4216 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004217 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12004218
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004219 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesde136e02015-05-25 11:13:28 +12004220
Cody Northropd2ad0342015-08-05 11:15:02 -06004221 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesde136e02015-05-25 11:13:28 +12004222 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
4223 FAIL() << "Incorrect warning: " << msgString;
4224 }
4225}
4226
Chris Forbes62e8e502015-05-25 11:13:29 +12004227TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4228{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004229 VkFlags msgFlags;
Chris Forbes62e8e502015-05-25 11:13:29 +12004230 std::string msgString;
4231 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12004233
4234 char const *vsSource =
4235 "#version 140\n"
4236 "#extension GL_ARB_separate_shader_objects: require\n"
4237 "#extension GL_ARB_shading_language_420pack: require\n"
4238 "\n"
4239 "layout(location=0) in vec4 x;\n" /* not provided */
4240 "void main(){\n"
4241 " gl_Position = x;\n"
4242 "}\n";
4243 char const *fsSource =
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) out vec4 color;\n"
4249 "void main(){\n"
4250 " color = vec4(1);\n"
4251 "}\n";
4252
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004253 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4254 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12004255
4256 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004257 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12004258 pipe.AddShader(&vs);
4259 pipe.AddShader(&fs);
4260
Chris Forbes62e8e502015-05-25 11:13:29 +12004261 VkDescriptorSetObj descriptorSet(m_device);
4262 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004263 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12004264
4265 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004266 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12004267
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004268 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes62e8e502015-05-25 11:13:29 +12004269
Cody Northropd2ad0342015-08-05 11:15:02 -06004270 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes62e8e502015-05-25 11:13:29 +12004271 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
4272 FAIL() << "Incorrect warning: " << msgString;
4273 }
4274}
4275
Chris Forbesc97d98e2015-05-25 11:13:31 +12004276TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4277{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004278 VkFlags msgFlags;
Chris Forbesc97d98e2015-05-25 11:13:31 +12004279 std::string msgString;
4280 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004281 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12004282
4283 VkVertexInputBindingDescription input_binding;
4284 memset(&input_binding, 0, sizeof(input_binding));
4285
4286 VkVertexInputAttributeDescription input_attrib;
4287 memset(&input_attrib, 0, sizeof(input_attrib));
4288 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4289
4290 char const *vsSource =
4291 "#version 140\n"
4292 "#extension GL_ARB_separate_shader_objects: require\n"
4293 "#extension GL_ARB_shading_language_420pack: require\n"
4294 "\n"
4295 "layout(location=0) in int x;\n" /* attrib provided float */
4296 "void main(){\n"
4297 " gl_Position = vec4(x);\n"
4298 "}\n";
4299 char const *fsSource =
4300 "#version 140\n"
4301 "#extension GL_ARB_separate_shader_objects: require\n"
4302 "#extension GL_ARB_shading_language_420pack: require\n"
4303 "\n"
4304 "layout(location=0) out vec4 color;\n"
4305 "void main(){\n"
4306 " color = vec4(1);\n"
4307 "}\n";
4308
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004309 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4310 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12004311
4312 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004313 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12004314 pipe.AddShader(&vs);
4315 pipe.AddShader(&fs);
4316
4317 pipe.AddVertexInputBindings(&input_binding, 1);
4318 pipe.AddVertexInputAttribs(&input_attrib, 1);
4319
Chris Forbesc97d98e2015-05-25 11:13:31 +12004320 VkDescriptorSetObj descriptorSet(m_device);
4321 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004322 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12004323
4324 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004325 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12004326
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004327 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc97d98e2015-05-25 11:13:31 +12004328
Cody Northropd2ad0342015-08-05 11:15:02 -06004329 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc97d98e2015-05-25 11:13:31 +12004330 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
4331 FAIL() << "Incorrect error: " << msgString;
4332 }
4333}
4334
Chris Forbes280ba2c2015-06-12 11:16:41 +12004335TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
4336{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004337 VkFlags msgFlags;
Chris Forbes280ba2c2015-06-12 11:16:41 +12004338 std::string msgString;
4339 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004340 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12004341
4342 /* Two binding descriptions for binding 0 */
4343 VkVertexInputBindingDescription input_bindings[2];
4344 memset(input_bindings, 0, sizeof(input_bindings));
4345
4346 VkVertexInputAttributeDescription input_attrib;
4347 memset(&input_attrib, 0, sizeof(input_attrib));
4348 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4349
4350 char const *vsSource =
4351 "#version 140\n"
4352 "#extension GL_ARB_separate_shader_objects: require\n"
4353 "#extension GL_ARB_shading_language_420pack: require\n"
4354 "\n"
4355 "layout(location=0) in float x;\n" /* attrib provided float */
4356 "void main(){\n"
4357 " gl_Position = vec4(x);\n"
4358 "}\n";
4359 char const *fsSource =
4360 "#version 140\n"
4361 "#extension GL_ARB_separate_shader_objects: require\n"
4362 "#extension GL_ARB_shading_language_420pack: require\n"
4363 "\n"
4364 "layout(location=0) out vec4 color;\n"
4365 "void main(){\n"
4366 " color = vec4(1);\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 Forbes280ba2c2015-06-12 11:16:41 +12004371
4372 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004373 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12004374 pipe.AddShader(&vs);
4375 pipe.AddShader(&fs);
4376
4377 pipe.AddVertexInputBindings(input_bindings, 2);
4378 pipe.AddVertexInputAttribs(&input_attrib, 1);
4379
Chris Forbes280ba2c2015-06-12 11:16:41 +12004380 VkDescriptorSetObj descriptorSet(m_device);
4381 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004382 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12004383
4384 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004385 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12004386
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004387 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes280ba2c2015-06-12 11:16:41 +12004388
Cody Northropd2ad0342015-08-05 11:15:02 -06004389 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes280ba2c2015-06-12 11:16:41 +12004390 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
4391 FAIL() << "Incorrect error: " << msgString;
4392 }
4393}
Chris Forbes8f68b562015-05-25 11:13:32 +12004394
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004395/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
4396 * rejects it. */
4397
4398TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
4399{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004400 VkFlags msgFlags;
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004401 std::string msgString;
4402 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004403
4404 char const *vsSource =
4405 "#version 140\n"
4406 "#extension GL_ARB_separate_shader_objects: require\n"
4407 "#extension GL_ARB_shading_language_420pack: require\n"
4408 "\n"
4409 "void main(){\n"
4410 " gl_Position = vec4(1);\n"
4411 "}\n";
4412 char const *fsSource =
4413 "#version 140\n"
4414 "#extension GL_ARB_separate_shader_objects: require\n"
4415 "#extension GL_ARB_shading_language_420pack: require\n"
4416 "\n"
4417 "void main(){\n"
4418 "}\n";
4419
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004420 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4421 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004422
4423 VkPipelineObj pipe(m_device);
4424 pipe.AddShader(&vs);
4425 pipe.AddShader(&fs);
4426
Chia-I Wu08accc62015-07-07 11:50:03 +08004427 /* set up CB 0, not written */
4428 pipe.AddColorAttachment();
4429 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004430
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004431 VkDescriptorSetObj descriptorSet(m_device);
4432 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004433 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004434
4435 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004436 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004437
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004438 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004439
Cody Northropd2ad0342015-08-05 11:15:02 -06004440 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004441 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
4442 FAIL() << "Incorrect error: " << msgString;
4443 }
4444}
4445
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004446TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
4447{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004448 VkFlags msgFlags;
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004449 std::string msgString;
4450 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004451
4452 char const *vsSource =
4453 "#version 140\n"
4454 "#extension GL_ARB_separate_shader_objects: require\n"
4455 "#extension GL_ARB_shading_language_420pack: require\n"
4456 "\n"
4457 "void main(){\n"
4458 " gl_Position = vec4(1);\n"
4459 "}\n";
4460 char const *fsSource =
4461 "#version 140\n"
4462 "#extension GL_ARB_separate_shader_objects: require\n"
4463 "#extension GL_ARB_shading_language_420pack: require\n"
4464 "\n"
4465 "layout(location=0) out vec4 x;\n"
4466 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4467 "void main(){\n"
4468 " x = vec4(1);\n"
4469 " y = vec4(1);\n"
4470 "}\n";
4471
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004472 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4473 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004474
4475 VkPipelineObj pipe(m_device);
4476 pipe.AddShader(&vs);
4477 pipe.AddShader(&fs);
4478
Chia-I Wu08accc62015-07-07 11:50:03 +08004479 /* set up CB 0, not written */
4480 pipe.AddColorAttachment();
4481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004482 /* FS writes CB 1, but we don't configure it */
4483
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004484 VkDescriptorSetObj descriptorSet(m_device);
4485 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004486 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004487
4488 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004489 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004490
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004491 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004492
Cody Northropd2ad0342015-08-05 11:15:02 -06004493 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004494 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
4495 FAIL() << "Incorrect warning: " << msgString;
4496 }
4497}
4498
Chris Forbesa36d69e2015-05-25 11:13:44 +12004499TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4500{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004501 VkFlags msgFlags;
Chris Forbesa36d69e2015-05-25 11:13:44 +12004502 std::string msgString;
4503 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004504
4505 char const *vsSource =
4506 "#version 140\n"
4507 "#extension GL_ARB_separate_shader_objects: require\n"
4508 "#extension GL_ARB_shading_language_420pack: require\n"
4509 "\n"
4510 "void main(){\n"
4511 " gl_Position = vec4(1);\n"
4512 "}\n";
4513 char const *fsSource =
4514 "#version 140\n"
4515 "#extension GL_ARB_separate_shader_objects: require\n"
4516 "#extension GL_ARB_shading_language_420pack: require\n"
4517 "\n"
4518 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4519 "void main(){\n"
4520 " x = ivec4(1);\n"
4521 "}\n";
4522
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004523 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4524 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004525
4526 VkPipelineObj pipe(m_device);
4527 pipe.AddShader(&vs);
4528 pipe.AddShader(&fs);
4529
Chia-I Wu08accc62015-07-07 11:50:03 +08004530 /* set up CB 0; type is UNORM by default */
4531 pipe.AddColorAttachment();
4532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004533
Chris Forbesa36d69e2015-05-25 11:13:44 +12004534 VkDescriptorSetObj descriptorSet(m_device);
4535 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004536 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004537
4538 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004539 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004540
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004541 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004542
Cody Northropd2ad0342015-08-05 11:15:02 -06004543 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa36d69e2015-05-25 11:13:44 +12004544 if (!strstr(msgString.c_str(),"does not match FS output type")) {
4545 FAIL() << "Incorrect error: " << msgString;
4546 }
4547}
Chris Forbes7b1b8932015-06-05 14:43:36 +12004548
Chris Forbes556c76c2015-08-14 12:04:59 +12004549TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4550{
4551 VkFlags msgFlags;
4552 std::string msgString;
4553 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12004554
4555 char const *vsSource =
4556 "#version 140\n"
4557 "#extension GL_ARB_separate_shader_objects: require\n"
4558 "#extension GL_ARB_shading_language_420pack: require\n"
4559 "\n"
4560 "void main(){\n"
4561 " gl_Position = vec4(1);\n"
4562 "}\n";
4563 char const *fsSource =
4564 "#version 140\n"
4565 "#extension GL_ARB_separate_shader_objects: require\n"
4566 "#extension GL_ARB_shading_language_420pack: require\n"
4567 "\n"
4568 "layout(location=0) out vec4 x;\n"
4569 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4570 "void main(){\n"
4571 " x = vec4(bar.y);\n"
4572 "}\n";
4573
4574 m_errorMonitor->ClearState();
4575
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004576 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4577 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12004578
4579
4580 VkPipelineObj pipe(m_device);
4581 pipe.AddShader(&vs);
4582 pipe.AddShader(&fs);
4583
4584 /* set up CB 0; type is UNORM by default */
4585 pipe.AddColorAttachment();
4586 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4587
4588 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004589 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12004590
4591 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4592
4593 /* should have generated an error -- pipeline layout does not
4594 * provide a uniform buffer in 0.0
4595 */
4596 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -06004597 ASSERT_TRUE((msgFlags & VK_DBG_REPORT_ERROR_BIT) == VK_DBG_REPORT_ERROR_BIT);
Chris Forbes556c76c2015-08-14 12:04:59 +12004598 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
4599 FAIL() << "Incorrect error: " << msgString;
4600 }
4601}
4602
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004603#endif // SHADER_CHECKER_TESTS
4604
4605#if DEVICE_LIMITS_TESTS
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004606TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4607{
4608 VkFlags msgFlags;
4609 std::string msgString;
4610
4611 ASSERT_NO_FATAL_FAILURE(InitState());
4612 m_errorMonitor->ClearState();
4613
4614 // Create an image
4615 VkImage image;
4616
4617 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4618 const int32_t tex_width = 32;
4619 const int32_t tex_height = 32;
4620
4621 VkImageCreateInfo image_create_info = {};
4622 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4623 image_create_info.pNext = NULL;
4624 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4625 image_create_info.format = tex_format;
4626 image_create_info.extent.width = tex_width;
4627 image_create_info.extent.height = tex_height;
4628 image_create_info.extent.depth = 1;
4629 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004630 image_create_info.arrayLayers = 1;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004631 image_create_info.samples = 1;
4632 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4633 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4634 image_create_info.flags = 0;
4635
4636 // Introduce error by sending down a bogus width extent
4637 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004638 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004639
4640 msgFlags = m_errorMonitor->GetState(&msgString);
4641 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4642 "with extents outside the queried limits";
4643 if (!strstr(msgString.c_str(),"CreateImage extents exceed allowable limits for format")) {
4644 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4645 }
4646}
4647
4648TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4649{
4650 VkFlags msgFlags;
4651 std::string msgString;
4652
4653 ASSERT_NO_FATAL_FAILURE(InitState());
4654 m_errorMonitor->ClearState();
4655
4656 // Create an image
4657 VkImage image;
4658
4659 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4660 const int32_t tex_width = 32;
4661 const int32_t tex_height = 32;
4662
4663 VkImageCreateInfo image_create_info = {};
4664 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4665 image_create_info.pNext = NULL;
4666 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4667 image_create_info.format = tex_format;
4668 image_create_info.extent.width = tex_width;
4669 image_create_info.extent.height = tex_height;
4670 image_create_info.extent.depth = 1;
4671 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004672 image_create_info.arrayLayers = 1;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004673 image_create_info.samples = 1;
4674 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4675 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4676 image_create_info.flags = 0;
4677
4678 // Introduce error by sending down individually allowable values that result in a surface size
4679 // exceeding the device maximum
4680 image_create_info.extent.width = 8192;
4681 image_create_info.extent.height = 8192;
4682 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004683 image_create_info.arrayLayers = 4;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004684 image_create_info.samples = 2;
4685 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004686 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004687
4688 msgFlags = m_errorMonitor->GetState(&msgString);
4689 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4690 "with resource size exceeding queried limit";
4691 if (!strstr(msgString.c_str(),"CreateImage resource size exceeds allowable maximum")) {
4692 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4693 }
4694}
4695
Mike Stroyana3082432015-09-25 13:39:21 -06004696TEST_F(VkLayerTest, UpdateBufferAlignment)
4697{
4698 VkFlags msgFlags;
4699 std::string msgString;
4700 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4701
4702 ASSERT_NO_FATAL_FAILURE(InitState());
4703
4704 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4705 vk_testing::Buffer buffer;
4706 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4707
4708 BeginCommandBuffer();
4709 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004710 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mike Stroyana3082432015-09-25 13:39:21 -06004711 msgFlags = m_errorMonitor->GetState(&msgString);
4712 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad offset";
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004713 if (!strstr(msgString.c_str(),"dstOffset, is not a multiple of 4")) {
4714 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
Mike Stroyana3082432015-09-25 13:39:21 -06004715 }
4716 // Introduce failure by using size that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004717 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mike Stroyana3082432015-09-25 13:39:21 -06004718 msgFlags = m_errorMonitor->GetState(&msgString);
4719 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad size";
4720 if (!strstr(msgString.c_str(),"dataSize, is not a multiple of 4")) {
4721 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4722 }
4723 EndCommandBuffer();
4724}
4725
4726TEST_F(VkLayerTest, FillBufferAlignment)
4727{
4728 VkFlags msgFlags;
4729 std::string msgString;
4730
4731 ASSERT_NO_FATAL_FAILURE(InitState());
4732
4733 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4734 vk_testing::Buffer buffer;
4735 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4736
4737 BeginCommandBuffer();
4738 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004739 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mike Stroyana3082432015-09-25 13:39:21 -06004740 msgFlags = m_errorMonitor->GetState(&msgString);
4741 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad offset";
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004742 if (!strstr(msgString.c_str(),"dstOffset, is not a multiple of 4")) {
4743 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
Mike Stroyana3082432015-09-25 13:39:21 -06004744 }
4745 // Introduce failure by using size that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004746 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mike Stroyana3082432015-09-25 13:39:21 -06004747 msgFlags = m_errorMonitor->GetState(&msgString);
4748 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad size";
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08004749 if (!strstr(msgString.c_str(),"size, is not a multiple of 4")) {
4750 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
Mike Stroyana3082432015-09-25 13:39:21 -06004751 }
4752 EndCommandBuffer();
4753}
4754
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004755#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12004756
Tobin Ehliscde08892015-09-22 10:11:37 -06004757#if IMAGE_TESTS
4758TEST_F(VkLayerTest, InvalidImageView)
4759{
4760 VkFlags msgFlags;
4761 std::string msgString;
4762 VkResult err;
4763
4764 ASSERT_NO_FATAL_FAILURE(InitState());
4765 m_errorMonitor->ClearState();
4766
Mike Stroyana3082432015-09-25 13:39:21 -06004767 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehliscde08892015-09-22 10:11:37 -06004768 VkImage image;
4769
4770 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4771 const int32_t tex_width = 32;
4772 const int32_t tex_height = 32;
4773
4774 VkImageCreateInfo image_create_info = {};
4775 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4776 image_create_info.pNext = NULL;
4777 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4778 image_create_info.format = tex_format;
4779 image_create_info.extent.width = tex_width;
4780 image_create_info.extent.height = tex_height;
4781 image_create_info.extent.depth = 1;
4782 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004783 image_create_info.arrayLayers = 1;
Tobin Ehliscde08892015-09-22 10:11:37 -06004784 image_create_info.samples = 1;
4785 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4786 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4787 image_create_info.flags = 0;
4788
Chia-I Wuf7458c52015-10-26 21:10:41 +08004789 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -06004790 ASSERT_VK_SUCCESS(err);
4791
4792 VkImageViewCreateInfo image_view_create_info = {};
4793 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4794 image_view_create_info.image = image;
4795 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4796 image_view_create_info.format = tex_format;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004797 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehliscde08892015-09-22 10:11:37 -06004798 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004799 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004800 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06004801
4802 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004803 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -06004804
4805 msgFlags = m_errorMonitor->GetState(&msgString);
4806 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an invalid ImageView";
4807 if (!strstr(msgString.c_str(),"vkCreateImageView called with baseMipLevel 10 ")) {
Mike Stroyana3082432015-09-25 13:39:21 -06004808 FAIL() << "Error received was not 'vkCreateImageView called with baseMipLevel 10...' but instead '" << msgString.c_str() << "'";
Tobin Ehliscde08892015-09-22 10:11:37 -06004809 }
4810}
Mike Stroyana3082432015-09-25 13:39:21 -06004811
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004812TEST_F(VkLayerTest, InvalidImageViewAspect)
4813{
4814 VkFlags msgFlags;
4815 std::string msgString;
4816 VkResult err;
4817
4818 ASSERT_NO_FATAL_FAILURE(InitState());
4819 m_errorMonitor->ClearState();
4820
4821 // Create an image and try to create a view with an invalid aspectMask
4822 VkImage image;
4823
4824 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4825 const int32_t tex_width = 32;
4826 const int32_t tex_height = 32;
4827
4828 VkImageCreateInfo image_create_info = {};
4829 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4830 image_create_info.pNext = NULL;
4831 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4832 image_create_info.format = tex_format;
4833 image_create_info.extent.width = tex_width;
4834 image_create_info.extent.height = tex_height;
4835 image_create_info.extent.depth = 1;
4836 image_create_info.mipLevels = 1;
4837 image_create_info.samples = 1;
4838 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4839 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4840 image_create_info.flags = 0;
4841
Chia-I Wuf7458c52015-10-26 21:10:41 +08004842 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004843 ASSERT_VK_SUCCESS(err);
4844
4845 VkImageViewCreateInfo image_view_create_info = {};
4846 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4847 image_view_create_info.image = image;
4848 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4849 image_view_create_info.format = tex_format;
4850 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004851 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004852 // Cause an error by setting an invalid image aspect
4853 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
4854
4855 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004856 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004857
4858 msgFlags = m_errorMonitor->GetState(&msgString);
4859 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error when specifying an invalid ImageView aspect";
4860 if (!strstr(msgString.c_str(),"vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set")) {
4861 FAIL() << "Error received was not 'VkCreateImageView: Color image formats must have ...' but instead '" << msgString.c_str() << "'";
4862 }
4863}
4864
Mike Stroyana3082432015-09-25 13:39:21 -06004865TEST_F(VkLayerTest, CopyImageTypeMismatch)
4866{
4867 VkFlags msgFlags;
4868 std::string msgString;
4869 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004870 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004871
4872 ASSERT_NO_FATAL_FAILURE(InitState());
4873 m_errorMonitor->ClearState();
4874
4875 // Create two images of different types and try to copy between them
4876 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004877 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06004878 VkDeviceMemory srcMem;
4879 VkDeviceMemory destMem;
4880 VkMemoryRequirements memReqs;
4881
4882 VkImageCreateInfo image_create_info = {};
4883 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4884 image_create_info.pNext = NULL;
4885 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4886 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4887 image_create_info.extent.width = 32;
4888 image_create_info.extent.height = 32;
4889 image_create_info.extent.depth = 1;
4890 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004891 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004892 image_create_info.samples = 1;
4893 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004894 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004895 image_create_info.flags = 0;
4896
Chia-I Wuf7458c52015-10-26 21:10:41 +08004897 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06004898 ASSERT_VK_SUCCESS(err);
4899
4900 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004901 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004902
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004903 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06004904 ASSERT_VK_SUCCESS(err);
4905
4906 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004907 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06004908 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4909 memAlloc.pNext = NULL;
4910 memAlloc.allocationSize = 0;
4911 memAlloc.memoryTypeIndex = 0;
4912
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004913 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004914 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004915 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4916 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004917 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06004918 ASSERT_VK_SUCCESS(err);
4919
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004920 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004921 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004922 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06004923 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004924 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06004925 ASSERT_VK_SUCCESS(err);
4926
4927 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4928 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004929 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06004930 ASSERT_VK_SUCCESS(err);
4931
4932 BeginCommandBuffer();
4933 VkImageCopy copyRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004934 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004935 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004936 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004937 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004938 copyRegion.srcOffset.x = 0;
4939 copyRegion.srcOffset.y = 0;
4940 copyRegion.srcOffset.z = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004941 copyRegion.dstSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
4942 copyRegion.dstSubresource.mipLevel = 0;
4943 copyRegion.dstSubresource.baseArrayLayer = 0;
4944 copyRegion.dstSubresource.layerCount = 0;
4945 copyRegion.dstOffset.x = 0;
4946 copyRegion.dstOffset.y = 0;
4947 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004948 copyRegion.extent.width = 1;
4949 copyRegion.extent.height = 1;
4950 copyRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004951 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06004952 EndCommandBuffer();
4953
4954 msgFlags = m_errorMonitor->GetState(&msgString);
4955 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4956 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4957 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4958 }
4959
Chia-I Wuf7458c52015-10-26 21:10:41 +08004960 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004961 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004962 vkFreeMemory(m_device->device(), srcMem, NULL);
4963 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06004964}
4965
4966TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
4967{
4968 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
4969}
4970
4971TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
4972{
4973 VkFlags msgFlags;
4974 std::string msgString;
4975 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004976 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004977
4978 ASSERT_NO_FATAL_FAILURE(InitState());
4979 m_errorMonitor->ClearState();
4980
4981 // Create two images of different types and try to copy between them
4982 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004983 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06004984 VkDeviceMemory srcMem;
4985 VkDeviceMemory destMem;
4986 VkMemoryRequirements memReqs;
4987
4988 VkImageCreateInfo image_create_info = {};
4989 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4990 image_create_info.pNext = NULL;
4991 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4992 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4993 image_create_info.extent.width = 32;
4994 image_create_info.extent.height = 32;
4995 image_create_info.extent.depth = 1;
4996 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004997 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004998 image_create_info.samples = 1;
4999 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005000 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005001 image_create_info.flags = 0;
5002
Chia-I Wuf7458c52015-10-26 21:10:41 +08005003 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005004 ASSERT_VK_SUCCESS(err);
5005
5006 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005007 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005008
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005009 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005010 ASSERT_VK_SUCCESS(err);
5011
5012 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005013 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06005014 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5015 memAlloc.pNext = NULL;
5016 memAlloc.allocationSize = 0;
5017 memAlloc.memoryTypeIndex = 0;
5018
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005019 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005020 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005021 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5022 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005023 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005024 ASSERT_VK_SUCCESS(err);
5025
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005026 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005027 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005028 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5029 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005030 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005031 ASSERT_VK_SUCCESS(err);
5032
5033 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5034 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005035 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005036 ASSERT_VK_SUCCESS(err);
5037
5038 BeginCommandBuffer();
5039 VkImageCopy copyRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06005040 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005041 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005042 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005043 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005044 copyRegion.srcOffset.x = 0;
5045 copyRegion.srcOffset.y = 0;
5046 copyRegion.srcOffset.z = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005047 copyRegion.dstSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
5048 copyRegion.dstSubresource.mipLevel = 0;
5049 copyRegion.dstSubresource.baseArrayLayer = 0;
5050 copyRegion.dstSubresource.layerCount = 0;
5051 copyRegion.dstOffset.x = 0;
5052 copyRegion.dstOffset.y = 0;
5053 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005054 copyRegion.extent.width = 1;
5055 copyRegion.extent.height = 1;
5056 copyRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005057 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005058 EndCommandBuffer();
5059
5060 msgFlags = m_errorMonitor->GetState(&msgString);
5061 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
5062 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
5063 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
5064 }
5065
Chia-I Wuf7458c52015-10-26 21:10:41 +08005066 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005067 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005068 vkFreeMemory(m_device->device(), srcMem, NULL);
5069 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005070}
5071
5072TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5073{
5074 VkFlags msgFlags;
5075 std::string msgString;
5076 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005077 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005078
5079 ASSERT_NO_FATAL_FAILURE(InitState());
5080 m_errorMonitor->ClearState();
5081
5082 // Create two images of sample count 1 and try to Resolve between them
5083 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005084 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005085 VkDeviceMemory srcMem;
5086 VkDeviceMemory destMem;
5087 VkMemoryRequirements memReqs;
5088
5089 VkImageCreateInfo image_create_info = {};
5090 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5091 image_create_info.pNext = NULL;
5092 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5093 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5094 image_create_info.extent.width = 32;
5095 image_create_info.extent.height = 1;
5096 image_create_info.extent.depth = 1;
5097 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005098 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06005099 image_create_info.samples = 1;
5100 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005101 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005102 image_create_info.flags = 0;
5103
Chia-I Wuf7458c52015-10-26 21:10:41 +08005104 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005105 ASSERT_VK_SUCCESS(err);
5106
5107 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005108 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005109
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005110 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005111 ASSERT_VK_SUCCESS(err);
5112
5113 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005114 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06005115 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5116 memAlloc.pNext = NULL;
5117 memAlloc.allocationSize = 0;
5118 memAlloc.memoryTypeIndex = 0;
5119
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005120 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005121 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005122 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5123 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005124 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005125 ASSERT_VK_SUCCESS(err);
5126
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005127 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005128 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005129 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5130 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005131 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005132 ASSERT_VK_SUCCESS(err);
5133
5134 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5135 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005136 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005137 ASSERT_VK_SUCCESS(err);
5138
5139 BeginCommandBuffer();
5140 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5141 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5142 //VK_IMAGE_LAYOUT_GENERAL = 1,
5143 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06005144 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005145 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005146 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005147 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005148 resolveRegion.srcOffset.x = 0;
5149 resolveRegion.srcOffset.y = 0;
5150 resolveRegion.srcOffset.z = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005151 resolveRegion.dstSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
5152 resolveRegion.dstSubresource.mipLevel = 0;
5153 resolveRegion.dstSubresource.baseArrayLayer = 0;
5154 resolveRegion.dstSubresource.layerCount = 0;
5155 resolveRegion.dstOffset.x = 0;
5156 resolveRegion.dstOffset.y = 0;
5157 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005158 resolveRegion.extent.width = 1;
5159 resolveRegion.extent.height = 1;
5160 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005161 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005162 EndCommandBuffer();
5163
5164 msgFlags = m_errorMonitor->GetState(&msgString);
5165 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
5166 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with source sample count less than 2.")) {
5167 FAIL() << "Error received was not 'vkCmdResolveImage called with source sample count less than 2.' but instead '" << msgString.c_str() << "'";
5168 }
5169
Chia-I Wuf7458c52015-10-26 21:10:41 +08005170 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005171 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005172 vkFreeMemory(m_device->device(), srcMem, NULL);
5173 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005174}
5175
5176TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5177{
5178 VkFlags msgFlags;
5179 std::string msgString;
5180 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005181 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005182
5183 ASSERT_NO_FATAL_FAILURE(InitState());
5184 m_errorMonitor->ClearState();
5185
5186 // Create two images of sample count 2 and try to Resolve between them
5187 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005188 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005189 VkDeviceMemory srcMem;
5190 VkDeviceMemory destMem;
5191 VkMemoryRequirements memReqs;
5192
5193 VkImageCreateInfo image_create_info = {};
5194 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5195 image_create_info.pNext = NULL;
5196 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5197 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5198 image_create_info.extent.width = 32;
5199 image_create_info.extent.height = 1;
5200 image_create_info.extent.depth = 1;
5201 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005202 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06005203 image_create_info.samples = 2;
5204 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06005205 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005206 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005207 image_create_info.flags = 0;
5208
Chia-I Wuf7458c52015-10-26 21:10:41 +08005209 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005210 ASSERT_VK_SUCCESS(err);
5211
5212 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northrop72458c02015-10-27 13:50:04 -06005213 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005214 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005215
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005216 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005217 ASSERT_VK_SUCCESS(err);
5218
5219 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005220 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06005221 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5222 memAlloc.pNext = NULL;
5223 memAlloc.allocationSize = 0;
5224 memAlloc.memoryTypeIndex = 0;
5225
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005226 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005227 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005228 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5229 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005230 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005231 ASSERT_VK_SUCCESS(err);
5232
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005233 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005234 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005235 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5236 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005237 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005238 ASSERT_VK_SUCCESS(err);
5239
5240 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5241 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005242 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005243 ASSERT_VK_SUCCESS(err);
5244
5245 BeginCommandBuffer();
5246 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5247 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5248 //VK_IMAGE_LAYOUT_GENERAL = 1,
5249 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06005250 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005251 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005252 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005253 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005254 resolveRegion.srcOffset.x = 0;
5255 resolveRegion.srcOffset.y = 0;
5256 resolveRegion.srcOffset.z = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005257 resolveRegion.dstSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
5258 resolveRegion.dstSubresource.mipLevel = 0;
5259 resolveRegion.dstSubresource.baseArrayLayer = 0;
5260 resolveRegion.dstSubresource.layerCount = 0;
5261 resolveRegion.dstOffset.x = 0;
5262 resolveRegion.dstOffset.y = 0;
5263 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005264 resolveRegion.extent.width = 1;
5265 resolveRegion.extent.height = 1;
5266 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005267 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005268 EndCommandBuffer();
5269
5270 msgFlags = m_errorMonitor->GetState(&msgString);
5271 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
5272 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with dest sample count greater than 1.")) {
5273 FAIL() << "Error received was not 'vkCmdResolveImage called with dest sample count greater than 1.' but instead '" << msgString.c_str() << "'";
5274 }
5275
Chia-I Wuf7458c52015-10-26 21:10:41 +08005276 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005277 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005278 vkFreeMemory(m_device->device(), srcMem, NULL);
5279 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005280}
5281
5282TEST_F(VkLayerTest, ResolveImageFormatMismatch)
5283{
5284 VkFlags msgFlags;
5285 std::string msgString;
5286 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005287 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005288
5289 ASSERT_NO_FATAL_FAILURE(InitState());
5290 m_errorMonitor->ClearState();
5291
5292 // Create two images of different types and try to copy between them
5293 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005294 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005295 VkDeviceMemory srcMem;
5296 VkDeviceMemory destMem;
5297 VkMemoryRequirements memReqs;
5298
5299 VkImageCreateInfo image_create_info = {};
5300 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5301 image_create_info.pNext = NULL;
5302 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5303 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5304 image_create_info.extent.width = 32;
5305 image_create_info.extent.height = 1;
5306 image_create_info.extent.depth = 1;
5307 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005308 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06005309 image_create_info.samples = 2;
5310 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06005311 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005312 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005313 image_create_info.flags = 0;
5314
Chia-I Wuf7458c52015-10-26 21:10:41 +08005315 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005316 ASSERT_VK_SUCCESS(err);
5317
Cody Northrop72458c02015-10-27 13:50:04 -06005318 // Set format to something other than source image
5319 image_create_info.format = VK_FORMAT_R32_SFLOAT;
5320 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005321 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005322 image_create_info.samples = 1;
5323
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005324 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005325 ASSERT_VK_SUCCESS(err);
5326
5327 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005328 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06005329 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5330 memAlloc.pNext = NULL;
5331 memAlloc.allocationSize = 0;
5332 memAlloc.memoryTypeIndex = 0;
5333
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005334 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005335 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005336 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5337 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005338 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005339 ASSERT_VK_SUCCESS(err);
5340
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005341 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005342 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005343 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5344 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005345 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005346 ASSERT_VK_SUCCESS(err);
5347
5348 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5349 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005350 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005351 ASSERT_VK_SUCCESS(err);
5352
5353 BeginCommandBuffer();
5354 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5355 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5356 //VK_IMAGE_LAYOUT_GENERAL = 1,
5357 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06005358 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005359 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005360 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005361 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005362 resolveRegion.srcOffset.x = 0;
5363 resolveRegion.srcOffset.y = 0;
5364 resolveRegion.srcOffset.z = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005365 resolveRegion.dstSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
5366 resolveRegion.dstSubresource.mipLevel = 0;
5367 resolveRegion.dstSubresource.baseArrayLayer = 0;
5368 resolveRegion.dstSubresource.layerCount = 0;
5369 resolveRegion.dstOffset.x = 0;
5370 resolveRegion.dstOffset.y = 0;
5371 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005372 resolveRegion.extent.width = 1;
5373 resolveRegion.extent.height = 1;
5374 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005375 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005376 EndCommandBuffer();
5377
5378 msgFlags = m_errorMonitor->GetState(&msgString);
5379 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage format mismatch";
5380 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest formats.")) {
5381 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest formats.' but instead '" << msgString.c_str() << "'";
5382 }
5383
Chia-I Wuf7458c52015-10-26 21:10:41 +08005384 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005385 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005386 vkFreeMemory(m_device->device(), srcMem, NULL);
5387 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005388}
5389
5390TEST_F(VkLayerTest, ResolveImageTypeMismatch)
5391{
5392 VkFlags msgFlags;
5393 std::string msgString;
5394 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005395 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005396
5397 ASSERT_NO_FATAL_FAILURE(InitState());
5398 m_errorMonitor->ClearState();
5399
5400 // Create two images of different types and try to copy between them
5401 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005402 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005403 VkDeviceMemory srcMem;
5404 VkDeviceMemory destMem;
5405 VkMemoryRequirements memReqs;
5406
5407 VkImageCreateInfo image_create_info = {};
5408 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5409 image_create_info.pNext = NULL;
5410 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5411 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5412 image_create_info.extent.width = 32;
5413 image_create_info.extent.height = 1;
5414 image_create_info.extent.depth = 1;
5415 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005416 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06005417 image_create_info.samples = 2;
5418 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06005419 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005420 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005421 image_create_info.flags = 0;
5422
Chia-I Wuf7458c52015-10-26 21:10:41 +08005423 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005424 ASSERT_VK_SUCCESS(err);
5425
5426 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northrop72458c02015-10-27 13:50:04 -06005427 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005428 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005429 image_create_info.samples = 1;
5430
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005431 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005432 ASSERT_VK_SUCCESS(err);
5433
5434 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005435 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyana3082432015-09-25 13:39:21 -06005436 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5437 memAlloc.pNext = NULL;
5438 memAlloc.allocationSize = 0;
5439 memAlloc.memoryTypeIndex = 0;
5440
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005441 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005442 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005443 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5444 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005445 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005446 ASSERT_VK_SUCCESS(err);
5447
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005448 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005449 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005450 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5451 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005452 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005453 ASSERT_VK_SUCCESS(err);
5454
5455 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5456 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005457 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005458 ASSERT_VK_SUCCESS(err);
5459
5460 BeginCommandBuffer();
5461 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5462 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5463 //VK_IMAGE_LAYOUT_GENERAL = 1,
5464 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06005465 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005466 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005467 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005468 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005469 resolveRegion.srcOffset.x = 0;
5470 resolveRegion.srcOffset.y = 0;
5471 resolveRegion.srcOffset.z = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005472 resolveRegion.dstSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
5473 resolveRegion.dstSubresource.mipLevel = 0;
5474 resolveRegion.dstSubresource.baseArrayLayer = 0;
5475 resolveRegion.dstSubresource.layerCount = 0;
5476 resolveRegion.dstOffset.x = 0;
5477 resolveRegion.dstOffset.y = 0;
5478 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005479 resolveRegion.extent.width = 1;
5480 resolveRegion.extent.height = 1;
5481 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005482 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005483 EndCommandBuffer();
5484
5485 msgFlags = m_errorMonitor->GetState(&msgString);
5486 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
5487 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest image types.")) {
5488 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest image types.' but instead '" << msgString.c_str() << "'";
5489 }
5490
Chia-I Wuf7458c52015-10-26 21:10:41 +08005491 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005492 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005493 vkFreeMemory(m_device->device(), srcMem, NULL);
5494 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005495}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005496
5497TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
5498{
5499 // Create a single Image descriptor and cause it to first hit an error due
5500 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
5501 // The image format check comes 2nd in validation so we trigger it first,
5502 // then when we cause aspect fail next, bad format check will be preempted
5503 VkFlags msgFlags;
5504 std::string msgString;
5505 VkResult err;
5506
5507 ASSERT_NO_FATAL_FAILURE(InitState());
5508 m_errorMonitor->ClearState();
5509 VkDescriptorTypeCount ds_type_count = {};
5510 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005511 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005512
5513 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5514 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5515 ds_pool_ci.pNext = NULL;
5516 ds_pool_ci.maxSets = 1;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005517 ds_pool_ci.typeCount = 1;
5518 ds_pool_ci.pTypeCounts = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005519
5520 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005521 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005522 ASSERT_VK_SUCCESS(err);
5523
5524 VkDescriptorSetLayoutBinding dsl_binding = {};
5525 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5526 dsl_binding.arraySize = 1;
5527 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5528 dsl_binding.pImmutableSamplers = NULL;
5529
5530 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5531 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5532 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005533 ds_layout_ci.bindingCount = 1;
5534 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005535 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005536 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005537 ASSERT_VK_SUCCESS(err);
5538
5539 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005540 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005541 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005542 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005543 alloc_info.descriptorPool = ds_pool;
5544 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005545 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005546 ASSERT_VK_SUCCESS(err);
5547
5548 VkImage image_bad;
5549 VkImage image_good;
5550 // One bad format and one good format for Color attachment
5551 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
5552 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
5553 const int32_t tex_width = 32;
5554 const int32_t tex_height = 32;
5555
5556 VkImageCreateInfo image_create_info = {};
5557 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5558 image_create_info.pNext = NULL;
5559 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5560 image_create_info.format = tex_format_bad;
5561 image_create_info.extent.width = tex_width;
5562 image_create_info.extent.height = tex_height;
5563 image_create_info.extent.depth = 1;
5564 image_create_info.mipLevels = 1;
5565 image_create_info.arrayLayers = 1;
5566 image_create_info.samples = 1;
5567 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5568 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
5569 image_create_info.flags = 0;
5570
Chia-I Wuf7458c52015-10-26 21:10:41 +08005571 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005572 ASSERT_VK_SUCCESS(err);
5573 image_create_info.format = tex_format_good;
5574 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005575 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005576 ASSERT_VK_SUCCESS(err);
5577
5578 VkImageViewCreateInfo image_view_create_info = {};
5579 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5580 image_view_create_info.image = image_bad;
5581 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5582 image_view_create_info.format = tex_format_bad;
5583 image_view_create_info.subresourceRange.baseArrayLayer = 0;
5584 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005585 image_view_create_info.subresourceRange.layerCount = 1;
5586 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005587 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5588
5589 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005590 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005591 msgFlags = m_errorMonitor->GetState(&msgString);
5592 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating ImageView for DS image w/ COLOR aspect bit set.";
5593 if (!strstr(msgString.c_str(),"Combination depth/stencil image formats can have only the ")) {
5594 FAIL() << "Error received was not 'Combination depth/stencil image formats can have only the....' but instead '" << msgString.c_str() << "'";
5595 }
5596
Chia-I Wuf7458c52015-10-26 21:10:41 +08005597 vkDestroyImage(m_device->device(), image_bad, NULL);
5598 vkDestroyImage(m_device->device(), image_good, NULL);
5599 vkDestroyImageView(m_device->device(), view, NULL);
5600 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5601 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005602}
5603
Tobin Ehliscde08892015-09-22 10:11:37 -06005604#endif // IMAGE_TESTS
5605
Tony Barbour300a6082015-04-07 13:44:53 -06005606int main(int argc, char **argv) {
5607 int result;
5608
5609 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06005610 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06005611
5612 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
5613
5614 result = RUN_ALL_TESTS();
5615
Tony Barbour6918cd52015-04-09 12:58:51 -06005616 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06005617 return result;
5618}