Optimize CUDA GL interop and provide fallback

This commit is contained in:
Cameron Gutman
2021-12-13 21:41:00 -06:00
parent c4d85cf928
commit 36e0468a99
4 changed files with 168 additions and 62 deletions
+24 -3
View File
@@ -2,6 +2,12 @@
#include "renderer.h"
#include <ffnvcodec/dynlink_loader.h>
extern "C" {
#include <libavutil/hwcontext_cuda.h>
}
class CUDARenderer : public IFFmpegRenderer {
public:
CUDARenderer();
@@ -12,10 +18,25 @@ public:
virtual bool needsTestFrame() override;
virtual bool isDirectRenderingSupported() override;
// Helper function used by SDLRenderer to read our CUDA frame
static bool copyCudaFrameToBoundTexture(AVFrame* frame);
private:
AVBufferRef* m_HwContext;
};
#define NV12_PLANES 2
// Helper class used by SDLRenderer to read our CUDA frame
class CUDAGLInteropHelper {
public:
CUDAGLInteropHelper(AVHWDeviceContext* context);
~CUDAGLInteropHelper();
bool registerBoundTextures();
void unregisterTextures();
bool copyCudaFrameToTextures(AVFrame* frame);
private:
CudaFunctions* m_Funcs;
AVCUDADeviceContext* m_Context;
CUgraphicsResource m_Resources[NV12_PLANES];
};