blob: e06551805bdff022d50031d8040619b481e8a2db [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
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002846 VkDescriptorImageInfo info = {};
2847 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002848
2849 VkWriteDescriptorSet descriptor_write;
2850 memset(&descriptor_write, 0, sizeof(descriptor_write));
2851 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2852 descriptor_write.destSet = descriptorSet;
2853 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002854 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002855 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002856 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002857
2858 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2859
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002860 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002861 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 -06002862 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 ")) {
2863 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 -06002864 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002865
2866 vkDestroySampler(m_device->device(), sampler);
Mike Stroyand1c84a52015-08-18 14:40:24 -06002867 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2868 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002869}
2870
2871TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2872{
2873 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002874 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002875 std::string msgString;
2876 VkResult err;
2877
2878 ASSERT_NO_FATAL_FAILURE(InitState());
2879 m_errorMonitor->ClearState();
2880 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06002881 VkDescriptorTypeCount ds_type_count = {};
2882 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2883 ds_type_count.count = 1;
2884
2885 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2886 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2887 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002888 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002889 ds_pool_ci.count = 1;
2890 ds_pool_ci.pTypeCount = &ds_type_count;
2891
Tobin Ehlis3b780662015-05-28 12:11:26 -06002892 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002893 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002894 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002895
Tony Barboureb254902015-07-15 12:50:33 -06002896 VkDescriptorSetLayoutBinding dsl_binding = {};
2897 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2898 dsl_binding.arraySize = 1;
2899 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2900 dsl_binding.pImmutableSamplers = NULL;
2901
2902 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2903 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2904 ds_layout_ci.pNext = NULL;
2905 ds_layout_ci.count = 1;
2906 ds_layout_ci.pBinding = &dsl_binding;
2907
Tobin Ehlis3b780662015-05-28 12:11:26 -06002908 VkDescriptorSetLayout ds_layout;
2909 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2910 ASSERT_VK_SUCCESS(err);
2911
2912 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002913 VkDescriptorSetAllocInfo alloc_info = {};
2914 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2915 alloc_info.count = 1;
2916 alloc_info.descriptorPool = ds_pool;
2917 alloc_info.pSetLayouts = &ds_layout;
2918 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002919 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002920
Tony Barboureb254902015-07-15 12:50:33 -06002921 VkSamplerCreateInfo sampler_ci = {};
2922 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2923 sampler_ci.pNext = NULL;
2924 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2925 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2926 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06002927 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2928 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2929 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06002930 sampler_ci.mipLodBias = 1.0;
2931 sampler_ci.maxAnisotropy = 1;
2932 sampler_ci.compareEnable = VK_FALSE;
2933 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2934 sampler_ci.minLod = 1.0;
2935 sampler_ci.maxLod = 1.0;
2936 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06002937 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06002938
Tobin Ehlis3b780662015-05-28 12:11:26 -06002939 VkSampler sampler;
2940 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2941 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002942
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002943 VkDescriptorImageInfo info = {};
2944 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002945
2946 VkWriteDescriptorSet descriptor_write;
2947 memset(&descriptor_write, 0, sizeof(descriptor_write));
2948 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2949 descriptor_write.destSet = descriptorSet;
2950 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
2951 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002952 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002953 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002954 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002955
2956 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2957
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002958 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002959 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 +08002960 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
2961 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 -06002962 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002963
2964 vkDestroySampler(m_device->device(), sampler);
Mike Stroyand1c84a52015-08-18 14:40:24 -06002965 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2966 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002967}
2968
2969TEST_F(VkLayerTest, InvalidDSUpdateIndex)
2970{
Tobin Ehlis3b780662015-05-28 12:11:26 -06002971 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002972 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002973 std::string msgString;
2974 VkResult err;
2975
2976 ASSERT_NO_FATAL_FAILURE(InitState());
2977 m_errorMonitor->ClearState();
2978 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06002979 VkDescriptorTypeCount ds_type_count = {};
2980 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2981 ds_type_count.count = 1;
2982
2983 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2984 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2985 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002986 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002987 ds_pool_ci.count = 1;
2988 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002989
Tobin Ehlis3b780662015-05-28 12:11:26 -06002990 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002991 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002992 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002993
Tony Barboureb254902015-07-15 12:50:33 -06002994 VkDescriptorSetLayoutBinding dsl_binding = {};
2995 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2996 dsl_binding.arraySize = 1;
2997 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2998 dsl_binding.pImmutableSamplers = NULL;
2999
3000 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3001 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3002 ds_layout_ci.pNext = NULL;
3003 ds_layout_ci.count = 1;
3004 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003005 VkDescriptorSetLayout ds_layout;
3006 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3007 ASSERT_VK_SUCCESS(err);
3008
3009 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003010 VkDescriptorSetAllocInfo alloc_info = {};
3011 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3012 alloc_info.count = 1;
3013 alloc_info.descriptorPool = ds_pool;
3014 alloc_info.pSetLayouts = &ds_layout;
3015 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003016 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003017
Tony Barboureb254902015-07-15 12:50:33 -06003018 VkSamplerCreateInfo sampler_ci = {};
3019 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3020 sampler_ci.pNext = NULL;
3021 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
3022 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
3023 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06003024 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3025 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3026 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06003027 sampler_ci.mipLodBias = 1.0;
3028 sampler_ci.maxAnisotropy = 1;
3029 sampler_ci.compareEnable = VK_FALSE;
3030 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3031 sampler_ci.minLod = 1.0;
3032 sampler_ci.maxLod = 1.0;
3033 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003034 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003035
Tobin Ehlis3b780662015-05-28 12:11:26 -06003036 VkSampler sampler;
3037 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3038 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003039
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003040 VkDescriptorImageInfo info = {};
3041 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003042
3043 VkWriteDescriptorSet descriptor_write;
3044 memset(&descriptor_write, 0, sizeof(descriptor_write));
3045 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3046 descriptor_write.destSet = descriptorSet;
3047 descriptor_write.destBinding = 2;
3048 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003049 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003050 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003051 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003052
3053 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3054
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003055 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003056 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 -06003057 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
3058 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
3059 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003060
3061 vkDestroySampler(m_device->device(), sampler);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003062 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3063 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003064}
3065
3066TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3067{
3068 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003069 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003070 std::string msgString;
3071 VkResult err;
3072
3073 ASSERT_NO_FATAL_FAILURE(InitState());
3074 m_errorMonitor->ClearState();
3075 //VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003076
Tony Barboureb254902015-07-15 12:50:33 -06003077 VkDescriptorTypeCount ds_type_count = {};
3078 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3079 ds_type_count.count = 1;
3080
3081 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3082 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3083 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003084 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003085 ds_pool_ci.count = 1;
3086 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003087
Tobin Ehlis3b780662015-05-28 12:11:26 -06003088 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003089 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003090 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06003091 VkDescriptorSetLayoutBinding dsl_binding = {};
3092 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3093 dsl_binding.arraySize = 1;
3094 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3095 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003096
Tony Barboureb254902015-07-15 12:50:33 -06003097 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3098 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3099 ds_layout_ci.pNext = NULL;
3100 ds_layout_ci.count = 1;
3101 ds_layout_ci.pBinding = &dsl_binding;
3102
Tobin Ehlis3b780662015-05-28 12:11:26 -06003103 VkDescriptorSetLayout ds_layout;
3104 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3105 ASSERT_VK_SUCCESS(err);
3106
3107 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003108 VkDescriptorSetAllocInfo alloc_info = {};
3109 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3110 alloc_info.count = 1;
3111 alloc_info.descriptorPool = ds_pool;
3112 alloc_info.pSetLayouts = &ds_layout;
3113 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003114 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003115
Tony Barboureb254902015-07-15 12:50:33 -06003116 VkSamplerCreateInfo sampler_ci = {};
3117 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3118 sampler_ci.pNext = NULL;
3119 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
3120 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
3121 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06003122 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3123 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3124 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06003125 sampler_ci.mipLodBias = 1.0;
3126 sampler_ci.maxAnisotropy = 1;
3127 sampler_ci.compareEnable = VK_FALSE;
3128 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3129 sampler_ci.minLod = 1.0;
3130 sampler_ci.maxLod = 1.0;
3131 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003132 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003133 VkSampler sampler;
3134 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3135 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003136
3137
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003138 VkDescriptorImageInfo info = {};
3139 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003140
3141 VkWriteDescriptorSet descriptor_write;
3142 memset(&descriptor_write, 0, sizeof(descriptor_write));
3143 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
3144 descriptor_write.destSet = descriptorSet;
3145 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003146 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003147 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003148 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003149
3150 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3151
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003152 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003153 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 -06003154 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
3155 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
3156 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003157
3158 vkDestroySampler(m_device->device(), sampler);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003159 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3160 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003161}
3162
3163TEST_F(VkLayerTest, NumSamplesMismatch)
3164{
Tobin Ehlis3b780662015-05-28 12:11:26 -06003165 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003166 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003167 std::string msgString;
3168 VkResult err;
3169
3170 ASSERT_NO_FATAL_FAILURE(InitState());
3171 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3172 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06003173 VkDescriptorTypeCount ds_type_count = {};
3174 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3175 ds_type_count.count = 1;
3176
3177 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003178 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3179 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003180 ds_pool_ci.maxSets = 1;
3181 ds_pool_ci.count = 1;
3182 ds_pool_ci.pTypeCount = &ds_type_count;
3183
Tobin Ehlis3b780662015-05-28 12:11:26 -06003184 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003185 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003186 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003187
Tony Barboureb254902015-07-15 12:50:33 -06003188 VkDescriptorSetLayoutBinding dsl_binding = {};
3189 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3190 dsl_binding.arraySize = 1;
3191 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3192 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003193
Tony Barboureb254902015-07-15 12:50:33 -06003194 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3195 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3196 ds_layout_ci.pNext = NULL;
3197 ds_layout_ci.count = 1;
3198 ds_layout_ci.pBinding = &dsl_binding;
3199
Tobin Ehlis3b780662015-05-28 12:11:26 -06003200 VkDescriptorSetLayout ds_layout;
3201 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3202 ASSERT_VK_SUCCESS(err);
3203
3204 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003205 VkDescriptorSetAllocInfo alloc_info = {};
3206 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3207 alloc_info.count = 1;
3208 alloc_info.descriptorPool = ds_pool;
3209 alloc_info.pSetLayouts = &ds_layout;
3210 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003211 ASSERT_VK_SUCCESS(err);
3212
Tony Barboureb254902015-07-15 12:50:33 -06003213 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3214 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3215 pipe_ms_state_ci.pNext = NULL;
3216 pipe_ms_state_ci.rasterSamples = 4;
3217 pipe_ms_state_ci.sampleShadingEnable = 0;
3218 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003219 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003220
Tony Barboureb254902015-07-15 12:50:33 -06003221 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3222 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3223 pipeline_layout_ci.pNext = NULL;
3224 pipeline_layout_ci.descriptorSetCount = 1;
3225 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003226
3227 VkPipelineLayout pipeline_layout;
3228 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3229 ASSERT_VK_SUCCESS(err);
3230
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003231 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3232 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 -06003233 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003234 VkPipelineObj pipe(m_device);
3235 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003236 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003237 pipe.SetMSAA(&pipe_ms_state_ci);
3238 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003239
Tony Barbourfe3351b2015-07-28 10:17:20 -06003240 BeginCommandBuffer();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003241 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003242
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003243 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003244 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 -06003245 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
3246 FAIL() << "Error received was not 'Num samples mismatch!...'";
3247 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003248
3249 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003250 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3251 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003252}
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003253
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003254TEST_F(VkLayerTest, ClearCmdNoDraw)
3255{
3256 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
3257 VkFlags msgFlags;
3258 std::string msgString;
3259 VkResult err;
3260
3261 ASSERT_NO_FATAL_FAILURE(InitState());
3262 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3263 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06003264
3265 VkDescriptorTypeCount ds_type_count = {};
3266 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3267 ds_type_count.count = 1;
3268
3269 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3270 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3271 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003272 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003273 ds_pool_ci.count = 1;
3274 ds_pool_ci.pTypeCount = &ds_type_count;
3275
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003276 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003277 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003278 ASSERT_VK_SUCCESS(err);
3279
Tony Barboureb254902015-07-15 12:50:33 -06003280 VkDescriptorSetLayoutBinding dsl_binding = {};
3281 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3282 dsl_binding.arraySize = 1;
3283 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3284 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003285
Tony Barboureb254902015-07-15 12:50:33 -06003286 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3287 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3288 ds_layout_ci.pNext = NULL;
3289 ds_layout_ci.count = 1;
3290 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003291
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003292 VkDescriptorSetLayout ds_layout;
3293 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3294 ASSERT_VK_SUCCESS(err);
3295
3296 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003297 VkDescriptorSetAllocInfo alloc_info = {};
3298 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3299 alloc_info.count = 1;
3300 alloc_info.descriptorPool = ds_pool;
3301 alloc_info.pSetLayouts = &ds_layout;
3302 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003303 ASSERT_VK_SUCCESS(err);
3304
Tony Barboureb254902015-07-15 12:50:33 -06003305 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3306 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3307 pipe_ms_state_ci.pNext = NULL;
3308 pipe_ms_state_ci.rasterSamples = 4;
3309 pipe_ms_state_ci.sampleShadingEnable = 0;
3310 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003311 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003312
Tony Barboureb254902015-07-15 12:50:33 -06003313 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3314 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3315 pipeline_layout_ci.pNext = NULL;
3316 pipeline_layout_ci.descriptorSetCount = 1;
3317 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003318
3319 VkPipelineLayout pipeline_layout;
3320 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3321 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003322
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003323 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3324 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 -06003325 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003326 VkPipelineObj pipe(m_device);
3327 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003328 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003329 pipe.SetMSAA(&pipe_ms_state_ci);
3330 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003331
3332 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003333
3334 m_errorMonitor->ClearState();
3335 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3336 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003337 VkClearAttachment color_attachment;
3338 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3339 color_attachment.clearValue.color.float32[0] = 1.0;
3340 color_attachment.clearValue.color.float32[1] = 1.0;
3341 color_attachment.clearValue.color.float32[2] = 1.0;
3342 color_attachment.clearValue.color.float32[3] = 1.0;
3343 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06003344 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003345
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003346 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003347 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003348 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 -06003349 if (!strstr(msgString.c_str(),"vkCmdClearAttachments() issued on CB object ")) {
3350 FAIL() << "Error received was not 'vkCmdClearAttachments() issued on CB object...'";
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003351 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003352
3353 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003354 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3355 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003356}
3357
Tobin Ehlis502480b2015-06-24 15:53:07 -06003358TEST_F(VkLayerTest, VtxBufferBadIndex)
3359{
3360 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
3361 VkFlags msgFlags;
3362 std::string msgString;
3363 VkResult err;
3364
3365 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06003366 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06003367 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3368 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06003369
3370 VkDescriptorTypeCount ds_type_count = {};
3371 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3372 ds_type_count.count = 1;
3373
3374 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3375 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3376 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003377 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003378 ds_pool_ci.count = 1;
3379 ds_pool_ci.pTypeCount = &ds_type_count;
3380
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003381 VkDescriptorPool ds_pool;
3382 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003383 ASSERT_VK_SUCCESS(err);
3384
Tony Barboureb254902015-07-15 12:50:33 -06003385 VkDescriptorSetLayoutBinding dsl_binding = {};
3386 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3387 dsl_binding.arraySize = 1;
3388 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3389 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003390
Tony Barboureb254902015-07-15 12:50:33 -06003391 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3392 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3393 ds_layout_ci.pNext = NULL;
3394 ds_layout_ci.count = 1;
3395 ds_layout_ci.pBinding = &dsl_binding;
3396
Tobin Ehlis502480b2015-06-24 15:53:07 -06003397 VkDescriptorSetLayout ds_layout;
3398 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3399 ASSERT_VK_SUCCESS(err);
3400
3401 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003402 VkDescriptorSetAllocInfo alloc_info = {};
3403 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3404 alloc_info.count = 1;
3405 alloc_info.descriptorPool = ds_pool;
3406 alloc_info.pSetLayouts = &ds_layout;
3407 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003408 ASSERT_VK_SUCCESS(err);
3409
Tony Barboureb254902015-07-15 12:50:33 -06003410 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3411 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3412 pipe_ms_state_ci.pNext = NULL;
3413 pipe_ms_state_ci.rasterSamples = 1;
3414 pipe_ms_state_ci.sampleShadingEnable = 0;
3415 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003416 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003417
Tony Barboureb254902015-07-15 12:50:33 -06003418 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3419 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3420 pipeline_layout_ci.pNext = NULL;
3421 pipeline_layout_ci.descriptorSetCount = 1;
3422 pipeline_layout_ci.pSetLayouts = &ds_layout;
3423 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003424
Tobin Ehlis502480b2015-06-24 15:53:07 -06003425 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3426 ASSERT_VK_SUCCESS(err);
3427
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003428 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3429 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 -06003430 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003431 VkPipelineObj pipe(m_device);
3432 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003433 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003434 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003435 pipe.SetViewport(m_viewports);
3436 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003437 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003438
3439 BeginCommandBuffer();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003440 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06003441 // Don't care about actual data, just need to get to draw to flag error
3442 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3443 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3444 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003445 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003446
3447 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003448 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 -06003449 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 -06003450 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 -06003451 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003452
3453 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003454 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3455 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003456}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003457#endif // DRAW_STATE_TESTS
3458
Tobin Ehlis0788f522015-05-26 16:11:58 -06003459#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06003460#if GTEST_IS_THREADSAFE
3461struct thread_data_struct {
3462 VkCmdBuffer cmdBuffer;
3463 VkEvent event;
3464 bool bailout;
3465};
3466
3467extern "C" void *AddToCommandBuffer(void *arg)
3468{
3469 struct thread_data_struct *data = (struct thread_data_struct *) arg;
3470 std::string msgString;
3471
3472 for (int i = 0; i<10000; i++) {
Tony Barbour0b2cfb22015-06-29 16:20:35 -06003473 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003474 if (data->bailout) {
3475 break;
3476 }
3477 }
3478 return NULL;
3479}
3480
3481TEST_F(VkLayerTest, ThreadCmdBufferCollision)
3482{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003483 VkFlags msgFlags;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003484 std::string msgString;
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003485 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003486
3487 ASSERT_NO_FATAL_FAILURE(InitState());
3488 ASSERT_NO_FATAL_FAILURE(InitViewport());
3489 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3490
Mike Stroyanaccf7692015-05-12 16:00:45 -06003491 m_errorMonitor->ClearState();
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003492
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003493 // Calls AllocCommandBuffers
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003494 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
3495
3496 // Avoid creating RenderPass
3497 cmdBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003498
3499 VkEventCreateInfo event_info;
3500 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003501 VkResult err;
3502
3503 memset(&event_info, 0, sizeof(event_info));
3504 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3505
3506 err = vkCreateEvent(device(), &event_info, &event);
3507 ASSERT_VK_SUCCESS(err);
3508
Mike Stroyanaccf7692015-05-12 16:00:45 -06003509 err = vkResetEvent(device(), event);
3510 ASSERT_VK_SUCCESS(err);
3511
3512 struct thread_data_struct data;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003513 data.cmdBuffer = cmdBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003514 data.event = event;
3515 data.bailout = false;
3516 m_errorMonitor->SetBailout(&data.bailout);
3517 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003518 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003519 // Add many entries to command buffer from this thread at the same time.
3520 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003521
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003522 test_platform_thread_join(thread, NULL);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003523 cmdBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003524
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003525 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003526 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 -06003527 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -05003528 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyanaccf7692015-05-12 16:00:45 -06003529 }
3530
Mike Stroyand1c84a52015-08-18 14:40:24 -06003531 vkDestroyEvent(device(), event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003532}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003533#endif // GTEST_IS_THREADSAFE
3534#endif // THREADING_TESTS
3535
Chris Forbes9f7ff632015-05-25 11:13:08 +12003536#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003537TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
3538{
3539 VkFlags msgFlags;
3540 std::string msgString;
3541 ASSERT_NO_FATAL_FAILURE(InitState());
3542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3543
3544 m_errorMonitor->ClearState();
3545
3546 VkShaderModule module;
3547 VkShaderModuleCreateInfo moduleCreateInfo;
3548 struct icd_spv_header spv;
3549
3550 spv.magic = ICD_SPV_MAGIC;
3551 spv.version = ICD_SPV_VERSION;
3552 spv.gen_magic = 0;
3553
3554 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3555 moduleCreateInfo.pNext = NULL;
3556 moduleCreateInfo.pCode = &spv;
3557 moduleCreateInfo.codeSize = 4;
3558 moduleCreateInfo.flags = 0;
3559 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3560
3561 msgFlags = m_errorMonitor->GetState(&msgString);
3562
Chris Forbes46794b82015-09-18 11:40:23 +12003563 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003564 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3565 FAIL() << "Incorrect warning: " << msgString;
3566 }
3567}
3568
3569TEST_F(VkLayerTest, InvalidSPIRVMagic)
3570{
3571 VkFlags msgFlags;
3572 std::string msgString;
3573 ASSERT_NO_FATAL_FAILURE(InitState());
3574 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3575
3576 m_errorMonitor->ClearState();
3577
3578 VkShaderModule module;
3579 VkShaderModuleCreateInfo moduleCreateInfo;
3580 struct icd_spv_header spv;
3581
3582 spv.magic = ~ICD_SPV_MAGIC;
3583 spv.version = ICD_SPV_VERSION;
3584 spv.gen_magic = 0;
3585
3586 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3587 moduleCreateInfo.pNext = NULL;
3588 moduleCreateInfo.pCode = &spv;
3589 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3590 moduleCreateInfo.flags = 0;
3591 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3592
3593 msgFlags = m_errorMonitor->GetState(&msgString);
3594
Chris Forbes46794b82015-09-18 11:40:23 +12003595 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003596 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3597 FAIL() << "Incorrect warning: " << msgString;
3598 }
3599}
3600
3601TEST_F(VkLayerTest, InvalidSPIRVVersion)
3602{
3603 VkFlags msgFlags;
3604 std::string msgString;
3605 ASSERT_NO_FATAL_FAILURE(InitState());
3606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3607
3608 m_errorMonitor->ClearState();
3609
3610 VkShaderModule module;
3611 VkShaderModuleCreateInfo moduleCreateInfo;
3612 struct icd_spv_header spv;
3613
3614 spv.magic = ICD_SPV_MAGIC;
3615 spv.version = ~ICD_SPV_VERSION;
3616 spv.gen_magic = 0;
3617
3618 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3619 moduleCreateInfo.pNext = NULL;
3620
3621 moduleCreateInfo.pCode = &spv;
3622 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3623 moduleCreateInfo.flags = 0;
3624 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3625
3626 msgFlags = m_errorMonitor->GetState(&msgString);
3627
Chris Forbes46794b82015-09-18 11:40:23 +12003628 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003629 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3630 FAIL() << "Incorrect warning: " << msgString;
3631 }
3632}
3633
Chris Forbes9f7ff632015-05-25 11:13:08 +12003634TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
3635{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003636 VkFlags msgFlags;
Chris Forbes9f7ff632015-05-25 11:13:08 +12003637 std::string msgString;
3638 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12003640
3641 char const *vsSource =
3642 "#version 140\n"
3643 "#extension GL_ARB_separate_shader_objects: require\n"
3644 "#extension GL_ARB_shading_language_420pack: require\n"
3645 "\n"
3646 "layout(location=0) out float x;\n"
3647 "void main(){\n"
3648 " gl_Position = vec4(1);\n"
3649 " x = 0;\n"
3650 "}\n";
3651 char const *fsSource =
3652 "#version 140\n"
3653 "#extension GL_ARB_separate_shader_objects: require\n"
3654 "#extension GL_ARB_shading_language_420pack: require\n"
3655 "\n"
3656 "layout(location=0) out vec4 color;\n"
3657 "void main(){\n"
3658 " color = vec4(1);\n"
3659 "}\n";
3660
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003661 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3662 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12003663
3664 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003665 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12003666 pipe.AddShader(&vs);
3667 pipe.AddShader(&fs);
3668
Chris Forbes9f7ff632015-05-25 11:13:08 +12003669 VkDescriptorSetObj descriptorSet(m_device);
3670 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003671 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12003672
3673 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003674 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12003675
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003676 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes9f7ff632015-05-25 11:13:08 +12003677
Cody Northropd2ad0342015-08-05 11:15:02 -06003678 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes9f7ff632015-05-25 11:13:08 +12003679 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
3680 FAIL() << "Incorrect warning: " << msgString;
3681 }
3682}
Chris Forbes9f7ff632015-05-25 11:13:08 +12003683
Chris Forbes59cb88d2015-05-25 11:13:13 +12003684TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
3685{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003686 VkFlags msgFlags;
Chris Forbes59cb88d2015-05-25 11:13:13 +12003687 std::string msgString;
3688 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003689 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12003690
3691 char const *vsSource =
3692 "#version 140\n"
3693 "#extension GL_ARB_separate_shader_objects: require\n"
3694 "#extension GL_ARB_shading_language_420pack: require\n"
3695 "\n"
3696 "void main(){\n"
3697 " gl_Position = vec4(1);\n"
3698 "}\n";
3699 char const *fsSource =
3700 "#version 140\n"
3701 "#extension GL_ARB_separate_shader_objects: require\n"
3702 "#extension GL_ARB_shading_language_420pack: require\n"
3703 "\n"
3704 "layout(location=0) in float x;\n"
3705 "layout(location=0) out vec4 color;\n"
3706 "void main(){\n"
3707 " color = vec4(x);\n"
3708 "}\n";
3709
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003710 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3711 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12003712
3713 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003714 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12003715 pipe.AddShader(&vs);
3716 pipe.AddShader(&fs);
3717
Chris Forbes59cb88d2015-05-25 11:13:13 +12003718 VkDescriptorSetObj descriptorSet(m_device);
3719 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003720 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12003721
3722 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003723 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12003724
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003725 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes59cb88d2015-05-25 11:13:13 +12003726
Cody Northropd2ad0342015-08-05 11:15:02 -06003727 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes59cb88d2015-05-25 11:13:13 +12003728 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
3729 FAIL() << "Incorrect error: " << msgString;
3730 }
3731}
3732
Chris Forbesb56af562015-05-25 11:13:17 +12003733TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
3734{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003735 VkFlags msgFlags;
Chris Forbesb56af562015-05-25 11:13:17 +12003736 std::string msgString;
3737 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12003739
3740 char const *vsSource =
3741 "#version 140\n"
3742 "#extension GL_ARB_separate_shader_objects: require\n"
3743 "#extension GL_ARB_shading_language_420pack: require\n"
3744 "\n"
3745 "layout(location=0) out int x;\n"
3746 "void main(){\n"
3747 " x = 0;\n"
3748 " gl_Position = vec4(1);\n"
3749 "}\n";
3750 char const *fsSource =
3751 "#version 140\n"
3752 "#extension GL_ARB_separate_shader_objects: require\n"
3753 "#extension GL_ARB_shading_language_420pack: require\n"
3754 "\n"
3755 "layout(location=0) in float x;\n" /* VS writes int */
3756 "layout(location=0) out vec4 color;\n"
3757 "void main(){\n"
3758 " color = vec4(x);\n"
3759 "}\n";
3760
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003761 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3762 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12003763
3764 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003765 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12003766 pipe.AddShader(&vs);
3767 pipe.AddShader(&fs);
3768
Chris Forbesb56af562015-05-25 11:13:17 +12003769 VkDescriptorSetObj descriptorSet(m_device);
3770 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003771 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12003772
3773 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003774 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12003775
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003776 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesb56af562015-05-25 11:13:17 +12003777
Cody Northropd2ad0342015-08-05 11:15:02 -06003778 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesb56af562015-05-25 11:13:17 +12003779 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
3780 FAIL() << "Incorrect error: " << msgString;
3781 }
3782}
3783
Chris Forbesde136e02015-05-25 11:13:28 +12003784TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
3785{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003786 VkFlags msgFlags;
Chris Forbesde136e02015-05-25 11:13:28 +12003787 std::string msgString;
3788 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12003790
3791 VkVertexInputBindingDescription input_binding;
3792 memset(&input_binding, 0, sizeof(input_binding));
3793
3794 VkVertexInputAttributeDescription input_attrib;
3795 memset(&input_attrib, 0, sizeof(input_attrib));
3796 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3797
3798 char const *vsSource =
3799 "#version 140\n"
3800 "#extension GL_ARB_separate_shader_objects: require\n"
3801 "#extension GL_ARB_shading_language_420pack: require\n"
3802 "\n"
3803 "void main(){\n"
3804 " gl_Position = vec4(1);\n"
3805 "}\n";
3806 char const *fsSource =
3807 "#version 140\n"
3808 "#extension GL_ARB_separate_shader_objects: require\n"
3809 "#extension GL_ARB_shading_language_420pack: require\n"
3810 "\n"
3811 "layout(location=0) out vec4 color;\n"
3812 "void main(){\n"
3813 " color = vec4(1);\n"
3814 "}\n";
3815
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003816 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3817 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12003818
3819 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003820 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12003821 pipe.AddShader(&vs);
3822 pipe.AddShader(&fs);
3823
3824 pipe.AddVertexInputBindings(&input_binding, 1);
3825 pipe.AddVertexInputAttribs(&input_attrib, 1);
3826
Chris Forbesde136e02015-05-25 11:13:28 +12003827 VkDescriptorSetObj descriptorSet(m_device);
3828 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003829 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12003830
3831 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003832 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12003833
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003834 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesde136e02015-05-25 11:13:28 +12003835
Cody Northropd2ad0342015-08-05 11:15:02 -06003836 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesde136e02015-05-25 11:13:28 +12003837 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
3838 FAIL() << "Incorrect warning: " << msgString;
3839 }
3840}
3841
Chris Forbes62e8e502015-05-25 11:13:29 +12003842TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
3843{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003844 VkFlags msgFlags;
Chris Forbes62e8e502015-05-25 11:13:29 +12003845 std::string msgString;
3846 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12003848
3849 char const *vsSource =
3850 "#version 140\n"
3851 "#extension GL_ARB_separate_shader_objects: require\n"
3852 "#extension GL_ARB_shading_language_420pack: require\n"
3853 "\n"
3854 "layout(location=0) in vec4 x;\n" /* not provided */
3855 "void main(){\n"
3856 " gl_Position = x;\n"
3857 "}\n";
3858 char const *fsSource =
3859 "#version 140\n"
3860 "#extension GL_ARB_separate_shader_objects: require\n"
3861 "#extension GL_ARB_shading_language_420pack: require\n"
3862 "\n"
3863 "layout(location=0) out vec4 color;\n"
3864 "void main(){\n"
3865 " color = vec4(1);\n"
3866 "}\n";
3867
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003868 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3869 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12003870
3871 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003872 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12003873 pipe.AddShader(&vs);
3874 pipe.AddShader(&fs);
3875
Chris Forbes62e8e502015-05-25 11:13:29 +12003876 VkDescriptorSetObj descriptorSet(m_device);
3877 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003878 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12003879
3880 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003881 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12003882
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003883 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes62e8e502015-05-25 11:13:29 +12003884
Cody Northropd2ad0342015-08-05 11:15:02 -06003885 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes62e8e502015-05-25 11:13:29 +12003886 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
3887 FAIL() << "Incorrect warning: " << msgString;
3888 }
3889}
3890
Chris Forbesc97d98e2015-05-25 11:13:31 +12003891TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
3892{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003893 VkFlags msgFlags;
Chris Forbesc97d98e2015-05-25 11:13:31 +12003894 std::string msgString;
3895 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003896 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12003897
3898 VkVertexInputBindingDescription input_binding;
3899 memset(&input_binding, 0, sizeof(input_binding));
3900
3901 VkVertexInputAttributeDescription input_attrib;
3902 memset(&input_attrib, 0, sizeof(input_attrib));
3903 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3904
3905 char const *vsSource =
3906 "#version 140\n"
3907 "#extension GL_ARB_separate_shader_objects: require\n"
3908 "#extension GL_ARB_shading_language_420pack: require\n"
3909 "\n"
3910 "layout(location=0) in int x;\n" /* attrib provided float */
3911 "void main(){\n"
3912 " gl_Position = vec4(x);\n"
3913 "}\n";
3914 char const *fsSource =
3915 "#version 140\n"
3916 "#extension GL_ARB_separate_shader_objects: require\n"
3917 "#extension GL_ARB_shading_language_420pack: require\n"
3918 "\n"
3919 "layout(location=0) out vec4 color;\n"
3920 "void main(){\n"
3921 " color = vec4(1);\n"
3922 "}\n";
3923
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003924 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3925 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12003926
3927 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003928 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12003929 pipe.AddShader(&vs);
3930 pipe.AddShader(&fs);
3931
3932 pipe.AddVertexInputBindings(&input_binding, 1);
3933 pipe.AddVertexInputAttribs(&input_attrib, 1);
3934
Chris Forbesc97d98e2015-05-25 11:13:31 +12003935 VkDescriptorSetObj descriptorSet(m_device);
3936 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003937 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12003938
3939 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003940 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12003941
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003942 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc97d98e2015-05-25 11:13:31 +12003943
Cody Northropd2ad0342015-08-05 11:15:02 -06003944 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc97d98e2015-05-25 11:13:31 +12003945 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
3946 FAIL() << "Incorrect error: " << msgString;
3947 }
3948}
3949
Chris Forbes280ba2c2015-06-12 11:16:41 +12003950TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
3951{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003952 VkFlags msgFlags;
Chris Forbes280ba2c2015-06-12 11:16:41 +12003953 std::string msgString;
3954 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12003956
3957 /* Two binding descriptions for binding 0 */
3958 VkVertexInputBindingDescription input_bindings[2];
3959 memset(input_bindings, 0, sizeof(input_bindings));
3960
3961 VkVertexInputAttributeDescription input_attrib;
3962 memset(&input_attrib, 0, sizeof(input_attrib));
3963 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3964
3965 char const *vsSource =
3966 "#version 140\n"
3967 "#extension GL_ARB_separate_shader_objects: require\n"
3968 "#extension GL_ARB_shading_language_420pack: require\n"
3969 "\n"
3970 "layout(location=0) in float x;\n" /* attrib provided float */
3971 "void main(){\n"
3972 " gl_Position = vec4(x);\n"
3973 "}\n";
3974 char const *fsSource =
3975 "#version 140\n"
3976 "#extension GL_ARB_separate_shader_objects: require\n"
3977 "#extension GL_ARB_shading_language_420pack: require\n"
3978 "\n"
3979 "layout(location=0) out vec4 color;\n"
3980 "void main(){\n"
3981 " color = vec4(1);\n"
3982 "}\n";
3983
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003984 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3985 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12003986
3987 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003988 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12003989 pipe.AddShader(&vs);
3990 pipe.AddShader(&fs);
3991
3992 pipe.AddVertexInputBindings(input_bindings, 2);
3993 pipe.AddVertexInputAttribs(&input_attrib, 1);
3994
Chris Forbes280ba2c2015-06-12 11:16:41 +12003995 VkDescriptorSetObj descriptorSet(m_device);
3996 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003997 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12003998
3999 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004000 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12004001
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004002 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes280ba2c2015-06-12 11:16:41 +12004003
Cody Northropd2ad0342015-08-05 11:15:02 -06004004 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes280ba2c2015-06-12 11:16:41 +12004005 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
4006 FAIL() << "Incorrect error: " << msgString;
4007 }
4008}
Chris Forbes8f68b562015-05-25 11:13:32 +12004009
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004010/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
4011 * rejects it. */
4012
4013TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
4014{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004015 VkFlags msgFlags;
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004016 std::string msgString;
4017 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004018
4019 char const *vsSource =
4020 "#version 140\n"
4021 "#extension GL_ARB_separate_shader_objects: require\n"
4022 "#extension GL_ARB_shading_language_420pack: require\n"
4023 "\n"
4024 "void main(){\n"
4025 " gl_Position = vec4(1);\n"
4026 "}\n";
4027 char const *fsSource =
4028 "#version 140\n"
4029 "#extension GL_ARB_separate_shader_objects: require\n"
4030 "#extension GL_ARB_shading_language_420pack: require\n"
4031 "\n"
4032 "void main(){\n"
4033 "}\n";
4034
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004035 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4036 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004037
4038 VkPipelineObj pipe(m_device);
4039 pipe.AddShader(&vs);
4040 pipe.AddShader(&fs);
4041
Chia-I Wu08accc62015-07-07 11:50:03 +08004042 /* set up CB 0, not written */
4043 pipe.AddColorAttachment();
4044 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004045
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004046 VkDescriptorSetObj descriptorSet(m_device);
4047 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06004048 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004049
4050 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004051 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004052
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004053 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004054
Cody Northropd2ad0342015-08-05 11:15:02 -06004055 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes4d6d1e52015-05-25 11:13:40 +12004056 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
4057 FAIL() << "Incorrect error: " << msgString;
4058 }
4059}
4060
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004061TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
4062{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004063 VkFlags msgFlags;
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004064 std::string msgString;
4065 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004066
4067 char const *vsSource =
4068 "#version 140\n"
4069 "#extension GL_ARB_separate_shader_objects: require\n"
4070 "#extension GL_ARB_shading_language_420pack: require\n"
4071 "\n"
4072 "void main(){\n"
4073 " gl_Position = vec4(1);\n"
4074 "}\n";
4075 char const *fsSource =
4076 "#version 140\n"
4077 "#extension GL_ARB_separate_shader_objects: require\n"
4078 "#extension GL_ARB_shading_language_420pack: require\n"
4079 "\n"
4080 "layout(location=0) out vec4 x;\n"
4081 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4082 "void main(){\n"
4083 " x = vec4(1);\n"
4084 " y = vec4(1);\n"
4085 "}\n";
4086
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004087 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4088 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004089
4090 VkPipelineObj pipe(m_device);
4091 pipe.AddShader(&vs);
4092 pipe.AddShader(&fs);
4093
Chia-I Wu08accc62015-07-07 11:50:03 +08004094 /* set up CB 0, not written */
4095 pipe.AddColorAttachment();
4096 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004097 /* FS writes CB 1, but we don't configure it */
4098
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004099 VkDescriptorSetObj descriptorSet(m_device);
4100 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06004101 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004102
4103 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004104 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004105
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004106 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004107
Cody Northropd2ad0342015-08-05 11:15:02 -06004108 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004109 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
4110 FAIL() << "Incorrect warning: " << msgString;
4111 }
4112}
4113
Chris Forbesa36d69e2015-05-25 11:13:44 +12004114TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4115{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004116 VkFlags msgFlags;
Chris Forbesa36d69e2015-05-25 11:13:44 +12004117 std::string msgString;
4118 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004119
4120 char const *vsSource =
4121 "#version 140\n"
4122 "#extension GL_ARB_separate_shader_objects: require\n"
4123 "#extension GL_ARB_shading_language_420pack: require\n"
4124 "\n"
4125 "void main(){\n"
4126 " gl_Position = vec4(1);\n"
4127 "}\n";
4128 char const *fsSource =
4129 "#version 140\n"
4130 "#extension GL_ARB_separate_shader_objects: require\n"
4131 "#extension GL_ARB_shading_language_420pack: require\n"
4132 "\n"
4133 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4134 "void main(){\n"
4135 " x = ivec4(1);\n"
4136 "}\n";
4137
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004138 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4139 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004140
4141 VkPipelineObj pipe(m_device);
4142 pipe.AddShader(&vs);
4143 pipe.AddShader(&fs);
4144
Chia-I Wu08accc62015-07-07 11:50:03 +08004145 /* set up CB 0; type is UNORM by default */
4146 pipe.AddColorAttachment();
4147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004148
Chris Forbesa36d69e2015-05-25 11:13:44 +12004149 VkDescriptorSetObj descriptorSet(m_device);
4150 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06004151 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004152
4153 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004154 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004155
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004156 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004157
Cody Northropd2ad0342015-08-05 11:15:02 -06004158 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa36d69e2015-05-25 11:13:44 +12004159 if (!strstr(msgString.c_str(),"does not match FS output type")) {
4160 FAIL() << "Incorrect error: " << msgString;
4161 }
4162}
Chris Forbes7b1b8932015-06-05 14:43:36 +12004163
Chris Forbes556c76c2015-08-14 12:04:59 +12004164TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4165{
4166 VkFlags msgFlags;
4167 std::string msgString;
4168 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12004169
4170 char const *vsSource =
4171 "#version 140\n"
4172 "#extension GL_ARB_separate_shader_objects: require\n"
4173 "#extension GL_ARB_shading_language_420pack: require\n"
4174 "\n"
4175 "void main(){\n"
4176 " gl_Position = vec4(1);\n"
4177 "}\n";
4178 char const *fsSource =
4179 "#version 140\n"
4180 "#extension GL_ARB_separate_shader_objects: require\n"
4181 "#extension GL_ARB_shading_language_420pack: require\n"
4182 "\n"
4183 "layout(location=0) out vec4 x;\n"
4184 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4185 "void main(){\n"
4186 " x = vec4(bar.y);\n"
4187 "}\n";
4188
4189 m_errorMonitor->ClearState();
4190
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004191 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4192 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12004193
4194
4195 VkPipelineObj pipe(m_device);
4196 pipe.AddShader(&vs);
4197 pipe.AddShader(&fs);
4198
4199 /* set up CB 0; type is UNORM by default */
4200 pipe.AddColorAttachment();
4201 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4202
4203 VkDescriptorSetObj descriptorSet(m_device);
4204 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
4205
4206 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4207
4208 /* should have generated an error -- pipeline layout does not
4209 * provide a uniform buffer in 0.0
4210 */
4211 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -06004212 ASSERT_TRUE((msgFlags & VK_DBG_REPORT_ERROR_BIT) == VK_DBG_REPORT_ERROR_BIT);
Chris Forbes556c76c2015-08-14 12:04:59 +12004213 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
4214 FAIL() << "Incorrect error: " << msgString;
4215 }
4216}
4217
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004218#endif // SHADER_CHECKER_TESTS
4219
4220#if DEVICE_LIMITS_TESTS
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004221TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4222{
4223 VkFlags msgFlags;
4224 std::string msgString;
4225
4226 ASSERT_NO_FATAL_FAILURE(InitState());
4227 m_errorMonitor->ClearState();
4228
4229 // Create an image
4230 VkImage image;
4231
4232 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4233 const int32_t tex_width = 32;
4234 const int32_t tex_height = 32;
4235
4236 VkImageCreateInfo image_create_info = {};
4237 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4238 image_create_info.pNext = NULL;
4239 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4240 image_create_info.format = tex_format;
4241 image_create_info.extent.width = tex_width;
4242 image_create_info.extent.height = tex_height;
4243 image_create_info.extent.depth = 1;
4244 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004245 image_create_info.arrayLayers = 1;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004246 image_create_info.samples = 1;
4247 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4248 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4249 image_create_info.flags = 0;
4250
4251 // Introduce error by sending down a bogus width extent
4252 image_create_info.extent.width = 65536;
4253 vkCreateImage(m_device->device(), &image_create_info, &image);
4254
4255 msgFlags = m_errorMonitor->GetState(&msgString);
4256 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4257 "with extents outside the queried limits";
4258 if (!strstr(msgString.c_str(),"CreateImage extents exceed allowable limits for format")) {
4259 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4260 }
4261}
4262
4263TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4264{
4265 VkFlags msgFlags;
4266 std::string msgString;
4267
4268 ASSERT_NO_FATAL_FAILURE(InitState());
4269 m_errorMonitor->ClearState();
4270
4271 // Create an image
4272 VkImage image;
4273
4274 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4275 const int32_t tex_width = 32;
4276 const int32_t tex_height = 32;
4277
4278 VkImageCreateInfo image_create_info = {};
4279 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4280 image_create_info.pNext = NULL;
4281 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4282 image_create_info.format = tex_format;
4283 image_create_info.extent.width = tex_width;
4284 image_create_info.extent.height = tex_height;
4285 image_create_info.extent.depth = 1;
4286 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004287 image_create_info.arrayLayers = 1;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004288 image_create_info.samples = 1;
4289 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4290 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4291 image_create_info.flags = 0;
4292
4293 // Introduce error by sending down individually allowable values that result in a surface size
4294 // exceeding the device maximum
4295 image_create_info.extent.width = 8192;
4296 image_create_info.extent.height = 8192;
4297 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004298 image_create_info.arrayLayers = 4;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004299 image_create_info.samples = 2;
4300 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
4301 vkCreateImage(m_device->device(), &image_create_info, &image);
4302
4303 msgFlags = m_errorMonitor->GetState(&msgString);
4304 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4305 "with resource size exceeding queried limit";
4306 if (!strstr(msgString.c_str(),"CreateImage resource size exceeds allowable maximum")) {
4307 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4308 }
4309}
4310
Mike Stroyana3082432015-09-25 13:39:21 -06004311TEST_F(VkLayerTest, UpdateBufferAlignment)
4312{
4313 VkFlags msgFlags;
4314 std::string msgString;
4315 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4316
4317 ASSERT_NO_FATAL_FAILURE(InitState());
4318
4319 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4320 vk_testing::Buffer buffer;
4321 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4322
4323 BeginCommandBuffer();
4324 // Introduce failure by using offset that is not multiple of 4
4325 m_cmdBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
4326 msgFlags = m_errorMonitor->GetState(&msgString);
4327 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad offset";
4328 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4329 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4330 }
4331 // Introduce failure by using size that is not multiple of 4
4332 m_cmdBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
4333 msgFlags = m_errorMonitor->GetState(&msgString);
4334 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad size";
4335 if (!strstr(msgString.c_str(),"dataSize, is not a multiple of 4")) {
4336 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4337 }
4338 EndCommandBuffer();
4339}
4340
4341TEST_F(VkLayerTest, FillBufferAlignment)
4342{
4343 VkFlags msgFlags;
4344 std::string msgString;
4345
4346 ASSERT_NO_FATAL_FAILURE(InitState());
4347
4348 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4349 vk_testing::Buffer buffer;
4350 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4351
4352 BeginCommandBuffer();
4353 // Introduce failure by using offset that is not multiple of 4
4354 m_cmdBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
4355 msgFlags = m_errorMonitor->GetState(&msgString);
4356 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad offset";
4357 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4358 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4359 }
4360 // Introduce failure by using size that is not multiple of 4
4361 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
4362 msgFlags = m_errorMonitor->GetState(&msgString);
4363 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad size";
4364 if (!strstr(msgString.c_str(),"fillSize, is not a multiple of 4")) {
4365 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize fillSize, is not a multiple of 4'";
4366 }
4367 EndCommandBuffer();
4368}
4369
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004370#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12004371
Tobin Ehliscde08892015-09-22 10:11:37 -06004372#if IMAGE_TESTS
4373TEST_F(VkLayerTest, InvalidImageView)
4374{
4375 VkFlags msgFlags;
4376 std::string msgString;
4377 VkResult err;
4378
4379 ASSERT_NO_FATAL_FAILURE(InitState());
4380 m_errorMonitor->ClearState();
4381
Mike Stroyana3082432015-09-25 13:39:21 -06004382 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehliscde08892015-09-22 10:11:37 -06004383 VkImage image;
4384
4385 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4386 const int32_t tex_width = 32;
4387 const int32_t tex_height = 32;
4388
4389 VkImageCreateInfo image_create_info = {};
4390 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4391 image_create_info.pNext = NULL;
4392 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4393 image_create_info.format = tex_format;
4394 image_create_info.extent.width = tex_width;
4395 image_create_info.extent.height = tex_height;
4396 image_create_info.extent.depth = 1;
4397 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004398 image_create_info.arrayLayers = 1;
Tobin Ehliscde08892015-09-22 10:11:37 -06004399 image_create_info.samples = 1;
4400 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4401 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4402 image_create_info.flags = 0;
4403
4404 err = vkCreateImage(m_device->device(), &image_create_info, &image);
4405 ASSERT_VK_SUCCESS(err);
4406
4407 VkImageViewCreateInfo image_view_create_info = {};
4408 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4409 image_view_create_info.image = image;
4410 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4411 image_view_create_info.format = tex_format;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004412 image_view_create_info.subresourceRange.numLayers = 1;
Tobin Ehliscde08892015-09-22 10:11:37 -06004413 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004414 image_view_create_info.subresourceRange.numLevels = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004415 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06004416
4417 VkImageView view;
4418 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
4419
4420 msgFlags = m_errorMonitor->GetState(&msgString);
4421 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an invalid ImageView";
4422 if (!strstr(msgString.c_str(),"vkCreateImageView called with baseMipLevel 10 ")) {
Mike Stroyana3082432015-09-25 13:39:21 -06004423 FAIL() << "Error received was not 'vkCreateImageView called with baseMipLevel 10...' but instead '" << msgString.c_str() << "'";
Tobin Ehliscde08892015-09-22 10:11:37 -06004424 }
4425}
Mike Stroyana3082432015-09-25 13:39:21 -06004426
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06004427TEST_F(VkLayerTest, InvalidImageViewAspect)
4428{
4429 VkFlags msgFlags;
4430 std::string msgString;
4431 VkResult err;
4432
4433 ASSERT_NO_FATAL_FAILURE(InitState());
4434 m_errorMonitor->ClearState();
4435
4436 // Create an image and try to create a view with an invalid aspectMask
4437 VkImage image;
4438
4439 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4440 const int32_t tex_width = 32;
4441 const int32_t tex_height = 32;
4442
4443 VkImageCreateInfo image_create_info = {};
4444 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4445 image_create_info.pNext = NULL;
4446 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4447 image_create_info.format = tex_format;
4448 image_create_info.extent.width = tex_width;
4449 image_create_info.extent.height = tex_height;
4450 image_create_info.extent.depth = 1;
4451 image_create_info.mipLevels = 1;
4452 image_create_info.samples = 1;
4453 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4454 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4455 image_create_info.flags = 0;
4456
4457 err = vkCreateImage(m_device->device(), &image_create_info, &image);
4458 ASSERT_VK_SUCCESS(err);
4459
4460 VkImageViewCreateInfo image_view_create_info = {};
4461 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4462 image_view_create_info.image = image;
4463 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4464 image_view_create_info.format = tex_format;
4465 image_view_create_info.subresourceRange.baseMipLevel = 0;
4466 image_view_create_info.subresourceRange.numLevels = 1;
4467 // Cause an error by setting an invalid image aspect
4468 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
4469
4470 VkImageView view;
4471 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
4472
4473 msgFlags = m_errorMonitor->GetState(&msgString);
4474 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error when specifying an invalid ImageView aspect";
4475 if (!strstr(msgString.c_str(),"vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set")) {
4476 FAIL() << "Error received was not 'VkCreateImageView: Color image formats must have ...' but instead '" << msgString.c_str() << "'";
4477 }
4478}
4479
Mike Stroyana3082432015-09-25 13:39:21 -06004480TEST_F(VkLayerTest, CopyImageTypeMismatch)
4481{
4482 VkFlags msgFlags;
4483 std::string msgString;
4484 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004485 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004486
4487 ASSERT_NO_FATAL_FAILURE(InitState());
4488 m_errorMonitor->ClearState();
4489
4490 // Create two images of different types and try to copy between them
4491 VkImage srcImage;
4492 VkImage destImage;
4493 VkDeviceMemory srcMem;
4494 VkDeviceMemory destMem;
4495 VkMemoryRequirements memReqs;
4496
4497 VkImageCreateInfo image_create_info = {};
4498 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4499 image_create_info.pNext = NULL;
4500 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4501 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4502 image_create_info.extent.width = 32;
4503 image_create_info.extent.height = 32;
4504 image_create_info.extent.depth = 1;
4505 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004506 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004507 image_create_info.samples = 1;
4508 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4509 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4510 image_create_info.flags = 0;
4511
4512 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4513 ASSERT_VK_SUCCESS(err);
4514
4515 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4516 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4517
4518 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4519 ASSERT_VK_SUCCESS(err);
4520
4521 // Allocate memory
4522 VkMemoryAllocInfo memAlloc = {};
4523 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4524 memAlloc.pNext = NULL;
4525 memAlloc.allocationSize = 0;
4526 memAlloc.memoryTypeIndex = 0;
4527
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004528 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004529 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004530 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4531 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004532 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4533 ASSERT_VK_SUCCESS(err);
4534
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004535 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004536 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004537 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06004538 ASSERT_VK_SUCCESS(err);
4539 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4540 ASSERT_VK_SUCCESS(err);
4541
4542 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4543 ASSERT_VK_SUCCESS(err);
4544 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4545 ASSERT_VK_SUCCESS(err);
4546
4547 BeginCommandBuffer();
4548 VkImageCopy copyRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004549 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004550 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004551 copyRegion.srcSubresource.baseArrayLayer = 0;
4552 copyRegion.srcSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004553 copyRegion.srcOffset.x = 0;
4554 copyRegion.srcOffset.y = 0;
4555 copyRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004556 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004557 copyRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004558 copyRegion.destSubresource.baseArrayLayer = 0;
4559 copyRegion.destSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004560 copyRegion.destOffset.x = 0;
4561 copyRegion.destOffset.y = 0;
4562 copyRegion.destOffset.z = 0;
4563 copyRegion.extent.width = 1;
4564 copyRegion.extent.height = 1;
4565 copyRegion.extent.depth = 1;
4566 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4567 EndCommandBuffer();
4568
4569 msgFlags = m_errorMonitor->GetState(&msgString);
4570 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4571 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4572 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4573 }
4574
4575 vkDestroyImage(m_device->device(), srcImage);
4576 vkDestroyImage(m_device->device(), destImage);
4577 vkFreeMemory(m_device->device(), srcMem);
4578 vkFreeMemory(m_device->device(), destMem);
4579}
4580
4581TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
4582{
4583 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
4584}
4585
4586TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
4587{
4588 VkFlags msgFlags;
4589 std::string msgString;
4590 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004591 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004592
4593 ASSERT_NO_FATAL_FAILURE(InitState());
4594 m_errorMonitor->ClearState();
4595
4596 // Create two images of different types and try to copy between them
4597 VkImage srcImage;
4598 VkImage destImage;
4599 VkDeviceMemory srcMem;
4600 VkDeviceMemory destMem;
4601 VkMemoryRequirements memReqs;
4602
4603 VkImageCreateInfo image_create_info = {};
4604 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4605 image_create_info.pNext = NULL;
4606 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4607 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4608 image_create_info.extent.width = 32;
4609 image_create_info.extent.height = 32;
4610 image_create_info.extent.depth = 1;
4611 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004612 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004613 image_create_info.samples = 1;
4614 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4615 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4616 image_create_info.flags = 0;
4617
4618 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4619 ASSERT_VK_SUCCESS(err);
4620
4621 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4622 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4623
4624 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4625 ASSERT_VK_SUCCESS(err);
4626
4627 // Allocate memory
4628 VkMemoryAllocInfo memAlloc = {};
4629 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4630 memAlloc.pNext = NULL;
4631 memAlloc.allocationSize = 0;
4632 memAlloc.memoryTypeIndex = 0;
4633
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004634 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004635 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004636 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4637 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004638 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4639 ASSERT_VK_SUCCESS(err);
4640
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004641 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004642 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004643 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4644 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004645 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4646 ASSERT_VK_SUCCESS(err);
4647
4648 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4649 ASSERT_VK_SUCCESS(err);
4650 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4651 ASSERT_VK_SUCCESS(err);
4652
4653 BeginCommandBuffer();
4654 VkImageCopy copyRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004655 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004656 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004657 copyRegion.srcSubresource.baseArrayLayer = 0;
4658 copyRegion.srcSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004659 copyRegion.srcOffset.x = 0;
4660 copyRegion.srcOffset.y = 0;
4661 copyRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004662 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004663 copyRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004664 copyRegion.destSubresource.baseArrayLayer = 0;
4665 copyRegion.destSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004666 copyRegion.destOffset.x = 0;
4667 copyRegion.destOffset.y = 0;
4668 copyRegion.destOffset.z = 0;
4669 copyRegion.extent.width = 1;
4670 copyRegion.extent.height = 1;
4671 copyRegion.extent.depth = 1;
4672 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4673 EndCommandBuffer();
4674
4675 msgFlags = m_errorMonitor->GetState(&msgString);
4676 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4677 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4678 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4679 }
4680
4681 vkDestroyImage(m_device->device(), srcImage);
4682 vkDestroyImage(m_device->device(), destImage);
4683 vkFreeMemory(m_device->device(), srcMem);
4684 vkFreeMemory(m_device->device(), destMem);
4685}
4686
4687TEST_F(VkLayerTest, ResolveImageLowSampleCount)
4688{
4689 VkFlags msgFlags;
4690 std::string msgString;
4691 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004692 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004693
4694 ASSERT_NO_FATAL_FAILURE(InitState());
4695 m_errorMonitor->ClearState();
4696
4697 // Create two images of sample count 1 and try to Resolve between them
4698 VkImage srcImage;
4699 VkImage destImage;
4700 VkDeviceMemory srcMem;
4701 VkDeviceMemory destMem;
4702 VkMemoryRequirements memReqs;
4703
4704 VkImageCreateInfo image_create_info = {};
4705 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4706 image_create_info.pNext = NULL;
4707 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4708 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4709 image_create_info.extent.width = 32;
4710 image_create_info.extent.height = 1;
4711 image_create_info.extent.depth = 1;
4712 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004713 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004714 image_create_info.samples = 1;
4715 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4716 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4717 image_create_info.flags = 0;
4718
4719 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4720 ASSERT_VK_SUCCESS(err);
4721
4722 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4723 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4724
4725 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4726 ASSERT_VK_SUCCESS(err);
4727
4728 // Allocate memory
4729 VkMemoryAllocInfo memAlloc = {};
4730 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4731 memAlloc.pNext = NULL;
4732 memAlloc.allocationSize = 0;
4733 memAlloc.memoryTypeIndex = 0;
4734
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004735 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004736 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004737 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4738 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004739 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4740 ASSERT_VK_SUCCESS(err);
4741
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004742 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004743 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004744 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4745 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004746 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4747 ASSERT_VK_SUCCESS(err);
4748
4749 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4750 ASSERT_VK_SUCCESS(err);
4751 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4752 ASSERT_VK_SUCCESS(err);
4753
4754 BeginCommandBuffer();
4755 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4756 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4757 //VK_IMAGE_LAYOUT_GENERAL = 1,
4758 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004759 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004760 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004761 resolveRegion.srcSubresource.baseArrayLayer = 0;
4762 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004763 resolveRegion.srcOffset.x = 0;
4764 resolveRegion.srcOffset.y = 0;
4765 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004766 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004767 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004768 resolveRegion.destSubresource.baseArrayLayer = 0;
4769 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004770 resolveRegion.destOffset.x = 0;
4771 resolveRegion.destOffset.y = 0;
4772 resolveRegion.destOffset.z = 0;
4773 resolveRegion.extent.width = 1;
4774 resolveRegion.extent.height = 1;
4775 resolveRegion.extent.depth = 1;
4776 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4777 EndCommandBuffer();
4778
4779 msgFlags = m_errorMonitor->GetState(&msgString);
4780 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4781 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with source sample count less than 2.")) {
4782 FAIL() << "Error received was not 'vkCmdResolveImage called with source sample count less than 2.' but instead '" << msgString.c_str() << "'";
4783 }
4784
4785 vkDestroyImage(m_device->device(), srcImage);
4786 vkDestroyImage(m_device->device(), destImage);
4787 vkFreeMemory(m_device->device(), srcMem);
4788 vkFreeMemory(m_device->device(), destMem);
4789}
4790
4791TEST_F(VkLayerTest, ResolveImageHighSampleCount)
4792{
4793 VkFlags msgFlags;
4794 std::string msgString;
4795 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004796 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004797
4798 ASSERT_NO_FATAL_FAILURE(InitState());
4799 m_errorMonitor->ClearState();
4800
4801 // Create two images of sample count 2 and try to Resolve between them
4802 VkImage srcImage;
4803 VkImage destImage;
4804 VkDeviceMemory srcMem;
4805 VkDeviceMemory destMem;
4806 VkMemoryRequirements memReqs;
4807
4808 VkImageCreateInfo image_create_info = {};
4809 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4810 image_create_info.pNext = NULL;
4811 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4812 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4813 image_create_info.extent.width = 32;
4814 image_create_info.extent.height = 1;
4815 image_create_info.extent.depth = 1;
4816 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004817 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004818 image_create_info.samples = 2;
4819 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4820 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4821 image_create_info.flags = 0;
4822
4823 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4824 ASSERT_VK_SUCCESS(err);
4825
4826 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4827 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4828
4829 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4830 ASSERT_VK_SUCCESS(err);
4831
4832 // Allocate memory
4833 VkMemoryAllocInfo memAlloc = {};
4834 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4835 memAlloc.pNext = NULL;
4836 memAlloc.allocationSize = 0;
4837 memAlloc.memoryTypeIndex = 0;
4838
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004839 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004840 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004841 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4842 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004843 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4844 ASSERT_VK_SUCCESS(err);
4845
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004846 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004847 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004848 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4849 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004850 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4851 ASSERT_VK_SUCCESS(err);
4852
4853 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4854 ASSERT_VK_SUCCESS(err);
4855 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4856 ASSERT_VK_SUCCESS(err);
4857
4858 BeginCommandBuffer();
4859 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4860 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4861 //VK_IMAGE_LAYOUT_GENERAL = 1,
4862 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004863 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004864 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004865 resolveRegion.srcSubresource.baseArrayLayer = 0;
4866 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004867 resolveRegion.srcOffset.x = 0;
4868 resolveRegion.srcOffset.y = 0;
4869 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004870 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004871 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004872 resolveRegion.destSubresource.baseArrayLayer = 0;
4873 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004874 resolveRegion.destOffset.x = 0;
4875 resolveRegion.destOffset.y = 0;
4876 resolveRegion.destOffset.z = 0;
4877 resolveRegion.extent.width = 1;
4878 resolveRegion.extent.height = 1;
4879 resolveRegion.extent.depth = 1;
4880 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4881 EndCommandBuffer();
4882
4883 msgFlags = m_errorMonitor->GetState(&msgString);
4884 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4885 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with dest sample count greater than 1.")) {
4886 FAIL() << "Error received was not 'vkCmdResolveImage called with dest sample count greater than 1.' but instead '" << msgString.c_str() << "'";
4887 }
4888
4889 vkDestroyImage(m_device->device(), srcImage);
4890 vkDestroyImage(m_device->device(), destImage);
4891 vkFreeMemory(m_device->device(), srcMem);
4892 vkFreeMemory(m_device->device(), destMem);
4893}
4894
4895TEST_F(VkLayerTest, ResolveImageFormatMismatch)
4896{
4897 VkFlags msgFlags;
4898 std::string msgString;
4899 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004900 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004901
4902 ASSERT_NO_FATAL_FAILURE(InitState());
4903 m_errorMonitor->ClearState();
4904
4905 // Create two images of different types and try to copy between them
4906 VkImage srcImage;
4907 VkImage destImage;
4908 VkDeviceMemory srcMem;
4909 VkDeviceMemory destMem;
4910 VkMemoryRequirements memReqs;
4911
4912 VkImageCreateInfo image_create_info = {};
4913 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4914 image_create_info.pNext = NULL;
4915 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4916 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4917 image_create_info.extent.width = 32;
4918 image_create_info.extent.height = 1;
4919 image_create_info.extent.depth = 1;
4920 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004921 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004922 image_create_info.samples = 2;
4923 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4924 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4925 image_create_info.flags = 0;
4926
4927 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4928 ASSERT_VK_SUCCESS(err);
4929
4930 image_create_info.format = VK_FORMAT_B8G8R8_SRGB;
4931 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4932 image_create_info.samples = 1;
4933
4934 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4935 ASSERT_VK_SUCCESS(err);
4936
4937 // Allocate memory
4938 VkMemoryAllocInfo memAlloc = {};
4939 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4940 memAlloc.pNext = NULL;
4941 memAlloc.allocationSize = 0;
4942 memAlloc.memoryTypeIndex = 0;
4943
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004944 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004945 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004946 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4947 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004948 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4949 ASSERT_VK_SUCCESS(err);
4950
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004951 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004952 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004953 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4954 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004955 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4956 ASSERT_VK_SUCCESS(err);
4957
4958 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4959 ASSERT_VK_SUCCESS(err);
4960 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4961 ASSERT_VK_SUCCESS(err);
4962
4963 BeginCommandBuffer();
4964 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4965 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4966 //VK_IMAGE_LAYOUT_GENERAL = 1,
4967 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004968 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004969 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004970 resolveRegion.srcSubresource.baseArrayLayer = 0;
4971 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004972 resolveRegion.srcOffset.x = 0;
4973 resolveRegion.srcOffset.y = 0;
4974 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004975 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004976 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06004977 resolveRegion.destSubresource.baseArrayLayer = 0;
4978 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06004979 resolveRegion.destOffset.x = 0;
4980 resolveRegion.destOffset.y = 0;
4981 resolveRegion.destOffset.z = 0;
4982 resolveRegion.extent.width = 1;
4983 resolveRegion.extent.height = 1;
4984 resolveRegion.extent.depth = 1;
4985 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4986 EndCommandBuffer();
4987
4988 msgFlags = m_errorMonitor->GetState(&msgString);
4989 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage format mismatch";
4990 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest formats.")) {
4991 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest formats.' but instead '" << msgString.c_str() << "'";
4992 }
4993
4994 vkDestroyImage(m_device->device(), srcImage);
4995 vkDestroyImage(m_device->device(), destImage);
4996 vkFreeMemory(m_device->device(), srcMem);
4997 vkFreeMemory(m_device->device(), destMem);
4998}
4999
5000TEST_F(VkLayerTest, ResolveImageTypeMismatch)
5001{
5002 VkFlags msgFlags;
5003 std::string msgString;
5004 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005005 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005006
5007 ASSERT_NO_FATAL_FAILURE(InitState());
5008 m_errorMonitor->ClearState();
5009
5010 // Create two images of different types and try to copy between them
5011 VkImage srcImage;
5012 VkImage destImage;
5013 VkDeviceMemory srcMem;
5014 VkDeviceMemory destMem;
5015 VkMemoryRequirements memReqs;
5016
5017 VkImageCreateInfo image_create_info = {};
5018 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5019 image_create_info.pNext = NULL;
5020 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5021 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5022 image_create_info.extent.width = 32;
5023 image_create_info.extent.height = 1;
5024 image_create_info.extent.depth = 1;
5025 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005026 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06005027 image_create_info.samples = 2;
5028 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5029 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
5030 image_create_info.flags = 0;
5031
5032 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
5033 ASSERT_VK_SUCCESS(err);
5034
5035 image_create_info.imageType = VK_IMAGE_TYPE_1D;
5036 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
5037 image_create_info.samples = 1;
5038
5039 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
5040 ASSERT_VK_SUCCESS(err);
5041
5042 // Allocate memory
5043 VkMemoryAllocInfo memAlloc = {};
5044 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5045 memAlloc.pNext = NULL;
5046 memAlloc.allocationSize = 0;
5047 memAlloc.memoryTypeIndex = 0;
5048
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005049 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005050 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005051 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5052 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06005053 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
5054 ASSERT_VK_SUCCESS(err);
5055
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005056 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005057 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005058 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5059 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06005060 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
5061 ASSERT_VK_SUCCESS(err);
5062
5063 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5064 ASSERT_VK_SUCCESS(err);
5065 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
5066 ASSERT_VK_SUCCESS(err);
5067
5068 BeginCommandBuffer();
5069 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5070 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5071 //VK_IMAGE_LAYOUT_GENERAL = 1,
5072 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06005073 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005074 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005075 resolveRegion.srcSubresource.baseArrayLayer = 0;
5076 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005077 resolveRegion.srcOffset.x = 0;
5078 resolveRegion.srcOffset.y = 0;
5079 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06005080 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005081 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005082 resolveRegion.destSubresource.baseArrayLayer = 0;
5083 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005084 resolveRegion.destOffset.x = 0;
5085 resolveRegion.destOffset.y = 0;
5086 resolveRegion.destOffset.z = 0;
5087 resolveRegion.extent.width = 1;
5088 resolveRegion.extent.height = 1;
5089 resolveRegion.extent.depth = 1;
5090 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
5091 EndCommandBuffer();
5092
5093 msgFlags = m_errorMonitor->GetState(&msgString);
5094 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
5095 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest image types.")) {
5096 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest image types.' but instead '" << msgString.c_str() << "'";
5097 }
5098
5099 vkDestroyImage(m_device->device(), srcImage);
5100 vkDestroyImage(m_device->device(), destImage);
5101 vkFreeMemory(m_device->device(), srcMem);
5102 vkFreeMemory(m_device->device(), destMem);
5103}
Tobin Ehliscde08892015-09-22 10:11:37 -06005104#endif // IMAGE_TESTS
5105
Tony Barbour300a6082015-04-07 13:44:53 -06005106int main(int argc, char **argv) {
5107 int result;
5108
5109 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06005110 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06005111
5112 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
5113
5114 result = RUN_ALL_TESTS();
5115
Tony Barbour6918cd52015-04-09 12:58:51 -06005116 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06005117 return result;
5118}