Sunshine master
Self-hosted game stream host for Moonlight.
vulkan_encode.cpp File Reference

Vulkan-native encoder: DMA-BUF -> Vulkan compute (RGB->YUV) -> Vulkan Video encode. No EGL/GL dependency — all GPU work stays in a single Vulkan queue. More...

#include <algorithm>
#include <array>
#include <cstdint>
#include <drm_fourcc.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <vector>
#include <vulkan/vulkan.h>
#include <libavcodec/avcodec.h>
#include <libavutil/hwcontext.h>
#include <libavutil/hwcontext_vulkan.h>
#include "graphics.h"
#include "src/config.h"
#include "src/logging.h"
#include "src/video_colorspace.h"
#include "vulkan_encode.h"
#include "shaders/rgb2yuv.spv.inc"
Include dependency graph for vulkan_encode.cpp:

Classes

struct  vk::PushConstants
 
class  vk::vk_vram_t
 

Macros

#define VK_CHECK(expr)
 
#define VK_CHECK_BOOL(expr)
 

Functions

std::unique_ptr< platf::avcodec_encode_device_tvk::make_avcodec_encode_device_ram (int width, int height)
 Create a Vulkan encode device for RAM capture.
 
std::unique_ptr< platf::avcodec_encode_device_tvk::make_avcodec_encode_device_vram (int width, int height, int offset_x, int offset_y)
 Create a Vulkan encode device for VRAM capture.
 
bool vk::validate ()
 Check if FFmpeg Vulkan Video encoding is available.
 
int vk::vulkan_init_avcodec_hardware_input_buffer (platf::avcodec_encode_device_t *encode_device, AVBufferRef **hw_device_buf)
 Initialize Vulkan hardware device for FFmpeg encoding.
 

Detailed Description

Vulkan-native encoder: DMA-BUF -> Vulkan compute (RGB->YUV) -> Vulkan Video encode. No EGL/GL dependency — all GPU work stays in a single Vulkan queue.

Macro Definition Documentation

◆ VK_CHECK

#define VK_CHECK ( expr)
Value:
do { \
VkResult _r = (expr); \
if (_r != VK_SUCCESS) { \
BOOST_LOG(error) << #expr << " failed: " << _r; \
return -1; \
} \
} while (0)

◆ VK_CHECK_BOOL

#define VK_CHECK_BOOL ( expr)
Value:
do { \
VkResult _r = (expr); \
if (_r != VK_SUCCESS) { \
BOOST_LOG(error) << #expr << " failed: " << _r; \
return false; \
} \
} while (0)

Function Documentation

◆ vulkan_init_avcodec_hardware_input_buffer()

int vk::vulkan_init_avcodec_hardware_input_buffer ( platf::avcodec_encode_device_t * encode_device,
AVBufferRef ** hw_device_buf )

Initialize Vulkan hardware device for FFmpeg encoding.

Parameters
encode_deviceThe encode device (vk_t).
hw_device_bufOutput hardware device buffer.
Returns
0 on success, negative on error.