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