Sunshine latest
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 HMODULE dll = NULL;
60 const ID3D11DevicePtr d3d_device;
61 ID3D11Texture2DPtr d3d_input_texture;
62
63 struct {
64 tcuInit *cuInit;
65 tcuD3D11GetDevice *cuD3D11GetDevice;
66 tcuCtxCreate_v2 *cuCtxCreate;
67 tcuCtxDestroy_v2 *cuCtxDestroy;
68 tcuCtxPushCurrent_v2 *cuCtxPushCurrent;
69 tcuCtxPopCurrent_v2 *cuCtxPopCurrent;
70 tcuMemAllocPitch_v2 *cuMemAllocPitch;
71 tcuMemFree_v2 *cuMemFree;
72 tcuGraphicsD3D11RegisterResource *cuGraphicsD3D11RegisterResource;
73 tcuGraphicsUnregisterResource *cuGraphicsUnregisterResource;
74 tcuGraphicsMapResources *cuGraphicsMapResources;
75 tcuGraphicsUnmapResources *cuGraphicsUnmapResources;
76 tcuGraphicsSubResourceGetMappedArray *cuGraphicsSubResourceGetMappedArray;
77 tcuMemcpy2D_v2 *cuMemcpy2D;
78 HMODULE dll;
79 } cuda_functions = {};
80
81 CUresult last_cuda_error = CUDA_SUCCESS;
82 CUcontext cuda_context = nullptr;
83 CUgraphicsResource cuda_d3d_input_texture = nullptr;
84 CUdeviceptr cuda_surface = 0;
85 size_t cuda_surface_pitch = 0;
86 };
87
88} // namespace nvenc
89#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:87
Declarations for abstract Direct3D11 NVENC encoder.