Add PixelFormat::NV12

This commit is contained in:
Wojtek Figat
2024-05-15 11:14:16 +02:00
parent 3ae30a59b3
commit 9d2dc91920
6 changed files with 18 additions and 2 deletions

View File

@@ -558,6 +558,11 @@ API_ENUM() enum class PixelFormat : uint32
/// </summary> /// </summary>
YUY2 = 108, YUY2 = 108,
/// <summary>
/// Packed YUV 4:2:0 video texture format. Texture uses separate views to access the luma (Y) plane separately from the chroma (UV) planes. For luminance data view, the mapping to the view channel is Y->R8. For chrominance data view, the mapping to the view channel is U->R8 and V->G8.
/// </summary>
NV12 = 109,
/// <summary> /// <summary>
/// The maximum format value (for internal use only). /// The maximum format value (for internal use only).
/// </summary> /// </summary>

View File

@@ -150,6 +150,8 @@ void PixelFormatExtensions::Init()
PixelFormat::BC4_UNorm, PixelFormat::BC4_UNorm,
}; };
InitFormat(formats8, 4); InitFormat(formats8, 4);
sizeOfInBits[(int32)PixelFormat::NV12] = 12;
} }
int32 PixelFormatExtensions::SizeInBits(PixelFormat format) int32 PixelFormatExtensions::SizeInBits(PixelFormat format)
@@ -379,6 +381,7 @@ bool PixelFormatExtensions::IsVideo(const PixelFormat format)
switch (format) switch (format)
{ {
case PixelFormat::YUY2: case PixelFormat::YUY2:
case PixelFormat::NV12:
return true; return true;
default: default:
return false; return false;

View File

@@ -349,6 +349,10 @@ void RenderTools::ComputePitch(PixelFormat format, int32 width, int32 height, ui
rowPitch = ((width + 1) >> 1) * 4; rowPitch = ((width + 1) >> 1) * 4;
slicePitch = rowPitch * height; slicePitch = rowPitch * height;
break; break;
case PixelFormat::NV12:
rowPitch = width;
slicePitch = width * height * 3 / 2;
break;
default: default:
// Default byte alignment // Default byte alignment
rowPitch = (width * PixelFormatExtensions::SizeInBits(format) + 7) / 8; rowPitch = (width * PixelFormatExtensions::SizeInBits(format) + 7) / 8;

View File

@@ -9,7 +9,7 @@
// @formatter:off // @formatter:off
DXGI_FORMAT PixelFormatToDXGIFormat[109] = DXGI_FORMAT PixelFormatToDXGIFormat[110] =
{ {
DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN,
DXGI_FORMAT_R32G32B32A32_TYPELESS, DXGI_FORMAT_R32G32B32A32_TYPELESS,
@@ -120,6 +120,7 @@ DXGI_FORMAT PixelFormatToDXGIFormat[109] =
DXGI_FORMAT_UNKNOWN, // ASTC_10x10_UNorm DXGI_FORMAT_UNKNOWN, // ASTC_10x10_UNorm
DXGI_FORMAT_UNKNOWN, // ASTC_10x10_UNorm_sRGB DXGI_FORMAT_UNKNOWN, // ASTC_10x10_UNorm_sRGB
DXGI_FORMAT_YUY2, DXGI_FORMAT_YUY2,
DXGI_FORMAT_NV12,
}; };
// @formatter:on // @formatter:on

View File

@@ -8,7 +8,7 @@
// @formatter:off // @formatter:off
VkFormat RenderToolsVulkan::PixelFormatToVkFormat[109] = VkFormat RenderToolsVulkan::PixelFormatToVkFormat[110] =
{ {
VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED,
VK_FORMAT_R32G32B32A32_SFLOAT, VK_FORMAT_R32G32B32A32_SFLOAT,
@@ -119,6 +119,7 @@ VkFormat RenderToolsVulkan::PixelFormatToVkFormat[109] =
VK_FORMAT_ASTC_10x10_UNORM_BLOCK, VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
VK_FORMAT_ASTC_10x10_SRGB_BLOCK, VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
VK_FORMAT_G8B8G8R8_422_UNORM, // YUY2 VK_FORMAT_G8B8G8R8_422_UNORM, // YUY2
VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, // NV12
}; };
VkBlendFactor RenderToolsVulkan::BlendToVkBlendFactor[20] = VkBlendFactor RenderToolsVulkan::BlendToVkBlendFactor[20] =

View File

@@ -96,6 +96,8 @@ namespace MF
player.Format = PixelFormat::B5G6R5_UNorm; player.Format = PixelFormat::B5G6R5_UNorm;
else if (subtype == MFVideoFormat_RGB555) else if (subtype == MFVideoFormat_RGB555)
player.Format = PixelFormat::B5G5R5A1_UNorm; player.Format = PixelFormat::B5G5R5A1_UNorm;
else if (subtype == MFVideoFormat_NV12)
player.Format = PixelFormat::NV12;
else if (subtype == MFVideoFormat_YUY2) else if (subtype == MFVideoFormat_YUY2)
player.Format = PixelFormat::YUY2; player.Format = PixelFormat::YUY2;
#if (WDK_NTDDI_VERSION >= NTDDI_WIN10) #if (WDK_NTDDI_VERSION >= NTDDI_WIN10)