Sunshine latest
Self-hosted game stream host for Moonlight.
cuda.cpp File Reference

Definitions for CUDA encoding. More...

#include <bitset>
#include <fcntl.h>
#include <filesystem>
#include <thread>
#include <ffnvcodec/dynlink_loader.h>
#include <NvFBC.h>
#include <libavcodec/avcodec.h>
#include <libavutil/hwcontext_cuda.h>
#include <libavutil/imgutils.h>
#include "cuda.h"
#include "graphics.h"
#include "src/logging.h"
#include "src/utility.h"
#include "src/video.h"
#include "wayland.h"
Include dependency graph for cuda.cpp:

Classes

class  cuda::nvfbc::ctx_t
 
class  cuda::cuda_ram_t
 
class  cuda::cuda_t
 
class  cuda::cuda_vram_t
 
class  cuda::nvfbc::display_t
 
class  cuda::gl_cuda_vram_t
 
class  cuda::nvfbc::handle_t
 
class  cuda::img_t
 

Macros

#define CU_CHECK(x, y)
 
#define CU_CHECK_IGNORE(x, y)    check((x), SUNSHINE_STRINGVIEW(y ": "))
 
#define SUNSHINE_STRINGVIEW(x)   SUNSHINE_STRINGVIEW_HELPER(x)
 
#define SUNSHINE_STRINGVIEW_HELPER(x)   x##sv
 

Typedefs

using cuda::cdf_t = util::safe_ptr<CudaFunctions, cff>
 
using cuda::registered_resource_t = util::safe_ptr<CUgraphicsResource_st, unregisterResource>
 

Functions

void cuda::cff (CudaFunctions *cf)
 
void cuda::freeStream (CUstream stream)
 
int cuda::init ()
 
int cuda::nvfbc::init ()
 
std::unique_ptr< platf::avcodec_encode_device_tcuda::make_avcodec_encode_device (int width, int height, bool vram)
 
std::unique_ptr< platf::avcodec_encode_device_tcuda::make_avcodec_gl_encode_device (int width, int height, int offset_x, int offset_y)
 Create a GL->CUDA encoding device for consuming captured dmabufs.
 
std::shared_ptr< display_tplatf::nvfbc_display (mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config)
 
std::vector< std::string > platf::nvfbc_display_names ()
 
file_t cuda::open_drm_fd_for_cuda_device (int index)
 Opens the DRM device associated with the CUDA device index.
 
void cuda::pass_error (const std::string_view &sv, const char *name, const char *description)
 
void cuda::unregisterResource (CUgraphicsResource resource)
 

Variables

constexpr auto cuda::cudaDevAttrMaxThreadsPerBlock = (CUdevice_attribute) 1
 
constexpr auto cuda::cudaDevAttrMaxThreadsPerMultiProcessor = (CUdevice_attribute) 39
 

Detailed Description

Definitions for CUDA encoding.

Macro Definition Documentation

◆ CU_CHECK

#define CU_CHECK ( x,
y )
Value:
if (check((x), SUNSHINE_STRINGVIEW(y ": "))) \
return -1

Function Documentation

◆ make_avcodec_gl_encode_device()

std::unique_ptr< platf::avcodec_encode_device_t > cuda::make_avcodec_gl_encode_device ( int width,
int height,
int offset_x,
int offset_y )

Create a GL->CUDA encoding device for consuming captured dmabufs.

Parameters
widthWidth of captured frames.
heightHeight of captured frames.
offset_xOffset of content in captured frame.
offset_yOffset of content in captured frame.
Returns
FFmpeg encoding device context.

◆ open_drm_fd_for_cuda_device()

file_t cuda::open_drm_fd_for_cuda_device ( int index)

Opens the DRM device associated with the CUDA device index.

Parameters
indexCUDA device index to open.
Returns
File descriptor or -1 on failure.