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 37static inline D3D12_HEAP_PROPERTIES 38dzn_ID3D12Device2_GetCustomHeapProperties(ID3D12Device2 *dev, UINT node_mask, D3D12_HEAP_TYPE type) 39{ 40 D3D12_HEAP_PROPERTIES ret; 41#ifdef _WIN32 42 ID3D12Device2_GetCustomHeapProperties(dev, &ret, node_mask, type); 43#elif D3D12_SDK_VERSION >= 606 44 ret = ID3D12Device2_GetCustomHeapProperties(dev, node_mask, type); 45#else 46 ret = ((D3D12_HEAP_PROPERTIES (STDMETHODCALLTYPE *)(ID3D12Device2 *, UINT, D3D12_HEAP_TYPE))dev->lpVtbl->GetCustomHeapProperties)(dev, node_mask, type); 47#endif 48 return ret; 49} 50 51static inline D3D12_RESOURCE_ALLOCATION_INFO 52dzn_ID3D12Device2_GetResourceAllocationInfo(ID3D12Device2 *dev, UINT visible_mask, UINT num_resource_descs, const D3D12_RESOURCE_DESC *resource_descs) 53{ 54 D3D12_RESOURCE_ALLOCATION_INFO ret; 55#ifdef _WIN32 56 ID3D12Device2_GetResourceAllocationInfo(dev, &ret, visible_mask, num_resource_descs, resource_descs); 57#elif D3D12_SDK_VERSION >= 606 58 ret = ID3D12Device2_GetResourceAllocationInfo(dev, visible_mask, num_resource_descs, resource_descs); 59#else 60 ret = ((D3D12_RESOURCE_ALLOCATION_INFO (STDMETHODCALLTYPE *)(ID3D12Device2 *, UINT, UINT, const D3D12_RESOURCE_DESC *)) 61 dev->lpVtbl->GetResourceAllocationInfo)(dev, visible_mask, num_resource_descs, resource_descs); 62#endif 63 return ret; 64} 65 66static inline D3D12_RESOURCE_DESC 67dzn_ID3D12Resource_GetDesc(ID3D12Resource *res) 68{ 69 D3D12_RESOURCE_DESC ret; 70#ifdef _WIN32 71 ID3D12Resource_GetDesc(res, &ret); 72#elif D3D12_SDK_VERSION >= 606 73 ret = ID3D12Resource_GetDesc(res); 74#else 75 ret = ((D3D12_RESOURCE_DESC (STDMETHODCALLTYPE *)(ID3D12Resource *))res->lpVtbl->GetDesc)(res); 76#endif 77 return ret; 78} 79 80static inline D3D12_CPU_DESCRIPTOR_HANDLE 81dzn_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap) 82{ 83 D3D12_CPU_DESCRIPTOR_HANDLE ret; 84#ifdef _WIN32 85 ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(heap, &ret); 86#elif D3D12_SDK_VERSION >= 606 87 ret = ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(heap); 88#else 89 ret = ((D3D12_CPU_DESCRIPTOR_HANDLE (STDMETHODCALLTYPE *)(ID3D12DescriptorHeap *))heap->lpVtbl->GetCPUDescriptorHandleForHeapStart)(heap); 90#endif 91 return ret; 92} 93 94static inline D3D12_GPU_DESCRIPTOR_HANDLE 95dzn_ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap) 96{ 97 D3D12_GPU_DESCRIPTOR_HANDLE ret; 98#ifdef _WIN32 99 ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(heap, &ret); 100#elif D3D12_SDK_VERSION >= 606 101 ret = ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(heap); 102#else 103 ret = ((D3D12_GPU_DESCRIPTOR_HANDLE (STDMETHODCALLTYPE *)(ID3D12DescriptorHeap *))heap->lpVtbl->GetGPUDescriptorHandleForHeapStart)(heap); 104#endif 105 return ret; 106} 107 108#endif /*DZN_ABI_HELPER_H*/ 109