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_DESCRIPTOR_POOL_H
25 #define D3D12_DESCRIPTOR_POOL_H
26
27 #ifndef _WIN32
28 #include <wsl/winadapter.h>
29 #endif
30
31 #define D3D12_IGNORE_SDK_LAYERS
32 #include <directx/d3d12.h>
33
34 struct d3d12_descriptor_pool;
35 struct d3d12_descriptor_heap;
36
37 struct d3d12_descriptor_handle {
38 D3D12_CPU_DESCRIPTOR_HANDLE cpu_handle;
39 D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle;
40 struct d3d12_descriptor_heap *heap;
41 };
42
43 inline bool
d3d12_descriptor_handle_is_allocated(struct d3d12_descriptor_handle * handle)44 d3d12_descriptor_handle_is_allocated(struct d3d12_descriptor_handle *handle)
45 {
46 return (handle->heap != NULL);
47 }
48
49 void
50 d3d12_descriptor_handle_free(struct d3d12_descriptor_handle *handle);
51
52 /* Offline Descriptor Pool */
53
54 struct d3d12_descriptor_pool*
55 d3d12_descriptor_pool_new(struct d3d12_screen *screen,
56 D3D12_DESCRIPTOR_HEAP_TYPE type,
57 uint32_t num_descriptors);
58
59 void
60 d3d12_descriptor_pool_free(struct d3d12_descriptor_pool *pool);
61
62 uint32_t
63 d3d12_descriptor_pool_alloc_handle(struct d3d12_descriptor_pool *pool,
64 struct d3d12_descriptor_handle *handle);
65
66
67 /* Online/Offline Descriptor Heaps */
68
69 struct d3d12_descriptor_heap*
70 d3d12_descriptor_heap_new(ID3D12Device *device,
71 D3D12_DESCRIPTOR_HEAP_TYPE type,
72 D3D12_DESCRIPTOR_HEAP_FLAGS flags,
73 uint32_t num_descriptors);
74
75 void
76 d3d12_descriptor_heap_free(struct d3d12_descriptor_heap *heap);
77
78 ID3D12DescriptorHeap*
79 d3d12_descriptor_heap_get(struct d3d12_descriptor_heap *heap);
80
81 void
82 d2d12_descriptor_heap_get_next_handle(struct d3d12_descriptor_heap *heap,
83 struct d3d12_descriptor_handle *handle);
84
85 uint32_t
86 d3d12_descriptor_heap_get_remaining_handles(struct d3d12_descriptor_heap *heap);
87
88 uint32_t
89 d3d12_descriptor_heap_alloc_handle(struct d3d12_descriptor_heap *heap,
90 struct d3d12_descriptor_handle *handle);
91
92 void
93 d3d12_descriptor_heap_append_handles(struct d3d12_descriptor_heap *heap,
94 D3D12_CPU_DESCRIPTOR_HANDLE *handles,
95 unsigned num_handles);
96
97 void
98 d3d12_descriptor_heap_clear(struct d3d12_descriptor_heap *heap);
99
100 #endif
101