Always do yuv conversion in vulkan

This commit is contained in:
Patrick Nicolas
2024-02-18 16:15:55 +01:00
parent 4d99392ced
commit e385e459ee
28 changed files with 1663 additions and 1502 deletions
+14 -26
View File
@@ -1,7 +1,7 @@
/*
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
* Copyright (C) 2022-2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022-2024 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,51 +22,39 @@
#include "nvEncodeAPI.h"
#include "video_encoder.h"
#include <cuda.h>
#include <vulkan/vulkan_raii.hpp>
namespace xrt::drivers::wivrn
{
class VideoEncoderNvenc : public VideoEncoder
{
vk_bundle * vk;
wivrn_vk_bundle& vk;
// relevant part of the input image to encode
int offset_x;
int offset_y;
int width;
int height;
vk::Rect2D rect;
NV_ENCODE_API_FUNCTION_LIST fn;
CUcontext cuda;
void * session_handle;
NV_ENC_OUTPUT_PTR bitstreamBuffer;
struct image_data
{
CUmipmappedArray cuda_image;
CUarray cuda_array;
};
std::vector<image_data> images;
vk::raii::Buffer yuv_buffer = nullptr;
vk::raii::DeviceMemory mem = nullptr;
CUexternalMemory extmem;
vk::Image luma;
vk::Image chroma;
CUdeviceptr frame;
size_t pitch;
NV_ENC_REGISTERED_PTR nvenc_resource;
video_codec codec;
float fps;
int bitrate;
bool supports_frame_invalidation;
public:
VideoEncoderNvenc(vk_bundle * vk, const encoder_settings & settings, float fps);
VideoEncoderNvenc(wivrn_vk_bundle& vk, const encoder_settings & settings, float fps);
void SetImages(int width,
int height,
VkFormat format,
int num_images,
VkImage * images,
VkImageView * views,
VkDeviceMemory * memory) override;
void Encode(int index, bool idr, std::chrono::steady_clock::time_point pts) override;
void PresentImage(yuv_converter & src_yuv, vk::raii::CommandBuffer & cmd_buf) override;
void Encode( bool idr, std::chrono::steady_clock::time_point pts) override;
};
} // namespace xrt::drivers::wivrn