1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © Yonggang Luo
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#ifndef D3D12_COMMON_STATE_H
25bf215546Sopenharmony_ci#define D3D12_COMMON_STATE_H
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#pragma once
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#ifndef _WIN32
30bf215546Sopenharmony_ci#include <wsl/winadapter.h>
31bf215546Sopenharmony_ci#else
32bf215546Sopenharmony_ci#include <unknwn.h>
33bf215546Sopenharmony_ci#endif
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#define D3D12_IGNORE_SDK_LAYERS
36bf215546Sopenharmony_ci#include <directx/d3d12.h>
37bf215546Sopenharmony_ci#include <directx/d3d12video.h>
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci#if defined(__cplusplus)
40bf215546Sopenharmony_ci#if !defined(_WIN32) || defined(_MSC_VER) || D3D12_SDK_VERSION < 606
41bf215546Sopenharmony_ciinline D3D12_CPU_DESCRIPTOR_HANDLE
42bf215546Sopenharmony_ciGetCPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
43bf215546Sopenharmony_ci{
44bf215546Sopenharmony_ci   return heap->GetCPUDescriptorHandleForHeapStart();
45bf215546Sopenharmony_ci}
46bf215546Sopenharmony_ciinline D3D12_GPU_DESCRIPTOR_HANDLE
47bf215546Sopenharmony_ciGetGPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
48bf215546Sopenharmony_ci{
49bf215546Sopenharmony_ci   return heap->GetGPUDescriptorHandleForHeapStart();
50bf215546Sopenharmony_ci}
51bf215546Sopenharmony_ciinline D3D12_RESOURCE_DESC
52bf215546Sopenharmony_ciGetDesc(ID3D12Resource *res)
53bf215546Sopenharmony_ci{
54bf215546Sopenharmony_ci   return res->GetDesc();
55bf215546Sopenharmony_ci}
56bf215546Sopenharmony_ciinline D3D12_HEAP_PROPERTIES
57bf215546Sopenharmony_ciGetCustomHeapProperties(ID3D12Device *dev, D3D12_HEAP_TYPE type)
58bf215546Sopenharmony_ci{
59bf215546Sopenharmony_ci   return dev->GetCustomHeapProperties(0, type);
60bf215546Sopenharmony_ci}
61bf215546Sopenharmony_ciinline LUID
62bf215546Sopenharmony_ciGetAdapterLuid(ID3D12Device *dev)
63bf215546Sopenharmony_ci{
64bf215546Sopenharmony_ci   return dev->GetAdapterLuid();
65bf215546Sopenharmony_ci}
66bf215546Sopenharmony_ciinline D3D12_VIDEO_PROCESS_OUTPUT_STREAM_DESC
67bf215546Sopenharmony_ciGetOutputStreamDesc(ID3D12VideoProcessor *proc)
68bf215546Sopenharmony_ci{
69bf215546Sopenharmony_ci   return proc->GetOutputStreamDesc();
70bf215546Sopenharmony_ci}
71bf215546Sopenharmony_ci#else
72bf215546Sopenharmony_ciinline D3D12_CPU_DESCRIPTOR_HANDLE
73bf215546Sopenharmony_ciGetCPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
74bf215546Sopenharmony_ci{
75bf215546Sopenharmony_ci   D3D12_CPU_DESCRIPTOR_HANDLE ret;
76bf215546Sopenharmony_ci   heap->GetCPUDescriptorHandleForHeapStart(&ret);
77bf215546Sopenharmony_ci   return ret;
78bf215546Sopenharmony_ci}
79bf215546Sopenharmony_ciinline D3D12_GPU_DESCRIPTOR_HANDLE
80bf215546Sopenharmony_ciGetGPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
81bf215546Sopenharmony_ci{
82bf215546Sopenharmony_ci   D3D12_GPU_DESCRIPTOR_HANDLE ret;
83bf215546Sopenharmony_ci   heap->GetGPUDescriptorHandleForHeapStart(&ret);
84bf215546Sopenharmony_ci   return ret;
85bf215546Sopenharmony_ci}
86bf215546Sopenharmony_ciinline D3D12_RESOURCE_DESC
87bf215546Sopenharmony_ciGetDesc(ID3D12Resource *res)
88bf215546Sopenharmony_ci{
89bf215546Sopenharmony_ci   D3D12_RESOURCE_DESC ret;
90bf215546Sopenharmony_ci   res->GetDesc(&ret);
91bf215546Sopenharmony_ci   return ret;
92bf215546Sopenharmony_ci}
93bf215546Sopenharmony_ciinline D3D12_HEAP_PROPERTIES
94bf215546Sopenharmony_ciGetCustomHeapProperties(ID3D12Device *dev, D3D12_HEAP_TYPE type)
95bf215546Sopenharmony_ci{
96bf215546Sopenharmony_ci   D3D12_HEAP_PROPERTIES ret;
97bf215546Sopenharmony_ci   dev->GetCustomHeapProperties(&ret, 0, type);
98bf215546Sopenharmony_ci   return ret;
99bf215546Sopenharmony_ci}
100bf215546Sopenharmony_ciinline LUID
101bf215546Sopenharmony_ciGetAdapterLuid(ID3D12Device *dev)
102bf215546Sopenharmony_ci{
103bf215546Sopenharmony_ci   LUID ret;
104bf215546Sopenharmony_ci   dev->GetAdapterLuid(&ret);
105bf215546Sopenharmony_ci   return ret;
106bf215546Sopenharmony_ci}
107bf215546Sopenharmony_ciinline D3D12_VIDEO_PROCESS_OUTPUT_STREAM_DESC
108bf215546Sopenharmony_ciGetOutputStreamDesc(ID3D12VideoProcessor *proc)
109bf215546Sopenharmony_ci{
110bf215546Sopenharmony_ci   D3D12_VIDEO_PROCESS_OUTPUT_STREAM_DESC ret;
111bf215546Sopenharmony_ci   proc->GetOutputStreamDesc(&ret);
112bf215546Sopenharmony_ci   return ret;
113bf215546Sopenharmony_ci}
114bf215546Sopenharmony_ci#endif
115bf215546Sopenharmony_ci#endif
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_ci#endif
118