blob: ad7700bc52d3c214fa5cf4ab054804109cd7bb07 [file] [log] [blame]
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001#include <vulkan.h>
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002#include "vk_debug_report_lunarg.h"
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -06003#include "test_common.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06004#include "vkrenderframework.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -06005#include "vk_layer_config.h"
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06006#include "../icd/common/icd-spv.h"
Tony Barbour30486ea2015-04-07 13:44:53 -06007
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05008#define GLM_FORCE_RADIANS
9#include "glm/glm.hpp"
10#include <glm/gtc/matrix_transform.hpp>
11
Tobin Ehlis57e6a612015-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 Forbes5af3bf22015-05-25 11:13:08 +120016#define SHADER_CHECKER_TESTS 1
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -060017#define DEVICE_LIMITS_TESTS 1
Tobin Ehlis342b9bf2015-09-22 10:11:37 -060018#define IMAGE_TESTS 1
Tobin Ehlis57e6a612015-05-26 16:11:58 -060019
Mark Lobodzinski5f25be42015-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 Northrope4bc6942015-08-26 10:01:32 -060033 BsoFailLineWidth = 0x00000001,
34 BsoFailDepthBias = 0x00000002,
Cody Northropf5bd2252015-08-17 11:10:49 -060035 BsoFailViewport = 0x00000004,
Tobin Ehlisf6cb4672015-09-29 08:18:34 -060036 BsoFailScissor = 0x00000008,
37 BsoFailBlend = 0x00000010,
38 BsoFailDepthBounds = 0x00000020,
39 BsoFailStencilReadMask = 0x00000040,
40 BsoFailStencilWriteMask = 0x00000080,
41 BsoFailStencilReference = 0x00000100,
Mark Lobodzinski5f25be42015-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 Lobodzinski6bbdff12015-06-02 09:41:30 -050051static const char bindStateVertShaderText[] =
Mark Lobodzinski5f25be42015-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 Lobodzinski6bbdff12015-06-02 09:41:30 -050061static const char bindStateFragShaderText[] =
Cody Northrop74a2d2c2015-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 Lobodzinski5f25be42015-05-14 15:08:13 -050070
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -060071static VkBool32 myDbgFunc(
Tony Barboure84a8d62015-07-10 14:10:27 -060072 VkFlags msgFlags,
73 VkDbgObjectType objType,
74 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-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 Barbour30486ea2015-04-07 13:44:53 -060080
81class ErrorMonitor {
82public:
Tony Barbour0c1bdc62015-04-29 17:34:29 -060083 ErrorMonitor()
Tony Barbour30486ea2015-04-07 13:44:53 -060084 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060085 test_platform_thread_create_mutex(&m_mutex);
86 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060087 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mike Stroyan09aae812015-05-12 16:00:45 -060088 m_bailout = NULL;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060089 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060090 }
91 void ClearState()
92 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060093 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060094 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -060095 m_msgString.clear();
Mike Stroyan7016f4f2015-07-13 14:45:35 -060096 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060097 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060098 VkFlags GetState(std::string *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060099 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600100 test_platform_thread_lock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -0600101 *msgString = m_msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600102 test_platform_thread_unlock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600103 return m_msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600104 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600105 void SetState(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600106 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600107 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600108 if (m_bailout != NULL) {
109 *m_bailout = true;
110 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600111 m_msgFlags = msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600112 m_msgString.reserve(strlen(msgString));
113 m_msgString = msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600114 test_platform_thread_unlock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600115 }
116 void SetBailout(bool *bailout)
117 {
118 m_bailout = bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600119 }
120
121private:
Mike Stroyan7016f4f2015-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 Barbour30486ea2015-04-07 13:44:53 -0600126};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500127
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600128static VkBool32 myDbgFunc(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600129 VkFlags msgFlags,
Tony Barboure84a8d62015-07-10 14:10:27 -0600130 VkDbgObjectType objType,
131 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-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 Barbour30486ea2015-04-07 13:44:53 -0600137{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600138 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600139 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600140 errMonitor->SetState(msgFlags, pMsg);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600141 return true;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600142 }
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600143
144 return false;
Tony Barbour30486ea2015-04-07 13:44:53 -0600145}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500146
Tony Barbour01999182015-04-09 12:58:51 -0600147class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600148{
149public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600150 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
151 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Mark Lobodzinski5f25be42015-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 Barbour1490c912015-07-28 10:17:20 -0600154 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
155 { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600156
Tony Barbour1490c912015-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 Goeltzenleuchter4ff11cc2015-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 Barbour1490c912015-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 Barbour30486ea2015-04-07 13:44:53 -0600170protected:
Tony Barbour01999182015-04-09 12:58:51 -0600171 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600172
173 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600174 std::vector<const char *> instance_layer_names;
175 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600176 std::vector<const char *> instance_extension_names;
177 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600178
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600179 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-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 Stroyan2237f522015-08-18 14:40:24 -0600185 // Use Threading layer first to protect others from ThreadCmdBufferCollision test
Courtney Goeltzenleuchterf5c61952015-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 Lobodzinskic11cd2c2015-09-17 09:44:05 -0600191 instance_layer_names.push_back("DeviceLimits");
Tobin Ehlis342b9bf2015-09-22 10:11:37 -0600192 instance_layer_names.push_back("Image");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600193
Courtney Goeltzenleuchterf5c61952015-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 Lobodzinskic11cd2c2015-09-17 09:44:05 -0600199 device_layer_names.push_back("DeviceLimits");
Tobin Ehlis342b9bf2015-09-22 10:11:37 -0600200 device_layer_names.push_back("Image");
Tony Barbour30486ea2015-04-07 13:44:53 -0600201
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600202 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600208 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600209
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600210 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-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 Barbour30486ea2015-04-07 13:44:53 -0600214 }
215
216 virtual void TearDown() {
217 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600218 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600219 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600220 }
221};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500222
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600223VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600224{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600225 VkResult result;
Tony Barbour30486ea2015-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 Forbesfe133ef2015-06-16 14:05:59 +1200233 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wuc278df82015-07-07 11:50:03 +0800234 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600235 }
236
237 return result;
238}
239
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600240VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600241{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600242 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600243
Chris Forbesfe133ef2015-06-16 14:05:59 +1200244 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800245 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200246 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600247
248 result = cmdBuffer.EndCommandBuffer();
249
250 return result;
251}
252
Mark Lobodzinski5f25be42015-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 Goeltzenleuchter8e2f0972015-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 Lobodzinski5f25be42015-05-14 15:08:13 -0500293
294 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800295 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500296 pipelineobj.AddShader(&vs);
297 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter2f5deb52015-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 Ehlisa88e2f52015-10-02 11:00:56 -0600304 // Viewport and scissors must stay in synch or other errors will occur than the ones we want
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600305 if (failMask & BsoFailViewport) {
306 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600307 m_viewports.clear();
308 m_scissors.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600309 }
310 if (failMask & BsoFailScissor) {
311 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600312 m_scissors.clear();
313 m_viewports.clear();
Courtney Goeltzenleuchter2f5deb52015-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 Lobodzinski5f25be42015-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 Barbour1490c912015-07-28 10:17:20 -0600335 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500336
Tony Barbour1490c912015-07-28 10:17:20 -0600337 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500338
339 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600340 Draw(3, 1, 0, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500341
342 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600343 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500344
Tony Barbour1490c912015-07-28 10:17:20 -0600345 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-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 Northrop2605cb02015-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 Barbourefbe9ca2015-07-15 12:50:33 -0600359 VkStencilOpState stencil = {};
360 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
Courtney Goeltzenleuchter2f5deb52015-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 Barbourefbe9ca2015-07-15 12:50:33 -0600364
365 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
366 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter2f5deb52015-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 Barbourefbe9ca2015-07-15 12:50:33 -0600375
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600376 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600377 pipelineobj.SetViewport(m_viewports);
378 pipelineobj.SetScissor(m_scissors);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500379 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600380 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
381 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500382 cmdBuffer->BindPipeline(pipelineobj);
383 cmdBuffer->BindDescriptorSet(descriptorSet);
384}
385
386// ********************************************************************************************************************
387// ********************************************************************************************************************
388// ********************************************************************************************************************
389// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600390#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500391TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
392{
393 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600394 VkFlags msgFlags;
Mark Lobodzinski81078192015-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 Barboure389b882015-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 Lobodzinski81078192015-05-19 10:28:29 -0500407
Tony Barbour1490c912015-07-28 10:17:20 -0600408 BeginCommandBuffer();
409 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
410 EndCommandBuffer();
Mark Lobodzinski81078192015-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 Goeltzenleuchter3ec31622015-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 Lobodzinski81078192015-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 Barbour1490c912015-07-28 10:17:20 -0600430 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500431
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600432 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-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 Lobodzinski81078192015-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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600442 VkFlags msgFlags;
Mark Lobodzinski81078192015-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 Barbour1490c912015-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 Lobodzinski81078192015-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 Goeltzenleuchter3ec31622015-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 Lobodzinski81078192015-05-19 10:28:29 -0500472 ASSERT_VK_SUCCESS( err );
473
474 m_errorMonitor->ClearState();
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600475
476 VkCmdBufferBeginInfo info = {};
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -0600477 info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600478 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
479 info.renderPass = VK_NULL_HANDLE;
480 info.subpass = 0;
481 info.framebuffer = VK_NULL_HANDLE;
482
483 // Introduce failure by calling BCB again before checking fence
484 vkBeginCommandBuffer(m_cmdBuffer->handle(), &info);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500485
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600486 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-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 Lobodzinski81078192015-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 Lobodzinski5f25be42015-05-14 15:08:13 -0500493TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
494{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600495 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500496 std::string msgString;
497 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600498 bool pass;
Mark Lobodzinski5f25be42015-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 Lobodzinski23182612015-05-29 09:32:35 -0500505 VkDeviceMemory mem;
506 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-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 Lobodzinski5f25be42015-05-14 15:08:13 -0500511
Tony Barbourefbe9ca2015-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 Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600521 image_create_info.arrayLayers = 1;
Tony Barbourefbe9ca2015-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 Lobodzinski87db5012015-09-14 17:43:42 -0600526
Tony Barbourefbe9ca2015-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 Lobodzinski5f25be42015-05-14 15:08:13 -0500531 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600532 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500533
534 err = vkCreateImage(m_device->device(), &image_create_info, &image);
535 ASSERT_VK_SUCCESS(err);
536
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600537 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500538 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500539 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500540
Mark Lobodzinski23182612015-05-29 09:32:35 -0500541 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500542
Courtney Goeltzenleuchter37a43a62015-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 Stroyan2237f522015-08-18 14:40:24 -0600545 vkDestroyImage(m_device->device(), image);
Tony Barbour49a3b652015-08-04 16:13:01 -0600546 return;
Mike Stroyan2237f522015-08-18 14:40:24 -0600547 }
Mike Stroyand72da752015-08-04 10:49:29 -0600548
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500549 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500550 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500551 ASSERT_VK_SUCCESS(err);
552
553 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600554 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-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 Lobodzinski23182612015-05-29 09:32:35 -0500559 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500560
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600561 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-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 Lobodzinski5f25be42015-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 Stroyan2237f522015-08-18 14:40:24 -0600566
567 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500568}
569
Tobin Ehlis33ce8fd2015-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 Ehlis33ce8fd2015-07-10 18:25:07 -0600633// msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600634//
Cody Northrop1684adb2015-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 Ehlis33ce8fd2015-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 Lobodzinski5f25be42015-05-14 15:08:13 -0500640
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500641TEST_F(VkLayerTest, RebindMemory)
642{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600643 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500644 std::string msgString;
645 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600646 bool pass;
Mark Lobodzinskic66c6712015-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 Lobodzinskic66c6712015-06-05 13:59:04 -0500660
Tony Barbourefbe9ca2015-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 Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600670 image_create_info.arrayLayers = 1;
Tony Barbourefbe9ca2015-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 Lobodzinskic66c6712015-06-05 13:59:04 -0500675
Tony Barbourefbe9ca2015-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 Lobodzinskic66c6712015-06-05 13:59:04 -0500684 err = vkCreateImage(m_device->device(), &image_create_info, &image);
685 ASSERT_VK_SUCCESS(err);
686
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600687 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500688 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500689 &mem_reqs);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500690
691 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600692 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
693 ASSERT_TRUE(pass);
Mark Lobodzinskic66c6712015-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 Barboure84a8d62015-07-10 14:10:27 -0600702 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-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 Barboure84a8d62015-07-10 14:10:27 -0600706 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500707
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600708 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-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 Lobodzinskic66c6712015-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 Stroyan2237f522015-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 Lobodzinskic66c6712015-06-05 13:59:04 -0500717}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500718
Tony Barbour8508b8e2015-04-09 10:48:04 -0600719TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600720{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600721 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600722 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600723 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600724
725 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-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 Barbour30486ea2015-04-07 13:44:53 -0600729
Tony Barbour30486ea2015-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 Barbour1490c912015-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 Barbour30486ea2015-04-07 13:44:53 -0600737
738 testFence.init(*m_device, fenceInfo);
739 m_errorMonitor->ClearState();
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600740
Courtney Goeltzenleuchter3ec31622015-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 Lobodzinski87db5012015-09-14 17:43:42 -0600751 vkQueueWaitIdle(m_device->m_queue );
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600752 msgFlags = m_errorMonitor->GetState(&msgString);
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600753
Cody Northrop1684adb2015-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 Barbour8508b8e2015-04-09 10:48:04 -0600755 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500756 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600757 }
758
759}
760
761TEST_F(VkLayerTest, ResetUnsignaledFence)
762{
763 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600764 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600765 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600766 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600767 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
768 fenceInfo.pNext = NULL;
769
Tony Barbour8508b8e2015-04-09 10:48:04 -0600770 ASSERT_NO_FATAL_FAILURE(InitState());
771 testFence.init(*m_device, fenceInfo);
772 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800773 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600774 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600775 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisc2033a02015-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 Barbour01999182015-04-09 12:58:51 -0600777 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500778 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600779 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600780
781}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600782
Chia-I Wuc278df82015-07-07 11:50:03 +0800783/* TODO: Update for changes due to bug-14075 tiling across render passes */
784#if 0
Tobin Ehlisd94ba722015-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 Barbour1490c912015-07-28 10:17:20 -0600794 BeginCommandBuffer();
Tobin Ehlisd94ba722015-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 Goeltzenleuchterc3b8eea2015-09-10 14:14:11 -0600811 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlisd94ba722015-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 Goeltzenleuchter3dee8082015-09-10 16:38:41 -0600823 .baseArrayLayer = 0,
Tobin Ehlisd94ba722015-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 Northrop1684adb2015-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 Ehlisd94ba722015-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 Lobodzinskic11cd2c2015-09-17 09:44:05 -0600834#endif // 0
835#endif // MEM_TRACKER_TESTS
836
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600837#if OBJ_TRACKER_TESTS
Tobin Ehlisf2f97402015-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 Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600855 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
856 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-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 Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600861 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-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 Ehlis87f115c2015-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 Stroyan2237f522015-08-18 14:40:24 -0600904
905 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -0600906 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
907 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600908}
909
910TEST_F(VkLayerTest, BindInvalidMemory)
911{
912 VkFlags msgFlags;
913 std::string msgString;
914 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600915 bool pass;
Tobin Ehlis87f115c2015-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 Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600938 image_create_info.arrayLayers = 1;
Tobin Ehlis87f115c2015-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 Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600953 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600954 image,
955 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600956
957 mem_alloc.allocationSize = mem_reqs.size;
958
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600959 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
960 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-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 Ehlis87f115c2015-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 Stroyan2237f522015-08-18 14:40:24 -0600979
980 vkDestroyImage(m_device->device(), image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600981}
982
983TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
984{
985 VkFlags msgFlags;
986 std::string msgString;
987 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600988 bool pass;
Tobin Ehlis87f115c2015-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 Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06001011 image_create_info.arrayLayers = 1;
Tobin Ehlis87f115c2015-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 Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06001026 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001027 image,
1028 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001029
1030 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001031 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1032 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-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 Ehlisf2f97402015-09-11 12:57:55 -06001051 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001052
1053 vkFreeMemory(m_device->device(), mem);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001054}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001055#endif // OBJ_TRACKER_TESTS
1056
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001057#if DRAW_STATE_TESTS
Tobin Ehlisf6cb4672015-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 Ehlis3dec46c2015-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 Ehlisf6cb4672015-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 Ehlisf6cb4672015-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 Ehlis0cea4082015-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
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -06001220 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001221 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 Goeltzenleuchter3ec31622015-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 Ehlis0cea4082015-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 Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001242 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-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";
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -06001246 if (!strstr(msgString.c_str(),"was begun w/ VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted")) {
1247 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001248 }
1249}
1250
Tobin Ehlise4076782015-06-24 15:53:07 -06001251TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001252{
1253 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001254 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001255 std::string msgString;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001256 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001257
1258 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001260 m_errorMonitor->ClearState();
Tobin Ehlisf2f97402015-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 Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001269 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1270 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001271 ds_pool_ci.count = 1;
1272 ds_pool_ci.pTypeCount = &ds_type_count;
1273
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001274 VkDescriptorPool ds_pool;
1275 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-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 Goeltzenleuchter8e2f0972015-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 Ehlisf2f97402015-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;
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -06001330 cmd_buf_info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001331
1332 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1333 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001334 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001335 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding pipeline to CmdBuffer w/o active RenderPass";
Tobin Ehlise4076782015-06-24 15:53:07 -06001336 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001337 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass' but rather '" << msgString.c_str() << "'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001338 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001339
1340 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001341 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1342 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001343}
1344
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001345TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1346{
1347 // Initiate Draw w/o a PSO bound
1348 VkFlags msgFlags;
1349 std::string msgString;
1350 VkResult err;
1351
1352 ASSERT_NO_FATAL_FAILURE(InitState());
1353 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1354 m_errorMonitor->ClearState();
1355
1356 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
1357 VkDescriptorTypeCount ds_type_count = {};
1358 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
1359 ds_type_count.count = 1;
1360
1361 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1362 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1363 ds_pool_ci.pNext = NULL;
1364 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1365 ds_pool_ci.maxSets = 1;
1366 ds_pool_ci.count = 1;
1367 ds_pool_ci.pTypeCount = &ds_type_count;
1368
1369 VkDescriptorPool ds_pool;
1370 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1371 ASSERT_VK_SUCCESS(err);
1372
1373 VkDescriptorSetLayoutBinding dsl_binding = {};
1374 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1375 dsl_binding.arraySize = 1;
1376 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1377 dsl_binding.pImmutableSamplers = NULL;
1378
1379 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1380 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1381 ds_layout_ci.pNext = NULL;
1382 ds_layout_ci.count = 1;
1383 ds_layout_ci.pBinding = &dsl_binding;
1384
1385 VkDescriptorSetLayout ds_layout;
1386 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1387 ASSERT_VK_SUCCESS(err);
1388
1389 VkDescriptorSet descriptorSet;
1390 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1391
1392 msgFlags = m_errorMonitor->GetState(&msgString);
1393 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after alloc descriptor from pool w/o requested type";
1394 if (!strstr(msgString.c_str(),"Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ")) {
1395 FAIL() << "Error received was not 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...' but rather '" << msgString.c_str() << "'";
1396 }
1397
1398 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1399 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1400}
1401
Tobin Ehlis3c543112015-10-08 13:13:50 -06001402TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1403{
1404 VkFlags msgFlags;
1405 std::string msgString;
1406 VkResult err;
1407
1408 ASSERT_NO_FATAL_FAILURE(InitState());
1409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1410 m_errorMonitor->ClearState();
1411
1412 VkDescriptorTypeCount ds_type_count = {};
1413 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1414 ds_type_count.count = 1;
1415
1416 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1417 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1418 ds_pool_ci.pNext = NULL;
1419 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT; // Can't free from ONE_SHOT Pool
1420 ds_pool_ci.maxSets = 1;
1421 ds_pool_ci.count = 1;
1422 ds_pool_ci.pTypeCount = &ds_type_count;
1423
1424 VkDescriptorPool ds_pool;
1425 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1426 ASSERT_VK_SUCCESS(err);
1427
1428 VkDescriptorSetLayoutBinding dsl_binding = {};
1429 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1430 dsl_binding.arraySize = 1;
1431 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1432 dsl_binding.pImmutableSamplers = NULL;
1433
1434 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1435 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1436 ds_layout_ci.pNext = NULL;
1437 ds_layout_ci.count = 1;
1438 ds_layout_ci.pBinding = &dsl_binding;
1439
1440 VkDescriptorSetLayout ds_layout;
1441 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1442 ASSERT_VK_SUCCESS(err);
1443
1444 VkDescriptorSet descriptorSet;
1445 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1446 ASSERT_VK_SUCCESS(err);
1447
1448 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1449 msgFlags = m_errorMonitor->GetState(&msgString);
1450 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after freeing descriptor from ONE_SHOT Pool";
1451 if (!strstr(msgString.c_str(),"It is invalid to call vkFreeDescriptorSets() with a pool created with usage type VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT.")) {
1452 FAIL() << "Error received was not 'It is invalid to call vkFreeDescriptorSets() with a pool created with...' but instead it was '" << msgString.c_str() << "'";
1453 }
1454
1455 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1456 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1457}
1458
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001459TEST_F(VkLayerTest, InvalidDescriptorPool)
1460{
1461 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1462 // The DS check for this is after driver has been called to validate DS internal data struct
1463 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001464/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001465 std::string msgString;
1466 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1467 vkResetDescriptorPool(device(), badPool);
1468
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001469 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001470 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Resetting an invalid DescriptorPool Object";
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001471 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1472 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1473 }*/
1474}
1475
1476TEST_F(VkLayerTest, InvalidDescriptorSet)
1477{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001478 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1479 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001480 // Create a valid cmd buffer
1481 // call vkCmdBindDescriptorSets w/ false DS
1482}
1483
1484TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1485{
1486 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1487 // The DS check for this is after driver has been called to validate DS internal data struct
1488}
1489
1490TEST_F(VkLayerTest, InvalidPipeline)
1491{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001492 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1493 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001494 // Create a valid cmd buffer
1495 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001496// VkFlags msgFlags;
1497// std::string msgString;
1498//
1499// ASSERT_NO_FATAL_FAILURE(InitState());
1500// m_errorMonitor->ClearState();
1501// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001502// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001503// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1504// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1505// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001506// ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlise4076782015-06-24 15:53:07 -06001507// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1508// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1509// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001510}
1511
Tobin Ehlis254eca02015-06-25 15:46:59 -06001512TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001513{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001514 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001515 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001516 std::string msgString;
1517 VkResult err;
1518
1519 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001520 ASSERT_NO_FATAL_FAILURE(InitViewport());
1521 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001522 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001523 VkDescriptorTypeCount ds_type_count = {};
1524 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1525 ds_type_count.count = 1;
1526
1527 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1528 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1529 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001530 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1531 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001532 ds_pool_ci.count = 1;
1533 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001534
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001535 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001536 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001537 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001538
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001539 VkDescriptorSetLayoutBinding dsl_binding = {};
1540 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1541 dsl_binding.arraySize = 1;
1542 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1543 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001544
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001545 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1546 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1547 ds_layout_ci.pNext = NULL;
1548 ds_layout_ci.count = 1;
1549 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001550 VkDescriptorSetLayout ds_layout;
1551 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1552 ASSERT_VK_SUCCESS(err);
1553
1554 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001555 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001556 ASSERT_VK_SUCCESS(err);
1557
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001558 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1559 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1560 pipeline_layout_ci.pNext = NULL;
1561 pipeline_layout_ci.descriptorSetCount = 1;
1562 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001563
1564 VkPipelineLayout pipeline_layout;
1565 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1566 ASSERT_VK_SUCCESS(err);
1567
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001568 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1569 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001570 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001571
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001572 VkPipelineObj pipe(m_device);
1573 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001574 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001575 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001576
1577 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001578 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001579 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001580
Tobin Ehlis254eca02015-06-25 15:46:59 -06001581 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001582 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not warn after binding a DescriptorSet that was never updated.";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001583 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1584 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1585 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001586
1587 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001588 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1589 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001590}
1591
1592TEST_F(VkLayerTest, NoBeginCmdBuffer)
1593{
1594 VkFlags msgFlags;
1595 std::string msgString;
1596
1597 ASSERT_NO_FATAL_FAILURE(InitState());
1598 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001599 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001600 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1601 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1602 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001603 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after ending a CmdBuffer w/o calling BeginCommandBuffer()";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001604 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1605 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1606 }
1607}
1608
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001609TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1610{
1611 VkFlags msgFlags;
1612 std::string msgString;
1613
1614 ASSERT_NO_FATAL_FAILURE(InitState());
1615 m_errorMonitor->ClearState();
1616
1617 // Calls CreateCommandBuffer
1618 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1619
1620 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001621 VkCmdBufferBeginInfo cmd_buf_info = {};
1622 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1623 cmd_buf_info.pNext = NULL;
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -06001624 cmd_buf_info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northrop10d8f982015-08-04 17:35:57 -06001625 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1626 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1627
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001628
1629 // The error should be caught by validation of the BeginCommandBuffer call
1630 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1631
1632 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001633 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing a non-NULL Framebuffer and Renderpass to BeginCommandBuffer()";
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001634 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1635 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1636 }
1637}
1638
1639TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1640{
1641 VkFlags msgFlags;
1642 std::string msgString;
1643 VkResult err;
1644 VkCmdBuffer draw_cmd;
1645 VkCmdPool cmd_pool;
1646
1647 ASSERT_NO_FATAL_FAILURE(InitState());
1648 m_errorMonitor->ClearState();
1649
Cody Northrop10d8f982015-08-04 17:35:57 -06001650 VkCmdBufferCreateInfo cmd = {};
1651 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1652 cmd.pNext = NULL;
1653 cmd.cmdPool = m_cmdPool;
1654 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1655 cmd.flags = 0;
1656
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001657 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06001658 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001659
1660 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001661 VkCmdBufferBeginInfo cmd_buf_info = {};
1662 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1663 cmd_buf_info.pNext = NULL;
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -06001664 cmd_buf_info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001665
1666 // The error should be caught by validation of the BeginCommandBuffer call
1667 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1668
1669 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001670 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing NULL Framebuffer/Renderpass to BeginCommandBuffer()";
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001671 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1672 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1673 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001674 vkDestroyCommandBuffer(m_device->device(), draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001675}
1676
Tobin Ehlis254eca02015-06-25 15:46:59 -06001677TEST_F(VkLayerTest, InvalidPipelineCreateState)
1678{
1679 // Attempt to Create Gfx Pipeline w/o a VS
1680 VkFlags msgFlags;
1681 std::string msgString;
1682 VkResult err;
1683
1684 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06001686 m_errorMonitor->ClearState();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001687
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001688 VkDescriptorTypeCount ds_type_count = {};
1689 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1690 ds_type_count.count = 1;
1691
1692 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1693 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1694 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001695 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1696 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001697 ds_pool_ci.count = 1;
1698 ds_pool_ci.pTypeCount = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001699
Tobin Ehlis254eca02015-06-25 15:46:59 -06001700 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001701 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001702 ASSERT_VK_SUCCESS(err);
1703
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001704 VkDescriptorSetLayoutBinding dsl_binding = {};
1705 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1706 dsl_binding.arraySize = 1;
1707 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1708 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001709
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001710 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1711 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1712 ds_layout_ci.pNext = NULL;
1713 ds_layout_ci.count = 1;
1714 ds_layout_ci.pBinding = &dsl_binding;
1715
Tobin Ehlis254eca02015-06-25 15:46:59 -06001716 VkDescriptorSetLayout ds_layout;
1717 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1718 ASSERT_VK_SUCCESS(err);
1719
1720 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001721 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001722 ASSERT_VK_SUCCESS(err);
1723
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001724 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1725 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001726 pipeline_layout_ci.descriptorSetCount = 1;
1727 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001728
1729 VkPipelineLayout pipeline_layout;
1730 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1731 ASSERT_VK_SUCCESS(err);
1732
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001733 VkViewport vp = {}; // Just need dummy vp to point to
1734 VkRect2D sc = {}; // dummy scissor to point to
1735
1736 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1737 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1738 vp_state_ci.scissorCount = 1;
1739 vp_state_ci.pScissors = &sc;
1740 vp_state_ci.viewportCount = 1;
1741 vp_state_ci.pViewports = &vp;
1742
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001743 VkGraphicsPipelineCreateInfo gp_ci = {};
1744 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001745 gp_ci.pViewportState = &vp_state_ci;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001746 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1747 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001748 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001749
1750 VkPipelineCacheCreateInfo pc_ci = {};
1751 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001752 pc_ci.initialSize = 0;
1753 pc_ci.initialData = 0;
1754 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001755
1756 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001757 VkPipelineCache pipelineCache;
1758
1759 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1760 ASSERT_VK_SUCCESS(err);
1761 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001762
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001763 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001764 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o VS.";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001765 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1766 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1767 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001768
1769 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1770 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001771 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1772 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001773}
Tobin Ehlis20693172015-09-17 08:46:18 -06001774/*// TODO : This test should be good, but needs Tess support in compiler to run
1775TEST_F(VkLayerTest, InvalidPatchControlPoints)
1776{
1777 // Attempt to Create Gfx Pipeline w/o a VS
1778 VkFlags msgFlags;
1779 std::string msgString;
1780 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001781
Tobin Ehlis20693172015-09-17 08:46:18 -06001782 ASSERT_NO_FATAL_FAILURE(InitState());
1783 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1784 m_errorMonitor->ClearState();
1785
1786 VkDescriptorTypeCount ds_type_count = {};
1787 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1788 ds_type_count.count = 1;
1789
1790 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1791 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1792 ds_pool_ci.pNext = NULL;
1793 ds_pool_ci.count = 1;
1794 ds_pool_ci.pTypeCount = &ds_type_count;
1795
1796 VkDescriptorPool ds_pool;
1797 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1798 ASSERT_VK_SUCCESS(err);
1799
1800 VkDescriptorSetLayoutBinding dsl_binding = {};
1801 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1802 dsl_binding.arraySize = 1;
1803 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1804 dsl_binding.pImmutableSamplers = NULL;
1805
1806 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1807 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1808 ds_layout_ci.pNext = NULL;
1809 ds_layout_ci.count = 1;
1810 ds_layout_ci.pBinding = &dsl_binding;
1811
1812 VkDescriptorSetLayout ds_layout;
1813 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1814 ASSERT_VK_SUCCESS(err);
1815
1816 VkDescriptorSet descriptorSet;
1817 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1818 ASSERT_VK_SUCCESS(err);
1819
1820 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1821 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1822 pipeline_layout_ci.pNext = NULL;
1823 pipeline_layout_ci.descriptorSetCount = 1;
1824 pipeline_layout_ci.pSetLayouts = &ds_layout;
1825
1826 VkPipelineLayout pipeline_layout;
1827 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1828 ASSERT_VK_SUCCESS(err);
1829
1830 VkPipelineShaderStageCreateInfo shaderStages[3];
1831 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1832
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001833 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06001834 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001835 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
1836 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06001837
1838 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001839 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001840 shaderStages[0].shader = vs.handle();
1841 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001842 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001843 shaderStages[1].shader = tc.handle();
1844 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001845 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001846 shaderStages[2].shader = te.handle();
1847
1848 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1849 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1850 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1851
1852 VkPipelineTessellationStateCreateInfo tsCI = {};
1853 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1854 tsCI.patchControlPoints = 0; // This will cause an error
1855
1856 VkGraphicsPipelineCreateInfo gp_ci = {};
1857 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1858 gp_ci.pNext = NULL;
1859 gp_ci.stageCount = 3;
1860 gp_ci.pStages = shaderStages;
1861 gp_ci.pVertexInputState = NULL;
1862 gp_ci.pInputAssemblyState = &iaCI;
1863 gp_ci.pTessellationState = &tsCI;
1864 gp_ci.pViewportState = NULL;
1865 gp_ci.pRasterState = NULL;
1866 gp_ci.pMultisampleState = NULL;
1867 gp_ci.pDepthStencilState = NULL;
1868 gp_ci.pColorBlendState = NULL;
1869 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1870 gp_ci.layout = pipeline_layout;
1871 gp_ci.renderPass = renderPass();
1872
1873 VkPipelineCacheCreateInfo pc_ci = {};
1874 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1875 pc_ci.pNext = NULL;
1876 pc_ci.initialSize = 0;
1877 pc_ci.initialData = 0;
1878 pc_ci.maxSize = 0;
1879
1880 VkPipeline pipeline;
1881 VkPipelineCache pipelineCache;
1882
1883 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1884 ASSERT_VK_SUCCESS(err);
1885 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1886
1887 msgFlags = m_errorMonitor->GetState(&msgString);
1888 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Tess Gfx Pipeline w/ 0 patchControlPoints.";
1889 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ")) {
1890 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...' but instead '" << msgString.c_str() << "'";
1891 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001892
1893 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1894 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001895 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1896 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis20693172015-09-17 08:46:18 -06001897}
1898*/
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001899// Set scissor and viewport counts to different numbers
1900TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
1901{
1902 // Attempt to Create Gfx Pipeline w/o a VS
1903 VkFlags msgFlags;
1904 std::string msgString;
1905 VkResult err;
1906
1907 ASSERT_NO_FATAL_FAILURE(InitState());
1908 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1909 m_errorMonitor->ClearState();
1910
1911 VkDescriptorTypeCount ds_type_count = {};
1912 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1913 ds_type_count.count = 1;
1914
1915 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1916 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1917 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1918 ds_pool_ci.maxSets = 1;
1919 ds_pool_ci.count = 1;
1920 ds_pool_ci.pTypeCount = &ds_type_count;
1921
1922 VkDescriptorPool ds_pool;
1923 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1924 ASSERT_VK_SUCCESS(err);
1925
1926 VkDescriptorSetLayoutBinding dsl_binding = {};
1927 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1928 dsl_binding.arraySize = 1;
1929 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1930
1931 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1932 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1933 ds_layout_ci.count = 1;
1934 ds_layout_ci.pBinding = &dsl_binding;
1935
1936 VkDescriptorSetLayout ds_layout;
1937 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1938 ASSERT_VK_SUCCESS(err);
1939
1940 VkDescriptorSet descriptorSet;
1941 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1942 ASSERT_VK_SUCCESS(err);
1943
1944 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1945 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1946 pipeline_layout_ci.descriptorSetCount = 1;
1947 pipeline_layout_ci.pSetLayouts = &ds_layout;
1948
1949 VkPipelineLayout pipeline_layout;
1950 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1951 ASSERT_VK_SUCCESS(err);
1952
1953 VkViewport vp = {}; // Just need dummy vp to point to
1954
1955 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1956 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1957 vp_state_ci.scissorCount = 0;
1958 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
1959 vp_state_ci.pViewports = &vp;
1960
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001961 VkPipelineShaderStageCreateInfo shaderStages[2];
1962 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001963
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001964 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1965 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001966 // but add it to be able to run on more devices
1967 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001968 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001969 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001970
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001971 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001972 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001973 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001974
1975 VkGraphicsPipelineCreateInfo gp_ci = {};
1976 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001977 gp_ci.stageCount = 2;
1978 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001979 gp_ci.pViewportState = &vp_state_ci;
1980 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1981 gp_ci.layout = pipeline_layout;
1982 gp_ci.renderPass = renderPass();
1983
1984 VkPipelineCacheCreateInfo pc_ci = {};
1985 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1986
1987 VkPipeline pipeline;
1988 VkPipelineCache pipelineCache;
1989
1990 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1991 ASSERT_VK_SUCCESS(err);
1992 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1993
1994 msgFlags = m_errorMonitor->GetState(&msgString);
1995 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/ viewport and scissor count mismatch.";
1996 if (!strstr(msgString.c_str(),"Gfx Pipeline viewport count (1) must match scissor count (0).")) {
1997 FAIL() << "Error received was not 'Gfx Pipeline viewport count (1) must match scissor count (0).' but instead it was '" << msgString.c_str() << "'";
1998 }
1999
2000 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2001 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002002 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2003 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2004}
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002005// Don't set viewport state in PSO. This is an error b/c we always need this state
2006// for the counts even if the data is going to be set dynamically.
2007TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002008{
2009 // Attempt to Create Gfx Pipeline w/o a VS
2010 VkFlags msgFlags;
2011 std::string msgString;
2012 VkResult err;
2013
2014 ASSERT_NO_FATAL_FAILURE(InitState());
2015 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2016 m_errorMonitor->ClearState();
2017
2018 VkDescriptorTypeCount ds_type_count = {};
2019 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2020 ds_type_count.count = 1;
2021
2022 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2023 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2024 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2025 ds_pool_ci.maxSets = 1;
2026 ds_pool_ci.count = 1;
2027 ds_pool_ci.pTypeCount = &ds_type_count;
2028
2029 VkDescriptorPool ds_pool;
2030 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2031 ASSERT_VK_SUCCESS(err);
2032
2033 VkDescriptorSetLayoutBinding dsl_binding = {};
2034 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2035 dsl_binding.arraySize = 1;
2036 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2037
2038 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2039 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2040 ds_layout_ci.count = 1;
2041 ds_layout_ci.pBinding = &dsl_binding;
2042
2043 VkDescriptorSetLayout ds_layout;
2044 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2045 ASSERT_VK_SUCCESS(err);
2046
2047 VkDescriptorSet descriptorSet;
2048 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
2049 ASSERT_VK_SUCCESS(err);
2050
2051 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2052 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2053 pipeline_layout_ci.descriptorSetCount = 1;
2054 pipeline_layout_ci.pSetLayouts = &ds_layout;
2055
2056 VkPipelineLayout pipeline_layout;
2057 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2058 ASSERT_VK_SUCCESS(err);
2059
2060 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2061 // Set scissor as dynamic to avoid second error
2062 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2063 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2064 dyn_state_ci.dynamicStateCount = 1;
2065 dyn_state_ci.pDynamicStates = &sc_state;
2066
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002067 VkPipelineShaderStageCreateInfo shaderStages[2];
2068 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002069
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002070 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2071 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002072 // but add it to be able to run on more devices
2073 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002074 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002075 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002076
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002077 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002078 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002079 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002080
2081 VkGraphicsPipelineCreateInfo gp_ci = {};
2082 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002083 gp_ci.stageCount = 2;
2084 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002085 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2086 gp_ci.pDynamicState = &dyn_state_ci;
2087 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2088 gp_ci.layout = pipeline_layout;
2089 gp_ci.renderPass = renderPass();
2090
2091 VkPipelineCacheCreateInfo pc_ci = {};
2092 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2093
2094 VkPipeline pipeline;
2095 VkPipelineCache pipelineCache;
2096
2097 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2098 ASSERT_VK_SUCCESS(err);
2099 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2100
2101 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002102 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o viewport state set.";
2103 if (!strstr(msgString.c_str(),"Gfx Pipeline pViewportState is null. Even if ")) {
2104 FAIL() << "Error received was not 'Gfx Pipeline pViewportState is null. Even if...' but instead it was '" << msgString.c_str() << "'";
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002105 }
2106
2107 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2108 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002109 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2110 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2111}
2112// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002113// Then run second test where dynamic scissor count doesn't match PSO scissor count
2114TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002115{
2116 VkFlags msgFlags;
2117 std::string msgString;
2118 VkResult err;
2119
2120 ASSERT_NO_FATAL_FAILURE(InitState());
2121 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2122 m_errorMonitor->ClearState();
2123
2124 VkDescriptorTypeCount ds_type_count = {};
2125 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2126 ds_type_count.count = 1;
2127
2128 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2129 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2130 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2131 ds_pool_ci.maxSets = 1;
2132 ds_pool_ci.count = 1;
2133 ds_pool_ci.pTypeCount = &ds_type_count;
2134
2135 VkDescriptorPool ds_pool;
2136 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2137 ASSERT_VK_SUCCESS(err);
2138
2139 VkDescriptorSetLayoutBinding dsl_binding = {};
2140 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2141 dsl_binding.arraySize = 1;
2142 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2143
2144 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2145 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2146 ds_layout_ci.count = 1;
2147 ds_layout_ci.pBinding = &dsl_binding;
2148
2149 VkDescriptorSetLayout ds_layout;
2150 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2151 ASSERT_VK_SUCCESS(err);
2152
2153 VkDescriptorSet descriptorSet;
2154 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
2155 ASSERT_VK_SUCCESS(err);
2156
2157 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2158 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2159 pipeline_layout_ci.descriptorSetCount = 1;
2160 pipeline_layout_ci.pSetLayouts = &ds_layout;
2161
2162 VkPipelineLayout pipeline_layout;
2163 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2164 ASSERT_VK_SUCCESS(err);
2165
2166 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2167 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2168 vp_state_ci.viewportCount = 1;
2169 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2170 vp_state_ci.scissorCount = 1;
2171 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2172
2173 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2174 // Set scissor as dynamic to avoid that error
2175 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2176 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2177 dyn_state_ci.dynamicStateCount = 1;
2178 dyn_state_ci.pDynamicStates = &sc_state;
2179
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002180 VkPipelineShaderStageCreateInfo shaderStages[2];
2181 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002182
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002183 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2184 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002185 // but add it to be able to run on more devices
2186 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002187 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002188 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002189
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002190 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002191 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002192 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002193
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002194 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2195 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2196 vi_ci.pNext = nullptr;
2197 vi_ci.bindingCount = 0;
2198 vi_ci.pVertexBindingDescriptions = nullptr;
2199 vi_ci.attributeCount = 0;
2200 vi_ci.pVertexAttributeDescriptions = nullptr;
2201
2202 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2203 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2204 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2205
2206 VkPipelineRasterStateCreateInfo rs_ci = {};
2207 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2208 rs_ci.pNext = nullptr;
2209
2210 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2211 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2212 cb_ci.pNext = nullptr;
2213
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002214 VkGraphicsPipelineCreateInfo gp_ci = {};
2215 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002216 gp_ci.stageCount = 2;
2217 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002218 gp_ci.pVertexInputState = &vi_ci;
2219 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002220 gp_ci.pViewportState = &vp_state_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002221 gp_ci.pRasterState = &rs_ci;
2222 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002223 gp_ci.pDynamicState = &dyn_state_ci;
2224 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2225 gp_ci.layout = pipeline_layout;
2226 gp_ci.renderPass = renderPass();
2227
2228 VkPipelineCacheCreateInfo pc_ci = {};
2229 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2230
2231 VkPipeline pipeline;
2232 VkPipelineCache pipelineCache;
2233
2234 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2235 ASSERT_VK_SUCCESS(err);
2236 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2237
2238 msgFlags = m_errorMonitor->GetState(&msgString);
2239 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2240 if (!strstr(msgString.c_str(),"Gfx Pipeline viewportCount is 1, but pViewports is NULL. ")) {
2241 FAIL() << "Error received was not 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...' but instead it was '" << msgString.c_str() << "'";
2242 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002243 m_errorMonitor->ClearState();
2244 // Now hit second fail case where we set scissor w/ different count than PSO
2245 // First need to successfully create the PSO from above by setting pViewports
2246 VkViewport vp = {}; // Just need dummy vp to point to
2247 vp_state_ci.pViewports = &vp;
2248 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2249 ASSERT_VK_SUCCESS(err);
2250 BeginCommandBuffer();
2251 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2252 VkRect2D scissors[2] = {}; // don't care about data
2253 // Count of 2 doesn't match PSO count of 1
2254 vkCmdSetScissor(m_cmdBuffer->GetBufferHandle(), 2, scissors);
2255 Draw(1, 0, 0, 0);
2256
2257 msgFlags = m_errorMonitor->GetState(&msgString);
2258 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic scissorCount different from PSO scissorCount.";
2259 if (!strstr(msgString.c_str(),"Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.")) {
2260 FAIL() << "Error received was not 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...' but instead it was '" << msgString.c_str() << "'";
2261 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002262
2263 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2264 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002265 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2266 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2267}
2268// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002269// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2270TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002271{
2272 VkFlags msgFlags;
2273 std::string msgString;
2274 VkResult err;
2275
2276 ASSERT_NO_FATAL_FAILURE(InitState());
2277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2278 m_errorMonitor->ClearState();
2279
2280 VkDescriptorTypeCount ds_type_count = {};
2281 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2282 ds_type_count.count = 1;
2283
2284 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2285 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2286 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2287 ds_pool_ci.maxSets = 1;
2288 ds_pool_ci.count = 1;
2289 ds_pool_ci.pTypeCount = &ds_type_count;
2290
2291 VkDescriptorPool ds_pool;
2292 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2293 ASSERT_VK_SUCCESS(err);
2294
2295 VkDescriptorSetLayoutBinding dsl_binding = {};
2296 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2297 dsl_binding.arraySize = 1;
2298 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2299
2300 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2301 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2302 ds_layout_ci.count = 1;
2303 ds_layout_ci.pBinding = &dsl_binding;
2304
2305 VkDescriptorSetLayout ds_layout;
2306 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2307 ASSERT_VK_SUCCESS(err);
2308
2309 VkDescriptorSet descriptorSet;
2310 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
2311 ASSERT_VK_SUCCESS(err);
2312
2313 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2314 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2315 pipeline_layout_ci.descriptorSetCount = 1;
2316 pipeline_layout_ci.pSetLayouts = &ds_layout;
2317
2318 VkPipelineLayout pipeline_layout;
2319 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2320 ASSERT_VK_SUCCESS(err);
2321
2322 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2323 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2324 vp_state_ci.scissorCount = 1;
2325 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2326 vp_state_ci.viewportCount = 1;
2327 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2328
2329 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2330 // Set scissor as dynamic to avoid that error
2331 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2332 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2333 dyn_state_ci.dynamicStateCount = 1;
2334 dyn_state_ci.pDynamicStates = &vp_state;
2335
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002336 VkPipelineShaderStageCreateInfo shaderStages[2];
2337 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002338
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002339 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2340 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002341 // but add it to be able to run on more devices
2342 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002343 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002344 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002345
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002346 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002347 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002348 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002349
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002350 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2351 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2352 vi_ci.pNext = nullptr;
2353 vi_ci.bindingCount = 0;
2354 vi_ci.pVertexBindingDescriptions = nullptr;
2355 vi_ci.attributeCount = 0;
2356 vi_ci.pVertexAttributeDescriptions = nullptr;
2357
2358 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2359 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2360 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2361
2362 VkPipelineRasterStateCreateInfo rs_ci = {};
2363 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2364 rs_ci.pNext = nullptr;
2365
2366 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2367 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2368 cb_ci.pNext = nullptr;
2369
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002370 VkGraphicsPipelineCreateInfo gp_ci = {};
2371 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002372 gp_ci.stageCount = 2;
2373 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002374 gp_ci.pVertexInputState = &vi_ci;
2375 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002376 gp_ci.pViewportState = &vp_state_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002377 gp_ci.pRasterState = &rs_ci;
2378 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002379 gp_ci.pDynamicState = &dyn_state_ci;
2380 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2381 gp_ci.layout = pipeline_layout;
2382 gp_ci.renderPass = renderPass();
2383
2384 VkPipelineCacheCreateInfo pc_ci = {};
2385 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2386
2387 VkPipeline pipeline;
2388 VkPipelineCache pipelineCache;
2389
2390 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2391 ASSERT_VK_SUCCESS(err);
2392 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2393
2394 msgFlags = m_errorMonitor->GetState(&msgString);
2395 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2396 if (!strstr(msgString.c_str(),"Gfx Pipeline scissorCount is 1, but pScissors is NULL. ")) {
2397 FAIL() << "Error received was not 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...' but instead it was '" << msgString.c_str() << "'";
2398 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002399 m_errorMonitor->ClearState();
2400 // Now hit second fail case where we set scissor w/ different count than PSO
2401 // First need to successfully create the PSO from above by setting pViewports
2402 VkRect2D sc = {}; // Just need dummy vp to point to
2403 vp_state_ci.pScissors = &sc;
2404 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2405 ASSERT_VK_SUCCESS(err);
2406 BeginCommandBuffer();
2407 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2408 VkViewport viewports[2] = {}; // don't care about data
2409 // Count of 2 doesn't match PSO count of 1
2410 vkCmdSetViewport(m_cmdBuffer->GetBufferHandle(), 2, viewports);
2411 Draw(1, 0, 0, 0);
2412
2413 msgFlags = m_errorMonitor->GetState(&msgString);
2414 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic viewportCount different from PSO viewportCount.";
2415 if (!strstr(msgString.c_str(),"Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.")) {
2416 FAIL() << "Error received was not 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...' but instead it was '" << msgString.c_str() << "'";
2417 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002418
2419 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2420 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002421 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2422 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2423}
2424
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002425TEST_F(VkLayerTest, NullRenderPass)
2426{
2427 // Bind a NULL RenderPass
2428 VkFlags msgFlags;
2429 std::string msgString;
2430
2431 ASSERT_NO_FATAL_FAILURE(InitState());
2432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2433 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002434
Tony Barbour1490c912015-07-28 10:17:20 -06002435 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002436 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06002437 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002438
2439 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002440 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002441 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
2442 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2443 }
2444}
2445
Tobin Ehlis254eca02015-06-25 15:46:59 -06002446TEST_F(VkLayerTest, RenderPassWithinRenderPass)
2447{
2448 // Bind a BeginRenderPass within an active RenderPass
2449 VkFlags msgFlags;
2450 std::string msgString;
2451
2452 ASSERT_NO_FATAL_FAILURE(InitState());
2453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2454 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002455
Tony Barbour1490c912015-07-28 10:17:20 -06002456 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002457 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002458 VkRenderPassBeginInfo rp_begin = {};
2459 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
2460 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002461 rp_begin.renderPass = renderPass();
2462 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002463
Tony Barbour1490c912015-07-28 10:17:20 -06002464 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002465
2466 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002467 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002468 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2469 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002470 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002471}
2472
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002473TEST_F(VkLayerTest, FillBufferWithinRenderPass)
2474{
2475 // Call CmdFillBuffer within an active renderpass
2476 VkFlags msgFlags;
2477 std::string msgString;
2478
2479 ASSERT_NO_FATAL_FAILURE(InitState());
2480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2481 m_errorMonitor->ClearState();
2482
2483 // Renderpass is started here
2484 BeginCommandBuffer();
2485
2486 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2487 vk_testing::Buffer destBuffer;
2488 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2489
2490 m_cmdBuffer->FillBuffer(destBuffer.handle(), 0, 4, 0x11111111);
2491
2492 msgFlags = m_errorMonitor->GetState(&msgString);
2493 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2494 "Did not receive error after calling CmdFillBuffer w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002495 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2496 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002497 }
2498}
2499
2500TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
2501{
2502 // Call CmdUpdateBuffer within an active renderpass
2503 VkFlags msgFlags;
2504 std::string msgString;
2505
2506 ASSERT_NO_FATAL_FAILURE(InitState());
2507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2508 m_errorMonitor->ClearState();
2509
2510 // Renderpass is started here
2511 BeginCommandBuffer();
2512
2513 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2514 vk_testing::Buffer destBuffer;
2515 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2516
2517 VkDeviceSize destOffset = 0;
2518 VkDeviceSize dataSize = 1024;
2519 const uint32_t *pData = NULL;
2520
2521 vkCmdUpdateBuffer(m_cmdBuffer->GetBufferHandle(), destBuffer.handle(), destOffset, dataSize, pData);
2522
2523 msgFlags = m_errorMonitor->GetState(&msgString);
2524 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2525 "Did not receive error after calling CmdUpdateBuffer w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002526 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2527 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002528 }
2529}
2530
2531TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
2532{
2533 // Call CmdClearColorImage within an active RenderPass
2534 VkFlags msgFlags;
2535 std::string msgString;
2536
2537 ASSERT_NO_FATAL_FAILURE(InitState());
2538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2539 m_errorMonitor->ClearState();
2540
2541 // Renderpass is started here
2542 BeginCommandBuffer();
2543
2544 VkClearColorValue clear_color = {0};
2545 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2546 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2547 const int32_t tex_width = 32;
2548 const int32_t tex_height = 32;
2549 VkImageCreateInfo image_create_info = {};
2550 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2551 image_create_info.pNext = NULL;
2552 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2553 image_create_info.format = tex_format;
2554 image_create_info.extent.width = tex_width;
2555 image_create_info.extent.height = tex_height;
2556 image_create_info.extent.depth = 1;
2557 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06002558 image_create_info.arrayLayers = 1;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002559 image_create_info.samples = 1;
2560 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2561 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2562
2563 vk_testing::Image destImage;
2564 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2565
2566 const VkImageSubresourceRange range =
2567 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
2568
2569 vkCmdClearColorImage(m_cmdBuffer->GetBufferHandle(),
2570 destImage.handle(),
2571 VK_IMAGE_LAYOUT_GENERAL,
2572 &clear_color,
2573 1,
2574 &range);
2575
2576 msgFlags = m_errorMonitor->GetState(&msgString);
2577 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2578 "Did not receive error after calling CmdClearColorImage w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002579 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2580 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002581 }
2582}
2583
2584TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
2585{
2586 // Call CmdClearDepthStencilImage within an active RenderPass
2587 VkFlags msgFlags;
2588 std::string msgString;
2589
2590 ASSERT_NO_FATAL_FAILURE(InitState());
2591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2592 m_errorMonitor->ClearState();
2593
2594 // Renderpass is started here
2595 BeginCommandBuffer();
2596
2597 VkClearDepthStencilValue clear_value = {0};
2598 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2599 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
2600 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2601 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
2602 image_create_info.extent.width = 64;
2603 image_create_info.extent.height = 64;
2604 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2605 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2606
2607 vk_testing::Image destImage;
2608 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2609
2610 const VkImageSubresourceRange range =
2611 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
2612
2613 vkCmdClearDepthStencilImage(m_cmdBuffer->GetBufferHandle(),
2614 destImage.handle(),
2615 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2616 &clear_value,
2617 1,
2618 &range);
2619
2620 msgFlags = m_errorMonitor->GetState(&msgString);
2621 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2622 "Did not receive error after calling CmdClearDepthStencilImage w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002623 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2624 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002625 }
2626}
2627
2628TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
2629{
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002630 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002631 VkFlags msgFlags;
2632 std::string msgString;
2633 VkResult err;
2634
2635 ASSERT_NO_FATAL_FAILURE(InitState());
2636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2637 m_errorMonitor->ClearState();
2638
2639 // Start no RenderPass
2640 err = m_cmdBuffer->BeginCommandBuffer();
2641 ASSERT_VK_SUCCESS(err);
2642
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002643 VkClearAttachment color_attachment;
2644 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2645 color_attachment.clearValue.color.float32[0] = 0;
2646 color_attachment.clearValue.color.float32[1] = 0;
2647 color_attachment.clearValue.color.float32[2] = 0;
2648 color_attachment.clearValue.color.float32[3] = 0;
2649 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06002650 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002651 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(),
2652 1, &color_attachment,
2653 1, &clear_rect);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002654
2655 msgFlags = m_errorMonitor->GetState(&msgString);
2656 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002657 "Did not receive error after calling CmdClearAttachments outside of an active RenderPass.";
2658 if (!strstr(msgString.c_str(),"vkCmdClearAttachments: This call must be issued inside an active render pass")) {
2659 FAIL() << "Error received was not 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002660 }
2661}
2662
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002663TEST_F(VkLayerTest, InvalidDynamicStateObject)
2664{
2665 // Create a valid cmd buffer
2666 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002667 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
2668 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002669}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06002670
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002671TEST_F(VkLayerTest, IdxBufferAlignmentError)
2672{
2673 // Bind a BeginRenderPass within an active RenderPass
2674 VkFlags msgFlags;
2675 std::string msgString;
2676 VkResult err;
2677
2678 ASSERT_NO_FATAL_FAILURE(InitState());
2679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2680 m_errorMonitor->ClearState();
2681 uint32_t qfi = 0;
2682 VkBufferCreateInfo buffCI = {};
2683 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2684 buffCI.size = 1024;
2685 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
2686 buffCI.queueFamilyCount = 1;
2687 buffCI.pQueueFamilyIndices = &qfi;
2688
2689 VkBuffer ib;
2690 err = vkCreateBuffer(m_device->device(), &buffCI, &ib);
2691 ASSERT_VK_SUCCESS(err);
2692
2693 BeginCommandBuffer();
2694 ASSERT_VK_SUCCESS(err);
2695 //vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2696 // Should error before calling to driver so don't care about actual data
2697 vkCmdBindIndexBuffer(m_cmdBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
2698
2699 msgFlags = m_errorMonitor->GetState(&msgString);
2700 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2701 if (!strstr(msgString.c_str(),"vkCmdBindIndexBuffer() offset (0x7) does not fall on ")) {
2702 FAIL() << "Error received was not 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...' but instead '" << msgString.c_str() << "'";
2703 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002704
2705 vkDestroyBuffer(m_device->device(), ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002706}
2707
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002708TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2709{
2710 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
2711 VkFlags msgFlags;
2712 std::string msgString;
2713
2714 ASSERT_NO_FATAL_FAILURE(InitState());
2715 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2716 m_errorMonitor->ClearState();
2717
2718 BeginCommandBuffer();
2719 //ASSERT_VK_SUCCESS(err);
2720 VkCmdBuffer primCB = m_cmdBuffer->GetBufferHandle();
2721 vkCmdExecuteCommands(m_cmdBuffer->GetBufferHandle(), 1, &primCB);
2722
2723 msgFlags = m_errorMonitor->GetState(&msgString);
2724 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2725 if (!strstr(msgString.c_str(),"vkCmdExecuteCommands() called w/ Primary Cmd Buffer ")) {
2726 FAIL() << "Error received was not 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer ' but instead '" << msgString.c_str() << "'";
2727 }
2728}
2729
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002730TEST_F(VkLayerTest, DSTypeMismatch)
2731{
2732 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002733 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002734 std::string msgString;
2735 VkResult err;
2736
2737 ASSERT_NO_FATAL_FAILURE(InitState());
2738 m_errorMonitor->ClearState();
2739 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002740 VkDescriptorTypeCount ds_type_count = {};
2741 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2742 ds_type_count.count = 1;
2743
2744 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2745 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2746 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002747 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2748 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002749 ds_pool_ci.count = 1;
2750 ds_pool_ci.pTypeCount = &ds_type_count;
2751
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002752 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002753 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002754 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002755 VkDescriptorSetLayoutBinding dsl_binding = {};
2756 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2757 dsl_binding.arraySize = 1;
2758 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2759 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002760
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002761 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2762 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2763 ds_layout_ci.pNext = NULL;
2764 ds_layout_ci.count = 1;
2765 ds_layout_ci.pBinding = &dsl_binding;
2766
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002767 VkDescriptorSetLayout ds_layout;
2768 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2769 ASSERT_VK_SUCCESS(err);
2770
2771 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002772 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002773 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002774
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002775 VkSamplerCreateInfo sampler_ci = {};
2776 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2777 sampler_ci.pNext = NULL;
2778 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2779 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2780 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002781 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2782 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2783 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002784 sampler_ci.mipLodBias = 1.0;
2785 sampler_ci.maxAnisotropy = 1;
2786 sampler_ci.compareEnable = VK_FALSE;
2787 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2788 sampler_ci.minLod = 1.0;
2789 sampler_ci.maxLod = 1.0;
2790 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002791 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2792
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002793 VkSampler sampler;
2794 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2795 ASSERT_VK_SUCCESS(err);
2796
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002797 VkDescriptorInfo descriptor_info;
2798 memset(&descriptor_info, 0, sizeof(descriptor_info));
2799 descriptor_info.sampler = sampler;
2800
2801 VkWriteDescriptorSet descriptor_write;
2802 memset(&descriptor_write, 0, sizeof(descriptor_write));
2803 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2804 descriptor_write.destSet = descriptorSet;
2805 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002806 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002807 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2808 descriptor_write.pDescriptors = &descriptor_info;
2809
2810 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2811
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002812 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002813 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating BUFFER Descriptor w/ incorrect type of SAMPLER.";
Tobin Ehlis3b341092015-09-30 08:30:20 -06002814 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 ")) {
2815 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 Ehlis2f87d2d2015-05-28 12:11:26 -06002816 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002817
2818 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06002819 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2820 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002821}
2822
2823TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2824{
2825 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002826 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002827 std::string msgString;
2828 VkResult err;
2829
2830 ASSERT_NO_FATAL_FAILURE(InitState());
2831 m_errorMonitor->ClearState();
2832 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002833 VkDescriptorTypeCount ds_type_count = {};
2834 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2835 ds_type_count.count = 1;
2836
2837 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2838 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2839 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002840 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2841 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002842 ds_pool_ci.count = 1;
2843 ds_pool_ci.pTypeCount = &ds_type_count;
2844
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002845 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002846 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002847 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002848
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002849 VkDescriptorSetLayoutBinding dsl_binding = {};
2850 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2851 dsl_binding.arraySize = 1;
2852 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2853 dsl_binding.pImmutableSamplers = NULL;
2854
2855 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2856 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2857 ds_layout_ci.pNext = NULL;
2858 ds_layout_ci.count = 1;
2859 ds_layout_ci.pBinding = &dsl_binding;
2860
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002861 VkDescriptorSetLayout ds_layout;
2862 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2863 ASSERT_VK_SUCCESS(err);
2864
2865 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002866 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002867 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002868
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002869 VkSamplerCreateInfo sampler_ci = {};
2870 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2871 sampler_ci.pNext = NULL;
2872 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2873 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2874 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002875 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2876 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2877 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002878 sampler_ci.mipLodBias = 1.0;
2879 sampler_ci.maxAnisotropy = 1;
2880 sampler_ci.compareEnable = VK_FALSE;
2881 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2882 sampler_ci.minLod = 1.0;
2883 sampler_ci.maxLod = 1.0;
2884 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002885 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002886
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002887 VkSampler sampler;
2888 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2889 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002890
2891 VkDescriptorInfo descriptor_info;
2892 memset(&descriptor_info, 0, sizeof(descriptor_info));
2893 descriptor_info.sampler = sampler;
2894
2895 VkWriteDescriptorSet descriptor_write;
2896 memset(&descriptor_write, 0, sizeof(descriptor_write));
2897 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2898 descriptor_write.destSet = descriptorSet;
2899 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
2900 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002901 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002902 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2903 descriptor_write.pDescriptors = &descriptor_info;
2904
2905 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2906
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002907 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002908 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ index out of bounds.";
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002909 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
2910 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002911 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002912
2913 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06002914 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2915 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002916}
2917
2918TEST_F(VkLayerTest, InvalidDSUpdateIndex)
2919{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002920 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002921 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002922 std::string msgString;
2923 VkResult err;
2924
2925 ASSERT_NO_FATAL_FAILURE(InitState());
2926 m_errorMonitor->ClearState();
2927 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002928 VkDescriptorTypeCount ds_type_count = {};
2929 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2930 ds_type_count.count = 1;
2931
2932 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2933 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2934 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002935 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2936 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002937 ds_pool_ci.count = 1;
2938 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002939
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002940 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002941 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002942 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002943
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002944 VkDescriptorSetLayoutBinding dsl_binding = {};
2945 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2946 dsl_binding.arraySize = 1;
2947 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2948 dsl_binding.pImmutableSamplers = NULL;
2949
2950 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2951 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2952 ds_layout_ci.pNext = NULL;
2953 ds_layout_ci.count = 1;
2954 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002955 VkDescriptorSetLayout ds_layout;
2956 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2957 ASSERT_VK_SUCCESS(err);
2958
2959 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002960 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002961 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002962
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002963 VkSamplerCreateInfo sampler_ci = {};
2964 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2965 sampler_ci.pNext = NULL;
2966 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2967 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2968 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002969 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2970 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2971 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002972 sampler_ci.mipLodBias = 1.0;
2973 sampler_ci.maxAnisotropy = 1;
2974 sampler_ci.compareEnable = VK_FALSE;
2975 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2976 sampler_ci.minLod = 1.0;
2977 sampler_ci.maxLod = 1.0;
2978 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002979 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002980
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002981 VkSampler sampler;
2982 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2983 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002984
2985 VkDescriptorInfo descriptor_info;
2986 memset(&descriptor_info, 0, sizeof(descriptor_info));
2987 descriptor_info.sampler = sampler;
2988
2989 VkWriteDescriptorSet descriptor_write;
2990 memset(&descriptor_write, 0, sizeof(descriptor_write));
2991 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2992 descriptor_write.destSet = descriptorSet;
2993 descriptor_write.destBinding = 2;
2994 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002995 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002996 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2997 descriptor_write.pDescriptors = &descriptor_info;
2998
2999 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3000
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003001 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003002 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ count too large for layout.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003003 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
3004 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
3005 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003006
3007 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06003008 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3009 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003010}
3011
3012TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3013{
3014 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003015 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003016 std::string msgString;
3017 VkResult err;
3018
3019 ASSERT_NO_FATAL_FAILURE(InitState());
3020 m_errorMonitor->ClearState();
3021 //VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003022
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003023 VkDescriptorTypeCount ds_type_count = {};
3024 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3025 ds_type_count.count = 1;
3026
3027 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3028 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3029 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003030 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3031 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003032 ds_pool_ci.count = 1;
3033 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003034
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003035 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003036 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003037 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003038 VkDescriptorSetLayoutBinding dsl_binding = {};
3039 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3040 dsl_binding.arraySize = 1;
3041 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3042 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003043
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003044 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3045 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3046 ds_layout_ci.pNext = NULL;
3047 ds_layout_ci.count = 1;
3048 ds_layout_ci.pBinding = &dsl_binding;
3049
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003050 VkDescriptorSetLayout ds_layout;
3051 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3052 ASSERT_VK_SUCCESS(err);
3053
3054 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003055 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003056 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003057
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003058 VkSamplerCreateInfo sampler_ci = {};
3059 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3060 sampler_ci.pNext = NULL;
3061 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
3062 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
3063 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06003064 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3065 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3066 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003067 sampler_ci.mipLodBias = 1.0;
3068 sampler_ci.maxAnisotropy = 1;
3069 sampler_ci.compareEnable = VK_FALSE;
3070 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3071 sampler_ci.minLod = 1.0;
3072 sampler_ci.maxLod = 1.0;
3073 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003074 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003075 VkSampler sampler;
3076 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3077 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003078
3079
3080 VkDescriptorInfo descriptor_info;
3081 memset(&descriptor_info, 0, sizeof(descriptor_info));
3082 descriptor_info.sampler = sampler;
3083
3084 VkWriteDescriptorSet descriptor_write;
3085 memset(&descriptor_write, 0, sizeof(descriptor_write));
3086 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
3087 descriptor_write.destSet = descriptorSet;
3088 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003089 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003090 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3091 descriptor_write.pDescriptors = &descriptor_info;
3092
3093 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3094
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003095 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003096 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid struct type.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003097 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
3098 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
3099 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003100
3101 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06003102 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3103 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003104}
3105
3106TEST_F(VkLayerTest, NumSamplesMismatch)
3107{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003108 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003109 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003110 std::string msgString;
3111 VkResult err;
3112
3113 ASSERT_NO_FATAL_FAILURE(InitState());
3114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3115 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003116 VkDescriptorTypeCount ds_type_count = {};
3117 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3118 ds_type_count.count = 1;
3119
3120 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003121 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3122 ds_pool_ci.pNext = NULL;
3123 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3124 ds_pool_ci.maxSets = 1;
3125 ds_pool_ci.count = 1;
3126 ds_pool_ci.pTypeCount = &ds_type_count;
3127
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003128 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003129 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003130 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003131
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003132 VkDescriptorSetLayoutBinding dsl_binding = {};
3133 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3134 dsl_binding.arraySize = 1;
3135 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3136 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003137
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003138 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3139 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3140 ds_layout_ci.pNext = NULL;
3141 ds_layout_ci.count = 1;
3142 ds_layout_ci.pBinding = &dsl_binding;
3143
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003144 VkDescriptorSetLayout ds_layout;
3145 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3146 ASSERT_VK_SUCCESS(err);
3147
3148 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003149 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003150 ASSERT_VK_SUCCESS(err);
3151
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003152 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3153 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3154 pipe_ms_state_ci.pNext = NULL;
3155 pipe_ms_state_ci.rasterSamples = 4;
3156 pipe_ms_state_ci.sampleShadingEnable = 0;
3157 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003158 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003159
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003160 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3161 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3162 pipeline_layout_ci.pNext = NULL;
3163 pipeline_layout_ci.descriptorSetCount = 1;
3164 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003165
3166 VkPipelineLayout pipeline_layout;
3167 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3168 ASSERT_VK_SUCCESS(err);
3169
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003170 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3171 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003172 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003173 VkPipelineObj pipe(m_device);
3174 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003175 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003176 pipe.SetMSAA(&pipe_ms_state_ci);
3177 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003178
Tony Barbour1490c912015-07-28 10:17:20 -06003179 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06003180 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003181
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003182 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003183 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/ mismatched MSAA from PSO.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003184 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
3185 FAIL() << "Error received was not 'Num samples mismatch!...'";
3186 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003187
3188 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003189 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3190 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003191}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003192
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003193TEST_F(VkLayerTest, ClearCmdNoDraw)
3194{
3195 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
3196 VkFlags msgFlags;
3197 std::string msgString;
3198 VkResult err;
3199
3200 ASSERT_NO_FATAL_FAILURE(InitState());
3201 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3202 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003203
3204 VkDescriptorTypeCount ds_type_count = {};
3205 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3206 ds_type_count.count = 1;
3207
3208 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3209 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3210 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003211 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3212 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003213 ds_pool_ci.count = 1;
3214 ds_pool_ci.pTypeCount = &ds_type_count;
3215
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003216 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003217 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003218 ASSERT_VK_SUCCESS(err);
3219
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003220 VkDescriptorSetLayoutBinding dsl_binding = {};
3221 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3222 dsl_binding.arraySize = 1;
3223 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3224 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003225
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003226 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3227 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3228 ds_layout_ci.pNext = NULL;
3229 ds_layout_ci.count = 1;
3230 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003231
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003232 VkDescriptorSetLayout ds_layout;
3233 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3234 ASSERT_VK_SUCCESS(err);
3235
3236 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003237 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003238 ASSERT_VK_SUCCESS(err);
3239
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003240 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3241 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3242 pipe_ms_state_ci.pNext = NULL;
3243 pipe_ms_state_ci.rasterSamples = 4;
3244 pipe_ms_state_ci.sampleShadingEnable = 0;
3245 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003246 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003247
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003248 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3249 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3250 pipeline_layout_ci.pNext = NULL;
3251 pipeline_layout_ci.descriptorSetCount = 1;
3252 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003253
3254 VkPipelineLayout pipeline_layout;
3255 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3256 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003257
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003258 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3259 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003260 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003261 VkPipelineObj pipe(m_device);
3262 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003263 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003264 pipe.SetMSAA(&pipe_ms_state_ci);
3265 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003266
3267 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003268
3269 m_errorMonitor->ClearState();
3270 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3271 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003272 VkClearAttachment color_attachment;
3273 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3274 color_attachment.clearValue.color.float32[0] = 1.0;
3275 color_attachment.clearValue.color.float32[1] = 1.0;
3276 color_attachment.clearValue.color.float32[2] = 1.0;
3277 color_attachment.clearValue.color.float32[3] = 1.0;
3278 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06003279 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003280
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003281 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003282 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003283 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 Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003284 if (!strstr(msgString.c_str(),"vkCmdClearAttachments() issued on CB object ")) {
3285 FAIL() << "Error received was not 'vkCmdClearAttachments() issued on CB object...'";
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003286 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003287
3288 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003289 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3290 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003291}
3292
Tobin Ehlise4076782015-06-24 15:53:07 -06003293TEST_F(VkLayerTest, VtxBufferBadIndex)
3294{
3295 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
3296 VkFlags msgFlags;
3297 std::string msgString;
3298 VkResult err;
3299
3300 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003301 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06003302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3303 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003304
3305 VkDescriptorTypeCount ds_type_count = {};
3306 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3307 ds_type_count.count = 1;
3308
3309 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3310 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3311 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003312 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3313 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003314 ds_pool_ci.count = 1;
3315 ds_pool_ci.pTypeCount = &ds_type_count;
3316
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003317 VkDescriptorPool ds_pool;
3318 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003319 ASSERT_VK_SUCCESS(err);
3320
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003321 VkDescriptorSetLayoutBinding dsl_binding = {};
3322 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3323 dsl_binding.arraySize = 1;
3324 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3325 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003326
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003327 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3328 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3329 ds_layout_ci.pNext = NULL;
3330 ds_layout_ci.count = 1;
3331 ds_layout_ci.pBinding = &dsl_binding;
3332
Tobin Ehlise4076782015-06-24 15:53:07 -06003333 VkDescriptorSetLayout ds_layout;
3334 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3335 ASSERT_VK_SUCCESS(err);
3336
3337 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003338 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06003339 ASSERT_VK_SUCCESS(err);
3340
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003341 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3342 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3343 pipe_ms_state_ci.pNext = NULL;
3344 pipe_ms_state_ci.rasterSamples = 1;
3345 pipe_ms_state_ci.sampleShadingEnable = 0;
3346 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003347 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003348
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003349 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3350 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3351 pipeline_layout_ci.pNext = NULL;
3352 pipeline_layout_ci.descriptorSetCount = 1;
3353 pipeline_layout_ci.pSetLayouts = &ds_layout;
3354 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06003355
Tobin Ehlise4076782015-06-24 15:53:07 -06003356 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3357 ASSERT_VK_SUCCESS(err);
3358
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003359 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3360 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003361 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003362 VkPipelineObj pipe(m_device);
3363 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003364 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003365 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003366 pipe.SetViewport(m_viewports);
3367 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003368 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003369
3370 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06003371 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06003372 // Don't care about actual data, just need to get to draw to flag error
3373 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3374 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3375 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003376 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06003377
3378 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003379 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
Tobin Ehlisd28acef2015-09-09 15:12:35 -06003380 if (!strstr(msgString.c_str(),"Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.")) {
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003381 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 Ehlise4076782015-06-24 15:53:07 -06003382 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003383
3384 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003385 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3386 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003387}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003388#endif // DRAW_STATE_TESTS
3389
Tobin Ehlis57e6a612015-05-26 16:11:58 -06003390#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06003391#if GTEST_IS_THREADSAFE
3392struct thread_data_struct {
3393 VkCmdBuffer cmdBuffer;
3394 VkEvent event;
3395 bool bailout;
3396};
3397
3398extern "C" void *AddToCommandBuffer(void *arg)
3399{
3400 struct thread_data_struct *data = (struct thread_data_struct *) arg;
3401 std::string msgString;
3402
3403 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06003404 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06003405 if (data->bailout) {
3406 break;
3407 }
3408 }
3409 return NULL;
3410}
3411
3412TEST_F(VkLayerTest, ThreadCmdBufferCollision)
3413{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003414 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06003415 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003416 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06003417
3418 ASSERT_NO_FATAL_FAILURE(InitState());
3419 ASSERT_NO_FATAL_FAILURE(InitViewport());
3420 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3421
Mike Stroyan09aae812015-05-12 16:00:45 -06003422 m_errorMonitor->ClearState();
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003423
3424 // Calls CreateCommandBuffer
3425 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
3426
3427 // Avoid creating RenderPass
3428 cmdBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003429
3430 VkEventCreateInfo event_info;
3431 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06003432 VkResult err;
3433
3434 memset(&event_info, 0, sizeof(event_info));
3435 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3436
3437 err = vkCreateEvent(device(), &event_info, &event);
3438 ASSERT_VK_SUCCESS(err);
3439
Mike Stroyan09aae812015-05-12 16:00:45 -06003440 err = vkResetEvent(device(), event);
3441 ASSERT_VK_SUCCESS(err);
3442
3443 struct thread_data_struct data;
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003444 data.cmdBuffer = cmdBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06003445 data.event = event;
3446 data.bailout = false;
3447 m_errorMonitor->SetBailout(&data.bailout);
3448 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003449 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06003450 // Add many entries to command buffer from this thread at the same time.
3451 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003452
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003453 test_platform_thread_join(thread, NULL);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003454 cmdBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003455
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003456 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003457 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err from using one VkCommandBufferObj in two threads";
Mike Stroyan09aae812015-05-12 16:00:45 -06003458 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05003459 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06003460 }
3461
Mike Stroyan2237f522015-08-18 14:40:24 -06003462 vkDestroyEvent(device(), event);
Mike Stroyan09aae812015-05-12 16:00:45 -06003463}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003464#endif // GTEST_IS_THREADSAFE
3465#endif // THREADING_TESTS
3466
Chris Forbes5af3bf22015-05-25 11:13:08 +12003467#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003468TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
3469{
3470 VkFlags msgFlags;
3471 std::string msgString;
3472 ASSERT_NO_FATAL_FAILURE(InitState());
3473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3474
3475 m_errorMonitor->ClearState();
3476
3477 VkShaderModule module;
3478 VkShaderModuleCreateInfo moduleCreateInfo;
3479 struct icd_spv_header spv;
3480
3481 spv.magic = ICD_SPV_MAGIC;
3482 spv.version = ICD_SPV_VERSION;
3483 spv.gen_magic = 0;
3484
3485 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3486 moduleCreateInfo.pNext = NULL;
3487 moduleCreateInfo.pCode = &spv;
3488 moduleCreateInfo.codeSize = 4;
3489 moduleCreateInfo.flags = 0;
3490 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3491
3492 msgFlags = m_errorMonitor->GetState(&msgString);
3493
Chris Forbes96b81762015-09-18 11:40:23 +12003494 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003495 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3496 FAIL() << "Incorrect warning: " << msgString;
3497 }
3498}
3499
3500TEST_F(VkLayerTest, InvalidSPIRVMagic)
3501{
3502 VkFlags msgFlags;
3503 std::string msgString;
3504 ASSERT_NO_FATAL_FAILURE(InitState());
3505 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3506
3507 m_errorMonitor->ClearState();
3508
3509 VkShaderModule module;
3510 VkShaderModuleCreateInfo moduleCreateInfo;
3511 struct icd_spv_header spv;
3512
3513 spv.magic = ~ICD_SPV_MAGIC;
3514 spv.version = ICD_SPV_VERSION;
3515 spv.gen_magic = 0;
3516
3517 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3518 moduleCreateInfo.pNext = NULL;
3519 moduleCreateInfo.pCode = &spv;
3520 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3521 moduleCreateInfo.flags = 0;
3522 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3523
3524 msgFlags = m_errorMonitor->GetState(&msgString);
3525
Chris Forbes96b81762015-09-18 11:40:23 +12003526 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003527 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3528 FAIL() << "Incorrect warning: " << msgString;
3529 }
3530}
3531
3532TEST_F(VkLayerTest, InvalidSPIRVVersion)
3533{
3534 VkFlags msgFlags;
3535 std::string msgString;
3536 ASSERT_NO_FATAL_FAILURE(InitState());
3537 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3538
3539 m_errorMonitor->ClearState();
3540
3541 VkShaderModule module;
3542 VkShaderModuleCreateInfo moduleCreateInfo;
3543 struct icd_spv_header spv;
3544
3545 spv.magic = ICD_SPV_MAGIC;
3546 spv.version = ~ICD_SPV_VERSION;
3547 spv.gen_magic = 0;
3548
3549 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3550 moduleCreateInfo.pNext = NULL;
3551
3552 moduleCreateInfo.pCode = &spv;
3553 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3554 moduleCreateInfo.flags = 0;
3555 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3556
3557 msgFlags = m_errorMonitor->GetState(&msgString);
3558
Chris Forbes96b81762015-09-18 11:40:23 +12003559 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003560 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3561 FAIL() << "Incorrect warning: " << msgString;
3562 }
3563}
3564
Chris Forbes5af3bf22015-05-25 11:13:08 +12003565TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
3566{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003567 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12003568 std::string msgString;
3569 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003570 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12003571
3572 char const *vsSource =
3573 "#version 140\n"
3574 "#extension GL_ARB_separate_shader_objects: require\n"
3575 "#extension GL_ARB_shading_language_420pack: require\n"
3576 "\n"
3577 "layout(location=0) out float x;\n"
3578 "void main(){\n"
3579 " gl_Position = vec4(1);\n"
3580 " x = 0;\n"
3581 "}\n";
3582 char const *fsSource =
3583 "#version 140\n"
3584 "#extension GL_ARB_separate_shader_objects: require\n"
3585 "#extension GL_ARB_shading_language_420pack: require\n"
3586 "\n"
3587 "layout(location=0) out vec4 color;\n"
3588 "void main(){\n"
3589 " color = vec4(1);\n"
3590 "}\n";
3591
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003592 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3593 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003594
3595 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003596 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12003597 pipe.AddShader(&vs);
3598 pipe.AddShader(&fs);
3599
Chris Forbes5af3bf22015-05-25 11:13:08 +12003600 VkDescriptorSetObj descriptorSet(m_device);
3601 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003602 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003603
3604 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003605 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12003606
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003607 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003608
Cody Northrop1684adb2015-08-05 11:15:02 -06003609 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003610 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
3611 FAIL() << "Incorrect warning: " << msgString;
3612 }
3613}
Chris Forbes5af3bf22015-05-25 11:13:08 +12003614
Chris Forbes3c10b852015-05-25 11:13:13 +12003615TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
3616{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003617 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12003618 std::string msgString;
3619 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12003621
3622 char const *vsSource =
3623 "#version 140\n"
3624 "#extension GL_ARB_separate_shader_objects: require\n"
3625 "#extension GL_ARB_shading_language_420pack: require\n"
3626 "\n"
3627 "void main(){\n"
3628 " gl_Position = vec4(1);\n"
3629 "}\n";
3630 char const *fsSource =
3631 "#version 140\n"
3632 "#extension GL_ARB_separate_shader_objects: require\n"
3633 "#extension GL_ARB_shading_language_420pack: require\n"
3634 "\n"
3635 "layout(location=0) in float x;\n"
3636 "layout(location=0) out vec4 color;\n"
3637 "void main(){\n"
3638 " color = vec4(x);\n"
3639 "}\n";
3640
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003641 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3642 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes3c10b852015-05-25 11:13:13 +12003643
3644 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003645 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12003646 pipe.AddShader(&vs);
3647 pipe.AddShader(&fs);
3648
Chris Forbes3c10b852015-05-25 11:13:13 +12003649 VkDescriptorSetObj descriptorSet(m_device);
3650 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003651 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12003652
3653 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003654 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12003655
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003656 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12003657
Cody Northrop1684adb2015-08-05 11:15:02 -06003658 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12003659 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
3660 FAIL() << "Incorrect error: " << msgString;
3661 }
3662}
3663
Chris Forbescc281692015-05-25 11:13:17 +12003664TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
3665{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003666 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12003667 std::string msgString;
3668 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003669 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12003670
3671 char const *vsSource =
3672 "#version 140\n"
3673 "#extension GL_ARB_separate_shader_objects: require\n"
3674 "#extension GL_ARB_shading_language_420pack: require\n"
3675 "\n"
3676 "layout(location=0) out int x;\n"
3677 "void main(){\n"
3678 " x = 0;\n"
3679 " gl_Position = vec4(1);\n"
3680 "}\n";
3681 char const *fsSource =
3682 "#version 140\n"
3683 "#extension GL_ARB_separate_shader_objects: require\n"
3684 "#extension GL_ARB_shading_language_420pack: require\n"
3685 "\n"
3686 "layout(location=0) in float x;\n" /* VS writes int */
3687 "layout(location=0) out vec4 color;\n"
3688 "void main(){\n"
3689 " color = vec4(x);\n"
3690 "}\n";
3691
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003692 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3693 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbescc281692015-05-25 11:13:17 +12003694
3695 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003696 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12003697 pipe.AddShader(&vs);
3698 pipe.AddShader(&fs);
3699
Chris Forbescc281692015-05-25 11:13:17 +12003700 VkDescriptorSetObj descriptorSet(m_device);
3701 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003702 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12003703
3704 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003705 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12003706
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003707 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12003708
Cody Northrop1684adb2015-08-05 11:15:02 -06003709 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12003710 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
3711 FAIL() << "Incorrect error: " << msgString;
3712 }
3713}
3714
Chris Forbes8291c052015-05-25 11:13:28 +12003715TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
3716{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003717 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12003718 std::string msgString;
3719 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003720 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12003721
3722 VkVertexInputBindingDescription input_binding;
3723 memset(&input_binding, 0, sizeof(input_binding));
3724
3725 VkVertexInputAttributeDescription input_attrib;
3726 memset(&input_attrib, 0, sizeof(input_attrib));
3727 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3728
3729 char const *vsSource =
3730 "#version 140\n"
3731 "#extension GL_ARB_separate_shader_objects: require\n"
3732 "#extension GL_ARB_shading_language_420pack: require\n"
3733 "\n"
3734 "void main(){\n"
3735 " gl_Position = vec4(1);\n"
3736 "}\n";
3737 char const *fsSource =
3738 "#version 140\n"
3739 "#extension GL_ARB_separate_shader_objects: require\n"
3740 "#extension GL_ARB_shading_language_420pack: require\n"
3741 "\n"
3742 "layout(location=0) out vec4 color;\n"
3743 "void main(){\n"
3744 " color = vec4(1);\n"
3745 "}\n";
3746
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003747 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3748 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes8291c052015-05-25 11:13:28 +12003749
3750 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003751 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12003752 pipe.AddShader(&vs);
3753 pipe.AddShader(&fs);
3754
3755 pipe.AddVertexInputBindings(&input_binding, 1);
3756 pipe.AddVertexInputAttribs(&input_attrib, 1);
3757
Chris Forbes8291c052015-05-25 11:13:28 +12003758 VkDescriptorSetObj descriptorSet(m_device);
3759 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003760 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12003761
3762 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003763 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12003764
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003765 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12003766
Cody Northrop1684adb2015-08-05 11:15:02 -06003767 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12003768 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
3769 FAIL() << "Incorrect warning: " << msgString;
3770 }
3771}
3772
Chris Forbes37367e62015-05-25 11:13:29 +12003773TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
3774{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003775 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12003776 std::string msgString;
3777 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003778 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12003779
3780 char const *vsSource =
3781 "#version 140\n"
3782 "#extension GL_ARB_separate_shader_objects: require\n"
3783 "#extension GL_ARB_shading_language_420pack: require\n"
3784 "\n"
3785 "layout(location=0) in vec4 x;\n" /* not provided */
3786 "void main(){\n"
3787 " gl_Position = x;\n"
3788 "}\n";
3789 char const *fsSource =
3790 "#version 140\n"
3791 "#extension GL_ARB_separate_shader_objects: require\n"
3792 "#extension GL_ARB_shading_language_420pack: require\n"
3793 "\n"
3794 "layout(location=0) out vec4 color;\n"
3795 "void main(){\n"
3796 " color = vec4(1);\n"
3797 "}\n";
3798
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003799 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3800 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes37367e62015-05-25 11:13:29 +12003801
3802 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003803 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12003804 pipe.AddShader(&vs);
3805 pipe.AddShader(&fs);
3806
Chris Forbes37367e62015-05-25 11:13:29 +12003807 VkDescriptorSetObj descriptorSet(m_device);
3808 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003809 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12003810
3811 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003812 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12003813
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003814 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12003815
Cody Northrop1684adb2015-08-05 11:15:02 -06003816 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12003817 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
3818 FAIL() << "Incorrect warning: " << msgString;
3819 }
3820}
3821
Chris Forbesa4b02322015-05-25 11:13:31 +12003822TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
3823{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003824 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12003825 std::string msgString;
3826 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12003828
3829 VkVertexInputBindingDescription input_binding;
3830 memset(&input_binding, 0, sizeof(input_binding));
3831
3832 VkVertexInputAttributeDescription input_attrib;
3833 memset(&input_attrib, 0, sizeof(input_attrib));
3834 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3835
3836 char const *vsSource =
3837 "#version 140\n"
3838 "#extension GL_ARB_separate_shader_objects: require\n"
3839 "#extension GL_ARB_shading_language_420pack: require\n"
3840 "\n"
3841 "layout(location=0) in int x;\n" /* attrib provided float */
3842 "void main(){\n"
3843 " gl_Position = vec4(x);\n"
3844 "}\n";
3845 char const *fsSource =
3846 "#version 140\n"
3847 "#extension GL_ARB_separate_shader_objects: require\n"
3848 "#extension GL_ARB_shading_language_420pack: require\n"
3849 "\n"
3850 "layout(location=0) out vec4 color;\n"
3851 "void main(){\n"
3852 " color = vec4(1);\n"
3853 "}\n";
3854
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003855 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3856 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa4b02322015-05-25 11:13:31 +12003857
3858 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003859 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12003860 pipe.AddShader(&vs);
3861 pipe.AddShader(&fs);
3862
3863 pipe.AddVertexInputBindings(&input_binding, 1);
3864 pipe.AddVertexInputAttribs(&input_attrib, 1);
3865
Chris Forbesa4b02322015-05-25 11:13:31 +12003866 VkDescriptorSetObj descriptorSet(m_device);
3867 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003868 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12003869
3870 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003871 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12003872
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003873 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12003874
Cody Northrop1684adb2015-08-05 11:15:02 -06003875 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12003876 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
3877 FAIL() << "Incorrect error: " << msgString;
3878 }
3879}
3880
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003881TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
3882{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003883 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003884 std::string msgString;
3885 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003887
3888 /* Two binding descriptions for binding 0 */
3889 VkVertexInputBindingDescription input_bindings[2];
3890 memset(input_bindings, 0, sizeof(input_bindings));
3891
3892 VkVertexInputAttributeDescription input_attrib;
3893 memset(&input_attrib, 0, sizeof(input_attrib));
3894 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3895
3896 char const *vsSource =
3897 "#version 140\n"
3898 "#extension GL_ARB_separate_shader_objects: require\n"
3899 "#extension GL_ARB_shading_language_420pack: require\n"
3900 "\n"
3901 "layout(location=0) in float x;\n" /* attrib provided float */
3902 "void main(){\n"
3903 " gl_Position = vec4(x);\n"
3904 "}\n";
3905 char const *fsSource =
3906 "#version 140\n"
3907 "#extension GL_ARB_separate_shader_objects: require\n"
3908 "#extension GL_ARB_shading_language_420pack: require\n"
3909 "\n"
3910 "layout(location=0) out vec4 color;\n"
3911 "void main(){\n"
3912 " color = vec4(1);\n"
3913 "}\n";
3914
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003915 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3916 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003917
3918 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003919 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003920 pipe.AddShader(&vs);
3921 pipe.AddShader(&fs);
3922
3923 pipe.AddVertexInputBindings(input_bindings, 2);
3924 pipe.AddVertexInputAttribs(&input_attrib, 1);
3925
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003926 VkDescriptorSetObj descriptorSet(m_device);
3927 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003928 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003929
3930 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003931 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003932
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003933 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003934
Cody Northrop1684adb2015-08-05 11:15:02 -06003935 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003936 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
3937 FAIL() << "Incorrect error: " << msgString;
3938 }
3939}
Chris Forbes4c948702015-05-25 11:13:32 +12003940
Chris Forbesc12ef122015-05-25 11:13:40 +12003941/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
3942 * rejects it. */
3943
3944TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
3945{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003946 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12003947 std::string msgString;
3948 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12003949
3950 char const *vsSource =
3951 "#version 140\n"
3952 "#extension GL_ARB_separate_shader_objects: require\n"
3953 "#extension GL_ARB_shading_language_420pack: require\n"
3954 "\n"
3955 "void main(){\n"
3956 " gl_Position = vec4(1);\n"
3957 "}\n";
3958 char const *fsSource =
3959 "#version 140\n"
3960 "#extension GL_ARB_separate_shader_objects: require\n"
3961 "#extension GL_ARB_shading_language_420pack: require\n"
3962 "\n"
3963 "void main(){\n"
3964 "}\n";
3965
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003966 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3967 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc12ef122015-05-25 11:13:40 +12003968
3969 VkPipelineObj pipe(m_device);
3970 pipe.AddShader(&vs);
3971 pipe.AddShader(&fs);
3972
Chia-I Wuc278df82015-07-07 11:50:03 +08003973 /* set up CB 0, not written */
3974 pipe.AddColorAttachment();
3975 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12003976
Chris Forbesc12ef122015-05-25 11:13:40 +12003977 VkDescriptorSetObj descriptorSet(m_device);
3978 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003979 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12003980
3981 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003982 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12003983
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003984 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12003985
Cody Northrop1684adb2015-08-05 11:15:02 -06003986 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12003987 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
3988 FAIL() << "Incorrect error: " << msgString;
3989 }
3990}
3991
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003992TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
3993{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003994 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003995 std::string msgString;
3996 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003997
3998 char const *vsSource =
3999 "#version 140\n"
4000 "#extension GL_ARB_separate_shader_objects: require\n"
4001 "#extension GL_ARB_shading_language_420pack: require\n"
4002 "\n"
4003 "void main(){\n"
4004 " gl_Position = vec4(1);\n"
4005 "}\n";
4006 char const *fsSource =
4007 "#version 140\n"
4008 "#extension GL_ARB_separate_shader_objects: require\n"
4009 "#extension GL_ARB_shading_language_420pack: require\n"
4010 "\n"
4011 "layout(location=0) out vec4 x;\n"
4012 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4013 "void main(){\n"
4014 " x = vec4(1);\n"
4015 " y = vec4(1);\n"
4016 "}\n";
4017
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004018 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4019 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004020
4021 VkPipelineObj pipe(m_device);
4022 pipe.AddShader(&vs);
4023 pipe.AddShader(&fs);
4024
Chia-I Wuc278df82015-07-07 11:50:03 +08004025 /* set up CB 0, not written */
4026 pipe.AddColorAttachment();
4027 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004028 /* FS writes CB 1, but we don't configure it */
4029
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004030 VkDescriptorSetObj descriptorSet(m_device);
4031 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004032 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004033
4034 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004035 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004036
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004037 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004038
Cody Northrop1684adb2015-08-05 11:15:02 -06004039 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004040 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
4041 FAIL() << "Incorrect warning: " << msgString;
4042 }
4043}
4044
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004045TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4046{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004047 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004048 std::string msgString;
4049 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004050
4051 char const *vsSource =
4052 "#version 140\n"
4053 "#extension GL_ARB_separate_shader_objects: require\n"
4054 "#extension GL_ARB_shading_language_420pack: require\n"
4055 "\n"
4056 "void main(){\n"
4057 " gl_Position = vec4(1);\n"
4058 "}\n";
4059 char const *fsSource =
4060 "#version 140\n"
4061 "#extension GL_ARB_separate_shader_objects: require\n"
4062 "#extension GL_ARB_shading_language_420pack: require\n"
4063 "\n"
4064 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4065 "void main(){\n"
4066 " x = ivec4(1);\n"
4067 "}\n";
4068
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004069 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4070 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004071
4072 VkPipelineObj pipe(m_device);
4073 pipe.AddShader(&vs);
4074 pipe.AddShader(&fs);
4075
Chia-I Wuc278df82015-07-07 11:50:03 +08004076 /* set up CB 0; type is UNORM by default */
4077 pipe.AddColorAttachment();
4078 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004079
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004080 VkDescriptorSetObj descriptorSet(m_device);
4081 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004082 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004083
4084 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004085 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004086
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004087 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004088
Cody Northrop1684adb2015-08-05 11:15:02 -06004089 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004090 if (!strstr(msgString.c_str(),"does not match FS output type")) {
4091 FAIL() << "Incorrect error: " << msgString;
4092 }
4093}
Chris Forbesc2050732015-06-05 14:43:36 +12004094
Chris Forbes76ce7882015-08-14 12:04:59 +12004095TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4096{
4097 VkFlags msgFlags;
4098 std::string msgString;
4099 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12004100
4101 char const *vsSource =
4102 "#version 140\n"
4103 "#extension GL_ARB_separate_shader_objects: require\n"
4104 "#extension GL_ARB_shading_language_420pack: require\n"
4105 "\n"
4106 "void main(){\n"
4107 " gl_Position = vec4(1);\n"
4108 "}\n";
4109 char const *fsSource =
4110 "#version 140\n"
4111 "#extension GL_ARB_separate_shader_objects: require\n"
4112 "#extension GL_ARB_shading_language_420pack: require\n"
4113 "\n"
4114 "layout(location=0) out vec4 x;\n"
4115 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4116 "void main(){\n"
4117 " x = vec4(bar.y);\n"
4118 "}\n";
4119
4120 m_errorMonitor->ClearState();
4121
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004122 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4123 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes76ce7882015-08-14 12:04:59 +12004124
4125
4126 VkPipelineObj pipe(m_device);
4127 pipe.AddShader(&vs);
4128 pipe.AddShader(&fs);
4129
4130 /* set up CB 0; type is UNORM by default */
4131 pipe.AddColorAttachment();
4132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4133
4134 VkDescriptorSetObj descriptorSet(m_device);
4135 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
4136
4137 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4138
4139 /* should have generated an error -- pipeline layout does not
4140 * provide a uniform buffer in 0.0
4141 */
4142 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -06004143 ASSERT_TRUE((msgFlags & VK_DBG_REPORT_ERROR_BIT) == VK_DBG_REPORT_ERROR_BIT);
Chris Forbes76ce7882015-08-14 12:04:59 +12004144 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
4145 FAIL() << "Incorrect error: " << msgString;
4146 }
4147}
4148
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004149#endif // SHADER_CHECKER_TESTS
4150
4151#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004152TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4153{
4154 VkFlags msgFlags;
4155 std::string msgString;
4156
4157 ASSERT_NO_FATAL_FAILURE(InitState());
4158 m_errorMonitor->ClearState();
4159
4160 // Create an image
4161 VkImage image;
4162
4163 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4164 const int32_t tex_width = 32;
4165 const int32_t tex_height = 32;
4166
4167 VkImageCreateInfo image_create_info = {};
4168 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4169 image_create_info.pNext = NULL;
4170 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4171 image_create_info.format = tex_format;
4172 image_create_info.extent.width = tex_width;
4173 image_create_info.extent.height = tex_height;
4174 image_create_info.extent.depth = 1;
4175 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004176 image_create_info.arrayLayers = 1;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004177 image_create_info.samples = 1;
4178 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4179 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4180 image_create_info.flags = 0;
4181
4182 // Introduce error by sending down a bogus width extent
4183 image_create_info.extent.width = 65536;
4184 vkCreateImage(m_device->device(), &image_create_info, &image);
4185
4186 msgFlags = m_errorMonitor->GetState(&msgString);
4187 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4188 "with extents outside the queried limits";
4189 if (!strstr(msgString.c_str(),"CreateImage extents exceed allowable limits for format")) {
4190 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4191 }
4192}
4193
4194TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4195{
4196 VkFlags msgFlags;
4197 std::string msgString;
4198
4199 ASSERT_NO_FATAL_FAILURE(InitState());
4200 m_errorMonitor->ClearState();
4201
4202 // Create an image
4203 VkImage image;
4204
4205 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4206 const int32_t tex_width = 32;
4207 const int32_t tex_height = 32;
4208
4209 VkImageCreateInfo image_create_info = {};
4210 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4211 image_create_info.pNext = NULL;
4212 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4213 image_create_info.format = tex_format;
4214 image_create_info.extent.width = tex_width;
4215 image_create_info.extent.height = tex_height;
4216 image_create_info.extent.depth = 1;
4217 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004218 image_create_info.arrayLayers = 1;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004219 image_create_info.samples = 1;
4220 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4221 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4222 image_create_info.flags = 0;
4223
4224 // Introduce error by sending down individually allowable values that result in a surface size
4225 // exceeding the device maximum
4226 image_create_info.extent.width = 8192;
4227 image_create_info.extent.height = 8192;
4228 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004229 image_create_info.arrayLayers = 4;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004230 image_create_info.samples = 2;
4231 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
4232 vkCreateImage(m_device->device(), &image_create_info, &image);
4233
4234 msgFlags = m_errorMonitor->GetState(&msgString);
4235 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4236 "with resource size exceeding queried limit";
4237 if (!strstr(msgString.c_str(),"CreateImage resource size exceeds allowable maximum")) {
4238 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4239 }
4240}
4241
Mike Stroyan43909d82015-09-25 13:39:21 -06004242TEST_F(VkLayerTest, UpdateBufferAlignment)
4243{
4244 VkFlags msgFlags;
4245 std::string msgString;
4246 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4247
4248 ASSERT_NO_FATAL_FAILURE(InitState());
4249
4250 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4251 vk_testing::Buffer buffer;
4252 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4253
4254 BeginCommandBuffer();
4255 // Introduce failure by using offset that is not multiple of 4
4256 m_cmdBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
4257 msgFlags = m_errorMonitor->GetState(&msgString);
4258 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad offset";
4259 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4260 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4261 }
4262 // Introduce failure by using size that is not multiple of 4
4263 m_cmdBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
4264 msgFlags = m_errorMonitor->GetState(&msgString);
4265 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad size";
4266 if (!strstr(msgString.c_str(),"dataSize, is not a multiple of 4")) {
4267 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4268 }
4269 EndCommandBuffer();
4270}
4271
4272TEST_F(VkLayerTest, FillBufferAlignment)
4273{
4274 VkFlags msgFlags;
4275 std::string msgString;
4276
4277 ASSERT_NO_FATAL_FAILURE(InitState());
4278
4279 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4280 vk_testing::Buffer buffer;
4281 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4282
4283 BeginCommandBuffer();
4284 // Introduce failure by using offset that is not multiple of 4
4285 m_cmdBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
4286 msgFlags = m_errorMonitor->GetState(&msgString);
4287 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad offset";
4288 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4289 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4290 }
4291 // Introduce failure by using size that is not multiple of 4
4292 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
4293 msgFlags = m_errorMonitor->GetState(&msgString);
4294 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad size";
4295 if (!strstr(msgString.c_str(),"fillSize, is not a multiple of 4")) {
4296 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize fillSize, is not a multiple of 4'";
4297 }
4298 EndCommandBuffer();
4299}
4300
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004301#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004302
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004303#if IMAGE_TESTS
4304TEST_F(VkLayerTest, InvalidImageView)
4305{
4306 VkFlags msgFlags;
4307 std::string msgString;
4308 VkResult err;
4309
4310 ASSERT_NO_FATAL_FAILURE(InitState());
4311 m_errorMonitor->ClearState();
4312
Mike Stroyan43909d82015-09-25 13:39:21 -06004313 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004314 VkImage image;
4315
4316 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4317 const int32_t tex_width = 32;
4318 const int32_t tex_height = 32;
4319
4320 VkImageCreateInfo image_create_info = {};
4321 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4322 image_create_info.pNext = NULL;
4323 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4324 image_create_info.format = tex_format;
4325 image_create_info.extent.width = tex_width;
4326 image_create_info.extent.height = tex_height;
4327 image_create_info.extent.depth = 1;
4328 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004329 image_create_info.arrayLayers = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004330 image_create_info.samples = 1;
4331 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4332 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4333 image_create_info.flags = 0;
4334
4335 err = vkCreateImage(m_device->device(), &image_create_info, &image);
4336 ASSERT_VK_SUCCESS(err);
4337
4338 VkImageViewCreateInfo image_view_create_info = {};
4339 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4340 image_view_create_info.image = image;
4341 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4342 image_view_create_info.format = tex_format;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004343 image_view_create_info.subresourceRange.numLayers = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004344 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004345 image_view_create_info.subresourceRange.numLevels = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004346
4347 VkImageView view;
4348 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
4349
4350 msgFlags = m_errorMonitor->GetState(&msgString);
4351 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an invalid ImageView";
4352 if (!strstr(msgString.c_str(),"vkCreateImageView called with baseMipLevel 10 ")) {
Mike Stroyan43909d82015-09-25 13:39:21 -06004353 FAIL() << "Error received was not 'vkCreateImageView called with baseMipLevel 10...' but instead '" << msgString.c_str() << "'";
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004354 }
4355}
Mike Stroyan43909d82015-09-25 13:39:21 -06004356
4357TEST_F(VkLayerTest, CopyImageTypeMismatch)
4358{
4359 VkFlags msgFlags;
4360 std::string msgString;
4361 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004362 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004363
4364 ASSERT_NO_FATAL_FAILURE(InitState());
4365 m_errorMonitor->ClearState();
4366
4367 // Create two images of different types and try to copy between them
4368 VkImage srcImage;
4369 VkImage destImage;
4370 VkDeviceMemory srcMem;
4371 VkDeviceMemory destMem;
4372 VkMemoryRequirements memReqs;
4373
4374 VkImageCreateInfo image_create_info = {};
4375 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4376 image_create_info.pNext = NULL;
4377 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4378 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4379 image_create_info.extent.width = 32;
4380 image_create_info.extent.height = 32;
4381 image_create_info.extent.depth = 1;
4382 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004383 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06004384 image_create_info.samples = 1;
4385 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4386 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4387 image_create_info.flags = 0;
4388
4389 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4390 ASSERT_VK_SUCCESS(err);
4391
4392 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4393 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4394
4395 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4396 ASSERT_VK_SUCCESS(err);
4397
4398 // Allocate memory
4399 VkMemoryAllocInfo memAlloc = {};
4400 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4401 memAlloc.pNext = NULL;
4402 memAlloc.allocationSize = 0;
4403 memAlloc.memoryTypeIndex = 0;
4404
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004405 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004406 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004407 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4408 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004409 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4410 ASSERT_VK_SUCCESS(err);
4411
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004412 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004413 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004414 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06004415 ASSERT_VK_SUCCESS(err);
4416 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4417 ASSERT_VK_SUCCESS(err);
4418
4419 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4420 ASSERT_VK_SUCCESS(err);
4421 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4422 ASSERT_VK_SUCCESS(err);
4423
4424 BeginCommandBuffer();
4425 VkImageCopy copyRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004426 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004427 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004428 copyRegion.srcSubresource.baseArrayLayer = 0;
4429 copyRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004430 copyRegion.srcOffset.x = 0;
4431 copyRegion.srcOffset.y = 0;
4432 copyRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004433 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004434 copyRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004435 copyRegion.destSubresource.baseArrayLayer = 0;
4436 copyRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004437 copyRegion.destOffset.x = 0;
4438 copyRegion.destOffset.y = 0;
4439 copyRegion.destOffset.z = 0;
4440 copyRegion.extent.width = 1;
4441 copyRegion.extent.height = 1;
4442 copyRegion.extent.depth = 1;
4443 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4444 EndCommandBuffer();
4445
4446 msgFlags = m_errorMonitor->GetState(&msgString);
4447 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4448 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4449 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4450 }
4451
4452 vkDestroyImage(m_device->device(), srcImage);
4453 vkDestroyImage(m_device->device(), destImage);
4454 vkFreeMemory(m_device->device(), srcMem);
4455 vkFreeMemory(m_device->device(), destMem);
4456}
4457
4458TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
4459{
4460 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
4461}
4462
4463TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
4464{
4465 VkFlags msgFlags;
4466 std::string msgString;
4467 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004468 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004469
4470 ASSERT_NO_FATAL_FAILURE(InitState());
4471 m_errorMonitor->ClearState();
4472
4473 // Create two images of different types and try to copy between them
4474 VkImage srcImage;
4475 VkImage destImage;
4476 VkDeviceMemory srcMem;
4477 VkDeviceMemory destMem;
4478 VkMemoryRequirements memReqs;
4479
4480 VkImageCreateInfo image_create_info = {};
4481 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4482 image_create_info.pNext = NULL;
4483 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4484 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4485 image_create_info.extent.width = 32;
4486 image_create_info.extent.height = 32;
4487 image_create_info.extent.depth = 1;
4488 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004489 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06004490 image_create_info.samples = 1;
4491 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4492 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4493 image_create_info.flags = 0;
4494
4495 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4496 ASSERT_VK_SUCCESS(err);
4497
4498 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4499 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4500
4501 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4502 ASSERT_VK_SUCCESS(err);
4503
4504 // Allocate memory
4505 VkMemoryAllocInfo memAlloc = {};
4506 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4507 memAlloc.pNext = NULL;
4508 memAlloc.allocationSize = 0;
4509 memAlloc.memoryTypeIndex = 0;
4510
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004511 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004512 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004513 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4514 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004515 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4516 ASSERT_VK_SUCCESS(err);
4517
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004518 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004519 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004520 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4521 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004522 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4523 ASSERT_VK_SUCCESS(err);
4524
4525 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4526 ASSERT_VK_SUCCESS(err);
4527 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4528 ASSERT_VK_SUCCESS(err);
4529
4530 BeginCommandBuffer();
4531 VkImageCopy copyRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004532 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004533 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004534 copyRegion.srcSubresource.baseArrayLayer = 0;
4535 copyRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004536 copyRegion.srcOffset.x = 0;
4537 copyRegion.srcOffset.y = 0;
4538 copyRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004539 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004540 copyRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004541 copyRegion.destSubresource.baseArrayLayer = 0;
4542 copyRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004543 copyRegion.destOffset.x = 0;
4544 copyRegion.destOffset.y = 0;
4545 copyRegion.destOffset.z = 0;
4546 copyRegion.extent.width = 1;
4547 copyRegion.extent.height = 1;
4548 copyRegion.extent.depth = 1;
4549 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4550 EndCommandBuffer();
4551
4552 msgFlags = m_errorMonitor->GetState(&msgString);
4553 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4554 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4555 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4556 }
4557
4558 vkDestroyImage(m_device->device(), srcImage);
4559 vkDestroyImage(m_device->device(), destImage);
4560 vkFreeMemory(m_device->device(), srcMem);
4561 vkFreeMemory(m_device->device(), destMem);
4562}
4563
4564TEST_F(VkLayerTest, ResolveImageLowSampleCount)
4565{
4566 VkFlags msgFlags;
4567 std::string msgString;
4568 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004569 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004570
4571 ASSERT_NO_FATAL_FAILURE(InitState());
4572 m_errorMonitor->ClearState();
4573
4574 // Create two images of sample count 1 and try to Resolve between them
4575 VkImage srcImage;
4576 VkImage destImage;
4577 VkDeviceMemory srcMem;
4578 VkDeviceMemory destMem;
4579 VkMemoryRequirements memReqs;
4580
4581 VkImageCreateInfo image_create_info = {};
4582 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4583 image_create_info.pNext = NULL;
4584 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4585 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4586 image_create_info.extent.width = 32;
4587 image_create_info.extent.height = 1;
4588 image_create_info.extent.depth = 1;
4589 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004590 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06004591 image_create_info.samples = 1;
4592 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4593 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4594 image_create_info.flags = 0;
4595
4596 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4597 ASSERT_VK_SUCCESS(err);
4598
4599 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4600 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4601
4602 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4603 ASSERT_VK_SUCCESS(err);
4604
4605 // Allocate memory
4606 VkMemoryAllocInfo memAlloc = {};
4607 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4608 memAlloc.pNext = NULL;
4609 memAlloc.allocationSize = 0;
4610 memAlloc.memoryTypeIndex = 0;
4611
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004612 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004613 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004614 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4615 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004616 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4617 ASSERT_VK_SUCCESS(err);
4618
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004619 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004620 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004621 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4622 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004623 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4624 ASSERT_VK_SUCCESS(err);
4625
4626 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4627 ASSERT_VK_SUCCESS(err);
4628 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4629 ASSERT_VK_SUCCESS(err);
4630
4631 BeginCommandBuffer();
4632 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4633 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4634 //VK_IMAGE_LAYOUT_GENERAL = 1,
4635 VkImageResolve resolveRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004636 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004637 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004638 resolveRegion.srcSubresource.baseArrayLayer = 0;
4639 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004640 resolveRegion.srcOffset.x = 0;
4641 resolveRegion.srcOffset.y = 0;
4642 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004643 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004644 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004645 resolveRegion.destSubresource.baseArrayLayer = 0;
4646 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004647 resolveRegion.destOffset.x = 0;
4648 resolveRegion.destOffset.y = 0;
4649 resolveRegion.destOffset.z = 0;
4650 resolveRegion.extent.width = 1;
4651 resolveRegion.extent.height = 1;
4652 resolveRegion.extent.depth = 1;
4653 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4654 EndCommandBuffer();
4655
4656 msgFlags = m_errorMonitor->GetState(&msgString);
4657 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4658 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with source sample count less than 2.")) {
4659 FAIL() << "Error received was not 'vkCmdResolveImage called with source sample count less than 2.' but instead '" << msgString.c_str() << "'";
4660 }
4661
4662 vkDestroyImage(m_device->device(), srcImage);
4663 vkDestroyImage(m_device->device(), destImage);
4664 vkFreeMemory(m_device->device(), srcMem);
4665 vkFreeMemory(m_device->device(), destMem);
4666}
4667
4668TEST_F(VkLayerTest, ResolveImageHighSampleCount)
4669{
4670 VkFlags msgFlags;
4671 std::string msgString;
4672 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004673 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004674
4675 ASSERT_NO_FATAL_FAILURE(InitState());
4676 m_errorMonitor->ClearState();
4677
4678 // Create two images of sample count 2 and try to Resolve between them
4679 VkImage srcImage;
4680 VkImage destImage;
4681 VkDeviceMemory srcMem;
4682 VkDeviceMemory destMem;
4683 VkMemoryRequirements memReqs;
4684
4685 VkImageCreateInfo image_create_info = {};
4686 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4687 image_create_info.pNext = NULL;
4688 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4689 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4690 image_create_info.extent.width = 32;
4691 image_create_info.extent.height = 1;
4692 image_create_info.extent.depth = 1;
4693 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004694 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06004695 image_create_info.samples = 2;
4696 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4697 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4698 image_create_info.flags = 0;
4699
4700 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4701 ASSERT_VK_SUCCESS(err);
4702
4703 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4704 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4705
4706 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4707 ASSERT_VK_SUCCESS(err);
4708
4709 // Allocate memory
4710 VkMemoryAllocInfo memAlloc = {};
4711 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4712 memAlloc.pNext = NULL;
4713 memAlloc.allocationSize = 0;
4714 memAlloc.memoryTypeIndex = 0;
4715
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004716 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004717 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004718 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4719 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004720 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4721 ASSERT_VK_SUCCESS(err);
4722
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004723 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004724 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004725 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4726 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004727 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4728 ASSERT_VK_SUCCESS(err);
4729
4730 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4731 ASSERT_VK_SUCCESS(err);
4732 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4733 ASSERT_VK_SUCCESS(err);
4734
4735 BeginCommandBuffer();
4736 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4737 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4738 //VK_IMAGE_LAYOUT_GENERAL = 1,
4739 VkImageResolve resolveRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004740 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004741 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004742 resolveRegion.srcSubresource.baseArrayLayer = 0;
4743 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004744 resolveRegion.srcOffset.x = 0;
4745 resolveRegion.srcOffset.y = 0;
4746 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004747 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004748 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004749 resolveRegion.destSubresource.baseArrayLayer = 0;
4750 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004751 resolveRegion.destOffset.x = 0;
4752 resolveRegion.destOffset.y = 0;
4753 resolveRegion.destOffset.z = 0;
4754 resolveRegion.extent.width = 1;
4755 resolveRegion.extent.height = 1;
4756 resolveRegion.extent.depth = 1;
4757 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4758 EndCommandBuffer();
4759
4760 msgFlags = m_errorMonitor->GetState(&msgString);
4761 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4762 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with dest sample count greater than 1.")) {
4763 FAIL() << "Error received was not 'vkCmdResolveImage called with dest sample count greater than 1.' but instead '" << msgString.c_str() << "'";
4764 }
4765
4766 vkDestroyImage(m_device->device(), srcImage);
4767 vkDestroyImage(m_device->device(), destImage);
4768 vkFreeMemory(m_device->device(), srcMem);
4769 vkFreeMemory(m_device->device(), destMem);
4770}
4771
4772TEST_F(VkLayerTest, ResolveImageFormatMismatch)
4773{
4774 VkFlags msgFlags;
4775 std::string msgString;
4776 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004777 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004778
4779 ASSERT_NO_FATAL_FAILURE(InitState());
4780 m_errorMonitor->ClearState();
4781
4782 // Create two images of different types and try to copy between them
4783 VkImage srcImage;
4784 VkImage destImage;
4785 VkDeviceMemory srcMem;
4786 VkDeviceMemory destMem;
4787 VkMemoryRequirements memReqs;
4788
4789 VkImageCreateInfo image_create_info = {};
4790 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4791 image_create_info.pNext = NULL;
4792 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4793 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4794 image_create_info.extent.width = 32;
4795 image_create_info.extent.height = 1;
4796 image_create_info.extent.depth = 1;
4797 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004798 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06004799 image_create_info.samples = 2;
4800 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4801 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4802 image_create_info.flags = 0;
4803
4804 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4805 ASSERT_VK_SUCCESS(err);
4806
4807 image_create_info.format = VK_FORMAT_B8G8R8_SRGB;
4808 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4809 image_create_info.samples = 1;
4810
4811 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4812 ASSERT_VK_SUCCESS(err);
4813
4814 // Allocate memory
4815 VkMemoryAllocInfo memAlloc = {};
4816 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4817 memAlloc.pNext = NULL;
4818 memAlloc.allocationSize = 0;
4819 memAlloc.memoryTypeIndex = 0;
4820
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004821 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004822 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004823 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4824 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004825 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4826 ASSERT_VK_SUCCESS(err);
4827
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004828 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004829 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004830 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4831 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004832 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4833 ASSERT_VK_SUCCESS(err);
4834
4835 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4836 ASSERT_VK_SUCCESS(err);
4837 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4838 ASSERT_VK_SUCCESS(err);
4839
4840 BeginCommandBuffer();
4841 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4842 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4843 //VK_IMAGE_LAYOUT_GENERAL = 1,
4844 VkImageResolve resolveRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004845 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004846 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004847 resolveRegion.srcSubresource.baseArrayLayer = 0;
4848 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004849 resolveRegion.srcOffset.x = 0;
4850 resolveRegion.srcOffset.y = 0;
4851 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004852 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004853 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004854 resolveRegion.destSubresource.baseArrayLayer = 0;
4855 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004856 resolveRegion.destOffset.x = 0;
4857 resolveRegion.destOffset.y = 0;
4858 resolveRegion.destOffset.z = 0;
4859 resolveRegion.extent.width = 1;
4860 resolveRegion.extent.height = 1;
4861 resolveRegion.extent.depth = 1;
4862 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4863 EndCommandBuffer();
4864
4865 msgFlags = m_errorMonitor->GetState(&msgString);
4866 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage format mismatch";
4867 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest formats.")) {
4868 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest formats.' but instead '" << msgString.c_str() << "'";
4869 }
4870
4871 vkDestroyImage(m_device->device(), srcImage);
4872 vkDestroyImage(m_device->device(), destImage);
4873 vkFreeMemory(m_device->device(), srcMem);
4874 vkFreeMemory(m_device->device(), destMem);
4875}
4876
4877TEST_F(VkLayerTest, ResolveImageTypeMismatch)
4878{
4879 VkFlags msgFlags;
4880 std::string msgString;
4881 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004882 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004883
4884 ASSERT_NO_FATAL_FAILURE(InitState());
4885 m_errorMonitor->ClearState();
4886
4887 // Create two images of different types and try to copy between them
4888 VkImage srcImage;
4889 VkImage destImage;
4890 VkDeviceMemory srcMem;
4891 VkDeviceMemory destMem;
4892 VkMemoryRequirements memReqs;
4893
4894 VkImageCreateInfo image_create_info = {};
4895 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4896 image_create_info.pNext = NULL;
4897 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4898 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4899 image_create_info.extent.width = 32;
4900 image_create_info.extent.height = 1;
4901 image_create_info.extent.depth = 1;
4902 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004903 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06004904 image_create_info.samples = 2;
4905 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4906 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4907 image_create_info.flags = 0;
4908
4909 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4910 ASSERT_VK_SUCCESS(err);
4911
4912 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4913 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4914 image_create_info.samples = 1;
4915
4916 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4917 ASSERT_VK_SUCCESS(err);
4918
4919 // Allocate memory
4920 VkMemoryAllocInfo memAlloc = {};
4921 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4922 memAlloc.pNext = NULL;
4923 memAlloc.allocationSize = 0;
4924 memAlloc.memoryTypeIndex = 0;
4925
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004926 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004927 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004928 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4929 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004930 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4931 ASSERT_VK_SUCCESS(err);
4932
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004933 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004934 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004935 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4936 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004937 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4938 ASSERT_VK_SUCCESS(err);
4939
4940 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4941 ASSERT_VK_SUCCESS(err);
4942 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4943 ASSERT_VK_SUCCESS(err);
4944
4945 BeginCommandBuffer();
4946 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4947 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4948 //VK_IMAGE_LAYOUT_GENERAL = 1,
4949 VkImageResolve resolveRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004950 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004951 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004952 resolveRegion.srcSubresource.baseArrayLayer = 0;
4953 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004954 resolveRegion.srcOffset.x = 0;
4955 resolveRegion.srcOffset.y = 0;
4956 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004957 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004958 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004959 resolveRegion.destSubresource.baseArrayLayer = 0;
4960 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004961 resolveRegion.destOffset.x = 0;
4962 resolveRegion.destOffset.y = 0;
4963 resolveRegion.destOffset.z = 0;
4964 resolveRegion.extent.width = 1;
4965 resolveRegion.extent.height = 1;
4966 resolveRegion.extent.depth = 1;
4967 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4968 EndCommandBuffer();
4969
4970 msgFlags = m_errorMonitor->GetState(&msgString);
4971 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4972 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest image types.")) {
4973 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest image types.' but instead '" << msgString.c_str() << "'";
4974 }
4975
4976 vkDestroyImage(m_device->device(), srcImage);
4977 vkDestroyImage(m_device->device(), destImage);
4978 vkFreeMemory(m_device->device(), srcMem);
4979 vkFreeMemory(m_device->device(), destMem);
4980}
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004981#endif // IMAGE_TESTS
4982
Tony Barbour30486ea2015-04-07 13:44:53 -06004983int main(int argc, char **argv) {
4984 int result;
4985
4986 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004987 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06004988
4989 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
4990
4991 result = RUN_ALL_TESTS();
4992
Tony Barbour01999182015-04-09 12:58:51 -06004993 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06004994 return result;
4995}