Skip to content

Commit 5bbfaab

Browse files
committed
encoder: add 10/12-bit packed YCbCr format support
- Add R10X6 and R12X4 single-channel packed formats to image view creation - Extend vkFormatInfo table with 10/12-bit packed formats: R10X6/R12X4 (1-ch), R10X6G10X6/R12X4G12X4 (2-ch), and 4-channel variants - Replace local getFormatTexelSize() with vkFormatLookUp() for texel size - Add VulkanAqProcessor.h include guarded with NV_AQ_GPU_LIB_SUPPORTED Signed-off-by: Tony Zlatinski <[email protected]>
1 parent 95db26b commit 5bbfaab

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

common/libs/VkCodecUtils/VkImageResource.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ VkResult VkImageResourceView::Create(const VulkanDeviceContext* vkDevCtx,
249249
switch(viewInfo.format) {
250250
case VK_FORMAT_R8_UNORM:
251251
case VK_FORMAT_R16_UNORM:
252+
case VK_FORMAT_R10X6_UNORM_PACK16:
253+
case VK_FORMAT_R12X4_UNORM_PACK16:
252254
case VK_FORMAT_R8G8_UNORM:
253255
case VK_FORMAT_R16G16_UNORM:
254256
case VK_FORMAT_R32_UINT:

common/libs/VkCodecUtils/nvVkFormats.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@ const VkFormatDesc vkFormatInfo[] = {
3232
{ VK_FORMAT_R32_SFLOAT, 1, 4, "r32f", },
3333
{ VK_FORMAT_R16_SFLOAT, 1, 2, "r16f", },
3434
{ VK_FORMAT_R16G16B16A16_UNORM, 4, 8, "rgba16", },
35+
{ VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16,4,8, "rgba16", },
36+
{ VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16,4,8, "rgba16", },
3537
{ VK_FORMAT_A2B10G10R10_UNORM_PACK32, 4, 4, "rgb10_a2", },
3638
{ VK_FORMAT_R16G16_UNORM, 2, 4, "rg16", },
39+
{ VK_FORMAT_R10X6G10X6_UNORM_2PACK16, 2, 4, "rg16", },
40+
{ VK_FORMAT_R12X4G12X4_UNORM_2PACK16, 2, 4, "rg16", },
3741
{ VK_FORMAT_R16_UNORM, 1, 2, "r16", },
42+
{ VK_FORMAT_R10X6_UNORM_PACK16, 1, 2, "r16", },
43+
{ VK_FORMAT_R12X4_UNORM_PACK16, 1, 2, "r16", },
3844
{ VK_FORMAT_R16G16B16A16_SNORM, 4, 8, "rgba16_snorm", },
3945
{ VK_FORMAT_R8G8B8A8_SNORM, 4, 4, "rgba8_snorm", },
4046
{ VK_FORMAT_R16G16_SNORM, 2, 4, "rg16_snorm", },

vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoder.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,9 @@
2424
#include "VkVideoEncoder/VkEncoderConfigH265.h"
2525
#include "VkVideoEncoder/VkEncoderConfigAV1.h"
2626
#include "VkCodecUtils/YCbCrConvUtilsCpu.h"
27-
28-
static size_t getFormatTexelSize(VkFormat format)
29-
{
30-
switch (format) {
31-
case VK_FORMAT_R8_UINT:
32-
case VK_FORMAT_R8_SINT:
33-
case VK_FORMAT_R8_UNORM:
34-
return 1;
35-
case VK_FORMAT_R16_UINT:
36-
case VK_FORMAT_R16_SINT:
37-
return 2;
38-
case VK_FORMAT_R32_UINT:
39-
case VK_FORMAT_R32_SINT:
40-
return 4;
41-
default:
42-
assert(!"unknown format");
43-
return 0;
44-
}
45-
}
27+
#ifdef NV_AQ_GPU_LIB_SUPPORTED
28+
#include "VulkanAqProcessor.h"
29+
#endif // NV_AQ_GPU_LIB_SUPPORTED
4630

4731
VkResult VkVideoEncoder::CreateVideoEncoder(const VulkanDeviceContext* vkDevCtx,
4832
VkSharedBaseObj<EncoderConfig>& encoderConfig,
@@ -101,18 +85,19 @@ VkResult VkVideoEncoder::LoadNextQpMapFrameFromFile(VkSharedBaseObj<VkVideoEncod
10185
uint8_t* writeQpMapImagePtr = srcQpMapImageDeviceMemory->GetDataPtr(qpMapImageOffset, qpMapMaxSize);
10286
assert(writeQpMapImagePtr != nullptr);
10387

104-
size_t formatSize = getFormatTexelSize(m_imageQpMapFormat);
88+
const VkFormatDesc* pFormatDesc = vkFormatLookUp(m_imageQpMapFormat);
89+
size_t formatTexelSize = (pFormatDesc != nullptr) ? pFormatDesc->numberOfBytes : 1;
10590
uint32_t inputQpMapWidth = (m_encoderConfig->input.width + m_qpMapTexelSize.width - 1) / m_qpMapTexelSize.width;
10691
uint32_t qpMapWidth = (m_encoderConfig->encodeWidth + m_qpMapTexelSize.width - 1) / m_qpMapTexelSize.width;
10792
uint32_t qpMapHeight = (m_encoderConfig->encodeHeight + m_qpMapTexelSize.height - 1) / m_qpMapTexelSize.height;
108-
uint64_t qpMapFileOffset = qpMapWidth * qpMapHeight * encodeFrameInfo->frameInputOrderNum * formatSize;
93+
uint64_t qpMapFileOffset = qpMapWidth * qpMapHeight * encodeFrameInfo->frameInputOrderNum * formatTexelSize;
10994
const uint8_t* pQpMapData = m_encoderConfig->qpMapFileHandler.GetMappedPtr(qpMapFileOffset);
11095

11196
const VkSubresourceLayout* dstQpMapSubresourceLayout = dstQpMapImageResource->GetSubresourceLayout();
11297

11398
for (uint32_t j = 0; j < qpMapHeight; j++) {
11499
memcpy(writeQpMapImagePtr + (dstQpMapSubresourceLayout[0].offset + j * dstQpMapSubresourceLayout[0].rowPitch),
115-
pQpMapData + j * inputQpMapWidth * formatSize, qpMapWidth * formatSize);
100+
pQpMapData + j * inputQpMapWidth * formatTexelSize, qpMapWidth * formatTexelSize);
116101
}
117102
}
118103

0 commit comments

Comments
 (0)