
Hacking on Mesa 3D Eleni Maria Stea <[email protected]> Introduction to Mesa 3D/OpenGL The most widely used open source OpenGL/Vulkan implementation Eleni Maria Stea Hacking on Mesa 3D 2 / 26 Introduction to Mesa 3D/OpenGL Historical I It started as an open source (MIT license) software OpenGL implementation. • swrast: software rasterizer I Then some hardware drivers were added as backends. • Intel, AMD Radeon, Nouveau, VMware virtual GPU I More APIs, specifications were implemented. • Vulkan • OpenGL ES1, ES2 & ES3 • OpenCL, OpenVG, VDPAU, XVMC, EGL interface I More software drivers were written. • llvmpipe, softpipe Eleni Maria Stea Hacking on Mesa 3D 3 / 26 Introduction to Mesa 3D/OpenGL Mesa 3d is a big project :-) We are going to focus on the OpenGL development. Eleni Maria Stea Hacking on Mesa 3D 4 / 26 Introduction to Mesa 3D/OpenGL The OpenGL API as part of the Linux Graphics Stack Indirect Rendering GLX (OpenGL extension to the X window system) Direct Rendering DRI (Direct Rendering Infrastructure) DRM (Direct Rendering Manager) A combination of the two https://en.wikipedia.org/wiki/Mesa_(computer_graphics) GLX + AIGLX (Accelerated Indirect GLX) Eleni Maria Stea Hacking on Mesa 3D 5 / 26 Developing the OpenGL So, what’s our contribution to the OpenGL implementation? I we write extensions (16-bits etc) I we add new features for the extensions to work I testing and bug fixes I releases This means that we occasionally make changes to: I the mesa core I the glsl compiler I the hardware drivers I and anywhere else needed Eleni Maria Stea Hacking on Mesa 3D 6 / 26 Developing the OpenGL OpenGL Extensions 1/4 : The concept behind I OpenGL is extensible by design. I Any hardware manufacturer who wishes to add a new feature that was missing from OpenGL can write an extension to provide it. I Any user wishing to use the feature can then use the extension through the extension mechanism. I Khronos group (that releases the OpenGL spec) decides which extensions will become part of the next OpenGL core version. I The manufacturers that write their own OpenGL implementations (Nvidia, Apple, Intel/Mesa, AMD/Mesa etc) and wish to release that new version must implement all the extensions that have been decided to be part of the core. Eleni Maria Stea Hacking on Mesa 3D 7 / 26 Developing the OpenGL OpenGL Extensions 2/4: Τhe specs OpenGL Registry git clone https://github.com/KhronosGroup/OpenGL-Registry.git Extensions Specifications I overview, contributors etc I dependencies I errors I detailed descriptions Eleni Maria Stea Hacking on Mesa 3D 8 / 26 Developing the OpenGL OpenGL Extensions 3/4: Required changes Adding a new extension requires changes in the API, the hardware drivers code (see i965), to the GLSL compiler and elsewhere. $ ack-grep -i -l ARB_shader_storage_buffer_object mesa include/GL/glcorearb.h mesa/src/mapi/glapi/registry/gl.xml include/GL/glext.h mesa/src/mapi/glapi/gen/meson.build src/mapi/glapi/registry/gl.xml mesa/src/mapi/glapi/gen/Makefile.am src/mapi/glapi/gen/Makefile.am mesa/src/mapi/glapi/gen/Makefile src/mapi/glapi/gen/gl_API.xml src/mesa/drivers/dri/i965/intel_extensions.c mesa/src/mapi/glapi/gen/Makefile.in src/mesa/main/extensions_table.h mesa/src/mapi/glapi/gen/gl_API.xml src/mesa/main/context.c mesa/src/mesa/drivers/dri/i965/intel_extensions.c src/mesa/main/mtypes.h mesa/src/mesa/main/extensions_table.h mesa/src/mesa/main/context.c src/mesa/main/bufferobj.c src/mesa/main/get.c mesa/src/mesa/main/mtypes.h src/mesa/main/version.c mesa/src/mesa/main/bufferobj.c src/mesa/main/get_hash_params.py mesa/src/mesa/main/get.c mesa/src/mesa/main/version.c src/mesa/main/uniforms.c mesa/src/mesa/main/get_hash_params.py src/mesa/state_tracker/st_extensions.c src/compiler/glsl/glsl_lexer.ll mesa/src/mesa/main/uniforms.c src/compiler/glsl/ir.h mesa/src/mesa/state_tracker/st_extensions.c mesa/src/compiler/glsl/glsl_lexer.ll src/compiler/glsl/ast_function.cpp mesa/src/compiler/glsl/ir.h src/compiler/glsl/glsl_parser_extras.cpp src/compiler/glsl/glsl_parser_extras.h mesa/src/compiler/glsl/ast_function.cpp mesa/include/GL/glcorearb.h mesa/src/compiler/glsl/glsl_parser_extras.cpp mesa/include/GL/glext.h mesa/src/compiler/glsl/glsl_parser_extras.h Eleni Maria Stea Hacking on Mesa 3D 9 / 26 Developing the OpenGL GLSL/GLSL Compiler In the previous slide we mentioned a ... GLSL compiler What’s the purpose of using a compiler into a graphics API? Eleni Maria Stea Hacking on Mesa 3D 10 / 26 Developing the OpenGL Rendering με το OpenGL : how we use the API Remember that every OpenGL object is made by primitives! Eleni Maria Stea Hacking on Mesa 3D 11 / 26 Developing the OpenGL The OpenGL Pipeline : Fully Programmable using the GLSL http://chamilo2.grenet.fr/inp/courses/ENSIMAG4MMG3D/document/instructions/practical_01.html Eleni Maria Stea Hacking on Mesa 3D 12 / 26 Developing the OpenGL GLSL->GLSL IR->NIR->ASM From OpenGL Shading Language to Assembly I GLSL I GLSL IR I NIR : SSA (Single Static Assignment) + non SSA I Native Code Eleni Maria Stea Hacking on Mesa 3D 13 / 26 Developing the OpenGL GLSL->GLSL IR->NIR->ASM 1/4 Let us examine a very simple OpenGL program: GLSL attribute vec4 vertex; void main() { gl_Position = vertex; } GLSL IR ( (declare (location=0 shader_out ) vec4 gl_Position) (declare (location=17 shader_in ) vec4 vertex) ( function main (signature void (parameters ) ( (assign (xyzw) (var_ref gl_Position) (var_ref vertex) ) )) ) ) Eleni Maria Stea Hacking on Mesa 3D 14 / 26 Developing the OpenGL GLSL->GLSL IR->NIR->ASM 2/4 NIR (ssa form) decl_var shader_in INTERP_MODE_NONE vec4 vertex (VERT_ATTRIB_GENERIC0, 17, 0) decl_var shader_out INTERP_MODE_NONE vec4 gl_Position (VARYING_SLOT_POS, 0, 0) decl_function main returning void impl main { block block_0: /* preds: */ vec1 32 ssa_0 = load_const (0x00000000 /* 0.000000 */) vec4 32 ssa_1 = intrinsic load_input (ssa_0) () (0, 0) /* base=0 */ /* component=0 */ intrinsic store_output (ssa_1, ssa_0) () (0, 15, 0) /* base=0 */ /* wrmask=xyzw */ /* component=0 */ /* gl_Position */ /* succs: block_0 */ block block_0: } Eleni Maria Stea Hacking on Mesa 3D 15 / 26 Developing the OpenGL GLSL->GLSL IR->NIR->ASM 3/4 NIR (final form) decl_var shader_in INTERP_MODE_NONE vec4 vertex (VERT_ATTRIB_GENERIC0, 17, 0) decl_var shader_out INTERP_MODE_NONE vec4 gl_Position (VARYING_SLOT_POS, 0, 0) decl_function main returning void impl main { block block_0: /* preds: */ vec1 32 ssa_0 = load_const (0x00000000 /* 0.000000 */) vec4 32 ssa_1 = intrinsic load_input (ssa_0) () (0, 0) /* base=0 */ /* component=0 */ intrinsic store_output (ssa_1, ssa_0) () (0, 15, 0) /* base=0 */ /* wrmask=xyzw */ /* component=0 */ /* gl_Position */ /* succs: block_0 */ block block_0: } Eleni Maria Stea Hacking on Mesa 3D 16 / 26 Developing the OpenGL GLSL->GLSL IR->NIR->ASM 4/4 Native Code START B0 (26 cycles) mov(8) g123<1>UD g1<8,8,1>UD { align1 WE_all 1Q compacted }; mov(8) g124<1>F g2<8,8,1>F { align1 1Q compacted }; mov(8) g125<1>F g3<8,8,1>F { align1 1Q compacted }; mov(8) g126<1>F g4<8,8,1>F { align1 1Q compacted }; mov(8) g127<1>F g5<8,8,1>F { align1 1Q compacted }; send(8) null<1>F g123<8,8,1>F urb 1 SIMD8 write mlen 5 rlen 0 { align1 1Q EOT }; nop ; END B0 Eleni Maria Stea Hacking on Mesa 3D 17 / 26 Debugging Tools GLSL->GLSL IR->NIR->ASM Debugging We can test the intermediate representations using some Mesa environment variables for the drivers $ export INTEL_DEBUG=vs $ export INTEL_DEBUG=fs $ export INTEL_DEBUG=vs,fs, ... Like in the following example ;-) Eleni Maria Stea Hacking on Mesa 3D 18 / 26 Debugging Tools OpenGL Extensions 4/4: Testing & Debugging And since we mentioned Debugging... There’s a process through which we can test our OpenGL extensions implementations. I For every new core feature that is added to OpenGL, developers (usually from Khronos group) write a test that tests the feature. I This test performs the same operation using software rendering and shaders and compares the output of each. I VK-GL-CTS: https://github.com/KhronosGroup/VK-GL-CTS I Every manufacturer can run the tests on its own implementation of an OpenGL version to make sure that the features of that version work fine. I When a test fails and the bug is not in the test, we know that probably our driver has a problem. I We also check for regressions from version to version or for cases where a feature might break another one (a test that used to run without errors doesn’t do that anymore). Eleni Maria Stea Hacking on Mesa 3D 19 / 26 Debugging Tools Other Debugging Tools Some useful tools for when a problem is detected. I GDB I MESA environment variables: https://www.mesa3d.org/envvars.html • We can dump and replace information (asm, IR, GLSL code) • We can switch between GL versions • We can test different code paths We can test driver specific operations • only get a look at the website :) I Some safe environments to run our experiments: chroot, jhbuild shell Eleni Maria Stea Hacking on Mesa 3D 20 / 26 Debugging Tools Debuging mesa, debugging open source graphics apps, debugging anything! We can debug any graphics app!! Mesa provides debugging tools for: I mesa itself I other open source graphics applications I even for proprietary software! Eleni Maria Stea Hacking on Mesa 3D 21 / 26 Debugging Tools Replacing the shaders’ code Limbo Showcase: No matter if we have a program’s source code, we can test but also modify its shaders while it’s running. I $ export MESA_SHADER_DUMP_PATH=‘pwd‘/dump_sdr/ I $ export MESA_SHADER_READ_PATH=‘pwd‘/read_sdr/ Eleni Maria Stea Hacking on Mesa 3D 22 / 26 Contributions How could someone
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages26 Page
-
File Size-