xref: /aosp_15_r20/external/mesa3d/src/virtio/vulkan/vn_device.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2019 Google LLC
3  * SPDX-License-Identifier: MIT
4  *
5  * based in part on anv and radv which are:
6  * Copyright © 2015 Intel Corporation
7  * Copyright © 2016 Red Hat.
8  * Copyright © 2016 Bas Nieuwenhuizen
9  */
10 
11 #ifndef VN_DEVICE_H
12 #define VN_DEVICE_H
13 
14 #include "vn_common.h"
15 
16 #include "vn_buffer.h"
17 #include "vn_device_memory.h"
18 #include "vn_feedback.h"
19 #include "vn_image.h"
20 
21 struct vn_device_memory_report {
22    PFN_vkDeviceMemoryReportCallbackEXT callback;
23    void *data;
24 };
25 
26 struct vn_device {
27    struct vn_device_base base;
28 
29    struct vn_instance *instance;
30    struct vn_physical_device *physical_device;
31    uint32_t device_mask;
32    struct vn_renderer *renderer;
33    struct vn_ring *primary_ring;
34 
35    struct vn_device_memory_report *memory_reports;
36    uint32_t memory_report_count;
37 
38    /* unique queue family indices in which to create the device queues */
39    uint32_t *queue_families;
40    uint32_t queue_family_count;
41 
42    struct vn_feedback_pool feedback_pool;
43 
44    /* feedback cmd pool per queue family used by the device
45     * - length matches queue_family_count
46     * - order matches queue_families
47     */
48    struct vn_feedback_cmd_pool *fb_cmd_pools;
49 
50    struct vn_queue *queues;
51    uint32_t queue_count;
52 
53    struct vn_buffer_reqs_cache buffer_reqs_cache;
54    struct vn_image_reqs_cache image_reqs_cache;
55 };
56 VK_DEFINE_HANDLE_CASTS(vn_device,
57                        base.base.base,
58                        VkDevice,
59                        VK_OBJECT_TYPE_DEVICE)
60 
61 static inline void
vn_device_emit_device_memory_report(struct vn_device * dev,VkDeviceMemoryReportEventTypeEXT type,uint64_t mem_obj_id,VkDeviceSize size,VkObjectType obj_type,uint64_t obj_handle,uint32_t heap_index)62 vn_device_emit_device_memory_report(struct vn_device *dev,
63                                     VkDeviceMemoryReportEventTypeEXT type,
64                                     uint64_t mem_obj_id,
65                                     VkDeviceSize size,
66                                     VkObjectType obj_type,
67                                     uint64_t obj_handle,
68                                     uint32_t heap_index)
69 {
70    assert(dev->memory_reports);
71    const VkDeviceMemoryReportCallbackDataEXT report = {
72       .sType = VK_STRUCTURE_TYPE_DEVICE_MEMORY_REPORT_CALLBACK_DATA_EXT,
73       .type = type,
74       .memoryObjectId = mem_obj_id,
75       .size = size,
76       .objectType = obj_type,
77       .objectHandle = obj_handle,
78       .heapIndex = heap_index,
79    };
80    for (uint32_t i = 0; i < dev->memory_report_count; i++)
81       dev->memory_reports[i].callback(&report, dev->memory_reports[i].data);
82 }
83 
84 #endif /* VN_DEVICE_H */
85