Handle has some limits and can't be used as unique buffer ID on systems
where display controller can scanout from CMA but GPU can work with both
CMA and VRAM.
Such systems have DRM/KMS and DRM/GPU drivers separated.
GBM frontend is always expecting handle for DRM/KMS driver.
In such system any attempt of importing the buffer with more
than 1 contiguous chunk into DRM/KMS driver will fail.
Using dma-buf inode as unique buffer ID is a common practice for
a last several years starting from [this kernel patch][1].
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ed63bb1d1f8469586006a9ca63c42344401aa2ab
Change-Id: Ic3a69010d5da2f866a2252fc7e9eb29d67f8e1ed
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
The gbm_mesa cherry-pick series added a mediatek gralloc@4.0 service
definition but the corresponding init .rc file was missing from the
aosp/android-16.0_r3 branch. Create it from the msm template.
Copyright (C) 2026 Brendan Szymanski <hello@bscubed.dev>
This is adaptation of the Rob Herring's gbm_gralloc HAL [1] to work
as minigbm backend, optimised to work in modern Android conditions.
gbm_gralloc has a huge potential and can provide more-or-less optimal
allocation by using mesa3d allocation APIs. It should work out of the
box for the all hardware mesa3d is supported.
Limitations:
This backend doesn't care of any other SOC-specific graphical components
such as camera, hardware video codecs, etc.
Differences between gbm_gralloc:
1. Designed to distinguish between Allocator and Mapper-sphal users.
For Allocator gbm driver is initialized using standalone KMS card
node (but only if 'lima', 'panfrost' or 'v3d' GPU was detected).
For Mapper requests driver is initialized only using GPU render node.
(which require less permissions for regular apps but suffitient
for mapping).
2. GBM driver is initialized and bo is imported into gbm_mesa only
if Mapper imports bo with software usage flags.
(no time wasted in case SW access isn't required)
3. gbm_gralloc supported only HAL_PIXEL_FORMAT_YV12 video format. This
driver aims to support more formats (using linear modifier only).
* NOTE:
This may also require:
1. Adding secomp rule into the mediaswcodec.policy file
"sched_getaffinity: 1"
2. Adding records to selinux vendor/file_contexts file
"/vendor/lib{64}?/libgbm_mesa_wrapper.so
u:object_r:same_process_hal_file:s0"
"/vendor/bin/hw/android\.hardware\.graphics\.allocator@4\.0-service\.minigbm_gbm_mesa
u:object_r:hal_graphics_allocator_default_exec:s0"
3. Kernel v5.3+ for using fstat(dma-buf)->inode as unique buffer id
[1]: https://github.com/robherring/gbm_gralloc
v2:
- Fixed incorrect size calculations for NV12 buffers
- Add etnaviv, freedreno and vc4 to gpus list which require kmsro entry
- Rebased
v3:
Squashed local fix commits:
- RPI4: Add alignment for CSI camera
- gbm_mesa: Handle DRM_FORMAT_R8 format to handle BLOBS
- gbm_mesa: Always use DRM_FORMAT_R8 for buffers that unsupported by GBM
- gbm_mesa: Add RGB888 format support for CPU access
- gbm_mesa: Remove incorrect negation
- gbm_mesa: Fallback COMPOSER buffers into VRAM
- gbm_mesa: Add combinations to support external camera
v4:
- Use dlopen/dlsym to access gbm_wrapper
- Add fallback allocation for unsupported by mesa3d formats
v5:
- Obtain map-time stride and report it to Android as pixel-stride.
Map-time strides are different after gbm_create and gbm_import.
Use map stride after gbm_import.
This fixes artifacts on Intel and Nouveau.
- GBM wrapper has been converted from cpp to c
- Code refactor and cleanup
- Licence headers added
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Change-Id: If0f3dac42bea74f97a87e5a682380c33f4ff6837
Some drivers may copy/convert the buffer during mapping and
in some cases stride of copied image can be different from
original. Android uses pixel_stride for CPU access and need
map_time stride instead of original stride in this cases.
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
... to avoid compile-time error on C++:
error: ISO C++11 does not allow conversion from string
literal to 'char *' [-Werror,-Wwritable-strings]
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Change-Id: I176eb657f72e92d6b5c7c3b25c78c56f776c20ab
Allow backends with custom DRM probing logic or
backends that does not rely on DRM (dma-heap, ION).
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Change-Id: I7bcaf10205ca051eb109d6e220b8a2af38267442
Bug: b:444260542
Test: Builds, CQ
Change-Id: I544c58d57529696c313601aafce2d75f133b874c
Signed-off-by: George D Sworo <george.d.sworo@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/6932115
Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Miguel Quintero <miguelquintero@google.com>
Commit-Queue: Miguel Quintero <miguelquintero@google.com>
Tested-by: Ryan Neph <ryanneph@google.com>
This is needed for ARC-R container targets using arc-cros-gralloc.
Meanwhile, bump -std=c++14 to -std=c++17 for std::optional and others.
Bug: b/433317686
Test: chromium CI + android CI
Change-Id: Id9ed5f27f6788ca63d0bdb9566c54b3cd4030e16
The write permission for restricted_mtk_cma is unnecessary.
Bug: 433330646
Test: allocate a buffer with GRALLOC_USAGE_PROTECTED usage
Flag: EXEMPT: desktop-only change
Change-Id: Id99a0e03f2e1c7cbb9f15596316dd21aaebdf4a3
All of virgl, venus and gfxstream have long been able to handle the
limited blob mem usage in the legacy backend.
BUG=b:327668289
TEST=AHB cts passing with Venus on Cuttlefish on ANV
Change-Id: Ie6a26c2e5e74faac6f8db060ffcfbb2364610d41
This change modifies buffer allocation to include necessary padding
for buffers with the BO_USE_CURSOR flag. This behavior mirrors
identical logic in the i915, xe, and mtk implementations.
Bug: b/426503691
Change-Id: Ic572a970dcde0606fa9ec5844c57d3136c5d0b84
(cherry picked from commit f13b0faac8501a3bf3eb90f2fd07107728576876)
Rather than use `clang-format` from $PATH (which changes between devs),
use `cros format` which has a pinned version for all people.
Add *.cpp to the include list as not all C++ files use *.cc.
Then run format on the files to fix latent issues.
BUG=None
TEST=./presubmit.sh
Change-Id: I28e167d454a7b089bb79e932b7265fa87e4c331f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/6475964
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Ryan Neph <ryanneph@google.com>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Dominik Behr <dbehr@chromium.org>
Bug: None
Test: lunch brya-trunk_staging-userdebug && m libminigbm_gralloc
Change-Id: I23022dbb536ade53951fe61014c5056e114f4bbc
Everything now builds under the same minigbm name for all platforms.
Bug: 388092228
Test: Boot corsola to desktop
Flag: EXEMPT: desktop-only change
Change-Id: I00708383151f832bcccec1aad8091f422dfcf2c3
This change modifies buffer allocation to include necessary padding
for buffers with the BO_USE_CURSOR flag. This behavior mirrors
identical logic in the i915 and xe implementations.
Bug: b/420919101
Change-Id: I113162cf400116e2627b2a6bb20b560207117cf3
For bringup purpose, SS VK might be used to boot the system. To ease the
runtime vulkan icd switch, normally we preset TARGET_BOARD_PLATFORM to
pastel, so that to leave ro.hardware.vulkan unset post boot. At runtime,
we can push a real hw driver and set ro.hardware.vulkan to switch to it,
which can be safely reset after reboot.
Bug: b/417259528
Test: boot to ui with SS VK chosen by TARGET_BOARD_PLATFORM
Change-Id: I37212fadaf007c2c2d054b878f0a4f411f1a6fe8
This change modifies buffer allocation to include necessary padding
for buffers with the BO_USE_CURSOR flag. This behavior mirrors
identical logic in the i915 implementation.
Bug: b/417750580
Change-Id: I3358678fd194eff24fad2cb3749ca59bac33afb8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/6546486
Commit-Queue: Andrew Wolfers <aswolfers@chromium.org>
Tested-by: Andrew Wolfers <aswolfers@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Drew Davenport <ddavenport@chromium.org>
goldfish-opengl will be retired
Bug: 416327221
Test: presubmit
Change-Id: Ie7250187d9604f9c6f9d368a513493dc72aa5c58
Signed-off-by: Roman Kiryanov <rkir@google.com>
for all render/scanout formats and R8 and non YUV image source formats.
Bug: 414820115
Test: run dEQP-VK.image.swapchain_mutable.android.2d_array
Change-Id: I074f84b75f9096a77c9db90e66fcbd98672372ea
so that to avoid any residual init, vintf, libs, etc when switching
gralloc backends for incremental builds.
Bug: N/A
Test: toggle between gralloc version and m and check
Change-Id: I2c19aa115b584de938e2364e40a52c56c901adda
Android gralloc via AIDL allows use of AHB-backed external memory for
storage images with usage AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER; its
equivalents are VK_IMAGE_USAGE_STORAGE_BIT/BO_USE_GPU_DATA_BUFFER.
On older interfaces before gralloc 4.1/AIDL, BO_USE_GPU_DATA_BUFFER
is only allowed for BLOB formats; this adds it to combinations with
non-BLOB formats for the newer interfaces.
The image_storage_formats list is a subset of the formats being used
that support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT which for anv is
power-of-two formats; here it ends up excluding the YCbCr formats.
Bug: 397763052
Test: dEQP-VK.wsi.android.[display_timing.*/ swapchain*]
Change-Id: I6b034790fa77f15fb341acfae4a45255231a5a14
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/6442090
Commit-Queue: Juston Li <justonli@google.com>
Commit-Queue: ChromeOS Auto Runner <chromeos-auto-runner@chromeos-bot.iam.gserviceaccount.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Tested-by: Juston Li <justonli@google.com>
(cherry picked from commit db68fa51e4b7ed19546c80806da9f462c3b5c8d7)