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

Definitions for handling video ram. More...

#include <cmath>
#include <d3dcompiler.h>
#include <DirectXMath.h>
#include <libavcodec/avcodec.h>
#include <libavutil/hwcontext_d3d11va.h>
#include <AMF/core/Factory.h>
#include <boost/algorithm/string/predicate.hpp>
#include "display.h"
#include "misc.h"
#include "src/config.h"
#include "src/logging.h"
#include "src/nvenc/nvenc_config.h"
#include "src/nvenc/nvenc_d3d11_native.h"
#include "src/nvenc/nvenc_d3d11_on_cuda.h"
#include "src/nvenc/nvenc_utils.h"
#include "src/video.h"
#include "utf_utils.h"
Include dependency graph for display_vram.cpp:

Classes

class  platf::dxgi::d3d_avcodec_encode_device_t
 D3D11 encode device that exposes captured textures to FFmpeg AVCodec. More...
 
class  platf::dxgi::d3d_base_encode_device
 Shared D3D11 conversion resources for AVCodec and NVENC encode devices. More...
 
class  platf::dxgi::d3d_nvenc_encode_device_t
 D3D11 encode device that exposes captured textures to NVENC. More...
 
struct  platf::dxgi::d3d_base_encode_device::encoder_img_ctx_t
 D3D texture and format information for encoder input. More...
 
struct  platf::dxgi::img_d3d_t
 D3D-backed captured image and duplication metadata. More...
 
struct  platf::dxgi::texture_lock_helper
 Keyed-mutex guard used while sharing a D3D texture. More...
 

Macros

#define SUNSHINE_SHADERS_DIR   SUNSHINE_ASSETS_DIR "/shaders/directx"
 Macro for SUNSHINE SHADERS DIR.
 

Typedefs

using frame_t = util::safe_ptr<AVFrame, free_frame>
 FFmpeg hardware frame pointer released with av_frame_free.
 

Functions

blob_t platf::dxgi::compile_pixel_shader (LPCSTR file)
 Compile an HLSL pixel shader from source text.
 
blob_t platf::dxgi::compile_shader (LPCSTR file, LPCSTR entrypoint, LPCSTR shader_model)
 Compile an HLSL shader from source text.
 
blob_t platf::dxgi::compile_vertex_shader (LPCSTR file)
 Compile an HLSL vertex shader from source text.
 
int platf::dxgi::init ()
 Initialize the Windows audio-control backend.
 
blend_t platf::dxgi::make_blend (device_t::pointer device, bool enable, bool invert)
 Create a blend object or message.
 
template<class T >
buf_t platf::dxgi::make_buffer (device_t::pointer device, const T &t)
 Create a buffer object or message.
 
util::buffer_t< std::uint8_t > platf::dxgi::make_cursor_alpha_image (const util::buffer_t< std::uint8_t > &img_data, DXGI_OUTDUPL_POINTER_SHAPE_INFO shape_info)
 Create cursor alpha image.
 
util::buffer_t< std::uint8_t > platf::dxgi::make_cursor_xor_image (const util::buffer_t< std::uint8_t > &img_data, DXGI_OUTDUPL_POINTER_SHAPE_INFO shape_info)
 Create cursor xor image.
 
bool platf::dxgi::set_cursor_texture (device_t::pointer device, gpu_cursor_t &cursor, util::buffer_t< std::uint8_t > &&cursor_img, DXGI_OUTDUPL_POINTER_SHAPE_INFO &shape_info)
 Set cursor texture.
 

Variables

blob_t platf::dxgi::convert_yuv420_packed_uv_type0_ps_hlsl
 Convert yuv420 packed uv type0 ps hlsl.
 
blob_t platf::dxgi::convert_yuv420_packed_uv_type0_ps_linear_hlsl
 Convert yuv420 packed uv type0 ps linear hlsl.
 
blob_t platf::dxgi::convert_yuv420_packed_uv_type0_ps_perceptual_quantizer_hlsl
 Convert yuv420 packed uv type0 ps perceptual quantizer hlsl.
 
blob_t platf::dxgi::convert_yuv420_packed_uv_type0_vs_hlsl
 Convert yuv420 packed uv type0 vs hlsl.
 
blob_t platf::dxgi::convert_yuv420_packed_uv_type0s_ps_hlsl
 Convert yuv420 packed uv type0s ps hlsl.
 
blob_t platf::dxgi::convert_yuv420_packed_uv_type0s_ps_linear_hlsl
 Convert yuv420 packed uv type0s ps linear hlsl.
 
blob_t platf::dxgi::convert_yuv420_packed_uv_type0s_ps_perceptual_quantizer_hlsl
 Convert yuv420 packed uv type0s ps perceptual quantizer hlsl.
 
blob_t platf::dxgi::convert_yuv420_packed_uv_type0s_vs_hlsl
 Convert yuv420 packed uv type0s vs hlsl.
 
blob_t platf::dxgi::convert_yuv420_planar_y_ps_hlsl
 Convert yuv420 planar y ps hlsl.
 
blob_t platf::dxgi::convert_yuv420_planar_y_ps_linear_hlsl
 Convert yuv420 planar y ps linear hlsl.
 
blob_t platf::dxgi::convert_yuv420_planar_y_ps_perceptual_quantizer_hlsl
 Convert yuv420 planar y ps perceptual quantizer hlsl.
 
blob_t platf::dxgi::convert_yuv420_planar_y_vs_hlsl
 Convert yuv420 planar y vs hlsl.
 
blob_t platf::dxgi::convert_yuv444_packed_ayuv_ps_hlsl
 Convert YUV444 packed ayuv ps hlsl.
 
blob_t platf::dxgi::convert_yuv444_packed_ayuv_ps_linear_hlsl
 Convert YUV444 packed ayuv ps linear hlsl.
 
blob_t platf::dxgi::convert_yuv444_packed_vs_hlsl
 Convert YUV444 packed vs hlsl.
 
blob_t platf::dxgi::convert_yuv444_packed_y410_ps_hlsl
 Convert YUV444 packed y410 ps hlsl.
 
blob_t platf::dxgi::convert_yuv444_packed_y410_ps_linear_hlsl
 Convert YUV444 packed y410 ps linear hlsl.
 
blob_t platf::dxgi::convert_yuv444_packed_y410_ps_perceptual_quantizer_hlsl
 Convert YUV444 packed y410 ps perceptual quantizer hlsl.
 
blob_t platf::dxgi::convert_yuv444_planar_ps_hlsl
 Convert YUV444 planar ps hlsl.
 
blob_t platf::dxgi::convert_yuv444_planar_ps_linear_hlsl
 Convert YUV444 planar ps linear hlsl.
 
blob_t platf::dxgi::convert_yuv444_planar_ps_perceptual_quantizer_hlsl
 Convert YUV444 planar ps perceptual quantizer hlsl.
 
blob_t platf::dxgi::convert_yuv444_planar_vs_hlsl
 Convert YUV444 planar vs hlsl.
 
blob_t platf::dxgi::cursor_ps_hlsl
 Cursor ps hlsl.
 
blob_t platf::dxgi::cursor_ps_normalize_white_hlsl
 Cursor ps normalize white hlsl.
 
blob_t platf::dxgi::cursor_vs_hlsl
 Cursor vs hlsl.
 

Detailed Description

Definitions for handling video ram.

Function Documentation

◆ compile_pixel_shader()

blob_t platf::dxgi::compile_pixel_shader ( LPCSTR file)

Compile an HLSL pixel shader from source text.

Parameters
fileOptional stdio file handle connected to the child process.
Returns
Compiled pixel shader object, or an empty handle when compilation fails.

◆ compile_shader()

blob_t platf::dxgi::compile_shader ( LPCSTR file,
LPCSTR entrypoint,
LPCSTR shader_model )

Compile an HLSL shader from source text.

Parameters
fileOptional stdio file handle connected to the child process.
entrypointFunction entry point to resolve from the library.
shader_modelShader model.
Returns
Compiled shader blob, or an empty blob when compilation fails.

◆ compile_vertex_shader()

blob_t platf::dxgi::compile_vertex_shader ( LPCSTR file)

Compile an HLSL vertex shader from source text.

Parameters
fileOptional stdio file handle connected to the child process.
Returns
Compiled vertex shader object, or an empty handle when compilation fails.

◆ init()

int platf::dxgi::init ( )

Initialize the Windows audio-control backend.

Initialize global D3D11 desktop duplication support.

Returns
0 on success; nonzero or negative platform status on failure.

◆ make_blend()

blend_t platf::dxgi::make_blend ( device_t::pointer device,
bool enable,
bool invert )

Create a blend object or message.

Parameters
deviceD3D, audio, or platform device used by the operation.
enableWhether the blend state should enable blending.
invertWhether the blend state should invert the color channels.
Returns
Constructed blend object.

◆ make_buffer()

template<class T >
buf_t platf::dxgi::make_buffer ( device_t::pointer device,
const T & t )

Create a buffer object or message.

Parameters
deviceD3D, audio, or platform device used by the operation.
tInitial value used to populate the GPU buffer.
Returns
Constructed buffer object.

◆ make_cursor_alpha_image()

util::buffer_t< std::uint8_t > platf::dxgi::make_cursor_alpha_image ( const util::buffer_t< std::uint8_t > & img_data,
DXGI_OUTDUPL_POINTER_SHAPE_INFO shape_info )

Create cursor alpha image.

Parameters
img_dataRaw pointer-shape bytes returned by DXGI.
shape_infoDXGI metadata describing the pointer shape.
Returns
Constructed cursor alpha image object.

◆ make_cursor_xor_image()

util::buffer_t< std::uint8_t > platf::dxgi::make_cursor_xor_image ( const util::buffer_t< std::uint8_t > & img_data,
DXGI_OUTDUPL_POINTER_SHAPE_INFO shape_info )

Create cursor xor image.

Parameters
img_dataRaw pointer-shape bytes returned by DXGI.
shape_infoDXGI metadata describing the pointer shape.
Returns
Constructed cursor xor image object.

◆ set_cursor_texture()

bool platf::dxgi::set_cursor_texture ( device_t::pointer device,
gpu_cursor_t & cursor,
util::buffer_t< std::uint8_t > && cursor_img,
DXGI_OUTDUPL_POINTER_SHAPE_INFO & shape_info )

Set cursor texture.

Parameters
deviceD3D, audio, or platform device used by the operation.
cursorCursor image or visibility state to composite.
cursor_imgCursor img.
shape_infoShape info.
Returns
True when the cursor image is uploaded to the D3D texture.