xref: /aosp_15_r20/external/mesa3d/src/intel/vulkan/layers/anv_rmv_layer.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2023 Intel Corporation
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 "anv_private.h"
27 #include "vk_common_entrypoints.h"
28 
anv_rmv_QueuePresentKHR(VkQueue _queue,const VkPresentInfoKHR * pPresentInfo)29 VkResult anv_rmv_QueuePresentKHR(
30     VkQueue                                  _queue,
31     const VkPresentInfoKHR*                  pPresentInfo)
32 {
33    ANV_FROM_HANDLE(anv_queue, queue, _queue);
34    struct anv_device *device = queue->device;
35 
36    VkResult res = anv_QueuePresentKHR(_queue, pPresentInfo);
37    if ((res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR) ||
38        !device->vk.memory_trace_data.is_enabled)
39       return res;
40 
41    vk_rmv_log_misc_token(&device->vk, VK_RMV_MISC_EVENT_TYPE_PRESENT);
42 
43    return VK_SUCCESS;
44 }
45 
anv_rmv_FlushMappedMemoryRanges(VkDevice _device,uint32_t memoryRangeCount,const VkMappedMemoryRange * pMemoryRanges)46 VkResult anv_rmv_FlushMappedMemoryRanges(
47     VkDevice                                    _device,
48     uint32_t                                    memoryRangeCount,
49     const VkMappedMemoryRange*                  pMemoryRanges)
50 {
51    ANV_FROM_HANDLE(anv_device, device, _device);
52 
53    VkResult res = anv_FlushMappedMemoryRanges(_device, memoryRangeCount, pMemoryRanges);
54    if (res != VK_SUCCESS || !device->vk.memory_trace_data.is_enabled)
55       return res;
56 
57    vk_rmv_log_misc_token(&device->vk, VK_RMV_MISC_EVENT_TYPE_FLUSH_MAPPED_RANGE);
58 
59    return VK_SUCCESS;
60 }
61 
anv_rmv_InvalidateMappedMemoryRanges(VkDevice _device,uint32_t memoryRangeCount,const VkMappedMemoryRange * pMemoryRanges)62 VkResult anv_rmv_InvalidateMappedMemoryRanges(
63     VkDevice                                    _device,
64     uint32_t                                    memoryRangeCount,
65     const VkMappedMemoryRange*                  pMemoryRanges)
66 {
67    ANV_FROM_HANDLE(anv_device, device, _device);
68 
69    VkResult res = anv_InvalidateMappedMemoryRanges(_device, memoryRangeCount, pMemoryRanges);
70    if (res != VK_SUCCESS || !device->vk.memory_trace_data.is_enabled)
71       return res;
72 
73    vk_rmv_log_misc_token(&device->vk, VK_RMV_MISC_EVENT_TYPE_INVALIDATE_RANGES);
74 
75    return VK_SUCCESS;
76 }
77 
anv_rmv_SetDebugUtilsObjectNameEXT(VkDevice _device,const VkDebugUtilsObjectNameInfoEXT * pNameInfo)78 VkResult anv_rmv_SetDebugUtilsObjectNameEXT(
79     VkDevice                                    _device,
80     const VkDebugUtilsObjectNameInfoEXT*        pNameInfo)
81 {
82    assert(pNameInfo->sType == VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT);
83    ANV_FROM_HANDLE(anv_device, device, _device);
84 
85    VkResult result = vk_common_SetDebugUtilsObjectNameEXT(_device, pNameInfo);
86    if (result != VK_SUCCESS || !device->vk.memory_trace_data.is_enabled)
87       return result;
88 
89    switch (pNameInfo->objectType) {
90    /* only name object types we care about */
91    case VK_OBJECT_TYPE_BUFFER:
92    case VK_OBJECT_TYPE_DEVICE_MEMORY:
93    case VK_OBJECT_TYPE_IMAGE:
94    case VK_OBJECT_TYPE_EVENT:
95    case VK_OBJECT_TYPE_QUERY_POOL:
96    case VK_OBJECT_TYPE_DESCRIPTOR_POOL:
97    case VK_OBJECT_TYPE_PIPELINE:
98       break;
99    default:
100       return VK_SUCCESS;
101    }
102 
103    struct vk_object_base *object =
104       vk_object_base_from_u64_handle(pNameInfo->objectHandle,
105                                      pNameInfo->objectType);
106 
107    simple_mtx_lock(&device->vk.memory_trace_data.token_mtx);
108    struct vk_rmv_userdata_token token;
109    token.name = vk_strdup(&device->vk.alloc, object->object_name,
110                           VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
111    token.resource_id = vk_rmv_get_resource_id_locked(&device->vk, pNameInfo->objectHandle);
112 
113    vk_rmv_emit_token(&device->vk.memory_trace_data, VK_RMV_TOKEN_TYPE_USERDATA, &token);
114    simple_mtx_unlock(&device->vk.memory_trace_data.token_mtx);
115 
116    return VK_SUCCESS;
117 }
118