d3d12: Add util video functions to d3d12_format

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16286>
This commit is contained in:
Sil Vilerino 2022-05-02 10:10:45 -07:00 committed by Marge Bot
parent 68bac42338
commit 6dbe05ffda
2 changed files with 62 additions and 0 deletions

View File

@ -24,6 +24,7 @@
#include "d3d12_format.h"
#include "pipe/p_format.h"
#include "pipe/p_video_enums.h"
#include "util/format/u_format.h"
#include "util/u_math.h"
#include "util/compiler.h"
@ -435,3 +436,53 @@ d3d12_get_format_num_planes(enum pipe_format fmt)
return util_format_is_depth_or_stencil(fmt) ?
util_bitcount(util_format_get_mask(fmt)) : 1;
}
DXGI_FORMAT
d3d12_convert_pipe_video_profile_to_dxgi_format(enum pipe_video_profile profile)
{
switch (profile) {
case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
case PIPE_VIDEO_PROFILE_MPEG4_AVC_CONSTRAINED_BASELINE:
case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN:
case PIPE_VIDEO_PROFILE_MPEG4_AVC_EXTENDED:
case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
return DXGI_FORMAT_NV12;
case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH10:
return DXGI_FORMAT_P010;
default:
{
unreachable("Unsupported pipe video profile");
} break;
}
}
DXGI_COLOR_SPACE_TYPE
d3d12_convert_from_legacy_color_space(bool rgb, uint32_t bits_per_element, bool studio_rgb, bool p709, bool studio_yuv)
{
if (rgb) {
if (bits_per_element > 32) {
// All 16 bit color channel data is assumed to be linear rather than SRGB
return DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709;
} else {
if (studio_rgb) {
return DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709;
} else {
return DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709;
}
}
} else {
if (p709) {
if (studio_yuv) {
return DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709;
} else {
return DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P709;
}
} else {
if (studio_yuv) {
return DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601;
} else {
return DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P601;
}
}
}
}

View File

@ -25,9 +25,14 @@
#define D3D12_FORMATS_H
#include <directx/dxgiformat.h>
#ifndef _WIN32
#include <wsl/winadapter.h>
#endif
#include <directx/dxgicommon.h>
#include "pipe/p_format.h"
#include "pipe/p_defines.h"
#include "pipe/p_video_enums.h"
#ifdef __cplusplus
extern "C" {
@ -72,6 +77,12 @@ d3d12_get_format_start_plane(enum pipe_format fmt);
unsigned
d3d12_get_format_num_planes(enum pipe_format fmt);
DXGI_FORMAT
d3d12_convert_pipe_video_profile_to_dxgi_format(enum pipe_video_profile profile);
DXGI_COLOR_SPACE_TYPE
d3d12_convert_from_legacy_color_space(bool rgb, uint32_t bits_per_element, bool studio_rgb, bool p709, bool studio_yuv);
#ifdef __cplusplus
}
#endif