diff --git a/src/gallium/drivers/d3d12/d3d12_format.c b/src/gallium/drivers/d3d12/d3d12_format.c index 5431dd01484..6efbc6c6a73 100644 --- a/src/gallium/drivers/d3d12/d3d12_format.c +++ b/src/gallium/drivers/d3d12/d3d12_format.c @@ -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; + } + } + } +} diff --git a/src/gallium/drivers/d3d12/d3d12_format.h b/src/gallium/drivers/d3d12/d3d12_format.h index e854120d301..ef5a1721d9e 100644 --- a/src/gallium/drivers/d3d12/d3d12_format.h +++ b/src/gallium/drivers/d3d12/d3d12_format.h @@ -25,9 +25,14 @@ #define D3D12_FORMATS_H #include +#ifndef _WIN32 +#include +#endif +#include #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