1 /*
2 * Copyright © Microsoft 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 #ifndef D3D12_SCREEN_H
25 #define D3D12_SCREEN_H
26
27 #include "pipe/p_screen.h"
28
29 #include "util/slab.h"
30 #include "d3d12_descriptor_pool.h"
31
32 #include "nir.h"
33
34 #include "d3d12_common.h"
35
36 struct pb_manager;
37
38 enum resource_dimension
39 {
40 RESOURCE_DIMENSION_UNKNOWN = 0,
41 RESOURCE_DIMENSION_BUFFER = 1,
42 RESOURCE_DIMENSION_TEXTURE1D = 2,
43 RESOURCE_DIMENSION_TEXTURE2D = 3,
44 RESOURCE_DIMENSION_TEXTURE2DMS = 4,
45 RESOURCE_DIMENSION_TEXTURE3D = 5,
46 RESOURCE_DIMENSION_TEXTURECUBE = 6,
47 RESOURCE_DIMENSION_TEXTURE1DARRAY = 7,
48 RESOURCE_DIMENSION_TEXTURE2DARRAY = 8,
49 RESOURCE_DIMENSION_TEXTURE2DMSARRAY = 9,
50 RESOURCE_DIMENSION_TEXTURECUBEARRAY = 10,
51 RESOURCE_DIMENSION_COUNT
52 };
53
54 struct d3d12_memory_info {
55 uint64_t usage;
56 uint64_t budget;
57 };
58
59 struct d3d12_screen {
60 struct pipe_screen base;
61 struct sw_winsys *winsys;
62 LUID adapter_luid;
63 char driver_uuid[PIPE_UUID_SIZE];
64 char device_uuid[PIPE_UUID_SIZE];
65
66 ID3D12Device3 *dev;
67 ID3D12CommandQueue *cmdqueue;
68 bool (*init)(struct d3d12_screen *screen);
69 void (*deinit)(struct d3d12_screen *screen);
70 void (*get_memory_info)(struct d3d12_screen *screen, struct d3d12_memory_info *output);
71
72 mtx_t submit_mutex;
73 ID3D12Fence *fence;
74 uint64_t fence_value;
75
76 struct list_head residency_list;
77 ID3D12Fence *residency_fence;
78 uint64_t residency_fence_value;
79
80 struct list_head context_list;
81
82 struct slab_parent_pool transfer_pool;
83 struct pb_manager *bufmgr;
84 struct pb_manager *cache_bufmgr;
85 struct pb_manager *slab_bufmgr;
86 struct pb_manager *readback_slab_bufmgr;
87
88 mtx_t descriptor_pool_mutex;
89 struct d3d12_descriptor_pool *rtv_pool;
90 struct d3d12_descriptor_pool *dsv_pool;
91 struct d3d12_descriptor_pool *view_pool;
92
93 struct d3d12_descriptor_handle null_srvs[RESOURCE_DIMENSION_COUNT];
94 struct d3d12_descriptor_handle null_uavs[RESOURCE_DIMENSION_COUNT];
95 struct d3d12_descriptor_handle null_rtv;
96
97 volatile uint32_t ctx_count;
98 volatile uint64_t resource_id_generator;
99
100 /* capabilities */
101 D3D_FEATURE_LEVEL max_feature_level;
102 D3D12_FEATURE_DATA_ARCHITECTURE architecture;
103 D3D12_FEATURE_DATA_D3D12_OPTIONS opts;
104 D3D12_FEATURE_DATA_D3D12_OPTIONS1 opts1;
105 D3D12_FEATURE_DATA_D3D12_OPTIONS2 opts2;
106 D3D12_FEATURE_DATA_D3D12_OPTIONS3 opts3;
107 D3D12_FEATURE_DATA_D3D12_OPTIONS4 opts4;
108
109 nir_shader_compiler_options nir_options;
110
111 /* description */
112 uint32_t vendor_id;
113 uint32_t device_id;
114 uint32_t subsys_id;
115 uint32_t revision;
116 uint64_t driver_version;
117 uint64_t memory_size_megabytes;
118 double timestamp_multiplier;
119 bool have_load_at_vertex;
120 bool support_shader_images;
121 bool support_create_not_resident;
122 };
123
124 static inline struct d3d12_screen *
d3d12_screen(struct pipe_screen * pipe)125 d3d12_screen(struct pipe_screen *pipe)
126 {
127 return (struct d3d12_screen *)pipe;
128 }
129
130 struct d3d12_dxgi_screen {
131 struct d3d12_screen base;
132
133 struct IDXGIFactory4 *factory;
134 struct IDXGIAdapter3 *adapter;
135 wchar_t description[128];
136 };
137
138 static inline struct d3d12_dxgi_screen *
d3d12_dxgi_screen(struct d3d12_screen * screen)139 d3d12_dxgi_screen(struct d3d12_screen *screen)
140 {
141 return (struct d3d12_dxgi_screen *)screen;
142 }
143
144 struct d3d12_dxcore_screen {
145 struct d3d12_screen base;
146
147 struct IDXCoreAdapterFactory *factory;
148 struct IDXCoreAdapter *adapter;
149 char description[256];
150 };
151
152 static inline struct d3d12_dxcore_screen *
d3d12_dxcore_screen(struct d3d12_screen * screen)153 d3d12_dxcore_screen(struct d3d12_screen *screen)
154 {
155 return (struct d3d12_dxcore_screen *)screen;
156 }
157
158 void
159 d3d12_init_screen_base(struct d3d12_screen *screen, struct sw_winsys *winsys, LUID *adapter_luid);
160
161 bool
162 d3d12_init_screen(struct d3d12_screen *screen, IUnknown *adapter);
163
164 void
165 d3d12_deinit_screen(struct d3d12_screen *screen);
166
167 void
168 d3d12_destroy_screen(struct d3d12_screen *screen);
169
170 #endif
171