blob: c28af1e0b6051a7aa884affccdbc71a31f94f99a [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:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600150 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
151 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500152 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
153 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600154 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
155 { GenericDrawPreparation(m_cmdBuffer, 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 */
158 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); }
159 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); }
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600160 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
161 { m_cmdBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
162 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
163 { m_cmdBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600164 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
165 void QueueCommandBuffer(const VkFence& fence) { m_cmdBuffer->QueueCommandBuffer(fence); }
166 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
167 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
168 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
169 { m_cmdBuffer->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 */
Mike Stroyand1c84a52015-08-18 14:40:24 -0600185 // Use Threading layer first to protect others from ThreadCmdBufferCollision 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;
204 this->app_info.pAppName = "layer_tests";
205 this->app_info.appVersion = 1;
206 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
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600223VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
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
227 result = cmdBuffer.BeginCommandBuffer();
228
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 Wu08accc62015-07-07 11:50:03 +0800234 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600235 }
236
237 return result;
238}
239
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600240VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
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 Wu0b50a1c2015-06-26 15:34:39 +0800245 cmdBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200246 }
Tony Barbour300a6082015-04-07 13:44:53 -0600247
248 result = cmdBuffer.EndCommandBuffer();
249
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
348void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
349{
350 if (m_depthStencil->Initialized()) {
351 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
352 } else {
353 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
354 }
355
356 cmdBuffer->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);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500379 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northrop29a08f22015-08-27 10:20:35 -0600380 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
381 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500382 cmdBuffer->BindPipeline(pipelineobj);
383 cmdBuffer->BindDescriptorSet(descriptorSet);
384}
385
386// ********************************************************************************************************************
387// ********************************************************************************************************************
388// ********************************************************************************************************************
389// ********************************************************************************************************************
Tobin Ehlis0788f522015-05-26 16:11:58 -0600390#if MEM_TRACKER_TESTS
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500391TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
392{
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();
409 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
410 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 Goeltzenleuchter646b9072015-10-20 18:04:07 -0600416 VkSubmitInfo submit_info = {
417 .waitSemCount = 0,
418 .pWaitSemaphores = NULL,
419 .cmdBufferCount = 1,
420 .pCommandBuffers = &m_cmdBuffer->handle(),
421 .signalSemCount = 0,
422 .pSignalSemaphores = NULL
423 };
424
425 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500426 ASSERT_VK_SUCCESS( err );
427
428 m_errorMonitor->ClearState();
429 // Introduce failure by calling begin again before checking fence
Tony Barbourfe3351b2015-07-28 10:17:20 -0600430 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500431
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600432 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600433 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 -0500434 if (!strstr(msgString.c_str(),"Resetting CB")) {
435 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
436 }
437}
438
439TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
440{
441 vk_testing::Fence testFence;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600442 VkFlags msgFlags;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500443 std::string msgString;
444
445 VkFenceCreateInfo fenceInfo = {};
446 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
447 fenceInfo.pNext = NULL;
448 fenceInfo.flags = 0;
449
450 ASSERT_NO_FATAL_FAILURE(InitState());
451 ASSERT_NO_FATAL_FAILURE(InitViewport());
452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
453
Tony Barbourfe3351b2015-07-28 10:17:20 -0600454 BeginCommandBuffer();
455 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
456 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500457
458 testFence.init(*m_device, fenceInfo);
459
460 // Bypass framework since it does the waits automatically
461 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600462 VkSubmitInfo submit_info = {
463 .waitSemCount = 0,
464 .pWaitSemaphores = NULL,
465 .cmdBufferCount = 1,
466 .pCommandBuffers = &m_cmdBuffer->handle(),
467 .signalSemCount = 0,
468 .pSignalSemaphores = NULL
469 };
470
471 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500472 ASSERT_VK_SUCCESS( err );
473
474 m_errorMonitor->ClearState();
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600475
476 VkCmdBufferBeginInfo info = {};
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -0600477 info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600478 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
479 info.renderPass = VK_NULL_HANDLE;
480 info.subpass = 0;
481 info.framebuffer = VK_NULL_HANDLE;
482
483 // Introduce failure by calling BCB again before checking fence
484 vkBeginCommandBuffer(m_cmdBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500485
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600486 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600487 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 -0500488 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
489 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
490 }
491}
492
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500493TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
494{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600495 VkFlags msgFlags;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500496 std::string msgString;
497 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600498 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500499
500 ASSERT_NO_FATAL_FAILURE(InitState());
501 m_errorMonitor->ClearState();
502
503 // Create an image, allocate memory, free it, and then try to bind it
504 VkImage image;
Mark Lobodzinski23065352015-05-29 09:32:35 -0500505 VkDeviceMemory mem;
506 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500507
508 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
509 const int32_t tex_width = 32;
510 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500511
Tony Barboureb254902015-07-15 12:50:33 -0600512 VkImageCreateInfo image_create_info = {};
513 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
514 image_create_info.pNext = NULL;
515 image_create_info.imageType = VK_IMAGE_TYPE_2D;
516 image_create_info.format = tex_format;
517 image_create_info.extent.width = tex_width;
518 image_create_info.extent.height = tex_height;
519 image_create_info.extent.depth = 1;
520 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600521 image_create_info.arrayLayers = 1;
Tony Barboureb254902015-07-15 12:50:33 -0600522 image_create_info.samples = 1;
523 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
524 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
525 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600526
Tony Barboureb254902015-07-15 12:50:33 -0600527 VkMemoryAllocInfo mem_alloc = {};
528 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
529 mem_alloc.pNext = NULL;
530 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -0600532 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500533
534 err = vkCreateImage(m_device->device(), &image_create_info, &image);
535 ASSERT_VK_SUCCESS(err);
536
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600537 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538 image,
Mark Lobodzinski23065352015-05-29 09:32:35 -0500539 &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500540
Mark Lobodzinski23065352015-05-29 09:32:35 -0500541 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500542
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600543 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
544 if(!pass) { // If we can't find any unmappable memory this test doesn't make sense
Mike Stroyand1c84a52015-08-18 14:40:24 -0600545 vkDestroyImage(m_device->device(), image);
Tony Barbour02fdc7d2015-08-04 16:13:01 -0600546 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -0600547 }
Mike Stroyan713b2d72015-08-04 10:49:29 -0600548
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500549 // allocate memory
Mark Lobodzinski23065352015-05-29 09:32:35 -0500550 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500551 ASSERT_VK_SUCCESS(err);
552
553 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -0600554 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500555 ASSERT_VK_SUCCESS(err);
556
557 // Map memory as if to initialize the image
558 void *mappedAddress = NULL;
Mark Lobodzinski23065352015-05-29 09:32:35 -0500559 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500560
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600561 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600562 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 -0500563 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
564 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
565 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600566
567 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500568}
569
Tobin Ehlis2717d132015-07-10 18:25:07 -0600570// TODO : Is this test still valid. Not sure it is with updates to memory binding model
571// Verify and delete the test of fix the check
572//TEST_F(VkLayerTest, FreeBoundMemory)
573//{
574// VkFlags msgFlags;
575// std::string msgString;
576// VkResult err;
577//
578// ASSERT_NO_FATAL_FAILURE(InitState());
579// m_errorMonitor->ClearState();
580//
581// // Create an image, allocate memory, free it, and then try to bind it
582// VkImage image;
583// VkDeviceMemory mem;
584// VkMemoryRequirements mem_reqs;
585//
586// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
587// const int32_t tex_width = 32;
588// const int32_t tex_height = 32;
589//
590// const VkImageCreateInfo image_create_info = {
591// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
592// .pNext = NULL,
593// .imageType = VK_IMAGE_TYPE_2D,
594// .format = tex_format,
595// .extent = { tex_width, tex_height, 1 },
596// .mipLevels = 1,
597// .arraySize = 1,
598// .samples = 1,
599// .tiling = VK_IMAGE_TILING_LINEAR,
600// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
601// .flags = 0,
602// };
603// VkMemoryAllocInfo mem_alloc = {
604// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
605// .pNext = NULL,
606// .allocationSize = 0,
607// .memoryTypeIndex = 0,
608// };
609//
610// err = vkCreateImage(m_device->device(), &image_create_info, &image);
611// ASSERT_VK_SUCCESS(err);
612//
613// err = vkGetImageMemoryRequirements(m_device->device(),
614// image,
615// &mem_reqs);
616// ASSERT_VK_SUCCESS(err);
617//
618// mem_alloc.allocationSize = mem_reqs.size;
619//
620// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
621// ASSERT_VK_SUCCESS(err);
622//
623// // allocate memory
624// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
625// ASSERT_VK_SUCCESS(err);
626//
627// // Bind memory to Image object
628// err = vkBindImageMemory(m_device->device(), image, mem, 0);
629// ASSERT_VK_SUCCESS(err);
630//
631// // Introduce validation failure, free memory while still bound to object
632// vkFreeMemory(m_device->device(), mem);
Tobin Ehlis2717d132015-07-10 18:25:07 -0600633// msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600634//
Cody Northropd2ad0342015-08-05 11:15:02 -0600635// 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 -0600636// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
637// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
638// }
639//}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500640
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500641TEST_F(VkLayerTest, RebindMemory)
642{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600643 VkFlags msgFlags;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500644 std::string msgString;
645 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600646 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500647
648 ASSERT_NO_FATAL_FAILURE(InitState());
649 m_errorMonitor->ClearState();
650
651 // Create an image, allocate memory, free it, and then try to bind it
652 VkImage image;
653 VkDeviceMemory mem1;
654 VkDeviceMemory mem2;
655 VkMemoryRequirements mem_reqs;
656
657 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
658 const int32_t tex_width = 32;
659 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500660
Tony Barboureb254902015-07-15 12:50:33 -0600661 VkImageCreateInfo image_create_info = {};
662 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
663 image_create_info.pNext = NULL;
664 image_create_info.imageType = VK_IMAGE_TYPE_2D;
665 image_create_info.format = tex_format;
666 image_create_info.extent.width = tex_width;
667 image_create_info.extent.height = tex_height;
668 image_create_info.extent.depth = 1;
669 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600670 image_create_info.arrayLayers = 1;
Tony Barboureb254902015-07-15 12:50:33 -0600671 image_create_info.samples = 1;
672 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
673 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
674 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500675
Tony Barboureb254902015-07-15 12:50:33 -0600676 VkMemoryAllocInfo mem_alloc = {};
677 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
678 mem_alloc.pNext = NULL;
679 mem_alloc.allocationSize = 0;
680 mem_alloc.memoryTypeIndex = 0;
681
682 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
683 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500684 err = vkCreateImage(m_device->device(), &image_create_info, &image);
685 ASSERT_VK_SUCCESS(err);
686
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600687 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500688 image,
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500689 &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500690
691 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600692 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
693 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500694
695 // allocate 2 memory objects
696 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
697 ASSERT_VK_SUCCESS(err);
698 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
699 ASSERT_VK_SUCCESS(err);
700
701 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -0600702 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500703 ASSERT_VK_SUCCESS(err);
704
705 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barbour67e99152015-07-10 14:10:27 -0600706 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500707
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600708 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600709 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 -0500710 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
711 FAIL() << "Error received did not match expected message when rebinding memory to an object";
712 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600713
714 vkDestroyImage(m_device->device(), image);
715 vkFreeMemory(m_device->device(), mem1);
716 vkFreeMemory(m_device->device(), mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500717}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500718
Tony Barbour0b4d9562015-04-09 10:48:04 -0600719TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour300a6082015-04-07 13:44:53 -0600720{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600721 vk_testing::Fence testFence;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600722 VkFlags msgFlags;
Tony Barbour300a6082015-04-07 13:44:53 -0600723 std::string msgString;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600724
725 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600726 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
727 fenceInfo.pNext = NULL;
728 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -0600729
Tony Barbour300a6082015-04-07 13:44:53 -0600730 ASSERT_NO_FATAL_FAILURE(InitState());
731 ASSERT_NO_FATAL_FAILURE(InitViewport());
732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
733
Tony Barbourfe3351b2015-07-28 10:17:20 -0600734 BeginCommandBuffer();
735 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
736 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600737
738 testFence.init(*m_device, fenceInfo);
739 m_errorMonitor->ClearState();
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600740
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600741 VkSubmitInfo submit_info = {
742 .waitSemCount = 0,
743 .pWaitSemaphores = NULL,
744 .cmdBufferCount = 1,
745 .pCommandBuffers = &m_cmdBuffer->handle(),
746 .signalSemCount = 0,
747 .pSignalSemaphores = NULL
748 };
749
750 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600751 vkQueueWaitIdle(m_device->m_queue );
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600752 msgFlags = m_errorMonitor->GetState(&msgString);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600753
Cody Northropd2ad0342015-08-05 11:15:02 -0600754 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 -0600755 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500756 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour0b4d9562015-04-09 10:48:04 -0600757 }
758
759}
760
761TEST_F(VkLayerTest, ResetUnsignaledFence)
762{
763 vk_testing::Fence testFence;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600764 VkFlags msgFlags;
Tony Barbour0b4d9562015-04-09 10:48:04 -0600765 std::string msgString;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600766 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600767 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
768 fenceInfo.pNext = NULL;
769
Tony Barbour0b4d9562015-04-09 10:48:04 -0600770 ASSERT_NO_FATAL_FAILURE(InitState());
771 testFence.init(*m_device, fenceInfo);
772 m_errorMonitor->ClearState();
Chia-I Wud9e8e822015-07-03 11:45:55 +0800773 VkFence fences[1] = {testFence.handle()};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600774 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600775 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisbcca3ce2015-10-01 10:14:48 -0600776 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 -0600777 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500778 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour0b4d9562015-04-09 10:48:04 -0600779 }
Tony Barbour300a6082015-04-07 13:44:53 -0600780
781}
Tobin Ehlis41376e12015-07-03 08:45:14 -0600782
Chia-I Wu08accc62015-07-07 11:50:03 +0800783/* TODO: Update for changes due to bug-14075 tiling across render passes */
784#if 0
Tobin Ehlis41376e12015-07-03 08:45:14 -0600785TEST_F(VkLayerTest, InvalidUsageBits)
786{
787 // Initiate Draw w/o a PSO bound
788 VkFlags msgFlags;
789 std::string msgString;
790
791 ASSERT_NO_FATAL_FAILURE(InitState());
792 m_errorMonitor->ClearState();
793 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600794 BeginCommandBuffer();
Tobin Ehlis41376e12015-07-03 08:45:14 -0600795
796 const VkExtent3D e3d = {
797 .width = 128,
798 .height = 128,
799 .depth = 1,
800 };
801 const VkImageCreateInfo ici = {
802 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
803 .pNext = NULL,
804 .imageType = VK_IMAGE_TYPE_2D,
805 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
806 .extent = e3d,
807 .mipLevels = 1,
808 .arraySize = 1,
809 .samples = 1,
810 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -0600811 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlis41376e12015-07-03 08:45:14 -0600812 .flags = 0,
813 };
814
815 VkImage dsi;
816 vkCreateImage(m_device->device(), &ici, &dsi);
817 VkDepthStencilView dsv;
818 const VkDepthStencilViewCreateInfo dsvci = {
819 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
820 .pNext = NULL,
821 .image = dsi,
822 .mipLevel = 0,
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600823 .baseArrayLayer = 0,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600824 .arraySize = 1,
825 .flags = 0,
826 };
827 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
828 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600829 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 -0600830 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
831 FAIL() << "Error received was not 'Invalid usage flag for image...'";
832 }
833}
Mark Lobodzinski209b5292015-09-17 09:44:05 -0600834#endif // 0
835#endif // MEM_TRACKER_TESTS
836
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600837#if OBJ_TRACKER_TESTS
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600838TEST_F(VkLayerTest, PipelineNotBound)
839{
840 VkFlags msgFlags;
841 std::string msgString;
842 VkResult err;
843
844 ASSERT_NO_FATAL_FAILURE(InitState());
845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
846 m_errorMonitor->ClearState();
847
848 VkDescriptorTypeCount ds_type_count = {};
849 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
850 ds_type_count.count = 1;
851
852 VkDescriptorPoolCreateInfo ds_pool_ci = {};
853 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
854 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -0600855 ds_pool_ci.maxSets = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600856 ds_pool_ci.count = 1;
857 ds_pool_ci.pTypeCount = &ds_type_count;
858
859 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -0600860 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600861 ASSERT_VK_SUCCESS(err);
862
863 VkDescriptorSetLayoutBinding dsl_binding = {};
864 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
865 dsl_binding.arraySize = 1;
866 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
867 dsl_binding.pImmutableSamplers = NULL;
868
869 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
870 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
871 ds_layout_ci.pNext = NULL;
872 ds_layout_ci.count = 1;
873 ds_layout_ci.pBinding = &dsl_binding;
874
875 VkDescriptorSetLayout ds_layout;
876 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
877 ASSERT_VK_SUCCESS(err);
878
879 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600880 VkDescriptorSetAllocInfo alloc_info = {};
881 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
882 alloc_info.count = 1;
883 alloc_info.descriptorPool = ds_pool;
884 alloc_info.pSetLayouts = &ds_layout;
885 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600886 ASSERT_VK_SUCCESS(err);
887
888 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
889 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
890 pipeline_layout_ci.pNext = NULL;
891 pipeline_layout_ci.descriptorSetCount = 1;
892 pipeline_layout_ci.pSetLayouts = &ds_layout;
893
894 VkPipelineLayout pipeline_layout;
895 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
896 ASSERT_VK_SUCCESS(err);
897
898 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
899
900 BeginCommandBuffer();
901 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
902
903 msgFlags = m_errorMonitor->GetState(&msgString);
904 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlisec598302015-09-15 15:02:17 -0600905 if (!strstr(msgString.c_str(),"Invalid VkPipeline Object ")) {
906 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be' but instead it was '" << msgString.c_str() << "'";
907 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600908
909 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -0600910 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
911 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlisec598302015-09-15 15:02:17 -0600912}
913
914TEST_F(VkLayerTest, BindInvalidMemory)
915{
916 VkFlags msgFlags;
917 std::string msgString;
918 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600919 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -0600920
921 ASSERT_NO_FATAL_FAILURE(InitState());
922 m_errorMonitor->ClearState();
923
924 // Create an image, allocate memory, free it, and then try to bind it
925 VkImage image;
926 VkDeviceMemory mem;
927 VkMemoryRequirements mem_reqs;
928
929 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
930 const int32_t tex_width = 32;
931 const int32_t tex_height = 32;
932
933 VkImageCreateInfo image_create_info = {};
934 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
935 image_create_info.pNext = NULL;
936 image_create_info.imageType = VK_IMAGE_TYPE_2D;
937 image_create_info.format = tex_format;
938 image_create_info.extent.width = tex_width;
939 image_create_info.extent.height = tex_height;
940 image_create_info.extent.depth = 1;
941 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600942 image_create_info.arrayLayers = 1;
Tobin Ehlisec598302015-09-15 15:02:17 -0600943 image_create_info.samples = 1;
944 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
945 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
946 image_create_info.flags = 0;
947
948 VkMemoryAllocInfo mem_alloc = {};
949 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
950 mem_alloc.pNext = NULL;
951 mem_alloc.allocationSize = 0;
952 mem_alloc.memoryTypeIndex = 0;
953
954 err = vkCreateImage(m_device->device(), &image_create_info, &image);
955 ASSERT_VK_SUCCESS(err);
956
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600957 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlisec598302015-09-15 15:02:17 -0600958 image,
959 &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -0600960
961 mem_alloc.allocationSize = mem_reqs.size;
962
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600963 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
964 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -0600965
966 // allocate memory
967 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
968 ASSERT_VK_SUCCESS(err);
969
970 // Introduce validation failure, free memory before binding
971 vkFreeMemory(m_device->device(), mem);
Tobin Ehlisec598302015-09-15 15:02:17 -0600972
973 // Try to bind free memory that has been freed
974 err = vkBindImageMemory(m_device->device(), image, mem, 0);
975 // This may very well return an error.
976 (void)err;
977
978 msgFlags = m_errorMonitor->GetState(&msgString);
979 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to bind a freed memory object";
980 if (!strstr(msgString.c_str(),"Invalid VkDeviceMemory Object ")) {
981 FAIL() << "Error received from BindInvalidMemory was not 'Invalid VkDeviceMemory Object 0x<handle>' but instead '" << msgString.c_str() << "'";
982 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600983
984 vkDestroyImage(m_device->device(), image);
Tobin Ehlisec598302015-09-15 15:02:17 -0600985}
986
987TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
988{
989 VkFlags msgFlags;
990 std::string msgString;
991 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600992 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -0600993
994 ASSERT_NO_FATAL_FAILURE(InitState());
995 m_errorMonitor->ClearState();
996
997 // Create an image object, allocate memory, destroy the object and then try to bind it
998 VkImage image;
999 VkDeviceMemory mem;
1000 VkMemoryRequirements mem_reqs;
1001
1002 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1003 const int32_t tex_width = 32;
1004 const int32_t tex_height = 32;
1005
1006 VkImageCreateInfo image_create_info = {};
1007 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1008 image_create_info.pNext = NULL;
1009 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1010 image_create_info.format = tex_format;
1011 image_create_info.extent.width = tex_width;
1012 image_create_info.extent.height = tex_height;
1013 image_create_info.extent.depth = 1;
1014 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06001015 image_create_info.arrayLayers = 1;
Tobin Ehlisec598302015-09-15 15:02:17 -06001016 image_create_info.samples = 1;
1017 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1018 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1019 image_create_info.flags = 0;
1020
1021 VkMemoryAllocInfo mem_alloc = {};
1022 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1023 mem_alloc.pNext = NULL;
1024 mem_alloc.allocationSize = 0;
1025 mem_alloc.memoryTypeIndex = 0;
1026
1027 err = vkCreateImage(m_device->device(), &image_create_info, &image);
1028 ASSERT_VK_SUCCESS(err);
1029
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001030 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlisec598302015-09-15 15:02:17 -06001031 image,
1032 &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06001033
1034 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001035 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1036 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001037
1038 // Allocate memory
1039 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
1040 ASSERT_VK_SUCCESS(err);
1041
1042 // Introduce validation failure, destroy Image object before binding
1043 vkDestroyImage(m_device->device(), image);
1044 ASSERT_VK_SUCCESS(err);
1045
1046 // Now Try to bind memory to this destroyed object
1047 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1048 // This may very well return an error.
1049 (void) err;
1050
1051 msgFlags = m_errorMonitor->GetState(&msgString);
1052 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while binding memory to a destroyed object";
1053 if (!strstr(msgString.c_str(),"Invalid VkImage Object ")) {
1054 FAIL() << "Error received from BindMemoryToDestroyedObject was not 'Invalid VkImage Object 0x<handle>' but rather '" << msgString.c_str() << "'";
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001055 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001056
1057 vkFreeMemory(m_device->device(), mem);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001058}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001059#endif // OBJ_TRACKER_TESTS
1060
Tobin Ehlis0788f522015-05-26 16:11:58 -06001061#if DRAW_STATE_TESTS
Tobin Ehlis963a4042015-09-29 08:18:34 -06001062TEST_F(VkLayerTest, LineWidthStateNotBound)
1063{
1064 VkFlags msgFlags;
1065 std::string msgString;
1066 m_errorMonitor->ClearState();
1067 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1068
1069 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1070
1071 msgFlags = m_errorMonitor->GetState(&msgString);
1072 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Line Width State Object";
1073 if (!strstr(msgString.c_str(),"Dynamic line width state not set for this command buffer")) {
1074 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic line width state not set for this command buffer'";
1075 }
1076}
1077
1078TEST_F(VkLayerTest, DepthBiasStateNotBound)
1079{
1080 VkFlags msgFlags;
1081 std::string msgString;
1082 m_errorMonitor->ClearState();
1083 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1084
1085 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1086
1087 msgFlags = m_errorMonitor->GetState(&msgString);
1088 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bias State Object";
1089 if (!strstr(msgString.c_str(),"Dynamic depth bias state not set for this command buffer")) {
1090 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bias state not set for this command buffer'";
1091 }
1092}
1093
1094TEST_F(VkLayerTest, ViewportStateNotBound)
1095{
1096 VkFlags msgFlags;
1097 std::string msgString;
1098 m_errorMonitor->ClearState();
1099 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1100
1101 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1102
1103 msgFlags = m_errorMonitor->GetState(&msgString);
1104 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 -06001105 // TODO : Viewport and scissor currently set as a pair in framework so scissor error masks viewport error
1106 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1107 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
Tobin Ehlis963a4042015-09-29 08:18:34 -06001108 }
1109}
1110
1111TEST_F(VkLayerTest, ScissorStateNotBound)
1112{
1113 VkFlags msgFlags;
1114 std::string msgString;
1115 m_errorMonitor->ClearState();
1116 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1117
1118 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1119
1120 msgFlags = m_errorMonitor->GetState(&msgString);
1121 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
1122 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1123 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
1124 }
1125}
1126
Tobin Ehlis963a4042015-09-29 08:18:34 -06001127TEST_F(VkLayerTest, BlendStateNotBound)
1128{
1129 VkFlags msgFlags;
1130 std::string msgString;
1131 m_errorMonitor->ClearState();
1132 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1133
1134 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1135
1136 msgFlags = m_errorMonitor->GetState(&msgString);
1137 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
1138 if (!strstr(msgString.c_str(),"Dynamic blend object state not set for this command buffer")) {
1139 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic blend object state not set for this command buffer'";
1140 }
1141}
1142
1143TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1144{
1145 VkFlags msgFlags;
1146 std::string msgString;
1147 m_errorMonitor->ClearState();
1148 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1149
1150 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1151
1152 msgFlags = m_errorMonitor->GetState(&msgString);
1153 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
1154 if (!strstr(msgString.c_str(),"Dynamic depth bounds state not set for this command buffer")) {
1155 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bounds state not set for this command buffer'";
1156 }
1157}
1158
1159TEST_F(VkLayerTest, StencilReadMaskNotSet)
1160{
1161 VkFlags msgFlags;
1162 std::string msgString;
1163 ASSERT_NO_FATAL_FAILURE(InitState());
1164 m_errorMonitor->ClearState();
1165 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1166
1167 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1168
1169 msgFlags = m_errorMonitor->GetState(&msgString);
1170 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Read Mask";
1171 if (!strstr(msgString.c_str(),"Dynamic stencil read mask state not set for this command buffer")) {
1172 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil read mask state not set for this command buffer'";
1173 }
1174}
1175
1176TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1177{
1178 VkFlags msgFlags;
1179 std::string msgString;
1180 ASSERT_NO_FATAL_FAILURE(InitState());
1181 m_errorMonitor->ClearState();
1182 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1183
1184 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1185
1186 msgFlags = m_errorMonitor->GetState(&msgString);
1187 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Write Mask";
1188 if (!strstr(msgString.c_str(),"Dynamic stencil write mask state not set for this command buffer")) {
1189 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil write mask state not set for this command buffer'";
1190 }
1191}
1192
1193TEST_F(VkLayerTest, StencilReferenceNotSet)
1194{
1195 VkFlags msgFlags;
1196 std::string msgString;
1197 m_errorMonitor->ClearState();
1198 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1199
1200 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1201
1202 msgFlags = m_errorMonitor->GetState(&msgString);
1203 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Reference";
1204 if (!strstr(msgString.c_str(),"Dynamic stencil reference state not set for this command buffer")) {
1205 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil reference state not set for this command buffer'";
1206 }
1207}
1208
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001209TEST_F(VkLayerTest, CmdBufferTwoSubmits)
1210{
1211 vk_testing::Fence testFence;
1212 VkFlags msgFlags;
1213 std::string msgString;
1214
1215 VkFenceCreateInfo fenceInfo = {};
1216 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1217 fenceInfo.pNext = NULL;
1218 fenceInfo.flags = 0;
1219
1220 ASSERT_NO_FATAL_FAILURE(InitState());
1221 ASSERT_NO_FATAL_FAILURE(InitViewport());
1222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1223
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -06001224 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001225 BeginCommandBuffer();
1226 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1227 EndCommandBuffer();
1228
1229 testFence.init(*m_device, fenceInfo);
1230
1231 // Bypass framework since it does the waits automatically
1232 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001233 VkSubmitInfo submit_info = {
1234 .waitSemCount = 0,
1235 .pWaitSemaphores = NULL,
1236 .cmdBufferCount = 1,
1237 .pCommandBuffers = &m_cmdBuffer->handle(),
1238 .signalSemCount = 0,
1239 .pSignalSemaphores = NULL
1240 };
1241 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001242 ASSERT_VK_SUCCESS( err );
1243
1244 m_errorMonitor->ClearState();
1245 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001246 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001247
1248 msgFlags = m_errorMonitor->GetState(&msgString);
1249 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";
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -06001250 if (!strstr(msgString.c_str(),"was begun w/ VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted")) {
1251 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001252 }
1253}
1254
Tobin Ehlis502480b2015-06-24 15:53:07 -06001255TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001256{
1257 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001258 VkFlags msgFlags;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001259 std::string msgString;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001260 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001261
1262 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001264 m_errorMonitor->ClearState();
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001265
1266 VkDescriptorTypeCount ds_type_count = {};
1267 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1268 ds_type_count.count = 1;
1269
1270 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1271 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1272 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001273 ds_pool_ci.maxSets = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001274 ds_pool_ci.count = 1;
1275 ds_pool_ci.pTypeCount = &ds_type_count;
1276
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001277 VkDescriptorPool ds_pool;
1278 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001279 ASSERT_VK_SUCCESS(err);
1280
1281 VkDescriptorSetLayoutBinding dsl_binding = {};
1282 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1283 dsl_binding.arraySize = 1;
1284 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1285 dsl_binding.pImmutableSamplers = NULL;
1286
1287 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1288 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1289 ds_layout_ci.pNext = NULL;
1290 ds_layout_ci.count = 1;
1291 ds_layout_ci.pBinding = &dsl_binding;
1292
1293 VkDescriptorSetLayout ds_layout;
1294 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1295 ASSERT_VK_SUCCESS(err);
1296
1297 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001298 VkDescriptorSetAllocInfo alloc_info = {};
1299 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1300 alloc_info.count = 1;
1301 alloc_info.descriptorPool = ds_pool;
1302 alloc_info.pSetLayouts = &ds_layout;
1303 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001304 ASSERT_VK_SUCCESS(err);
1305 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1306 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1307 pipe_ms_state_ci.pNext = NULL;
1308 pipe_ms_state_ci.rasterSamples = 1;
1309 pipe_ms_state_ci.sampleShadingEnable = 0;
1310 pipe_ms_state_ci.minSampleShading = 1.0;
1311 pipe_ms_state_ci.pSampleMask = NULL;
1312
1313 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1314 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1315 pipeline_layout_ci.pNext = NULL;
1316 pipeline_layout_ci.descriptorSetCount = 1;
1317 pipeline_layout_ci.pSetLayouts = &ds_layout;
1318 VkPipelineLayout pipeline_layout;
1319
1320 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1321 ASSERT_VK_SUCCESS(err);
1322
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001323 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1324 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 -06001325 // but add it to be able to run on more devices
1326 VkPipelineObj pipe(m_device);
1327 pipe.AddShader(&vs);
1328 pipe.AddShader(&fs);
1329 pipe.SetMSAA(&pipe_ms_state_ci);
1330 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1331 m_errorMonitor->ClearState();
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001332 // Calls AllocCommandBuffers
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001333 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1334 VkCmdBufferBeginInfo cmd_buf_info = {};
1335 memset(&cmd_buf_info, 0, sizeof(VkCmdBufferBeginInfo));
1336 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1337 cmd_buf_info.pNext = NULL;
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -06001338 cmd_buf_info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001339
1340 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1341 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001342 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001343 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding pipeline to CmdBuffer w/o active RenderPass";
Tobin Ehlis502480b2015-06-24 15:53:07 -06001344 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001345 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 -06001346 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001347
1348 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06001349 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1350 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001351}
1352
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001353TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1354{
1355 // Initiate Draw w/o a PSO bound
1356 VkFlags msgFlags;
1357 std::string msgString;
1358 VkResult err;
1359
1360 ASSERT_NO_FATAL_FAILURE(InitState());
1361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1362 m_errorMonitor->ClearState();
1363
1364 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
1365 VkDescriptorTypeCount ds_type_count = {};
1366 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
1367 ds_type_count.count = 1;
1368
1369 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1370 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1371 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001372 ds_pool_ci.flags = 0;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001373 ds_pool_ci.maxSets = 1;
1374 ds_pool_ci.count = 1;
1375 ds_pool_ci.pTypeCount = &ds_type_count;
1376
1377 VkDescriptorPool ds_pool;
1378 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1379 ASSERT_VK_SUCCESS(err);
1380
1381 VkDescriptorSetLayoutBinding dsl_binding = {};
1382 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1383 dsl_binding.arraySize = 1;
1384 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1385 dsl_binding.pImmutableSamplers = NULL;
1386
1387 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1388 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1389 ds_layout_ci.pNext = NULL;
1390 ds_layout_ci.count = 1;
1391 ds_layout_ci.pBinding = &dsl_binding;
1392
1393 VkDescriptorSetLayout ds_layout;
1394 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1395 ASSERT_VK_SUCCESS(err);
1396
1397 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001398 VkDescriptorSetAllocInfo alloc_info = {};
1399 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1400 alloc_info.count = 1;
1401 alloc_info.descriptorPool = ds_pool;
1402 alloc_info.pSetLayouts = &ds_layout;
1403 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001404
1405 msgFlags = m_errorMonitor->GetState(&msgString);
1406 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after alloc descriptor from pool w/o requested type";
1407 if (!strstr(msgString.c_str(),"Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ")) {
1408 FAIL() << "Error received was not 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...' but rather '" << msgString.c_str() << "'";
1409 }
1410
1411 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1412 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1413}
1414
Tobin Ehlise735c692015-10-08 13:13:50 -06001415TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1416{
1417 VkFlags msgFlags;
1418 std::string msgString;
1419 VkResult err;
1420
1421 ASSERT_NO_FATAL_FAILURE(InitState());
1422 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1423 m_errorMonitor->ClearState();
1424
1425 VkDescriptorTypeCount ds_type_count = {};
1426 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1427 ds_type_count.count = 1;
1428
1429 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1430 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1431 ds_pool_ci.pNext = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06001432 ds_pool_ci.maxSets = 1;
1433 ds_pool_ci.count = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001434 ds_pool_ci.flags = 0;
1435 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1436 // app can only call vkResetDescriptorPool on this pool.;
Tobin Ehlise735c692015-10-08 13:13:50 -06001437 ds_pool_ci.pTypeCount = &ds_type_count;
1438
1439 VkDescriptorPool ds_pool;
1440 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1441 ASSERT_VK_SUCCESS(err);
1442
1443 VkDescriptorSetLayoutBinding dsl_binding = {};
1444 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1445 dsl_binding.arraySize = 1;
1446 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1447 dsl_binding.pImmutableSamplers = NULL;
1448
1449 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1450 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1451 ds_layout_ci.pNext = NULL;
1452 ds_layout_ci.count = 1;
1453 ds_layout_ci.pBinding = &dsl_binding;
1454
1455 VkDescriptorSetLayout ds_layout;
1456 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1457 ASSERT_VK_SUCCESS(err);
1458
1459 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001460 VkDescriptorSetAllocInfo alloc_info = {};
1461 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1462 alloc_info.count = 1;
1463 alloc_info.descriptorPool = ds_pool;
1464 alloc_info.pSetLayouts = &ds_layout;
1465 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06001466 ASSERT_VK_SUCCESS(err);
1467
1468 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1469 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001470 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after freeing descriptor from non-free Pool";
1471
1472 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 -06001473 FAIL() << "Error received was not 'It is invalid to call vkFreeDescriptorSets() with a pool created with...' but instead it was '" << msgString.c_str() << "'";
1474 }
1475
1476 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1477 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1478}
1479
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001480TEST_F(VkLayerTest, InvalidDescriptorPool)
1481{
1482 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1483 // The DS check for this is after driver has been called to validate DS internal data struct
1484 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001485/* VkFlags msgFlags;
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001486 std::string msgString;
1487 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1488 vkResetDescriptorPool(device(), badPool);
1489
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001490 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001491 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 -06001492 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1493 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1494 }*/
1495}
1496
1497TEST_F(VkLayerTest, InvalidDescriptorSet)
1498{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001499 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1500 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001501 // Create a valid cmd buffer
1502 // call vkCmdBindDescriptorSets w/ false DS
1503}
1504
1505TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1506{
1507 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1508 // The DS check for this is after driver has been called to validate DS internal data struct
1509}
1510
1511TEST_F(VkLayerTest, InvalidPipeline)
1512{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001513 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1514 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001515 // Create a valid cmd buffer
1516 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlis502480b2015-06-24 15:53:07 -06001517// VkFlags msgFlags;
1518// std::string msgString;
1519//
1520// ASSERT_NO_FATAL_FAILURE(InitState());
1521// m_errorMonitor->ClearState();
1522// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001523// BeginCommandBuffer();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001524// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1525// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1526// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001527// ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlis502480b2015-06-24 15:53:07 -06001528// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1529// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1530// }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001531}
1532
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001533TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001534{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001535 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001536 VkFlags msgFlags;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001537 std::string msgString;
1538 VkResult err;
1539
1540 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06001541 ASSERT_NO_FATAL_FAILURE(InitViewport());
1542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001543 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06001544 VkDescriptorTypeCount ds_type_count = {};
1545 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1546 ds_type_count.count = 1;
1547
1548 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1549 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1550 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001551 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001552 ds_pool_ci.count = 1;
1553 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06001554
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001555 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001556 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001557 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001558
Tony Barboureb254902015-07-15 12:50:33 -06001559 VkDescriptorSetLayoutBinding dsl_binding = {};
1560 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1561 dsl_binding.arraySize = 1;
1562 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1563 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001564
Tony Barboureb254902015-07-15 12:50:33 -06001565 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1566 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1567 ds_layout_ci.pNext = NULL;
1568 ds_layout_ci.count = 1;
1569 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001570 VkDescriptorSetLayout ds_layout;
1571 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1572 ASSERT_VK_SUCCESS(err);
1573
1574 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001575 VkDescriptorSetAllocInfo alloc_info = {};
1576 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1577 alloc_info.count = 1;
1578 alloc_info.descriptorPool = ds_pool;
1579 alloc_info.pSetLayouts = &ds_layout;
1580 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001581 ASSERT_VK_SUCCESS(err);
1582
Tony Barboureb254902015-07-15 12:50:33 -06001583 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1584 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1585 pipeline_layout_ci.pNext = NULL;
1586 pipeline_layout_ci.descriptorSetCount = 1;
1587 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001588
1589 VkPipelineLayout pipeline_layout;
1590 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1591 ASSERT_VK_SUCCESS(err);
1592
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001593 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1594 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 -06001595 // but add it to be able to run on more devices
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001596
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001597 VkPipelineObj pipe(m_device);
1598 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06001599 pipe.AddShader(&fs);
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001600 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001601
1602 BeginCommandBuffer();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001603 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001604 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001605
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001606 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001607 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 -06001608 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1609 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1610 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001611
1612 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06001613 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1614 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001615}
1616
1617TEST_F(VkLayerTest, NoBeginCmdBuffer)
1618{
1619 VkFlags msgFlags;
1620 std::string msgString;
1621
1622 ASSERT_NO_FATAL_FAILURE(InitState());
1623 m_errorMonitor->ClearState();
Tony Barbourfe3351b2015-07-28 10:17:20 -06001624 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001625 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1626 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1627 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001628 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after ending a CmdBuffer w/o calling BeginCommandBuffer()";
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001629 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1630 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1631 }
1632}
1633
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001634TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1635{
1636 VkFlags msgFlags;
1637 std::string msgString;
1638
1639 ASSERT_NO_FATAL_FAILURE(InitState());
1640 m_errorMonitor->ClearState();
1641
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001642 // Calls AllocCommandBuffers
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001643 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1644
1645 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northropb4569702015-08-04 17:35:57 -06001646 VkCmdBufferBeginInfo cmd_buf_info = {};
1647 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1648 cmd_buf_info.pNext = NULL;
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -06001649 cmd_buf_info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northropb4569702015-08-04 17:35:57 -06001650 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1651 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1652
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001653
1654 // The error should be caught by validation of the BeginCommandBuffer call
1655 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1656
1657 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001658 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 -06001659 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001660 FAIL() << "Error received was not 'vkAllocCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001661 }
1662}
1663
1664TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1665{
1666 VkFlags msgFlags;
1667 std::string msgString;
1668 VkResult err;
1669 VkCmdBuffer draw_cmd;
1670 VkCmdPool cmd_pool;
1671
1672 ASSERT_NO_FATAL_FAILURE(InitState());
1673 m_errorMonitor->ClearState();
1674
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001675 VkCmdBufferAllocInfo cmd = {};
1676 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_ALLOC_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06001677 cmd.pNext = NULL;
1678 cmd.cmdPool = m_cmdPool;
1679 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001680 cmd.count = 1;
Cody Northropb4569702015-08-04 17:35:57 -06001681
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001682 err = vkAllocCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06001683 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001684
1685 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northropb4569702015-08-04 17:35:57 -06001686 VkCmdBufferBeginInfo cmd_buf_info = {};
1687 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1688 cmd_buf_info.pNext = NULL;
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -06001689 cmd_buf_info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001690
1691 // The error should be caught by validation of the BeginCommandBuffer call
1692 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1693
1694 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001695 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 -06001696 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001697 FAIL() << "Error received was not 'vkAllocCommandBuffers(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001698 }
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001699 vkFreeCommandBuffers(m_device->device(), m_cmdPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001700}
1701
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001702TEST_F(VkLayerTest, InvalidPipelineCreateState)
1703{
1704 // Attempt to Create Gfx Pipeline w/o a VS
1705 VkFlags msgFlags;
1706 std::string msgString;
1707 VkResult err;
1708
1709 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001711 m_errorMonitor->ClearState();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001712
Tony Barboureb254902015-07-15 12:50:33 -06001713 VkDescriptorTypeCount ds_type_count = {};
1714 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1715 ds_type_count.count = 1;
1716
1717 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1718 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1719 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001720 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001721 ds_pool_ci.count = 1;
1722 ds_pool_ci.pTypeCount = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001723
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001724 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001725 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001726 ASSERT_VK_SUCCESS(err);
1727
Tony Barboureb254902015-07-15 12:50:33 -06001728 VkDescriptorSetLayoutBinding dsl_binding = {};
1729 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1730 dsl_binding.arraySize = 1;
1731 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1732 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001733
Tony Barboureb254902015-07-15 12:50:33 -06001734 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1735 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1736 ds_layout_ci.pNext = NULL;
1737 ds_layout_ci.count = 1;
1738 ds_layout_ci.pBinding = &dsl_binding;
1739
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001740 VkDescriptorSetLayout ds_layout;
1741 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1742 ASSERT_VK_SUCCESS(err);
1743
1744 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001745 VkDescriptorSetAllocInfo alloc_info = {};
1746 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1747 alloc_info.count = 1;
1748 alloc_info.descriptorPool = ds_pool;
1749 alloc_info.pSetLayouts = &ds_layout;
1750 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001751 ASSERT_VK_SUCCESS(err);
1752
Tony Barboureb254902015-07-15 12:50:33 -06001753 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1754 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tony Barboureb254902015-07-15 12:50:33 -06001755 pipeline_layout_ci.descriptorSetCount = 1;
1756 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001757
1758 VkPipelineLayout pipeline_layout;
1759 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1760 ASSERT_VK_SUCCESS(err);
1761
Tobin Ehlise68360f2015-10-01 11:15:13 -06001762 VkViewport vp = {}; // Just need dummy vp to point to
1763 VkRect2D sc = {}; // dummy scissor to point to
1764
1765 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1766 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1767 vp_state_ci.scissorCount = 1;
1768 vp_state_ci.pScissors = &sc;
1769 vp_state_ci.viewportCount = 1;
1770 vp_state_ci.pViewports = &vp;
1771
Tony Barboureb254902015-07-15 12:50:33 -06001772 VkGraphicsPipelineCreateInfo gp_ci = {};
1773 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06001774 gp_ci.pViewportState = &vp_state_ci;
Tony Barboureb254902015-07-15 12:50:33 -06001775 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1776 gp_ci.layout = pipeline_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001777 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06001778
1779 VkPipelineCacheCreateInfo pc_ci = {};
1780 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tony Barboureb254902015-07-15 12:50:33 -06001781 pc_ci.initialSize = 0;
1782 pc_ci.initialData = 0;
1783 pc_ci.maxSize = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001784
1785 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06001786 VkPipelineCache pipelineCache;
1787
1788 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1789 ASSERT_VK_SUCCESS(err);
1790 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001791
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001792 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001793 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 -06001794 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1795 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1796 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001797
1798 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1799 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06001800 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1801 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001802}
Tobin Ehlis912df022015-09-17 08:46:18 -06001803/*// TODO : This test should be good, but needs Tess support in compiler to run
1804TEST_F(VkLayerTest, InvalidPatchControlPoints)
1805{
1806 // Attempt to Create Gfx Pipeline w/o a VS
1807 VkFlags msgFlags;
1808 std::string msgString;
1809 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001810
Tobin Ehlis912df022015-09-17 08:46:18 -06001811 ASSERT_NO_FATAL_FAILURE(InitState());
1812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1813 m_errorMonitor->ClearState();
1814
1815 VkDescriptorTypeCount ds_type_count = {};
1816 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1817 ds_type_count.count = 1;
1818
1819 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1820 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1821 ds_pool_ci.pNext = NULL;
1822 ds_pool_ci.count = 1;
1823 ds_pool_ci.pTypeCount = &ds_type_count;
1824
1825 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001826 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06001827 ASSERT_VK_SUCCESS(err);
1828
1829 VkDescriptorSetLayoutBinding dsl_binding = {};
1830 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1831 dsl_binding.arraySize = 1;
1832 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1833 dsl_binding.pImmutableSamplers = NULL;
1834
1835 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1836 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1837 ds_layout_ci.pNext = NULL;
1838 ds_layout_ci.count = 1;
1839 ds_layout_ci.pBinding = &dsl_binding;
1840
1841 VkDescriptorSetLayout ds_layout;
1842 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1843 ASSERT_VK_SUCCESS(err);
1844
1845 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001846 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06001847 ASSERT_VK_SUCCESS(err);
1848
1849 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1850 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1851 pipeline_layout_ci.pNext = NULL;
1852 pipeline_layout_ci.descriptorSetCount = 1;
1853 pipeline_layout_ci.pSetLayouts = &ds_layout;
1854
1855 VkPipelineLayout pipeline_layout;
1856 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1857 ASSERT_VK_SUCCESS(err);
1858
1859 VkPipelineShaderStageCreateInfo shaderStages[3];
1860 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1861
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001862 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06001863 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001864 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
1865 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06001866
1867 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001868 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001869 shaderStages[0].shader = vs.handle();
1870 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001871 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001872 shaderStages[1].shader = tc.handle();
1873 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001874 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001875 shaderStages[2].shader = te.handle();
1876
1877 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1878 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1879 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1880
1881 VkPipelineTessellationStateCreateInfo tsCI = {};
1882 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1883 tsCI.patchControlPoints = 0; // This will cause an error
1884
1885 VkGraphicsPipelineCreateInfo gp_ci = {};
1886 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1887 gp_ci.pNext = NULL;
1888 gp_ci.stageCount = 3;
1889 gp_ci.pStages = shaderStages;
1890 gp_ci.pVertexInputState = NULL;
1891 gp_ci.pInputAssemblyState = &iaCI;
1892 gp_ci.pTessellationState = &tsCI;
1893 gp_ci.pViewportState = NULL;
1894 gp_ci.pRasterState = NULL;
1895 gp_ci.pMultisampleState = NULL;
1896 gp_ci.pDepthStencilState = NULL;
1897 gp_ci.pColorBlendState = NULL;
1898 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1899 gp_ci.layout = pipeline_layout;
1900 gp_ci.renderPass = renderPass();
1901
1902 VkPipelineCacheCreateInfo pc_ci = {};
1903 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1904 pc_ci.pNext = NULL;
1905 pc_ci.initialSize = 0;
1906 pc_ci.initialData = 0;
1907 pc_ci.maxSize = 0;
1908
1909 VkPipeline pipeline;
1910 VkPipelineCache pipelineCache;
1911
1912 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1913 ASSERT_VK_SUCCESS(err);
1914 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1915
1916 msgFlags = m_errorMonitor->GetState(&msgString);
1917 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Tess Gfx Pipeline w/ 0 patchControlPoints.";
1918 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ")) {
1919 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...' but instead '" << msgString.c_str() << "'";
1920 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001921
1922 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1923 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06001924 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1925 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06001926}
1927*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06001928// Set scissor and viewport counts to different numbers
1929TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
1930{
1931 // Attempt to Create Gfx Pipeline w/o a VS
1932 VkFlags msgFlags;
1933 std::string msgString;
1934 VkResult err;
1935
1936 ASSERT_NO_FATAL_FAILURE(InitState());
1937 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1938 m_errorMonitor->ClearState();
1939
1940 VkDescriptorTypeCount ds_type_count = {};
1941 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1942 ds_type_count.count = 1;
1943
1944 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1945 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06001946 ds_pool_ci.maxSets = 1;
1947 ds_pool_ci.count = 1;
1948 ds_pool_ci.pTypeCount = &ds_type_count;
1949
1950 VkDescriptorPool ds_pool;
1951 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1952 ASSERT_VK_SUCCESS(err);
1953
1954 VkDescriptorSetLayoutBinding dsl_binding = {};
1955 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1956 dsl_binding.arraySize = 1;
1957 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1958
1959 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1960 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1961 ds_layout_ci.count = 1;
1962 ds_layout_ci.pBinding = &dsl_binding;
1963
1964 VkDescriptorSetLayout ds_layout;
1965 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1966 ASSERT_VK_SUCCESS(err);
1967
1968 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001969 VkDescriptorSetAllocInfo alloc_info = {};
1970 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1971 alloc_info.count = 1;
1972 alloc_info.descriptorPool = ds_pool;
1973 alloc_info.pSetLayouts = &ds_layout;
1974 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06001975 ASSERT_VK_SUCCESS(err);
1976
1977 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1978 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1979 pipeline_layout_ci.descriptorSetCount = 1;
1980 pipeline_layout_ci.pSetLayouts = &ds_layout;
1981
1982 VkPipelineLayout pipeline_layout;
1983 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1984 ASSERT_VK_SUCCESS(err);
1985
1986 VkViewport vp = {}; // Just need dummy vp to point to
1987
1988 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1989 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1990 vp_state_ci.scissorCount = 0;
1991 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
1992 vp_state_ci.pViewports = &vp;
1993
Cody Northropeb3a6c12015-10-05 14:44:45 -06001994 VkPipelineShaderStageCreateInfo shaderStages[2];
1995 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06001996
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001997 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1998 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 -06001999 // but add it to be able to run on more devices
2000 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002001 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002002 shaderStages[0].shader = vs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002003
Cody Northropeb3a6c12015-10-05 14:44:45 -06002004 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002005 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002006 shaderStages[1].shader = fs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002007
2008 VkGraphicsPipelineCreateInfo gp_ci = {};
2009 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002010 gp_ci.stageCount = 2;
2011 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002012 gp_ci.pViewportState = &vp_state_ci;
2013 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2014 gp_ci.layout = pipeline_layout;
2015 gp_ci.renderPass = renderPass();
2016
2017 VkPipelineCacheCreateInfo pc_ci = {};
2018 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2019
2020 VkPipeline pipeline;
2021 VkPipelineCache pipelineCache;
2022
2023 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2024 ASSERT_VK_SUCCESS(err);
2025 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2026
2027 msgFlags = m_errorMonitor->GetState(&msgString);
2028 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/ viewport and scissor count mismatch.";
2029 if (!strstr(msgString.c_str(),"Gfx Pipeline viewport count (1) must match scissor count (0).")) {
2030 FAIL() << "Error received was not 'Gfx Pipeline viewport count (1) must match scissor count (0).' but instead it was '" << msgString.c_str() << "'";
2031 }
2032
2033 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2034 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002035 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2036 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2037}
Tobin Ehlisd332f282015-10-02 11:00:56 -06002038// Don't set viewport state in PSO. This is an error b/c we always need this state
2039// for the counts even if the data is going to be set dynamically.
2040TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002041{
2042 // Attempt to Create Gfx Pipeline w/o a VS
2043 VkFlags msgFlags;
2044 std::string msgString;
2045 VkResult err;
2046
2047 ASSERT_NO_FATAL_FAILURE(InitState());
2048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2049 m_errorMonitor->ClearState();
2050
2051 VkDescriptorTypeCount ds_type_count = {};
2052 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2053 ds_type_count.count = 1;
2054
2055 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2056 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002057 ds_pool_ci.maxSets = 1;
2058 ds_pool_ci.count = 1;
2059 ds_pool_ci.pTypeCount = &ds_type_count;
2060
2061 VkDescriptorPool ds_pool;
2062 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2063 ASSERT_VK_SUCCESS(err);
2064
2065 VkDescriptorSetLayoutBinding dsl_binding = {};
2066 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2067 dsl_binding.arraySize = 1;
2068 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2069
2070 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2071 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2072 ds_layout_ci.count = 1;
2073 ds_layout_ci.pBinding = &dsl_binding;
2074
2075 VkDescriptorSetLayout ds_layout;
2076 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2077 ASSERT_VK_SUCCESS(err);
2078
2079 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002080 VkDescriptorSetAllocInfo alloc_info = {};
2081 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2082 alloc_info.count = 1;
2083 alloc_info.descriptorPool = ds_pool;
2084 alloc_info.pSetLayouts = &ds_layout;
2085 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002086 ASSERT_VK_SUCCESS(err);
2087
2088 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2089 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2090 pipeline_layout_ci.descriptorSetCount = 1;
2091 pipeline_layout_ci.pSetLayouts = &ds_layout;
2092
2093 VkPipelineLayout pipeline_layout;
2094 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2095 ASSERT_VK_SUCCESS(err);
2096
2097 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2098 // Set scissor as dynamic to avoid second error
2099 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2100 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2101 dyn_state_ci.dynamicStateCount = 1;
2102 dyn_state_ci.pDynamicStates = &sc_state;
2103
Cody Northropeb3a6c12015-10-05 14:44:45 -06002104 VkPipelineShaderStageCreateInfo shaderStages[2];
2105 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002106
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002107 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2108 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 -06002109 // but add it to be able to run on more devices
2110 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002111 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002112 shaderStages[0].shader = vs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002113
Cody Northropeb3a6c12015-10-05 14:44:45 -06002114 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002115 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002116 shaderStages[1].shader = fs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002117
2118 VkGraphicsPipelineCreateInfo gp_ci = {};
2119 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002120 gp_ci.stageCount = 2;
2121 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002122 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2123 gp_ci.pDynamicState = &dyn_state_ci;
2124 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2125 gp_ci.layout = pipeline_layout;
2126 gp_ci.renderPass = renderPass();
2127
2128 VkPipelineCacheCreateInfo pc_ci = {};
2129 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2130
2131 VkPipeline pipeline;
2132 VkPipelineCache pipelineCache;
2133
2134 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2135 ASSERT_VK_SUCCESS(err);
2136 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2137
2138 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002139 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o viewport state set.";
2140 if (!strstr(msgString.c_str(),"Gfx Pipeline pViewportState is null. Even if ")) {
2141 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 -06002142 }
2143
2144 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2145 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002146 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2147 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2148}
2149// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002150// Then run second test where dynamic scissor count doesn't match PSO scissor count
2151TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002152{
2153 VkFlags msgFlags;
2154 std::string msgString;
2155 VkResult err;
2156
2157 ASSERT_NO_FATAL_FAILURE(InitState());
2158 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2159 m_errorMonitor->ClearState();
2160
2161 VkDescriptorTypeCount ds_type_count = {};
2162 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2163 ds_type_count.count = 1;
2164
2165 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2166 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002167 ds_pool_ci.maxSets = 1;
2168 ds_pool_ci.count = 1;
2169 ds_pool_ci.pTypeCount = &ds_type_count;
2170
2171 VkDescriptorPool ds_pool;
2172 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2173 ASSERT_VK_SUCCESS(err);
2174
2175 VkDescriptorSetLayoutBinding dsl_binding = {};
2176 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2177 dsl_binding.arraySize = 1;
2178 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2179
2180 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2181 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2182 ds_layout_ci.count = 1;
2183 ds_layout_ci.pBinding = &dsl_binding;
2184
2185 VkDescriptorSetLayout ds_layout;
2186 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2187 ASSERT_VK_SUCCESS(err);
2188
2189 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002190 VkDescriptorSetAllocInfo alloc_info = {};
2191 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2192 alloc_info.count = 1;
2193 alloc_info.descriptorPool = ds_pool;
2194 alloc_info.pSetLayouts = &ds_layout;
2195 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002196 ASSERT_VK_SUCCESS(err);
2197
2198 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2199 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2200 pipeline_layout_ci.descriptorSetCount = 1;
2201 pipeline_layout_ci.pSetLayouts = &ds_layout;
2202
2203 VkPipelineLayout pipeline_layout;
2204 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2205 ASSERT_VK_SUCCESS(err);
2206
2207 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2208 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2209 vp_state_ci.viewportCount = 1;
2210 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2211 vp_state_ci.scissorCount = 1;
2212 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2213
2214 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2215 // Set scissor as dynamic to avoid that error
2216 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2217 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2218 dyn_state_ci.dynamicStateCount = 1;
2219 dyn_state_ci.pDynamicStates = &sc_state;
2220
Cody Northropeb3a6c12015-10-05 14:44:45 -06002221 VkPipelineShaderStageCreateInfo shaderStages[2];
2222 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002223
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002224 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2225 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 -06002226 // but add it to be able to run on more devices
2227 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002228 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002229 shaderStages[0].shader = vs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002230
Cody Northropeb3a6c12015-10-05 14:44:45 -06002231 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002232 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002233 shaderStages[1].shader = fs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002234
Cody Northropf6622dc2015-10-06 10:33:21 -06002235 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2236 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2237 vi_ci.pNext = nullptr;
2238 vi_ci.bindingCount = 0;
2239 vi_ci.pVertexBindingDescriptions = nullptr;
2240 vi_ci.attributeCount = 0;
2241 vi_ci.pVertexAttributeDescriptions = nullptr;
2242
2243 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2244 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2245 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2246
2247 VkPipelineRasterStateCreateInfo rs_ci = {};
2248 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2249 rs_ci.pNext = nullptr;
2250
2251 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2252 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2253 cb_ci.pNext = nullptr;
2254
Tobin Ehlise68360f2015-10-01 11:15:13 -06002255 VkGraphicsPipelineCreateInfo gp_ci = {};
2256 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002257 gp_ci.stageCount = 2;
2258 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06002259 gp_ci.pVertexInputState = &vi_ci;
2260 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002261 gp_ci.pViewportState = &vp_state_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06002262 gp_ci.pRasterState = &rs_ci;
2263 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002264 gp_ci.pDynamicState = &dyn_state_ci;
2265 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2266 gp_ci.layout = pipeline_layout;
2267 gp_ci.renderPass = renderPass();
2268
2269 VkPipelineCacheCreateInfo pc_ci = {};
2270 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2271
2272 VkPipeline pipeline;
2273 VkPipelineCache pipelineCache;
2274
2275 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2276 ASSERT_VK_SUCCESS(err);
2277 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2278
2279 msgFlags = m_errorMonitor->GetState(&msgString);
2280 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2281 if (!strstr(msgString.c_str(),"Gfx Pipeline viewportCount is 1, but pViewports is NULL. ")) {
2282 FAIL() << "Error received was not 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...' but instead it was '" << msgString.c_str() << "'";
2283 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002284 m_errorMonitor->ClearState();
2285 // Now hit second fail case where we set scissor w/ different count than PSO
2286 // First need to successfully create the PSO from above by setting pViewports
2287 VkViewport vp = {}; // Just need dummy vp to point to
2288 vp_state_ci.pViewports = &vp;
2289 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2290 ASSERT_VK_SUCCESS(err);
2291 BeginCommandBuffer();
2292 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2293 VkRect2D scissors[2] = {}; // don't care about data
2294 // Count of 2 doesn't match PSO count of 1
2295 vkCmdSetScissor(m_cmdBuffer->GetBufferHandle(), 2, scissors);
2296 Draw(1, 0, 0, 0);
2297
2298 msgFlags = m_errorMonitor->GetState(&msgString);
2299 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic scissorCount different from PSO scissorCount.";
2300 if (!strstr(msgString.c_str(),"Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.")) {
2301 FAIL() << "Error received was not 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...' but instead it was '" << msgString.c_str() << "'";
2302 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06002303
2304 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2305 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002306 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2307 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2308}
2309// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002310// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2311TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002312{
2313 VkFlags msgFlags;
2314 std::string msgString;
2315 VkResult err;
2316
2317 ASSERT_NO_FATAL_FAILURE(InitState());
2318 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2319 m_errorMonitor->ClearState();
2320
2321 VkDescriptorTypeCount ds_type_count = {};
2322 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2323 ds_type_count.count = 1;
2324
2325 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2326 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002327 ds_pool_ci.maxSets = 1;
2328 ds_pool_ci.count = 1;
2329 ds_pool_ci.pTypeCount = &ds_type_count;
2330
2331 VkDescriptorPool ds_pool;
2332 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2333 ASSERT_VK_SUCCESS(err);
2334
2335 VkDescriptorSetLayoutBinding dsl_binding = {};
2336 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2337 dsl_binding.arraySize = 1;
2338 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2339
2340 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2341 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2342 ds_layout_ci.count = 1;
2343 ds_layout_ci.pBinding = &dsl_binding;
2344
2345 VkDescriptorSetLayout ds_layout;
2346 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2347 ASSERT_VK_SUCCESS(err);
2348
2349 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002350 VkDescriptorSetAllocInfo alloc_info = {};
2351 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2352 alloc_info.count = 1;
2353 alloc_info.descriptorPool = ds_pool;
2354 alloc_info.pSetLayouts = &ds_layout;
2355 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002356 ASSERT_VK_SUCCESS(err);
2357
2358 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2359 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2360 pipeline_layout_ci.descriptorSetCount = 1;
2361 pipeline_layout_ci.pSetLayouts = &ds_layout;
2362
2363 VkPipelineLayout pipeline_layout;
2364 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2365 ASSERT_VK_SUCCESS(err);
2366
2367 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2368 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2369 vp_state_ci.scissorCount = 1;
2370 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2371 vp_state_ci.viewportCount = 1;
2372 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2373
2374 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2375 // Set scissor as dynamic to avoid that error
2376 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2377 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2378 dyn_state_ci.dynamicStateCount = 1;
2379 dyn_state_ci.pDynamicStates = &vp_state;
2380
Cody Northropeb3a6c12015-10-05 14:44:45 -06002381 VkPipelineShaderStageCreateInfo shaderStages[2];
2382 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002383
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002384 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2385 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 -06002386 // but add it to be able to run on more devices
2387 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002388 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002389 shaderStages[0].shader = vs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002390
Cody Northropeb3a6c12015-10-05 14:44:45 -06002391 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002392 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002393 shaderStages[1].shader = fs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002394
Cody Northropf6622dc2015-10-06 10:33:21 -06002395 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2396 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2397 vi_ci.pNext = nullptr;
2398 vi_ci.bindingCount = 0;
2399 vi_ci.pVertexBindingDescriptions = nullptr;
2400 vi_ci.attributeCount = 0;
2401 vi_ci.pVertexAttributeDescriptions = nullptr;
2402
2403 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2404 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2405 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2406
2407 VkPipelineRasterStateCreateInfo rs_ci = {};
2408 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2409 rs_ci.pNext = nullptr;
2410
2411 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2412 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2413 cb_ci.pNext = nullptr;
2414
Tobin Ehlise68360f2015-10-01 11:15:13 -06002415 VkGraphicsPipelineCreateInfo gp_ci = {};
2416 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002417 gp_ci.stageCount = 2;
2418 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06002419 gp_ci.pVertexInputState = &vi_ci;
2420 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002421 gp_ci.pViewportState = &vp_state_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06002422 gp_ci.pRasterState = &rs_ci;
2423 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002424 gp_ci.pDynamicState = &dyn_state_ci;
2425 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2426 gp_ci.layout = pipeline_layout;
2427 gp_ci.renderPass = renderPass();
2428
2429 VkPipelineCacheCreateInfo pc_ci = {};
2430 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2431
2432 VkPipeline pipeline;
2433 VkPipelineCache pipelineCache;
2434
2435 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2436 ASSERT_VK_SUCCESS(err);
2437 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2438
2439 msgFlags = m_errorMonitor->GetState(&msgString);
2440 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2441 if (!strstr(msgString.c_str(),"Gfx Pipeline scissorCount is 1, but pScissors is NULL. ")) {
2442 FAIL() << "Error received was not 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...' but instead it was '" << msgString.c_str() << "'";
2443 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002444 m_errorMonitor->ClearState();
2445 // Now hit second fail case where we set scissor w/ different count than PSO
2446 // First need to successfully create the PSO from above by setting pViewports
2447 VkRect2D sc = {}; // Just need dummy vp to point to
2448 vp_state_ci.pScissors = &sc;
2449 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2450 ASSERT_VK_SUCCESS(err);
2451 BeginCommandBuffer();
2452 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2453 VkViewport viewports[2] = {}; // don't care about data
2454 // Count of 2 doesn't match PSO count of 1
2455 vkCmdSetViewport(m_cmdBuffer->GetBufferHandle(), 2, viewports);
2456 Draw(1, 0, 0, 0);
2457
2458 msgFlags = m_errorMonitor->GetState(&msgString);
2459 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic viewportCount different from PSO viewportCount.";
2460 if (!strstr(msgString.c_str(),"Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.")) {
2461 FAIL() << "Error received was not 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...' but instead it was '" << msgString.c_str() << "'";
2462 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06002463
2464 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2465 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002466 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2467 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2468}
2469
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002470TEST_F(VkLayerTest, NullRenderPass)
2471{
2472 // Bind a NULL RenderPass
2473 VkFlags msgFlags;
2474 std::string msgString;
2475
2476 ASSERT_NO_FATAL_FAILURE(InitState());
2477 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2478 m_errorMonitor->ClearState();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002479
Tony Barbourfe3351b2015-07-28 10:17:20 -06002480 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002481 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbourfe3351b2015-07-28 10:17:20 -06002482 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002483
2484 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002485 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002486 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
2487 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2488 }
2489}
2490
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002491TEST_F(VkLayerTest, RenderPassWithinRenderPass)
2492{
2493 // Bind a BeginRenderPass within an active RenderPass
2494 VkFlags msgFlags;
2495 std::string msgString;
2496
2497 ASSERT_NO_FATAL_FAILURE(InitState());
2498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2499 m_errorMonitor->ClearState();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002500
Tony Barbourfe3351b2015-07-28 10:17:20 -06002501 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002502 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barboureb254902015-07-15 12:50:33 -06002503 VkRenderPassBeginInfo rp_begin = {};
2504 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
2505 rp_begin.pNext = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002506 rp_begin.renderPass = renderPass();
2507 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002508
Tony Barbourfe3351b2015-07-28 10:17:20 -06002509 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002510
2511 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002512 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 -06002513 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2514 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002515 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002516}
2517
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002518TEST_F(VkLayerTest, FillBufferWithinRenderPass)
2519{
2520 // Call CmdFillBuffer within an active renderpass
2521 VkFlags msgFlags;
2522 std::string msgString;
2523
2524 ASSERT_NO_FATAL_FAILURE(InitState());
2525 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2526 m_errorMonitor->ClearState();
2527
2528 // Renderpass is started here
2529 BeginCommandBuffer();
2530
2531 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2532 vk_testing::Buffer destBuffer;
2533 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2534
2535 m_cmdBuffer->FillBuffer(destBuffer.handle(), 0, 4, 0x11111111);
2536
2537 msgFlags = m_errorMonitor->GetState(&msgString);
2538 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2539 "Did not receive error after calling CmdFillBuffer w/i an active RenderPass.";
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002540 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2541 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002542 }
2543}
2544
2545TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
2546{
2547 // Call CmdUpdateBuffer within an active renderpass
2548 VkFlags msgFlags;
2549 std::string msgString;
2550
2551 ASSERT_NO_FATAL_FAILURE(InitState());
2552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2553 m_errorMonitor->ClearState();
2554
2555 // Renderpass is started here
2556 BeginCommandBuffer();
2557
2558 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2559 vk_testing::Buffer destBuffer;
2560 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2561
2562 VkDeviceSize destOffset = 0;
2563 VkDeviceSize dataSize = 1024;
2564 const uint32_t *pData = NULL;
2565
2566 vkCmdUpdateBuffer(m_cmdBuffer->GetBufferHandle(), destBuffer.handle(), destOffset, dataSize, pData);
2567
2568 msgFlags = m_errorMonitor->GetState(&msgString);
2569 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2570 "Did not receive error after calling CmdUpdateBuffer w/i an active RenderPass.";
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002571 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2572 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002573 }
2574}
2575
2576TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
2577{
2578 // Call CmdClearColorImage within an active RenderPass
2579 VkFlags msgFlags;
2580 std::string msgString;
2581
2582 ASSERT_NO_FATAL_FAILURE(InitState());
2583 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2584 m_errorMonitor->ClearState();
2585
2586 // Renderpass is started here
2587 BeginCommandBuffer();
2588
2589 VkClearColorValue clear_color = {0};
2590 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2591 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2592 const int32_t tex_width = 32;
2593 const int32_t tex_height = 32;
2594 VkImageCreateInfo image_create_info = {};
2595 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2596 image_create_info.pNext = NULL;
2597 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2598 image_create_info.format = tex_format;
2599 image_create_info.extent.width = tex_width;
2600 image_create_info.extent.height = tex_height;
2601 image_create_info.extent.depth = 1;
2602 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06002603 image_create_info.arrayLayers = 1;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002604 image_create_info.samples = 1;
2605 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2606 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2607
2608 vk_testing::Image destImage;
2609 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2610
2611 const VkImageSubresourceRange range =
2612 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
2613
2614 vkCmdClearColorImage(m_cmdBuffer->GetBufferHandle(),
2615 destImage.handle(),
2616 VK_IMAGE_LAYOUT_GENERAL,
2617 &clear_color,
2618 1,
2619 &range);
2620
2621 msgFlags = m_errorMonitor->GetState(&msgString);
2622 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2623 "Did not receive error after calling CmdClearColorImage w/i an active RenderPass.";
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002624 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2625 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002626 }
2627}
2628
2629TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
2630{
2631 // Call CmdClearDepthStencilImage within an active RenderPass
2632 VkFlags msgFlags;
2633 std::string msgString;
2634
2635 ASSERT_NO_FATAL_FAILURE(InitState());
2636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2637 m_errorMonitor->ClearState();
2638
2639 // Renderpass is started here
2640 BeginCommandBuffer();
2641
2642 VkClearDepthStencilValue clear_value = {0};
2643 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2644 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
2645 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2646 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
2647 image_create_info.extent.width = 64;
2648 image_create_info.extent.height = 64;
2649 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2650 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2651
2652 vk_testing::Image destImage;
2653 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2654
2655 const VkImageSubresourceRange range =
2656 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
2657
2658 vkCmdClearDepthStencilImage(m_cmdBuffer->GetBufferHandle(),
2659 destImage.handle(),
2660 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2661 &clear_value,
2662 1,
2663 &range);
2664
2665 msgFlags = m_errorMonitor->GetState(&msgString);
2666 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2667 "Did not receive error after calling CmdClearDepthStencilImage w/i an active RenderPass.";
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002668 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2669 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002670 }
2671}
2672
2673TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
2674{
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002675 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002676 VkFlags msgFlags;
2677 std::string msgString;
2678 VkResult err;
2679
2680 ASSERT_NO_FATAL_FAILURE(InitState());
2681 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2682 m_errorMonitor->ClearState();
2683
2684 // Start no RenderPass
2685 err = m_cmdBuffer->BeginCommandBuffer();
2686 ASSERT_VK_SUCCESS(err);
2687
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002688 VkClearAttachment color_attachment;
2689 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2690 color_attachment.clearValue.color.float32[0] = 0;
2691 color_attachment.clearValue.color.float32[1] = 0;
2692 color_attachment.clearValue.color.float32[2] = 0;
2693 color_attachment.clearValue.color.float32[3] = 0;
2694 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06002695 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002696 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(),
2697 1, &color_attachment,
2698 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002699
2700 msgFlags = m_errorMonitor->GetState(&msgString);
2701 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002702 "Did not receive error after calling CmdClearAttachments outside of an active RenderPass.";
2703 if (!strstr(msgString.c_str(),"vkCmdClearAttachments: This call must be issued inside an active render pass")) {
2704 FAIL() << "Error received was not 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002705 }
2706}
2707
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002708TEST_F(VkLayerTest, InvalidDynamicStateObject)
2709{
2710 // Create a valid cmd buffer
2711 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002712 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
2713 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002714}
Tobin Ehlis1056d452015-05-27 14:55:35 -06002715
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002716TEST_F(VkLayerTest, IdxBufferAlignmentError)
2717{
2718 // Bind a BeginRenderPass within an active RenderPass
2719 VkFlags msgFlags;
2720 std::string msgString;
2721 VkResult err;
2722
2723 ASSERT_NO_FATAL_FAILURE(InitState());
2724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2725 m_errorMonitor->ClearState();
2726 uint32_t qfi = 0;
2727 VkBufferCreateInfo buffCI = {};
2728 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2729 buffCI.size = 1024;
2730 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
2731 buffCI.queueFamilyCount = 1;
2732 buffCI.pQueueFamilyIndices = &qfi;
2733
2734 VkBuffer ib;
2735 err = vkCreateBuffer(m_device->device(), &buffCI, &ib);
2736 ASSERT_VK_SUCCESS(err);
2737
2738 BeginCommandBuffer();
2739 ASSERT_VK_SUCCESS(err);
2740 //vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2741 // Should error before calling to driver so don't care about actual data
2742 vkCmdBindIndexBuffer(m_cmdBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
2743
2744 msgFlags = m_errorMonitor->GetState(&msgString);
2745 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2746 if (!strstr(msgString.c_str(),"vkCmdBindIndexBuffer() offset (0x7) does not fall on ")) {
2747 FAIL() << "Error received was not 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...' but instead '" << msgString.c_str() << "'";
2748 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002749
2750 vkDestroyBuffer(m_device->device(), ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002751}
2752
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06002753TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2754{
2755 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
2756 VkFlags msgFlags;
2757 std::string msgString;
2758
2759 ASSERT_NO_FATAL_FAILURE(InitState());
2760 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2761 m_errorMonitor->ClearState();
2762
2763 BeginCommandBuffer();
2764 //ASSERT_VK_SUCCESS(err);
2765 VkCmdBuffer primCB = m_cmdBuffer->GetBufferHandle();
2766 vkCmdExecuteCommands(m_cmdBuffer->GetBufferHandle(), 1, &primCB);
2767
2768 msgFlags = m_errorMonitor->GetState(&msgString);
2769 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2770 if (!strstr(msgString.c_str(),"vkCmdExecuteCommands() called w/ Primary Cmd Buffer ")) {
2771 FAIL() << "Error received was not 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer ' but instead '" << msgString.c_str() << "'";
2772 }
2773}
2774
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002775TEST_F(VkLayerTest, DSTypeMismatch)
2776{
2777 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002778 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002779 std::string msgString;
2780 VkResult err;
2781
2782 ASSERT_NO_FATAL_FAILURE(InitState());
2783 m_errorMonitor->ClearState();
2784 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06002785 VkDescriptorTypeCount ds_type_count = {};
2786 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2787 ds_type_count.count = 1;
2788
2789 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2790 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2791 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002792 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002793 ds_pool_ci.count = 1;
2794 ds_pool_ci.pTypeCount = &ds_type_count;
2795
Tobin Ehlis3b780662015-05-28 12:11:26 -06002796 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002797 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002798 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06002799 VkDescriptorSetLayoutBinding dsl_binding = {};
2800 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2801 dsl_binding.arraySize = 1;
2802 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2803 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002804
Tony Barboureb254902015-07-15 12:50:33 -06002805 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2806 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2807 ds_layout_ci.pNext = NULL;
2808 ds_layout_ci.count = 1;
2809 ds_layout_ci.pBinding = &dsl_binding;
2810
Tobin Ehlis3b780662015-05-28 12:11:26 -06002811 VkDescriptorSetLayout ds_layout;
2812 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2813 ASSERT_VK_SUCCESS(err);
2814
2815 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002816 VkDescriptorSetAllocInfo alloc_info = {};
2817 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2818 alloc_info.count = 1;
2819 alloc_info.descriptorPool = ds_pool;
2820 alloc_info.pSetLayouts = &ds_layout;
2821 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002822 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002823
Tony Barboureb254902015-07-15 12:50:33 -06002824 VkSamplerCreateInfo sampler_ci = {};
2825 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2826 sampler_ci.pNext = NULL;
2827 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2828 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2829 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06002830 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2831 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2832 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06002833 sampler_ci.mipLodBias = 1.0;
2834 sampler_ci.maxAnisotropy = 1;
2835 sampler_ci.compareEnable = VK_FALSE;
2836 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2837 sampler_ci.minLod = 1.0;
2838 sampler_ci.maxLod = 1.0;
2839 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06002840 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2841
Tobin Ehlis3b780662015-05-28 12:11:26 -06002842 VkSampler sampler;
2843 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2844 ASSERT_VK_SUCCESS(err);
2845
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002846 VkDescriptorInfo descriptor_info;
2847 memset(&descriptor_info, 0, sizeof(descriptor_info));
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06002848 descriptor_info.imageInfo.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002849
2850 VkWriteDescriptorSet descriptor_write;
2851 memset(&descriptor_write, 0, sizeof(descriptor_write));
2852 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2853 descriptor_write.destSet = descriptorSet;
2854 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002855 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002856 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2857 descriptor_write.pDescriptors = &descriptor_info;
2858
2859 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2860
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002861 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002862 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating BUFFER Descriptor w/ incorrect type of SAMPLER.";
Tobin Ehlis483cc352015-09-30 08:30:20 -06002863 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ")) {
2864 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...' but instead '" << msgString.c_str() << "'";
Tobin Ehlis3b780662015-05-28 12:11:26 -06002865 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002866
2867 vkDestroySampler(m_device->device(), sampler);
Mike Stroyand1c84a52015-08-18 14:40:24 -06002868 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2869 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002870}
2871
2872TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2873{
2874 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002875 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002876 std::string msgString;
2877 VkResult err;
2878
2879 ASSERT_NO_FATAL_FAILURE(InitState());
2880 m_errorMonitor->ClearState();
2881 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06002882 VkDescriptorTypeCount ds_type_count = {};
2883 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2884 ds_type_count.count = 1;
2885
2886 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2887 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2888 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002889 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002890 ds_pool_ci.count = 1;
2891 ds_pool_ci.pTypeCount = &ds_type_count;
2892
Tobin Ehlis3b780662015-05-28 12:11:26 -06002893 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002894 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002895 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002896
Tony Barboureb254902015-07-15 12:50:33 -06002897 VkDescriptorSetLayoutBinding dsl_binding = {};
2898 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2899 dsl_binding.arraySize = 1;
2900 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2901 dsl_binding.pImmutableSamplers = NULL;
2902
2903 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2904 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2905 ds_layout_ci.pNext = NULL;
2906 ds_layout_ci.count = 1;
2907 ds_layout_ci.pBinding = &dsl_binding;
2908
Tobin Ehlis3b780662015-05-28 12:11:26 -06002909 VkDescriptorSetLayout ds_layout;
2910 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2911 ASSERT_VK_SUCCESS(err);
2912
2913 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002914 VkDescriptorSetAllocInfo alloc_info = {};
2915 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2916 alloc_info.count = 1;
2917 alloc_info.descriptorPool = ds_pool;
2918 alloc_info.pSetLayouts = &ds_layout;
2919 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002920 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002921
Tony Barboureb254902015-07-15 12:50:33 -06002922 VkSamplerCreateInfo sampler_ci = {};
2923 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2924 sampler_ci.pNext = NULL;
2925 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2926 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2927 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06002928 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2929 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2930 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06002931 sampler_ci.mipLodBias = 1.0;
2932 sampler_ci.maxAnisotropy = 1;
2933 sampler_ci.compareEnable = VK_FALSE;
2934 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2935 sampler_ci.minLod = 1.0;
2936 sampler_ci.maxLod = 1.0;
2937 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06002938 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06002939
Tobin Ehlis3b780662015-05-28 12:11:26 -06002940 VkSampler sampler;
2941 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2942 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002943
2944 VkDescriptorInfo descriptor_info;
2945 memset(&descriptor_info, 0, sizeof(descriptor_info));
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06002946 descriptor_info.imageInfo.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002947
2948 VkWriteDescriptorSet descriptor_write;
2949 memset(&descriptor_write, 0, sizeof(descriptor_write));
2950 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2951 descriptor_write.destSet = descriptorSet;
2952 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
2953 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002954 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002955 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2956 descriptor_write.pDescriptors = &descriptor_info;
2957
2958 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2959
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002960 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002961 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 +08002962 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
2963 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 -06002964 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002965
2966 vkDestroySampler(m_device->device(), sampler);
Mike Stroyand1c84a52015-08-18 14:40:24 -06002967 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2968 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002969}
2970
2971TEST_F(VkLayerTest, InvalidDSUpdateIndex)
2972{
Tobin Ehlis3b780662015-05-28 12:11:26 -06002973 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002974 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002975 std::string msgString;
2976 VkResult err;
2977
2978 ASSERT_NO_FATAL_FAILURE(InitState());
2979 m_errorMonitor->ClearState();
2980 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06002981 VkDescriptorTypeCount ds_type_count = {};
2982 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2983 ds_type_count.count = 1;
2984
2985 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2986 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2987 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002988 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002989 ds_pool_ci.count = 1;
2990 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002991
Tobin Ehlis3b780662015-05-28 12:11:26 -06002992 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002993 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002994 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002995
Tony Barboureb254902015-07-15 12:50:33 -06002996 VkDescriptorSetLayoutBinding dsl_binding = {};
2997 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2998 dsl_binding.arraySize = 1;
2999 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3000 dsl_binding.pImmutableSamplers = NULL;
3001
3002 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3003 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3004 ds_layout_ci.pNext = NULL;
3005 ds_layout_ci.count = 1;
3006 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003007 VkDescriptorSetLayout ds_layout;
3008 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3009 ASSERT_VK_SUCCESS(err);
3010
3011 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003012 VkDescriptorSetAllocInfo alloc_info = {};
3013 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3014 alloc_info.count = 1;
3015 alloc_info.descriptorPool = ds_pool;
3016 alloc_info.pSetLayouts = &ds_layout;
3017 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003018 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003019
Tony Barboureb254902015-07-15 12:50:33 -06003020 VkSamplerCreateInfo sampler_ci = {};
3021 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3022 sampler_ci.pNext = NULL;
3023 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
3024 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
3025 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06003026 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3027 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3028 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06003029 sampler_ci.mipLodBias = 1.0;
3030 sampler_ci.maxAnisotropy = 1;
3031 sampler_ci.compareEnable = VK_FALSE;
3032 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3033 sampler_ci.minLod = 1.0;
3034 sampler_ci.maxLod = 1.0;
3035 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003036 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003037
Tobin Ehlis3b780662015-05-28 12:11:26 -06003038 VkSampler sampler;
3039 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3040 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003041
3042 VkDescriptorInfo descriptor_info;
3043 memset(&descriptor_info, 0, sizeof(descriptor_info));
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06003044 descriptor_info.imageInfo.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003045
3046 VkWriteDescriptorSet descriptor_write;
3047 memset(&descriptor_write, 0, sizeof(descriptor_write));
3048 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3049 descriptor_write.destSet = descriptorSet;
3050 descriptor_write.destBinding = 2;
3051 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003052 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003053 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3054 descriptor_write.pDescriptors = &descriptor_info;
3055
3056 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3057
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003058 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003059 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 -06003060 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
3061 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
3062 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003063
3064 vkDestroySampler(m_device->device(), sampler);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003065 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3066 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003067}
3068
3069TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3070{
3071 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003072 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003073 std::string msgString;
3074 VkResult err;
3075
3076 ASSERT_NO_FATAL_FAILURE(InitState());
3077 m_errorMonitor->ClearState();
3078 //VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003079
Tony Barboureb254902015-07-15 12:50:33 -06003080 VkDescriptorTypeCount ds_type_count = {};
3081 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3082 ds_type_count.count = 1;
3083
3084 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3085 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3086 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003087 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003088 ds_pool_ci.count = 1;
3089 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003090
Tobin Ehlis3b780662015-05-28 12:11:26 -06003091 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003092 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003093 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06003094 VkDescriptorSetLayoutBinding dsl_binding = {};
3095 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3096 dsl_binding.arraySize = 1;
3097 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3098 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003099
Tony Barboureb254902015-07-15 12:50:33 -06003100 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3101 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3102 ds_layout_ci.pNext = NULL;
3103 ds_layout_ci.count = 1;
3104 ds_layout_ci.pBinding = &dsl_binding;
3105
Tobin Ehlis3b780662015-05-28 12:11:26 -06003106 VkDescriptorSetLayout ds_layout;
3107 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3108 ASSERT_VK_SUCCESS(err);
3109
3110 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003111 VkDescriptorSetAllocInfo alloc_info = {};
3112 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3113 alloc_info.count = 1;
3114 alloc_info.descriptorPool = ds_pool;
3115 alloc_info.pSetLayouts = &ds_layout;
3116 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003117 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003118
Tony Barboureb254902015-07-15 12:50:33 -06003119 VkSamplerCreateInfo sampler_ci = {};
3120 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3121 sampler_ci.pNext = NULL;
3122 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
3123 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
3124 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06003125 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3126 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3127 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06003128 sampler_ci.mipLodBias = 1.0;
3129 sampler_ci.maxAnisotropy = 1;
3130 sampler_ci.compareEnable = VK_FALSE;
3131 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3132 sampler_ci.minLod = 1.0;
3133 sampler_ci.maxLod = 1.0;
3134 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003135 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003136 VkSampler sampler;
3137 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3138 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003139
3140
3141 VkDescriptorInfo descriptor_info;
3142 memset(&descriptor_info, 0, sizeof(descriptor_info));
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06003143 descriptor_info.imageInfo.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003144
3145 VkWriteDescriptorSet descriptor_write;
3146 memset(&descriptor_write, 0, sizeof(descriptor_write));
3147 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
3148 descriptor_write.destSet = descriptorSet;
3149 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003150 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003151 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3152 descriptor_write.pDescriptors = &descriptor_info;
3153
3154 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3155
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003156 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003157 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 -06003158 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
3159 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
3160 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003161
3162 vkDestroySampler(m_device->device(), sampler);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003163 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3164 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003165}
3166
3167TEST_F(VkLayerTest, NumSamplesMismatch)
3168{
Tobin Ehlis3b780662015-05-28 12:11:26 -06003169 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003170 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003171 std::string msgString;
3172 VkResult err;
3173
3174 ASSERT_NO_FATAL_FAILURE(InitState());
3175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3176 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06003177 VkDescriptorTypeCount ds_type_count = {};
3178 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3179 ds_type_count.count = 1;
3180
3181 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003182 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3183 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003184 ds_pool_ci.maxSets = 1;
3185 ds_pool_ci.count = 1;
3186 ds_pool_ci.pTypeCount = &ds_type_count;
3187
Tobin Ehlis3b780662015-05-28 12:11:26 -06003188 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003189 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003190 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003191
Tony Barboureb254902015-07-15 12:50:33 -06003192 VkDescriptorSetLayoutBinding dsl_binding = {};
3193 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3194 dsl_binding.arraySize = 1;
3195 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3196 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003197
Tony Barboureb254902015-07-15 12:50:33 -06003198 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3199 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3200 ds_layout_ci.pNext = NULL;
3201 ds_layout_ci.count = 1;
3202 ds_layout_ci.pBinding = &dsl_binding;
3203
Tobin Ehlis3b780662015-05-28 12:11:26 -06003204 VkDescriptorSetLayout ds_layout;
3205 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3206 ASSERT_VK_SUCCESS(err);
3207
3208 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003209 VkDescriptorSetAllocInfo alloc_info = {};
3210 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3211 alloc_info.count = 1;
3212 alloc_info.descriptorPool = ds_pool;
3213 alloc_info.pSetLayouts = &ds_layout;
3214 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003215 ASSERT_VK_SUCCESS(err);
3216
Tony Barboureb254902015-07-15 12:50:33 -06003217 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3218 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3219 pipe_ms_state_ci.pNext = NULL;
3220 pipe_ms_state_ci.rasterSamples = 4;
3221 pipe_ms_state_ci.sampleShadingEnable = 0;
3222 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003223 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003224
Tony Barboureb254902015-07-15 12:50:33 -06003225 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3226 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3227 pipeline_layout_ci.pNext = NULL;
3228 pipeline_layout_ci.descriptorSetCount = 1;
3229 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003230
3231 VkPipelineLayout pipeline_layout;
3232 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3233 ASSERT_VK_SUCCESS(err);
3234
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003235 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3236 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 -06003237 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003238 VkPipelineObj pipe(m_device);
3239 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003240 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003241 pipe.SetMSAA(&pipe_ms_state_ci);
3242 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003243
Tony Barbourfe3351b2015-07-28 10:17:20 -06003244 BeginCommandBuffer();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003245 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003246
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003247 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003248 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 -06003249 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
3250 FAIL() << "Error received was not 'Num samples mismatch!...'";
3251 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003252
3253 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003254 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3255 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003256}
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003257
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003258TEST_F(VkLayerTest, ClearCmdNoDraw)
3259{
3260 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
3261 VkFlags msgFlags;
3262 std::string msgString;
3263 VkResult err;
3264
3265 ASSERT_NO_FATAL_FAILURE(InitState());
3266 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3267 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06003268
3269 VkDescriptorTypeCount ds_type_count = {};
3270 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3271 ds_type_count.count = 1;
3272
3273 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3274 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3275 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003276 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003277 ds_pool_ci.count = 1;
3278 ds_pool_ci.pTypeCount = &ds_type_count;
3279
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003280 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003281 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003282 ASSERT_VK_SUCCESS(err);
3283
Tony Barboureb254902015-07-15 12:50:33 -06003284 VkDescriptorSetLayoutBinding dsl_binding = {};
3285 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3286 dsl_binding.arraySize = 1;
3287 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3288 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003289
Tony Barboureb254902015-07-15 12:50:33 -06003290 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3291 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3292 ds_layout_ci.pNext = NULL;
3293 ds_layout_ci.count = 1;
3294 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003295
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003296 VkDescriptorSetLayout ds_layout;
3297 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3298 ASSERT_VK_SUCCESS(err);
3299
3300 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003301 VkDescriptorSetAllocInfo alloc_info = {};
3302 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3303 alloc_info.count = 1;
3304 alloc_info.descriptorPool = ds_pool;
3305 alloc_info.pSetLayouts = &ds_layout;
3306 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003307 ASSERT_VK_SUCCESS(err);
3308
Tony Barboureb254902015-07-15 12:50:33 -06003309 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3310 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3311 pipe_ms_state_ci.pNext = NULL;
3312 pipe_ms_state_ci.rasterSamples = 4;
3313 pipe_ms_state_ci.sampleShadingEnable = 0;
3314 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003315 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003316
Tony Barboureb254902015-07-15 12:50:33 -06003317 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3318 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3319 pipeline_layout_ci.pNext = NULL;
3320 pipeline_layout_ci.descriptorSetCount = 1;
3321 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003322
3323 VkPipelineLayout pipeline_layout;
3324 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3325 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003326
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003327 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3328 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 -06003329 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003330 VkPipelineObj pipe(m_device);
3331 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003332 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003333 pipe.SetMSAA(&pipe_ms_state_ci);
3334 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003335
3336 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003337
3338 m_errorMonitor->ClearState();
3339 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3340 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003341 VkClearAttachment color_attachment;
3342 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3343 color_attachment.clearValue.color.float32[0] = 1.0;
3344 color_attachment.clearValue.color.float32[1] = 1.0;
3345 color_attachment.clearValue.color.float32[2] = 1.0;
3346 color_attachment.clearValue.color.float32[3] = 1.0;
3347 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06003348 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003349
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003350 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003351 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003352 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 -06003353 if (!strstr(msgString.c_str(),"vkCmdClearAttachments() issued on CB object ")) {
3354 FAIL() << "Error received was not 'vkCmdClearAttachments() issued on CB object...'";
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003355 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003356
3357 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003358 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3359 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003360}
3361
Tobin Ehlis502480b2015-06-24 15:53:07 -06003362TEST_F(VkLayerTest, VtxBufferBadIndex)
3363{
3364 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
3365 VkFlags msgFlags;
3366 std::string msgString;
3367 VkResult err;
3368
3369 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06003370 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06003371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3372 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06003373
3374 VkDescriptorTypeCount ds_type_count = {};
3375 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3376 ds_type_count.count = 1;
3377
3378 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3379 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3380 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003381 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003382 ds_pool_ci.count = 1;
3383 ds_pool_ci.pTypeCount = &ds_type_count;
3384
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003385 VkDescriptorPool ds_pool;
3386 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003387 ASSERT_VK_SUCCESS(err);
3388
Tony Barboureb254902015-07-15 12:50:33 -06003389 VkDescriptorSetLayoutBinding dsl_binding = {};
3390 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3391 dsl_binding.arraySize = 1;
3392 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3393 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003394
Tony Barboureb254902015-07-15 12:50:33 -06003395 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3396 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3397 ds_layout_ci.pNext = NULL;
3398 ds_layout_ci.count = 1;
3399 ds_layout_ci.pBinding = &dsl_binding;
3400
Tobin Ehlis502480b2015-06-24 15:53:07 -06003401 VkDescriptorSetLayout ds_layout;
3402 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3403 ASSERT_VK_SUCCESS(err);
3404
3405 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003406 VkDescriptorSetAllocInfo alloc_info = {};
3407 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3408 alloc_info.count = 1;
3409 alloc_info.descriptorPool = ds_pool;
3410 alloc_info.pSetLayouts = &ds_layout;
3411 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003412 ASSERT_VK_SUCCESS(err);
3413
Tony Barboureb254902015-07-15 12:50:33 -06003414 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3415 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3416 pipe_ms_state_ci.pNext = NULL;
3417 pipe_ms_state_ci.rasterSamples = 1;
3418 pipe_ms_state_ci.sampleShadingEnable = 0;
3419 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003420 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003421
Tony Barboureb254902015-07-15 12:50:33 -06003422 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3423 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3424 pipeline_layout_ci.pNext = NULL;
3425 pipeline_layout_ci.descriptorSetCount = 1;
3426 pipeline_layout_ci.pSetLayouts = &ds_layout;
3427 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003428
Tobin Ehlis502480b2015-06-24 15:53:07 -06003429 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3430 ASSERT_VK_SUCCESS(err);
3431
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003432 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3433 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 -06003434 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003435 VkPipelineObj pipe(m_device);
3436 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003437 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003438 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003439 pipe.SetViewport(m_viewports);
3440 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003441 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003442
3443 BeginCommandBuffer();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003444 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06003445 // Don't care about actual data, just need to get to draw to flag error
3446 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3447 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3448 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003449 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003450
3451 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003452 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 -06003453 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 -06003454 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 -06003455 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003456
3457 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003458 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3459 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003460}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003461#endif // DRAW_STATE_TESTS
3462
Tobin Ehlis0788f522015-05-26 16:11:58 -06003463#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06003464#if GTEST_IS_THREADSAFE
3465struct thread_data_struct {
3466 VkCmdBuffer cmdBuffer;
3467 VkEvent event;
3468 bool bailout;
3469};
3470
3471extern "C" void *AddToCommandBuffer(void *arg)
3472{
3473 struct thread_data_struct *data = (struct thread_data_struct *) arg;
3474 std::string msgString;
3475
3476 for (int i = 0; i<10000; i++) {
Tony Barbour0b2cfb22015-06-29 16:20:35 -06003477 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003478 if (data->bailout) {
3479 break;
3480 }
3481 }
3482 return NULL;
3483}
3484
3485TEST_F(VkLayerTest, ThreadCmdBufferCollision)
3486{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003487 VkFlags msgFlags;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003488 std::string msgString;
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003489 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003490
3491 ASSERT_NO_FATAL_FAILURE(InitState());
3492 ASSERT_NO_FATAL_FAILURE(InitViewport());
3493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3494
Mike Stroyanaccf7692015-05-12 16:00:45 -06003495 m_errorMonitor->ClearState();
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003496
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003497 // Calls AllocCommandBuffers
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003498 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
3499
3500 // Avoid creating RenderPass
3501 cmdBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003502
3503 VkEventCreateInfo event_info;
3504 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003505 VkResult err;
3506
3507 memset(&event_info, 0, sizeof(event_info));
3508 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3509
3510 err = vkCreateEvent(device(), &event_info, &event);
3511 ASSERT_VK_SUCCESS(err);
3512
Mike Stroyanaccf7692015-05-12 16:00:45 -06003513 err = vkResetEvent(device(), event);
3514 ASSERT_VK_SUCCESS(err);
3515
3516 struct thread_data_struct data;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003517 data.cmdBuffer = cmdBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003518 data.event = event;
3519 data.bailout = false;
3520 m_errorMonitor->SetBailout(&data.bailout);
3521 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003522 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003523 // Add many entries to command buffer from this thread at the same time.
3524 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003525
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003526 test_platform_thread_join(thread, NULL);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003527 cmdBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003528
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003529 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003530 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 -06003531 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -05003532 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyanaccf7692015-05-12 16:00:45 -06003533 }
3534
Mike Stroyand1c84a52015-08-18 14:40:24 -06003535 vkDestroyEvent(device(), event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003536}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003537#endif // GTEST_IS_THREADSAFE
3538#endif // THREADING_TESTS
3539
Chris Forbes9f7ff632015-05-25 11:13:08 +12003540#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003541TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
3542{
3543 VkFlags msgFlags;
3544 std::string msgString;
3545 ASSERT_NO_FATAL_FAILURE(InitState());
3546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3547
3548 m_errorMonitor->ClearState();
3549
3550 VkShaderModule module;
3551 VkShaderModuleCreateInfo moduleCreateInfo;
3552 struct icd_spv_header spv;
3553
3554 spv.magic = ICD_SPV_MAGIC;
3555 spv.version = ICD_SPV_VERSION;
3556 spv.gen_magic = 0;
3557
3558 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3559 moduleCreateInfo.pNext = NULL;
3560 moduleCreateInfo.pCode = &spv;
3561 moduleCreateInfo.codeSize = 4;
3562 moduleCreateInfo.flags = 0;
3563 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3564
3565 msgFlags = m_errorMonitor->GetState(&msgString);
3566
Chris Forbes46794b82015-09-18 11:40:23 +12003567 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003568 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3569 FAIL() << "Incorrect warning: " << msgString;
3570 }
3571}
3572
3573TEST_F(VkLayerTest, InvalidSPIRVMagic)
3574{
3575 VkFlags msgFlags;
3576 std::string msgString;
3577 ASSERT_NO_FATAL_FAILURE(InitState());
3578 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3579
3580 m_errorMonitor->ClearState();
3581
3582 VkShaderModule module;
3583 VkShaderModuleCreateInfo moduleCreateInfo;
3584 struct icd_spv_header spv;
3585
3586 spv.magic = ~ICD_SPV_MAGIC;
3587 spv.version = ICD_SPV_VERSION;
3588 spv.gen_magic = 0;
3589
3590 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3591 moduleCreateInfo.pNext = NULL;
3592 moduleCreateInfo.pCode = &spv;
3593 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3594 moduleCreateInfo.flags = 0;
3595 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3596
3597 msgFlags = m_errorMonitor->GetState(&msgString);
3598
Chris Forbes46794b82015-09-18 11:40:23 +12003599 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003600 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3601 FAIL() << "Incorrect warning: " << msgString;
3602 }
3603}
3604
3605TEST_F(VkLayerTest, InvalidSPIRVVersion)
3606{
3607 VkFlags msgFlags;
3608 std::string msgString;
3609 ASSERT_NO_FATAL_FAILURE(InitState());
3610 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3611
3612 m_errorMonitor->ClearState();
3613
3614 VkShaderModule module;
3615 VkShaderModuleCreateInfo moduleCreateInfo;
3616 struct icd_spv_header spv;
3617
3618 spv.magic = ICD_SPV_MAGIC;
3619 spv.version = ~ICD_SPV_VERSION;
3620 spv.gen_magic = 0;
3621
3622 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3623 moduleCreateInfo.pNext = NULL;
3624
3625 moduleCreateInfo.pCode = &spv;
3626 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3627 moduleCreateInfo.flags = 0;
3628 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3629
3630 msgFlags = m_errorMonitor->GetState(&msgString);
3631
Chris Forbes46794b82015-09-18 11:40:23 +12003632 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003633 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3634 FAIL() << "Incorrect warning: " << msgString;
3635 }
3636}
3637
Chris Forbes9f7ff632015-05-25 11:13:08 +12003638TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
3639{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003640 VkFlags msgFlags;
Chris Forbes9f7ff632015-05-25 11:13:08 +12003641 std::string msgString;
3642 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12003644
3645 char const *vsSource =
3646 "#version 140\n"
3647 "#extension GL_ARB_separate_shader_objects: require\n"
3648 "#extension GL_ARB_shading_language_420pack: require\n"
3649 "\n"
3650 "layout(location=0) out float x;\n"
3651 "void main(){\n"
3652 " gl_Position = vec4(1);\n"
3653 " x = 0;\n"
3654 "}\n";
3655 char const *fsSource =
3656 "#version 140\n"
3657 "#extension GL_ARB_separate_shader_objects: require\n"
3658 "#extension GL_ARB_shading_language_420pack: require\n"
3659 "\n"
3660 "layout(location=0) out vec4 color;\n"
3661 "void main(){\n"
3662 " color = vec4(1);\n"
3663 "}\n";
3664
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003665 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3666 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12003667
3668 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003669 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12003670 pipe.AddShader(&vs);
3671 pipe.AddShader(&fs);
3672
Chris Forbes9f7ff632015-05-25 11:13:08 +12003673 VkDescriptorSetObj descriptorSet(m_device);
3674 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003675 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12003676
3677 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003678 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12003679
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003680 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes9f7ff632015-05-25 11:13:08 +12003681
Cody Northropd2ad0342015-08-05 11:15:02 -06003682 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes9f7ff632015-05-25 11:13:08 +12003683 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
3684 FAIL() << "Incorrect warning: " << msgString;
3685 }
3686}
Chris Forbes9f7ff632015-05-25 11:13:08 +12003687
Chris Forbes59cb88d2015-05-25 11:13:13 +12003688TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
3689{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003690 VkFlags msgFlags;
Chris Forbes59cb88d2015-05-25 11:13:13 +12003691 std::string msgString;
3692 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003693 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12003694
3695 char const *vsSource =
3696 "#version 140\n"
3697 "#extension GL_ARB_separate_shader_objects: require\n"
3698 "#extension GL_ARB_shading_language_420pack: require\n"
3699 "\n"
3700 "void main(){\n"
3701 " gl_Position = vec4(1);\n"
3702 "}\n";
3703 char const *fsSource =
3704 "#version 140\n"
3705 "#extension GL_ARB_separate_shader_objects: require\n"
3706 "#extension GL_ARB_shading_language_420pack: require\n"
3707 "\n"
3708 "layout(location=0) in float x;\n"
3709 "layout(location=0) out vec4 color;\n"
3710 "void main(){\n"
3711 " color = vec4(x);\n"
3712 "}\n";
3713
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003714 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3715 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12003716
3717 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003718 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12003719 pipe.AddShader(&vs);
3720 pipe.AddShader(&fs);
3721
Chris Forbes59cb88d2015-05-25 11:13:13 +12003722 VkDescriptorSetObj descriptorSet(m_device);
3723 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003724 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12003725
3726 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003727 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12003728
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003729 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes59cb88d2015-05-25 11:13:13 +12003730
Cody Northropd2ad0342015-08-05 11:15:02 -06003731 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes59cb88d2015-05-25 11:13:13 +12003732 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
3733 FAIL() << "Incorrect error: " << msgString;
3734 }
3735}
3736
Chris Forbesb56af562015-05-25 11:13:17 +12003737TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
3738{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003739 VkFlags msgFlags;
Chris Forbesb56af562015-05-25 11:13:17 +12003740 std::string msgString;
3741 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12003743
3744 char const *vsSource =
3745 "#version 140\n"
3746 "#extension GL_ARB_separate_shader_objects: require\n"
3747 "#extension GL_ARB_shading_language_420pack: require\n"
3748 "\n"
3749 "layout(location=0) out int x;\n"
3750 "void main(){\n"
3751 " x = 0;\n"
3752 " gl_Position = vec4(1);\n"
3753 "}\n";
3754 char const *fsSource =
3755 "#version 140\n"
3756 "#extension GL_ARB_separate_shader_objects: require\n"
3757 "#extension GL_ARB_shading_language_420pack: require\n"
3758 "\n"
3759 "layout(location=0) in float x;\n" /* VS writes int */
3760 "layout(location=0) out vec4 color;\n"
3761 "void main(){\n"
3762 " color = vec4(x);\n"
3763 "}\n";
3764
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003765 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3766 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12003767
3768 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003769 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12003770 pipe.AddShader(&vs);
3771 pipe.AddShader(&fs);
3772
Chris Forbesb56af562015-05-25 11:13:17 +12003773 VkDescriptorSetObj descriptorSet(m_device);
3774 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003775 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12003776
3777 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003778 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12003779
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003780 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesb56af562015-05-25 11:13:17 +12003781
Cody Northropd2ad0342015-08-05 11:15:02 -06003782 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesb56af562015-05-25 11:13:17 +12003783 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
3784 FAIL() << "Incorrect error: " << msgString;
3785 }
3786}
3787
Chris Forbesde136e02015-05-25 11:13:28 +12003788TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
3789{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003790 VkFlags msgFlags;
Chris Forbesde136e02015-05-25 11:13:28 +12003791 std::string msgString;
3792 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12003794
3795 VkVertexInputBindingDescription input_binding;
3796 memset(&input_binding, 0, sizeof(input_binding));
3797
3798 VkVertexInputAttributeDescription input_attrib;
3799 memset(&input_attrib, 0, sizeof(input_attrib));
3800 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3801
3802 char const *vsSource =
3803 "#version 140\n"
3804 "#extension GL_ARB_separate_shader_objects: require\n"
3805 "#extension GL_ARB_shading_language_420pack: require\n"
3806 "\n"
3807 "void main(){\n"
3808 " gl_Position = vec4(1);\n"
3809 "}\n";
3810 char const *fsSource =
3811 "#version 140\n"
3812 "#extension GL_ARB_separate_shader_objects: require\n"
3813 "#extension GL_ARB_shading_language_420pack: require\n"
3814 "\n"
3815 "layout(location=0) out vec4 color;\n"
3816 "void main(){\n"
3817 " color = vec4(1);\n"
3818 "}\n";
3819
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003820 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3821 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12003822
3823 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003824 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12003825 pipe.AddShader(&vs);
3826 pipe.AddShader(&fs);
3827
3828 pipe.AddVertexInputBindings(&input_binding, 1);
3829 pipe.AddVertexInputAttribs(&input_attrib, 1);
3830
Chris Forbesde136e02015-05-25 11:13:28 +12003831 VkDescriptorSetObj descriptorSet(m_device);
3832 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003833 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12003834
3835 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003836 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12003837
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003838 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesde136e02015-05-25 11:13:28 +12003839
Cody Northropd2ad0342015-08-05 11:15:02 -06003840 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesde136e02015-05-25 11:13:28 +12003841 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
3842 FAIL() << "Incorrect warning: " << msgString;
3843 }
3844}
3845
Chris Forbes62e8e502015-05-25 11:13:29 +12003846TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
3847{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003848 VkFlags msgFlags;
Chris Forbes62e8e502015-05-25 11:13:29 +12003849 std::string msgString;
3850 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12003852
3853 char const *vsSource =
3854 "#version 140\n"
3855 "#extension GL_ARB_separate_shader_objects: require\n"
3856 "#extension GL_ARB_shading_language_420pack: require\n"
3857 "\n"
3858 "layout(location=0) in vec4 x;\n" /* not provided */
3859 "void main(){\n"
3860 " gl_Position = x;\n"
3861 "}\n";
3862 char const *fsSource =
3863 "#version 140\n"
3864 "#extension GL_ARB_separate_shader_objects: require\n"
3865 "#extension GL_ARB_shading_language_420pack: require\n"
3866 "\n"
3867 "layout(location=0) out vec4 color;\n"
3868 "void main(){\n"
3869 " color = vec4(1);\n"
3870 "}\n";
3871
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003872 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3873 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12003874
3875 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003876 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12003877 pipe.AddShader(&vs);
3878 pipe.AddShader(&fs);
3879
Chris Forbes62e8e502015-05-25 11:13:29 +12003880 VkDescriptorSetObj descriptorSet(m_device);
3881 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003882 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12003883
3884 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003885 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12003886
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003887 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes62e8e502015-05-25 11:13:29 +12003888
Cody Northropd2ad0342015-08-05 11:15:02 -06003889 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes62e8e502015-05-25 11:13:29 +12003890 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
3891 FAIL() << "Incorrect warning: " << msgString;
3892 }
3893}
3894
Chris Forbesc97d98e2015-05-25 11:13:31 +12003895TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
3896{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003897 VkFlags msgFlags;
Chris Forbesc97d98e2015-05-25 11:13:31 +12003898 std::string msgString;
3899 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003900 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12003901
3902 VkVertexInputBindingDescription input_binding;
3903 memset(&input_binding, 0, sizeof(input_binding));
3904
3905 VkVertexInputAttributeDescription input_attrib;
3906 memset(&input_attrib, 0, sizeof(input_attrib));
3907 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3908
3909 char const *vsSource =
3910 "#version 140\n"
3911 "#extension GL_ARB_separate_shader_objects: require\n"
3912 "#extension GL_ARB_shading_language_420pack: require\n"
3913 "\n"
3914 "layout(location=0) in int x;\n" /* attrib provided float */
3915 "void main(){\n"
3916 " gl_Position = vec4(x);\n"
3917 "}\n";
3918 char const *fsSource =
3919 "#version 140\n"
3920 "#extension GL_ARB_separate_shader_objects: require\n"
3921 "#extension GL_ARB_shading_language_420pack: require\n"
3922 "\n"
3923 "layout(location=0) out vec4 color;\n"
3924 "void main(){\n"
3925 " color = vec4(1);\n"
3926 "}\n";
3927
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003928 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3929 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12003930
3931 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003932 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12003933 pipe.AddShader(&vs);
3934 pipe.AddShader(&fs);
3935
3936 pipe.AddVertexInputBindings(&input_binding, 1);
3937 pipe.AddVertexInputAttribs(&input_attrib, 1);
3938
Chris Forbesc97d98e2015-05-25 11:13:31 +12003939 VkDescriptorSetObj descriptorSet(m_device);
3940 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003941 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12003942
3943 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003944 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12003945
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003946 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc97d98e2015-05-25 11:13:31 +12003947
Cody Northropd2ad0342015-08-05 11:15:02 -06003948 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc97d98e2015-05-25 11:13:31 +12003949 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
3950 FAIL() << "Incorrect error: " << msgString;
3951 }
3952}
3953
Chris Forbes280ba2c2015-06-12 11:16:41 +12003954TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
3955{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003956 VkFlags msgFlags;
Chris Forbes280ba2c2015-06-12 11:16:41 +12003957 std::string msgString;
3958 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12003960
3961 /* Two binding descriptions for binding 0 */
3962 VkVertexInputBindingDescription input_bindings[2];
3963 memset(input_bindings, 0, sizeof(input_bindings));
3964
3965 VkVertexInputAttributeDescription input_attrib;
3966 memset(&input_attrib, 0, sizeof(input_attrib));
3967 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3968
3969 char const *vsSource =
3970 "#version 140\n"
3971 "#extension GL_ARB_separate_shader_objects: require\n"
3972 "#extension GL_ARB_shading_language_420pack: require\n"
3973 "\n"
3974 "layout(location=0) in float x;\n" /* attrib provided float */
3975 "void main(){\n"
3976 " gl_Position = vec4(x);\n"
3977 "}\n";
3978 char const *fsSource =
3979 "#version 140\n"
3980 "#extension GL_ARB_separate_shader_objects: require\n"
3981 "#extension GL_ARB_shading_language_420pack: require\n"
3982 "\n"
3983 "layout(location=0) out vec4 color;\n"
3984 "void main(){\n"
3985 " color = vec4(1);\n"
3986 "}\n";
3987
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003988 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3989 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12003990
3991 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003992 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12003993 pipe.AddShader(&vs);
3994 pipe.AddShader(&fs);
3995
3996 pipe.AddVertexInputBindings(input_bindings, 2);
3997 pipe.AddVertexInputAttribs(&input_attrib, 1);
3998
Chris Forbes280ba2c2015-06-12 11:16:41 +12003999 VkDescriptorSetObj descriptorSet(m_device);
4000 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06004001 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12004002
4003 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004004 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12004005
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004006 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes280ba2c2015-06-12 11:16:41 +12004007
Cody Northropd2ad0342015-08-05 11:15:02 -06004008 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes280ba2c2015-06-12 11:16:41 +12004009 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
4010 FAIL() << "Incorrect error: " << msgString;
4011 }
4012}
Chris Forbes8f68b562015-05-25 11:13:32 +12004013
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004014/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
4015 * rejects it. */
4016
4017TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
4018{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004019 VkFlags msgFlags;
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004020 std::string msgString;
4021 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004022
4023 char const *vsSource =
4024 "#version 140\n"
4025 "#extension GL_ARB_separate_shader_objects: require\n"
4026 "#extension GL_ARB_shading_language_420pack: require\n"
4027 "\n"
4028 "void main(){\n"
4029 " gl_Position = vec4(1);\n"
4030 "}\n";
4031 char const *fsSource =
4032 "#version 140\n"
4033 "#extension GL_ARB_separate_shader_objects: require\n"
4034 "#extension GL_ARB_shading_language_420pack: require\n"
4035 "\n"
4036 "void main(){\n"
4037 "}\n";
4038
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004039 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4040 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004041
4042 VkPipelineObj pipe(m_device);
4043 pipe.AddShader(&vs);
4044 pipe.AddShader(&fs);
4045
Chia-I Wu08accc62015-07-07 11:50:03 +08004046 /* set up CB 0, not written */
4047 pipe.AddColorAttachment();
4048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004049
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004050 VkDescriptorSetObj descriptorSet(m_device);
4051 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06004052 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004053
4054 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004055 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004056
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004057 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004058
Cody Northropd2ad0342015-08-05 11:15:02 -06004059 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004060 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
4061 FAIL() << "Incorrect error: " << msgString;
4062 }
4063}
4064
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004065TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
4066{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004067 VkFlags msgFlags;
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004068 std::string msgString;
4069 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004070
4071 char const *vsSource =
4072 "#version 140\n"
4073 "#extension GL_ARB_separate_shader_objects: require\n"
4074 "#extension GL_ARB_shading_language_420pack: require\n"
4075 "\n"
4076 "void main(){\n"
4077 " gl_Position = vec4(1);\n"
4078 "}\n";
4079 char const *fsSource =
4080 "#version 140\n"
4081 "#extension GL_ARB_separate_shader_objects: require\n"
4082 "#extension GL_ARB_shading_language_420pack: require\n"
4083 "\n"
4084 "layout(location=0) out vec4 x;\n"
4085 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4086 "void main(){\n"
4087 " x = vec4(1);\n"
4088 " y = vec4(1);\n"
4089 "}\n";
4090
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004091 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4092 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004093
4094 VkPipelineObj pipe(m_device);
4095 pipe.AddShader(&vs);
4096 pipe.AddShader(&fs);
4097
Chia-I Wu08accc62015-07-07 11:50:03 +08004098 /* set up CB 0, not written */
4099 pipe.AddColorAttachment();
4100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004101 /* FS writes CB 1, but we don't configure it */
4102
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004103 VkDescriptorSetObj descriptorSet(m_device);
4104 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06004105 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004106
4107 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004108 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004109
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004110 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004111
Cody Northropd2ad0342015-08-05 11:15:02 -06004112 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004113 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
4114 FAIL() << "Incorrect warning: " << msgString;
4115 }
4116}
4117
Chris Forbesa36d69e2015-05-25 11:13:44 +12004118TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4119{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004120 VkFlags msgFlags;
Chris Forbesa36d69e2015-05-25 11:13:44 +12004121 std::string msgString;
4122 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004123
4124 char const *vsSource =
4125 "#version 140\n"
4126 "#extension GL_ARB_separate_shader_objects: require\n"
4127 "#extension GL_ARB_shading_language_420pack: require\n"
4128 "\n"
4129 "void main(){\n"
4130 " gl_Position = vec4(1);\n"
4131 "}\n";
4132 char const *fsSource =
4133 "#version 140\n"
4134 "#extension GL_ARB_separate_shader_objects: require\n"
4135 "#extension GL_ARB_shading_language_420pack: require\n"
4136 "\n"
4137 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4138 "void main(){\n"
4139 " x = ivec4(1);\n"
4140 "}\n";
4141
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004142 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4143 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004144
4145 VkPipelineObj pipe(m_device);
4146 pipe.AddShader(&vs);
4147 pipe.AddShader(&fs);
4148
Chia-I Wu08accc62015-07-07 11:50:03 +08004149 /* set up CB 0; type is UNORM by default */
4150 pipe.AddColorAttachment();
4151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004152
Chris Forbesa36d69e2015-05-25 11:13:44 +12004153 VkDescriptorSetObj descriptorSet(m_device);
4154 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06004155 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004156
4157 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004158 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004159
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004160 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004161
Cody Northropd2ad0342015-08-05 11:15:02 -06004162 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa36d69e2015-05-25 11:13:44 +12004163 if (!strstr(msgString.c_str(),"does not match FS output type")) {
4164 FAIL() << "Incorrect error: " << msgString;
4165 }
4166}
Chris Forbes7b1b8932015-06-05 14:43:36 +12004167
Chris Forbes556c76c2015-08-14 12:04:59 +12004168TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4169{
4170 VkFlags msgFlags;
4171 std::string msgString;
4172 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12004173
4174 char const *vsSource =
4175 "#version 140\n"
4176 "#extension GL_ARB_separate_shader_objects: require\n"
4177 "#extension GL_ARB_shading_language_420pack: require\n"
4178 "\n"
4179 "void main(){\n"
4180 " gl_Position = vec4(1);\n"
4181 "}\n";
4182 char const *fsSource =
4183 "#version 140\n"
4184 "#extension GL_ARB_separate_shader_objects: require\n"
4185 "#extension GL_ARB_shading_language_420pack: require\n"
4186 "\n"
4187 "layout(location=0) out vec4 x;\n"
4188 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4189 "void main(){\n"
4190 " x = vec4(bar.y);\n"
4191 "}\n";
4192
4193 m_errorMonitor->ClearState();
4194
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004195 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4196 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12004197
4198
4199 VkPipelineObj pipe(m_device);
4200 pipe.AddShader(&vs);
4201 pipe.AddShader(&fs);
4202
4203 /* set up CB 0; type is UNORM by default */
4204 pipe.AddColorAttachment();
4205 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4206
4207 VkDescriptorSetObj descriptorSet(m_device);
4208 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
4209
4210 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4211
4212 /* should have generated an error -- pipeline layout does not
4213 * provide a uniform buffer in 0.0
4214 */
4215 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -06004216 ASSERT_TRUE((msgFlags & VK_DBG_REPORT_ERROR_BIT) == VK_DBG_REPORT_ERROR_BIT);
Chris Forbes556c76c2015-08-14 12:04:59 +12004217 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
4218 FAIL() << "Incorrect error: " << msgString;
4219 }
4220}
4221
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004222#endif // SHADER_CHECKER_TESTS
4223
4224#if DEVICE_LIMITS_TESTS
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004225TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4226{
4227 VkFlags msgFlags;
4228 std::string msgString;
4229
4230 ASSERT_NO_FATAL_FAILURE(InitState());
4231 m_errorMonitor->ClearState();
4232
4233 // Create an image
4234 VkImage image;
4235
4236 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4237 const int32_t tex_width = 32;
4238 const int32_t tex_height = 32;
4239
4240 VkImageCreateInfo image_create_info = {};
4241 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4242 image_create_info.pNext = NULL;
4243 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4244 image_create_info.format = tex_format;
4245 image_create_info.extent.width = tex_width;
4246 image_create_info.extent.height = tex_height;
4247 image_create_info.extent.depth = 1;
4248 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004249 image_create_info.arrayLayers = 1;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004250 image_create_info.samples = 1;
4251 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4252 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4253 image_create_info.flags = 0;
4254
4255 // Introduce error by sending down a bogus width extent
4256 image_create_info.extent.width = 65536;
4257 vkCreateImage(m_device->device(), &image_create_info, &image);
4258
4259 msgFlags = m_errorMonitor->GetState(&msgString);
4260 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4261 "with extents outside the queried limits";
4262 if (!strstr(msgString.c_str(),"CreateImage extents exceed allowable limits for format")) {
4263 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4264 }
4265}
4266
4267TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4268{
4269 VkFlags msgFlags;
4270 std::string msgString;
4271
4272 ASSERT_NO_FATAL_FAILURE(InitState());
4273 m_errorMonitor->ClearState();
4274
4275 // Create an image
4276 VkImage image;
4277
4278 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4279 const int32_t tex_width = 32;
4280 const int32_t tex_height = 32;
4281
4282 VkImageCreateInfo image_create_info = {};
4283 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4284 image_create_info.pNext = NULL;
4285 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4286 image_create_info.format = tex_format;
4287 image_create_info.extent.width = tex_width;
4288 image_create_info.extent.height = tex_height;
4289 image_create_info.extent.depth = 1;
4290 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004291 image_create_info.arrayLayers = 1;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004292 image_create_info.samples = 1;
4293 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4294 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4295 image_create_info.flags = 0;
4296
4297 // Introduce error by sending down individually allowable values that result in a surface size
4298 // exceeding the device maximum
4299 image_create_info.extent.width = 8192;
4300 image_create_info.extent.height = 8192;
4301 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004302 image_create_info.arrayLayers = 4;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004303 image_create_info.samples = 2;
4304 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
4305 vkCreateImage(m_device->device(), &image_create_info, &image);
4306
4307 msgFlags = m_errorMonitor->GetState(&msgString);
4308 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4309 "with resource size exceeding queried limit";
4310 if (!strstr(msgString.c_str(),"CreateImage resource size exceeds allowable maximum")) {
4311 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4312 }
4313}
4314
Mike Stroyana3082432015-09-25 13:39:21 -06004315TEST_F(VkLayerTest, UpdateBufferAlignment)
4316{
4317 VkFlags msgFlags;
4318 std::string msgString;
4319 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4320
4321 ASSERT_NO_FATAL_FAILURE(InitState());
4322
4323 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4324 vk_testing::Buffer buffer;
4325 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4326
4327 BeginCommandBuffer();
4328 // Introduce failure by using offset that is not multiple of 4
4329 m_cmdBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
4330 msgFlags = m_errorMonitor->GetState(&msgString);
4331 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad offset";
4332 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4333 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4334 }
4335 // Introduce failure by using size that is not multiple of 4
4336 m_cmdBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
4337 msgFlags = m_errorMonitor->GetState(&msgString);
4338 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad size";
4339 if (!strstr(msgString.c_str(),"dataSize, is not a multiple of 4")) {
4340 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4341 }
4342 EndCommandBuffer();
4343}
4344
4345TEST_F(VkLayerTest, FillBufferAlignment)
4346{
4347 VkFlags msgFlags;
4348 std::string msgString;
4349
4350 ASSERT_NO_FATAL_FAILURE(InitState());
4351
4352 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4353 vk_testing::Buffer buffer;
4354 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4355
4356 BeginCommandBuffer();
4357 // Introduce failure by using offset that is not multiple of 4
4358 m_cmdBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
4359 msgFlags = m_errorMonitor->GetState(&msgString);
4360 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad offset";
4361 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4362 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4363 }
4364 // Introduce failure by using size that is not multiple of 4
4365 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
4366 msgFlags = m_errorMonitor->GetState(&msgString);
4367 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad size";
4368 if (!strstr(msgString.c_str(),"fillSize, is not a multiple of 4")) {
4369 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize fillSize, is not a multiple of 4'";
4370 }
4371 EndCommandBuffer();
4372}
4373
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004374#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12004375
Tobin Ehliscde08892015-09-22 10:11:37 -06004376#if IMAGE_TESTS
4377TEST_F(VkLayerTest, InvalidImageView)
4378{
4379 VkFlags msgFlags;
4380 std::string msgString;
4381 VkResult err;
4382
4383 ASSERT_NO_FATAL_FAILURE(InitState());
4384 m_errorMonitor->ClearState();
4385
Mike Stroyana3082432015-09-25 13:39:21 -06004386 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehliscde08892015-09-22 10:11:37 -06004387 VkImage image;
4388
4389 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4390 const int32_t tex_width = 32;
4391 const int32_t tex_height = 32;
4392
4393 VkImageCreateInfo image_create_info = {};
4394 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4395 image_create_info.pNext = NULL;
4396 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4397 image_create_info.format = tex_format;
4398 image_create_info.extent.width = tex_width;
4399 image_create_info.extent.height = tex_height;
4400 image_create_info.extent.depth = 1;
4401 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004402 image_create_info.arrayLayers = 1;
Tobin Ehliscde08892015-09-22 10:11:37 -06004403 image_create_info.samples = 1;
4404 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4405 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4406 image_create_info.flags = 0;
4407
4408 err = vkCreateImage(m_device->device(), &image_create_info, &image);
4409 ASSERT_VK_SUCCESS(err);
4410
4411 VkImageViewCreateInfo image_view_create_info = {};
4412 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4413 image_view_create_info.image = image;
4414 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4415 image_view_create_info.format = tex_format;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004416 image_view_create_info.subresourceRange.numLayers = 1;
Tobin Ehliscde08892015-09-22 10:11:37 -06004417 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004418 image_view_create_info.subresourceRange.numLevels = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004419 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06004420
4421 VkImageView view;
4422 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
4423
4424 msgFlags = m_errorMonitor->GetState(&msgString);
4425 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an invalid ImageView";
4426 if (!strstr(msgString.c_str(),"vkCreateImageView called with baseMipLevel 10 ")) {
Mike Stroyana3082432015-09-25 13:39:21 -06004427 FAIL() << "Error received was not 'vkCreateImageView called with baseMipLevel 10...' but instead '" << msgString.c_str() << "'";
Tobin Ehliscde08892015-09-22 10:11:37 -06004428 }
4429}
Mike Stroyana3082432015-09-25 13:39:21 -06004430
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004431TEST_F(VkLayerTest, InvalidImageViewAspect)
4432{
4433 VkFlags msgFlags;
4434 std::string msgString;
4435 VkResult err;
4436
4437 ASSERT_NO_FATAL_FAILURE(InitState());
4438 m_errorMonitor->ClearState();
4439
4440 // Create an image and try to create a view with an invalid aspectMask
4441 VkImage image;
4442
4443 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4444 const int32_t tex_width = 32;
4445 const int32_t tex_height = 32;
4446
4447 VkImageCreateInfo image_create_info = {};
4448 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4449 image_create_info.pNext = NULL;
4450 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4451 image_create_info.format = tex_format;
4452 image_create_info.extent.width = tex_width;
4453 image_create_info.extent.height = tex_height;
4454 image_create_info.extent.depth = 1;
4455 image_create_info.mipLevels = 1;
4456 image_create_info.samples = 1;
4457 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4458 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4459 image_create_info.flags = 0;
4460
4461 err = vkCreateImage(m_device->device(), &image_create_info, &image);
4462 ASSERT_VK_SUCCESS(err);
4463
4464 VkImageViewCreateInfo image_view_create_info = {};
4465 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4466 image_view_create_info.image = image;
4467 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4468 image_view_create_info.format = tex_format;
4469 image_view_create_info.subresourceRange.baseMipLevel = 0;
4470 image_view_create_info.subresourceRange.numLevels = 1;
4471 // Cause an error by setting an invalid image aspect
4472 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
4473
4474 VkImageView view;
4475 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
4476
4477 msgFlags = m_errorMonitor->GetState(&msgString);
4478 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error when specifying an invalid ImageView aspect";
4479 if (!strstr(msgString.c_str(),"vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set")) {
4480 FAIL() << "Error received was not 'VkCreateImageView: Color image formats must have ...' but instead '" << msgString.c_str() << "'";
4481 }
4482}
4483
Mike Stroyana3082432015-09-25 13:39:21 -06004484TEST_F(VkLayerTest, CopyImageTypeMismatch)
4485{
4486 VkFlags msgFlags;
4487 std::string msgString;
4488 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004489 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004490
4491 ASSERT_NO_FATAL_FAILURE(InitState());
4492 m_errorMonitor->ClearState();
4493
4494 // Create two images of different types and try to copy between them
4495 VkImage srcImage;
4496 VkImage destImage;
4497 VkDeviceMemory srcMem;
4498 VkDeviceMemory destMem;
4499 VkMemoryRequirements memReqs;
4500
4501 VkImageCreateInfo image_create_info = {};
4502 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4503 image_create_info.pNext = NULL;
4504 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4505 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4506 image_create_info.extent.width = 32;
4507 image_create_info.extent.height = 32;
4508 image_create_info.extent.depth = 1;
4509 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004510 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004511 image_create_info.samples = 1;
4512 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4513 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4514 image_create_info.flags = 0;
4515
4516 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4517 ASSERT_VK_SUCCESS(err);
4518
4519 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4520 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4521
4522 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4523 ASSERT_VK_SUCCESS(err);
4524
4525 // Allocate memory
4526 VkMemoryAllocInfo memAlloc = {};
4527 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4528 memAlloc.pNext = NULL;
4529 memAlloc.allocationSize = 0;
4530 memAlloc.memoryTypeIndex = 0;
4531
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004532 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004533 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004534 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4535 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004536 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4537 ASSERT_VK_SUCCESS(err);
4538
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004539 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004540 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004541 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06004542 ASSERT_VK_SUCCESS(err);
4543 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4544 ASSERT_VK_SUCCESS(err);
4545
4546 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4547 ASSERT_VK_SUCCESS(err);
4548 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4549 ASSERT_VK_SUCCESS(err);
4550
4551 BeginCommandBuffer();
4552 VkImageCopy copyRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004553 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004554 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004555 copyRegion.srcSubresource.baseArrayLayer = 0;
4556 copyRegion.srcSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004557 copyRegion.srcOffset.x = 0;
4558 copyRegion.srcOffset.y = 0;
4559 copyRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004560 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004561 copyRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004562 copyRegion.destSubresource.baseArrayLayer = 0;
4563 copyRegion.destSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004564 copyRegion.destOffset.x = 0;
4565 copyRegion.destOffset.y = 0;
4566 copyRegion.destOffset.z = 0;
4567 copyRegion.extent.width = 1;
4568 copyRegion.extent.height = 1;
4569 copyRegion.extent.depth = 1;
4570 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4571 EndCommandBuffer();
4572
4573 msgFlags = m_errorMonitor->GetState(&msgString);
4574 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4575 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4576 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4577 }
4578
4579 vkDestroyImage(m_device->device(), srcImage);
4580 vkDestroyImage(m_device->device(), destImage);
4581 vkFreeMemory(m_device->device(), srcMem);
4582 vkFreeMemory(m_device->device(), destMem);
4583}
4584
4585TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
4586{
4587 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
4588}
4589
4590TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
4591{
4592 VkFlags msgFlags;
4593 std::string msgString;
4594 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004595 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004596
4597 ASSERT_NO_FATAL_FAILURE(InitState());
4598 m_errorMonitor->ClearState();
4599
4600 // Create two images of different types and try to copy between them
4601 VkImage srcImage;
4602 VkImage destImage;
4603 VkDeviceMemory srcMem;
4604 VkDeviceMemory destMem;
4605 VkMemoryRequirements memReqs;
4606
4607 VkImageCreateInfo image_create_info = {};
4608 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4609 image_create_info.pNext = NULL;
4610 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4611 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4612 image_create_info.extent.width = 32;
4613 image_create_info.extent.height = 32;
4614 image_create_info.extent.depth = 1;
4615 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004616 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004617 image_create_info.samples = 1;
4618 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4619 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4620 image_create_info.flags = 0;
4621
4622 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4623 ASSERT_VK_SUCCESS(err);
4624
4625 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4626 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4627
4628 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4629 ASSERT_VK_SUCCESS(err);
4630
4631 // Allocate memory
4632 VkMemoryAllocInfo memAlloc = {};
4633 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4634 memAlloc.pNext = NULL;
4635 memAlloc.allocationSize = 0;
4636 memAlloc.memoryTypeIndex = 0;
4637
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004638 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004639 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004640 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4641 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004642 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4643 ASSERT_VK_SUCCESS(err);
4644
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004645 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004646 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004647 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4648 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004649 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4650 ASSERT_VK_SUCCESS(err);
4651
4652 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4653 ASSERT_VK_SUCCESS(err);
4654 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4655 ASSERT_VK_SUCCESS(err);
4656
4657 BeginCommandBuffer();
4658 VkImageCopy copyRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004659 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004660 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004661 copyRegion.srcSubresource.baseArrayLayer = 0;
4662 copyRegion.srcSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004663 copyRegion.srcOffset.x = 0;
4664 copyRegion.srcOffset.y = 0;
4665 copyRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004666 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004667 copyRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004668 copyRegion.destSubresource.baseArrayLayer = 0;
4669 copyRegion.destSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004670 copyRegion.destOffset.x = 0;
4671 copyRegion.destOffset.y = 0;
4672 copyRegion.destOffset.z = 0;
4673 copyRegion.extent.width = 1;
4674 copyRegion.extent.height = 1;
4675 copyRegion.extent.depth = 1;
4676 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4677 EndCommandBuffer();
4678
4679 msgFlags = m_errorMonitor->GetState(&msgString);
4680 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4681 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4682 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4683 }
4684
4685 vkDestroyImage(m_device->device(), srcImage);
4686 vkDestroyImage(m_device->device(), destImage);
4687 vkFreeMemory(m_device->device(), srcMem);
4688 vkFreeMemory(m_device->device(), destMem);
4689}
4690
4691TEST_F(VkLayerTest, ResolveImageLowSampleCount)
4692{
4693 VkFlags msgFlags;
4694 std::string msgString;
4695 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004696 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004697
4698 ASSERT_NO_FATAL_FAILURE(InitState());
4699 m_errorMonitor->ClearState();
4700
4701 // Create two images of sample count 1 and try to Resolve between them
4702 VkImage srcImage;
4703 VkImage destImage;
4704 VkDeviceMemory srcMem;
4705 VkDeviceMemory destMem;
4706 VkMemoryRequirements memReqs;
4707
4708 VkImageCreateInfo image_create_info = {};
4709 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4710 image_create_info.pNext = NULL;
4711 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4712 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4713 image_create_info.extent.width = 32;
4714 image_create_info.extent.height = 1;
4715 image_create_info.extent.depth = 1;
4716 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004717 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004718 image_create_info.samples = 1;
4719 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4720 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4721 image_create_info.flags = 0;
4722
4723 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4724 ASSERT_VK_SUCCESS(err);
4725
4726 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4727 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4728
4729 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4730 ASSERT_VK_SUCCESS(err);
4731
4732 // Allocate memory
4733 VkMemoryAllocInfo memAlloc = {};
4734 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4735 memAlloc.pNext = NULL;
4736 memAlloc.allocationSize = 0;
4737 memAlloc.memoryTypeIndex = 0;
4738
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004739 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004740 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004741 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4742 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004743 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4744 ASSERT_VK_SUCCESS(err);
4745
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004746 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004747 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004748 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4749 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004750 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4751 ASSERT_VK_SUCCESS(err);
4752
4753 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4754 ASSERT_VK_SUCCESS(err);
4755 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4756 ASSERT_VK_SUCCESS(err);
4757
4758 BeginCommandBuffer();
4759 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4760 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4761 //VK_IMAGE_LAYOUT_GENERAL = 1,
4762 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004763 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004764 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004765 resolveRegion.srcSubresource.baseArrayLayer = 0;
4766 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004767 resolveRegion.srcOffset.x = 0;
4768 resolveRegion.srcOffset.y = 0;
4769 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004770 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004771 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004772 resolveRegion.destSubresource.baseArrayLayer = 0;
4773 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004774 resolveRegion.destOffset.x = 0;
4775 resolveRegion.destOffset.y = 0;
4776 resolveRegion.destOffset.z = 0;
4777 resolveRegion.extent.width = 1;
4778 resolveRegion.extent.height = 1;
4779 resolveRegion.extent.depth = 1;
4780 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4781 EndCommandBuffer();
4782
4783 msgFlags = m_errorMonitor->GetState(&msgString);
4784 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4785 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with source sample count less than 2.")) {
4786 FAIL() << "Error received was not 'vkCmdResolveImage called with source sample count less than 2.' but instead '" << msgString.c_str() << "'";
4787 }
4788
4789 vkDestroyImage(m_device->device(), srcImage);
4790 vkDestroyImage(m_device->device(), destImage);
4791 vkFreeMemory(m_device->device(), srcMem);
4792 vkFreeMemory(m_device->device(), destMem);
4793}
4794
4795TEST_F(VkLayerTest, ResolveImageHighSampleCount)
4796{
4797 VkFlags msgFlags;
4798 std::string msgString;
4799 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004800 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004801
4802 ASSERT_NO_FATAL_FAILURE(InitState());
4803 m_errorMonitor->ClearState();
4804
4805 // Create two images of sample count 2 and try to Resolve between them
4806 VkImage srcImage;
4807 VkImage destImage;
4808 VkDeviceMemory srcMem;
4809 VkDeviceMemory destMem;
4810 VkMemoryRequirements memReqs;
4811
4812 VkImageCreateInfo image_create_info = {};
4813 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4814 image_create_info.pNext = NULL;
4815 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4816 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4817 image_create_info.extent.width = 32;
4818 image_create_info.extent.height = 1;
4819 image_create_info.extent.depth = 1;
4820 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004821 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004822 image_create_info.samples = 2;
4823 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4824 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4825 image_create_info.flags = 0;
4826
4827 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4828 ASSERT_VK_SUCCESS(err);
4829
4830 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4831 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4832
4833 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4834 ASSERT_VK_SUCCESS(err);
4835
4836 // Allocate memory
4837 VkMemoryAllocInfo memAlloc = {};
4838 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4839 memAlloc.pNext = NULL;
4840 memAlloc.allocationSize = 0;
4841 memAlloc.memoryTypeIndex = 0;
4842
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004843 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004844 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004845 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4846 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004847 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4848 ASSERT_VK_SUCCESS(err);
4849
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004850 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004851 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004852 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4853 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004854 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4855 ASSERT_VK_SUCCESS(err);
4856
4857 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4858 ASSERT_VK_SUCCESS(err);
4859 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4860 ASSERT_VK_SUCCESS(err);
4861
4862 BeginCommandBuffer();
4863 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4864 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4865 //VK_IMAGE_LAYOUT_GENERAL = 1,
4866 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004867 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004868 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004869 resolveRegion.srcSubresource.baseArrayLayer = 0;
4870 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004871 resolveRegion.srcOffset.x = 0;
4872 resolveRegion.srcOffset.y = 0;
4873 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004874 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004875 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004876 resolveRegion.destSubresource.baseArrayLayer = 0;
4877 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004878 resolveRegion.destOffset.x = 0;
4879 resolveRegion.destOffset.y = 0;
4880 resolveRegion.destOffset.z = 0;
4881 resolveRegion.extent.width = 1;
4882 resolveRegion.extent.height = 1;
4883 resolveRegion.extent.depth = 1;
4884 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4885 EndCommandBuffer();
4886
4887 msgFlags = m_errorMonitor->GetState(&msgString);
4888 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4889 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with dest sample count greater than 1.")) {
4890 FAIL() << "Error received was not 'vkCmdResolveImage called with dest sample count greater than 1.' but instead '" << msgString.c_str() << "'";
4891 }
4892
4893 vkDestroyImage(m_device->device(), srcImage);
4894 vkDestroyImage(m_device->device(), destImage);
4895 vkFreeMemory(m_device->device(), srcMem);
4896 vkFreeMemory(m_device->device(), destMem);
4897}
4898
4899TEST_F(VkLayerTest, ResolveImageFormatMismatch)
4900{
4901 VkFlags msgFlags;
4902 std::string msgString;
4903 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004904 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004905
4906 ASSERT_NO_FATAL_FAILURE(InitState());
4907 m_errorMonitor->ClearState();
4908
4909 // Create two images of different types and try to copy between them
4910 VkImage srcImage;
4911 VkImage destImage;
4912 VkDeviceMemory srcMem;
4913 VkDeviceMemory destMem;
4914 VkMemoryRequirements memReqs;
4915
4916 VkImageCreateInfo image_create_info = {};
4917 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4918 image_create_info.pNext = NULL;
4919 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4920 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4921 image_create_info.extent.width = 32;
4922 image_create_info.extent.height = 1;
4923 image_create_info.extent.depth = 1;
4924 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004925 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004926 image_create_info.samples = 2;
4927 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4928 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4929 image_create_info.flags = 0;
4930
4931 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4932 ASSERT_VK_SUCCESS(err);
4933
4934 image_create_info.format = VK_FORMAT_B8G8R8_SRGB;
4935 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4936 image_create_info.samples = 1;
4937
4938 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4939 ASSERT_VK_SUCCESS(err);
4940
4941 // Allocate memory
4942 VkMemoryAllocInfo memAlloc = {};
4943 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4944 memAlloc.pNext = NULL;
4945 memAlloc.allocationSize = 0;
4946 memAlloc.memoryTypeIndex = 0;
4947
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004948 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004949 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004950 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4951 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004952 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4953 ASSERT_VK_SUCCESS(err);
4954
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004955 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004956 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004957 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4958 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004959 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4960 ASSERT_VK_SUCCESS(err);
4961
4962 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4963 ASSERT_VK_SUCCESS(err);
4964 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4965 ASSERT_VK_SUCCESS(err);
4966
4967 BeginCommandBuffer();
4968 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4969 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4970 //VK_IMAGE_LAYOUT_GENERAL = 1,
4971 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004972 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004973 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004974 resolveRegion.srcSubresource.baseArrayLayer = 0;
4975 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004976 resolveRegion.srcOffset.x = 0;
4977 resolveRegion.srcOffset.y = 0;
4978 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004979 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004980 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004981 resolveRegion.destSubresource.baseArrayLayer = 0;
4982 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004983 resolveRegion.destOffset.x = 0;
4984 resolveRegion.destOffset.y = 0;
4985 resolveRegion.destOffset.z = 0;
4986 resolveRegion.extent.width = 1;
4987 resolveRegion.extent.height = 1;
4988 resolveRegion.extent.depth = 1;
4989 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4990 EndCommandBuffer();
4991
4992 msgFlags = m_errorMonitor->GetState(&msgString);
4993 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage format mismatch";
4994 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest formats.")) {
4995 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest formats.' but instead '" << msgString.c_str() << "'";
4996 }
4997
4998 vkDestroyImage(m_device->device(), srcImage);
4999 vkDestroyImage(m_device->device(), destImage);
5000 vkFreeMemory(m_device->device(), srcMem);
5001 vkFreeMemory(m_device->device(), destMem);
5002}
5003
5004TEST_F(VkLayerTest, ResolveImageTypeMismatch)
5005{
5006 VkFlags msgFlags;
5007 std::string msgString;
5008 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005009 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005010
5011 ASSERT_NO_FATAL_FAILURE(InitState());
5012 m_errorMonitor->ClearState();
5013
5014 // Create two images of different types and try to copy between them
5015 VkImage srcImage;
5016 VkImage destImage;
5017 VkDeviceMemory srcMem;
5018 VkDeviceMemory destMem;
5019 VkMemoryRequirements memReqs;
5020
5021 VkImageCreateInfo image_create_info = {};
5022 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5023 image_create_info.pNext = NULL;
5024 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5025 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5026 image_create_info.extent.width = 32;
5027 image_create_info.extent.height = 1;
5028 image_create_info.extent.depth = 1;
5029 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005030 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06005031 image_create_info.samples = 2;
5032 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5033 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
5034 image_create_info.flags = 0;
5035
5036 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
5037 ASSERT_VK_SUCCESS(err);
5038
5039 image_create_info.imageType = VK_IMAGE_TYPE_1D;
5040 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
5041 image_create_info.samples = 1;
5042
5043 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
5044 ASSERT_VK_SUCCESS(err);
5045
5046 // Allocate memory
5047 VkMemoryAllocInfo memAlloc = {};
5048 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5049 memAlloc.pNext = NULL;
5050 memAlloc.allocationSize = 0;
5051 memAlloc.memoryTypeIndex = 0;
5052
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005053 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005054 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005055 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5056 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06005057 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
5058 ASSERT_VK_SUCCESS(err);
5059
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005060 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005061 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005062 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5063 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06005064 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
5065 ASSERT_VK_SUCCESS(err);
5066
5067 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5068 ASSERT_VK_SUCCESS(err);
5069 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
5070 ASSERT_VK_SUCCESS(err);
5071
5072 BeginCommandBuffer();
5073 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5074 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5075 //VK_IMAGE_LAYOUT_GENERAL = 1,
5076 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06005077 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005078 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005079 resolveRegion.srcSubresource.baseArrayLayer = 0;
5080 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005081 resolveRegion.srcOffset.x = 0;
5082 resolveRegion.srcOffset.y = 0;
5083 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06005084 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005085 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005086 resolveRegion.destSubresource.baseArrayLayer = 0;
5087 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005088 resolveRegion.destOffset.x = 0;
5089 resolveRegion.destOffset.y = 0;
5090 resolveRegion.destOffset.z = 0;
5091 resolveRegion.extent.width = 1;
5092 resolveRegion.extent.height = 1;
5093 resolveRegion.extent.depth = 1;
5094 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
5095 EndCommandBuffer();
5096
5097 msgFlags = m_errorMonitor->GetState(&msgString);
5098 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
5099 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest image types.")) {
5100 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest image types.' but instead '" << msgString.c_str() << "'";
5101 }
5102
5103 vkDestroyImage(m_device->device(), srcImage);
5104 vkDestroyImage(m_device->device(), destImage);
5105 vkFreeMemory(m_device->device(), srcMem);
5106 vkFreeMemory(m_device->device(), destMem);
5107}
Tobin Ehliscde08892015-09-22 10:11:37 -06005108#endif // IMAGE_TESTS
5109
Tony Barbour300a6082015-04-07 13:44:53 -06005110int main(int argc, char **argv) {
5111 int result;
5112
5113 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06005114 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06005115
5116 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
5117
5118 result = RUN_ALL_TESTS();
5119
Tony Barbour6918cd52015-04-09 12:58:51 -06005120 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06005121 return result;
5122}