data-oriented design and c++ - 游戏程序员的自我修养 · data-oriented design and c++ mike...
TRANSCRIPT
![Page 1: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/1.jpg)
Data-Oriented Design and C++
Mike ActonEngine Director, Insomniac Games
@mike_acton
![Page 2: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/2.jpg)
A bit of background…
![Page 3: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/3.jpg)
What does an “Engine” team do?
![Page 4: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/4.jpg)
Runtime systems
e.g.• Rendering• Animation and gestures• Streaming• Cinematics• VFX• Post-FX• Navigation• Localization• …many, many more!
![Page 5: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/5.jpg)
Development tools
e.g.• Level creation• Lighting• Material editing• VFX creation• Animation/state machine editing• Visual scripting• Scene painting• Cinematics creation• …many, many more!
![Page 6: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/6.jpg)
What’s important to us?
![Page 7: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/7.jpg)
What’s important to us?
• Hard deadlines
![Page 8: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/8.jpg)
What’s important to us?
• Hard deadlines
• Soft realtime performance requirements (Soft=33ms)
![Page 9: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/9.jpg)
What’s important to us?
• Hard deadlines
• Soft realtime performance requirements (Soft=33ms)
• Usability
![Page 10: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/10.jpg)
What’s important to us?
• Hard deadlines
• Soft realtime performance requirements (Soft=33ms)
• Usability
• Performance
![Page 11: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/11.jpg)
What’s important to us?
• Hard deadlines
• Soft realtime performance requirements (Soft=33ms)
• Usability
• Performance
• Maintenance
![Page 12: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/12.jpg)
What’s important to us?
• Hard deadlines
• Soft realtime performance requirements (Soft=33ms)
• Usability
• Performance
• Maintenance
• Debugability
![Page 13: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/13.jpg)
What languages do we use…?
![Page 14: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/14.jpg)
What languages do we use…?
• C
• C++
• Asm
• Perl
• Javascript
• C#
![Page 15: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/15.jpg)
What languages do we use…?
• C
• C++ ~70%
• Asm
• Perl
• Javascript
• C#
![Page 16: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/16.jpg)
What languages do we use…?
• C
• C++ ~70%
• Asm
• Perl
• Javascript
• C#
• Pixel shaders, vertex shaders, geometry shaders, compute shaders, …
![Page 17: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/17.jpg)
We don’t make games for Mars but…
![Page 18: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/18.jpg)
How are games like the Mars rovers?
![Page 19: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/19.jpg)
How are games like the Mars rovers?
•Exceptions
![Page 20: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/20.jpg)
How are games like the Mars rovers?
•Exceptions
•Templates
![Page 21: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/21.jpg)
How are games like the Mars rovers?
•Exceptions
•Templates
• Iostream
![Page 22: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/22.jpg)
How are games like the Mars rovers?
•Exceptions
•Templates
• Iostream
•Multiple inheritance
![Page 23: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/23.jpg)
How are games like the Mars rovers?
•Exceptions
•Templates
• Iostream
•Multiple inheritance
•Operator overloading
![Page 24: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/24.jpg)
How are games like the Mars rovers?
•Exceptions
•Templates
• Iostream
•Multiple inheritance
•Operator overloading
•RTTI
![Page 25: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/25.jpg)
How are games like the Mars rovers?
•No STL
![Page 26: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/26.jpg)
How are games like the Mars rovers?
•No STL
•Custom allocators (lots)
![Page 27: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/27.jpg)
How are games like the Mars rovers?
•No STL
•Custom allocators (lots)
•Custom debugging tools
![Page 28: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/28.jpg)
Is data-oriented even a thing…?
![Page 29: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/29.jpg)
Data-Oriented Design Principles
The purpose of all programs, and all parts of those programs, is to transform data from one form to another.
![Page 30: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/30.jpg)
Data-Oriented Design Principles
If you don’t understand the data you don’t understand the problem.
![Page 31: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/31.jpg)
Data-Oriented Design Principles
Conversely, understand the problem by understanding the data.
![Page 32: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/32.jpg)
Data-Oriented Design Principles
Different problems require different solutions.
![Page 33: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/33.jpg)
Data-Oriented Design Principles
If you have different data, you have a different problem.
![Page 34: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/34.jpg)
Data-Oriented Design Principles
If you don’t understand the cost of solving the problem, you don’t understand the problem.
![Page 35: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/35.jpg)
Data-Oriented Design Principles
If you don’t understand the hardware, you can’t reason about the cost of solving the problem.
![Page 36: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/36.jpg)
Data-Oriented Design Principles
Everything is a data problem. Including usability, maintenance, debug-ability, etc. Everything.
![Page 37: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/37.jpg)
Data-Oriented Design Principles
Solving problems you probably don’t have creates more problems you definitely do.
![Page 38: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/38.jpg)
Data-Oriented Design Principles
Latency and throughput are only the same in sequential systems.
![Page 39: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/39.jpg)
Data-Oriented Design Principles
Latency and throughput are only the same in sequential systems.
![Page 40: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/40.jpg)
Data-Oriented Design Principles
Rule of thumb: Where there is one, there are many. Try looking on the time axis.
![Page 41: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/41.jpg)
Data-Oriented Design Principles
Rule of thumb: The more context you have, the better you can make the solution. Don’t throw away data you need.
![Page 42: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/42.jpg)
Data-Oriented Design Principles
Rule of thumb: NUMA extends to I/O and pre-built data all the way back through time to original source creation.
![Page 43: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/43.jpg)
Data-Oriented Design Principles
Software does not run in a magic fairy aether powered by the fevered dreams of CS PhDs.
![Page 44: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/44.jpg)
Is data-oriented even a thing…?
…certainly not new ideas.
…more of a reminder of first principles.
![Page 45: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/45.jpg)
…but it is a response to the culture of C++
![Page 46: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/46.jpg)
…but it is a response to the culture of C++
…and The Three Big Lies it has engendered
![Page 47: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/47.jpg)
![Page 48: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/48.jpg)
![Page 49: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/49.jpg)
![Page 50: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/50.jpg)
![Page 51: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/51.jpg)
![Page 52: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/52.jpg)
![Page 53: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/53.jpg)
![Page 54: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/54.jpg)
![Page 55: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/55.jpg)
![Page 56: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/56.jpg)
![Page 57: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/57.jpg)
![Page 58: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/58.jpg)
![Page 59: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/59.jpg)
![Page 60: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/60.jpg)
![Page 61: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/61.jpg)
![Page 62: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/62.jpg)
![Page 63: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/63.jpg)
![Page 64: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/64.jpg)
i.e. Programmer’s job is NOT to write code; Programmer’s job is to solve (data transformation) problems
![Page 65: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/65.jpg)
![Page 66: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/66.jpg)
![Page 67: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/67.jpg)
![Page 68: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/68.jpg)
![Page 69: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/69.jpg)
![Page 70: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/70.jpg)
![Page 71: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/71.jpg)
![Page 72: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/72.jpg)
A simple example…
![Page 73: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/73.jpg)
![Page 74: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/74.jpg)
![Page 75: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/75.jpg)
![Page 76: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/76.jpg)
![Page 77: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/77.jpg)
![Page 78: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/78.jpg)
![Page 79: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/79.jpg)
![Page 80: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/80.jpg)
![Page 81: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/81.jpg)
![Page 82: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/82.jpg)
Solve for the most common case first,Not the most generic.
![Page 83: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/83.jpg)
“Can’t the compiler do it?”
![Page 84: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/84.jpg)
A little review…
![Page 85: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/85.jpg)
http://www.agner.org/optimize/instruction_tables.pdf
(AMD Piledriver)
![Page 86: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/86.jpg)
http://www.agner.org/optimize/instruction_tables.pdf
(AMD Piledriver)
![Page 87: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/87.jpg)
http://research.scee.net/files/presentations/gcapaustralia09/Pitfalls_of_Object_Oriented_Programming_GCAP_09.pdf
![Page 88: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/88.jpg)
http://www.gameenginebook.com/SINFO.pdf
![Page 89: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/89.jpg)
The Battle of North Bridge
L1
L2
RAM
![Page 90: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/90.jpg)
L2 cache misses/frame(Most significant component)
![Page 91: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/91.jpg)
Not even including shared memory modes…
NameGPU-visible
CachedGPU Coherent
Heap-cacheable No Yes No
Heap-write-combined No No No
Physical-uncached ? No No
GPU-write-combined Yes No No
GPU-write-combined-read-only Yes No No
GPU-cacheable Yes Yes Yes
GPU-cacheable-noncoherent-RO Yes Yes No
Command-write-combined No No No
Command-cacheable No Yes Yes
![Page 92: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/92.jpg)
http://deplinenoise.wordpress.com/2013/12/28/optimizable-code/
![Page 93: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/93.jpg)
![Page 94: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/94.jpg)
2 x 32bit read; same cache line = ~200
![Page 95: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/95.jpg)
Float mul, add = ~10
![Page 96: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/96.jpg)
Let’s assume callq is replaced. Sqrt = ~30
![Page 97: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/97.jpg)
Mul back to same addr; in L1; = ~3
![Page 98: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/98.jpg)
Read+add from new line= ~200
![Page 99: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/99.jpg)
Time spent waiting for L2 vs. actual work
~10:1
![Page 100: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/100.jpg)
Time spent waiting for L2 vs. actual work
~10:1
This is the compiler’s space.
![Page 101: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/101.jpg)
Time spent waiting for L2 vs. actual work
~10:1
This is the compiler’s space.
![Page 102: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/102.jpg)
Compiler cannot solve the most significant problems.
![Page 103: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/103.jpg)
Today’s subject: The 90% of problem space we
need to solve that the compiler cannot.
(And how we can help it with the 10% that it can.)
![Page 104: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/104.jpg)
Simple, obvious things to look for + Back of the envelope calculations
= Substantial wins
![Page 105: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/105.jpg)
L2 cache misses/frame(Don’t waste them!)
![Page 106: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/106.jpg)
Waste 56 bytes / 64 bytes
![Page 107: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/107.jpg)
Waste 60 bytes / 64 bytes
![Page 108: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/108.jpg)
90% waste!
![Page 109: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/109.jpg)
Alternatively,Only 10% capacity used*
* Not the same as “used well”, but we’ll start here.
![Page 110: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/110.jpg)
![Page 111: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/111.jpg)
12 bytes x count(5) = 72
![Page 112: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/112.jpg)
12 bytes x count(5) = 72
4 bytes x count(5) = 20
![Page 113: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/113.jpg)
12 bytes x count(32) = 384 = 64 x 6
4 bytes x count(32) = 128 = 64 x 2
![Page 114: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/114.jpg)
12 bytes x count(32) = 384 = 64 x 6
4 bytes x count(32) = 128 = 64 x 2
(6/32) = ~5.33 loop/cache line
![Page 115: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/115.jpg)
12 bytes x count(32) = 384 = 64 x 6
4 bytes x count(32) = 128 = 64 x 2
Sqrt + math = ~40 x 5.33 = 213.33 cycles/cache line(6/32) = ~5.33 loop/cache line
![Page 116: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/116.jpg)
12 bytes x count(32) = 384 = 64 x 6
4 bytes x count(32) = 128 = 64 x 2
Sqrt + math = ~40 x 5.33 = 213.33 cycles/cache line(6/32) = ~5.33 loop/cache line
+ streaming prefetch bonus
![Page 117: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/117.jpg)
12 bytes x count(32) = 384 = 64 x 6
4 bytes x count(32) = 128 = 64 x 2
Sqrt + math = ~40 x 5.33 = 213.33 cycles/cache line(6/32) = ~5.33 loop/cache line
+ streaming prefetch bonus
Using cache line to capacity* =10x speedup
* Used. Still not necessarily as efficiently as possible
![Page 118: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/118.jpg)
Sqrt + math = ~40 x 5.33 = 213.33 cycles/cache line(6/32) = ~5.33 loop/cache line
+ streaming prefetch bonus
In addition…1. Code is maintainable
2. Code is debugable3. Can REASON about cost of change
![Page 119: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/119.jpg)
Sqrt + math = ~40 x 5.33 = 213.33 cycles/cache line(6/32) = ~5.33 loop/cache line
+ streaming prefetch bonus
In addition…1. Code is maintainable
2. Code is debugable3. Can REASON about cost of change
Ignoring inconvenient facts is not engineering;It’s dogma.
![Page 120: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/120.jpg)
bools in structs… (3) Extremely low information density
![Page 121: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/121.jpg)
bools in structs… (3) Extremely low information density
How big is your cache line?
![Page 122: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/122.jpg)
bools in structs… (3) Extremely low information density
How big is your cache line?
What’s the most commonly accessed data?
64b?
![Page 123: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/123.jpg)
(2) Bools and last-minute decision makingHow is it used? What does it generate?
![Page 124: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/124.jpg)
MSVC
![Page 125: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/125.jpg)
MSVC
Re-read and re-test…
Increment and loop…
![Page 126: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/126.jpg)
Re-read and re-test…
Increment and loop…
Why?
Super-conservative aliasing rules…?Member value might change?
![Page 127: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/127.jpg)
What about something more aggressive…?
![Page 128: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/128.jpg)
Test once and return…
What about something more aggressive…?
![Page 129: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/129.jpg)
Okay, so what about…
![Page 130: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/130.jpg)
…well at least it inlined it?
![Page 131: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/131.jpg)
MSVC doesn’t fare any better…
![Page 132: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/132.jpg)
Don’t re-read member values or re-call functions whenyou already have the data.
(4) Ghost reads and writes
![Page 133: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/133.jpg)
BAM!
![Page 134: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/134.jpg)
:(
![Page 135: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/135.jpg)
(4) Ghost reads and writes
Don’t re-read member values or re-call functions whenyou already have the data.
Hoist all loop-invariant reads and branches. Even super-obvious ones that should already be in registers.
![Page 136: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/136.jpg)
:)
![Page 137: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/137.jpg)
:)
A bit of unnecessary branching, but more-or-less equivalent.
![Page 138: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/138.jpg)
(4) Ghost reads and writes
Don’t re-read member values or re-call functions whenyou already have the data.
Hoist all loop-invariant reads and branches. Even super-obvious ones that should already be in registers.
Applies to any member fields especially. (Not particular to bools)
![Page 139: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/139.jpg)
(3) Extremely low information density
![Page 140: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/140.jpg)
(3) Extremely low information density
What is the information density for is_spawnover time?
![Page 141: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/141.jpg)
(3) Extremely low information density
What is the information density for is_spawnover time?
The easy way.
![Page 142: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/142.jpg)
![Page 143: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/143.jpg)
Zip the output10,000 frames= 915 bytes= (915*8)/10,000= 0.732 bits/frame
![Page 144: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/144.jpg)
Zip the output10,000 frames= 915 bytes= (915*8)/10,000= 0.732 bits/frame
Alternatively,Calculate Shannon Entropy:
![Page 145: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/145.jpg)
(3) Extremely low information density
What does that tell us?
![Page 146: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/146.jpg)
(3) Extremely low information density
What does that tell us?
Figure (~2 L2 misses each frame ) x 10,000If each cache line = 64b,128b x 10,000 = 1,280,000 bytes
![Page 147: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/147.jpg)
(3) Extremely low information density
What does that tell us?
Figure (~2 L2 misses each frame ) x 10,000If each cache line = 64b,128b x 10,000 = 1,280,000 bytes
If avg information content = 0.732bits/frameX 10,000 = 7320 bits/ 8 = 915 bytes
![Page 148: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/148.jpg)
(3) Extremely low information density
What does that tell us?
Figure (~2 L2 misses each frame ) x 10,000If each cache line = 64b,128b x 10,000 = 1,280,000 bytes
If avg information content = 0.732bits/frameX 10,000 = 7320 bits/ 8 = 915 bytes
Percentage waste (Noise::Signal) =(1,280,000-915)/1,280,000
![Page 149: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/149.jpg)
What’re the alternatives?
![Page 150: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/150.jpg)
(1) Per-frame…
![Page 151: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/151.jpg)
(1) Per-frame…
1 of 512 (8*64) bits used…
(decision table)
![Page 152: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/152.jpg)
(1) Per-frame…
1 of 512 (8*64) bits used…
(decision table)
(a) Make same decision x 512
![Page 153: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/153.jpg)
(1) Per-frame…
1 of 512 (8*64) bits used…
(decision table)
(a) Make same decision x 512
(b) Combine with other reads / xforms
![Page 154: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/154.jpg)
(1) Per-frame…
1 of 512 (8*64) bits used…
(decision table)
(a) Make same decision x 512
(b) Combine with other reads / xforms
Generally simplest. - But things cannot exist in abstract bubble.- Will require context.
![Page 155: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/155.jpg)
(2) Over-frames…
![Page 156: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/156.jpg)
(2) Over-frames…
i.e. Only read when needed
![Page 157: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/157.jpg)
(2) Over-frames…
i.e. Only read when needed
e.g.
Arrays of command buffers for future frames…
![Page 158: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/158.jpg)
Let’s review some code…
![Page 159: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/159.jpg)
![Page 160: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/160.jpg)
http://yosoygames.com.ar/wp/2013/11/on-mike-actons-review-of-ogrenode-cpp/
![Page 161: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/161.jpg)
![Page 162: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/162.jpg)
(1) Can’t re-arrange memory (much)
Limited by ABI
Can’t limit unused reads
Extra padding
![Page 163: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/163.jpg)
(2) Bools and last-minute decision making
![Page 164: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/164.jpg)
Are we done with the constructor?
(5) Over-generalization
![Page 165: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/165.jpg)
Are we done with the constructor?
(5) Over-generalization
Complex constructors tend to imply that…- Reads are unmanaged (one at a time…)
![Page 166: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/166.jpg)
Are we done with the constructor?
(5) Over-generalization
Complex constructors tend to imply that…- Reads are unmanaged (one at a time…)- Unnecessary reads/writes in destructors
![Page 167: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/167.jpg)
Are we done with the constructor?
(5) Over-generalization
Complex constructors tend to imply that…- Reads are unmanaged (one at a time…)- Unnecessary reads/writes in destructors- Unmanaged icache (i.e. virtuals)
=> unmanaged reads/writes
![Page 168: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/168.jpg)
Are we done with the constructor?
(5) Over-generalization
Complex constructors tend to imply that…- Reads are unmanaged (one at a time…)- Unnecessary reads/writes in destructors- Unmanaged icache (i.e. virtuals)
=> unmanaged reads/writes- Unnecessarily complex state machines (back to bools)
- E.g. 2^7 states
![Page 169: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/169.jpg)
Are we done with the constructor?
(5) Over-generalization
Complex constructors tend to imply that…- Reads are unmanaged (one at a time…)- Unnecessary reads/writes in destructors- Unmanaged icache (i.e. virtuals)
=> unmanaged reads/writes- Unnecessarily complex state machines (back to bools)
- E.g. 2^7 states
Rule of thumb:Store each state type separately
Store same states together(No state value needed)
![Page 170: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/170.jpg)
Are we done with the constructor?
(5) Over-generalization
(6) Undefined or under-defined constraints
![Page 171: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/171.jpg)
Are we done with the constructor?
(5) Over-generalization
(6) Undefined or under-defined constraints
Imply more (wasted) reads because pretending youdon’t know what it could be.
![Page 172: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/172.jpg)
Are we done with the constructor?
(5) Over-generalization
(6) Undefined or under-defined constraints
Imply more (wasted) reads because pretending youdon’t know what it could be.
e.g. Strings, generally. Filenames, in particular.
![Page 173: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/173.jpg)
Are we done with the constructor?
(5) Over-generalization
(6) Undefined or under-defined constraints
Imply more (wasted) reads because pretending youdon’t know what it could be.
e.g. Strings, generally. Filenames, in particular.
Rule of thumb:The best code is code that doesn’t need to exist.
Do it offline. Do it once.e.g. precompiled string hashes
![Page 174: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/174.jpg)
Are we done with the constructor?
(5) Over-generalization
(6) Undefined or under-defined constraints
(7) Over-solving (computing too much)
Compiler doesn’t have enough context to know how to simplify your problems for you.
![Page 175: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/175.jpg)
Are we done with the constructor?
(5) Over-generalization
(6) Undefined or under-defined constraints
(7) Over-solving (computing too much)
Compiler doesn’t have enough context to know how to simplify your problems for you.
But you can make simple tools that do…- E.g. Premultiply matrices
![Page 176: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/176.jpg)
Are we done with the constructor?
(5) Over-generalization
(6) Undefined or under-defined constraints
(7) Over-solving (computing too much)
Compiler doesn’t have enough context to know how to simplify your problems for you.
But you can make simple tools that do…- E.g. Premultiply matrices
Work with the (actual) data you have.- E.g. Sparse or affine matrices
![Page 177: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/177.jpg)
How do we approach “fixing” it?
![Page 178: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/178.jpg)
![Page 179: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/179.jpg)
(2) Bools and last-minute decision making
![Page 180: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/180.jpg)
Step 1: organizeSeparate states so you can reason about them
![Page 181: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/181.jpg)
Step 1: organizeSeparate states so you can reason about them
Step 2: triageWhat are the relative values of each casei.e. p(call) * count
![Page 182: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/182.jpg)
Step 1: organizeSeparate states so you can reason about them
Step 2: triageWhat are the relative values of each casei.e. p(call) * count
e.g. in-game vs. in-editor
![Page 183: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/183.jpg)
Step 1: organizeSeparate states so you can reason about them
Step 2: triageWhat are the relative values of each casei.e. p(call) * count
Step 3: reduce waste
![Page 184: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/184.jpg)
~200 cycles x 2 x count
(back of the envelope read cost)
![Page 185: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/185.jpg)
~200 cycles x 2 x count
~2.28 count per 200 cycles= ~88
(back of the envelope read cost)
![Page 186: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/186.jpg)
~200 cycles x 2 x count
~2.28 count per 200 cycles= ~88
(back of the envelope read cost)
t = 2 * cross(q.xyz, v)
v' = v + q.w * t + cross(q.xyz, t)
![Page 187: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/187.jpg)
~200 cycles x 2 x count
~2.28 count per 200 cycles= ~88
(back of the envelope read cost)
t = 2 * cross(q.xyz, v)
v' = v + q.w * t + cross(q.xyz, t)
(close enough to dig in andmeasure)
![Page 188: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/188.jpg)
Apply the same steps recursively…
![Page 189: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/189.jpg)
Apply the same steps recursively…
Step 1: organizeSeparate states so you can reason about them
Root or not; Calling function with context can distinguish
![Page 190: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/190.jpg)
Apply the same steps recursively…
Step 1: organizeSeparate states so you can reason about them
Root or not; Calling function with context can distinguish
![Page 191: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/191.jpg)
Apply the same steps recursively…
Step 1: organizeSeparate states so you can reason about them
![Page 192: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/192.jpg)
Apply the same steps recursively…
Step 1: organizeSeparate states so you can reason about them
Can’t reason well about the cost from…
![Page 193: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/193.jpg)
Step 1: organizeSeparate states so you can reason about them
![Page 194: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/194.jpg)
Step 1: organizeSeparate states so you can reason about them
Step 2: triageWhat are the relative values of each casei.e. p(call) * count
Step 3: reduce waste
![Page 195: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/195.jpg)
Good News:Most problems are
easy to see.
![Page 196: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/196.jpg)
Good News:Side-effect of solving the 90%
well, compiler can solve the 10% better.
![Page 197: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/197.jpg)
Good News:Organized data makes
maintenance, debugging and concurrency much easier
![Page 198: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/198.jpg)
Bad News:Good programming is hard.Bad programming is easy.
![Page 199: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/199.jpg)
http://realtimecollisiondetection.net/blog/?p=81
http://realtimecollisiondetection.net/blog/?p=44
While we’re on the subject…DESIGN PATTERNS:
“
![Page 200: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/200.jpg)
![Page 201: Data-Oriented Design and C++ - 游戏程序员的自我修养 · Data-Oriented Design and C++ Mike Acton Engine Director, Insomniac Games ... •Javascript •C# •Pixel shaders,](https://reader036.vdocuments.us/reader036/viewer/2022062402/5f0514717e708231d4112906/html5/thumbnails/201.jpg)