1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © Microsoft Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci/* The purpose of this file is to abstract the differences between the Windows
25bf215546Sopenharmony_ci * C ABI for D3D12 and the Linux ABI. Essentially, for class methods that return
26bf215546Sopenharmony_ci * structures, the MSVC C++ ABI specifies that they are always called with the return
27bf215546Sopenharmony_ci * structure allocated by the caller, and passed as a hidden second parameter,
28bf215546Sopenharmony_ci * after "this". But the C compiler doesn't apply that automatically to the C
29bf215546Sopenharmony_ci * equivalent definition of the method, and so that ABI needs to be explicitly
30bf215546Sopenharmony_ci * embedded in the C function signature. For Linux, no such ABI difference between
31bf215546Sopenharmony_ci * C and C++ exists, and so C callers should use the same signature as C++.
32bf215546Sopenharmony_ci */
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#ifndef DZN_ABI_HELPER_H
35bf215546Sopenharmony_ci#define DZN_ABI_HELPER_H
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_cistatic inline D3D12_HEAP_PROPERTIES
38bf215546Sopenharmony_cidzn_ID3D12Device2_GetCustomHeapProperties(ID3D12Device2 *dev, UINT node_mask, D3D12_HEAP_TYPE type)
39bf215546Sopenharmony_ci{
40bf215546Sopenharmony_ci    D3D12_HEAP_PROPERTIES ret;
41bf215546Sopenharmony_ci#ifdef _WIN32
42bf215546Sopenharmony_ci    ID3D12Device2_GetCustomHeapProperties(dev, &ret, node_mask, type);
43bf215546Sopenharmony_ci#elif D3D12_SDK_VERSION >= 606
44bf215546Sopenharmony_ci    ret = ID3D12Device2_GetCustomHeapProperties(dev, node_mask, type);
45bf215546Sopenharmony_ci#else
46bf215546Sopenharmony_ci    ret = ((D3D12_HEAP_PROPERTIES (STDMETHODCALLTYPE *)(ID3D12Device2 *, UINT, D3D12_HEAP_TYPE))dev->lpVtbl->GetCustomHeapProperties)(dev, node_mask, type);
47bf215546Sopenharmony_ci#endif
48bf215546Sopenharmony_ci    return ret;
49bf215546Sopenharmony_ci}
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_cistatic inline D3D12_RESOURCE_ALLOCATION_INFO
52bf215546Sopenharmony_cidzn_ID3D12Device2_GetResourceAllocationInfo(ID3D12Device2 *dev, UINT visible_mask, UINT num_resource_descs, const D3D12_RESOURCE_DESC *resource_descs)
53bf215546Sopenharmony_ci{
54bf215546Sopenharmony_ci    D3D12_RESOURCE_ALLOCATION_INFO ret;
55bf215546Sopenharmony_ci#ifdef _WIN32
56bf215546Sopenharmony_ci    ID3D12Device2_GetResourceAllocationInfo(dev, &ret, visible_mask, num_resource_descs, resource_descs);
57bf215546Sopenharmony_ci#elif D3D12_SDK_VERSION >= 606
58bf215546Sopenharmony_ci    ret = ID3D12Device2_GetResourceAllocationInfo(dev, visible_mask, num_resource_descs, resource_descs);
59bf215546Sopenharmony_ci#else
60bf215546Sopenharmony_ci    ret = ((D3D12_RESOURCE_ALLOCATION_INFO (STDMETHODCALLTYPE *)(ID3D12Device2 *, UINT, UINT, const D3D12_RESOURCE_DESC *))
61bf215546Sopenharmony_ci        dev->lpVtbl->GetResourceAllocationInfo)(dev, visible_mask, num_resource_descs, resource_descs);
62bf215546Sopenharmony_ci#endif
63bf215546Sopenharmony_ci    return ret;
64bf215546Sopenharmony_ci}
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_cistatic inline D3D12_RESOURCE_DESC
67bf215546Sopenharmony_cidzn_ID3D12Resource_GetDesc(ID3D12Resource *res)
68bf215546Sopenharmony_ci{
69bf215546Sopenharmony_ci    D3D12_RESOURCE_DESC ret;
70bf215546Sopenharmony_ci#ifdef _WIN32
71bf215546Sopenharmony_ci    ID3D12Resource_GetDesc(res, &ret);
72bf215546Sopenharmony_ci#elif D3D12_SDK_VERSION >= 606
73bf215546Sopenharmony_ci    ret = ID3D12Resource_GetDesc(res);
74bf215546Sopenharmony_ci#else
75bf215546Sopenharmony_ci    ret = ((D3D12_RESOURCE_DESC (STDMETHODCALLTYPE *)(ID3D12Resource *))res->lpVtbl->GetDesc)(res);
76bf215546Sopenharmony_ci#endif
77bf215546Sopenharmony_ci    return ret;
78bf215546Sopenharmony_ci}
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_cistatic inline D3D12_CPU_DESCRIPTOR_HANDLE
81bf215546Sopenharmony_cidzn_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
82bf215546Sopenharmony_ci{
83bf215546Sopenharmony_ci    D3D12_CPU_DESCRIPTOR_HANDLE ret;
84bf215546Sopenharmony_ci#ifdef _WIN32
85bf215546Sopenharmony_ci    ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(heap, &ret);
86bf215546Sopenharmony_ci#elif D3D12_SDK_VERSION >= 606
87bf215546Sopenharmony_ci    ret = ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(heap);
88bf215546Sopenharmony_ci#else
89bf215546Sopenharmony_ci    ret = ((D3D12_CPU_DESCRIPTOR_HANDLE (STDMETHODCALLTYPE *)(ID3D12DescriptorHeap *))heap->lpVtbl->GetCPUDescriptorHandleForHeapStart)(heap);
90bf215546Sopenharmony_ci#endif
91bf215546Sopenharmony_ci    return ret;
92bf215546Sopenharmony_ci}
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_cistatic inline D3D12_GPU_DESCRIPTOR_HANDLE
95bf215546Sopenharmony_cidzn_ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
96bf215546Sopenharmony_ci{
97bf215546Sopenharmony_ci    D3D12_GPU_DESCRIPTOR_HANDLE ret;
98bf215546Sopenharmony_ci#ifdef _WIN32
99bf215546Sopenharmony_ci    ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(heap, &ret);
100bf215546Sopenharmony_ci#elif D3D12_SDK_VERSION >= 606
101bf215546Sopenharmony_ci    ret = ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(heap);
102bf215546Sopenharmony_ci#else
103bf215546Sopenharmony_ci    ret = ((D3D12_GPU_DESCRIPTOR_HANDLE (STDMETHODCALLTYPE *)(ID3D12DescriptorHeap *))heap->lpVtbl->GetGPUDescriptorHandleForHeapStart)(heap);
104bf215546Sopenharmony_ci#endif
105bf215546Sopenharmony_ci    return ret;
106bf215546Sopenharmony_ci}
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_ci#endif /*DZN_ABI_HELPER_H*/
109