WIP: intel/isl: return the correct row pitch for 64 byte alignment
Hello! I've tried to build and run kmscube from source, in order to study and contribute with mesa, and I think that I've found a bug (don't know if it's in mesa or DRM yet). I'm trying to create a patch for it, and I thought that maybe you could help me. The bug description and the PoC that I've made are described below. This is not a definitive solution, since I don't know exactly how to fix it.
For i915 architecture and screens of resolution 1366x768,
the row pitch alignment returned is currently 4 bytes.
edit: i965 driver, not i915 architecture
The framebuffer row pitch is a number >= screen_width*bpb,
(which is 1366*4=5464, for this particular case) that is also
multiple of the alignment value (4 bytes, currently).
However, the kernel requires a row pitch value that is 64 byte
aligned in order to create a framebuffer, and 5464 % 64 != 0
Fix that returning a row pitch alignment of 64.
Signed-off-by: Leandro Ribeiro <leandrohr@riseup.net>
Laptop specs
- Intel(R) Core(TM) i7-5500U CPU @ 2.40GHz
- OpenGL renderer string: Mesa DRI Intel(R) HD Graphics 5500 (Broadwell GT2)
- There's also an AMD Radeon R5 M230, which I'm not using (idk if this matters)
- Screen resolution: 1366 x 768
- OpenGL ES 3.1 Mesa 19.3.0-devel
- 5.3.5-arch1-1-ARCH
How to reproduce the bug
- Build kmscube (https://gitlab.freedesktop.org/mesa/kmscube/) from source
- Go to tty (kmscube needs an available display) and run the program:
./kmscube -D /dev/dri/card0
kmscube error
- failed to create fb: Invalid argument
- Failed to get a new framebuffer BO
DRM debug messages
- [ +0.000039] [drm:intel_framebuffer_init [i915]] plane 0 pitch (5464) must be at least 64 byte aligned
- [ +0.000012] [drm:drm_internal_framebuffer_create [drm]] could not create framebuffer
- [ +0.000007] [drm:drm_ioctl [drm]] pid=708, ret = -22
- Kernel related file:
drivers/gpu/drm/i915/display/intel_display.c
What I've done to ""fix"" the error
vim mesa/src/intel/isl/isl.c
- In function
isl_calc_row_pitch
, the alignment value thatìsl_calc_row_pitch_alignment
returns is 4. The function returns in the statementreturn bs;
, for this particular case. - If I edit the function
isl_calc_row_pitch_alignment
toreturn 64;
the kmscube works. - The value that
isl_calc_min_row_pitch
returns is multiple of the alignment value. - When alignment is 4, it returns 5464 and then we have the bug. When it's 64, it returns 5504 and everything works, because the kernel requires the row pitch to be 64 byte aligned.
- As mentioned before, this is just a PoC, since I don't know if the kernel requirement is wrong or if the problem is the value computed by the Intel mesa driver.
Similar bug report and patch
- Bug report: #1825 (moved)
- Patch: !1756
- Didn't work for me:
isl_calc_min_row_pitch
returnsisl_calc_linear_min_row_pitch
, sincetile_info->tiling == ISL_TILING_LINEAR
. - So
isl_calc_tiled_min_row_pitch
, the function edited in the patch, is not being called. It's called only iftile_info->tiling != ISL_TILING_LINEAR
.
CC: @jekstrand