1 /*
2 * Copyright © 2022 Friedrich Vock
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "rmv/vk_rmv_common.h"
25 #include "rmv/vk_rmv_tokens.h"
26 #include "radv_private.h"
27 #include "vk_common_entrypoints.h"
28 #include "wsi_common_entrypoints.h"
29
30 VKAPI_ATTR VkResult VKAPI_CALL
rmv_QueuePresentKHR(VkQueue _queue,const VkPresentInfoKHR * pPresentInfo)31 rmv_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo)
32 {
33 RADV_FROM_HANDLE(radv_queue, queue, _queue);
34 struct radv_device *device = queue->device;
35
36 VkResult res = queue->device->layer_dispatch.rmv.QueuePresentKHR(_queue, pPresentInfo);
37 if ((res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR) || !device->vk.memory_trace_data.is_enabled)
38 return res;
39
40 vk_rmv_log_misc_token(&device->vk, VK_RMV_MISC_EVENT_TYPE_PRESENT);
41
42 return VK_SUCCESS;
43 }
44
45 VKAPI_ATTR VkResult VKAPI_CALL
rmv_FlushMappedMemoryRanges(VkDevice _device,uint32_t memoryRangeCount,const VkMappedMemoryRange * pMemoryRanges)46 rmv_FlushMappedMemoryRanges(VkDevice _device, uint32_t memoryRangeCount, const VkMappedMemoryRange *pMemoryRanges)
47 {
48 RADV_FROM_HANDLE(radv_device, device, _device);
49
50 VkResult res = device->layer_dispatch.rmv.FlushMappedMemoryRanges(_device, memoryRangeCount, pMemoryRanges);
51 if (res != VK_SUCCESS || !device->vk.memory_trace_data.is_enabled)
52 return res;
53
54 vk_rmv_log_misc_token(&device->vk, VK_RMV_MISC_EVENT_TYPE_FLUSH_MAPPED_RANGE);
55
56 return VK_SUCCESS;
57 }
58
59 VKAPI_ATTR VkResult VKAPI_CALL
rmv_InvalidateMappedMemoryRanges(VkDevice _device,uint32_t memoryRangeCount,const VkMappedMemoryRange * pMemoryRanges)60 rmv_InvalidateMappedMemoryRanges(VkDevice _device, uint32_t memoryRangeCount, const VkMappedMemoryRange *pMemoryRanges)
61 {
62 RADV_FROM_HANDLE(radv_device, device, _device);
63
64 VkResult res = device->layer_dispatch.rmv.InvalidateMappedMemoryRanges(_device, memoryRangeCount, pMemoryRanges);
65 if (res != VK_SUCCESS || !device->vk.memory_trace_data.is_enabled)
66 return res;
67
68 vk_rmv_log_misc_token(&device->vk, VK_RMV_MISC_EVENT_TYPE_INVALIDATE_RANGES);
69
70 return VK_SUCCESS;
71 }
72
73 VKAPI_ATTR VkResult VKAPI_CALL
rmv_DebugMarkerSetObjectNameEXT(VkDevice device,const VkDebugMarkerObjectNameInfoEXT * pNameInfo)74 rmv_DebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo)
75 {
76 assert(pNameInfo->sType == VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT);
77 VkDebugUtilsObjectNameInfoEXT name_info;
78 name_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
79 name_info.objectType = pNameInfo->objectType;
80 name_info.objectHandle = pNameInfo->object;
81 name_info.pObjectName = pNameInfo->pObjectName;
82 return rmv_SetDebugUtilsObjectNameEXT(device, &name_info);
83 }
84
85 VKAPI_ATTR VkResult VKAPI_CALL
rmv_SetDebugUtilsObjectNameEXT(VkDevice _device,const VkDebugUtilsObjectNameInfoEXT * pNameInfo)86 rmv_SetDebugUtilsObjectNameEXT(VkDevice _device, const VkDebugUtilsObjectNameInfoEXT *pNameInfo)
87 {
88 assert(pNameInfo->sType == VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT);
89 RADV_FROM_HANDLE(radv_device, device, _device);
90
91 VkResult result = device->layer_dispatch.rmv.SetDebugUtilsObjectNameEXT(_device, pNameInfo);
92 if (result != VK_SUCCESS || !device->vk.memory_trace_data.is_enabled)
93 return result;
94
95 switch (pNameInfo->objectType) {
96 /* only name object types we care about */
97 case VK_OBJECT_TYPE_BUFFER:
98 case VK_OBJECT_TYPE_DEVICE_MEMORY:
99 case VK_OBJECT_TYPE_IMAGE:
100 case VK_OBJECT_TYPE_EVENT:
101 case VK_OBJECT_TYPE_QUERY_POOL:
102 case VK_OBJECT_TYPE_DESCRIPTOR_POOL:
103 case VK_OBJECT_TYPE_PIPELINE:
104 break;
105 default:
106 return VK_SUCCESS;
107 }
108
109 size_t name_len = strlen(pNameInfo->pObjectName);
110 char *name_buf = malloc(name_len + 1);
111 if (!name_buf) {
112 /*
113 * Silently fail, so that applications may still continue if possible.
114 */
115 return VK_SUCCESS;
116 }
117 strcpy(name_buf, pNameInfo->pObjectName);
118
119 simple_mtx_lock(&device->vk.memory_trace_data.token_mtx);
120 struct vk_rmv_userdata_token token;
121 token.name = name_buf;
122 token.resource_id = vk_rmv_get_resource_id_locked(&device->vk, pNameInfo->objectHandle);
123
124 vk_rmv_emit_token(&device->vk.memory_trace_data, VK_RMV_TOKEN_TYPE_USERDATA, &token);
125 simple_mtx_unlock(&device->vk.memory_trace_data.token_mtx);
126
127 return VK_SUCCESS;
128 }
129