2022-05-02 21:48:23 +00:00
|
|
|
// Copyright 2020-2022, Collabora, Ltd.
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief Format conversion for DXGI/D3D.
|
|
|
|
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
|
|
|
|
* @ingroup aux_d3d
|
|
|
|
*/
|
|
|
|
|
2022-05-22 11:02:47 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-05-02 21:48:23 +00:00
|
|
|
#include "xrt/xrt_windows.h"
|
|
|
|
#include "xrt/xrt_vulkan_includes.h"
|
|
|
|
|
|
|
|
#include <dxgiformat.h>
|
|
|
|
|
2022-05-22 11:02:47 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-05-02 21:48:23 +00:00
|
|
|
static inline DXGI_FORMAT
|
|
|
|
d3d_vk_format_to_dxgi(int64_t format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case VK_FORMAT_B8G8R8A8_SRGB: return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
|
|
|
|
case VK_FORMAT_B8G8R8A8_UNORM: return DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
case VK_FORMAT_D16_UNORM: return DXGI_FORMAT_D16_UNORM;
|
2022-07-13 18:24:09 +00:00
|
|
|
case VK_FORMAT_D24_UNORM_S8_UINT: return DXGI_FORMAT_D24_UNORM_S8_UINT;
|
|
|
|
case VK_FORMAT_D32_SFLOAT_S8_UINT: return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
|
2022-05-02 21:48:23 +00:00
|
|
|
case VK_FORMAT_D32_SFLOAT: return DXGI_FORMAT_D32_FLOAT;
|
2022-05-23 21:08:32 +00:00
|
|
|
// case VK_FORMAT_R16G16B16_SFLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT; /// @todo OK to just add A?
|
|
|
|
// case VK_FORMAT_R16G16B16_UNORM: return DXGI_FORMAT_R16G16B16A16_UNORM; /// @todo OK to just add A?
|
2022-07-13 18:24:09 +00:00
|
|
|
case VK_FORMAT_R16G16B16A16_SFLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT;
|
2022-05-02 21:48:23 +00:00
|
|
|
case VK_FORMAT_R16G16B16A16_UNORM: return DXGI_FORMAT_R16G16B16A16_UNORM;
|
|
|
|
case VK_FORMAT_R8G8B8A8_SRGB: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
|
|
|
|
case VK_FORMAT_R8G8B8A8_UNORM: return DXGI_FORMAT_R8G8B8A8_UNORM; // Should not be used, colour precision.
|
2022-09-16 18:27:15 +00:00
|
|
|
case VK_FORMAT_R32_SFLOAT: return DXGI_FORMAT_R32_FLOAT;
|
2022-05-02 21:48:23 +00:00
|
|
|
|
|
|
|
case VK_FORMAT_X8_D24_UNORM_PACK32: /// @todo DXGI_FORMAT_D24_UNORM_S8_UINT ?
|
|
|
|
return (DXGI_FORMAT)0;
|
|
|
|
case VK_FORMAT_A2B10G10R10_UNORM_PACK32: /// @todo DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM ?
|
|
|
|
return (DXGI_FORMAT)0;
|
|
|
|
|
|
|
|
default: return (DXGI_FORMAT)0;
|
|
|
|
}
|
|
|
|
}
|
2022-05-22 11:02:47 +00:00
|
|
|
|
2022-05-02 21:48:23 +00:00
|
|
|
static inline DXGI_FORMAT
|
|
|
|
d3d_dxgi_format_to_typeless_dxgi(DXGI_FORMAT format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
2022-07-13 18:24:09 +00:00
|
|
|
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: //
|
|
|
|
case DXGI_FORMAT_B8G8R8A8_UNORM: //
|
|
|
|
return DXGI_FORMAT_B8G8R8A8_TYPELESS;
|
|
|
|
|
|
|
|
case DXGI_FORMAT_D16_UNORM: //
|
|
|
|
return DXGI_FORMAT_R16_TYPELESS;
|
|
|
|
|
|
|
|
case DXGI_FORMAT_D32_FLOAT: //
|
|
|
|
return DXGI_FORMAT_R32_TYPELESS;
|
|
|
|
|
|
|
|
case DXGI_FORMAT_D24_UNORM_S8_UINT: //
|
|
|
|
return DXGI_FORMAT_R24G8_TYPELESS;
|
|
|
|
|
|
|
|
case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: //
|
|
|
|
return DXGI_FORMAT_R32G8X24_TYPELESS;
|
|
|
|
|
|
|
|
case DXGI_FORMAT_R16G16B16A16_FLOAT: //
|
|
|
|
case DXGI_FORMAT_R16G16B16A16_UNORM: //
|
|
|
|
return DXGI_FORMAT_R16G16B16A16_TYPELESS;
|
|
|
|
|
|
|
|
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
|
|
|
|
case DXGI_FORMAT_R8G8B8A8_UNORM: //
|
|
|
|
return DXGI_FORMAT_R8G8B8A8_TYPELESS;
|
|
|
|
|
2022-09-16 18:27:15 +00:00
|
|
|
case DXGI_FORMAT_R32_FLOAT: //
|
|
|
|
return DXGI_FORMAT_R32_TYPELESS;
|
|
|
|
|
2022-05-02 21:48:23 +00:00
|
|
|
default: return format;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int64_t
|
|
|
|
d3d_dxgi_format_to_vk(DXGI_FORMAT format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case DXGI_FORMAT_R8G8B8A8_UNORM: return VK_FORMAT_R8G8B8A8_UNORM; // Should not be used, colour precision.
|
|
|
|
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: return VK_FORMAT_R8G8B8A8_SRGB;
|
|
|
|
case DXGI_FORMAT_B8G8R8A8_UNORM: return VK_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: return VK_FORMAT_B8G8R8A8_SRGB;
|
2022-07-13 18:24:09 +00:00
|
|
|
case DXGI_FORMAT_R16G16B16A16_FLOAT: return VK_FORMAT_R16G16B16A16_SFLOAT;
|
2022-05-02 21:48:23 +00:00
|
|
|
case DXGI_FORMAT_R16G16B16A16_UNORM: return VK_FORMAT_R16G16B16A16_UNORM;
|
2022-07-13 18:24:09 +00:00
|
|
|
case DXGI_FORMAT_R16G16B16A16_SNORM: return VK_FORMAT_R16G16B16A16_SNORM;
|
2022-09-16 18:27:15 +00:00
|
|
|
case DXGI_FORMAT_R32_FLOAT: return VK_FORMAT_R32_SFLOAT;
|
2022-05-02 21:48:23 +00:00
|
|
|
case DXGI_FORMAT_D16_UNORM: return VK_FORMAT_D16_UNORM;
|
|
|
|
case DXGI_FORMAT_D32_FLOAT: return VK_FORMAT_D32_SFLOAT;
|
|
|
|
case DXGI_FORMAT_D24_UNORM_S8_UINT: return VK_FORMAT_D24_UNORM_S8_UINT;
|
|
|
|
case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return VK_FORMAT_D32_SFLOAT_S8_UINT;
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-22 11:02:47 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|