-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCUDA_Graphics.tex
131 lines (102 loc) · 3.81 KB
/
CUDA_Graphics.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
\chapter{CUDA Graphics (OpenGL/DirectX)}
\label{chap:CUDA_OpenGL.DirectX}
A CUDA application can interact (write/read) with data from OpenGL/Direct3D
APIs by mapping the resource from OpenGL/Direct3D to the address space of CUDA.
Currently, this feature is only available in CUDA C/C++.
At the beginning of the program, the CUDA device need to be enabled with
OpenGL/DirectX interoperability using
\begin{verbatim}
cudaGLSetGLDevice(dev_ID)
\end{verbatim}
\textcolor{red}{IMPORTANT: cudaGLSetGLDevice() and cudaSetDevice() are mutually
exclusive. So, we only use one of them}. We use cudaSetDevice() in a
pure computational CUDA application.
{\bf What can be registerred and mapped?}: OpenGL buffers, texture, and
render-buffer objects.
The orders:
\begin{enumerate}
\item register
\item map
\item use in CUDA
\item unmap
\item repeat 2
\item unregister
\end{enumerate}
To register the resource with CUDA
\begin{verbatim}
// register a buffer
cudaGraphicsGLRegisterBuffer()
// register a texture or render-buffer object
cudaGraphicsGLRegisterImage()
\end{verbatim}
\textcolor{red}{Register a resource is potentially high-overhead, so you're
recommended to register once per resource}. To unregister, use
\begin{verbatim}
cudaGraphicsUnregisterResource()
\end{verbatim}
\begin{enumerate}
\item The function cudaGraphicsGLRegisterBuffer() returns a pointer to a CUDA graphics
object of type
\begin{verbatim}
struct cudaGraphicsResource
\end{verbatim}
and can be read/written by kernels or via \verb!cudaMemcpy()! function.
The function also supports all texture formats with 1, 2 or 4 components with
the following internal types
\begin{verbatim}
// float
GL_RGBA_FLOAT32
// normalized integer
GL_RGBA8, GL_INTENSITY16
// unnormalized integer
GL_RGBA8UI
\end{verbatim}
\textcolor{red}{IMPORTANT: unnormalized integer formats require OpenGL 3.0; and
thus written by shaders (CUDA cores), not fixed function pipeline}.
\item The second function returns as a CUDA array which can be read/written
via \verb!cudaMemcpy2D()! call. To read from a kernel, it need to be bind to
a texture or a surface reference. When the resource is registered with
\verb!cudaGraphicsRegisterFlagsSurfaceLoadStore! flag (using
cudaGraphicsResourceSetMapFlags()), it can be written via surface write
functions.
\end{enumerate}
Once it's registerred, it can be mapped or unmapped as many time as necessary
using
\begin{verbatim}
cudaGraphicsMapResources()
cudaGraphicsUnmapResources()
\end{verbatim}
Then, it can be used from the CUDA kernel using the memory address returned by
\begin{verbatim}
// for buffers
cudaGraphicsResourceGetMappedPointer()
// for CUDA arrays
cudaGraphicsSubResourceGetMappedArray()
\end{verbatim}
When we know the resource is being used for read-only or write-only, we can
optimize resource management, by using
\begin{verbatim}
cudaGraphicsResourceSetMapFlags()
\end{verbatim}
to specify usage hints.
\textcolor{red}{While the resource is mapped, OpenGL/Direct3D APIs can't use
them. Otherwise, undefined results are returned}.
\section{OpenGL vs. DirectX interoperability}
\label{sec:opengl-vs.-directx}
\verb!cudaGLMapBufferObject()!
\verb!cudaD3D9MapVertexBuffer()!
\section{Geforce}
\url{http://www.geforce.com/whats-new/articles/geforce-experience-2-1-2-released}
\begin{enumerate}
\item Dynamic Super Resolution (DSR)
\item 4K ShadowPlay recording
\end{enumerate}
\subsection{GameStream}
\begin{enumerate}
\item Notebook GameStream
\item Remotely wake-on-LAN (from sleep mode)
\item Remote Streaming: stream PC games to SHIELD from outside your home
\end{enumerate}
\subsection{ShadowPlay}
\subsection{SHIELD game controller}
\url{http://shield.nvidia.com/wireless-game-controller/}