Institutionen För Systemteknik Department of Electrical Engineering
Total Page:16
File Type:pdf, Size:1020Kb
Institutionen för systemteknik Department of Electrical Engineering Examensarbete Evaluation of multi-threading in Vulkan av Axel Blackert LiTH-ISY-EX-ET--16/0458--SE 2016-09-12 Linköpings universitet Linköpings universitet SE-581 83 Linköping, Sweden 581 83 Linköping Abstract Today processor development has a lot of focus on parallel performance by providing multiple cores that programs can use. The problem with the current version of OpenGL is that it lacks support for utilizing multiple CPU threads for calling rendering commands. Vulkan is a new low level graphics API that gives more control to the developers and provides tools to properly utilize multiple threads for doing rendering operations in parallel. This should give increased performance in situations where the CPU is limiting the performance of the application and the goal of this report is to evaluate how large these performance gains can be in different scenes. To do this evaluation a test program is written with both Vulkan and OpenGL implementations and by rendering the same scene using different APIs and techniques the performance can be compared. In addition to evaluating the multithreaded rendering performance the new explicit pipelines in Vulkan is also evaluated. Definitions CPU – Central Processing Unit GPU – Graphical Processing Unit API – Application Programming Interface FPS – Frames Per Second GLSL – OpenGL Shading Language 1 CONTENT Introduction ............................................................................................................................................. 1 1.1 Background ............................................................................................................................. 1 1.2 Purpose .................................................................................................................................... 1 1.3 Task ......................................................................................................................................... 1 1.4 Limitations .............................................................................................................................. 1 2 Theory ............................................................................................................................................. 2 2.1 Khronos Group ........................................................................................................................ 2 2.2 Vulkan ..................................................................................................................................... 2 2.3 Driver overhead ...................................................................................................................... 3 2.4 Platform independence ............................................................................................................ 3 2.5 Multithreading ......................................................................................................................... 3 2.5.1 No global state .................................................................................................................... 4 2.5.2 No synchronization in the drivers ....................................................................................... 4 2.5.3 Separation between generation and execution of rendering ................................................ 5 2.6 Rendering pipeline .................................................................................................................. 5 2.7 Instancing ................................................................................................................................ 6 2.8 3rd party libraries ..................................................................................................................... 6 2.8.1 GLM .................................................................................................................................... 6 2.8.2 Assimp ................................................................................................................................ 6 2.8.3 GLEW ................................................................................................................................. 6 2.8.4 TSBK07 utilities ................................................................................................................. 6 2.8.5 Sascha Willems utilities ...................................................................................................... 6 2.9 Previous Work ........................................................................................................................ 7 3 Method ............................................................................................................................................ 8 3.1 The resulting program ............................................................................................................. 8 3.2 Technical Terms ...................................................................................................................... 8 3.2.1 Vertex and fragment shaders ............................................................................................... 8 3.2.2 Shader uniforms .................................................................................................................. 8 3.2.3 Push constants ..................................................................................................................... 8 3.2.4 Command buffer ................................................................................................................. 8 3.2.5 Command pool .................................................................................................................... 8 3.3 Implementation details ............................................................................................................ 8 3.3.1 Rendering interface ............................................................................................................. 9 3.3.2 Creating the renderer ........................................................................................................... 9 3.3.3 Recording performance ..................................................................................................... 10 3.3.4 Vulkan renderer................................................................................................................. 10 3.3.5 OpenGL renderer .............................................................................................................. 10 3.3.6 Shader ............................................................................................................................... 10 3.3.7 Camera .............................................................................................................................. 10 3.3.8 Loading models ................................................................................................................. 11 3.4 Test system ............................................................................................................................ 11 3.5 Testing................................................................................................................................... 11 3.5.1 Multi-threading tests ......................................................................................................... 11 3.5.2 Pipeline management tests ................................................................................................ 12 4 Evaluation ...................................................................................................................................... 13 4.1 Low detail model tests .......................................................................................................... 13 4.1.1 Single threaded Vulkan, low detail model ........................................................................ 14 4.1.2 Four threads with Vulkan, low detail model ..................................................................... 14 4.1.3 Single threaded OpenGL, low res model .......................................................................... 15 4.2 High detail model test ........................................................................................................... 16 4.2.1 Single threaded Vulkan, high res model ........................................................................... 16 4.2.2 Four threaded Vulkan, high res model .............................................................................. 17 4.2.3 Single threaded OpenGL, high detail model ..................................................................... 18 4.3 Instancing .............................................................................................................................. 18 4.4 Pipeline swapping performance ............................................................................................ 18 4.4.1 Changing facing, culling and shader ................................................................................. 18 4.4.2 Changing facing and culling ............................................................................................. 19 5 Conclusion ..................................................................................................................................... 20 5.1 Multithreading ......................................................................................................................