more
[webkit_codecamp] / codecamp.tex
1 \documentclass[usenames,dvipsnames]{beamer}
2 \usepackage[font=small,skip=-1pt]{caption}
3 \usepackage{xcolor}
4 \usepackage{color, colortbl}
5 \usepackage{caption}
6 \usepackage{listings}
7 \usepackage{graphicx}
8 \usepackage{hyperref}
9 \usepackage{comment}
10 \usepackage{textpos}
11 \usepackage{tgpagella}
12 \usepackage[utf8]{inputenc}
13 \usepackage{fontspec}
14 \usepackage{tabularx, array, booktabs}
15 \usepackage{cite}
16 \usepackage{verbatim}
17 \usepackage{comment}
18 \usepackage{adjustbox}
19
20 \newcommand\topalign[1]{%
21   \setbox0\hbox{#1}%
22   \raisebox{\dimexpr-\ht0+\dp0\relax}{\usebox0}}
23
24 \definecolor{blond}{rgb}{0.98, 0.94, 0.75}
25 \definecolor{beige}{rgb}{0.96, 0.96, 0.86}
26 \definecolor{mGreen}{rgb}{0,0.6,0}
27 \definecolor{mGray}{rgb}{0.5,0.5,0.5}
28 \definecolor{mPurple}{rgb}{0.58,0,0.82}
29 \definecolor{bgcolor}{rgb}{0.8,0.8,0.8}
30 \definecolor{afblue}{rgb}{0.36, 0.54, 0.66}
31 \definecolor{coolblack}{rgb}{0.0, 0.18, 0.39}
32 \definecolor{paleaqua}{rgb}{0.74, 0.83, 0.9}
33 \definecolor{platinum}{rgb}{0.9, 0.89, 0.89}
34 \definecolor{whitesmoke}{rgb}{0.96, 0.96, 0.96}
35 \definecolor{carolinablue}{rgb}{0.6, 0.73, 0.89}
36 \definecolor{amber}{rgb}{1.0, 0.75, 0.0}
37 \definecolor{deepjunglegreen}{rgb}{0.0, 0.29, 0.29}
38 \definecolor{mediumred-violet}{rgb}{0.63, 0.1, 0.42}
39 \definecolor{babypink}{rgb}{0.96, 0.76, 0.76}
40 \definecolor{beaublue}{rgb}{0.74, 0.83, 0.9}
41 \definecolor{bananayellow}{rgb}{1.0, 0.88, 0.21}
42 \definecolor{bananamania}{rgb}{0.98, 0.91, 0.81}
43 \definecolor{crimsonglory}{rgb}{0.75, 0.0, 0.2}
44
45 \lstdefinestyle{CStyle}{
46         language=C++,                % choose the language of the code
47 %       basicstyle=\footnotesize,       % the size of the fonts that are used for the code
48         basicstyle=\tt\color{afblue},
49     breakatwhitespace=false,
50     breaklines=true,
51         backgroundcolor=\color{bgcolor},  % choose the background color. You must add \usepackage{color}
52         showspaces=false,               % show spaces adding particular underscores
53         showstringspaces=false,         % underline spaces within strings
54         showtabs=false,                 % show tabs within strings adding particular underscores
55         frame=single,           % adds a frame around the code
56         tabsize=2,          % sets default tabsize to 2 spaces
57         captionpos=b,           % sets the caption-position to bottom
58         breaklines=true,        % sets automatic line breaking
59         breakatwhitespace=false,    % sets if automatic breaks should only happen at whitespace
60     commentstyle=\color{mGreen},
61     keywordstyle=\color{magenta},
62     stringstyle=\color{mPurple},
63         rulesepcolor=\color{gray},
64     rulecolor=\color{black},
65 }
66
67 \setmainfont{Noto Sans} % substitute with any font that exists on your system
68 \setsansfont{Noto Sans} % substitute with any font that exists on your system
69 \setmonofont{Noto Sans Mono Medium} % substitute with any font that exists on your system
70
71 \usetheme{Warsaw}
72 \useoutertheme{infolines}
73 \usecolortheme{crane}
74
75 \captionsetup[figure]{labelformat=empty}
76
77 \addtobeamertemplate{headline}{}{\vskip2pt}
78 \addtobeamertemplate{headline}{}{%
79         \begin{textblock*}{5mm}(.9\textwidth,-0.6cm)
80         \includegraphics[height=0.67cm]{data/igalia-logo.png}
81 \end{textblock*}}
82
83 \definecolor{links}{rgb}{0.1, 0.3, 0.6}
84 \hypersetup{colorlinks,linkcolor=,urlcolor=links}
85
86 \pgfdeclareimage[height=\paperheight]{igaliabglight}{data/igalia_bg_light.eps}
87 \pgfdeclareimage[height=\paperheight]{igaliabg}{data/igaliabg.eps}
88
89 %\setbeamertemplate{title page}{
90 %        \begin{picture}(-90, 180)
91 %                       \put(-200, -74){%
92 %                \pgfuseimage{igaliabg}
93 %            }
94 %
95 %            \put(55,19){%
96 %                               \begin{minipage}[b][36mm][t]{240mm}
97 %                    \usebeamerfont{title}{\inserttitle\par}
98 %                    \usebeamerfont{author}{\insertauthor\par}
99 %                    \usebeamerfont{title}{\insertinstitute\par}
100 %                \end{minipage}
101 %            }
102 %               \end{picture}
103 %}
104
105 \setbeamertemplate{navigation symbols}{}
106 \setbeamertemplate{title page}{
107         \begin{picture}(0,0)
108             \put(-30,-164){%
109                 \pgfuseimage{igaliabg}
110             }
111
112             \put(0,-110.7){%
113                 \begin{minipage}[b][38mm][t]{220mm}
114                     \usebeamerfont{title}{\inserttitle\par}
115                     \usebeamerfont{author}{\insertauthor\par}
116                 \end{minipage}
117             }
118
119                         \put(240, -138){
120                                 \usebeamerfont{date}{\huge{{\insertdate}}\par}
121                                 }
122                 \end{picture}
123 }
124
125 \setbeamertemplate{itemize items}[triangle]
126 \setbeamertemplate{itemize subitem}[circle]
127 \setbeamerfont{frametitle}{size=\small}
128
129 \setbeamertemplate{blocks}[default]
130 \setbeamercolor{block title}{fg=amber,bg=black}
131
132 \title{\textbf{Sharing texture data between drivers}}
133 \author[Eleni Maria Stea <estea@igalia.com>]{\small{Eleni Maria Stea
134 <estea@igalia.com>}\\\\\includegraphics{data/igalia.eps}}
135 \date{\tiny{WebKit Codecamp}}
136
137 \AtBeginSection[]
138 {
139   \begin{frame}
140     \frametitle{Outline}
141         \tableofcontents[currentsection]
142   \end{frame}
143 }
144
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 \begin{document}
147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148
149 \begin{frame}[plain]
150 \titlepage
151 \end{frame}
152
153 \begin{frame}
154         \frametitle{Outline}
155         \tableofcontents
156 \end{frame}
157
158 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159
160 \begin{comment}
161 \begin{frame}[fragile,c]
162     \frametitle{}
163     \begin{center}
164     \end{center}
165 \end{frame}
166 \end{comment}
167
168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 \section[Introduction]{Introduction: Using ANGLE in WebGL2}
170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171
172 \begin{frame}[fragile,c]
173     \frametitle{A few words about ANGLE}
174         \center{\textbf{\color{coolblack}{ANGLE is an EGL/GLESv2 implementation}}}
175
176         \setbeamertemplate{itemize/enumerate body begin}{\scriptsize}
177         \setbeamertemplate{itemize/enumerate subbody begin}{\tiny}
178         \setbeamertemplate{itemize/enumerate subsubbody begin}{\tiny}
179         \setbeamertemplate{itemize items}[triangle]
180     \setbeamertemplate{blocks}[rounded]
181
182         \vspace{0.3cm}
183     \begin{block}{\color{afblue}{\scriptsize\textbf{EGL/GLESv2}:}}
184                 \begin{itemize}
185                         \itemsep0.2cm
186             \item GLESv2 is used to render graphics using the GPU (graphics
187                 API).
188             \item EGL is used to create a GLESv2 context.
189         \end{itemize}
190         \end{block}
191         \vspace{0.3cm}
192
193     \begin{block}{\color{afblue}{\scriptsize\textbf{ANGLE EGL/GLESv2}:}}
194                 \begin{itemize}
195                         \itemsep0.2cm
196                         \item GLESv2 is implemented \textbf{on top of other APIs} (OpenGL,
197                 Vulkan, GLESv2). EGL too (EGL, GLX, gbm, headless display).
198             \item Users can select the most convenient backend using some 
199                 \textbf{ANGLE EGL extensions} (\texttt{eglext\_angle.h}) that
200                 provide extra attributes to some standard EGL API stucts.
201                         \item Primary \textbf{purpose} of ANGLE is to provide EGL/GLESv2 to systems
202                 lacking it.
203         \end{itemize}
204         \end{block}
205
206         \vspace{0.2cm}
207 \end{frame}
208
209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210
211 \begin{frame}[fragile,c]
212     \frametitle{Using ANGLE in WebKit}
213
214     \center{\textbf{\color{coolblack}{Using ANGLE (EGL/GLESv2 backend) in WebGL2 }}}
215         \vspace{0.2cm}
216
217         \setbeamertemplate{itemize/enumerate body begin}{\scriptsize}
218         \setbeamertemplate{itemize/enumerate subbody begin}{\tiny}
219         \setbeamertemplate{itemize/enumerate subsubbody begin}{\tiny}
220         \setbeamertemplate{itemize items}[triangle]
221         \setbeamertemplate{blocks}[rounded]
222
223         \vspace{0.1cm}
224
225     \begin{block}{\color{afblue}{\scriptsize\textbf{Reasons}:}}
226                 \begin{itemize}
227             \item better performance in some cases (Žan Doberšek)
228             \item it'll be mostly an optimized wrapper around the native driver (libGLES*
229                                 is available on Linux desktop!)
230         \end{itemize}
231         \end{block}
232         \vspace{0.3cm}
233     \begin{block}{\color{afblue}{\scriptsize\textbf{Problem}:}}
234                 \begin{itemize}
235                         \item \textbf{ANGLE} renders on a \textbf{GLESv2 texture} created by ANGLE context
236                         \item {\color{coolblack}WebKit \textbf{graphics pipeline} components use
237                                 \textbf{OpenGL textures} that
238                                 are composited by the WebKit compositor}
239             \item We are currently \textbf{\textit{copying}} the ANGLE texture data to
240                 an OpenGL texture to assemble the final image and this is
241                 \textbf{\textit{slow}}!
242         \end{itemize}
243         \end{block}
244
245         \vspace{0.1cm}
246
247     \center{\textbf{\color{coolblack}{We need to replace this copy with
248     something better!}}}
249
250         \vspace{0.2cm}
251 \end{frame}
252
253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254
255 \begin{frame}[fragile,c]
256     \frametitle{Experiments on Linux}
257
258     \vspace{0.3cm}
259     {\footnotesize{
260         \begin{enumerate}
261         \itemsep0.3cm
262         \item {\color{coolblack}\textbf{Use ANGLE and EGL in the same program:
263             create 2 X11 windows, and draw 2 images from 2 different contexts
264                 by 2 different drivers.}
265
266                 \tiny{{(In several cases ANGLE behaves
267                 different from EGL: e.g. when \texttt{eglMakeCurrent} doesn't
268                 call \texttt{eglMakeCurrent}!!).}}
269                 }
270             \item {\color{coolblack}\textbf{Fix the problem with shared 
271                 context and shared textures.}
272
273                 \tiny{{(required
274                 modifications in ANGLE OpenGL driver, writing an ANGLE extension, forcing the 
275                 EGL/OpenGL backend, and it wouldn't work with multiple
276                 processes)}}
277                 }
278             \item {\color{coolblack}\textbf{Fix the problem by sharing a Linux kernel 
279                 dma-buf buffer across drivers.}
280
281                 \tiny{{(drivers must support some EGL/GL extensions, but both mesa and
282                 ANGLE support them)}}
283                 }
284             \item {\color{coolblack}\textbf{Solve the multiple processes case.}
285
286                 \tiny{{(we need some sort of IPC to exchange the dma-buf FD)}}
287                 }
288         \end{enumerate}
289     }}
290 \end{frame}
291
292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 \section[Experiment 1]{Experiment 1: Using ANGLE and the native system driver in the same
301 program}
302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303
304 \begin{frame}[fragile,c]
305     \frametitle{Step 1: Setting up to debug ANGLE with GDB}
306
307         \vspace{0.2cm}
308
309     \begin{center}
310                 \scriptsize{
311                 I've ran my experiments using test programs and ANGLE,\\
312                 and I had to
313                 \textbf{\color{mediumred-violet}modify the default set up} to 
314                 debug/explore ANGLE calls with GDB:
315                 }
316     \end{center}
317
318         \vspace{0.1cm}
319
320         \setbeamertemplate{blocks}[rounded]
321
322         \begin{block}{\footnotesize{\textbf{Problems when building ANGLE:}}}\scriptsize{\texttt{
323                 \begin{itemize}
324                         \itemsep0.1cm
325                                 \color{coolblack}
326                         \item {{Default \textbf{gn} configuration redirects debugging
327                                 symbols into separate files where GDB can't find them.}}
328                         \item {\textbf{GDB} doesn't know where to find the ANGLE
329                                 installation directories.}
330                         \item {{\textbf{dwarf5} is not fully implemented on GDB, and so it's
331                                 impossible to step without errors when it's enabled.}}
332                         \item {\textbf{Debugging symbols} aren't enabled by default.}
333                 \end{itemize}}}
334         \vspace{0.2cm}
335         \end{block}
336
337         \vspace{0.3cm}
338
339         \scriptsize{
340                 \setbeamertemplate{itemize item}[circle]
341         \begin{itemize}
342                 \item {\textbf{Blog post} on how to set up
343                         \textbf{\color{mediumred-violet}{ANGLE}} and \textbf{\color{mediumred-violet}{GDB}} for debugging: \url{https://eleni.mutantstargoat.com/hikiko/debug-angle/}}
344                 \item {\textbf{Gist} with the \textbf{\color{mediumred-violet}{GN args}}
345                         I've used: \url{https://gistof.com/gnargs}}
346         \end{itemize}}
347         \vspace{0.2cm}
348 \end{frame}
349
350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
351
352 \begin{frame}[fragile,c]
353     \frametitle{Step 2: Contexts from two drivers in the same
354     program 1/2}
355
356         \setbeamertemplate{itemize/enumerate body begin}{\scriptsize}
357         \setbeamertemplate{itemize/enumerate subbody begin}{\tiny}
358         \setbeamertemplate{itemize/enumerate subsubbody begin}{\tiny}
359         \setbeamertemplate{itemize items}[triangle]
360         \setbeamertemplate{blocks}[rounded]
361
362         \begin{center}
363         \textbf{\color{coolblack}First Test}
364         \end{center}
365         \vspace{-0.1cm}
366         \scriptsize{\color{coolblack}
367         I've first written a program where both ANGLE and native system driver render
368         images on two different X11 windows and displayed them side by side:
369         }
370         \vspace{-0.1cm}
371         \begin{center}
372         \adjustbox{valign=t, margin=1ex,
373         padding=1ex}{\includegraphics[height=1.5cm]{data/angle_egl.png}}
374         \end{center}
375         \vspace{-0.1cm}
376         \begin{block}{\footnotesize{Things I had to take care of:}}
377         \begin{itemize}
378                 \item {Set ANGLE \textbf{library paths} in Makefile and link
379                         with native system EGL.}
380                 \item {\textbf{Dynamically open} ANGLE EGL and load its functions prefixed with
381                         \texttt{angle\_} to distinguish them from native EGL ones.}
382                 \item {Do the same for GLESv2.}
383                 \item {\textbf{Invalidate the ANGLE context} at every display call.\\
384                         (\textit{When ANGLE is not the only
385                         implementation available \texttt{MakeCurrent} is not working as
386                         expected!!!})}
387         \end{itemize}
388         \end{block}
389 \end{frame}
390
391 \begin{frame}[fragile,c]
392     \frametitle{Step 2: Contexts from two drivers in the same
393     program 2/2}
394         \vspace{0.1cm}
395         \begin{center}
396                 \textbf{\color{coolblack}Why invalidate the ANGLE context before MakeCurrent?}
397                 \\
398                 \begin{table}[c]
399                         \begin{tabularx}{\textwidth}{l X}
400                                 \tiny{\textbf{\color{mediumred-violet}Context is cached in ANGLE!}} &
401                                 \adjustbox{valign=c, margin=0.1ex,
402                                 padding=0.1ex}{\includegraphics[height=2cm]{data/makecurrent.png}} \\
403                         \end{tabularx}
404                 \end{table}
405         \end{center}
406
407         \vspace{-0.1cm}
408         \begin{center}
409                 \textbf{\color{coolblack}More on Makefile changes and dynamic loading:}
410         \end{center}
411
412         \setbeamertemplate{itemize/enumerate body begin}{\tiny}
413         \setbeamertemplate{itemize items}[circle]
414         
415         \tiny{
416         \textbf{\texttt{\color{black}{Blog post:}}}
417         {Sharing texture data between ANGLE and the native system driver:\\
418         \url{https://eleni.mutantstargoat.com/hikiko/angle-dma/}}\\
419         \vspace{0.1cm}
420         \begin{itemize}
421             \itemsep0.1cm
422             \item 
423                 {\color{black}Step 1: Using
424                 both libraries in the same program.}
425             \item 
426                 {\color{black}{About ANGLE MakeCurrent.}}
427         \end{itemize}
428
429         \vspace{0.3cm}
430
431         \color{black}{\textbf{\texttt{Code:}}}
432         {\url{https://github.com/hikiko/shctx/tree/wip/system\_egl\_dynamic\_angle}}
433
434         }
435 \end{frame}
436
437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
438
439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
440 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
441 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
442 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
443 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
444
445 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
446 \section[Experiment 2]{Experiment 2: Sharing a texture across drivers using shared context}
447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
448
449 \begin{frame}[fragile,c]
450     \frametitle{Shared Context}
451     \begin{center}
452         \scriptsize{
453             \textbf{\color{coolblack}{A texture can be accessed by multiple OpenGL or
454             GLESv2 contexts when these contexts are \textit{shared}:}}
455         }
456         \vspace{0.001cm}
457         \texttt{
458             \begin{table}[h]
459                 \centering
460                 \begin{adjustbox}{max width=\textwidth}
461                     \begin{tabular}{|l|}
462                         \hline
463                         \rowcolor{platinum}
464                         \\
465                         \rowcolor{platinum}
466                         \textbf{new\_ctx} = {\color{mediumred-violet}eglCreateContext}(new\_ctx\_dpy, new\_ctx\_config,
467                         \textbf{native\_ctx}, new\_ctx\_attrib);\\
468                         \rowcolor{platinum}\\
469                         \hline
470                     \end{tabular}
471                 \end{adjustbox}
472             \end{table}
473         }
474
475         \vspace{0.1cm}
476         \scriptsize{
477             \textbf{\color{coolblack}{A texture generated by each context can be bound and used by the
478             other\\ without ever leaving the GPU!}}
479         }
480         \vspace{0.01cm}
481
482         \tiny{
483             \texttt{
484                 \begin{table}[h]
485                     \centering
486                     \begin{adjustbox}{max width=\textwidth}
487                         \begin{tabular}{|l|}
488                             \rowcolor{platinum}
489                             \hline
490                             \rowcolor{platinum}
491                             \\
492                             \rowcolor{platinum}
493                         glBindTexture({\color{mediumred-violet}GL\_TEXTURE\_2D}, \textbf{\color{afblue}gl\_shared\_tex});\\
494                             \rowcolor{platinum}
495                         {\color{darkgray}/* ... gl operations ... */}\\
496                             \rowcolor{platinum}
497                         \\
498                             \rowcolor{platinum}
499                         angle\_glBindTexture({\color{mediumred-violet}GL\_TEXTURE\_2D}, \textbf{\color{afblue}gl\_shared\_tex});\\
500                             \rowcolor{platinum}
501                         {\color{darkgray}/* ... angle\_gl operations ... */}\\
502                             \rowcolor{platinum}
503                         \\\hline
504                     \end{tabular}
505                     \end{adjustbox}
506                 \end{table}
507             }}
508
509     \vspace{0.2cm}
510         \setbeamertemplate{itemize/enumerate body begin}{\tiny}
511         \setbeamertemplate{itemize items}[triangle]
512
513         %\setbeamertemplate{blocks}
514         \scriptsize{  \textbf{\color{coolblack}{Shared context restrictions:}}}
515         \vspace{0.1cm}
516         \begin{itemize}
517             \item Contexts must be created by the \textbf{same API} (both OpenGL,
518                 or both GLESv2, same driver).
519             \item Contexts must be created by the \textbf{same
520                 process}.(\textbf{=>
521                 {\color{coolblack}{not
522                 suitable for every project!}}})
523         \end{itemize}
524     \end{center}
525 \end{frame}
526
527 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
528
529 \begin{frame}[fragile,c]
530     \frametitle{Could we use shared context in WebKit?}
531
532         \setbeamertemplate{itemize/enumerate body begin}{\tiny}
533         \setbeamertemplate{itemize items}[triangle]
534     \begin{center}
535         \scriptsize{
536             \textbf{\color{coolblack} Could we use shared context in WebKit?}\\
537
538             \vspace{0.2cm}
539
540             \textbf{Short answer:} Currently yes (with some workaround) but not in the
541             future.
542
543             \vspace{0.3cm}
544
545             \begin{block}{Requirements to use shared context/textures in \textbf{WebKit}:}
546                 \begin{itemize}
547                     \item We should use the \textbf{ANGLE EGL/OpenGL backend in
548                         WebGL2} to
549                         match the main Graphics Pipeline API/driver (both contexts
550                         should be OpenGL or GLESv2 and from the same driver!)
551                     \item We'd need an \textbf{ANGLE extension} to allow passing
552                         native shared context to ANGLE's eglCreateContext instead of
553                         ANGLE shared context.
554                     \item We should never move WebGL2 and Graphics Pipeline in
555                         different processes. Shared contexts should be created by
556                         the same process! (\textbf{Reason we've rejected this
557                         method}).
558                 \end{itemize}
559             \end{block}
560         }
561
562         \vspace{0.3cm}
563
564         \tiny{
565             \textbf{\color{coolblack}{NEW}} ANGLE extension:\\
566             \texttt{EGL\_ANGLE\_native\_shared\_context}
567
568             \vspace{0.2cm}
569
570
571             \textbf{\color{coolblack}NEW} \texttt{\color{afblue}EGLAttrib} attribute can be passed
572             to \texttt{\color{afblue}eglCreateContext}:\\
573             \texttt{EGL\_NATIVE\_SHARED\_CONTEXT\_ANGLE}
574
575             \vspace{0.3cm}
576             {\color{coolblack}
577             This attribute indicates that the shared context in
578             \texttt{\color{deepjunglegreen}eglCreateContext}
579             is \textbf{not ANGLE} and should be used as native in the internal
580             implementation.
581             }
582         }
583     \end{center}
584 \end{frame}
585
586 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
587 \begin{frame}[fragile,c]
588     \frametitle{EGL\_ANGLE\_native\_shared\_context}
589
590         \setbeamertemplate{itemize/enumerate body begin}{\tiny}
591     \setbeamertemplate{itemize items}[triangle]{\tiny}
592     \setbeamercolor{block body}{bg=white}
593
594     \begin{center}
595         \tiny{
596             \begin{block}{This is how we create shared OpenGL
597                 context using EGL (system or ANGLE):}
598                 \centering
599                 \begin{adjustbox}{max width=\textwidth}
600                     \adjustbox{valign=t}{\includegraphics[height=1.3cm]{data/shared_ctx1.png}}
601                 \end{adjustbox}
602
603                 \begin{comment}
604                 {\color{coolblack}
605                 \begin{table}[t]
606                     \centering
607                     \begin{adjustbox}{max width=\textwidth}
608                         \begin{tabular}{l}
609                             · In case of system EGL \texttt{ctx\_A} and
610                             \texttt{ctx\_B} are native
611                             EGL contexts.\\
612                             · In case of ANGLE they are ANGLE EGL contexts.\\
613                         \end{tabular}
614                     \end{adjustbox}
615                 \end{table}
616                 }
617                 \end{comment}
618             \end{block}
619         }
620
621         \tiny{
622         \begin{block}{This is how we'd create shared
623         OpenGL context between native EGL and ANGLE EGL using
624             \texttt{EGL\_ANGLE\_native\_shared\_context}:}
625
626             \vspace{0.2cm}
627             \begin{itemize}
628                 \item \tiny{We'd pass the native EGL context (created by the native system
629                     driver) as {\color{black}shared context} to the
630                     native OpenGL context that is created {\color{black}in the ANGLE
631                     OpenGL backend} using the native system driver!}
632                 \item \tiny{We'd need use the {\color{black}new EGL attribute
633                     (\texttt{EGL\_NATIVE\_SHARED\_CONTEXT\_ANGLE})} to let ANGLE know
634                     that the shared context \textit{\color{coolblack}is not ANGLE but native}
635                     context!}
636             \end{itemize}
637             \vspace{-0.2cm}
638
639         \begin{table}[t]
640             \centering
641             \begin{tabular}{l}
642                 \begin{adjustbox}{max width=\textwidth}
643                     \adjustbox{valign=t}{\includegraphics[height=3.5cm]{data/shared_ctx2.png}}
644                 \end{adjustbox}
645             \end{tabular}
646         \end{table}
647         \end{block}
648     }
649
650
651     \end{center}
652 \end{frame}
653
654 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
655 \begin{frame}[fragile,c]
656     \frametitle{Some work on the shared context approach}
657         \setbeamertemplate{itemize/enumerate body begin}{\tiny}
658     \setbeamertemplate{itemize items}[triangle]{\tiny}
659     \setbeamercolor{block body}{bg=white}
660
661     \begin{center}
662         \begin{block}{\tiny{Extension
663             \texttt{EGL\_NATIVE\_SHARED\_CONTEXT\_ANGLE}:}}
664             \vspace{0.2cm}
665             \tiny{
666                 \begin{table}[h]
667                     \centering
668                         Worked on the extension implementation (draft state, there are
669                         bugs).\\
670                     \begin{tabular}{l}
671                         \\
672                         \textbf{Concept:}\\
673                         \begin{adjustbox}{max width=\textwidth}
674                             \adjustbox{valign=t}{\includegraphics[scale=0.2]{data/shared_ctx3.png}}
675                         \end{adjustbox}\\
676                     \end{tabular}
677                 \end{table}
678             }
679         \end{block}
680         \begin{block}{\tiny{Experimental programs (to test the extension and
681             familiarize with the shared context concept):}}
682             \begin{itemize}
683                 \item A test program that uses EGL ctxA to create a texture and
684                     EGL ctxB to display it on an X11 window.
685                 \item The same program written in ANGLE (there were
686                     differences!)
687                 \item A test program that uses EGL ctxA to create a texture and
688                     ANGLE EGL ctxB to display it on an X11 window.
689                 \item Variations of the above:
690                     \url{https://github.com/hikiko/shctx/branches}
691             \end{itemize}
692         \end{block}
693     \end{center}
694    \end{frame}
695    
696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
697    \begin{frame}
698        \frametitle{Abandoned!}
699        \begin{center}
700            \textbf{\color{coolblack} Why not shared context?}
701            \vspace{0.5cm}
702
703            {\footnotesize{
704                \begin{itemize}
705                    \item Shared context would be a nice and clean approach if we wanted to use
706                        it with our current WebKit code.
707                    \item But there is a plan to use \textbf{separate processes} for WebGL2 and
708                                            the main graphics pipeline!! (Žan Doberšek)
709                \end{itemize}
710            }}
711
712            \vspace{0.5cm}
713            \textbf{\color{coolblack} But there was a \textit{better} approach!}
714        \end{center}
715    \end{frame}
716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
717
718 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
719 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
720 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
721 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
722
723 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
724 \section[Experiment 3]{Experiment 3: Sharing texture data across drivers using kernel DMA buffers}
725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
726
727 \begin{frame}
728     \frametitle{DMA buffers for the win!}
729
730     \begin{center}
731                 \textbf{\color{coolblack}Fortunately we are on Linux!}
732
733                 \setbeamercolor{block body}{bg=white}
734                 \setbeamercolor{block title}{bg=white, fg=coolblack}
735                 \begin{block}{\scriptsize{There is a Linux kernel framework that can be used for
736                         content sharing between different Linux drivers!}}
737
738                         \vspace{-0.1cm}
739                         \begin{table}[t]
740                                 \centering
741                                 \begin{tabular}{l}
742                                         \begin{adjustbox}{max width=\textwidth}
743                                                 \adjustbox{valign=t}{\includegraphics[height=3.1cm]{data/dma_buf_sharing.png}}
744                                         \end{adjustbox}
745                                 \end{tabular}
746                         \end{table}
747
748                         \textbf{\scriptsize{\color{coolblack}A few things that need our attention:}}\\
749                         \vspace{0.1cm}
750
751                         \setbeamertemplate{itemize/enumerate body begin}{\tiny}
752                         \begin{itemize}
753                                 \item There are {\color{coolblack}EGL and OpenGL/GLESv2
754                                         extensions} to make this content sharing easier!
755                                 \item It's {\color{coolblack}driver independent}!
756                                 \item It works with {\color{coolblack}multiple processes}!
757                                 \item As long as ANGLE can expose the required extensions to
758                                         import a dma\_buf file descriptor this method is
759                                         {\color{coolblack}"ANGLE backend
760                                         independent"}!
761                                 \item Works {\color{coolblack}only on Linux}... but in case of
762                                         WPE we won't need to support other systems! (Žan Doberšek)
763                         \end{itemize}
764                 \end{block}
765     \end{center}
766 \end{frame}
767
768 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
769
770 \begin{frame}
771         \frametitle{Extensions and new approach}
772
773         \setbeamercolor{block body}{bg=white}
774         \setbeamertemplate{itemize/enumerate body begin}{\tiny}
775
776         \begin{block}{\scriptsize{How the kernel DMA buffers would help us avoid copying
777                 the WebGL texture data?}}
778
779                 \begin{center}
780                         \begin{itemize}
781                                 \item Each texture is backed by a Linux kernel dma\_buffer.
782                                 \item Multiple textures can use the same dma buffer as backing
783                                         storage if they meet some requirements.
784                                 \item We can export the file descriptor of one buffer from one
785                                         driver and use it to access the buffer from the other
786                                         driver.
787                                 \item So we can export the FD that corresponds to the compositor
788                                         texture, import it in WebGL when we create the render target
789                                         and when the WebGL texture is filled, the compositor texture
790                                         will be also filled, as they share the backing storage!
791                         \end{itemize}
792                 \end{center}
793         \end{block}
794         \begin{block}{\scriptsize{EGL and GL extensions that can be used:}}
795                 \begin{center}
796                         \begin{itemize}
797                                 \item
798                                         \href{https://www.khronos.org/registry/EGL/extensions/MESA/EGL\_MESA\_image\_dma\_buf\_export.txt}{EGL\_MESA\_image\_dma\_buf\_export}:
799                                         \\ This extension allows creating one or multiple Linux dma\_buf
800                                         file descriptors from the EGLImage that corresponds to a texture.
801                                 \item \href{https://www.khronos.org/registry/EGL/extensions/EXT/EGL\_EXT\_image\_dma\_buf\_import.txt}{EGL\_EXT\_image\_dma\_buf\_import}:
802                                         \\ This extension allows creating an EGLImage (that will be used to create a
803                                         texture) from one or multiple Linux dma\_buf file
804                                         descriptors.
805                                 \item \href{https://www.khronos.org/registry/EGL/extensions/EXT/EGL\_EXT\_image\_dma\_buf\_import\_modifiers.txt}{EGL\_EXT\_image\_dma\_buf\_import\_modifiers}:
806                                         \\ This extension builds on EGL\_EXT\_image\_dma\_buf\_import, in order to support
807                                         format modifiers used for tiling, compression, and additional non-linear
808                                         modes.
809                                 \item \href{https://www.khronos.org/registry/OpenGL/extensions/OES/OES\_EGL\_image\_external.txt}{OES\_EGL\_image\_external}: 
810                                         \\ This extension provides a mechanism for creating EGLImage texture targets
811                                         from EGLImages.
812                         \end{itemize}
813                 \end{center}
814         \end{block}
815 \end{frame}
816
817 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
818
819 \begin{frame}
820         \frametitle{Example:}
821
822         \setbeamercolor{block body}{bg=white}{\scriptsize}
823         \setbeamertemplate{itemize/enumerate body begin}{\tiny}
824
825         \begin{block}{\scriptsize{I've written an example:}}
826                 \begin{center}
827                         \begin{itemize}
828                                 \item First using EGL!\\
829                                         Blog post: \url{https://eleni.mutantstargoat.com/hikiko/egl-dma-1/} \\
830                                         Code: \url{https://gistof.com/dma-egl-version}
831                                 \item Then using a native EGL context and a context from ANGLE!\\
832                                         Blog post: \url{https://eleni.mutantstargoat.com/hikiko/angle-dma/}\\
833                                         Code: \url{https://gistof.com/dmaangleeglversion}
834                         \end{itemize}
835                 \end{center}
836         \end{block}
837         \vspace{-0.3cm}
838         \begin{block}{\scriptsize{Snippet from the exporter:}}
839                 \vspace{-0.1cm}
840                 \tiny{
841                 \begin{table}[t]
842                         \centering
843                         \begin{tabular}{l}
844                                 {\color{coolblack}Exporting a dma buffer from a texture
845                                 \texttt{texA}:}\\ 
846                                 \begin{adjustbox}{max width=\textwidth}
847                                         \adjustbox{valign=t}{\includegraphics[height=4cm]{data/dma_export_and_struct.png}}
848                                 \end{adjustbox}\\
849                         \end{tabular}
850                 \end{table}
851                 }
852         \end{block}
853 \end{frame}
854
855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
856
857 \begin{frame}
858         \frametitle{Example continued}
859         \setbeamercolor{block body}{bg=white}{\scriptsize}
860         \setbeamertemplate{itemize/enumerate body begin}{\tiny}
861
862         \begin{block}{\scriptsize{Snippets from the importer:}}
863                 \vspace{-0.1cm}
864                 \tiny{
865                 \begin{table}[t]
866                         \centering
867                         \begin{tabular}{l}
868                                 {\color{coolblack}Creating an EGLImage from the dma buffer using
869                                 the exported fd and the exported modifiers:}\\ 
870                                 \\
871                                 \begin{adjustbox}{max width=\textwidth}
872                                         \adjustbox{valign=t}{\includegraphics[height=3.5cm]{data/dma_import.png}}
873                                 \end{adjustbox}\\
874 \\
875 \\
876                                 {\color{coolblack}Creating a texture using that external
877                                 EGLImage:}\\ 
878                                 \\
879                                 \begin{adjustbox}{max width=\textwidth}
880                                         \adjustbox{valign=t}{\includegraphics[height=2cm]{data/dma_targetteture2does.png}}
881                                 \end{adjustbox}\\
882                         \end{tabular}
883                 \end{table}
884                 }
885         \end{block}
886 \end{frame}
887
888 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
889
890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
892 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
895
896 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
897 \section[Multiple Processes]{Multiple Processes}
898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
899
900 \begin{frame}[fragile,c]
901     \frametitle{What if WebGL and Graphics pipeline were separate processes?}
902         \setbeamertemplate{blocks}[rounded]
903
904 \vspace{0.3cm}
905     \center{
906         \textbf{\small{There is a plan to split the main graphics pipeline and the WebGL2
907     pipeline in two processes. (Žan Doberšek)}}}
908
909 \vspace{0.5cm}
910         \begin{block}{Can we still use shared DMA buffers?}
911         \footnotesize{
912
913     \begin{itemize}
914        \itemsep0.3cm
915        \item {\color{coolblack} \textbf{YES!} DMA buffers can be shared across
916               multiple processes.}
917                   \item {\color{coolblack} But we need some sort of \textbf{\textit{interprocess
918                           communication}} to exchange the file descriptor.}
919                   \item {\color{coolblack} This is a client-server
920                           \textbf{\textit{example}} that uses unix
921             sockets to pass the dma-buf FD from one process to the other:
922                         \url{https://gitlab.com/blaztinn/dma-buf-texture-sharing}.}
923             \end{itemize}
924
925         }
926     \end{block}
927
928 \vspace{0.3cm}
929 \end{frame}
930
931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
932
933 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
934 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
936 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
937 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
938
939 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
940 \section[WebKit Integration]{WebKit Integration}
941 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
942
943 \begin{frame}[fragile,c]
944     \frametitle{WIP WebKit:}
945         \center{\normalsize{\textbf{\color{coolblack}{Ongoing work on WebKit}}}}
946
947         \vspace{0.3cm}
948
949         {\footnotesize{
950         \begin{block}{DONE/WIP/TODO}
951             \begin{itemize}
952                 \item{Use the right CMake options (one can't simply enable
953                     \texttt{USE\_ANGLE\_WEBGL} ☺):
954                     \color{coolblack}{\textbf{FIXED }}}
955                 \item{There were compile errors when ANGLE was used: 
956                     \color{coolblack}{\textbf{FIXED/Pending to send the patches}}}
957                 \item{Link errors when ANGLE is used:
958                     \color{coolblack}{\textbf{WIP/Partially FIXED}}}
959                 \item{Copy replacement: \color{coolblack}{\textbf{WIP/TODO}}}
960             \end{itemize}
961         \end{block}
962         }}
963
964         \vspace{0.2cm}
965         \begin{center}
966                 \setbeamertemplate{itemize/enumerate body begin}{\scriptsize}
967                 \setbeamertemplate{itemize/enumerate subbody begin}[circle]{\tiny}
968                         \begin{itemize}
969                                 \itemsep0.2cm
970                                 \item The extensions to import dma-buf buffers in ANGLE are
971                                         implemented and exposed to the user => {\color{coolblack}in WebGL we can easily import the main pipeline
972                                         DMA buf when we create the render target!}
973                                 \item The extension to export dma-buf buffers from EGL is
974                                         supported on mesa => {\color{coolblack}we could run a check before creating
975                                         the shared dma buffer and use either use it or fallback to
976                                         something else (libgbm? copying?)}
977                         \end{itemize}
978         \end{center}
979 \end{frame}
980
981 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
982
983 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
984 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
985 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
986 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
987 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
988
989 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
990 \section[References]{References}
991 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
992 %\setbeamertemplate{bibliography entry title}{}
993 %\setbeamertemplate{bibliography entry location}{}
994 %\setbeamertemplate{bibliography entry note}{}
995 \setbeamerfont{bibliography item}{size=\footnotesize}
996 \setbeamerfont{bibliography entry author}{size=\footnotesize}
997 \setbeamerfont{bibliography entry title}{size=\footnotesize}
998 \setbeamerfont{bibliography entry year}{size=\footnotesize}
999 \setbeamerfont{bibliography entry note}{size=\footnotesize}
1000
1001 \begin{frame}[allowframebreaks]
1002         \frametitle{Links}
1003         \bibliographystyle{unsrt}
1004         \bibliography{bib/references.bib}
1005         \nocite{*}
1006 \end{frame}
1007
1008 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1009 \end{document}
1010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%