Monado OpenXR Runtime
d3d_dxgi_formats.h
Go to the documentation of this file.
1// Copyright 2020-2022, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Format conversion for DXGI/D3D.
6 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
7 * @ingroup aux_d3d
8 */
9
10#pragma once
11
12#include "xrt/xrt_windows.h"
14
15#include <dxgiformat.h>
16
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22static inline DXGI_FORMAT
23d3d_vk_format_to_dxgi(int64_t format)
24{
25 switch (format) {
26 case VK_FORMAT_B8G8R8A8_SRGB: return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
27 case VK_FORMAT_B8G8R8A8_UNORM: return DXGI_FORMAT_B8G8R8A8_UNORM;
28 case VK_FORMAT_D16_UNORM: return DXGI_FORMAT_D16_UNORM;
29 case VK_FORMAT_D24_UNORM_S8_UINT: return DXGI_FORMAT_D24_UNORM_S8_UINT;
30 case VK_FORMAT_D32_SFLOAT_S8_UINT: return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
31 case VK_FORMAT_D32_SFLOAT: return DXGI_FORMAT_D32_FLOAT;
32 // case VK_FORMAT_R16G16B16_SFLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT; /// @todo OK to just add A?
33 // case VK_FORMAT_R16G16B16_UNORM: return DXGI_FORMAT_R16G16B16A16_UNORM; /// @todo OK to just add A?
34 case VK_FORMAT_R16G16B16A16_SFLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT;
35 case VK_FORMAT_R16G16B16A16_UNORM: return DXGI_FORMAT_R16G16B16A16_UNORM;
36 case VK_FORMAT_R8G8B8A8_SRGB: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
37 case VK_FORMAT_R8G8B8A8_UNORM: return DXGI_FORMAT_R8G8B8A8_UNORM; // Should not be used, colour precision.
38 case VK_FORMAT_R32_SFLOAT: return DXGI_FORMAT_R32_FLOAT;
39
40 case VK_FORMAT_X8_D24_UNORM_PACK32: /// @todo DXGI_FORMAT_D24_UNORM_S8_UINT ?
41 return (DXGI_FORMAT)0;
42 case VK_FORMAT_A2B10G10R10_UNORM_PACK32: /// @todo DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM ?
43 return (DXGI_FORMAT)0;
44
45 default: return (DXGI_FORMAT)0;
46 }
47}
48
49static inline DXGI_FORMAT
50d3d_dxgi_format_to_typeless_dxgi(DXGI_FORMAT format)
51{
52 switch (format) {
53 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: //
54 case DXGI_FORMAT_B8G8R8A8_UNORM: //
55 return DXGI_FORMAT_B8G8R8A8_TYPELESS;
56
57 case DXGI_FORMAT_D16_UNORM: //
58 return DXGI_FORMAT_R16_TYPELESS;
59
60 case DXGI_FORMAT_D32_FLOAT: //
61 return DXGI_FORMAT_R32_TYPELESS;
62
63 case DXGI_FORMAT_D24_UNORM_S8_UINT: //
64 return DXGI_FORMAT_R24G8_TYPELESS;
65
66 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: //
67 return DXGI_FORMAT_R32G8X24_TYPELESS;
68
69 case DXGI_FORMAT_R16G16B16A16_FLOAT: //
70 case DXGI_FORMAT_R16G16B16A16_UNORM: //
71 return DXGI_FORMAT_R16G16B16A16_TYPELESS;
72
73 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
74 case DXGI_FORMAT_R8G8B8A8_UNORM: //
75 return DXGI_FORMAT_R8G8B8A8_TYPELESS;
76
77 case DXGI_FORMAT_R32_FLOAT: //
78 return DXGI_FORMAT_R32_TYPELESS;
79
80 default: return format;
81 }
82}
83
84static inline int64_t
85d3d_dxgi_format_to_vk(DXGI_FORMAT format)
86{
87 switch (format) {
88 case DXGI_FORMAT_R8G8B8A8_UNORM: return VK_FORMAT_R8G8B8A8_UNORM; // Should not be used, colour precision.
89 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: return VK_FORMAT_R8G8B8A8_SRGB;
90 case DXGI_FORMAT_B8G8R8A8_UNORM: return VK_FORMAT_B8G8R8A8_UNORM;
91 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: return VK_FORMAT_B8G8R8A8_SRGB;
92 case DXGI_FORMAT_R16G16B16A16_FLOAT: return VK_FORMAT_R16G16B16A16_SFLOAT;
93 case DXGI_FORMAT_R16G16B16A16_UNORM: return VK_FORMAT_R16G16B16A16_UNORM;
94 case DXGI_FORMAT_R16G16B16A16_SNORM: return VK_FORMAT_R16G16B16A16_SNORM;
95 case DXGI_FORMAT_R32_FLOAT: return VK_FORMAT_R32_SFLOAT;
96 case DXGI_FORMAT_D16_UNORM: return VK_FORMAT_D16_UNORM;
97 case DXGI_FORMAT_D32_FLOAT: return VK_FORMAT_D32_SFLOAT;
98 case DXGI_FORMAT_D24_UNORM_S8_UINT: return VK_FORMAT_D24_UNORM_S8_UINT;
99 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return VK_FORMAT_D32_SFLOAT_S8_UINT;
100 default: return 0;
101 }
102}
103
104#ifdef __cplusplus
105}
106#endif
static DXGI_FORMAT d3d_vk_format_to_dxgi(int64_t format)
Definition: d3d_dxgi_formats.h:23
Include all of the Vulkan headers in one place, and cope with any "messy" includes implied by it.
A minimal way to include Windows.h.