• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 inline D3D12_RESOURCE_DESC
GetDesc(ID3D12Resource * res)67 GetDesc(ID3D12Resource *res)
68 {
69    return res->GetDesc();
70 }
71 inline D3D12_HEAP_PROPERTIES
GetCustomHeapProperties(ID3D12Device * dev,D3D12_HEAP_TYPE type)72 GetCustomHeapProperties(ID3D12Device *dev, D3D12_HEAP_TYPE type)
73 {
74    return dev->GetCustomHeapProperties(0, type);
75 }
76 inline LUID
GetAdapterLuid(ID3D12Device * dev)77 GetAdapterLuid(ID3D12Device *dev)
78 {
79    return dev->GetAdapterLuid();
80 }
81 inline D3D12_VIDEO_PROCESS_OUTPUT_STREAM_DESC
GetOutputStreamDesc(ID3D12VideoProcessor * proc)82 GetOutputStreamDesc(ID3D12VideoProcessor *proc)
83 {
84    return proc->GetOutputStreamDesc();
85 }
86 #else
87 inline D3D12_CPU_DESCRIPTOR_HANDLE
GetCPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap * heap)88 GetCPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
89 {
90    D3D12_CPU_DESCRIPTOR_HANDLE ret;
91    heap->GetCPUDescriptorHandleForHeapStart(&ret);
92    return ret;
93 }
94 inline D3D12_GPU_DESCRIPTOR_HANDLE
GetGPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap * heap)95 GetGPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
96 {
97    D3D12_GPU_DESCRIPTOR_HANDLE ret;
98    heap->GetGPUDescriptorHandleForHeapStart(&ret);
99    return ret;
100 }
101 inline D3D12_RESOURCE_DESC
GetDesc(ID3D12Resource * res)102 GetDesc(ID3D12Resource *res)
103 {
104    D3D12_RESOURCE_DESC ret;
105    res->GetDesc(&ret);
106    return ret;
107 }
108 inline D3D12_HEAP_PROPERTIES
GetCustomHeapProperties(ID3D12Device * dev,D3D12_HEAP_TYPE type)109 GetCustomHeapProperties(ID3D12Device *dev, D3D12_HEAP_TYPE type)
110 {
111    D3D12_HEAP_PROPERTIES ret;
112    dev->GetCustomHeapProperties(&ret, 0, type);
113    return ret;
114 }
115 inline LUID
GetAdapterLuid(ID3D12Device * dev)116 GetAdapterLuid(ID3D12Device *dev)
117 {
118    LUID ret;
119    dev->GetAdapterLuid(&ret);
120    return ret;
121 }
122 inline D3D12_VIDEO_PROCESS_OUTPUT_STREAM_DESC
GetOutputStreamDesc(ID3D12VideoProcessor * proc)123 GetOutputStreamDesc(ID3D12VideoProcessor *proc)
124 {
125    D3D12_VIDEO_PROCESS_OUTPUT_STREAM_DESC ret;
126    proc->GetOutputStreamDesc(&ret);
127    return ret;
128 }
129 #endif
130 #endif
131 
132 #endif
133