SlideShare una empresa de Scribd logo
1 de 17
Descargar para leer sin conexión
JavaScript and the browser
as a platform
for game development
David Galeano
mloc.js 2014
David Galeano
● Co-founder and CTO of Turbulenz Limited since 2009
● Technical Director of EA Tech Graphics
● Team leader of RenderWare Graphics
● Game developer at Dinamic Multimedia
● In the video game industry since 1995
○ Worked on many platforms
○ Worked on many technology domains
○ Worked with many programming languages
○ Worked with many operating systems
We have built the first high performance Internet generation game engine and web service called the Turbulenz
platform.
● An industry leading HTML5 JavaScript 2D + 3D game engine
● A web service for social and game APIs accessible across all platforms
● A developer service for the publishing of content online
● An ultra modern destination for playing games with friends online
● Seamlessly working across desktops, browsers, mobiles and tablets
We are relaunching our consumer HTML5 game site this year (in beta now), try it here:
https://ga.me
About Turbulenz
What is possible today
JavaScript in the browser is a viable platform for game development.
We can create high quality games.
The different layers between you and the hardware do affect performance, but not as much as in the past and the GPU is
closer than ever.
These are some examples of what is possible today with JavaScript in the browser:
● Third Person Action Game (Polycraft)
● First Person Shooter Demo (Quake 4 assets)
Polycraft
● Developed by Wonderstruck
● Persistent island game combining arcade
and strategy
ga.me/games/polycraft
Polycraft Challenges
● ~200K lines of code (ignoring comments or blank lines)
○ Misspelled properties, missing arguments, wrong argument type, etc.
○ JSLint, JSHint, IDEs code intelligence help a lot but still not perfect
● Level meshes built from thousands of small pieces in the in-game editor
○ Would be CPU limited because of number of draw calls
○ These are merged into 32x32m blocks
● Hundreds of dynamic renderables for complex bases
○ Would also be CPU limited because of number of draw calls
○ Uses pseudo-instancing, with up to 32 copies of meshes, to reduce draw calls for common objects such as
walls
○ Cut render calls by ~1/3, 10-20% total speedup
● Mostly GPU limited because of expensive lighting model
Quake 4 Demo
● Original game developed by Raven
Software and id Software
● Multi Platform: Xbox 360, Windows, Linux,
Mac OS X
● Just a demo to show that we can deliver
similar visual quality to native applications
Quake 4 Demo Challenges
● 1694 assets to load
○ Compression: 7-Zip better than gzip
○ Caching to reduce HTTP request: assets with unique names to be cached for 10 years
○ Archives to reduce HTTP requests overhead: group textures into tar files
● 353 lights, 346 particle systems
○ Culling: portals, bounding box trees
● 55 shading techniques, 451 materials
○ Minimize state changes: sort by technique and material
● Mostly CPU limited because of scene complexity
○ Some rooms have dozens of lights casting shadows
What we need for the future
To make JavaScript and the browser the ultimate platform for game development, what else is needed?
Many things, but I am not going to talk today about monetization, mobile browsers, copyright protection, anti-cheating, etc.
I am just going to focus on JavaScript performance.
Where is the performance gap with native applications?
● Memory usage
● Parallelism
● Improved floating point performance
Memory Usage
Memory overhead still too high for standard JS objects.
More memory means more cache misses and potentially running out of memory and / or paging to disk.
Manually storing complex objects on typed arrays is hard to maintain.
Typed objects could be the solution
http://wiki.ecmascript.org/doku.php?id=harmony:typed_objects
We want to write code like this:
const Point2D = new StructType({ x: uint16, y: uint16 });
const Vector2D = new StructType({ x: int32, y: int32 });
const Color = new StructType({ r: uint8, g: uint8, b: uint8, a: uint8 });
const Pixel = new StructType({ point: Point2D, color: Color });
let a = Pixel({ point: { x: 0, y: 0 },
color: { r: 255, g: 255, b: 255, a: 255 } });
let b = Pixel({ point: { x: 1, y: 1 },
color: { r: 0, g: 255, b: 0, a: 255 } });
let a2b = Vector2D({ x: (b.point.x - a.point.x), y: (b.point.y - a.point.y) });
Memory Usage...
Instead of code like this:
We also need a way to prefetch memory ahead of time when iterating over arrays of typed objects, this is still fundamental
in order to reduce cache misses.
// PhysicsContact
// [0, 3) : localA (vector3)
// [3, 6) : localB (vector3)
...
// [22,25) : Jacobian : normal x relA * iInertiaA (vector3)
// [25,28) : Jacobian : normal x relB * iInertiaB (vector3)
...
// [50,51) : bounce
// [51,52) : new
…
var contact = new Float32Array(52);
…
var ra0 = contact[6];
var ra1 = contact[7];
var ra2 = contact[8];
….
contact[22] = ((A0 * ca0) + (A3 * ca1) + (A6 * ca2));
contact[23] = ((A1 * ca0) + (A4 * ca1) + (A7 * ca2));
contact[24] = ((A2 * ca0) + (A5 * ca1) + (A8 * ca2));
Parallelism
We need to take advantage of multiple cores, even my phone has 4 of them! Web Workers are not perfect:
● Data can be transferred but not shared
○ Requires data duplication in many cases
○ Being able to share read-only data could help
● Threads communicate by messages
○ Hard to visualize and maintain complex trees of task dependencies
● Hacky-ish way of embedding Web Worker code
○ Not all browsers supporting Web Workers allow you to create Blob URLs
● Number of CPU cores is not exposed
○ Easy to oversubscribe or undersubscribe
Parallelism...
Parallel Array (River Trail) is useful but limited
http://wiki.ecmascript.org/doku.php?id=strawman:data_parallelism
● Requiring elemental functions may limit the kind of problems you can solve with them
● Every parallel operation generates a new array
○ It would be better to be able to provide a destination array
● Some browsers will not like the fact that parallel operations are blocking
● Would you be able to debug it?
WebCL is more powerful than Parallel Array
http://www.khronos.org/webcl/
● Allows non-blocking operations
● Total control over source and destination buffers
● But OpenCL kernels can only be debugged outside the browser
● Still limited in the kind of code it can execute in parallel
● And we have no idea if / when it would be available without requiring a plugin…
Parallelism...
Ideal API would provide a task management system based on data access and ownership
● Tasks would be declared to operate on specific buffers with specific read / write requirements
● Task manager will build dependency tree based on task order and data access requirements
● Task manager will distribute individual tasks among all available cores
This is similar to how some declarative build systems work, you declare all the tasks and their explicit dependencies and the
build system takes care of building everything in parallel in the right order.
We implemented systems like that for PS3, Xbox360 and PC, they scale really well, the overhead of the task manager is
minimal unless you create thousands of tasks per frame.
Could be partially implemented with Web Workers but it will never be as optimal as a native implementation because of the
limitations previously described.
Improved floating point performance
Games spend most of their time doing floating point operations but we are not taking advantage of the full potential of modern CPUs.
32-bit floating point operations
● Most games do not need 64-bit floating point operations but JS standard requires it
● Early experiments using Math.fround show 10-20% improvement
● But it is expensive to modify thousands of existing lines of code to add Math.fround everywhere
○ contact[22] = (Math.fround(Math.fround(A0 * ca0) + Math.fround(A3 * ca1)) + Math.fround(A6 * ca2));
● Would be simpler for game developers if language spec could be relaxed to allow 32-bit operations when the final result of a
sequence of operations is stored to a 32-bit location
SIMD
● Many vector and matrix operations could be optimized with SIMD instructions
● Would need good integration with Typed Arrays and/or Typed Objects
● Exiting proposal has limited types, Mono.Simd is more thorough
○ https://github.com/johnmccutchan/ecmascript_simd
○ http://docs.go-mono.com/?link=N%3aMono.Simd
● Also expensive to modify existing vector math libraries to use it
○ But gains should be bigger and probably worth it
Improved floating point performance
Crazy idea: runtime settings?
● “use single-precision”;
● “use fast-math”;
Native applications have access to compiler settings that can be used to tune code generation for speed. For example, GCC
has “-ffast-math” and Visual Studio has “/fp:fast” to relax the rules on floating point operations, allowing optimizations that
may not generate precise results but good enough in many cases.
Questions & Answers
Game site:
https://ga.me
Twitter:
@turbulenz
@wonderstruck_uk
Developer site:
http://biz.turbulenz.com
David Galeano:
@davidgaleano
davidgaleano@turbulenz.com
Open Source Turbulenz Engine:
https://github.com/turbulenz/turbulenz_engine
Online Turbulenz Engine documentation:
http://docs.turbulenz.com

Más contenido relacionado

La actualidad más candente

OpenGL 4.5 Update for NVIDIA GPUs
OpenGL 4.5 Update for NVIDIA GPUsOpenGL 4.5 Update for NVIDIA GPUs
OpenGL 4.5 Update for NVIDIA GPUsMark Kilgard
 
Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5firenze-gtug
 
vkFX: Effect(ive) approach for Vulkan API
vkFX: Effect(ive) approach for Vulkan APIvkFX: Effect(ive) approach for Vulkan API
vkFX: Effect(ive) approach for Vulkan APITristan Lorach
 
Approaching zero driver overhead
Approaching zero driver overheadApproaching zero driver overhead
Approaching zero driver overheadCass Everitt
 
WebRTC ... GWT & in-browser computation
WebRTC ... GWT & in-browser computationWebRTC ... GWT & in-browser computation
WebRTC ... GWT & in-browser computationJooinK
 
Android RenderScript
Android RenderScriptAndroid RenderScript
Android RenderScriptJungsoo Nam
 
NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityMark Kilgard
 
Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3ICS
 
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14AMD Developer Central
 
Android High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptAndroid High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptArvind Devaraj
 
EXT_window_rectangles
EXT_window_rectanglesEXT_window_rectangles
EXT_window_rectanglesMark Kilgard
 
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...ScyllaDB
 

La actualidad más candente (20)

OpenGL 4.5 Update for NVIDIA GPUs
OpenGL 4.5 Update for NVIDIA GPUsOpenGL 4.5 Update for NVIDIA GPUs
OpenGL 4.5 Update for NVIDIA GPUs
 
Hello, QML
Hello, QMLHello, QML
Hello, QML
 
OpenGL for 2015
OpenGL for 2015OpenGL for 2015
OpenGL for 2015
 
Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5
 
vkFX: Effect(ive) approach for Vulkan API
vkFX: Effect(ive) approach for Vulkan APIvkFX: Effect(ive) approach for Vulkan API
vkFX: Effect(ive) approach for Vulkan API
 
Approaching zero driver overhead
Approaching zero driver overheadApproaching zero driver overhead
Approaching zero driver overhead
 
WebRTC ... GWT & in-browser computation
WebRTC ... GWT & in-browser computationWebRTC ... GWT & in-browser computation
WebRTC ... GWT & in-browser computation
 
Android RenderScript
Android RenderScriptAndroid RenderScript
Android RenderScript
 
NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL Functionality
 
Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3
 
Qt Qml
Qt QmlQt Qml
Qt Qml
 
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
 
Android High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptAndroid High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscript
 
RenderScript
RenderScriptRenderScript
RenderScript
 
NvFX GTC 2013
NvFX GTC 2013NvFX GTC 2013
NvFX GTC 2013
 
Opengl basics
Opengl basicsOpengl basics
Opengl basics
 
Open gl
Open glOpen gl
Open gl
 
EXT_window_rectangles
EXT_window_rectanglesEXT_window_rectangles
EXT_window_rectangles
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
 

Destacado

TVI Show Timeline _ Illegal Pyramid System , Market Leaders Imprisoned Asia ,...
TVI Show Timeline _ Illegal Pyramid System , Market Leaders Imprisoned Asia ,...TVI Show Timeline _ Illegal Pyramid System , Market Leaders Imprisoned Asia ,...
TVI Show Timeline _ Illegal Pyramid System , Market Leaders Imprisoned Asia ,...Elizabeth813Frazier
 
Gutell 091.imb.2004.13.495
Gutell 091.imb.2004.13.495Gutell 091.imb.2004.13.495
Gutell 091.imb.2004.13.495Robin Gutell
 
Leading agile product development
Leading agile product developmentLeading agile product development
Leading agile product developmentArto Saari
 
Correcciondelapruebadeecompu
CorrecciondelapruebadeecompuCorrecciondelapruebadeecompu
Correcciondelapruebadeecompupabonmonica
 
R2cities Progetto Europeo Social Housing
R2cities Progetto Europeo Social HousingR2cities Progetto Europeo Social Housing
R2cities Progetto Europeo Social HousingOfficinae Verdi
 
Como Publicar Anuncios Na TelexFREE
Como Publicar Anuncios Na TelexFREEComo Publicar Anuncios Na TelexFREE
Como Publicar Anuncios Na TelexFREETelexfree Suporte
 
Création une plate bande d’inspiration « (1)
Création une plate bande d’inspiration « (1)Création une plate bande d’inspiration « (1)
Création une plate bande d’inspiration « (1)Habilux Anne
 
про беньковського (автосохраненный)
про беньковського (автосохраненный)про беньковського (автосохраненный)
про беньковського (автосохраненный)Muzpck
 
бало
балобало
балоkachmad
 
Corporate finance teminologies
Corporate finance teminologiesCorporate finance teminologies
Corporate finance teminologiesZafar aziz
 

Destacado (20)

Opr04 irj
Opr04 irjOpr04 irj
Opr04 irj
 
TVI Show Timeline _ Illegal Pyramid System , Market Leaders Imprisoned Asia ,...
TVI Show Timeline _ Illegal Pyramid System , Market Leaders Imprisoned Asia ,...TVI Show Timeline _ Illegal Pyramid System , Market Leaders Imprisoned Asia ,...
TVI Show Timeline _ Illegal Pyramid System , Market Leaders Imprisoned Asia ,...
 
Gutell 091.imb.2004.13.495
Gutell 091.imb.2004.13.495Gutell 091.imb.2004.13.495
Gutell 091.imb.2004.13.495
 
Leading agile product development
Leading agile product developmentLeading agile product development
Leading agile product development
 
Correcciondelapruebadeecompu
CorrecciondelapruebadeecompuCorrecciondelapruebadeecompu
Correcciondelapruebadeecompu
 
Romania mif
Romania mifRomania mif
Romania mif
 
R2cities Progetto Europeo Social Housing
R2cities Progetto Europeo Social HousingR2cities Progetto Europeo Social Housing
R2cities Progetto Europeo Social Housing
 
Como Publicar Anuncios Na TelexFREE
Como Publicar Anuncios Na TelexFREEComo Publicar Anuncios Na TelexFREE
Como Publicar Anuncios Na TelexFREE
 
Riesgos del internt
Riesgos del interntRiesgos del internt
Riesgos del internt
 
Italiy mif
Italiy mifItaliy mif
Italiy mif
 
Unit 3 task 3 table 2
Unit 3 task 3 table 2Unit 3 task 3 table 2
Unit 3 task 3 table 2
 
Création une plate bande d’inspiration « (1)
Création une plate bande d’inspiration « (1)Création une plate bande d’inspiration « (1)
Création une plate bande d’inspiration « (1)
 
про беньковського (автосохраненный)
про беньковського (автосохраненный)про беньковського (автосохраненный)
про беньковського (автосохраненный)
 
Make in Progress | Cross Creativity 19/06
Make in Progress | Cross Creativity 19/06Make in Progress | Cross Creativity 19/06
Make in Progress | Cross Creativity 19/06
 
Amarcord
AmarcordAmarcord
Amarcord
 
бало
балобало
бало
 
Corporate finance teminologies
Corporate finance teminologiesCorporate finance teminologies
Corporate finance teminologies
 
Music video structure
Music video structureMusic video structure
Music video structure
 
Poland mif
Poland mifPoland mif
Poland mif
 
Justin p
Justin pJustin p
Justin p
 

Similar a mloc.js 2014 - JavaScript and the browser as a platform for game development

Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I💻 Anton Gerdelan
 
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...DevClub_lv
 
JS Fest 2019. Денис Радин. AAA 3D графика в Web с ReactJS, BabylonJS и Unity3D
JS Fest 2019. Денис Радин. AAA 3D графика в Web с ReactJS, BabylonJS и Unity3DJS Fest 2019. Денис Радин. AAA 3D графика в Web с ReactJS, BabylonJS и Unity3D
JS Fest 2019. Денис Радин. AAA 3D графика в Web с ReactJS, BabylonJS и Unity3DJSFestUA
 
Developing games and graphic visualizations in Pascal
Developing games and graphic visualizations in PascalDeveloping games and graphic visualizations in Pascal
Developing games and graphic visualizations in PascalMichalis Kamburelis
 
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.UA Mobile
 
C++ on the Web: Run your big 3D game in the browser
C++ on the Web: Run your big 3D game in the browserC++ on the Web: Run your big 3D game in the browser
C++ on the Web: Run your big 3D game in the browserAndre Weissflog
 
The Next Leap in JavaScript Performance
The Next Leap in JavaScript PerformanceThe Next Leap in JavaScript Performance
The Next Leap in JavaScript PerformanceIntel® Software
 
JIT Spraying Never Dies - Bypass CFG By Leveraging WARP Shader JIT Spraying.pdf
JIT Spraying Never Dies - Bypass CFG By Leveraging WARP Shader JIT Spraying.pdfJIT Spraying Never Dies - Bypass CFG By Leveraging WARP Shader JIT Spraying.pdf
JIT Spraying Never Dies - Bypass CFG By Leveraging WARP Shader JIT Spraying.pdfSamiraKids
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll buildMark Stoodley
 
Power of WebGL (FSTO 2014)
Power of WebGL (FSTO 2014)Power of WebGL (FSTO 2014)
Power of WebGL (FSTO 2014)Verold
 
On component interface
On component interfaceOn component interface
On component interfaceLaurence Chen
 
Node.js Presentation
Node.js PresentationNode.js Presentation
Node.js PresentationExist
 
Parallel Futures of a Game Engine (v2.0)
Parallel Futures of a Game Engine (v2.0)Parallel Futures of a Game Engine (v2.0)
Parallel Futures of a Game Engine (v2.0)Johan Andersson
 
Skiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DSkiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DMithun Hunsur
 
Interactive 3D graphics for web with three.js, Andrey Vedilin, DataArt
Interactive  3D graphics for web with three.js, Andrey Vedilin, DataArtInteractive  3D graphics for web with three.js, Andrey Vedilin, DataArt
Interactive 3D graphics for web with three.js, Andrey Vedilin, DataArtAlina Vilk
 
Castle Game Engine and the joy of making and using a custom game engine
Castle Game Engine and the joy  of making and using a custom game engineCastle Game Engine and the joy  of making and using a custom game engine
Castle Game Engine and the joy of making and using a custom game engineMichalis Kamburelis
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5David Voyles
 
HTML5 New Features and Resources
HTML5 New Features and ResourcesHTML5 New Features and Resources
HTML5 New Features and ResourcesRon Reiter
 

Similar a mloc.js 2014 - JavaScript and the browser as a platform for game development (20)

Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I
 
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...
 
JS Fest 2019. Денис Радин. AAA 3D графика в Web с ReactJS, BabylonJS и Unity3D
JS Fest 2019. Денис Радин. AAA 3D графика в Web с ReactJS, BabylonJS и Unity3DJS Fest 2019. Денис Радин. AAA 3D графика в Web с ReactJS, BabylonJS и Unity3D
JS Fest 2019. Денис Радин. AAA 3D графика в Web с ReactJS, BabylonJS и Unity3D
 
Developing games and graphic visualizations in Pascal
Developing games and graphic visualizations in PascalDeveloping games and graphic visualizations in Pascal
Developing games and graphic visualizations in Pascal
 
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
 
C++ on the Web: Run your big 3D game in the browser
C++ on the Web: Run your big 3D game in the browserC++ on the Web: Run your big 3D game in the browser
C++ on the Web: Run your big 3D game in the browser
 
The Next Leap in JavaScript Performance
The Next Leap in JavaScript PerformanceThe Next Leap in JavaScript Performance
The Next Leap in JavaScript Performance
 
JIT Spraying Never Dies - Bypass CFG By Leveraging WARP Shader JIT Spraying.pdf
JIT Spraying Never Dies - Bypass CFG By Leveraging WARP Shader JIT Spraying.pdfJIT Spraying Never Dies - Bypass CFG By Leveraging WARP Shader JIT Spraying.pdf
JIT Spraying Never Dies - Bypass CFG By Leveraging WARP Shader JIT Spraying.pdf
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll build
 
Power of WebGL (FSTO 2014)
Power of WebGL (FSTO 2014)Power of WebGL (FSTO 2014)
Power of WebGL (FSTO 2014)
 
On component interface
On component interfaceOn component interface
On component interface
 
Node.js Presentation
Node.js PresentationNode.js Presentation
Node.js Presentation
 
Parallel Futures of a Game Engine (v2.0)
Parallel Futures of a Game Engine (v2.0)Parallel Futures of a Game Engine (v2.0)
Parallel Futures of a Game Engine (v2.0)
 
Skiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DSkiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in D
 
Interactive 3D graphics for web with three.js, Andrey Vedilin, DataArt
Interactive  3D graphics for web with three.js, Andrey Vedilin, DataArtInteractive  3D graphics for web with three.js, Andrey Vedilin, DataArt
Interactive 3D graphics for web with three.js, Andrey Vedilin, DataArt
 
Castle Game Engine and the joy of making and using a custom game engine
Castle Game Engine and the joy  of making and using a custom game engineCastle Game Engine and the joy  of making and using a custom game engine
Castle Game Engine and the joy of making and using a custom game engine
 
Node azure
Node azureNode azure
Node azure
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
 
HTML5 New Features and Resources
HTML5 New Features and ResourcesHTML5 New Features and Resources
HTML5 New Features and Resources
 
HTML5 Game Development frameworks overview
HTML5 Game Development frameworks overviewHTML5 Game Development frameworks overview
HTML5 Game Development frameworks overview
 

Último

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

mloc.js 2014 - JavaScript and the browser as a platform for game development

  • 1. JavaScript and the browser as a platform for game development David Galeano mloc.js 2014
  • 2. David Galeano ● Co-founder and CTO of Turbulenz Limited since 2009 ● Technical Director of EA Tech Graphics ● Team leader of RenderWare Graphics ● Game developer at Dinamic Multimedia ● In the video game industry since 1995 ○ Worked on many platforms ○ Worked on many technology domains ○ Worked with many programming languages ○ Worked with many operating systems
  • 3. We have built the first high performance Internet generation game engine and web service called the Turbulenz platform. ● An industry leading HTML5 JavaScript 2D + 3D game engine ● A web service for social and game APIs accessible across all platforms ● A developer service for the publishing of content online ● An ultra modern destination for playing games with friends online ● Seamlessly working across desktops, browsers, mobiles and tablets We are relaunching our consumer HTML5 game site this year (in beta now), try it here: https://ga.me About Turbulenz
  • 4. What is possible today JavaScript in the browser is a viable platform for game development. We can create high quality games. The different layers between you and the hardware do affect performance, but not as much as in the past and the GPU is closer than ever. These are some examples of what is possible today with JavaScript in the browser: ● Third Person Action Game (Polycraft) ● First Person Shooter Demo (Quake 4 assets)
  • 5. Polycraft ● Developed by Wonderstruck ● Persistent island game combining arcade and strategy ga.me/games/polycraft
  • 6. Polycraft Challenges ● ~200K lines of code (ignoring comments or blank lines) ○ Misspelled properties, missing arguments, wrong argument type, etc. ○ JSLint, JSHint, IDEs code intelligence help a lot but still not perfect ● Level meshes built from thousands of small pieces in the in-game editor ○ Would be CPU limited because of number of draw calls ○ These are merged into 32x32m blocks ● Hundreds of dynamic renderables for complex bases ○ Would also be CPU limited because of number of draw calls ○ Uses pseudo-instancing, with up to 32 copies of meshes, to reduce draw calls for common objects such as walls ○ Cut render calls by ~1/3, 10-20% total speedup ● Mostly GPU limited because of expensive lighting model
  • 7. Quake 4 Demo ● Original game developed by Raven Software and id Software ● Multi Platform: Xbox 360, Windows, Linux, Mac OS X ● Just a demo to show that we can deliver similar visual quality to native applications
  • 8. Quake 4 Demo Challenges ● 1694 assets to load ○ Compression: 7-Zip better than gzip ○ Caching to reduce HTTP request: assets with unique names to be cached for 10 years ○ Archives to reduce HTTP requests overhead: group textures into tar files ● 353 lights, 346 particle systems ○ Culling: portals, bounding box trees ● 55 shading techniques, 451 materials ○ Minimize state changes: sort by technique and material ● Mostly CPU limited because of scene complexity ○ Some rooms have dozens of lights casting shadows
  • 9. What we need for the future To make JavaScript and the browser the ultimate platform for game development, what else is needed? Many things, but I am not going to talk today about monetization, mobile browsers, copyright protection, anti-cheating, etc. I am just going to focus on JavaScript performance. Where is the performance gap with native applications? ● Memory usage ● Parallelism ● Improved floating point performance
  • 10. Memory Usage Memory overhead still too high for standard JS objects. More memory means more cache misses and potentially running out of memory and / or paging to disk. Manually storing complex objects on typed arrays is hard to maintain. Typed objects could be the solution http://wiki.ecmascript.org/doku.php?id=harmony:typed_objects We want to write code like this: const Point2D = new StructType({ x: uint16, y: uint16 }); const Vector2D = new StructType({ x: int32, y: int32 }); const Color = new StructType({ r: uint8, g: uint8, b: uint8, a: uint8 }); const Pixel = new StructType({ point: Point2D, color: Color }); let a = Pixel({ point: { x: 0, y: 0 }, color: { r: 255, g: 255, b: 255, a: 255 } }); let b = Pixel({ point: { x: 1, y: 1 }, color: { r: 0, g: 255, b: 0, a: 255 } }); let a2b = Vector2D({ x: (b.point.x - a.point.x), y: (b.point.y - a.point.y) });
  • 11. Memory Usage... Instead of code like this: We also need a way to prefetch memory ahead of time when iterating over arrays of typed objects, this is still fundamental in order to reduce cache misses. // PhysicsContact // [0, 3) : localA (vector3) // [3, 6) : localB (vector3) ... // [22,25) : Jacobian : normal x relA * iInertiaA (vector3) // [25,28) : Jacobian : normal x relB * iInertiaB (vector3) ... // [50,51) : bounce // [51,52) : new … var contact = new Float32Array(52); … var ra0 = contact[6]; var ra1 = contact[7]; var ra2 = contact[8]; …. contact[22] = ((A0 * ca0) + (A3 * ca1) + (A6 * ca2)); contact[23] = ((A1 * ca0) + (A4 * ca1) + (A7 * ca2)); contact[24] = ((A2 * ca0) + (A5 * ca1) + (A8 * ca2));
  • 12. Parallelism We need to take advantage of multiple cores, even my phone has 4 of them! Web Workers are not perfect: ● Data can be transferred but not shared ○ Requires data duplication in many cases ○ Being able to share read-only data could help ● Threads communicate by messages ○ Hard to visualize and maintain complex trees of task dependencies ● Hacky-ish way of embedding Web Worker code ○ Not all browsers supporting Web Workers allow you to create Blob URLs ● Number of CPU cores is not exposed ○ Easy to oversubscribe or undersubscribe
  • 13. Parallelism... Parallel Array (River Trail) is useful but limited http://wiki.ecmascript.org/doku.php?id=strawman:data_parallelism ● Requiring elemental functions may limit the kind of problems you can solve with them ● Every parallel operation generates a new array ○ It would be better to be able to provide a destination array ● Some browsers will not like the fact that parallel operations are blocking ● Would you be able to debug it? WebCL is more powerful than Parallel Array http://www.khronos.org/webcl/ ● Allows non-blocking operations ● Total control over source and destination buffers ● But OpenCL kernels can only be debugged outside the browser ● Still limited in the kind of code it can execute in parallel ● And we have no idea if / when it would be available without requiring a plugin…
  • 14. Parallelism... Ideal API would provide a task management system based on data access and ownership ● Tasks would be declared to operate on specific buffers with specific read / write requirements ● Task manager will build dependency tree based on task order and data access requirements ● Task manager will distribute individual tasks among all available cores This is similar to how some declarative build systems work, you declare all the tasks and their explicit dependencies and the build system takes care of building everything in parallel in the right order. We implemented systems like that for PS3, Xbox360 and PC, they scale really well, the overhead of the task manager is minimal unless you create thousands of tasks per frame. Could be partially implemented with Web Workers but it will never be as optimal as a native implementation because of the limitations previously described.
  • 15. Improved floating point performance Games spend most of their time doing floating point operations but we are not taking advantage of the full potential of modern CPUs. 32-bit floating point operations ● Most games do not need 64-bit floating point operations but JS standard requires it ● Early experiments using Math.fround show 10-20% improvement ● But it is expensive to modify thousands of existing lines of code to add Math.fround everywhere ○ contact[22] = (Math.fround(Math.fround(A0 * ca0) + Math.fround(A3 * ca1)) + Math.fround(A6 * ca2)); ● Would be simpler for game developers if language spec could be relaxed to allow 32-bit operations when the final result of a sequence of operations is stored to a 32-bit location SIMD ● Many vector and matrix operations could be optimized with SIMD instructions ● Would need good integration with Typed Arrays and/or Typed Objects ● Exiting proposal has limited types, Mono.Simd is more thorough ○ https://github.com/johnmccutchan/ecmascript_simd ○ http://docs.go-mono.com/?link=N%3aMono.Simd ● Also expensive to modify existing vector math libraries to use it ○ But gains should be bigger and probably worth it
  • 16. Improved floating point performance Crazy idea: runtime settings? ● “use single-precision”; ● “use fast-math”; Native applications have access to compiler settings that can be used to tune code generation for speed. For example, GCC has “-ffast-math” and Visual Studio has “/fp:fast” to relax the rules on floating point operations, allowing optimizations that may not generate precise results but good enough in many cases.
  • 17. Questions & Answers Game site: https://ga.me Twitter: @turbulenz @wonderstruck_uk Developer site: http://biz.turbulenz.com David Galeano: @davidgaleano davidgaleano@turbulenz.com Open Source Turbulenz Engine: https://github.com/turbulenz/turbulenz_engine Online Turbulenz Engine documentation: http://docs.turbulenz.com