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