blob: 897134bc4c0d85a11b0cac99b0b35d6463cd9e5d [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 = {};
477 info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT | VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
478 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.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
856 ds_pool_ci.maxSets = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600857 ds_pool_ci.count = 1;
858 ds_pool_ci.pTypeCount = &ds_type_count;
859
860 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -0600861 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600862 ASSERT_VK_SUCCESS(err);
863
864 VkDescriptorSetLayoutBinding dsl_binding = {};
865 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
866 dsl_binding.arraySize = 1;
867 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
868 dsl_binding.pImmutableSamplers = NULL;
869
870 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
871 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
872 ds_layout_ci.pNext = NULL;
873 ds_layout_ci.count = 1;
874 ds_layout_ci.pBinding = &dsl_binding;
875
876 VkDescriptorSetLayout ds_layout;
877 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
878 ASSERT_VK_SUCCESS(err);
879
880 VkDescriptorSet descriptorSet;
881 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
882 ASSERT_VK_SUCCESS(err);
883
884 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
885 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
886 pipeline_layout_ci.pNext = NULL;
887 pipeline_layout_ci.descriptorSetCount = 1;
888 pipeline_layout_ci.pSetLayouts = &ds_layout;
889
890 VkPipelineLayout pipeline_layout;
891 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
892 ASSERT_VK_SUCCESS(err);
893
894 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
895
896 BeginCommandBuffer();
897 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
898
899 msgFlags = m_errorMonitor->GetState(&msgString);
900 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 -0600901 if (!strstr(msgString.c_str(),"Invalid VkPipeline Object ")) {
902 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be' but instead it was '" << msgString.c_str() << "'";
903 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600904
905 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -0600906 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
907 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlisec598302015-09-15 15:02:17 -0600908}
909
910TEST_F(VkLayerTest, BindInvalidMemory)
911{
912 VkFlags msgFlags;
913 std::string msgString;
914 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600915 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -0600916
917 ASSERT_NO_FATAL_FAILURE(InitState());
918 m_errorMonitor->ClearState();
919
920 // Create an image, allocate memory, free it, and then try to bind it
921 VkImage image;
922 VkDeviceMemory mem;
923 VkMemoryRequirements mem_reqs;
924
925 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
926 const int32_t tex_width = 32;
927 const int32_t tex_height = 32;
928
929 VkImageCreateInfo image_create_info = {};
930 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
931 image_create_info.pNext = NULL;
932 image_create_info.imageType = VK_IMAGE_TYPE_2D;
933 image_create_info.format = tex_format;
934 image_create_info.extent.width = tex_width;
935 image_create_info.extent.height = tex_height;
936 image_create_info.extent.depth = 1;
937 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600938 image_create_info.arrayLayers = 1;
Tobin Ehlisec598302015-09-15 15:02:17 -0600939 image_create_info.samples = 1;
940 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
941 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
942 image_create_info.flags = 0;
943
944 VkMemoryAllocInfo mem_alloc = {};
945 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
946 mem_alloc.pNext = NULL;
947 mem_alloc.allocationSize = 0;
948 mem_alloc.memoryTypeIndex = 0;
949
950 err = vkCreateImage(m_device->device(), &image_create_info, &image);
951 ASSERT_VK_SUCCESS(err);
952
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600953 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlisec598302015-09-15 15:02:17 -0600954 image,
955 &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -0600956
957 mem_alloc.allocationSize = mem_reqs.size;
958
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600959 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
960 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -0600961
962 // allocate memory
963 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
964 ASSERT_VK_SUCCESS(err);
965
966 // Introduce validation failure, free memory before binding
967 vkFreeMemory(m_device->device(), mem);
Tobin Ehlisec598302015-09-15 15:02:17 -0600968
969 // Try to bind free memory that has been freed
970 err = vkBindImageMemory(m_device->device(), image, mem, 0);
971 // This may very well return an error.
972 (void)err;
973
974 msgFlags = m_errorMonitor->GetState(&msgString);
975 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to bind a freed memory object";
976 if (!strstr(msgString.c_str(),"Invalid VkDeviceMemory Object ")) {
977 FAIL() << "Error received from BindInvalidMemory was not 'Invalid VkDeviceMemory Object 0x<handle>' but instead '" << msgString.c_str() << "'";
978 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600979
980 vkDestroyImage(m_device->device(), image);
Tobin Ehlisec598302015-09-15 15:02:17 -0600981}
982
983TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
984{
985 VkFlags msgFlags;
986 std::string msgString;
987 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600988 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -0600989
990 ASSERT_NO_FATAL_FAILURE(InitState());
991 m_errorMonitor->ClearState();
992
993 // Create an image object, allocate memory, destroy the object and then try to bind it
994 VkImage image;
995 VkDeviceMemory mem;
996 VkMemoryRequirements mem_reqs;
997
998 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
999 const int32_t tex_width = 32;
1000 const int32_t tex_height = 32;
1001
1002 VkImageCreateInfo image_create_info = {};
1003 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1004 image_create_info.pNext = NULL;
1005 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1006 image_create_info.format = tex_format;
1007 image_create_info.extent.width = tex_width;
1008 image_create_info.extent.height = tex_height;
1009 image_create_info.extent.depth = 1;
1010 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06001011 image_create_info.arrayLayers = 1;
Tobin Ehlisec598302015-09-15 15:02:17 -06001012 image_create_info.samples = 1;
1013 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1014 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1015 image_create_info.flags = 0;
1016
1017 VkMemoryAllocInfo mem_alloc = {};
1018 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1019 mem_alloc.pNext = NULL;
1020 mem_alloc.allocationSize = 0;
1021 mem_alloc.memoryTypeIndex = 0;
1022
1023 err = vkCreateImage(m_device->device(), &image_create_info, &image);
1024 ASSERT_VK_SUCCESS(err);
1025
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001026 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlisec598302015-09-15 15:02:17 -06001027 image,
1028 &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06001029
1030 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001031 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1032 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001033
1034 // Allocate memory
1035 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
1036 ASSERT_VK_SUCCESS(err);
1037
1038 // Introduce validation failure, destroy Image object before binding
1039 vkDestroyImage(m_device->device(), image);
1040 ASSERT_VK_SUCCESS(err);
1041
1042 // Now Try to bind memory to this destroyed object
1043 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1044 // This may very well return an error.
1045 (void) err;
1046
1047 msgFlags = m_errorMonitor->GetState(&msgString);
1048 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while binding memory to a destroyed object";
1049 if (!strstr(msgString.c_str(),"Invalid VkImage Object ")) {
1050 FAIL() << "Error received from BindMemoryToDestroyedObject was not 'Invalid VkImage Object 0x<handle>' but rather '" << msgString.c_str() << "'";
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001051 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001052
1053 vkFreeMemory(m_device->device(), mem);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001054}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001055#endif // OBJ_TRACKER_TESTS
1056
Tobin Ehlis0788f522015-05-26 16:11:58 -06001057#if DRAW_STATE_TESTS
Tobin Ehlis963a4042015-09-29 08:18:34 -06001058TEST_F(VkLayerTest, LineWidthStateNotBound)
1059{
1060 VkFlags msgFlags;
1061 std::string msgString;
1062 m_errorMonitor->ClearState();
1063 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1064
1065 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1066
1067 msgFlags = m_errorMonitor->GetState(&msgString);
1068 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Line Width State Object";
1069 if (!strstr(msgString.c_str(),"Dynamic line width state not set for this command buffer")) {
1070 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic line width state not set for this command buffer'";
1071 }
1072}
1073
1074TEST_F(VkLayerTest, DepthBiasStateNotBound)
1075{
1076 VkFlags msgFlags;
1077 std::string msgString;
1078 m_errorMonitor->ClearState();
1079 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1080
1081 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1082
1083 msgFlags = m_errorMonitor->GetState(&msgString);
1084 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bias State Object";
1085 if (!strstr(msgString.c_str(),"Dynamic depth bias state not set for this command buffer")) {
1086 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bias state not set for this command buffer'";
1087 }
1088}
1089
1090TEST_F(VkLayerTest, ViewportStateNotBound)
1091{
1092 VkFlags msgFlags;
1093 std::string msgString;
1094 m_errorMonitor->ClearState();
1095 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1096
1097 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1098
1099 msgFlags = m_errorMonitor->GetState(&msgString);
1100 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 -06001101 // TODO : Viewport and scissor currently set as a pair in framework so scissor error masks viewport error
1102 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1103 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
Tobin Ehlis963a4042015-09-29 08:18:34 -06001104 }
1105}
1106
1107TEST_F(VkLayerTest, ScissorStateNotBound)
1108{
1109 VkFlags msgFlags;
1110 std::string msgString;
1111 m_errorMonitor->ClearState();
1112 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1113
1114 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1115
1116 msgFlags = m_errorMonitor->GetState(&msgString);
1117 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
1118 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1119 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
1120 }
1121}
1122
Tobin Ehlis963a4042015-09-29 08:18:34 -06001123TEST_F(VkLayerTest, BlendStateNotBound)
1124{
1125 VkFlags msgFlags;
1126 std::string msgString;
1127 m_errorMonitor->ClearState();
1128 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1129
1130 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1131
1132 msgFlags = m_errorMonitor->GetState(&msgString);
1133 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
1134 if (!strstr(msgString.c_str(),"Dynamic blend object state not set for this command buffer")) {
1135 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic blend object state not set for this command buffer'";
1136 }
1137}
1138
1139TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1140{
1141 VkFlags msgFlags;
1142 std::string msgString;
1143 m_errorMonitor->ClearState();
1144 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1145
1146 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1147
1148 msgFlags = m_errorMonitor->GetState(&msgString);
1149 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
1150 if (!strstr(msgString.c_str(),"Dynamic depth bounds state not set for this command buffer")) {
1151 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bounds state not set for this command buffer'";
1152 }
1153}
1154
1155TEST_F(VkLayerTest, StencilReadMaskNotSet)
1156{
1157 VkFlags msgFlags;
1158 std::string msgString;
1159 ASSERT_NO_FATAL_FAILURE(InitState());
1160 m_errorMonitor->ClearState();
1161 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1162
1163 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1164
1165 msgFlags = m_errorMonitor->GetState(&msgString);
1166 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Read Mask";
1167 if (!strstr(msgString.c_str(),"Dynamic stencil read mask state not set for this command buffer")) {
1168 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil read mask state not set for this command buffer'";
1169 }
1170}
1171
1172TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1173{
1174 VkFlags msgFlags;
1175 std::string msgString;
1176 ASSERT_NO_FATAL_FAILURE(InitState());
1177 m_errorMonitor->ClearState();
1178 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1179
1180 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1181
1182 msgFlags = m_errorMonitor->GetState(&msgString);
1183 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Write Mask";
1184 if (!strstr(msgString.c_str(),"Dynamic stencil write mask state not set for this command buffer")) {
1185 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil write mask state not set for this command buffer'";
1186 }
1187}
1188
1189TEST_F(VkLayerTest, StencilReferenceNotSet)
1190{
1191 VkFlags msgFlags;
1192 std::string msgString;
1193 m_errorMonitor->ClearState();
1194 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1195
1196 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1197
1198 msgFlags = m_errorMonitor->GetState(&msgString);
1199 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Reference";
1200 if (!strstr(msgString.c_str(),"Dynamic stencil reference state not set for this command buffer")) {
1201 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil reference state not set for this command buffer'";
1202 }
1203}
1204
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001205TEST_F(VkLayerTest, CmdBufferTwoSubmits)
1206{
1207 vk_testing::Fence testFence;
1208 VkFlags msgFlags;
1209 std::string msgString;
1210
1211 VkFenceCreateInfo fenceInfo = {};
1212 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1213 fenceInfo.pNext = NULL;
1214 fenceInfo.flags = 0;
1215
1216 ASSERT_NO_FATAL_FAILURE(InitState());
1217 ASSERT_NO_FATAL_FAILURE(InitViewport());
1218 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1219
1220 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set
1221 BeginCommandBuffer();
1222 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1223 EndCommandBuffer();
1224
1225 testFence.init(*m_device, fenceInfo);
1226
1227 // Bypass framework since it does the waits automatically
1228 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001229 VkSubmitInfo submit_info = {
1230 .waitSemCount = 0,
1231 .pWaitSemaphores = NULL,
1232 .cmdBufferCount = 1,
1233 .pCommandBuffers = &m_cmdBuffer->handle(),
1234 .signalSemCount = 0,
1235 .pSignalSemaphores = NULL
1236 };
1237 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001238 ASSERT_VK_SUCCESS( err );
1239
1240 m_errorMonitor->ClearState();
1241 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001242 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001243
1244 msgFlags = m_errorMonitor->GetState(&msgString);
1245 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";
Tobin Ehlisf1878c72015-08-18 14:24:32 -06001246 if (!strstr(msgString.c_str(),"was begun w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set, but has been submitted")) {
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001247 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set...'";
1248 }
1249}
1250
Tobin Ehlis502480b2015-06-24 15:53:07 -06001251TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001252{
1253 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001254 VkFlags msgFlags;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001255 std::string msgString;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001256 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001257
1258 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001260 m_errorMonitor->ClearState();
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001261
1262 VkDescriptorTypeCount ds_type_count = {};
1263 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1264 ds_type_count.count = 1;
1265
1266 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1267 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1268 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001269 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1270 ds_pool_ci.maxSets = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001271 ds_pool_ci.count = 1;
1272 ds_pool_ci.pTypeCount = &ds_type_count;
1273
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001274 VkDescriptorPool ds_pool;
1275 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001276 ASSERT_VK_SUCCESS(err);
1277
1278 VkDescriptorSetLayoutBinding dsl_binding = {};
1279 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1280 dsl_binding.arraySize = 1;
1281 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1282 dsl_binding.pImmutableSamplers = NULL;
1283
1284 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1285 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1286 ds_layout_ci.pNext = NULL;
1287 ds_layout_ci.count = 1;
1288 ds_layout_ci.pBinding = &dsl_binding;
1289
1290 VkDescriptorSetLayout ds_layout;
1291 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1292 ASSERT_VK_SUCCESS(err);
1293
1294 VkDescriptorSet descriptorSet;
1295 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1296 ASSERT_VK_SUCCESS(err);
1297 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1298 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1299 pipe_ms_state_ci.pNext = NULL;
1300 pipe_ms_state_ci.rasterSamples = 1;
1301 pipe_ms_state_ci.sampleShadingEnable = 0;
1302 pipe_ms_state_ci.minSampleShading = 1.0;
1303 pipe_ms_state_ci.pSampleMask = NULL;
1304
1305 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1306 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1307 pipeline_layout_ci.pNext = NULL;
1308 pipeline_layout_ci.descriptorSetCount = 1;
1309 pipeline_layout_ci.pSetLayouts = &ds_layout;
1310 VkPipelineLayout pipeline_layout;
1311
1312 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1313 ASSERT_VK_SUCCESS(err);
1314
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001315 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1316 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 -06001317 // but add it to be able to run on more devices
1318 VkPipelineObj pipe(m_device);
1319 pipe.AddShader(&vs);
1320 pipe.AddShader(&fs);
1321 pipe.SetMSAA(&pipe_ms_state_ci);
1322 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1323 m_errorMonitor->ClearState();
1324 // Calls CreateCommandBuffer
1325 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1326 VkCmdBufferBeginInfo cmd_buf_info = {};
1327 memset(&cmd_buf_info, 0, sizeof(VkCmdBufferBeginInfo));
1328 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1329 cmd_buf_info.pNext = NULL;
1330 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1331 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1332
1333 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1334 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001335 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001336 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 -06001337 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001338 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 -06001339 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001340
1341 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06001342 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1343 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001344}
1345
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001346TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1347{
1348 // Initiate Draw w/o a PSO bound
1349 VkFlags msgFlags;
1350 std::string msgString;
1351 VkResult err;
1352
1353 ASSERT_NO_FATAL_FAILURE(InitState());
1354 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1355 m_errorMonitor->ClearState();
1356
1357 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
1358 VkDescriptorTypeCount ds_type_count = {};
1359 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
1360 ds_type_count.count = 1;
1361
1362 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1363 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1364 ds_pool_ci.pNext = NULL;
1365 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1366 ds_pool_ci.maxSets = 1;
1367 ds_pool_ci.count = 1;
1368 ds_pool_ci.pTypeCount = &ds_type_count;
1369
1370 VkDescriptorPool ds_pool;
1371 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1372 ASSERT_VK_SUCCESS(err);
1373
1374 VkDescriptorSetLayoutBinding dsl_binding = {};
1375 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1376 dsl_binding.arraySize = 1;
1377 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1378 dsl_binding.pImmutableSamplers = NULL;
1379
1380 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1381 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1382 ds_layout_ci.pNext = NULL;
1383 ds_layout_ci.count = 1;
1384 ds_layout_ci.pBinding = &dsl_binding;
1385
1386 VkDescriptorSetLayout ds_layout;
1387 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1388 ASSERT_VK_SUCCESS(err);
1389
1390 VkDescriptorSet descriptorSet;
1391 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1392
1393 msgFlags = m_errorMonitor->GetState(&msgString);
1394 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after alloc descriptor from pool w/o requested type";
1395 if (!strstr(msgString.c_str(),"Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ")) {
1396 FAIL() << "Error received was not 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...' but rather '" << msgString.c_str() << "'";
1397 }
1398
1399 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1400 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1401}
1402
Tobin Ehlise735c692015-10-08 13:13:50 -06001403TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1404{
1405 VkFlags msgFlags;
1406 std::string msgString;
1407 VkResult err;
1408
1409 ASSERT_NO_FATAL_FAILURE(InitState());
1410 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1411 m_errorMonitor->ClearState();
1412
1413 VkDescriptorTypeCount ds_type_count = {};
1414 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1415 ds_type_count.count = 1;
1416
1417 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1418 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1419 ds_pool_ci.pNext = NULL;
1420 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT; // Can't free from ONE_SHOT Pool
1421 ds_pool_ci.maxSets = 1;
1422 ds_pool_ci.count = 1;
1423 ds_pool_ci.pTypeCount = &ds_type_count;
1424
1425 VkDescriptorPool ds_pool;
1426 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1427 ASSERT_VK_SUCCESS(err);
1428
1429 VkDescriptorSetLayoutBinding dsl_binding = {};
1430 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1431 dsl_binding.arraySize = 1;
1432 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1433 dsl_binding.pImmutableSamplers = NULL;
1434
1435 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1436 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1437 ds_layout_ci.pNext = NULL;
1438 ds_layout_ci.count = 1;
1439 ds_layout_ci.pBinding = &dsl_binding;
1440
1441 VkDescriptorSetLayout ds_layout;
1442 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1443 ASSERT_VK_SUCCESS(err);
1444
1445 VkDescriptorSet descriptorSet;
1446 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1447 ASSERT_VK_SUCCESS(err);
1448
1449 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1450 msgFlags = m_errorMonitor->GetState(&msgString);
1451 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after freeing descriptor from ONE_SHOT Pool";
1452 if (!strstr(msgString.c_str(),"It is invalid to call vkFreeDescriptorSets() with a pool created with usage type VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT.")) {
1453 FAIL() << "Error received was not 'It is invalid to call vkFreeDescriptorSets() with a pool created with...' but instead it was '" << msgString.c_str() << "'";
1454 }
1455
1456 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1457 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1458}
1459
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001460TEST_F(VkLayerTest, InvalidDescriptorPool)
1461{
1462 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1463 // The DS check for this is after driver has been called to validate DS internal data struct
1464 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001465/* VkFlags msgFlags;
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001466 std::string msgString;
1467 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1468 vkResetDescriptorPool(device(), badPool);
1469
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001470 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001471 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 -06001472 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1473 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1474 }*/
1475}
1476
1477TEST_F(VkLayerTest, InvalidDescriptorSet)
1478{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001479 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1480 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001481 // Create a valid cmd buffer
1482 // call vkCmdBindDescriptorSets w/ false DS
1483}
1484
1485TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1486{
1487 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1488 // The DS check for this is after driver has been called to validate DS internal data struct
1489}
1490
1491TEST_F(VkLayerTest, InvalidPipeline)
1492{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001493 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1494 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001495 // Create a valid cmd buffer
1496 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlis502480b2015-06-24 15:53:07 -06001497// VkFlags msgFlags;
1498// std::string msgString;
1499//
1500// ASSERT_NO_FATAL_FAILURE(InitState());
1501// m_errorMonitor->ClearState();
1502// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001503// BeginCommandBuffer();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001504// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1505// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1506// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001507// 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 -06001508// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1509// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1510// }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001511}
1512
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001513TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001514{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001515 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001516 VkFlags msgFlags;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001517 std::string msgString;
1518 VkResult err;
1519
1520 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06001521 ASSERT_NO_FATAL_FAILURE(InitViewport());
1522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001523 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06001524 VkDescriptorTypeCount ds_type_count = {};
1525 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1526 ds_type_count.count = 1;
1527
1528 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1529 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1530 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001531 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1532 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001533 ds_pool_ci.count = 1;
1534 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06001535
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001536 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001537 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001538 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001539
Tony Barboureb254902015-07-15 12:50:33 -06001540 VkDescriptorSetLayoutBinding dsl_binding = {};
1541 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1542 dsl_binding.arraySize = 1;
1543 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1544 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001545
Tony Barboureb254902015-07-15 12:50:33 -06001546 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1547 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1548 ds_layout_ci.pNext = NULL;
1549 ds_layout_ci.count = 1;
1550 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001551 VkDescriptorSetLayout ds_layout;
1552 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1553 ASSERT_VK_SUCCESS(err);
1554
1555 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001556 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001557 ASSERT_VK_SUCCESS(err);
1558
Tony Barboureb254902015-07-15 12:50:33 -06001559 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1560 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1561 pipeline_layout_ci.pNext = NULL;
1562 pipeline_layout_ci.descriptorSetCount = 1;
1563 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001564
1565 VkPipelineLayout pipeline_layout;
1566 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1567 ASSERT_VK_SUCCESS(err);
1568
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001569 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1570 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 -06001571 // but add it to be able to run on more devices
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001572
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001573 VkPipelineObj pipe(m_device);
1574 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06001575 pipe.AddShader(&fs);
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001576 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001577
1578 BeginCommandBuffer();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001579 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001580 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001581
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001582 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001583 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 -06001584 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1585 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1586 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001587
1588 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06001589 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1590 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001591}
1592
1593TEST_F(VkLayerTest, NoBeginCmdBuffer)
1594{
1595 VkFlags msgFlags;
1596 std::string msgString;
1597
1598 ASSERT_NO_FATAL_FAILURE(InitState());
1599 m_errorMonitor->ClearState();
Tony Barbourfe3351b2015-07-28 10:17:20 -06001600 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001601 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1602 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1603 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001604 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 -06001605 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1606 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1607 }
1608}
1609
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001610TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1611{
1612 VkFlags msgFlags;
1613 std::string msgString;
1614
1615 ASSERT_NO_FATAL_FAILURE(InitState());
1616 m_errorMonitor->ClearState();
1617
1618 // Calls CreateCommandBuffer
1619 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1620
1621 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northropb4569702015-08-04 17:35:57 -06001622 VkCmdBufferBeginInfo cmd_buf_info = {};
1623 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1624 cmd_buf_info.pNext = NULL;
1625 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1626 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1627 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1628 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1629
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001630
1631 // The error should be caught by validation of the BeginCommandBuffer call
1632 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1633
1634 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001635 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 -06001636 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1637 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1638 }
1639}
1640
1641TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1642{
1643 VkFlags msgFlags;
1644 std::string msgString;
1645 VkResult err;
1646 VkCmdBuffer draw_cmd;
1647 VkCmdPool cmd_pool;
1648
1649 ASSERT_NO_FATAL_FAILURE(InitState());
1650 m_errorMonitor->ClearState();
1651
Cody Northropb4569702015-08-04 17:35:57 -06001652 VkCmdBufferCreateInfo cmd = {};
1653 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1654 cmd.pNext = NULL;
1655 cmd.cmdPool = m_cmdPool;
1656 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1657 cmd.flags = 0;
1658
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001659 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06001660 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001661
1662 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northropb4569702015-08-04 17:35:57 -06001663 VkCmdBufferBeginInfo cmd_buf_info = {};
1664 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1665 cmd_buf_info.pNext = NULL;
1666 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1667 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001668
1669 // The error should be caught by validation of the BeginCommandBuffer call
1670 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1671
1672 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001673 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 -06001674 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1675 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1676 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001677 vkDestroyCommandBuffer(m_device->device(), draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001678}
1679
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001680TEST_F(VkLayerTest, InvalidPipelineCreateState)
1681{
1682 // Attempt to Create Gfx Pipeline w/o a VS
1683 VkFlags msgFlags;
1684 std::string msgString;
1685 VkResult err;
1686
1687 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001688 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001689 m_errorMonitor->ClearState();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001690
Tony Barboureb254902015-07-15 12:50:33 -06001691 VkDescriptorTypeCount ds_type_count = {};
1692 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1693 ds_type_count.count = 1;
1694
1695 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1696 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1697 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001698 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1699 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001700 ds_pool_ci.count = 1;
1701 ds_pool_ci.pTypeCount = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001702
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001703 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001704 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001705 ASSERT_VK_SUCCESS(err);
1706
Tony Barboureb254902015-07-15 12:50:33 -06001707 VkDescriptorSetLayoutBinding dsl_binding = {};
1708 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1709 dsl_binding.arraySize = 1;
1710 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1711 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001712
Tony Barboureb254902015-07-15 12:50:33 -06001713 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1714 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1715 ds_layout_ci.pNext = NULL;
1716 ds_layout_ci.count = 1;
1717 ds_layout_ci.pBinding = &dsl_binding;
1718
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001719 VkDescriptorSetLayout ds_layout;
1720 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1721 ASSERT_VK_SUCCESS(err);
1722
1723 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001724 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001725 ASSERT_VK_SUCCESS(err);
1726
Tony Barboureb254902015-07-15 12:50:33 -06001727 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1728 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tony Barboureb254902015-07-15 12:50:33 -06001729 pipeline_layout_ci.descriptorSetCount = 1;
1730 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001731
1732 VkPipelineLayout pipeline_layout;
1733 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1734 ASSERT_VK_SUCCESS(err);
1735
Tobin Ehlise68360f2015-10-01 11:15:13 -06001736 VkViewport vp = {}; // Just need dummy vp to point to
1737 VkRect2D sc = {}; // dummy scissor to point to
1738
1739 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1740 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1741 vp_state_ci.scissorCount = 1;
1742 vp_state_ci.pScissors = &sc;
1743 vp_state_ci.viewportCount = 1;
1744 vp_state_ci.pViewports = &vp;
1745
Tony Barboureb254902015-07-15 12:50:33 -06001746 VkGraphicsPipelineCreateInfo gp_ci = {};
1747 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06001748 gp_ci.pViewportState = &vp_state_ci;
Tony Barboureb254902015-07-15 12:50:33 -06001749 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1750 gp_ci.layout = pipeline_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001751 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06001752
1753 VkPipelineCacheCreateInfo pc_ci = {};
1754 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tony Barboureb254902015-07-15 12:50:33 -06001755 pc_ci.initialSize = 0;
1756 pc_ci.initialData = 0;
1757 pc_ci.maxSize = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001758
1759 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06001760 VkPipelineCache pipelineCache;
1761
1762 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1763 ASSERT_VK_SUCCESS(err);
1764 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001765
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001766 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001767 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 -06001768 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1769 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1770 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001771
1772 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1773 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06001774 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1775 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001776}
Tobin Ehlis912df022015-09-17 08:46:18 -06001777/*// TODO : This test should be good, but needs Tess support in compiler to run
1778TEST_F(VkLayerTest, InvalidPatchControlPoints)
1779{
1780 // Attempt to Create Gfx Pipeline w/o a VS
1781 VkFlags msgFlags;
1782 std::string msgString;
1783 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001784
Tobin Ehlis912df022015-09-17 08:46:18 -06001785 ASSERT_NO_FATAL_FAILURE(InitState());
1786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1787 m_errorMonitor->ClearState();
1788
1789 VkDescriptorTypeCount ds_type_count = {};
1790 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1791 ds_type_count.count = 1;
1792
1793 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1794 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1795 ds_pool_ci.pNext = NULL;
1796 ds_pool_ci.count = 1;
1797 ds_pool_ci.pTypeCount = &ds_type_count;
1798
1799 VkDescriptorPool ds_pool;
1800 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1801 ASSERT_VK_SUCCESS(err);
1802
1803 VkDescriptorSetLayoutBinding dsl_binding = {};
1804 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1805 dsl_binding.arraySize = 1;
1806 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1807 dsl_binding.pImmutableSamplers = NULL;
1808
1809 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1810 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1811 ds_layout_ci.pNext = NULL;
1812 ds_layout_ci.count = 1;
1813 ds_layout_ci.pBinding = &dsl_binding;
1814
1815 VkDescriptorSetLayout ds_layout;
1816 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1817 ASSERT_VK_SUCCESS(err);
1818
1819 VkDescriptorSet descriptorSet;
1820 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1821 ASSERT_VK_SUCCESS(err);
1822
1823 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1824 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1825 pipeline_layout_ci.pNext = NULL;
1826 pipeline_layout_ci.descriptorSetCount = 1;
1827 pipeline_layout_ci.pSetLayouts = &ds_layout;
1828
1829 VkPipelineLayout pipeline_layout;
1830 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1831 ASSERT_VK_SUCCESS(err);
1832
1833 VkPipelineShaderStageCreateInfo shaderStages[3];
1834 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1835
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001836 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06001837 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001838 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
1839 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06001840
1841 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001842 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001843 shaderStages[0].shader = vs.handle();
1844 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001845 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001846 shaderStages[1].shader = tc.handle();
1847 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001848 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06001849 shaderStages[2].shader = te.handle();
1850
1851 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1852 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1853 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1854
1855 VkPipelineTessellationStateCreateInfo tsCI = {};
1856 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1857 tsCI.patchControlPoints = 0; // This will cause an error
1858
1859 VkGraphicsPipelineCreateInfo gp_ci = {};
1860 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1861 gp_ci.pNext = NULL;
1862 gp_ci.stageCount = 3;
1863 gp_ci.pStages = shaderStages;
1864 gp_ci.pVertexInputState = NULL;
1865 gp_ci.pInputAssemblyState = &iaCI;
1866 gp_ci.pTessellationState = &tsCI;
1867 gp_ci.pViewportState = NULL;
1868 gp_ci.pRasterState = NULL;
1869 gp_ci.pMultisampleState = NULL;
1870 gp_ci.pDepthStencilState = NULL;
1871 gp_ci.pColorBlendState = NULL;
1872 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1873 gp_ci.layout = pipeline_layout;
1874 gp_ci.renderPass = renderPass();
1875
1876 VkPipelineCacheCreateInfo pc_ci = {};
1877 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1878 pc_ci.pNext = NULL;
1879 pc_ci.initialSize = 0;
1880 pc_ci.initialData = 0;
1881 pc_ci.maxSize = 0;
1882
1883 VkPipeline pipeline;
1884 VkPipelineCache pipelineCache;
1885
1886 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1887 ASSERT_VK_SUCCESS(err);
1888 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1889
1890 msgFlags = m_errorMonitor->GetState(&msgString);
1891 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Tess Gfx Pipeline w/ 0 patchControlPoints.";
1892 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ")) {
1893 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...' but instead '" << msgString.c_str() << "'";
1894 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001895
1896 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1897 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06001898 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1899 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06001900}
1901*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06001902// Set scissor and viewport counts to different numbers
1903TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
1904{
1905 // Attempt to Create Gfx Pipeline w/o a VS
1906 VkFlags msgFlags;
1907 std::string msgString;
1908 VkResult err;
1909
1910 ASSERT_NO_FATAL_FAILURE(InitState());
1911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1912 m_errorMonitor->ClearState();
1913
1914 VkDescriptorTypeCount ds_type_count = {};
1915 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1916 ds_type_count.count = 1;
1917
1918 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1919 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1920 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1921 ds_pool_ci.maxSets = 1;
1922 ds_pool_ci.count = 1;
1923 ds_pool_ci.pTypeCount = &ds_type_count;
1924
1925 VkDescriptorPool ds_pool;
1926 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1927 ASSERT_VK_SUCCESS(err);
1928
1929 VkDescriptorSetLayoutBinding dsl_binding = {};
1930 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1931 dsl_binding.arraySize = 1;
1932 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1933
1934 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1935 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1936 ds_layout_ci.count = 1;
1937 ds_layout_ci.pBinding = &dsl_binding;
1938
1939 VkDescriptorSetLayout ds_layout;
1940 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1941 ASSERT_VK_SUCCESS(err);
1942
1943 VkDescriptorSet descriptorSet;
1944 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1945 ASSERT_VK_SUCCESS(err);
1946
1947 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1948 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1949 pipeline_layout_ci.descriptorSetCount = 1;
1950 pipeline_layout_ci.pSetLayouts = &ds_layout;
1951
1952 VkPipelineLayout pipeline_layout;
1953 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1954 ASSERT_VK_SUCCESS(err);
1955
1956 VkViewport vp = {}; // Just need dummy vp to point to
1957
1958 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1959 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1960 vp_state_ci.scissorCount = 0;
1961 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
1962 vp_state_ci.pViewports = &vp;
1963
Cody Northropeb3a6c12015-10-05 14:44:45 -06001964 VkPipelineShaderStageCreateInfo shaderStages[2];
1965 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06001966
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001967 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1968 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 -06001969 // but add it to be able to run on more devices
1970 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001971 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06001972 shaderStages[0].shader = vs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06001973
Cody Northropeb3a6c12015-10-05 14:44:45 -06001974 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001975 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06001976 shaderStages[1].shader = fs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06001977
1978 VkGraphicsPipelineCreateInfo gp_ci = {};
1979 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06001980 gp_ci.stageCount = 2;
1981 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06001982 gp_ci.pViewportState = &vp_state_ci;
1983 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1984 gp_ci.layout = pipeline_layout;
1985 gp_ci.renderPass = renderPass();
1986
1987 VkPipelineCacheCreateInfo pc_ci = {};
1988 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1989
1990 VkPipeline pipeline;
1991 VkPipelineCache pipelineCache;
1992
1993 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1994 ASSERT_VK_SUCCESS(err);
1995 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1996
1997 msgFlags = m_errorMonitor->GetState(&msgString);
1998 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/ viewport and scissor count mismatch.";
1999 if (!strstr(msgString.c_str(),"Gfx Pipeline viewport count (1) must match scissor count (0).")) {
2000 FAIL() << "Error received was not 'Gfx Pipeline viewport count (1) must match scissor count (0).' but instead it was '" << msgString.c_str() << "'";
2001 }
2002
2003 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2004 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002005 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2006 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2007}
Tobin Ehlisd332f282015-10-02 11:00:56 -06002008// Don't set viewport state in PSO. This is an error b/c we always need this state
2009// for the counts even if the data is going to be set dynamically.
2010TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002011{
2012 // Attempt to Create Gfx Pipeline w/o a VS
2013 VkFlags msgFlags;
2014 std::string msgString;
2015 VkResult err;
2016
2017 ASSERT_NO_FATAL_FAILURE(InitState());
2018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2019 m_errorMonitor->ClearState();
2020
2021 VkDescriptorTypeCount ds_type_count = {};
2022 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2023 ds_type_count.count = 1;
2024
2025 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2026 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2027 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2028 ds_pool_ci.maxSets = 1;
2029 ds_pool_ci.count = 1;
2030 ds_pool_ci.pTypeCount = &ds_type_count;
2031
2032 VkDescriptorPool ds_pool;
2033 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2034 ASSERT_VK_SUCCESS(err);
2035
2036 VkDescriptorSetLayoutBinding dsl_binding = {};
2037 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2038 dsl_binding.arraySize = 1;
2039 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2040
2041 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2042 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2043 ds_layout_ci.count = 1;
2044 ds_layout_ci.pBinding = &dsl_binding;
2045
2046 VkDescriptorSetLayout ds_layout;
2047 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2048 ASSERT_VK_SUCCESS(err);
2049
2050 VkDescriptorSet descriptorSet;
2051 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
2052 ASSERT_VK_SUCCESS(err);
2053
2054 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2055 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2056 pipeline_layout_ci.descriptorSetCount = 1;
2057 pipeline_layout_ci.pSetLayouts = &ds_layout;
2058
2059 VkPipelineLayout pipeline_layout;
2060 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2061 ASSERT_VK_SUCCESS(err);
2062
2063 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2064 // Set scissor as dynamic to avoid second error
2065 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2066 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2067 dyn_state_ci.dynamicStateCount = 1;
2068 dyn_state_ci.pDynamicStates = &sc_state;
2069
Cody Northropeb3a6c12015-10-05 14:44:45 -06002070 VkPipelineShaderStageCreateInfo shaderStages[2];
2071 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002072
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002073 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2074 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 -06002075 // but add it to be able to run on more devices
2076 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002077 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002078 shaderStages[0].shader = vs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002079
Cody Northropeb3a6c12015-10-05 14:44:45 -06002080 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002081 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002082 shaderStages[1].shader = fs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002083
2084 VkGraphicsPipelineCreateInfo gp_ci = {};
2085 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002086 gp_ci.stageCount = 2;
2087 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002088 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2089 gp_ci.pDynamicState = &dyn_state_ci;
2090 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2091 gp_ci.layout = pipeline_layout;
2092 gp_ci.renderPass = renderPass();
2093
2094 VkPipelineCacheCreateInfo pc_ci = {};
2095 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2096
2097 VkPipeline pipeline;
2098 VkPipelineCache pipelineCache;
2099
2100 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2101 ASSERT_VK_SUCCESS(err);
2102 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2103
2104 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002105 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o viewport state set.";
2106 if (!strstr(msgString.c_str(),"Gfx Pipeline pViewportState is null. Even if ")) {
2107 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 -06002108 }
2109
2110 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2111 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002112 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2113 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2114}
2115// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002116// Then run second test where dynamic scissor count doesn't match PSO scissor count
2117TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002118{
2119 VkFlags msgFlags;
2120 std::string msgString;
2121 VkResult err;
2122
2123 ASSERT_NO_FATAL_FAILURE(InitState());
2124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2125 m_errorMonitor->ClearState();
2126
2127 VkDescriptorTypeCount ds_type_count = {};
2128 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2129 ds_type_count.count = 1;
2130
2131 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2132 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2133 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2134 ds_pool_ci.maxSets = 1;
2135 ds_pool_ci.count = 1;
2136 ds_pool_ci.pTypeCount = &ds_type_count;
2137
2138 VkDescriptorPool ds_pool;
2139 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2140 ASSERT_VK_SUCCESS(err);
2141
2142 VkDescriptorSetLayoutBinding dsl_binding = {};
2143 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2144 dsl_binding.arraySize = 1;
2145 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2146
2147 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2148 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2149 ds_layout_ci.count = 1;
2150 ds_layout_ci.pBinding = &dsl_binding;
2151
2152 VkDescriptorSetLayout ds_layout;
2153 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2154 ASSERT_VK_SUCCESS(err);
2155
2156 VkDescriptorSet descriptorSet;
2157 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
2158 ASSERT_VK_SUCCESS(err);
2159
2160 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2161 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2162 pipeline_layout_ci.descriptorSetCount = 1;
2163 pipeline_layout_ci.pSetLayouts = &ds_layout;
2164
2165 VkPipelineLayout pipeline_layout;
2166 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2167 ASSERT_VK_SUCCESS(err);
2168
2169 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2170 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2171 vp_state_ci.viewportCount = 1;
2172 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2173 vp_state_ci.scissorCount = 1;
2174 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2175
2176 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2177 // Set scissor as dynamic to avoid that error
2178 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2179 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2180 dyn_state_ci.dynamicStateCount = 1;
2181 dyn_state_ci.pDynamicStates = &sc_state;
2182
Cody Northropeb3a6c12015-10-05 14:44:45 -06002183 VkPipelineShaderStageCreateInfo shaderStages[2];
2184 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002185
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002186 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2187 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 -06002188 // but add it to be able to run on more devices
2189 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002190 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002191 shaderStages[0].shader = vs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002192
Cody Northropeb3a6c12015-10-05 14:44:45 -06002193 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002194 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002195 shaderStages[1].shader = fs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002196
Cody Northropf6622dc2015-10-06 10:33:21 -06002197 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2198 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2199 vi_ci.pNext = nullptr;
2200 vi_ci.bindingCount = 0;
2201 vi_ci.pVertexBindingDescriptions = nullptr;
2202 vi_ci.attributeCount = 0;
2203 vi_ci.pVertexAttributeDescriptions = nullptr;
2204
2205 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2206 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2207 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2208
2209 VkPipelineRasterStateCreateInfo rs_ci = {};
2210 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2211 rs_ci.pNext = nullptr;
2212
2213 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2214 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2215 cb_ci.pNext = nullptr;
2216
Tobin Ehlise68360f2015-10-01 11:15:13 -06002217 VkGraphicsPipelineCreateInfo gp_ci = {};
2218 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002219 gp_ci.stageCount = 2;
2220 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06002221 gp_ci.pVertexInputState = &vi_ci;
2222 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002223 gp_ci.pViewportState = &vp_state_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06002224 gp_ci.pRasterState = &rs_ci;
2225 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002226 gp_ci.pDynamicState = &dyn_state_ci;
2227 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2228 gp_ci.layout = pipeline_layout;
2229 gp_ci.renderPass = renderPass();
2230
2231 VkPipelineCacheCreateInfo pc_ci = {};
2232 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2233
2234 VkPipeline pipeline;
2235 VkPipelineCache pipelineCache;
2236
2237 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2238 ASSERT_VK_SUCCESS(err);
2239 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2240
2241 msgFlags = m_errorMonitor->GetState(&msgString);
2242 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2243 if (!strstr(msgString.c_str(),"Gfx Pipeline viewportCount is 1, but pViewports is NULL. ")) {
2244 FAIL() << "Error received was not 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...' but instead it was '" << msgString.c_str() << "'";
2245 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002246 m_errorMonitor->ClearState();
2247 // Now hit second fail case where we set scissor w/ different count than PSO
2248 // First need to successfully create the PSO from above by setting pViewports
2249 VkViewport vp = {}; // Just need dummy vp to point to
2250 vp_state_ci.pViewports = &vp;
2251 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2252 ASSERT_VK_SUCCESS(err);
2253 BeginCommandBuffer();
2254 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2255 VkRect2D scissors[2] = {}; // don't care about data
2256 // Count of 2 doesn't match PSO count of 1
2257 vkCmdSetScissor(m_cmdBuffer->GetBufferHandle(), 2, scissors);
2258 Draw(1, 0, 0, 0);
2259
2260 msgFlags = m_errorMonitor->GetState(&msgString);
2261 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic scissorCount different from PSO scissorCount.";
2262 if (!strstr(msgString.c_str(),"Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.")) {
2263 FAIL() << "Error received was not 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...' but instead it was '" << msgString.c_str() << "'";
2264 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06002265
2266 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2267 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002268 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2269 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2270}
2271// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002272// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2273TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002274{
2275 VkFlags msgFlags;
2276 std::string msgString;
2277 VkResult err;
2278
2279 ASSERT_NO_FATAL_FAILURE(InitState());
2280 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2281 m_errorMonitor->ClearState();
2282
2283 VkDescriptorTypeCount ds_type_count = {};
2284 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2285 ds_type_count.count = 1;
2286
2287 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2288 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2289 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2290 ds_pool_ci.maxSets = 1;
2291 ds_pool_ci.count = 1;
2292 ds_pool_ci.pTypeCount = &ds_type_count;
2293
2294 VkDescriptorPool ds_pool;
2295 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2296 ASSERT_VK_SUCCESS(err);
2297
2298 VkDescriptorSetLayoutBinding dsl_binding = {};
2299 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2300 dsl_binding.arraySize = 1;
2301 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2302
2303 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2304 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2305 ds_layout_ci.count = 1;
2306 ds_layout_ci.pBinding = &dsl_binding;
2307
2308 VkDescriptorSetLayout ds_layout;
2309 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2310 ASSERT_VK_SUCCESS(err);
2311
2312 VkDescriptorSet descriptorSet;
2313 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
2314 ASSERT_VK_SUCCESS(err);
2315
2316 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2317 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2318 pipeline_layout_ci.descriptorSetCount = 1;
2319 pipeline_layout_ci.pSetLayouts = &ds_layout;
2320
2321 VkPipelineLayout pipeline_layout;
2322 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2323 ASSERT_VK_SUCCESS(err);
2324
2325 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2326 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2327 vp_state_ci.scissorCount = 1;
2328 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2329 vp_state_ci.viewportCount = 1;
2330 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2331
2332 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2333 // Set scissor as dynamic to avoid that error
2334 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2335 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2336 dyn_state_ci.dynamicStateCount = 1;
2337 dyn_state_ci.pDynamicStates = &vp_state;
2338
Cody Northropeb3a6c12015-10-05 14:44:45 -06002339 VkPipelineShaderStageCreateInfo shaderStages[2];
2340 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002341
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002342 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2343 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 -06002344 // but add it to be able to run on more devices
2345 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002346 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002347 shaderStages[0].shader = vs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002348
Cody Northropeb3a6c12015-10-05 14:44:45 -06002349 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002350 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002351 shaderStages[1].shader = fs.handle();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002352
Cody Northropf6622dc2015-10-06 10:33:21 -06002353 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2354 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2355 vi_ci.pNext = nullptr;
2356 vi_ci.bindingCount = 0;
2357 vi_ci.pVertexBindingDescriptions = nullptr;
2358 vi_ci.attributeCount = 0;
2359 vi_ci.pVertexAttributeDescriptions = nullptr;
2360
2361 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2362 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2363 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2364
2365 VkPipelineRasterStateCreateInfo rs_ci = {};
2366 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2367 rs_ci.pNext = nullptr;
2368
2369 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2370 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2371 cb_ci.pNext = nullptr;
2372
Tobin Ehlise68360f2015-10-01 11:15:13 -06002373 VkGraphicsPipelineCreateInfo gp_ci = {};
2374 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002375 gp_ci.stageCount = 2;
2376 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06002377 gp_ci.pVertexInputState = &vi_ci;
2378 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002379 gp_ci.pViewportState = &vp_state_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06002380 gp_ci.pRasterState = &rs_ci;
2381 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002382 gp_ci.pDynamicState = &dyn_state_ci;
2383 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2384 gp_ci.layout = pipeline_layout;
2385 gp_ci.renderPass = renderPass();
2386
2387 VkPipelineCacheCreateInfo pc_ci = {};
2388 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2389
2390 VkPipeline pipeline;
2391 VkPipelineCache pipelineCache;
2392
2393 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2394 ASSERT_VK_SUCCESS(err);
2395 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2396
2397 msgFlags = m_errorMonitor->GetState(&msgString);
2398 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2399 if (!strstr(msgString.c_str(),"Gfx Pipeline scissorCount is 1, but pScissors is NULL. ")) {
2400 FAIL() << "Error received was not 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...' but instead it was '" << msgString.c_str() << "'";
2401 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002402 m_errorMonitor->ClearState();
2403 // Now hit second fail case where we set scissor w/ different count than PSO
2404 // First need to successfully create the PSO from above by setting pViewports
2405 VkRect2D sc = {}; // Just need dummy vp to point to
2406 vp_state_ci.pScissors = &sc;
2407 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2408 ASSERT_VK_SUCCESS(err);
2409 BeginCommandBuffer();
2410 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2411 VkViewport viewports[2] = {}; // don't care about data
2412 // Count of 2 doesn't match PSO count of 1
2413 vkCmdSetViewport(m_cmdBuffer->GetBufferHandle(), 2, viewports);
2414 Draw(1, 0, 0, 0);
2415
2416 msgFlags = m_errorMonitor->GetState(&msgString);
2417 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic viewportCount different from PSO viewportCount.";
2418 if (!strstr(msgString.c_str(),"Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.")) {
2419 FAIL() << "Error received was not 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...' but instead it was '" << msgString.c_str() << "'";
2420 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06002421
2422 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2423 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002424 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2425 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2426}
2427
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002428TEST_F(VkLayerTest, NullRenderPass)
2429{
2430 // Bind a NULL RenderPass
2431 VkFlags msgFlags;
2432 std::string msgString;
2433
2434 ASSERT_NO_FATAL_FAILURE(InitState());
2435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2436 m_errorMonitor->ClearState();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002437
Tony Barbourfe3351b2015-07-28 10:17:20 -06002438 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002439 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbourfe3351b2015-07-28 10:17:20 -06002440 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002441
2442 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002443 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002444 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
2445 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2446 }
2447}
2448
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002449TEST_F(VkLayerTest, RenderPassWithinRenderPass)
2450{
2451 // Bind a BeginRenderPass within an active RenderPass
2452 VkFlags msgFlags;
2453 std::string msgString;
2454
2455 ASSERT_NO_FATAL_FAILURE(InitState());
2456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2457 m_errorMonitor->ClearState();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002458
Tony Barbourfe3351b2015-07-28 10:17:20 -06002459 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06002460 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barboureb254902015-07-15 12:50:33 -06002461 VkRenderPassBeginInfo rp_begin = {};
2462 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
2463 rp_begin.pNext = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002464 rp_begin.renderPass = renderPass();
2465 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002466
Tony Barbourfe3351b2015-07-28 10:17:20 -06002467 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002468
2469 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002470 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 -06002471 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2472 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002473 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002474}
2475
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002476TEST_F(VkLayerTest, FillBufferWithinRenderPass)
2477{
2478 // Call CmdFillBuffer within an active renderpass
2479 VkFlags msgFlags;
2480 std::string msgString;
2481
2482 ASSERT_NO_FATAL_FAILURE(InitState());
2483 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2484 m_errorMonitor->ClearState();
2485
2486 // Renderpass is started here
2487 BeginCommandBuffer();
2488
2489 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2490 vk_testing::Buffer destBuffer;
2491 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2492
2493 m_cmdBuffer->FillBuffer(destBuffer.handle(), 0, 4, 0x11111111);
2494
2495 msgFlags = m_errorMonitor->GetState(&msgString);
2496 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2497 "Did not receive error after calling CmdFillBuffer w/i an active RenderPass.";
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002498 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2499 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002500 }
2501}
2502
2503TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
2504{
2505 // Call CmdUpdateBuffer within an active renderpass
2506 VkFlags msgFlags;
2507 std::string msgString;
2508
2509 ASSERT_NO_FATAL_FAILURE(InitState());
2510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2511 m_errorMonitor->ClearState();
2512
2513 // Renderpass is started here
2514 BeginCommandBuffer();
2515
2516 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2517 vk_testing::Buffer destBuffer;
2518 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2519
2520 VkDeviceSize destOffset = 0;
2521 VkDeviceSize dataSize = 1024;
2522 const uint32_t *pData = NULL;
2523
2524 vkCmdUpdateBuffer(m_cmdBuffer->GetBufferHandle(), destBuffer.handle(), destOffset, dataSize, pData);
2525
2526 msgFlags = m_errorMonitor->GetState(&msgString);
2527 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2528 "Did not receive error after calling CmdUpdateBuffer w/i an active RenderPass.";
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002529 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2530 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002531 }
2532}
2533
2534TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
2535{
2536 // Call CmdClearColorImage within an active RenderPass
2537 VkFlags msgFlags;
2538 std::string msgString;
2539
2540 ASSERT_NO_FATAL_FAILURE(InitState());
2541 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2542 m_errorMonitor->ClearState();
2543
2544 // Renderpass is started here
2545 BeginCommandBuffer();
2546
2547 VkClearColorValue clear_color = {0};
2548 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2549 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2550 const int32_t tex_width = 32;
2551 const int32_t tex_height = 32;
2552 VkImageCreateInfo image_create_info = {};
2553 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2554 image_create_info.pNext = NULL;
2555 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2556 image_create_info.format = tex_format;
2557 image_create_info.extent.width = tex_width;
2558 image_create_info.extent.height = tex_height;
2559 image_create_info.extent.depth = 1;
2560 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06002561 image_create_info.arrayLayers = 1;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002562 image_create_info.samples = 1;
2563 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2564 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2565
2566 vk_testing::Image destImage;
2567 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2568
2569 const VkImageSubresourceRange range =
2570 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
2571
2572 vkCmdClearColorImage(m_cmdBuffer->GetBufferHandle(),
2573 destImage.handle(),
2574 VK_IMAGE_LAYOUT_GENERAL,
2575 &clear_color,
2576 1,
2577 &range);
2578
2579 msgFlags = m_errorMonitor->GetState(&msgString);
2580 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2581 "Did not receive error after calling CmdClearColorImage w/i an active RenderPass.";
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002582 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2583 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002584 }
2585}
2586
2587TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
2588{
2589 // Call CmdClearDepthStencilImage within an active RenderPass
2590 VkFlags msgFlags;
2591 std::string msgString;
2592
2593 ASSERT_NO_FATAL_FAILURE(InitState());
2594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2595 m_errorMonitor->ClearState();
2596
2597 // Renderpass is started here
2598 BeginCommandBuffer();
2599
2600 VkClearDepthStencilValue clear_value = {0};
2601 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2602 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
2603 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2604 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
2605 image_create_info.extent.width = 64;
2606 image_create_info.extent.height = 64;
2607 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2608 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2609
2610 vk_testing::Image destImage;
2611 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2612
2613 const VkImageSubresourceRange range =
2614 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
2615
2616 vkCmdClearDepthStencilImage(m_cmdBuffer->GetBufferHandle(),
2617 destImage.handle(),
2618 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2619 &clear_value,
2620 1,
2621 &range);
2622
2623 msgFlags = m_errorMonitor->GetState(&msgString);
2624 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2625 "Did not receive error after calling CmdClearDepthStencilImage w/i an active RenderPass.";
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002626 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2627 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002628 }
2629}
2630
2631TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
2632{
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002633 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002634 VkFlags msgFlags;
2635 std::string msgString;
2636 VkResult err;
2637
2638 ASSERT_NO_FATAL_FAILURE(InitState());
2639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2640 m_errorMonitor->ClearState();
2641
2642 // Start no RenderPass
2643 err = m_cmdBuffer->BeginCommandBuffer();
2644 ASSERT_VK_SUCCESS(err);
2645
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002646 VkClearAttachment color_attachment;
2647 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2648 color_attachment.clearValue.color.float32[0] = 0;
2649 color_attachment.clearValue.color.float32[1] = 0;
2650 color_attachment.clearValue.color.float32[2] = 0;
2651 color_attachment.clearValue.color.float32[3] = 0;
2652 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06002653 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002654 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(),
2655 1, &color_attachment,
2656 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002657
2658 msgFlags = m_errorMonitor->GetState(&msgString);
2659 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06002660 "Did not receive error after calling CmdClearAttachments outside of an active RenderPass.";
2661 if (!strstr(msgString.c_str(),"vkCmdClearAttachments: This call must be issued inside an active render pass")) {
2662 FAIL() << "Error received was not 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
Mark Lobodzinskid5639502015-09-24 09:51:47 -06002663 }
2664}
2665
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002666TEST_F(VkLayerTest, InvalidDynamicStateObject)
2667{
2668 // Create a valid cmd buffer
2669 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002670 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
2671 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002672}
Tobin Ehlis1056d452015-05-27 14:55:35 -06002673
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002674TEST_F(VkLayerTest, IdxBufferAlignmentError)
2675{
2676 // Bind a BeginRenderPass within an active RenderPass
2677 VkFlags msgFlags;
2678 std::string msgString;
2679 VkResult err;
2680
2681 ASSERT_NO_FATAL_FAILURE(InitState());
2682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2683 m_errorMonitor->ClearState();
2684 uint32_t qfi = 0;
2685 VkBufferCreateInfo buffCI = {};
2686 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2687 buffCI.size = 1024;
2688 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
2689 buffCI.queueFamilyCount = 1;
2690 buffCI.pQueueFamilyIndices = &qfi;
2691
2692 VkBuffer ib;
2693 err = vkCreateBuffer(m_device->device(), &buffCI, &ib);
2694 ASSERT_VK_SUCCESS(err);
2695
2696 BeginCommandBuffer();
2697 ASSERT_VK_SUCCESS(err);
2698 //vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2699 // Should error before calling to driver so don't care about actual data
2700 vkCmdBindIndexBuffer(m_cmdBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
2701
2702 msgFlags = m_errorMonitor->GetState(&msgString);
2703 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2704 if (!strstr(msgString.c_str(),"vkCmdBindIndexBuffer() offset (0x7) does not fall on ")) {
2705 FAIL() << "Error received was not 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...' but instead '" << msgString.c_str() << "'";
2706 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002707
2708 vkDestroyBuffer(m_device->device(), ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002709}
2710
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06002711TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2712{
2713 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
2714 VkFlags msgFlags;
2715 std::string msgString;
2716
2717 ASSERT_NO_FATAL_FAILURE(InitState());
2718 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2719 m_errorMonitor->ClearState();
2720
2721 BeginCommandBuffer();
2722 //ASSERT_VK_SUCCESS(err);
2723 VkCmdBuffer primCB = m_cmdBuffer->GetBufferHandle();
2724 vkCmdExecuteCommands(m_cmdBuffer->GetBufferHandle(), 1, &primCB);
2725
2726 msgFlags = m_errorMonitor->GetState(&msgString);
2727 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2728 if (!strstr(msgString.c_str(),"vkCmdExecuteCommands() called w/ Primary Cmd Buffer ")) {
2729 FAIL() << "Error received was not 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer ' but instead '" << msgString.c_str() << "'";
2730 }
2731}
2732
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002733TEST_F(VkLayerTest, DSTypeMismatch)
2734{
2735 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002736 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002737 std::string msgString;
2738 VkResult err;
2739
2740 ASSERT_NO_FATAL_FAILURE(InitState());
2741 m_errorMonitor->ClearState();
2742 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06002743 VkDescriptorTypeCount ds_type_count = {};
2744 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2745 ds_type_count.count = 1;
2746
2747 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2748 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2749 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002750 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2751 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002752 ds_pool_ci.count = 1;
2753 ds_pool_ci.pTypeCount = &ds_type_count;
2754
Tobin Ehlis3b780662015-05-28 12:11:26 -06002755 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002756 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002757 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06002758 VkDescriptorSetLayoutBinding dsl_binding = {};
2759 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2760 dsl_binding.arraySize = 1;
2761 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2762 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002763
Tony Barboureb254902015-07-15 12:50:33 -06002764 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2765 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2766 ds_layout_ci.pNext = NULL;
2767 ds_layout_ci.count = 1;
2768 ds_layout_ci.pBinding = &dsl_binding;
2769
Tobin Ehlis3b780662015-05-28 12:11:26 -06002770 VkDescriptorSetLayout ds_layout;
2771 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2772 ASSERT_VK_SUCCESS(err);
2773
2774 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06002775 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002776 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002777
Tony Barboureb254902015-07-15 12:50:33 -06002778 VkSamplerCreateInfo sampler_ci = {};
2779 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2780 sampler_ci.pNext = NULL;
2781 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2782 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2783 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06002784 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2785 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2786 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06002787 sampler_ci.mipLodBias = 1.0;
2788 sampler_ci.maxAnisotropy = 1;
2789 sampler_ci.compareEnable = VK_FALSE;
2790 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2791 sampler_ci.minLod = 1.0;
2792 sampler_ci.maxLod = 1.0;
2793 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06002794 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2795
Tobin Ehlis3b780662015-05-28 12:11:26 -06002796 VkSampler sampler;
2797 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2798 ASSERT_VK_SUCCESS(err);
2799
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002800 VkDescriptorInfo descriptor_info;
2801 memset(&descriptor_info, 0, sizeof(descriptor_info));
2802 descriptor_info.sampler = sampler;
2803
2804 VkWriteDescriptorSet descriptor_write;
2805 memset(&descriptor_write, 0, sizeof(descriptor_write));
2806 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2807 descriptor_write.destSet = descriptorSet;
2808 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002809 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002810 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2811 descriptor_write.pDescriptors = &descriptor_info;
2812
2813 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2814
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002815 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002816 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 -06002817 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 ")) {
2818 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 -06002819 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002820
2821 vkDestroySampler(m_device->device(), sampler);
Mike Stroyand1c84a52015-08-18 14:40:24 -06002822 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2823 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002824}
2825
2826TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2827{
2828 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002829 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002830 std::string msgString;
2831 VkResult err;
2832
2833 ASSERT_NO_FATAL_FAILURE(InitState());
2834 m_errorMonitor->ClearState();
2835 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06002836 VkDescriptorTypeCount ds_type_count = {};
2837 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2838 ds_type_count.count = 1;
2839
2840 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2841 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2842 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002843 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2844 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002845 ds_pool_ci.count = 1;
2846 ds_pool_ci.pTypeCount = &ds_type_count;
2847
Tobin Ehlis3b780662015-05-28 12:11:26 -06002848 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002849 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002850 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002851
Tony Barboureb254902015-07-15 12:50:33 -06002852 VkDescriptorSetLayoutBinding dsl_binding = {};
2853 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2854 dsl_binding.arraySize = 1;
2855 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2856 dsl_binding.pImmutableSamplers = NULL;
2857
2858 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2859 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2860 ds_layout_ci.pNext = NULL;
2861 ds_layout_ci.count = 1;
2862 ds_layout_ci.pBinding = &dsl_binding;
2863
Tobin Ehlis3b780662015-05-28 12:11:26 -06002864 VkDescriptorSetLayout ds_layout;
2865 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2866 ASSERT_VK_SUCCESS(err);
2867
2868 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06002869 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002870 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002871
Tony Barboureb254902015-07-15 12:50:33 -06002872 VkSamplerCreateInfo sampler_ci = {};
2873 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2874 sampler_ci.pNext = NULL;
2875 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2876 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2877 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06002878 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2879 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2880 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06002881 sampler_ci.mipLodBias = 1.0;
2882 sampler_ci.maxAnisotropy = 1;
2883 sampler_ci.compareEnable = VK_FALSE;
2884 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2885 sampler_ci.minLod = 1.0;
2886 sampler_ci.maxLod = 1.0;
2887 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06002888 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06002889
Tobin Ehlis3b780662015-05-28 12:11:26 -06002890 VkSampler sampler;
2891 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2892 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002893
2894 VkDescriptorInfo descriptor_info;
2895 memset(&descriptor_info, 0, sizeof(descriptor_info));
2896 descriptor_info.sampler = sampler;
2897
2898 VkWriteDescriptorSet descriptor_write;
2899 memset(&descriptor_write, 0, sizeof(descriptor_write));
2900 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2901 descriptor_write.destSet = descriptorSet;
2902 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
2903 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002904 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002905 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2906 descriptor_write.pDescriptors = &descriptor_info;
2907
2908 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2909
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002910 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002911 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 +08002912 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
2913 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 -06002914 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002915
2916 vkDestroySampler(m_device->device(), sampler);
Mike Stroyand1c84a52015-08-18 14:40:24 -06002917 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2918 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002919}
2920
2921TEST_F(VkLayerTest, InvalidDSUpdateIndex)
2922{
Tobin Ehlis3b780662015-05-28 12:11:26 -06002923 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002924 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002925 std::string msgString;
2926 VkResult err;
2927
2928 ASSERT_NO_FATAL_FAILURE(InitState());
2929 m_errorMonitor->ClearState();
2930 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06002931 VkDescriptorTypeCount ds_type_count = {};
2932 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2933 ds_type_count.count = 1;
2934
2935 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2936 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2937 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002938 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2939 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002940 ds_pool_ci.count = 1;
2941 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002942
Tobin Ehlis3b780662015-05-28 12:11:26 -06002943 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002944 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002945 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002946
Tony Barboureb254902015-07-15 12:50:33 -06002947 VkDescriptorSetLayoutBinding dsl_binding = {};
2948 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2949 dsl_binding.arraySize = 1;
2950 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2951 dsl_binding.pImmutableSamplers = NULL;
2952
2953 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2954 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2955 ds_layout_ci.pNext = NULL;
2956 ds_layout_ci.count = 1;
2957 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002958 VkDescriptorSetLayout ds_layout;
2959 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2960 ASSERT_VK_SUCCESS(err);
2961
2962 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06002963 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002964 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002965
Tony Barboureb254902015-07-15 12:50:33 -06002966 VkSamplerCreateInfo sampler_ci = {};
2967 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2968 sampler_ci.pNext = NULL;
2969 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2970 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2971 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06002972 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2973 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2974 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06002975 sampler_ci.mipLodBias = 1.0;
2976 sampler_ci.maxAnisotropy = 1;
2977 sampler_ci.compareEnable = VK_FALSE;
2978 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2979 sampler_ci.minLod = 1.0;
2980 sampler_ci.maxLod = 1.0;
2981 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06002982 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06002983
Tobin Ehlis3b780662015-05-28 12:11:26 -06002984 VkSampler sampler;
2985 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2986 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002987
2988 VkDescriptorInfo descriptor_info;
2989 memset(&descriptor_info, 0, sizeof(descriptor_info));
2990 descriptor_info.sampler = sampler;
2991
2992 VkWriteDescriptorSet descriptor_write;
2993 memset(&descriptor_write, 0, sizeof(descriptor_write));
2994 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2995 descriptor_write.destSet = descriptorSet;
2996 descriptor_write.destBinding = 2;
2997 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002998 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002999 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3000 descriptor_write.pDescriptors = &descriptor_info;
3001
3002 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3003
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003004 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003005 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 -06003006 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
3007 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
3008 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003009
3010 vkDestroySampler(m_device->device(), sampler);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003011 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3012 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003013}
3014
3015TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3016{
3017 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003018 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003019 std::string msgString;
3020 VkResult err;
3021
3022 ASSERT_NO_FATAL_FAILURE(InitState());
3023 m_errorMonitor->ClearState();
3024 //VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003025
Tony Barboureb254902015-07-15 12:50:33 -06003026 VkDescriptorTypeCount ds_type_count = {};
3027 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3028 ds_type_count.count = 1;
3029
3030 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3031 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3032 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003033 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3034 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003035 ds_pool_ci.count = 1;
3036 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003037
Tobin Ehlis3b780662015-05-28 12:11:26 -06003038 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003039 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003040 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06003041 VkDescriptorSetLayoutBinding dsl_binding = {};
3042 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3043 dsl_binding.arraySize = 1;
3044 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3045 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003046
Tony Barboureb254902015-07-15 12:50:33 -06003047 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3048 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3049 ds_layout_ci.pNext = NULL;
3050 ds_layout_ci.count = 1;
3051 ds_layout_ci.pBinding = &dsl_binding;
3052
Tobin Ehlis3b780662015-05-28 12:11:26 -06003053 VkDescriptorSetLayout ds_layout;
3054 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3055 ASSERT_VK_SUCCESS(err);
3056
3057 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06003058 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003059 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003060
Tony Barboureb254902015-07-15 12:50:33 -06003061 VkSamplerCreateInfo sampler_ci = {};
3062 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3063 sampler_ci.pNext = NULL;
3064 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
3065 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
3066 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06003067 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3068 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3069 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06003070 sampler_ci.mipLodBias = 1.0;
3071 sampler_ci.maxAnisotropy = 1;
3072 sampler_ci.compareEnable = VK_FALSE;
3073 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3074 sampler_ci.minLod = 1.0;
3075 sampler_ci.maxLod = 1.0;
3076 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003077 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003078 VkSampler sampler;
3079 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3080 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003081
3082
3083 VkDescriptorInfo descriptor_info;
3084 memset(&descriptor_info, 0, sizeof(descriptor_info));
3085 descriptor_info.sampler = sampler;
3086
3087 VkWriteDescriptorSet descriptor_write;
3088 memset(&descriptor_write, 0, sizeof(descriptor_write));
3089 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
3090 descriptor_write.destSet = descriptorSet;
3091 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003092 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003093 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3094 descriptor_write.pDescriptors = &descriptor_info;
3095
3096 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3097
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003098 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003099 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 -06003100 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
3101 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
3102 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003103
3104 vkDestroySampler(m_device->device(), sampler);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003105 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3106 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003107}
3108
3109TEST_F(VkLayerTest, NumSamplesMismatch)
3110{
Tobin Ehlis3b780662015-05-28 12:11:26 -06003111 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003112 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003113 std::string msgString;
3114 VkResult err;
3115
3116 ASSERT_NO_FATAL_FAILURE(InitState());
3117 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3118 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06003119 VkDescriptorTypeCount ds_type_count = {};
3120 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3121 ds_type_count.count = 1;
3122
3123 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003124 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3125 ds_pool_ci.pNext = NULL;
3126 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3127 ds_pool_ci.maxSets = 1;
3128 ds_pool_ci.count = 1;
3129 ds_pool_ci.pTypeCount = &ds_type_count;
3130
Tobin Ehlis3b780662015-05-28 12:11:26 -06003131 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003132 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003133 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003134
Tony Barboureb254902015-07-15 12:50:33 -06003135 VkDescriptorSetLayoutBinding dsl_binding = {};
3136 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3137 dsl_binding.arraySize = 1;
3138 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3139 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003140
Tony Barboureb254902015-07-15 12:50:33 -06003141 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3142 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3143 ds_layout_ci.pNext = NULL;
3144 ds_layout_ci.count = 1;
3145 ds_layout_ci.pBinding = &dsl_binding;
3146
Tobin Ehlis3b780662015-05-28 12:11:26 -06003147 VkDescriptorSetLayout ds_layout;
3148 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3149 ASSERT_VK_SUCCESS(err);
3150
3151 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06003152 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003153 ASSERT_VK_SUCCESS(err);
3154
Tony Barboureb254902015-07-15 12:50:33 -06003155 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3156 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3157 pipe_ms_state_ci.pNext = NULL;
3158 pipe_ms_state_ci.rasterSamples = 4;
3159 pipe_ms_state_ci.sampleShadingEnable = 0;
3160 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003161 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003162
Tony Barboureb254902015-07-15 12:50:33 -06003163 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3164 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3165 pipeline_layout_ci.pNext = NULL;
3166 pipeline_layout_ci.descriptorSetCount = 1;
3167 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003168
3169 VkPipelineLayout pipeline_layout;
3170 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3171 ASSERT_VK_SUCCESS(err);
3172
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003173 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3174 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 -06003175 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003176 VkPipelineObj pipe(m_device);
3177 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003178 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003179 pipe.SetMSAA(&pipe_ms_state_ci);
3180 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003181
Tony Barbourfe3351b2015-07-28 10:17:20 -06003182 BeginCommandBuffer();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003183 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003184
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003185 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003186 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 -06003187 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
3188 FAIL() << "Error received was not 'Num samples mismatch!...'";
3189 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003190
3191 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003192 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3193 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003194}
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003195
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003196TEST_F(VkLayerTest, ClearCmdNoDraw)
3197{
3198 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
3199 VkFlags msgFlags;
3200 std::string msgString;
3201 VkResult err;
3202
3203 ASSERT_NO_FATAL_FAILURE(InitState());
3204 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3205 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06003206
3207 VkDescriptorTypeCount ds_type_count = {};
3208 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3209 ds_type_count.count = 1;
3210
3211 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3212 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3213 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003214 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3215 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003216 ds_pool_ci.count = 1;
3217 ds_pool_ci.pTypeCount = &ds_type_count;
3218
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003219 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003220 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003221 ASSERT_VK_SUCCESS(err);
3222
Tony Barboureb254902015-07-15 12:50:33 -06003223 VkDescriptorSetLayoutBinding dsl_binding = {};
3224 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3225 dsl_binding.arraySize = 1;
3226 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3227 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003228
Tony Barboureb254902015-07-15 12:50:33 -06003229 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3230 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3231 ds_layout_ci.pNext = NULL;
3232 ds_layout_ci.count = 1;
3233 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003234
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003235 VkDescriptorSetLayout ds_layout;
3236 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3237 ASSERT_VK_SUCCESS(err);
3238
3239 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06003240 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003241 ASSERT_VK_SUCCESS(err);
3242
Tony Barboureb254902015-07-15 12:50:33 -06003243 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3244 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3245 pipe_ms_state_ci.pNext = NULL;
3246 pipe_ms_state_ci.rasterSamples = 4;
3247 pipe_ms_state_ci.sampleShadingEnable = 0;
3248 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003249 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003250
Tony Barboureb254902015-07-15 12:50:33 -06003251 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3252 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3253 pipeline_layout_ci.pNext = NULL;
3254 pipeline_layout_ci.descriptorSetCount = 1;
3255 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003256
3257 VkPipelineLayout pipeline_layout;
3258 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3259 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003260
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003261 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3262 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 -06003263 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003264 VkPipelineObj pipe(m_device);
3265 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003266 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003267 pipe.SetMSAA(&pipe_ms_state_ci);
3268 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003269
3270 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003271
3272 m_errorMonitor->ClearState();
3273 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3274 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003275 VkClearAttachment color_attachment;
3276 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3277 color_attachment.clearValue.color.float32[0] = 1.0;
3278 color_attachment.clearValue.color.float32[1] = 1.0;
3279 color_attachment.clearValue.color.float32[2] = 1.0;
3280 color_attachment.clearValue.color.float32[3] = 1.0;
3281 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06003282 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003283
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003284 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003285 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003286 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 -06003287 if (!strstr(msgString.c_str(),"vkCmdClearAttachments() issued on CB object ")) {
3288 FAIL() << "Error received was not 'vkCmdClearAttachments() issued on CB object...'";
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003289 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003290
3291 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003292 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3293 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003294}
3295
Tobin Ehlis502480b2015-06-24 15:53:07 -06003296TEST_F(VkLayerTest, VtxBufferBadIndex)
3297{
3298 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
3299 VkFlags msgFlags;
3300 std::string msgString;
3301 VkResult err;
3302
3303 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06003304 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06003305 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3306 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06003307
3308 VkDescriptorTypeCount ds_type_count = {};
3309 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3310 ds_type_count.count = 1;
3311
3312 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3313 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3314 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003315 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3316 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003317 ds_pool_ci.count = 1;
3318 ds_pool_ci.pTypeCount = &ds_type_count;
3319
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003320 VkDescriptorPool ds_pool;
3321 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003322 ASSERT_VK_SUCCESS(err);
3323
Tony Barboureb254902015-07-15 12:50:33 -06003324 VkDescriptorSetLayoutBinding dsl_binding = {};
3325 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3326 dsl_binding.arraySize = 1;
3327 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3328 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003329
Tony Barboureb254902015-07-15 12:50:33 -06003330 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3331 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3332 ds_layout_ci.pNext = NULL;
3333 ds_layout_ci.count = 1;
3334 ds_layout_ci.pBinding = &dsl_binding;
3335
Tobin Ehlis502480b2015-06-24 15:53:07 -06003336 VkDescriptorSetLayout ds_layout;
3337 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3338 ASSERT_VK_SUCCESS(err);
3339
3340 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06003341 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003342 ASSERT_VK_SUCCESS(err);
3343
Tony Barboureb254902015-07-15 12:50:33 -06003344 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3345 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3346 pipe_ms_state_ci.pNext = NULL;
3347 pipe_ms_state_ci.rasterSamples = 1;
3348 pipe_ms_state_ci.sampleShadingEnable = 0;
3349 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06003350 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003351
Tony Barboureb254902015-07-15 12:50:33 -06003352 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3353 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3354 pipeline_layout_ci.pNext = NULL;
3355 pipeline_layout_ci.descriptorSetCount = 1;
3356 pipeline_layout_ci.pSetLayouts = &ds_layout;
3357 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06003358
Tobin Ehlis502480b2015-06-24 15:53:07 -06003359 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3360 ASSERT_VK_SUCCESS(err);
3361
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003362 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3363 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 -06003364 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003365 VkPipelineObj pipe(m_device);
3366 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003367 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003368 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003369 pipe.SetViewport(m_viewports);
3370 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003371 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003372
3373 BeginCommandBuffer();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06003374 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06003375 // Don't care about actual data, just need to get to draw to flag error
3376 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3377 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3378 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003379 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003380
3381 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003382 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 -06003383 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 -06003384 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 -06003385 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003386
3387 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003388 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3389 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06003390}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003391#endif // DRAW_STATE_TESTS
3392
Tobin Ehlis0788f522015-05-26 16:11:58 -06003393#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06003394#if GTEST_IS_THREADSAFE
3395struct thread_data_struct {
3396 VkCmdBuffer cmdBuffer;
3397 VkEvent event;
3398 bool bailout;
3399};
3400
3401extern "C" void *AddToCommandBuffer(void *arg)
3402{
3403 struct thread_data_struct *data = (struct thread_data_struct *) arg;
3404 std::string msgString;
3405
3406 for (int i = 0; i<10000; i++) {
Tony Barbour0b2cfb22015-06-29 16:20:35 -06003407 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003408 if (data->bailout) {
3409 break;
3410 }
3411 }
3412 return NULL;
3413}
3414
3415TEST_F(VkLayerTest, ThreadCmdBufferCollision)
3416{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003417 VkFlags msgFlags;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003418 std::string msgString;
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003419 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003420
3421 ASSERT_NO_FATAL_FAILURE(InitState());
3422 ASSERT_NO_FATAL_FAILURE(InitViewport());
3423 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3424
Mike Stroyanaccf7692015-05-12 16:00:45 -06003425 m_errorMonitor->ClearState();
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003426
3427 // Calls CreateCommandBuffer
3428 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
3429
3430 // Avoid creating RenderPass
3431 cmdBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003432
3433 VkEventCreateInfo event_info;
3434 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06003435 VkResult err;
3436
3437 memset(&event_info, 0, sizeof(event_info));
3438 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3439
3440 err = vkCreateEvent(device(), &event_info, &event);
3441 ASSERT_VK_SUCCESS(err);
3442
Mike Stroyanaccf7692015-05-12 16:00:45 -06003443 err = vkResetEvent(device(), event);
3444 ASSERT_VK_SUCCESS(err);
3445
3446 struct thread_data_struct data;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003447 data.cmdBuffer = cmdBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003448 data.event = event;
3449 data.bailout = false;
3450 m_errorMonitor->SetBailout(&data.bailout);
3451 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003452 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003453 // Add many entries to command buffer from this thread at the same time.
3454 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003455
Mike Stroyan4268d1f2015-07-13 14:45:35 -06003456 test_platform_thread_join(thread, NULL);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06003457 cmdBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06003458
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003459 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06003460 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 -06003461 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -05003462 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyanaccf7692015-05-12 16:00:45 -06003463 }
3464
Mike Stroyand1c84a52015-08-18 14:40:24 -06003465 vkDestroyEvent(device(), event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06003466}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003467#endif // GTEST_IS_THREADSAFE
3468#endif // THREADING_TESTS
3469
Chris Forbes9f7ff632015-05-25 11:13:08 +12003470#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003471TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
3472{
3473 VkFlags msgFlags;
3474 std::string msgString;
3475 ASSERT_NO_FATAL_FAILURE(InitState());
3476 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3477
3478 m_errorMonitor->ClearState();
3479
3480 VkShaderModule module;
3481 VkShaderModuleCreateInfo moduleCreateInfo;
3482 struct icd_spv_header spv;
3483
3484 spv.magic = ICD_SPV_MAGIC;
3485 spv.version = ICD_SPV_VERSION;
3486 spv.gen_magic = 0;
3487
3488 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3489 moduleCreateInfo.pNext = NULL;
3490 moduleCreateInfo.pCode = &spv;
3491 moduleCreateInfo.codeSize = 4;
3492 moduleCreateInfo.flags = 0;
3493 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3494
3495 msgFlags = m_errorMonitor->GetState(&msgString);
3496
Chris Forbes46794b82015-09-18 11:40:23 +12003497 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003498 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3499 FAIL() << "Incorrect warning: " << msgString;
3500 }
3501}
3502
3503TEST_F(VkLayerTest, InvalidSPIRVMagic)
3504{
3505 VkFlags msgFlags;
3506 std::string msgString;
3507 ASSERT_NO_FATAL_FAILURE(InitState());
3508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3509
3510 m_errorMonitor->ClearState();
3511
3512 VkShaderModule module;
3513 VkShaderModuleCreateInfo moduleCreateInfo;
3514 struct icd_spv_header spv;
3515
3516 spv.magic = ~ICD_SPV_MAGIC;
3517 spv.version = ICD_SPV_VERSION;
3518 spv.gen_magic = 0;
3519
3520 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3521 moduleCreateInfo.pNext = NULL;
3522 moduleCreateInfo.pCode = &spv;
3523 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3524 moduleCreateInfo.flags = 0;
3525 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3526
3527 msgFlags = m_errorMonitor->GetState(&msgString);
3528
Chris Forbes46794b82015-09-18 11:40:23 +12003529 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003530 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3531 FAIL() << "Incorrect warning: " << msgString;
3532 }
3533}
3534
3535TEST_F(VkLayerTest, InvalidSPIRVVersion)
3536{
3537 VkFlags msgFlags;
3538 std::string msgString;
3539 ASSERT_NO_FATAL_FAILURE(InitState());
3540 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3541
3542 m_errorMonitor->ClearState();
3543
3544 VkShaderModule module;
3545 VkShaderModuleCreateInfo moduleCreateInfo;
3546 struct icd_spv_header spv;
3547
3548 spv.magic = ICD_SPV_MAGIC;
3549 spv.version = ~ICD_SPV_VERSION;
3550 spv.gen_magic = 0;
3551
3552 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3553 moduleCreateInfo.pNext = NULL;
3554
3555 moduleCreateInfo.pCode = &spv;
3556 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3557 moduleCreateInfo.flags = 0;
3558 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3559
3560 msgFlags = m_errorMonitor->GetState(&msgString);
3561
Chris Forbes46794b82015-09-18 11:40:23 +12003562 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06003563 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3564 FAIL() << "Incorrect warning: " << msgString;
3565 }
3566}
3567
Chris Forbes9f7ff632015-05-25 11:13:08 +12003568TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
3569{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003570 VkFlags msgFlags;
Chris Forbes9f7ff632015-05-25 11:13:08 +12003571 std::string msgString;
3572 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003573 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12003574
3575 char const *vsSource =
3576 "#version 140\n"
3577 "#extension GL_ARB_separate_shader_objects: require\n"
3578 "#extension GL_ARB_shading_language_420pack: require\n"
3579 "\n"
3580 "layout(location=0) out float x;\n"
3581 "void main(){\n"
3582 " gl_Position = vec4(1);\n"
3583 " x = 0;\n"
3584 "}\n";
3585 char const *fsSource =
3586 "#version 140\n"
3587 "#extension GL_ARB_separate_shader_objects: require\n"
3588 "#extension GL_ARB_shading_language_420pack: require\n"
3589 "\n"
3590 "layout(location=0) out vec4 color;\n"
3591 "void main(){\n"
3592 " color = vec4(1);\n"
3593 "}\n";
3594
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003595 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3596 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12003597
3598 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003599 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12003600 pipe.AddShader(&vs);
3601 pipe.AddShader(&fs);
3602
Chris Forbes9f7ff632015-05-25 11:13:08 +12003603 VkDescriptorSetObj descriptorSet(m_device);
3604 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003605 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12003606
3607 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003608 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12003609
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003610 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes9f7ff632015-05-25 11:13:08 +12003611
Cody Northropd2ad0342015-08-05 11:15:02 -06003612 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes9f7ff632015-05-25 11:13:08 +12003613 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
3614 FAIL() << "Incorrect warning: " << msgString;
3615 }
3616}
Chris Forbes9f7ff632015-05-25 11:13:08 +12003617
Chris Forbes59cb88d2015-05-25 11:13:13 +12003618TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
3619{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003620 VkFlags msgFlags;
Chris Forbes59cb88d2015-05-25 11:13:13 +12003621 std::string msgString;
3622 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003623 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12003624
3625 char const *vsSource =
3626 "#version 140\n"
3627 "#extension GL_ARB_separate_shader_objects: require\n"
3628 "#extension GL_ARB_shading_language_420pack: require\n"
3629 "\n"
3630 "void main(){\n"
3631 " gl_Position = vec4(1);\n"
3632 "}\n";
3633 char const *fsSource =
3634 "#version 140\n"
3635 "#extension GL_ARB_separate_shader_objects: require\n"
3636 "#extension GL_ARB_shading_language_420pack: require\n"
3637 "\n"
3638 "layout(location=0) in float x;\n"
3639 "layout(location=0) out vec4 color;\n"
3640 "void main(){\n"
3641 " color = vec4(x);\n"
3642 "}\n";
3643
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003644 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3645 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12003646
3647 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003648 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12003649 pipe.AddShader(&vs);
3650 pipe.AddShader(&fs);
3651
Chris Forbes59cb88d2015-05-25 11:13:13 +12003652 VkDescriptorSetObj descriptorSet(m_device);
3653 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003654 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12003655
3656 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003657 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12003658
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003659 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes59cb88d2015-05-25 11:13:13 +12003660
Cody Northropd2ad0342015-08-05 11:15:02 -06003661 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes59cb88d2015-05-25 11:13:13 +12003662 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
3663 FAIL() << "Incorrect error: " << msgString;
3664 }
3665}
3666
Chris Forbesb56af562015-05-25 11:13:17 +12003667TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
3668{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003669 VkFlags msgFlags;
Chris Forbesb56af562015-05-25 11:13:17 +12003670 std::string msgString;
3671 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003672 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12003673
3674 char const *vsSource =
3675 "#version 140\n"
3676 "#extension GL_ARB_separate_shader_objects: require\n"
3677 "#extension GL_ARB_shading_language_420pack: require\n"
3678 "\n"
3679 "layout(location=0) out int x;\n"
3680 "void main(){\n"
3681 " x = 0;\n"
3682 " gl_Position = vec4(1);\n"
3683 "}\n";
3684 char const *fsSource =
3685 "#version 140\n"
3686 "#extension GL_ARB_separate_shader_objects: require\n"
3687 "#extension GL_ARB_shading_language_420pack: require\n"
3688 "\n"
3689 "layout(location=0) in float x;\n" /* VS writes int */
3690 "layout(location=0) out vec4 color;\n"
3691 "void main(){\n"
3692 " color = vec4(x);\n"
3693 "}\n";
3694
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003695 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3696 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12003697
3698 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003699 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12003700 pipe.AddShader(&vs);
3701 pipe.AddShader(&fs);
3702
Chris Forbesb56af562015-05-25 11:13:17 +12003703 VkDescriptorSetObj descriptorSet(m_device);
3704 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003705 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12003706
3707 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003708 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12003709
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003710 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesb56af562015-05-25 11:13:17 +12003711
Cody Northropd2ad0342015-08-05 11:15:02 -06003712 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesb56af562015-05-25 11:13:17 +12003713 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
3714 FAIL() << "Incorrect error: " << msgString;
3715 }
3716}
3717
Chris Forbesde136e02015-05-25 11:13:28 +12003718TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
3719{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003720 VkFlags msgFlags;
Chris Forbesde136e02015-05-25 11:13:28 +12003721 std::string msgString;
3722 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12003724
3725 VkVertexInputBindingDescription input_binding;
3726 memset(&input_binding, 0, sizeof(input_binding));
3727
3728 VkVertexInputAttributeDescription input_attrib;
3729 memset(&input_attrib, 0, sizeof(input_attrib));
3730 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3731
3732 char const *vsSource =
3733 "#version 140\n"
3734 "#extension GL_ARB_separate_shader_objects: require\n"
3735 "#extension GL_ARB_shading_language_420pack: require\n"
3736 "\n"
3737 "void main(){\n"
3738 " gl_Position = vec4(1);\n"
3739 "}\n";
3740 char const *fsSource =
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 vec4 color;\n"
3746 "void main(){\n"
3747 " color = vec4(1);\n"
3748 "}\n";
3749
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003750 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3751 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12003752
3753 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003754 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12003755 pipe.AddShader(&vs);
3756 pipe.AddShader(&fs);
3757
3758 pipe.AddVertexInputBindings(&input_binding, 1);
3759 pipe.AddVertexInputAttribs(&input_attrib, 1);
3760
Chris Forbesde136e02015-05-25 11:13:28 +12003761 VkDescriptorSetObj descriptorSet(m_device);
3762 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003763 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12003764
3765 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003766 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12003767
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003768 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesde136e02015-05-25 11:13:28 +12003769
Cody Northropd2ad0342015-08-05 11:15:02 -06003770 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesde136e02015-05-25 11:13:28 +12003771 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
3772 FAIL() << "Incorrect warning: " << msgString;
3773 }
3774}
3775
Chris Forbes62e8e502015-05-25 11:13:29 +12003776TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
3777{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003778 VkFlags msgFlags;
Chris Forbes62e8e502015-05-25 11:13:29 +12003779 std::string msgString;
3780 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12003782
3783 char const *vsSource =
3784 "#version 140\n"
3785 "#extension GL_ARB_separate_shader_objects: require\n"
3786 "#extension GL_ARB_shading_language_420pack: require\n"
3787 "\n"
3788 "layout(location=0) in vec4 x;\n" /* not provided */
3789 "void main(){\n"
3790 " gl_Position = x;\n"
3791 "}\n";
3792 char const *fsSource =
3793 "#version 140\n"
3794 "#extension GL_ARB_separate_shader_objects: require\n"
3795 "#extension GL_ARB_shading_language_420pack: require\n"
3796 "\n"
3797 "layout(location=0) out vec4 color;\n"
3798 "void main(){\n"
3799 " color = vec4(1);\n"
3800 "}\n";
3801
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003802 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3803 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12003804
3805 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003806 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12003807 pipe.AddShader(&vs);
3808 pipe.AddShader(&fs);
3809
Chris Forbes62e8e502015-05-25 11:13:29 +12003810 VkDescriptorSetObj descriptorSet(m_device);
3811 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003812 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12003813
3814 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003815 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12003816
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003817 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes62e8e502015-05-25 11:13:29 +12003818
Cody Northropd2ad0342015-08-05 11:15:02 -06003819 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes62e8e502015-05-25 11:13:29 +12003820 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
3821 FAIL() << "Incorrect warning: " << msgString;
3822 }
3823}
3824
Chris Forbesc97d98e2015-05-25 11:13:31 +12003825TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
3826{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003827 VkFlags msgFlags;
Chris Forbesc97d98e2015-05-25 11:13:31 +12003828 std::string msgString;
3829 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12003831
3832 VkVertexInputBindingDescription input_binding;
3833 memset(&input_binding, 0, sizeof(input_binding));
3834
3835 VkVertexInputAttributeDescription input_attrib;
3836 memset(&input_attrib, 0, sizeof(input_attrib));
3837 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3838
3839 char const *vsSource =
3840 "#version 140\n"
3841 "#extension GL_ARB_separate_shader_objects: require\n"
3842 "#extension GL_ARB_shading_language_420pack: require\n"
3843 "\n"
3844 "layout(location=0) in int x;\n" /* attrib provided float */
3845 "void main(){\n"
3846 " gl_Position = vec4(x);\n"
3847 "}\n";
3848 char const *fsSource =
3849 "#version 140\n"
3850 "#extension GL_ARB_separate_shader_objects: require\n"
3851 "#extension GL_ARB_shading_language_420pack: require\n"
3852 "\n"
3853 "layout(location=0) out vec4 color;\n"
3854 "void main(){\n"
3855 " color = vec4(1);\n"
3856 "}\n";
3857
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003858 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3859 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12003860
3861 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003862 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12003863 pipe.AddShader(&vs);
3864 pipe.AddShader(&fs);
3865
3866 pipe.AddVertexInputBindings(&input_binding, 1);
3867 pipe.AddVertexInputAttribs(&input_attrib, 1);
3868
Chris Forbesc97d98e2015-05-25 11:13:31 +12003869 VkDescriptorSetObj descriptorSet(m_device);
3870 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003871 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12003872
3873 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003874 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12003875
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003876 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc97d98e2015-05-25 11:13:31 +12003877
Cody Northropd2ad0342015-08-05 11:15:02 -06003878 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc97d98e2015-05-25 11:13:31 +12003879 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
3880 FAIL() << "Incorrect error: " << msgString;
3881 }
3882}
3883
Chris Forbes280ba2c2015-06-12 11:16:41 +12003884TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
3885{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003886 VkFlags msgFlags;
Chris Forbes280ba2c2015-06-12 11:16:41 +12003887 std::string msgString;
3888 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12003890
3891 /* Two binding descriptions for binding 0 */
3892 VkVertexInputBindingDescription input_bindings[2];
3893 memset(input_bindings, 0, sizeof(input_bindings));
3894
3895 VkVertexInputAttributeDescription input_attrib;
3896 memset(&input_attrib, 0, sizeof(input_attrib));
3897 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3898
3899 char const *vsSource =
3900 "#version 140\n"
3901 "#extension GL_ARB_separate_shader_objects: require\n"
3902 "#extension GL_ARB_shading_language_420pack: require\n"
3903 "\n"
3904 "layout(location=0) in float x;\n" /* attrib provided float */
3905 "void main(){\n"
3906 " gl_Position = vec4(x);\n"
3907 "}\n";
3908 char const *fsSource =
3909 "#version 140\n"
3910 "#extension GL_ARB_separate_shader_objects: require\n"
3911 "#extension GL_ARB_shading_language_420pack: require\n"
3912 "\n"
3913 "layout(location=0) out vec4 color;\n"
3914 "void main(){\n"
3915 " color = vec4(1);\n"
3916 "}\n";
3917
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003918 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3919 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12003920
3921 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003922 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12003923 pipe.AddShader(&vs);
3924 pipe.AddShader(&fs);
3925
3926 pipe.AddVertexInputBindings(input_bindings, 2);
3927 pipe.AddVertexInputAttribs(&input_attrib, 1);
3928
Chris Forbes280ba2c2015-06-12 11:16:41 +12003929 VkDescriptorSetObj descriptorSet(m_device);
3930 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003931 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12003932
3933 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003934 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12003935
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003936 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes280ba2c2015-06-12 11:16:41 +12003937
Cody Northropd2ad0342015-08-05 11:15:02 -06003938 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes280ba2c2015-06-12 11:16:41 +12003939 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
3940 FAIL() << "Incorrect error: " << msgString;
3941 }
3942}
Chris Forbes8f68b562015-05-25 11:13:32 +12003943
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003944/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
3945 * rejects it. */
3946
3947TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
3948{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003949 VkFlags msgFlags;
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003950 std::string msgString;
3951 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003952
3953 char const *vsSource =
3954 "#version 140\n"
3955 "#extension GL_ARB_separate_shader_objects: require\n"
3956 "#extension GL_ARB_shading_language_420pack: require\n"
3957 "\n"
3958 "void main(){\n"
3959 " gl_Position = vec4(1);\n"
3960 "}\n";
3961 char const *fsSource =
3962 "#version 140\n"
3963 "#extension GL_ARB_separate_shader_objects: require\n"
3964 "#extension GL_ARB_shading_language_420pack: require\n"
3965 "\n"
3966 "void main(){\n"
3967 "}\n";
3968
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003969 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3970 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003971
3972 VkPipelineObj pipe(m_device);
3973 pipe.AddShader(&vs);
3974 pipe.AddShader(&fs);
3975
Chia-I Wu08accc62015-07-07 11:50:03 +08003976 /* set up CB 0, not written */
3977 pipe.AddColorAttachment();
3978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003979
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003980 VkDescriptorSetObj descriptorSet(m_device);
3981 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003982 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003983
3984 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003985 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003986
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003987 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003988
Cody Northropd2ad0342015-08-05 11:15:02 -06003989 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003990 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
3991 FAIL() << "Incorrect error: " << msgString;
3992 }
3993}
3994
Chris Forbesf3fffaa2015-05-25 11:13:43 +12003995TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
3996{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003997 VkFlags msgFlags;
Chris Forbesf3fffaa2015-05-25 11:13:43 +12003998 std::string msgString;
3999 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004000
4001 char const *vsSource =
4002 "#version 140\n"
4003 "#extension GL_ARB_separate_shader_objects: require\n"
4004 "#extension GL_ARB_shading_language_420pack: require\n"
4005 "\n"
4006 "void main(){\n"
4007 " gl_Position = vec4(1);\n"
4008 "}\n";
4009 char const *fsSource =
4010 "#version 140\n"
4011 "#extension GL_ARB_separate_shader_objects: require\n"
4012 "#extension GL_ARB_shading_language_420pack: require\n"
4013 "\n"
4014 "layout(location=0) out vec4 x;\n"
4015 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4016 "void main(){\n"
4017 " x = vec4(1);\n"
4018 " y = vec4(1);\n"
4019 "}\n";
4020
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004021 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4022 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004023
4024 VkPipelineObj pipe(m_device);
4025 pipe.AddShader(&vs);
4026 pipe.AddShader(&fs);
4027
Chia-I Wu08accc62015-07-07 11:50:03 +08004028 /* set up CB 0, not written */
4029 pipe.AddColorAttachment();
4030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004031 /* FS writes CB 1, but we don't configure it */
4032
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004033 VkDescriptorSetObj descriptorSet(m_device);
4034 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06004035 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004036
4037 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004038 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004039
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004040 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004041
Cody Northropd2ad0342015-08-05 11:15:02 -06004042 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12004043 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
4044 FAIL() << "Incorrect warning: " << msgString;
4045 }
4046}
4047
Chris Forbesa36d69e2015-05-25 11:13:44 +12004048TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4049{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004050 VkFlags msgFlags;
Chris Forbesa36d69e2015-05-25 11:13:44 +12004051 std::string msgString;
4052 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004053
4054 char const *vsSource =
4055 "#version 140\n"
4056 "#extension GL_ARB_separate_shader_objects: require\n"
4057 "#extension GL_ARB_shading_language_420pack: require\n"
4058 "\n"
4059 "void main(){\n"
4060 " gl_Position = vec4(1);\n"
4061 "}\n";
4062 char const *fsSource =
4063 "#version 140\n"
4064 "#extension GL_ARB_separate_shader_objects: require\n"
4065 "#extension GL_ARB_shading_language_420pack: require\n"
4066 "\n"
4067 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4068 "void main(){\n"
4069 " x = ivec4(1);\n"
4070 "}\n";
4071
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004072 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4073 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004074
4075 VkPipelineObj pipe(m_device);
4076 pipe.AddShader(&vs);
4077 pipe.AddShader(&fs);
4078
Chia-I Wu08accc62015-07-07 11:50:03 +08004079 /* set up CB 0; type is UNORM by default */
4080 pipe.AddColorAttachment();
4081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004082
Chris Forbesa36d69e2015-05-25 11:13:44 +12004083 VkDescriptorSetObj descriptorSet(m_device);
4084 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06004085 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004086
4087 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06004088 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12004089
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004090 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa36d69e2015-05-25 11:13:44 +12004091
Cody Northropd2ad0342015-08-05 11:15:02 -06004092 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa36d69e2015-05-25 11:13:44 +12004093 if (!strstr(msgString.c_str(),"does not match FS output type")) {
4094 FAIL() << "Incorrect error: " << msgString;
4095 }
4096}
Chris Forbes7b1b8932015-06-05 14:43:36 +12004097
Chris Forbes556c76c2015-08-14 12:04:59 +12004098TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4099{
4100 VkFlags msgFlags;
4101 std::string msgString;
4102 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12004103
4104 char const *vsSource =
4105 "#version 140\n"
4106 "#extension GL_ARB_separate_shader_objects: require\n"
4107 "#extension GL_ARB_shading_language_420pack: require\n"
4108 "\n"
4109 "void main(){\n"
4110 " gl_Position = vec4(1);\n"
4111 "}\n";
4112 char const *fsSource =
4113 "#version 140\n"
4114 "#extension GL_ARB_separate_shader_objects: require\n"
4115 "#extension GL_ARB_shading_language_420pack: require\n"
4116 "\n"
4117 "layout(location=0) out vec4 x;\n"
4118 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4119 "void main(){\n"
4120 " x = vec4(bar.y);\n"
4121 "}\n";
4122
4123 m_errorMonitor->ClearState();
4124
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004125 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4126 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12004127
4128
4129 VkPipelineObj pipe(m_device);
4130 pipe.AddShader(&vs);
4131 pipe.AddShader(&fs);
4132
4133 /* set up CB 0; type is UNORM by default */
4134 pipe.AddColorAttachment();
4135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4136
4137 VkDescriptorSetObj descriptorSet(m_device);
4138 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
4139
4140 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4141
4142 /* should have generated an error -- pipeline layout does not
4143 * provide a uniform buffer in 0.0
4144 */
4145 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -06004146 ASSERT_TRUE((msgFlags & VK_DBG_REPORT_ERROR_BIT) == VK_DBG_REPORT_ERROR_BIT);
Chris Forbes556c76c2015-08-14 12:04:59 +12004147 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
4148 FAIL() << "Incorrect error: " << msgString;
4149 }
4150}
4151
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004152#endif // SHADER_CHECKER_TESTS
4153
4154#if DEVICE_LIMITS_TESTS
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004155TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4156{
4157 VkFlags msgFlags;
4158 std::string msgString;
4159
4160 ASSERT_NO_FATAL_FAILURE(InitState());
4161 m_errorMonitor->ClearState();
4162
4163 // Create an image
4164 VkImage image;
4165
4166 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4167 const int32_t tex_width = 32;
4168 const int32_t tex_height = 32;
4169
4170 VkImageCreateInfo image_create_info = {};
4171 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4172 image_create_info.pNext = NULL;
4173 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4174 image_create_info.format = tex_format;
4175 image_create_info.extent.width = tex_width;
4176 image_create_info.extent.height = tex_height;
4177 image_create_info.extent.depth = 1;
4178 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004179 image_create_info.arrayLayers = 1;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004180 image_create_info.samples = 1;
4181 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4182 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4183 image_create_info.flags = 0;
4184
4185 // Introduce error by sending down a bogus width extent
4186 image_create_info.extent.width = 65536;
4187 vkCreateImage(m_device->device(), &image_create_info, &image);
4188
4189 msgFlags = m_errorMonitor->GetState(&msgString);
4190 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4191 "with extents outside the queried limits";
4192 if (!strstr(msgString.c_str(),"CreateImage extents exceed allowable limits for format")) {
4193 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4194 }
4195}
4196
4197TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4198{
4199 VkFlags msgFlags;
4200 std::string msgString;
4201
4202 ASSERT_NO_FATAL_FAILURE(InitState());
4203 m_errorMonitor->ClearState();
4204
4205 // Create an image
4206 VkImage image;
4207
4208 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4209 const int32_t tex_width = 32;
4210 const int32_t tex_height = 32;
4211
4212 VkImageCreateInfo image_create_info = {};
4213 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4214 image_create_info.pNext = NULL;
4215 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4216 image_create_info.format = tex_format;
4217 image_create_info.extent.width = tex_width;
4218 image_create_info.extent.height = tex_height;
4219 image_create_info.extent.depth = 1;
4220 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004221 image_create_info.arrayLayers = 1;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004222 image_create_info.samples = 1;
4223 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4224 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4225 image_create_info.flags = 0;
4226
4227 // Introduce error by sending down individually allowable values that result in a surface size
4228 // exceeding the device maximum
4229 image_create_info.extent.width = 8192;
4230 image_create_info.extent.height = 8192;
4231 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004232 image_create_info.arrayLayers = 4;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06004233 image_create_info.samples = 2;
4234 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
4235 vkCreateImage(m_device->device(), &image_create_info, &image);
4236
4237 msgFlags = m_errorMonitor->GetState(&msgString);
4238 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4239 "with resource size exceeding queried limit";
4240 if (!strstr(msgString.c_str(),"CreateImage resource size exceeds allowable maximum")) {
4241 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4242 }
4243}
4244
Mike Stroyana3082432015-09-25 13:39:21 -06004245TEST_F(VkLayerTest, UpdateBufferAlignment)
4246{
4247 VkFlags msgFlags;
4248 std::string msgString;
4249 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4250
4251 ASSERT_NO_FATAL_FAILURE(InitState());
4252
4253 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4254 vk_testing::Buffer buffer;
4255 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4256
4257 BeginCommandBuffer();
4258 // Introduce failure by using offset that is not multiple of 4
4259 m_cmdBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
4260 msgFlags = m_errorMonitor->GetState(&msgString);
4261 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad offset";
4262 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4263 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4264 }
4265 // Introduce failure by using size that is not multiple of 4
4266 m_cmdBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
4267 msgFlags = m_errorMonitor->GetState(&msgString);
4268 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad size";
4269 if (!strstr(msgString.c_str(),"dataSize, is not a multiple of 4")) {
4270 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4271 }
4272 EndCommandBuffer();
4273}
4274
4275TEST_F(VkLayerTest, FillBufferAlignment)
4276{
4277 VkFlags msgFlags;
4278 std::string msgString;
4279
4280 ASSERT_NO_FATAL_FAILURE(InitState());
4281
4282 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4283 vk_testing::Buffer buffer;
4284 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4285
4286 BeginCommandBuffer();
4287 // Introduce failure by using offset that is not multiple of 4
4288 m_cmdBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
4289 msgFlags = m_errorMonitor->GetState(&msgString);
4290 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad offset";
4291 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4292 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4293 }
4294 // Introduce failure by using size that is not multiple of 4
4295 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
4296 msgFlags = m_errorMonitor->GetState(&msgString);
4297 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad size";
4298 if (!strstr(msgString.c_str(),"fillSize, is not a multiple of 4")) {
4299 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize fillSize, is not a multiple of 4'";
4300 }
4301 EndCommandBuffer();
4302}
4303
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004304#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12004305
Tobin Ehliscde08892015-09-22 10:11:37 -06004306#if IMAGE_TESTS
4307TEST_F(VkLayerTest, InvalidImageView)
4308{
4309 VkFlags msgFlags;
4310 std::string msgString;
4311 VkResult err;
4312
4313 ASSERT_NO_FATAL_FAILURE(InitState());
4314 m_errorMonitor->ClearState();
4315
Mike Stroyana3082432015-09-25 13:39:21 -06004316 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehliscde08892015-09-22 10:11:37 -06004317 VkImage image;
4318
4319 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4320 const int32_t tex_width = 32;
4321 const int32_t tex_height = 32;
4322
4323 VkImageCreateInfo image_create_info = {};
4324 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4325 image_create_info.pNext = NULL;
4326 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4327 image_create_info.format = tex_format;
4328 image_create_info.extent.width = tex_width;
4329 image_create_info.extent.height = tex_height;
4330 image_create_info.extent.depth = 1;
4331 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004332 image_create_info.arrayLayers = 1;
Tobin Ehliscde08892015-09-22 10:11:37 -06004333 image_create_info.samples = 1;
4334 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4335 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4336 image_create_info.flags = 0;
4337
4338 err = vkCreateImage(m_device->device(), &image_create_info, &image);
4339 ASSERT_VK_SUCCESS(err);
4340
4341 VkImageViewCreateInfo image_view_create_info = {};
4342 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4343 image_view_create_info.image = image;
4344 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4345 image_view_create_info.format = tex_format;
4346 image_view_create_info.subresourceRange.arraySize = 1;
4347 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
4348 image_view_create_info.subresourceRange.mipLevels = 1;
4349
4350 VkImageView view;
4351 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
4352
4353 msgFlags = m_errorMonitor->GetState(&msgString);
4354 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an invalid ImageView";
4355 if (!strstr(msgString.c_str(),"vkCreateImageView called with baseMipLevel 10 ")) {
Mike Stroyana3082432015-09-25 13:39:21 -06004356 FAIL() << "Error received was not 'vkCreateImageView called with baseMipLevel 10...' but instead '" << msgString.c_str() << "'";
Tobin Ehliscde08892015-09-22 10:11:37 -06004357 }
4358}
Mike Stroyana3082432015-09-25 13:39:21 -06004359
4360TEST_F(VkLayerTest, CopyImageTypeMismatch)
4361{
4362 VkFlags msgFlags;
4363 std::string msgString;
4364 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004365 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004366
4367 ASSERT_NO_FATAL_FAILURE(InitState());
4368 m_errorMonitor->ClearState();
4369
4370 // Create two images of different types and try to copy between them
4371 VkImage srcImage;
4372 VkImage destImage;
4373 VkDeviceMemory srcMem;
4374 VkDeviceMemory destMem;
4375 VkMemoryRequirements memReqs;
4376
4377 VkImageCreateInfo image_create_info = {};
4378 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4379 image_create_info.pNext = NULL;
4380 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4381 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4382 image_create_info.extent.width = 32;
4383 image_create_info.extent.height = 32;
4384 image_create_info.extent.depth = 1;
4385 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004386 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004387 image_create_info.samples = 1;
4388 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4389 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4390 image_create_info.flags = 0;
4391
4392 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4393 ASSERT_VK_SUCCESS(err);
4394
4395 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4396 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4397
4398 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4399 ASSERT_VK_SUCCESS(err);
4400
4401 // Allocate memory
4402 VkMemoryAllocInfo memAlloc = {};
4403 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4404 memAlloc.pNext = NULL;
4405 memAlloc.allocationSize = 0;
4406 memAlloc.memoryTypeIndex = 0;
4407
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004408 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004409 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004410 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4411 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004412 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4413 ASSERT_VK_SUCCESS(err);
4414
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004415 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004416 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004417 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06004418 ASSERT_VK_SUCCESS(err);
4419 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4420 ASSERT_VK_SUCCESS(err);
4421
4422 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4423 ASSERT_VK_SUCCESS(err);
4424 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4425 ASSERT_VK_SUCCESS(err);
4426
4427 BeginCommandBuffer();
4428 VkImageCopy copyRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004429 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004430 copyRegion.srcSubresource.mipLevel = 0;
4431 copyRegion.srcSubresource.arrayLayer = 0;
4432 copyRegion.srcSubresource.arraySize = 0;
4433 copyRegion.srcOffset.x = 0;
4434 copyRegion.srcOffset.y = 0;
4435 copyRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004436 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004437 copyRegion.destSubresource.mipLevel = 0;
4438 copyRegion.destSubresource.arrayLayer = 0;
4439 copyRegion.destSubresource.arraySize = 0;
4440 copyRegion.destOffset.x = 0;
4441 copyRegion.destOffset.y = 0;
4442 copyRegion.destOffset.z = 0;
4443 copyRegion.extent.width = 1;
4444 copyRegion.extent.height = 1;
4445 copyRegion.extent.depth = 1;
4446 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4447 EndCommandBuffer();
4448
4449 msgFlags = m_errorMonitor->GetState(&msgString);
4450 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4451 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4452 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4453 }
4454
4455 vkDestroyImage(m_device->device(), srcImage);
4456 vkDestroyImage(m_device->device(), destImage);
4457 vkFreeMemory(m_device->device(), srcMem);
4458 vkFreeMemory(m_device->device(), destMem);
4459}
4460
4461TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
4462{
4463 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
4464}
4465
4466TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
4467{
4468 VkFlags msgFlags;
4469 std::string msgString;
4470 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004471 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004472
4473 ASSERT_NO_FATAL_FAILURE(InitState());
4474 m_errorMonitor->ClearState();
4475
4476 // Create two images of different types and try to copy between them
4477 VkImage srcImage;
4478 VkImage destImage;
4479 VkDeviceMemory srcMem;
4480 VkDeviceMemory destMem;
4481 VkMemoryRequirements memReqs;
4482
4483 VkImageCreateInfo image_create_info = {};
4484 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4485 image_create_info.pNext = NULL;
4486 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4487 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4488 image_create_info.extent.width = 32;
4489 image_create_info.extent.height = 32;
4490 image_create_info.extent.depth = 1;
4491 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004492 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004493 image_create_info.samples = 1;
4494 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4495 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4496 image_create_info.flags = 0;
4497
4498 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4499 ASSERT_VK_SUCCESS(err);
4500
4501 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4502 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4503
4504 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4505 ASSERT_VK_SUCCESS(err);
4506
4507 // Allocate memory
4508 VkMemoryAllocInfo memAlloc = {};
4509 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4510 memAlloc.pNext = NULL;
4511 memAlloc.allocationSize = 0;
4512 memAlloc.memoryTypeIndex = 0;
4513
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004514 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004515 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004516 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4517 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004518 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4519 ASSERT_VK_SUCCESS(err);
4520
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004521 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004522 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004523 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4524 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004525 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4526 ASSERT_VK_SUCCESS(err);
4527
4528 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4529 ASSERT_VK_SUCCESS(err);
4530 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4531 ASSERT_VK_SUCCESS(err);
4532
4533 BeginCommandBuffer();
4534 VkImageCopy copyRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004535 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004536 copyRegion.srcSubresource.mipLevel = 0;
4537 copyRegion.srcSubresource.arrayLayer = 0;
4538 copyRegion.srcSubresource.arraySize = 0;
4539 copyRegion.srcOffset.x = 0;
4540 copyRegion.srcOffset.y = 0;
4541 copyRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004542 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004543 copyRegion.destSubresource.mipLevel = 0;
4544 copyRegion.destSubresource.arrayLayer = 0;
4545 copyRegion.destSubresource.arraySize = 0;
4546 copyRegion.destOffset.x = 0;
4547 copyRegion.destOffset.y = 0;
4548 copyRegion.destOffset.z = 0;
4549 copyRegion.extent.width = 1;
4550 copyRegion.extent.height = 1;
4551 copyRegion.extent.depth = 1;
4552 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4553 EndCommandBuffer();
4554
4555 msgFlags = m_errorMonitor->GetState(&msgString);
4556 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4557 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4558 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4559 }
4560
4561 vkDestroyImage(m_device->device(), srcImage);
4562 vkDestroyImage(m_device->device(), destImage);
4563 vkFreeMemory(m_device->device(), srcMem);
4564 vkFreeMemory(m_device->device(), destMem);
4565}
4566
4567TEST_F(VkLayerTest, ResolveImageLowSampleCount)
4568{
4569 VkFlags msgFlags;
4570 std::string msgString;
4571 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004572 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004573
4574 ASSERT_NO_FATAL_FAILURE(InitState());
4575 m_errorMonitor->ClearState();
4576
4577 // Create two images of sample count 1 and try to Resolve between them
4578 VkImage srcImage;
4579 VkImage destImage;
4580 VkDeviceMemory srcMem;
4581 VkDeviceMemory destMem;
4582 VkMemoryRequirements memReqs;
4583
4584 VkImageCreateInfo image_create_info = {};
4585 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4586 image_create_info.pNext = NULL;
4587 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4588 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4589 image_create_info.extent.width = 32;
4590 image_create_info.extent.height = 1;
4591 image_create_info.extent.depth = 1;
4592 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004593 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004594 image_create_info.samples = 1;
4595 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4596 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4597 image_create_info.flags = 0;
4598
4599 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4600 ASSERT_VK_SUCCESS(err);
4601
4602 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4603 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4604
4605 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4606 ASSERT_VK_SUCCESS(err);
4607
4608 // Allocate memory
4609 VkMemoryAllocInfo memAlloc = {};
4610 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4611 memAlloc.pNext = NULL;
4612 memAlloc.allocationSize = 0;
4613 memAlloc.memoryTypeIndex = 0;
4614
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004615 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004616 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004617 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4618 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004619 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4620 ASSERT_VK_SUCCESS(err);
4621
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004622 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004623 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004624 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4625 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004626 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4627 ASSERT_VK_SUCCESS(err);
4628
4629 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4630 ASSERT_VK_SUCCESS(err);
4631 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4632 ASSERT_VK_SUCCESS(err);
4633
4634 BeginCommandBuffer();
4635 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4636 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4637 //VK_IMAGE_LAYOUT_GENERAL = 1,
4638 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004639 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004640 resolveRegion.srcSubresource.mipLevel = 0;
4641 resolveRegion.srcSubresource.arrayLayer = 0;
4642 resolveRegion.srcSubresource.arraySize = 0;
4643 resolveRegion.srcOffset.x = 0;
4644 resolveRegion.srcOffset.y = 0;
4645 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004646 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004647 resolveRegion.destSubresource.mipLevel = 0;
4648 resolveRegion.destSubresource.arrayLayer = 0;
4649 resolveRegion.destSubresource.arraySize = 0;
4650 resolveRegion.destOffset.x = 0;
4651 resolveRegion.destOffset.y = 0;
4652 resolveRegion.destOffset.z = 0;
4653 resolveRegion.extent.width = 1;
4654 resolveRegion.extent.height = 1;
4655 resolveRegion.extent.depth = 1;
4656 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4657 EndCommandBuffer();
4658
4659 msgFlags = m_errorMonitor->GetState(&msgString);
4660 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4661 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with source sample count less than 2.")) {
4662 FAIL() << "Error received was not 'vkCmdResolveImage called with source sample count less than 2.' but instead '" << msgString.c_str() << "'";
4663 }
4664
4665 vkDestroyImage(m_device->device(), srcImage);
4666 vkDestroyImage(m_device->device(), destImage);
4667 vkFreeMemory(m_device->device(), srcMem);
4668 vkFreeMemory(m_device->device(), destMem);
4669}
4670
4671TEST_F(VkLayerTest, ResolveImageHighSampleCount)
4672{
4673 VkFlags msgFlags;
4674 std::string msgString;
4675 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004676 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004677
4678 ASSERT_NO_FATAL_FAILURE(InitState());
4679 m_errorMonitor->ClearState();
4680
4681 // Create two images of sample count 2 and try to Resolve between them
4682 VkImage srcImage;
4683 VkImage destImage;
4684 VkDeviceMemory srcMem;
4685 VkDeviceMemory destMem;
4686 VkMemoryRequirements memReqs;
4687
4688 VkImageCreateInfo image_create_info = {};
4689 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4690 image_create_info.pNext = NULL;
4691 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4692 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4693 image_create_info.extent.width = 32;
4694 image_create_info.extent.height = 1;
4695 image_create_info.extent.depth = 1;
4696 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004697 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004698 image_create_info.samples = 2;
4699 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4700 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4701 image_create_info.flags = 0;
4702
4703 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4704 ASSERT_VK_SUCCESS(err);
4705
4706 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4707 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4708
4709 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4710 ASSERT_VK_SUCCESS(err);
4711
4712 // Allocate memory
4713 VkMemoryAllocInfo memAlloc = {};
4714 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4715 memAlloc.pNext = NULL;
4716 memAlloc.allocationSize = 0;
4717 memAlloc.memoryTypeIndex = 0;
4718
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004719 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004720 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004721 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4722 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004723 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4724 ASSERT_VK_SUCCESS(err);
4725
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004726 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004727 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004728 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4729 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004730 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4731 ASSERT_VK_SUCCESS(err);
4732
4733 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4734 ASSERT_VK_SUCCESS(err);
4735 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4736 ASSERT_VK_SUCCESS(err);
4737
4738 BeginCommandBuffer();
4739 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4740 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4741 //VK_IMAGE_LAYOUT_GENERAL = 1,
4742 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004743 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004744 resolveRegion.srcSubresource.mipLevel = 0;
4745 resolveRegion.srcSubresource.arrayLayer = 0;
4746 resolveRegion.srcSubresource.arraySize = 0;
4747 resolveRegion.srcOffset.x = 0;
4748 resolveRegion.srcOffset.y = 0;
4749 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004750 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004751 resolveRegion.destSubresource.mipLevel = 0;
4752 resolveRegion.destSubresource.arrayLayer = 0;
4753 resolveRegion.destSubresource.arraySize = 0;
4754 resolveRegion.destOffset.x = 0;
4755 resolveRegion.destOffset.y = 0;
4756 resolveRegion.destOffset.z = 0;
4757 resolveRegion.extent.width = 1;
4758 resolveRegion.extent.height = 1;
4759 resolveRegion.extent.depth = 1;
4760 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4761 EndCommandBuffer();
4762
4763 msgFlags = m_errorMonitor->GetState(&msgString);
4764 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4765 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with dest sample count greater than 1.")) {
4766 FAIL() << "Error received was not 'vkCmdResolveImage called with dest sample count greater than 1.' but instead '" << msgString.c_str() << "'";
4767 }
4768
4769 vkDestroyImage(m_device->device(), srcImage);
4770 vkDestroyImage(m_device->device(), destImage);
4771 vkFreeMemory(m_device->device(), srcMem);
4772 vkFreeMemory(m_device->device(), destMem);
4773}
4774
4775TEST_F(VkLayerTest, ResolveImageFormatMismatch)
4776{
4777 VkFlags msgFlags;
4778 std::string msgString;
4779 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004780 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004781
4782 ASSERT_NO_FATAL_FAILURE(InitState());
4783 m_errorMonitor->ClearState();
4784
4785 // Create two images of different types and try to copy between them
4786 VkImage srcImage;
4787 VkImage destImage;
4788 VkDeviceMemory srcMem;
4789 VkDeviceMemory destMem;
4790 VkMemoryRequirements memReqs;
4791
4792 VkImageCreateInfo image_create_info = {};
4793 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4794 image_create_info.pNext = NULL;
4795 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4796 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4797 image_create_info.extent.width = 32;
4798 image_create_info.extent.height = 1;
4799 image_create_info.extent.depth = 1;
4800 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004801 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004802 image_create_info.samples = 2;
4803 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4804 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4805 image_create_info.flags = 0;
4806
4807 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4808 ASSERT_VK_SUCCESS(err);
4809
4810 image_create_info.format = VK_FORMAT_B8G8R8_SRGB;
4811 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4812 image_create_info.samples = 1;
4813
4814 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4815 ASSERT_VK_SUCCESS(err);
4816
4817 // Allocate memory
4818 VkMemoryAllocInfo memAlloc = {};
4819 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4820 memAlloc.pNext = NULL;
4821 memAlloc.allocationSize = 0;
4822 memAlloc.memoryTypeIndex = 0;
4823
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004824 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004825 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004826 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4827 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004828 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4829 ASSERT_VK_SUCCESS(err);
4830
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004831 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004832 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004833 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4834 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004835 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4836 ASSERT_VK_SUCCESS(err);
4837
4838 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4839 ASSERT_VK_SUCCESS(err);
4840 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4841 ASSERT_VK_SUCCESS(err);
4842
4843 BeginCommandBuffer();
4844 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4845 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4846 //VK_IMAGE_LAYOUT_GENERAL = 1,
4847 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004848 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004849 resolveRegion.srcSubresource.mipLevel = 0;
4850 resolveRegion.srcSubresource.arrayLayer = 0;
4851 resolveRegion.srcSubresource.arraySize = 0;
4852 resolveRegion.srcOffset.x = 0;
4853 resolveRegion.srcOffset.y = 0;
4854 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004855 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004856 resolveRegion.destSubresource.mipLevel = 0;
4857 resolveRegion.destSubresource.arrayLayer = 0;
4858 resolveRegion.destSubresource.arraySize = 0;
4859 resolveRegion.destOffset.x = 0;
4860 resolveRegion.destOffset.y = 0;
4861 resolveRegion.destOffset.z = 0;
4862 resolveRegion.extent.width = 1;
4863 resolveRegion.extent.height = 1;
4864 resolveRegion.extent.depth = 1;
4865 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4866 EndCommandBuffer();
4867
4868 msgFlags = m_errorMonitor->GetState(&msgString);
4869 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage format mismatch";
4870 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest formats.")) {
4871 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest formats.' but instead '" << msgString.c_str() << "'";
4872 }
4873
4874 vkDestroyImage(m_device->device(), srcImage);
4875 vkDestroyImage(m_device->device(), destImage);
4876 vkFreeMemory(m_device->device(), srcMem);
4877 vkFreeMemory(m_device->device(), destMem);
4878}
4879
4880TEST_F(VkLayerTest, ResolveImageTypeMismatch)
4881{
4882 VkFlags msgFlags;
4883 std::string msgString;
4884 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004885 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06004886
4887 ASSERT_NO_FATAL_FAILURE(InitState());
4888 m_errorMonitor->ClearState();
4889
4890 // Create two images of different types and try to copy between them
4891 VkImage srcImage;
4892 VkImage destImage;
4893 VkDeviceMemory srcMem;
4894 VkDeviceMemory destMem;
4895 VkMemoryRequirements memReqs;
4896
4897 VkImageCreateInfo image_create_info = {};
4898 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4899 image_create_info.pNext = NULL;
4900 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4901 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4902 image_create_info.extent.width = 32;
4903 image_create_info.extent.height = 1;
4904 image_create_info.extent.depth = 1;
4905 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004906 image_create_info.arrayLayers = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06004907 image_create_info.samples = 2;
4908 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4909 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4910 image_create_info.flags = 0;
4911
4912 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4913 ASSERT_VK_SUCCESS(err);
4914
4915 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4916 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4917 image_create_info.samples = 1;
4918
4919 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4920 ASSERT_VK_SUCCESS(err);
4921
4922 // Allocate memory
4923 VkMemoryAllocInfo memAlloc = {};
4924 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4925 memAlloc.pNext = NULL;
4926 memAlloc.allocationSize = 0;
4927 memAlloc.memoryTypeIndex = 0;
4928
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004929 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004930 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004931 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4932 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004933 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4934 ASSERT_VK_SUCCESS(err);
4935
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06004936 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06004937 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06004938 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4939 ASSERT_TRUE(pass);
Mike Stroyana3082432015-09-25 13:39:21 -06004940 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4941 ASSERT_VK_SUCCESS(err);
4942
4943 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4944 ASSERT_VK_SUCCESS(err);
4945 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4946 ASSERT_VK_SUCCESS(err);
4947
4948 BeginCommandBuffer();
4949 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4950 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4951 //VK_IMAGE_LAYOUT_GENERAL = 1,
4952 VkImageResolve resolveRegion;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004953 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004954 resolveRegion.srcSubresource.mipLevel = 0;
4955 resolveRegion.srcSubresource.arrayLayer = 0;
4956 resolveRegion.srcSubresource.arraySize = 0;
4957 resolveRegion.srcOffset.x = 0;
4958 resolveRegion.srcOffset.y = 0;
4959 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -06004960 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06004961 resolveRegion.destSubresource.mipLevel = 0;
4962 resolveRegion.destSubresource.arrayLayer = 0;
4963 resolveRegion.destSubresource.arraySize = 0;
4964 resolveRegion.destOffset.x = 0;
4965 resolveRegion.destOffset.y = 0;
4966 resolveRegion.destOffset.z = 0;
4967 resolveRegion.extent.width = 1;
4968 resolveRegion.extent.height = 1;
4969 resolveRegion.extent.depth = 1;
4970 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4971 EndCommandBuffer();
4972
4973 msgFlags = m_errorMonitor->GetState(&msgString);
4974 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4975 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest image types.")) {
4976 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest image types.' but instead '" << msgString.c_str() << "'";
4977 }
4978
4979 vkDestroyImage(m_device->device(), srcImage);
4980 vkDestroyImage(m_device->device(), destImage);
4981 vkFreeMemory(m_device->device(), srcMem);
4982 vkFreeMemory(m_device->device(), destMem);
4983}
Tobin Ehliscde08892015-09-22 10:11:37 -06004984#endif // IMAGE_TESTS
4985
Tony Barbour300a6082015-04-07 13:44:53 -06004986int main(int argc, char **argv) {
4987 int result;
4988
4989 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06004990 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06004991
4992 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
4993
4994 result = RUN_ALL_TESTS();
4995
Tony Barbour6918cd52015-04-09 12:58:51 -06004996 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06004997 return result;
4998}