Assume positions are already aligned for nvenc

This commit is contained in:
Patrick Nicolas
2024-11-10 15:24:07 +01:00
parent 5d5f4b8af4
commit 6fdac88fd8
2 changed files with 8 additions and 12 deletions
+8 -10
View File
@@ -145,8 +145,8 @@ video_encoder_nvenc::video_encoder_nvenc(
bitrate(settings.bitrate) bitrate(settings.bitrate)
{ {
std::tie(cuda_fn, nvenc_fn, fn, cuda, session_handle) = init(); std::tie(cuda_fn, nvenc_fn, fn, cuda, session_handle) = init();
settings.video_width += 32 - settings.video_width % 32; assert(settings.width % 32 == 0);
settings.video_height += 32 - settings.video_height % 32; assert(settings.height % 32 == 0);
rect = vk::Rect2D{ rect = vk::Rect2D{
.offset = { .offset = {
.x = settings.offset_x, .x = settings.offset_x,
@@ -157,8 +157,6 @@ video_encoder_nvenc::video_encoder_nvenc(
.height = settings.height, .height = settings.height,
}, },
}; };
height = settings.video_height;
width = settings.video_width;
uint32_t count; uint32_t count;
std::vector<GUID> presets; std::vector<GUID> presets;
@@ -251,7 +249,7 @@ video_encoder_nvenc::video_encoder_nvenc(
NVENC_CHECK(fn.nvEncCreateBitstreamBuffer(session_handle, &params3)); NVENC_CHECK(fn.nvEncCreateBitstreamBuffer(session_handle, &params3));
bitstreamBuffer = params3.bitstreamBuffer; bitstreamBuffer = params3.bitstreamBuffer;
vk::DeviceSize buffer_size = width * settings.video_height * 3 / 2; vk::DeviceSize buffer_size = rect.extent.width * settings.video_height * 3 / 2;
vk::StructureChain buffer_create_info{ vk::StructureChain buffer_create_info{
vk::BufferCreateInfo{ vk::BufferCreateInfo{
@@ -313,7 +311,7 @@ video_encoder_nvenc::video_encoder_nvenc(
.resourceType = NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR, .resourceType = NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR,
.width = settings.video_width, .width = settings.video_width,
.height = settings.video_height, .height = settings.video_height,
.pitch = width, .pitch = rect.extent.width,
.resourceToRegister = (void *)frame, .resourceToRegister = (void *)frame,
.bufferFormat = NV_ENC_BUFFER_FORMAT_NV12, .bufferFormat = NV_ENC_BUFFER_FORMAT_NV12,
.bufferUsage = NV_ENC_INPUT_IMAGE, .bufferUsage = NV_ENC_INPUT_IMAGE,
@@ -337,7 +335,7 @@ void video_encoder_nvenc::present_image(vk::Image y_cbcr, vk::raii::CommandBuffe
vk::ImageLayout::eTransferSrcOptimal, vk::ImageLayout::eTransferSrcOptimal,
*in[slot].yuv, *in[slot].yuv,
vk::BufferImageCopy{ vk::BufferImageCopy{
.bufferRowLength = width, .bufferRowLength = rect.extent.width,
.imageSubresource = { .imageSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane0, .aspectMask = vk::ImageAspectFlagBits::ePlane0,
.baseArrayLayer = uint32_t(channels), .baseArrayLayer = uint32_t(channels),
@@ -357,8 +355,8 @@ void video_encoder_nvenc::present_image(vk::Image y_cbcr, vk::raii::CommandBuffe
vk::ImageLayout::eTransferSrcOptimal, vk::ImageLayout::eTransferSrcOptimal,
*in[slot].yuv, *in[slot].yuv,
vk::BufferImageCopy{ vk::BufferImageCopy{
.bufferOffset = width * height, .bufferOffset = rect.extent.width * rect.extent.height,
.bufferRowLength = uint32_t(width / 2), .bufferRowLength = uint32_t(rect.extent.width / 2),
.imageSubresource = { .imageSubresource = {
.aspectMask = vk::ImageAspectFlagBits::ePlane1, .aspectMask = vk::ImageAspectFlagBits::ePlane1,
.baseArrayLayer = uint32_t(channels), .baseArrayLayer = uint32_t(channels),
@@ -388,7 +386,7 @@ std::optional<video_encoder::data> video_encoder_nvenc::encode(bool idr, std::ch
.version = NV_ENC_PIC_PARAMS_VER, .version = NV_ENC_PIC_PARAMS_VER,
.inputWidth = rect.extent.width, .inputWidth = rect.extent.width,
.inputHeight = rect.extent.height, .inputHeight = rect.extent.height,
.inputPitch = width, .inputPitch = rect.extent.width,
.encodePicFlags = uint32_t(idr ? NV_ENC_PIC_FLAG_FORCEIDR | NV_ENC_PIC_FLAG_OUTPUT_SPSPPS : 0), .encodePicFlags = uint32_t(idr ? NV_ENC_PIC_FLAG_FORCEIDR | NV_ENC_PIC_FLAG_OUTPUT_SPSPPS : 0),
.frameIdx = 0, .frameIdx = 0,
.inputTimeStamp = 0, .inputTimeStamp = 0,
-2
View File
@@ -58,8 +58,6 @@ private:
}; };
std::array<in_t, num_slots> in; std::array<in_t, num_slots> in;
uint32_t width;
uint32_t height;
float fps; float fps;
int bitrate; int bitrate;