blob: d24e0debb2a32e0bf1238ad5864c0ff7c67f84a1 [file] [log] [blame]
Tobin Ehlisacab8882014-11-14 13:01:02 -07001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlisacab8882014-11-14 13:01:02 -07003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060025#include "vkLayer.h"
Tobin Ehlis3c26a542014-11-18 11:28:33 -070026// Object Tracker ERROR codes
27typedef enum _OBJECT_TRACK_ERROR
28{
Chia-I Wub1466182015-01-05 14:33:42 +080029 OBJTRACK_NONE, // Used for INFO & other non-error messages
30 OBJTRACK_UNKNOWN_OBJECT, // Updating uses of object that's not in global object list
31 OBJTRACK_INTERNAL_ERROR, // Bug with data tracking within the layer
32 OBJTRACK_DESTROY_OBJECT_FAILED, // Couldn't find object to be destroyed
33 OBJTRACK_MISSING_OBJECT, // Attempted look-up on object that isn't in global object list
34 OBJTRACK_OBJECT_LEAK, // OBJECT was not correctly freed/destroyed
35 OBJTRACK_OBJCOUNT_MAX_EXCEEDED, // Request for Object data in excess of max obj count
Tobin Ehlis235c20e2015-01-16 08:56:30 -070036 OBJTRACK_INVALID_FENCE, // Requested status of unsubmitted fence object
Mark Lobodzinski01552702015-02-03 10:06:31 -060037 OBJTRACK_VIEWPORT_NOT_BOUND, // Draw submitted with no viewport state object bound
38 OBJTRACK_RASTER_NOT_BOUND, // Draw submitted with no raster state object bound
39 OBJTRACK_COLOR_BLEND_NOT_BOUND, // Draw submitted with no color blend state object bound
40 OBJTRACK_DEPTH_STENCIL_NOT_BOUND, // Draw submitted with no depth-stencil state object bound
Mark Lobodzinski4186e712015-02-03 11:52:26 -060041 OBJTRACK_GPU_MEM_MAPPED, // Mem object ref'd in cmd buff is still mapped
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -060042 OBJTRACK_GETGPUINFO_NOT_CALLED, // Gpu Information has not been requested before drawing
43 OBJTRACK_MEMREFCOUNT_MAX_EXCEEDED, // Number of QueueSubmit memory references exceeds GPU maximum
Tobin Ehlis3c26a542014-11-18 11:28:33 -070044} OBJECT_TRACK_ERROR;
45
Tobin Ehlis235c20e2015-01-16 08:56:30 -070046// Object Status -- used to track state of individual objects
47typedef enum _OBJECT_STATUS
48{
Mark Lobodzinski01552702015-02-03 10:06:31 -060049 OBJSTATUS_NONE = 0x00000000, // No status is set
50 OBJSTATUS_FENCE_IS_SUBMITTED = 0x00000001, // Fence has been submitted
51 OBJSTATUS_VIEWPORT_BOUND = 0x00000002, // Viewport state object has been bound
52 OBJSTATUS_RASTER_BOUND = 0x00000004, // Viewport state object has been bound
53 OBJSTATUS_COLOR_BLEND_BOUND = 0x00000008, // Viewport state object has been bound
54 OBJSTATUS_DEPTH_STENCIL_BOUND = 0x00000010, // Viewport state object has been bound
Mark Lobodzinski4186e712015-02-03 11:52:26 -060055 OBJSTATUS_GPU_MEM_MAPPED = 0x00000020, // Memory object is currently mapped
Tobin Ehlis235c20e2015-01-16 08:56:30 -070056} OBJECT_STATUS;
57// TODO : Make this code-generated
Tobin Ehlisacab8882014-11-14 13:01:02 -070058// Object type enum
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060059typedef enum _VK_OBJECT_TYPE
Tobin Ehlisacab8882014-11-14 13:01:02 -070060{
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -060061 VkObjectTypeSampler,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -060062 VkObjectTypeDynamicDsState,
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -060063 VkObjectTypeDescriptorSet,
64 VkObjectTypeDescriptorPool,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -060065 VkObjectTypeDynamicCbState,
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -060066 VkObjectTypeImageView,
67 VkObjectTypeSemaphore,
68 VkObjectTypeShader,
69 VkObjectTypeDescriptorSetLayout,
70 VkObjectTypeDescriptorSetLayoutChain,
71 VkObjectTypeBuffer,
72 VkObjectTypePipeline,
73 VkObjectTypeDevice,
74 VkObjectTypeQueryPool,
75 VkObjectTypeEvent,
76 VkObjectTypeQueue,
77 VkObjectTypePhysicalGpu,
78 VkObjectTypeRenderPass,
79 VkObjectTypeFramebuffer,
80 VkObjectTypeImage,
81 VkObjectTypeBufferView,
82 VkObjectTypeDepthStencilView,
83 VkObjectTypeInstance,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -060084 VkObjectTypeDynamicVpState,
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -060085 VkObjectTypeColorAttachmentView,
86 VkObjectTypeGpuMemory,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -060087 VkObjectTypeDynamicRsState,
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -060088 VkObjectTypeFence,
89 VkObjectTypeCmdBuffer,
90 VkObjectTypePresentableImageMemory,
Chia-I Wub1466182015-01-05 14:33:42 +080091
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -060092 VkObjectTypeUnknown,
93 VkNumObjectType,
94 VkObjectTypeAny, // Allow global object list to be queried/retrieved
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060095} VK_OBJECT_TYPE;
Tobin Ehlisacab8882014-11-14 13:01:02 -070096
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060097static const char* string_VK_OBJECT_TYPE(VK_OBJECT_TYPE type) {
Tobin Ehlisacab8882014-11-14 13:01:02 -070098 switch (type)
99 {
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600100 case VkObjectTypeDevice:
Tobin Ehlisacab8882014-11-14 13:01:02 -0700101 return "DEVICE";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600102 case VkObjectTypePipeline:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700103 return "PIPELINE";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600104 case VkObjectTypeFence:
Tobin Ehlisacab8882014-11-14 13:01:02 -0700105 return "FENCE";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600106 case VkObjectTypeDescriptorSetLayout:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700107 return "DESCRIPTOR_SET_LAYOUT";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600108 case VkObjectTypeDescriptorSetLayoutChain:
Courtney Goeltzenleuchter24591b62015-04-02 22:54:15 -0600109 return "DESCRIPTOR_SET_LAYOUT_CHAIN";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600110 case VkObjectTypeGpuMemory:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700111 return "GPU_MEMORY";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600112 case VkObjectTypeQueue:
Tobin Ehlisacab8882014-11-14 13:01:02 -0700113 return "QUEUE";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600114 case VkObjectTypeImage:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700115 return "IMAGE";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600116 case VkObjectTypeCmdBuffer:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700117 return "CMD_BUFFER";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600118 case VkObjectTypeSemaphore:
Courtney Goeltzenleuchter0d2efef2015-03-25 17:14:29 -0600119 return "SEMAPHORE";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600120 case VkObjectTypeFramebuffer:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700121 return "FRAMEBUFFER";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600122 case VkObjectTypeSampler:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700123 return "SAMPLER";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600124 case VkObjectTypeColorAttachmentView:
Tobin Ehlisacab8882014-11-14 13:01:02 -0700125 return "COLOR_ATTACHMENT_VIEW";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600126 case VkObjectTypeBufferView:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700127 return "BUFFER_VIEW";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600128 case VkObjectTypeDescriptorSet:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700129 return "DESCRIPTOR_SET";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600130 case VkObjectTypePhysicalGpu:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700131 return "PHYSICAL_GPU";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600132 case VkObjectTypeImageView:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700133 return "IMAGE_VIEW";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600134 case VkObjectTypeBuffer:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700135 return "BUFFER";
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -0600136 case VkObjectTypeDynamicRsState:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700137 return "DYNAMIC_RS_STATE_OBJECT";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600138 case VkObjectTypeEvent:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700139 return "EVENT";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600140 case VkObjectTypeDepthStencilView:
Tobin Ehlisacab8882014-11-14 13:01:02 -0700141 return "DEPTH_STENCIL_VIEW";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600142 case VkObjectTypeShader:
Tobin Ehlisacab8882014-11-14 13:01:02 -0700143 return "SHADER";
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -0600144 case VkObjectTypeDynamicDsState:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700145 return "DYNAMIC_DS_STATE_OBJECT";
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -0600146 case VkObjectTypeDynamicVpState:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700147 return "DYNAMIC_VP_STATE_OBJECT";
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -0600148 case VkObjectTypeDynamicCbState:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700149 return "DYNAMIC_CB_STATE_OBJECT";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600150 case VkObjectTypeInstance:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700151 return "INSTANCE";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600152 case VkObjectTypeRenderPass:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700153 return "RENDER_PASS";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600154 case VkObjectTypeQueryPool:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700155 return "QUERY_POOL";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600156 case VkObjectTypeDescriptorPool:
Courtney Goeltzenleuchter24591b62015-04-02 22:54:15 -0600157 return "DESCRIPTOR_POOL";
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -0600158 case VkObjectTypePresentableImageMemory:
Courtney Goeltzenleuchterf6adc302015-03-26 16:16:16 -0600159 return "PRESENTABLE_IMAGE_MEMORY";
Tobin Ehlisacab8882014-11-14 13:01:02 -0700160 default:
161 return "UNKNOWN";
162 }
163}
164
165typedef struct _OBJTRACK_NODE {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600166 void *pObj;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600167 VK_OBJECT_TYPE objType;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600168 uint64_t numUses;
Tobin Ehlis235c20e2015-01-16 08:56:30 -0700169 OBJECT_STATUS status;
Tobin Ehlisacab8882014-11-14 13:01:02 -0700170} OBJTRACK_NODE;
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -0600171
Tobin Ehlisacab8882014-11-14 13:01:02 -0700172// prototype for extension functions
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600173uint64_t objTrackGetObjectCount(VK_OBJECT_TYPE type);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600174VkResult objTrackGetObjects(VK_OBJECT_TYPE type, uint64_t objCount, OBJTRACK_NODE* pObjNodeArray);
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -0600175
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700176// Func ptr typedefs
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600177typedef uint64_t (*OBJ_TRACK_GET_OBJECT_COUNT)(VK_OBJECT_TYPE);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600178typedef VkResult (*OBJ_TRACK_GET_OBJECTS)(VK_OBJECT_TYPE, uint64_t, OBJTRACK_NODE*);