-
Notifications
You must be signed in to change notification settings - Fork 102
Description
Hey @ericstoneking , hope all is well. Wanted to share something I found
WSL2 supports native X-11 forwarding and has support for discrete GPUs
https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps
On my machine, I followed the setup steps as normal for the WSL:
& bash
& sudo apt update
& sudo apt-get install vim-gtk
& sudo apt install gcc
& sudo apt install g++ [[if needed. LWS]]
& DISPLAY=:1 gvim #check that opens a xming display window
& sudo apt-cache search glut
& sudo apt-get install freeglut3-dev
& sudo apt-get install libglfw3-dev
I did not need to export the display, with WSL2 it should be set such that DISPLAY=:0
What I did have to do for things to work and use my GPU on my laptop:
export MESA_D3D12_DEFAULT_ADAPTER_NAME=NVIDIA
export LIBGL_ALWAYS_SOFTWARE=false
Can check with this: glxinfo | grep renderer
GLX_MESA_copy_sub_buffer, GLX_MESA_gl_interop, GLX_MESA_query_renderer,
GLX_MESA_copy_sub_buffer, GLX_MESA_gl_interop, GLX_MESA_query_renderer,
Extended renderer info (GLX_MESA_query_renderer):
OpenGL renderer string: D3D12 (NVIDIA RTX A3000 Laptop GPU)
Tried to run ./42, the windows would come up but they were black. Then the could would seg fault.
So ran ./42 with gdb and saw this issue:
#0 0x00000000000000e0 in ?? ()
#1 0x00007ffff1cbfd80 in ?? () from /lib/x86_64-linux-gnu/libgallium-25.2.8-0ubuntu0.24.04.1.so
#2 0x00007ffff1cf31cd in ?? () from /lib/x86_64-linux-gnu/libgallium-25.2.8-0ubuntu0.24.04.1.so
#3 0x00007ffff1cf3af5 in ?? () from /lib/x86_64-linux-gnu/libgallium-25.2.8-0ubuntu0.24.04.1.so
#4 0x00007ffff1cf491d in ?? () from /lib/x86_64-linux-gnu/libgallium-25.2.8-0ubuntu0.24.04.1.so
#5 0x00007ffff16f4fc8 in ?? () from /lib/x86_64-linux-gnu/libgallium-25.2.8-0ubuntu0.24.04.1.so
#6 0x00007ffff16f522a in ?? () from /lib/x86_64-linux-gnu/libgallium-25.2.8-0ubuntu0.24.04.1.so
#7 0x00007ffff1cf418d in ?? () from /lib/x86_64-linux-gnu/libgallium-25.2.8-0ubuntu0.24.04.1.so
#8 0x00007ffff16b7f40 in ?? () from /lib/x86_64-linux-gnu/libgallium-25.2.8-0ubuntu0.24.04.1.so
#9 0x00007ffff16b897b in ?? () from /lib/x86_64-linux-gnu/libgallium-25.2.8-0ubuntu0.24.04.1.so
#10 0x00007ffff16bae16 in ?? () from /lib/x86_64-linux-gnu/libgallium-25.2.8-0ubuntu0.24.04.1.so
#11 0x00007ffff134323d in ?? () from /lib/x86_64-linux-gnu/libgallium-25.2.8-0ubuntu0.24.04.1.so
#12 0x00007ffff1257965 in ?? () from /lib/x86_64-linux-gnu/libgallium-25.2.8-0ubuntu0.24.04.1.so
#13 0x00007ffff7f253fd in glutBitmapCharacter (fontID=0x7ffff7f4e6f8 <glutBitmap8By13>, character=<optimized out>)
at /usr/src/freeglut-3.4.0-1build1/src/fg_font.c:136
#14 0x000055555563a10c in DrawBitmapString (font=0x7ffff7f4e6f8 <glutBitmap8By13>,
string=0x7fffffffda00 "UTC 099-00:00:00.00") at ./Kit/Source/glkit.c:37
#15 0x0000555555616477 in DrawCamHUD () at ./Source/42gl.c:714
#16 0x000055555561bbe7 in DrawNearAuxObjects () at ./Source/42gl.c:1662
#17 0x000055555562298f in CamRenderExec () at ./Source/42gl.c:2573
#18 0x00007ffff7f16fb3 in fghRedrawWindow (window=window@entry=0x5555570a8b20)
at /usr/src/freeglut-3.4.0-1build1/src/fg_main.c:133
#19 0x00007ffff7f208ad in fgProcessWork (window=window@entry=0x5555570a8b20)
at /usr/src/freeglut-3.4.0-1build1/src/fg_main.c:435
#20 0x00007ffff7f22099 in fghcbProcessWork (window=0x5555570a8b20, enumerator=0x7fffffffdc40)
at /usr/src/freeglut-3.4.0-1build1/src/fg_main.c:157
#21 0x00007ffff7f215c9 in fgEnumWindows (enumCallback=enumCallback@entry=0x7ffff7f22060 <fghcbProcessWork>,
enumerator=enumerator@entry=0x7fffffffdc40) at /usr/src/freeglut-3.4.0-1build1/src/fg_structure.c:406
#22 0x00007ffff7f21888 in fghProcessWork () at /usr/src/freeglut-3.4.0-1build1/src/fg_main.c:172
--Type <RET> for more, q to quit, c to continue without paging--
#23 glutMainLoopEvent () at /usr/src/freeglut-3.4.0-1build1/src/fg_main.c:457
#24 0x00007ffff7f21924 in glutMainLoop () at /usr/src/freeglut-3.4.0-1build1/src/fg_main.c:489
#25 0x000055555563a0cf in HandoffToGui (argc=1, argv=0x7fffffffde68) at ./Source/42glut.c:1399
#26 0x000055555555b74e in exec (argc=1, argv=0x7fffffffde68) at ./Source/42exec.c:415
#27 0x0000555555559cad in main (argc=1, argv=0x7fffffffde68) at ./Source/42main.c:41
I saw it had something to do with the DrawBitmapString function. Now as any good GNC engineer I just added this bit to glkit.c
From this:
void DrawBitmapString(void *font, const char *string)
{
const char *c;
for(c=string; *c != '\0'; c++) {
glutBitmapCharacter(font, *c);
}
}
To this:
void DrawBitmapString(void *font, const char *string)
{
#ifndef ENABLE_GL_TEXT
(void)font;
(void)string;
// WSL/GLUT bitmap text disabled: crashes inside glutBitmapCharacter
return;
#else
const char *c;
for (c = string; *c != '\0'; c++)
glutBitmapCharacter(font, *c);
#endif
}
Essentially just turned it off.
And now everything works, minus lacking the text:
GLFW also had this issue, and then I turned that text off and it works as well now. Let me know your thoughts.