Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raspberry Pi 5 - KMSDRM driver / garbage displayed when drawing to framebuffer (no X11 / Wayland) - reverting to ATOMIC kmsdrm driver commit range works #8579

Closed
tekker opened this issue Nov 18, 2023 · 39 comments
Assignees
Milestone

Comments

@tekker
Copy link

tekker commented Nov 18, 2023

Hi, SDL kmsdrm driver displays garbage when drawing to rpi5 framebuffer (testing without X11 or Wayland). When compiling against either current builds of libdrm / mesa git or against the version in the Raspberry Pi 5 OS distributed with the board (Bookworm). While SDL (latest git version) compiles correctly without errors, there are a small number of automation test failures.

Running the test binaries testdraw, testgles2 etc display garbage however when exiting the app for a fraction of a second the actual correct frame is displayed. The testvulkan demo however works correctly with KMSDRM.

Using @vanfanel commits at commit [KMS/DRM] Small readability changes., the drawing routines complete correctly and everything seems to work OK, including testgles2, testdraw etc.

I don't have much experience with SDL or DRM (or graphics subsystem) but looks like using the ATOMIC modesetting & use of planes etc may be needed for PI5 compatibility (this is the approach kmscube uses, which displays correctly on Pi5).

@tekker tekker changed the title Raspberry Pi 5 - KMSDRM driver / garbage displayed when drawing to framebuffer (no X11 / Wayland) - maybe ATOMIC needed Raspberry Pi 5 - KMSDRM driver / garbage displayed when drawing to framebuffer (no X11 / Wayland) - reverting to ATOMIC kmsdrm driver commit range works Nov 18, 2023
@icculus icculus added this to the 2.30.0 milestone Nov 20, 2023
@icculus icculus self-assigned this Nov 20, 2023
@icculus
Copy link
Collaborator

icculus commented Nov 20, 2023

I'll see if I can take the merged kmsdrm code I did awhile ago and get it working again.

Putting this in the 2.30.0 milestone since that's going to be most urgent for Pi5 users and has a conveniently-soon deadline.

@cmitu
Copy link

cmitu commented Nov 20, 2023

@icculus I'm not sure there's an issue with the SDL2 version. FWIW, RetroPie uses SDL2 under KMS/DRM almost exclusively (the front-end, EmulationStation, is a SDL2 app using OpenGL/GLES) and we haven't got complaints from users on latest RaspiOS & Pi5 trying out RetroPie. The version we use distribute right now is 2.26.3, but I don't think anything changed w.r.t. KMS/DRM on the SDL2 branch.

@tekker are you sure you're getting this errors with the MESA distributed with RaspiOS ? Which SDL versions are you testing ?

@vanfanel
Copy link
Contributor

@cmitu I am also almost sure this is not an SDL2 problem, but a MESA problem.

@tekker Can you please test current git MESA with SDL2 KMS/DRM? It has to be the latest git version, since there were important fixes merged yesterday.

@tekker
Copy link
Author

tekker commented Nov 20, 2023

@vanfanel Apologies, I don't have my pi5 for the next week and unfortunately can't test the fixes of the last 2 days. Regarding whether this is a SDL2 problem - from memory glmark2-es2 master built against MESA has the same result (garbage displayed I think) whereas current kmscube master runs correctly. What I noticed was that for a brief fraction of a second after killing the test executable (ie. testdraw2), just before returning to kms console, the correct image was displayed onscreen.

@cmitu This was tested against current SDL master at 19/11/23. After testing latest SDL master, tested latest release version with same result. I avoided testing on RetroPie / RaspiOS, this was tested using a set of docker images running on latest LibreELEC nightly images for RPI5 and disabling all Kodi systemd so that I have direct access to DRM - apologies I can't send a copy of the docker files to reproduce as I don't have the Pi5 with me this week. This approach was based on minimal modifications from working Docker KMSDRM libdrm/ligglvnd/mesa/SDL2 build for Pi4 on LibreELEC nightly with Kodi systemd disabled.

SDL master was built using:

cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_FLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72 -DEGL_NO_X11" -DCMAKE_CXX_FLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72 -DEGL_NO_X11" DSDL_X11=OFF -DSDL_WAYLAND=OFF -DSDL_OSS=OFF -DSDL_DISKAUDIO=OFF -DSDL_DUMMYVIDEO=OFF -DSDL_VULKAN=ON -DSDL_OPENGLES=ON -DVIDEO_OPENGL=ON -DSDL_KMSDRM=ON -DSDL_PULSEAUDIO=OFF -DSDL_TEST_LIBRARY=ON -DSDL_TESTS=ON -DSDL_LIBUDEV=OFF

@icculus I did confirm this issue was occurring with latest libdrm git and using mesa distributed with RpiOS built via

wget https://archive.mesa3d.org//mesa-23.2.1.tar.xz
wget http://archive.raspberrypi.com/debian/pool/main/m/mesa/mesa_23.2.1-0+rpt2.diff.gz
tar xvzpf mesa-23.2.1.tar.xz
cd mesa-23.2.1
zcat ../mesa_23.2.1-0+rpt2.diff.gz | patch -p1
for f in $(cat debian/patches/series); do patch -p1 < debian/patches/$f; done

@slouken slouken modified the milestones: 2.30.0, 2.32.0 Nov 22, 2023
@appnjoy
Copy link

appnjoy commented Nov 23, 2023

This is exactly the same issue I'm having with KMS driver trying to run Dosbox from framebuffer on Raspberry Pi 5.

I compiled Dosbox (3 versions) in Raspberry Pi 4 with Bookworm Lite and run from console in framwbuffer, everything worked 100% but as soon as I moved microSD to Raspberry Pi 5 and did run Dosbox, all i got is a white garbage screen with a mouse pointer. Then trying to exiting from DosBox caused for half a second to see the buffer correctly before to come back to command line.

@vanfanel
Copy link
Contributor

@appnjoy Please test against latest MESA Git code, there have been fixes for Wayland / KMSDRM on the Pi5 in the last few days.

@tekker
Copy link
Author

tekker commented Nov 28, 2023

@vanfanel Tested against latest git mesa / libdrm etc, with similar issues - garbage displayed looks a lot different (looks a bit like white-ish noise) than previous mesa build, with the same effect of correct image displaying briefly on exit . @appnjoy I can verify that the cursor is displayed OK on some tests as well, and the buffer displaying for a fraction of a second when exiting.

The SDL automation test produces errors along these lines (same as previous mesa latest git)

INFO:  11/28/23 17:25:36: >>> Test 'video_getSetWindowData': Passed
INFO:  11/28/23 17:25:36: ----- Test Case 23.18: 'video_setWindowCenteredOnDisplay' started
INFO:  11/28/23 17:25:36: Test Description: 'Checks using SDL_WINDOWPOS_CENTERED_DISPLAY centers the window on a display'
INFO:  11/28/23 17:25:36: Test Iteration 1: execKey 513967493303119183
INFO:  11/28/23 17:25:36: Assert 'SDL_GetDisplayBounds()': Passed
INFO:  11/28/23 17:25:36: Assert 'Verify return value; expected: 0, got: 0': Passed
INFO:  11/28/23 17:25:36: Assert 'SDL_GetDisplayBounds()': Passed
INFO:  11/28/23 17:25:36: Assert 'Verify return value; expected: 0, got: 0': Passed
INFO:  11/28/23 17:25:36: Assert 'Call to SDL_CreateWindow('Title',805240833,805240833,654,549,SHOWN)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate that returned window struct is not NULL': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate display ID (current: 1, expected: 1)': Passed
ERROR: 11/28/23 17:25:36: Assert 'Validate width (current: 720, expected: 654)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate height (current: 576, expected: 549)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate x (current: 0, expected: 353)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate y (current: 0, expected: 109)': Failed
INFO:  11/28/23 17:25:36: Assert 'Verify return value; expected: 0, got: 0': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate display ID (current: 1, expected: 1)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate width (current: 1360, expected: 1360)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate height (current: 768, expected: 768)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate x (current: 0, expected: 0)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate y (current: 0, expected: 0)': Passed
INFO:  11/28/23 17:25:36: Assert 'Verify return value; expected: 0, got: 0': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate display index (current: 1, expected: 1)': Passed
ERROR: 11/28/23 17:25:36: Assert 'Validate width (current: 720, expected: 654)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate height (current: 576, expected: 549)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate x (current: 320, expected: 353)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate y (current: 96, expected: 109)': Failed
INFO:  11/28/23 17:25:36: Assert 'Validate display ID (current: 1, expected: 1)': Passed
ERROR: 11/28/23 17:25:36: Assert 'Validate width (current: 720, expected: 654)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate height (current: 576, expected: 549)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate x (current: 320, expected: 353)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate y (current: 96, expected: 109)': Failed
INFO:  11/28/23 17:25:36: Assert 'Call to SDL_DestroyWindow()': Passed
INFO:  11/28/23 17:25:36: Assert 'Call to SDL_CreateWindow('Title',805240833,805240833,640,559,SHOWN)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate that returned window struct is not NULL': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate display ID (current: 1, expected: 1)': Passed
ERROR: 11/28/23 17:25:36: Assert 'Validate width (current: 720, expected: 640)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate height (current: 576, expected: 559)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate x (current: 0, expected: 360)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate y (current: 0, expected: 104)': Failed
INFO:  11/28/23 17:25:36: Assert 'Verify return value; expected: 0, got: 0': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate display ID (current: 1, expected: 1)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate width (current: 1360, expected: 1360)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate height (current: 768, expected: 768)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate x (current: 0, expected: 0)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate y (current: 0, expected: 0)': Passed
INFO:  11/28/23 17:25:36: Assert 'Verify return value; expected: 0, got: 0': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate display index (current: 1, expected: 1)': Passed
ERROR: 11/28/23 17:25:36: Assert 'Validate width (current: 720, expected: 640)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate height (current: 576, expected: 559)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate x (current: 320, expected: 360)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate y (current: 96, expected: 104)': Failed
INFO:  11/28/23 17:25:36: Assert 'Validate display ID (current: 1, expected: 1)': Passed
ERROR: 11/28/23 17:25:36: Assert 'Validate width (current: 720, expected: 640)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate height (current: 576, expected: 559)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate x (current: 320, expected: 360)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate y (current: 96, expected: 104)': Failed
INFO:  11/28/23 17:25:36: Assert 'Call to SDL_DestroyWindow()': Passed
INFO:  11/28/23 17:25:36: Assert 'Call to SDL_CreateWindow('Title',805240833,805240833,750,467,SHOWN)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate that returned window struct is not NULL': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate display ID (current: 1, expected: 1)': Passed
ERROR: 11/28/23 17:25:36: Assert 'Validate width (current: 1360, expected: 750)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate height (current: 768, expected: 467)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate x (current: 0, expected: 305)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate y (current: 0, expected: 150)': Failed
INFO:  11/28/23 17:25:36: Assert 'Verify return value; expected: 0, got: 0': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate display ID (current: 1, expected: 1)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate width (current: 1360, expected: 1360)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate height (current: 768, expected: 768)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate x (current: 0, expected: 0)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate y (current: 0, expected: 0)': Passed
INFO:  11/28/23 17:25:36: Assert 'Verify return value; expected: 0, got: 0': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate display index (current: 1, expected: 1)': Passed
ERROR: 11/28/23 17:25:36: Assert 'Validate width (current: 1360, expected: 750)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate height (current: 768, expected: 467)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate x (current: 0, expected: 305)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate y (current: 0, expected: 150)': Failed
INFO:  11/28/23 17:25:36: Assert 'Validate display ID (current: 1, expected: 1)': Passed
ERROR: 11/28/23 17:25:36: Assert 'Validate width (current: 1360, expected: 750)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate height (current: 768, expected: 467)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate x (current: 0, expected: 305)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate y (current: 0, expected: 150)': Failed
INFO:  11/28/23 17:25:36: Assert 'Call to SDL_DestroyWindow()': Passed
INFO:  11/28/23 17:25:36: Assert 'Call to SDL_CreateWindow('Title',805240833,805240833,784,495,SHOWN)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate that returned window struct is not NULL': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate display ID (current: 1, expected: 1)': Passed
ERROR: 11/28/23 17:25:36: Assert 'Validate width (current: 1360, expected: 784)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate height (current: 768, expected: 495)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate x (current: 0, expected: 288)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate y (current: 0, expected: 136)': Failed
INFO:  11/28/23 17:25:36: Assert 'Verify return value; expected: 0, got: 0': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate display ID (current: 1, expected: 1)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate width (current: 1360, expected: 1360)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate height (current: 768, expected: 768)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate x (current: 0, expected: 0)': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate y (current: 0, expected: 0)': Passed
INFO:  11/28/23 17:25:36: Assert 'Verify return value; expected: 0, got: 0': Passed
INFO:  11/28/23 17:25:36: Assert 'Validate display index (current: 1, expected: 1)': Passed
ERROR: 11/28/23 17:25:36: Assert 'Validate width (current: 1360, expected: 784)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate height (current: 768, expected: 495)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate x (current: 0, expected: 288)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate y (current: 0, expected: 136)': Failed
INFO:  11/28/23 17:25:36: Assert 'Validate display ID (current: 1, expected: 1)': Passed
ERROR: 11/28/23 17:25:36: Assert 'Validate width (current: 1360, expected: 784)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate height (current: 768, expected: 495)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate x (current: 0, expected: 288)': Failed
ERROR: 11/28/23 17:25:36: Assert 'Validate y (current: 0, expected: 136)': Failed
INFO:  11/28/23 17:25:36: Assert 'Call to SDL_DestroyWindow()': Passed
INFO:  11/28/23 17:25:36: Fuzzer invocations: 8
ERROR: 11/28/23 17:25:36: Assert Summary: Total=104 Passed=56 Failed=48
INFO:  11/28/23 17:25:36: Total Test runtime: 0.3 sec
ERROR: 11/28/23 17:25:36: >>> Test 'video_setWindowCenteredOnDisplay': Failed
INFO:  11/28/23 17:25:36: Total Suite runtime: 2.9 sec
ERROR: 11/28/23 17:25:36: Suite Summary: Total=18 Passed=17 Failed=1 Skipped=0
ERROR: 11/28/23 17:25:36: >>> Suite 'Video': Failed
...
ERROR: 11/28/23 17:25:37: >>> Run /w seed '0768L92A4CAEVA2R': Failed
INFO:  11/28/23 17:25:37: Harness input to repro failures:
INFO:  11/28/23 17:25:37:  --seed 0768L92A4CAEVA2R --filter video_setWindowCenteredOnDisplay
INFO:  11/28/23 17:25:37: Exit code: 1

EDIT: This probably should be ignored as these automation tests fail on Pi4 as well (video_setWindowCenteredOnDisplay), maybe due to no WM

@tekker
Copy link
Author

tekker commented Nov 29, 2023

For reference, here is the Dockerfile I have been using for testing RPI5 KMSDRM. The mesa git upstream is commented out to test with current Raspi OS package'd mesa in this version.

FROM balenalib/raspberrypi5-debian-python:latest-bookworm-build as base

RUN install_packages \
    build-essential \
    git \
    rsync \
    plymouth \
    cmake \
    libasound2-dev \
    curl \
    pkg-config \
    wget \
    libboost-program-options-dev libboost-thread-dev libboost-system-dev liblog4cplus-dev \
    libudev-dev python3 swig \
    lirc liblirc-dev lirc-compat-remotes

COPY . ./devel
WORKDIR /devel

RUN python3 -m pip install ninja meson

RUN git clone --depth 1 https://gitlab.freedesktop.org/glvnd/libglvnd.git \
	&& cd libglvnd \
	&& mkdir build \
	&& cd build \
	&& CFLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72" meson --prefix=/usr --libdir=lib -Dglx=disabled -Dx11=disabled .. \
	&& ninja -j4 \
	&& sudo ninja install

RUN install_packages flex bison python3-mako python3-setuptools libexpat1-dev libudev-dev gettext ca-certificates xz-utils zlib1g-dev pkg-config 

RUN git clone --depth=1 https://gitlab.freedesktop.org/mesa/drm.git \
	&& cd drm \
	&& CFLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72" CXXFLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72" meson setup --prefix=/usr --libdir=lib -Dudev=true -Dvc4=enabled -Dintel=disabled -Dvmwgfx=disabled -Dradeon=disabled -Damdgpu=disabled -Dnouveau=disabled -Dfreedreno=disabled -Dinstall-test-programs=true build \
	&& meson compile -C build \
	&& sudo meson install -C build

RUN install_packages libvulkan-dev libvulkan1 vulkan-tools glslang-tools llvm llvm-dev llvm-runtime \
	libwayland-dev wayland-protocols libwayland-egl-backend-dev

RUN wget https://archive.mesa3d.org/mesa-23.2.1.tar.xz \
	&& wget http://archive.raspberrypi.com/debian/pool/main/m/mesa/mesa_23.2.1-1~bpo12+rpt2.diff.gz \
	&& xz -d mesa-23.2.1.tar.xz \
	&& tar xvpf mesa-23.2.1.tar \
	&& cd mesa-23.2.1 \
	&& zcat ../mesa_23.2.1-1~bpo12+rpt2.diff.gz | patch -p1 \
	&& for f in $(cat debian/patches/series); do patch -p1 < debian/patches/$f; done \
	&& CFLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72" CXXFLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72" meson setup --prefix=/usr --libdir=lib -Dbuildtype=release -Dglx=disabled -Dplatforms=wayland -Dllvm=disabled -Dvulkan-drivers=broadcom -Dgallium-drivers=v3d,vc4,kmsro -Dglvnd=true build \
	&& meson compile -C build \
	&& sudo meson install -C build


#RUN git clone https://gitlab.freedesktop.org/mesa/mesa \
#	&& cd mesa \
#	&& CFLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72" meson setup --prefix=/usr --libdir=lib -Dbuildtype=release -Dglx=disabled -Dplatforms=wayland -Dllvm=disabled -Dvulkan-drivers=broadcom -Dgallium-drivers=v3d,vc4,kmsro -Dglvnd=true build \
#	&& meson compile -C build \
#	&& sudo meson install -C build

RUN git clone --depth=1 https://gitlab.freedesktop.org/mesa/kmscube.git \
        && cd kmscube \
        && CFLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72" meson setup --prefix=/usr --libdir=lib build \
        && meson compile -C build \
        && sudo meson install -C build

RUN install_packages libfmt-dev
RUN git clone https://github.com/tomba/kmsxx \
        && cd kmsxx \
        && CFLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72" CXXFLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72" meson setup -Dkmscube=false build \
        && meson compile -C build \
        && sudo meson install -C build

RUN git clone --depth 1 https://github.com/libsdl-org/SDL.git \
	&& cd SDL \
	&& cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_FLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72 -DEGL_NO_X11" -DCMAKE_CXX_FLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72 -DEGL_NO_X11" DSDL_X11=OFF -DSDL_WAYLAND=OFF -DSDL_OSS=OFF -DSDL_DISKAUDIO=OFF -DSDL_DUMMYVIDEO=OFF -DSDL_VULKAN=ON -DSDL_OPENGLES=ON -DVIDEO_OPENGL=ON -DSDL_KMSDRM=ON -DSDL_PULSEAUDIO=OFF -DSDL_TEST_LIBRARY=ON -DSDL_TESTS=ON -DSDL_LIBUDEV=OFF \
	&& cmake --build build \
	&& cmake --install build --prefix /usr

RUN install_packages unzip vim
RUN mkdir working-ver \
	&& cd working-ver \
	&& wget https://codeload.github.com/libsdl-org/SDL/zip/940e1b8dd94318a5307601f4b61d1cbf6b7dd757 \
	&& unzip 940e1b8dd94318a5307601f4b61d1cbf6b7dd757 \
	&& cd SDL-940e1b8dd94318a5307601f4b61d1cbf6b7dd757/ \
	&& cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_FLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72 -DEGL_NO_X11" -DCMAKE_CXX_FLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72 -DEGL_NO_X11" DVIDEO_X11=OFF -DVIDEO_WAYLAND=OFF -DOSS=OFF -DDISKAUDIO=OFF -DVIDEO_DUMMY=OFF -DVIDEO_VULKAN=ON -DVIDEO_OPENGLES=ON -DVIDEO_OPENGL=ON -DVIDEO_KMSDRM=ON -DSDL_PULSEAUDIO=OFF -DKMSDRM_SHARED=ON -DSDL_TEST=ON \
	&& cmake --build build -j 5

RUN install_packages libbsd-dev
RUN git clone https://github.com/AndrewFromMelbourne/drmfb32 --recursive \
	&& cd drmfb32 \
	&& mkdir build \
	&& cd build \
	&& cmake .. \
	&& make -j4

RUN install_packages libpng-dev
RUN git clone https://github.com/glmark2/glmark2 --depth=1 \
	&& cd glmark2 \
	&& CFLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72" CXXFLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72" meson setup -Dflavors=drm-glesv2 build \
	&& meson compile -C build \
        && sudo meson install -C build

RUN install_packages libglm-dev libassimp-dev
RUN git clone https://github.com/vkmark/vkmark \
	&& cd vkmark \
	&& CFLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72" CXXFLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72" meson setup -Dkms=true -Dwayland=false -Dxcb=false build \
	&& meson compile -C build \
	&& sudo meson install -C build
# test with vkmark -d --winsys-options kms-drm-device=/dev/dri/card1

RUN install_packages libxkbcommon-dev libpixman-1-dev hwdata libseat-dev
RUN git clone https://github.com/cage-kiosk/cage \
	&& cd cage \
	&& git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.16.0 \
	&& CFLAGS="-O2 -march=armv8-a+crc+simd -mtune=cortex-a72" meson setup --prefix=/usr --libdir=lib -Dxwayland=false build \
	&& meson compile -C build \
	&& sudo meson install -C build

ENTRYPOINT ["bash"]

which is built using

buildx build -t mesa-rpi .

and run with

docker run -v `pwd`:/test --privileged -i -t mesa-rpi

The visual artificacts are the same as in the above issue at BlitterStudio/amiberry#1189

@pjft
Copy link

pjft commented Nov 29, 2023

Unsure if it's related, but hoping it helps as I was the one submitting the issue referenced above: the artifacts didn't present themselves when launching the application from the terminal. They only manifested themselves when launching the application from specific code paths (that used to work in previous scenarios) and that we're troubleshooting there.

I do confirm that the mouse pointer renders correctly, and after back and forth in recompiling code and updating dependencies I also get the "white-ish noise", as you describe. Check if the same. See video.

2023-11-29.11-46-43.PIMG_1918.mov

Once again, unsure where the issue lies, but thought I'd share for everyone to be on the same page and decide whether this is relevant to the topic or not.

@pjft
Copy link

pjft commented Nov 29, 2023

-- Final update for now: this was found to be related to VSync, in the other thread

@tekker
Copy link
Author

tekker commented Nov 30, 2023

I can confirm that starting from scratch with fresh Raspbian OS install (ie. not using Docker at all), the same issue (garbage on framebuffer with KMSDRM only when not using ATOMIC glmark2-es2-drm, SDL drawchessboard etc) is present.

This is using current mesa as distributed with Raspbian, I have yet to test with Mesa upstream in this environment. Using the same build scripts as taken from Dockerfile in this issue. This issue is specific to KMSDRM only (ie. Wayland / Vulkan have no problems at all).

It's definitely not a SDL issue, only created the issue here due to the set of commits for Atomic modesetting in SDL which vanfanel created avoids the framebuffer corruption.

@maru-sama
Copy link

Hello

I have similar issues with a KIVy application as well.

I recently upgraded one of my Pis to to bookworm and in the process also had to update the Kivy GUI to run with python-3.11. Since the distribution includes the kivy packageI just simply installed it, which also pulled in the SDL dependency (2.26.5+dfsg-1 in this case). I started my GUI application and the whole screen was garbled.

Then I remembered that I build SDL manually ages ago when I first started developping the app (2.0.10). I installed this version in /usr/local and then compiled an older version of kivy linking against that.

After that the application started working again without any issues.

I can try and bisect of when the breakage happened for me, but maybe someone can give me some ideas at which version I should start.

@slouken
Copy link
Collaborator

slouken commented Dec 1, 2023

You can probably start bisecting on major releases. They should be backwards compatible, so you can just step through newer versions until it breaks.

@maru-sama
Copy link

maru-sama commented Dec 1, 2023

I started doing this..

  • 2.0.16: breaks
  • 2.0.14: Works but the image is not full screen, it looks like a higher resolution
  • 2.0.12: Is fine

Im now bisecting between 2.0.16 and 2.0.14

@maru-sama
Copy link

maru-sama commented Dec 1, 2023

Oook, so after a long bisecting session I tracked it down to aac74db. This one apparently breaks the touchscreen display with my Pi. I tried 9384e59 as well and with this everything works and the scaling is correct as well.

@slouken
Copy link
Collaborator

slouken commented Dec 1, 2023

Just to be clear, you tried the latest code with aac74db reverted and that fixed the issue, is that right? @vanfanel, can you take a look?

@slouken slouken modified the milestones: 2.32.0, 2.30.0 Dec 1, 2023
@maru-sama
Copy link

A simple revert was not possible. It tried to revert this commit in 2.0.16 but it did not completely work (the screen froze). The display looked fine though before it froze.
I can try to revert it with the latest release but I guess it is even more complicated.

@maru-sama
Copy link

Ok there are two many changes and for me a simple revert is indeed not possible. That said the commit which enables async flip support definitely breaks it for me, while the commit before works fine.
If someone could provide me a simple patch against current maint to revert this, I could try it on my setup.

@maru-sama
Copy link

maru-sama commented Dec 1, 2023

I found an easier way for testing.
I hardcoded async_support FALSE in the drm init function

viddata->async_pageflip_support = async_pageflip ? SDL_TRUE : SDL_FALSE;
and compiled 2.28.5 this way. Everything works fine without any issues this way.

So it seems that SDL is not the problem, but the async pageflip support for my setup is not working. With older SDL versions it just does not happen because they do not support it.

@vanfanel
Copy link
Contributor

vanfanel commented Dec 1, 2023

@slouken This is, indeed, a MESA, libDRM or kernel problem, regarding drmModePageFlip() with the DRM_MODE_PAGE_FLIP_ASYNC flag.
I have opened an issue on MESA gitlab here:
https://gitlab.freedesktop.org/mesa/mesa/-/issues/10242
I hope they can easily find the cause and fix it. Fingers crossed!

@maru-sama
Copy link

@vanfanel for your information I can reproduce this on a rpi4, just saw that I did not mention this earlier.

@vanfanel
Copy link
Contributor

vanfanel commented Dec 1, 2023

@maru-sama Hadn't seen that! So, when did SDL2(KMS/DRM) break on the Pi4 and 5? I haven't used anything on KMS/DRM for the last year or so.
Was it on a MESA version? With an SDL2 commit?

@maru-sama
Copy link

I updated to bookworm which installed a new Sdl version that enables async page flip. This breaks my kivy application I have running at home. If I hardcode no async page support in the Sdl lib it works fine.

@vanfanel
Copy link
Contributor

vanfanel commented Dec 1, 2023

@maru-sama Ok, this is a MESA problem, I have modified my report (I don't have a Pi4 here to test), so let's see what they find out.

@appnjoy
Copy link

appnjoy commented Dec 2, 2023

@maru-sama Hadn't seen that! So, when did SDL2(KMS/DRM) break on the Pi4 and 5? I haven't used anything on KMS/DRM for the last year or so. Was it on a MESA version? With an SDL2 commit?

It's not a SDL problem, Dosbox-SVN, DosBox-ECE use SDL1 and DosBox'X SDL2, all of them work w/out any problem on Raspberry Pi 4 with Bookworm and KMS driver, I had garbage problem only on Raspberry Pi 5.

@tekker
Copy link
Author

tekker commented Dec 2, 2023

@appnjoy Garbage on framebuffer only appeared on Pi5 for me as well.

@maru-sama
Copy link

This is with pageflip disabled
IMG_20231202_092036

The same code with pageflip enabled.
IMG_20231202_092206

Both on a rpi4

@tekker
Copy link
Author

tekker commented Dec 2, 2023

@maru-sama Against current SDL master and current MESA master, the garbage framebuffer issue is resolved for me with the async pageflip modifucation to SDL/src/video/kmsdrm/SDL_kmsdrmvideo.c. 👍 This is on Pi 5.

I am limiting testing to SDL demos, ie. testdraw, testgles2, testsprite, testyuv. In Pi5, with asyncpageflip=false, verything looks reasonably OK in KMSDRM except for maybe some minor tearing on testgles2 demo. Demos still work fine in Vulkan, Wayland.

These do also work on Pi4 latest mesa / sdl master for me (without needing async pageflip disabled in the SDL_kmsdrmvideo), except for superfast cube (thousands of FPS) with testgles2, not sure what is causing that. EDIT: @maru-sama Disabling asyncpageflip resolves this issue as well in Pi 4.

@tekker
Copy link
Author

tekker commented Dec 2, 2023

The same issue with framebuffer corruption against current MESA using KMSDRM can be seen with glmark2 (https://github.com/glmark2/glmark2)

Following @maru-sama changes for SDL, disabling async page flip in glmark2 source resolves the framebuffer corruption issue, glmark2-es2-drm now displays correctly on RPI 5.

https://github.com/glmark2/glmark2/blob/5f23d540342ba69e12afeb6a1ac4f6fd36747975/src/native-state-drm.cpp#L678

@vanfanel
Copy link
Contributor

vanfanel commented Dec 2, 2023

@tekker I could replicate that on my Pi5, and passed that information to the MESA people. Thanks a lot for not only reporting the issue but going down to the cause! I am sure it will be fixed soon.

@tekker
Copy link
Author

tekker commented Dec 2, 2023

No worries @vanfanel thank you for all your effort :)

@dtcooper
Copy link

dtcooper commented Dec 4, 2023

Happening with pygame using the kmsdrm driver on a raspberry pi 5 using the lite os (no display environment) as well!

@icculus
Copy link
Collaborator

icculus commented Dec 5, 2023

Okay, we're all in agreement this isn't an SDL issue, so I'm going to close this unless new information comes up that says otherwise.

Thanks to everyone that researched this so thoroughly!

@icculus icculus closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2023
@dtcooper
Copy link

dtcooper commented Dec 8, 2023

In case anyone's looking for manually patched libsdl2 packages with @maru-sama's hardcoded fix, here they are. Made pygame work perfectly for me perfectly on a Raspberry Pi 5 using the KMSDRM driver.

Included packages are:

  • libsdl2-2.0-0-dbgsym_2.26.5+dfsg-1github85791_arm64.deb
  • libsdl2-2.0-0_2.26.5+dfsg-1github85791_arm64.deb
  • libsdl2-dev_2.26.5+dfsg-1github85791_arm64.deb
  • libsdl2-doc_2.26.5+dfsg-1github85791_all.deb
  • libsdl2-tests-dbgsym_2.26.5+dfsg-1github85791_arm64.deb
  • libsdl2-tests_2.26.5+dfsg-1github85791_arm64.deb

libsdl2-github-issues-8579-fix-packages.zip

@appnjoy
Copy link

appnjoy commented Dec 10, 2023

In case anyone's looking for manually patched libsdl2 packages with @maru-sama's hardcoded fix, here they are. Made pygame work perfectly for me perfectly on a Raspberry Pi 5 using the KMSDRM driver.

Included packages are:

  • libsdl2-2.0-0-dbgsym_2.26.5+dfsg-1github85791_arm64.deb
  • libsdl2-2.0-0_2.26.5+dfsg-1github85791_arm64.deb
  • libsdl2-dev_2.26.5+dfsg-1github85791_arm64.deb
  • libsdl2-doc_2.26.5+dfsg-1github85791_all.deb
  • libsdl2-tests-dbgsym_2.26.5+dfsg-1github85791_arm64.deb
  • libsdl2-tests_2.26.5+dfsg-1github85791_arm64.deb

libsdl2-github-issues-8579-fix-packages.zip

Thank you very much for sharing this :)

Unfortunately I solve the problem halfway, just for Dosbox-X (compiled against SDL2) because I have the same problem with Dosbox-SVN and Dosbox-ECE on Raspberry Pi 5 compiled against SDL1.

Is there any patched version of SDL1 that fix the issue?

Thanks

@slouken
Copy link
Collaborator

slouken commented Dec 11, 2023

@vanfanel, what's the implication of turning off async page flip? Is this something we can/should do for the next SDL release?

@slouken slouken reopened this Dec 11, 2023
@vanfanel
Copy link
Contributor

@icculus
The use case of sync pageflip is to be able to present a new frame immediately (or as soon as possible), even if after missing a vblank. This might result in tearing, but it's useful when a high framerate is desired, such as for gaming.

I am not interested on tearing, so yeah, go for it, disable async pageflip, nothing worth will be lost.

@mairacanal
Copy link

I believe this problem is no longer reproducible when using kernel 6.7 [1].

[1] https://github.com/raspberrypi/linux/tree/rpi-6.7.y

@slouken slouken assigned slouken and unassigned vanfanel Dec 24, 2023
@slouken
Copy link
Collaborator

slouken commented Jan 6, 2024

Since there's an upstream fix coming, I'm going to go ahead and mark this as closed. If anybody runs across this, there are packages built with the workaround available above.

@slouken slouken closed this as completed Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants