Sunshine0.0.5917
Sunshine 0.0.5917
Self-hosted game stream host for Moonlight.
Loading...
Searching...
No Matches
nvenc_d3d11_on_cuda.h
Go to the documentation of this file.
1
5#pragma once
6#ifdef _WIN32
7 // local includes
8 #include "nvenc_d3d11.h"
9 #include "nvenc_sdk.h"
10
11namespace NVENC_NAMESPACE {
12
17 class nvenc_d3d11_on_cuda final: public nvenc_d3d11 {
18 public:
24 explicit nvenc_d3d11_on_cuda(ID3D11Device *d3d_device, ::nvenc::shared_dll dll);
25 ~nvenc_d3d11_on_cuda() override;
26
27 ID3D11Texture2D *get_input_texture() override;
28
29 private:
30 bool init_library() override;
31
32 bool create_and_register_input_buffer() override;
33
34 bool synchronize_input_buffer() override;
35
36 bool cuda_succeeded(CUresult result);
37
38 bool cuda_failed(CUresult result);
39
40 struct autopop_context {
41 autopop_context(nvenc_d3d11_on_cuda &parent, CUcontext pushed_context):
42 parent(parent),
43 pushed_context(pushed_context) {
44 }
45
46 ~autopop_context();
47
48 explicit operator bool() const {
49 return pushed_context != nullptr;
50 }
51
52 nvenc_d3d11_on_cuda &parent;
53 CUcontext pushed_context = nullptr;
54 };
55
56 autopop_context push_context();
57
58 const ID3D11DevicePtr d3d_device;
59 ID3D11Texture2DPtr d3d_input_texture;
60
61 struct {
62 tcuInit *cuInit;
63 tcuD3D11GetDevice *cuD3D11GetDevice;
64 tcuCtxCreate_v2 *cuCtxCreate;
65 tcuCtxDestroy_v2 *cuCtxDestroy;
66 tcuCtxPushCurrent_v2 *cuCtxPushCurrent;
67 tcuCtxPopCurrent_v2 *cuCtxPopCurrent;
68 tcuMemAllocPitch_v2 *cuMemAllocPitch;
69 tcuMemFree_v2 *cuMemFree;
70 tcuGraphicsD3D11RegisterResource *cuGraphicsD3D11RegisterResource;
71 tcuGraphicsUnregisterResource *cuGraphicsUnregisterResource;
72 tcuGraphicsMapResources *cuGraphicsMapResources;
73 tcuGraphicsUnmapResources *cuGraphicsUnmapResources;
74 tcuGraphicsSubResourceGetMappedArray *cuGraphicsSubResourceGetMappedArray;
75 tcuMemcpy2D_v2 *cuMemcpy2D;
76 HMODULE dll;
77 } cuda_functions = {};
78
79 CUresult last_cuda_error = CUDA_SUCCESS;
80 CUcontext cuda_context = nullptr;
81 CUgraphicsResource cuda_d3d_input_texture = nullptr;
82 CUdeviceptr cuda_surface = 0;
83 size_t cuda_surface_pitch = 0;
84 };
85
86} // namespace NVENC_NAMESPACE
87#endif
nvenc_d3d11_on_cuda(ID3D11Device *d3d_device, ::nvenc::shared_dll dll)
Definition nvenc_d3d11_on_cuda.cpp:14
ID3D11Texture2D * get_input_texture() override
Get input surface texture.
Definition nvenc_d3d11_on_cuda.cpp:55
nvenc_d3d11(NV_ENC_DEVICE_TYPE device_type, ::nvenc::shared_dll dll)
Initialize an NVENC session wrapper for D3D11 input textures.
Definition nvenc_d3d11.cpp:13
ID3D11Texture2D * ID3D11Texture2DPtr
COM smart pointer for ID3D11Texture2D.
Definition nvenc_d3d11.h:27
std::shared_ptr< std::remove_pointer_t< HMODULE > > shared_dll
Shared ownership wrapper for a loaded Windows module.
Definition nvenc_shared_dll.h:20
ID3D11Device * ID3D11DevicePtr
COM smart pointer for ID3D11Device.
Definition nvenc_d3d11.h:23
Declarations for abstract Direct3D11 NVENC encoder.
Imports one NVENC SDK into its version-specific implementation namespace.
#define NVENC_NAMESPACE
Namespace used for the documented NVENC implementation.
Definition nvenc_sdk.h:12