d3d12: Add util video functions to d3d12_format
authorSil Vilerino <sivileri@microsoft.com>
Mon, 2 May 2022 17:10:45 +0000 (10:10 -0700)
committerMarge Bot <emma+marge@anholt.net>
Tue, 17 May 2022 21:02:25 +0000 (21:02 +0000)
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16286>

src/gallium/drivers/d3d12/d3d12_format.c
src/gallium/drivers/d3d12/d3d12_format.h

index 5431dd0..6efbc6c 100644 (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;
+         }
+      }
+   }
+}
index e854120..ef5a172 100644 (file)
 #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