• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "wsi_common_entrypoints.h"
29 
anv_rmv_QueuePresentKHR(VkQueue _queue,const VkPresentInfoKHR * pPresentInfo)30 VkResult anv_rmv_QueuePresentKHR(
31     VkQueue                                  _queue,
32     const VkPresentInfoKHR*                  pPresentInfo)
33 {
34    ANV_FROM_HANDLE(anv_queue, queue, _queue);
35    struct anv_device *device = queue->device;
36 
37    VkResult res = anv_QueuePresentKHR(_queue, pPresentInfo);
38    if ((res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR) ||
39        !device->vk.memory_trace_data.is_enabled)
40       return res;
41 
42    vk_rmv_log_misc_token(&device->vk, VK_RMV_MISC_EVENT_TYPE_PRESENT);
43 
44    return VK_SUCCESS;
45 }
46 
anv_rmv_FlushMappedMemoryRanges(VkDevice _device,uint32_t memoryRangeCount,const VkMappedMemoryRange * pMemoryRanges)47 VkResult anv_rmv_FlushMappedMemoryRanges(
48     VkDevice                                    _device,
49     uint32_t                                    memoryRangeCount,
50     const VkMappedMemoryRange*                  pMemoryRanges)
51 {
52    ANV_FROM_HANDLE(anv_device, device, _device);
53 
54    VkResult res = anv_FlushMappedMemoryRanges(_device, memoryRangeCount, pMemoryRanges);
55    if (res != VK_SUCCESS || !device->vk.memory_trace_data.is_enabled)
56       return res;
57 
58    vk_rmv_log_misc_token(&device->vk, VK_RMV_MISC_EVENT_TYPE_FLUSH_MAPPED_RANGE);
59 
60    return VK_SUCCESS;
61 }
62 
anv_rmv_InvalidateMappedMemoryRanges(VkDevice _device,uint32_t memoryRangeCount,const VkMappedMemoryRange * pMemoryRanges)63 VkResult anv_rmv_InvalidateMappedMemoryRanges(
64     VkDevice                                    _device,
65     uint32_t                                    memoryRangeCount,
66     const VkMappedMemoryRange*                  pMemoryRanges)
67 {
68    ANV_FROM_HANDLE(anv_device, device, _device);
69 
70    VkResult res = anv_InvalidateMappedMemoryRanges(_device, memoryRangeCount, pMemoryRanges);
71    if (res != VK_SUCCESS || !device->vk.memory_trace_data.is_enabled)
72       return res;
73 
74    vk_rmv_log_misc_token(&device->vk, VK_RMV_MISC_EVENT_TYPE_INVALIDATE_RANGES);
75 
76    return VK_SUCCESS;
77 }
78 
anv_rmv_DebugMarkerSetObjectNameEXT(VkDevice device,const VkDebugMarkerObjectNameInfoEXT * pNameInfo)79 VkResult anv_rmv_DebugMarkerSetObjectNameEXT(
80     VkDevice                                    device,
81     const VkDebugMarkerObjectNameInfoEXT*       pNameInfo)
82 {
83    assert(pNameInfo->sType == VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT);
84    VkDebugUtilsObjectNameInfoEXT name_info;
85    name_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
86    name_info.objectType = pNameInfo->objectType;
87    name_info.objectHandle = pNameInfo->object;
88    name_info.pObjectName = pNameInfo->pObjectName;
89    return anv_rmv_SetDebugUtilsObjectNameEXT(device, &name_info);
90 }
91 
anv_rmv_SetDebugUtilsObjectNameEXT(VkDevice _device,const VkDebugUtilsObjectNameInfoEXT * pNameInfo)92 VkResult anv_rmv_SetDebugUtilsObjectNameEXT(
93     VkDevice                                    _device,
94     const VkDebugUtilsObjectNameInfoEXT*        pNameInfo)
95 {
96    assert(pNameInfo->sType == VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT);
97    ANV_FROM_HANDLE(anv_device, device, _device);
98 
99    VkResult result = vk_common_SetDebugUtilsObjectNameEXT(_device, pNameInfo);
100    if (result != VK_SUCCESS || !device->vk.memory_trace_data.is_enabled)
101       return result;
102 
103    switch (pNameInfo->objectType) {
104    /* only name object types we care about */
105    case VK_OBJECT_TYPE_BUFFER:
106    case VK_OBJECT_TYPE_DEVICE_MEMORY:
107    case VK_OBJECT_TYPE_IMAGE:
108    case VK_OBJECT_TYPE_EVENT:
109    case VK_OBJECT_TYPE_QUERY_POOL:
110    case VK_OBJECT_TYPE_DESCRIPTOR_POOL:
111    case VK_OBJECT_TYPE_PIPELINE:
112       break;
113    default:
114       return VK_SUCCESS;
115    }
116 
117    size_t name_len = strlen(pNameInfo->pObjectName);
118    char *name_buf = malloc(name_len + 1);
119    if (!name_buf) {
120       /*
121        * Silently fail, so that applications may still continue if possible.
122        */
123       return VK_SUCCESS;
124    }
125    strcpy(name_buf, pNameInfo->pObjectName);
126 
127    simple_mtx_lock(&device->vk.memory_trace_data.token_mtx);
128    struct vk_rmv_userdata_token token;
129    token.name = name_buf;
130    token.resource_id = vk_rmv_get_resource_id_locked(&device->vk, pNameInfo->objectHandle);
131 
132    vk_rmv_emit_token(&device->vk.memory_trace_data, VK_RMV_TOKEN_TYPE_USERDATA, &token);
133    simple_mtx_unlock(&device->vk.memory_trace_data.token_mtx);
134 
135    return VK_SUCCESS;
136 }
137