• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    struct vn_renderer *renderer;
32    struct vn_ring *primary_ring;
33 
34    struct vn_device_memory_report *memory_reports;
35    uint32_t memory_report_count;
36 
37    /* unique queue family indices in which to create the device queues */
38    uint32_t *queue_families;
39    uint32_t queue_family_count;
40 
41    struct vn_device_memory_pool memory_pools[VK_MAX_MEMORY_TYPES];
42 
43    struct vn_feedback_pool feedback_pool;
44 
45    /* feedback cmd pool per queue family used by the device
46     * - length matches queue_family_count
47     * - order matches queue_families
48     */
49    struct vn_feedback_cmd_pool *fb_cmd_pools;
50 
51    struct vn_queue *queues;
52    uint32_t queue_count;
53 
54    struct vn_buffer_reqs_cache buffer_reqs_cache;
55    struct vn_image_reqs_cache image_reqs_cache;
56 };
57 VK_DEFINE_HANDLE_CASTS(vn_device,
58                        base.base.base,
59                        VkDevice,
60                        VK_OBJECT_TYPE_DEVICE)
61 
62 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)63 vn_device_emit_device_memory_report(struct vn_device *dev,
64                                     VkDeviceMemoryReportEventTypeEXT type,
65                                     uint64_t mem_obj_id,
66                                     VkDeviceSize size,
67                                     VkObjectType obj_type,
68                                     uint64_t obj_handle,
69                                     uint32_t heap_index)
70 {
71    assert(dev->memory_reports);
72    const VkDeviceMemoryReportCallbackDataEXT report = {
73       .sType = VK_STRUCTURE_TYPE_DEVICE_MEMORY_REPORT_CALLBACK_DATA_EXT,
74       .type = type,
75       .memoryObjectId = mem_obj_id,
76       .size = size,
77       .objectType = obj_type,
78       .objectHandle = obj_handle,
79       .heapIndex = heap_index,
80    };
81    for (uint32_t i = 0; i < dev->memory_report_count; i++)
82       dev->memory_reports[i].callback(&report, dev->memory_reports[i].data);
83 }
84 
85 #endif /* VN_DEVICE_H */
86