xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/d3d12/d3d12_common.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © Yonggang Luo
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_COMMON_STATE_H
25 #define D3D12_COMMON_STATE_H
26 
27 #pragma once
28 
29 #include <wsl/winadapter.h>
30 
31 #define D3D12_IGNORE_SDK_LAYERS
32 #ifndef _GAMING_XBOX
33 #include <directx/d3d12.h>
34 #include <directx/d3d12video.h>
35 #elif defined(__cplusplus)
36 #ifdef _GAMING_XBOX_SCARLETT
37 #include <d3d12_xs.h>
38 #include <d3d12video_xs.h>
39 #else
40 #include <d3d12_x.h>
41 #include <d3d12video_x.h>
42 #endif
43 #ifdef IID_PPV_ARGS
44 #undef IID_PPV_ARGS
45 #endif
46 #define IID_PPV_ARGS IID_GRAPHICS_PPV_ARGS
47 #define D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT (D3D12_HEAP_FLAGS) 0x800
48 #endif /* _GAMING_XBOX */
49 
50 #ifndef D3D12_TEXTURE_DATA_PITCH_ALIGNMENT
51 #define D3D12_TEXTURE_DATA_PITCH_ALIGNMENT D3D12XBOX_TEXTURE_DATA_PITCH_ALIGNMENT
52 #endif /* D3D12_TEXTURE_DATA_PITCH_ALIGNMENT */
53 
54 #if defined(__cplusplus)
55 #if !defined(_WIN32) || defined(_MSC_VER)
56 inline D3D12_CPU_DESCRIPTOR_HANDLE
GetCPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap * heap)57 GetCPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
58 {
59    return heap->GetCPUDescriptorHandleForHeapStart();
60 }
61 inline D3D12_GPU_DESCRIPTOR_HANDLE
GetGPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap * heap)62 GetGPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
63 {
64    return heap->GetGPUDescriptorHandleForHeapStart();
65 }
66 D3D12_HEAP_DESC
GetDesc(ID3D12Heap * heap)67 inline GetDesc(ID3D12Heap* heap)
68 {
69    return heap->GetDesc();
70 }
71 inline D3D12_RESOURCE_DESC
GetDesc(ID3D12Resource * res)72 GetDesc(ID3D12Resource *res)
73 {
74    return res->GetDesc();
75 }
76 inline D3D12_HEAP_PROPERTIES
GetCustomHeapProperties(ID3D12Device * dev,D3D12_HEAP_TYPE type)77 GetCustomHeapProperties(ID3D12Device *dev, D3D12_HEAP_TYPE type)
78 {
79    return dev->GetCustomHeapProperties(0, type);
80 }
81 inline LUID
GetAdapterLuid(ID3D12Device * dev)82 GetAdapterLuid(ID3D12Device *dev)
83 {
84    return dev->GetAdapterLuid();
85 }
86 inline D3D12_VIDEO_PROCESS_OUTPUT_STREAM_DESC
GetOutputStreamDesc(ID3D12VideoProcessor * proc)87 GetOutputStreamDesc(ID3D12VideoProcessor *proc)
88 {
89    return proc->GetOutputStreamDesc();
90 }
91 inline D3D12_RESOURCE_ALLOCATION_INFO
GetResourceAllocationInfo(ID3D12Device * dev,UINT visibleMask,UINT numResourceDescs,const D3D12_RESOURCE_DESC * pResourceDescs)92 GetResourceAllocationInfo(ID3D12Device *dev, UINT visibleMask, UINT numResourceDescs, const D3D12_RESOURCE_DESC *pResourceDescs)
93 {
94    return dev->GetResourceAllocationInfo(visibleMask, numResourceDescs, pResourceDescs);
95 }
96 #else
97 inline D3D12_CPU_DESCRIPTOR_HANDLE
GetCPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap * heap)98 GetCPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
99 {
100    D3D12_CPU_DESCRIPTOR_HANDLE ret;
101    heap->GetCPUDescriptorHandleForHeapStart(&ret);
102    return ret;
103 }
104 inline D3D12_GPU_DESCRIPTOR_HANDLE
GetGPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap * heap)105 GetGPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
106 {
107    D3D12_GPU_DESCRIPTOR_HANDLE ret;
108    heap->GetGPUDescriptorHandleForHeapStart(&ret);
109    return ret;
110 }
111 D3D12_HEAP_DESC
GetDesc(ID3D12Heap * heap)112 inline GetDesc(ID3D12Heap* heap)
113 {
114    D3D12_HEAP_DESC ret;
115    heap->GetDesc(&ret);
116    return ret;
117 }
118 inline D3D12_RESOURCE_DESC
GetDesc(ID3D12Resource * res)119 GetDesc(ID3D12Resource *res)
120 {
121    D3D12_RESOURCE_DESC ret;
122    res->GetDesc(&ret);
123    return ret;
124 }
125 inline D3D12_HEAP_PROPERTIES
GetCustomHeapProperties(ID3D12Device * dev,D3D12_HEAP_TYPE type)126 GetCustomHeapProperties(ID3D12Device *dev, D3D12_HEAP_TYPE type)
127 {
128    D3D12_HEAP_PROPERTIES ret;
129    dev->GetCustomHeapProperties(&ret, 0, type);
130    return ret;
131 }
132 inline LUID
GetAdapterLuid(ID3D12Device * dev)133 GetAdapterLuid(ID3D12Device *dev)
134 {
135    LUID ret;
136    dev->GetAdapterLuid(&ret);
137    return ret;
138 }
139 inline D3D12_VIDEO_PROCESS_OUTPUT_STREAM_DESC
GetOutputStreamDesc(ID3D12VideoProcessor * proc)140 GetOutputStreamDesc(ID3D12VideoProcessor *proc)
141 {
142    D3D12_VIDEO_PROCESS_OUTPUT_STREAM_DESC ret;
143    proc->GetOutputStreamDesc(&ret);
144    return ret;
145 }
146 inline D3D12_RESOURCE_ALLOCATION_INFO
GetResourceAllocationInfo(ID3D12Device * dev,UINT visibleMask,UINT numResourceDescs,const D3D12_RESOURCE_DESC * pResourceDescs)147 GetResourceAllocationInfo(ID3D12Device *dev, UINT visibleMask, UINT numResourceDescs, const D3D12_RESOURCE_DESC *pResourceDescs)
148 {
149    D3D12_RESOURCE_ALLOCATION_INFO ret;
150    dev->GetResourceAllocationInfo(&ret, visibleMask, numResourceDescs, pResourceDescs);
151    return ret;
152 }
153 #endif
154 #endif
155 
156 #endif
157