Sunshine v2026.319.132152
Self-hosted game stream host for Moonlight.
nvenc_d3d11_on_cuda.h
Go to the documentation of this file.
1
5#pragma once
6#ifdef _WIN32
7 // lib includes
8 #include <ffnvcodec/dynlink_cuda.h>
9
10 // local includes
11 #include "nvenc_d3d11.h"
12
13namespace nvenc {
14
19 class nvenc_d3d11_on_cuda final: public nvenc_d3d11 {
20 public:
25 explicit nvenc_d3d11_on_cuda(ID3D11Device *d3d_device);
27
28 ID3D11Texture2D *get_input_texture() override;
29
30 private:
31 bool init_library() override;
32
33 bool create_and_register_input_buffer() override;
34
35 bool synchronize_input_buffer() override;
36
37 bool cuda_succeeded(CUresult result);
38
39 bool cuda_failed(CUresult result);
40
41 struct autopop_context {
42 autopop_context(nvenc_d3d11_on_cuda &parent, CUcontext pushed_context):
43 parent(parent),
44 pushed_context(pushed_context) {
45 }
46
47 ~autopop_context();
48
49 explicit operator bool() const {
50 return pushed_context != nullptr;
51 }
52
53 nvenc_d3d11_on_cuda &parent;
54 CUcontext pushed_context = nullptr;
55 };
56
57 autopop_context push_context();
58
59 const ID3D11DevicePtr d3d_device;
60 ID3D11Texture2DPtr d3d_input_texture;
61
62 struct {
63 tcuInit *cuInit;
64 tcuD3D11GetDevice *cuD3D11GetDevice;
65 tcuCtxCreate_v2 *cuCtxCreate;
66 tcuCtxDestroy_v2 *cuCtxDestroy;
67 tcuCtxPushCurrent_v2 *cuCtxPushCurrent;
68 tcuCtxPopCurrent_v2 *cuCtxPopCurrent;
69 tcuMemAllocPitch_v2 *cuMemAllocPitch;
70 tcuMemFree_v2 *cuMemFree;
71 tcuGraphicsD3D11RegisterResource *cuGraphicsD3D11RegisterResource;
72 tcuGraphicsUnregisterResource *cuGraphicsUnregisterResource;
73 tcuGraphicsMapResources *cuGraphicsMapResources;
74 tcuGraphicsUnmapResources *cuGraphicsUnmapResources;
75 tcuGraphicsSubResourceGetMappedArray *cuGraphicsSubResourceGetMappedArray;
76 tcuMemcpy2D_v2 *cuMemcpy2D;
77 HMODULE dll;
78 } cuda_functions = {};
79
80 CUresult last_cuda_error = CUDA_SUCCESS;
81 CUcontext cuda_context = nullptr;
82 CUgraphicsResource cuda_d3d_input_texture = nullptr;
83 CUdeviceptr cuda_surface = 0;
84 size_t cuda_surface_pitch = 0;
85 };
86
87} // namespace nvenc
88#endif
Interop Direct3D11 on CUDA NVENC encoder. Input surface is Direct3D11, encoding is performed by CUDA.
Definition nvenc_d3d11_on_cuda.h:19
ID3D11Texture2D * get_input_texture() override
Get input surface texture.
Definition nvenc_d3d11_on_cuda.cpp:55
nvenc_d3d11_on_cuda(ID3D11Device *d3d_device)
Definition nvenc_d3d11_on_cuda.cpp:14
Abstract Direct3D11 NVENC encoder. Encapsulates common code used by native and interop implementation...
Definition nvenc_d3d11.h:26
Standalone NVENC encoder.
Definition nvenc_base.cpp:90
Declarations for abstract Direct3D11 NVENC encoder.