xref: /aosp_15_r20/external/mesa3d/src/microsoft/vulkan/dzn_abi_helper.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 /* The purpose of this file is to abstract the differences between the Windows
25  * C ABI for D3D12 and the Linux ABI. Essentially, for class methods that return
26  * structures, the MSVC C++ ABI specifies that they are always called with the return
27  * structure allocated by the caller, and passed as a hidden second parameter,
28  * after "this". But the C compiler doesn't apply that automatically to the C
29  * equivalent definition of the method, and so that ABI needs to be explicitly
30  * embedded in the C function signature. For Linux, no such ABI difference between
31  * C and C++ exists, and so C callers should use the same signature as C++.
32  */
33 
34 #ifndef DZN_ABI_HELPER_H
35 #define DZN_ABI_HELPER_H
36 
37 static inline D3D12_HEAP_PROPERTIES
dzn_ID3D12Device4_GetCustomHeapProperties(ID3D12Device4 * dev,UINT node_mask,D3D12_HEAP_TYPE type)38 dzn_ID3D12Device4_GetCustomHeapProperties(ID3D12Device4 *dev, UINT node_mask, D3D12_HEAP_TYPE type)
39 {
40     D3D12_HEAP_PROPERTIES ret;
41 #ifdef _WIN32
42     ID3D12Device4_GetCustomHeapProperties(dev, &ret, node_mask, type);
43 #else
44     ret = ID3D12Device4_GetCustomHeapProperties(dev, node_mask, type);
45 #endif
46     return ret;
47 }
48 
49 static inline D3D12_RESOURCE_ALLOCATION_INFO
dzn_ID3D12Device4_GetResourceAllocationInfo(ID3D12Device4 * dev,UINT visible_mask,UINT num_resource_descs,const D3D12_RESOURCE_DESC * resource_descs)50 dzn_ID3D12Device4_GetResourceAllocationInfo(ID3D12Device4 *dev, UINT visible_mask, UINT num_resource_descs, const D3D12_RESOURCE_DESC *resource_descs)
51 {
52     D3D12_RESOURCE_ALLOCATION_INFO ret;
53 #ifdef _WIN32
54     ID3D12Device4_GetResourceAllocationInfo(dev, &ret, visible_mask, num_resource_descs, resource_descs);
55 #else
56     ret = ID3D12Device4_GetResourceAllocationInfo(dev, visible_mask, num_resource_descs, resource_descs);
57 #endif
58     return ret;
59 }
60 
61 static inline D3D12_RESOURCE_ALLOCATION_INFO
dzn_ID3D12Device12_GetResourceAllocationInfo3(ID3D12Device12 * dev,UINT visible_mask,UINT num_resource_descs,const D3D12_RESOURCE_DESC1 * resource_descs,const UINT * num_castable_formats,const DXGI_FORMAT * const * castable_formats,D3D12_RESOURCE_ALLOCATION_INFO1 * allocation_info1)62 dzn_ID3D12Device12_GetResourceAllocationInfo3(ID3D12Device12 *dev, UINT visible_mask, UINT num_resource_descs, const D3D12_RESOURCE_DESC1 *resource_descs,
63                                               const UINT *num_castable_formats, const DXGI_FORMAT *const *castable_formats,
64                                               D3D12_RESOURCE_ALLOCATION_INFO1 *allocation_info1)
65 {
66    D3D12_RESOURCE_ALLOCATION_INFO ret;
67 #ifdef _WIN32
68    ID3D12Device12_GetResourceAllocationInfo3(dev, &ret, visible_mask, num_resource_descs, resource_descs, num_castable_formats, castable_formats, allocation_info1);
69 #else
70    ret = ID3D12Device12_GetResourceAllocationInfo3(dev, visible_mask, num_resource_descs, resource_descs, num_castable_formats, castable_formats, allocation_info1);
71 #endif
72    return ret;
73 }
74 
75 static inline D3D12_RESOURCE_DESC
dzn_ID3D12Resource_GetDesc(ID3D12Resource * res)76 dzn_ID3D12Resource_GetDesc(ID3D12Resource *res)
77 {
78     D3D12_RESOURCE_DESC ret;
79 #ifdef _WIN32
80     ID3D12Resource_GetDesc(res, &ret);
81 #else
82     ret = ID3D12Resource_GetDesc(res);
83 #endif
84     return ret;
85 }
86 
87 static inline D3D12_HEAP_DESC
dzn_ID3D12Heap_GetDesc(ID3D12Heap * heap)88 dzn_ID3D12Heap_GetDesc(ID3D12Heap *heap)
89 {
90    D3D12_HEAP_DESC ret;
91 #ifdef _WIN32
92     ID3D12Heap_GetDesc(heap, &ret);
93 #else
94     ret = ID3D12Heap_GetDesc(heap);
95 #endif
96     return ret;
97 }
98 
99 static inline D3D12_CPU_DESCRIPTOR_HANDLE
dzn_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap * heap)100 dzn_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
101 {
102     D3D12_CPU_DESCRIPTOR_HANDLE ret;
103 #ifdef _WIN32
104     ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(heap, &ret);
105 #else
106     ret = ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(heap);
107 #endif
108     return ret;
109 }
110 
111 static inline D3D12_GPU_DESCRIPTOR_HANDLE
dzn_ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap * heap)112 dzn_ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
113 {
114     D3D12_GPU_DESCRIPTOR_HANDLE ret;
115 #ifdef _WIN32
116     ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(heap, &ret);
117 #else
118     ret = ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(heap);
119 #endif
120     return ret;
121 }
122 
123 #endif /*DZN_ABI_HELPER_H*/
124