In crosvm, the MinigbmDevice implementation of the Gralloc interface
assumes that a call to get_image_memory_requirements will be immediately
followed by a matching call to allocate_memory, as the implementation
stashes a buffer allocated by the first call to be returned by the
second.
However on Android multiple processes/threads can be making calls to
allocate memory via CrosGralloc. In particular if the device is
configured to use the cross-domain back-end, and two threads are trying
to allocate memory, the two requests to get the memory requirements for
an allocation can be submitted to crosvm followed by the two requests to
actually allocate memory.
When the assumption is violated, the crosvm code was raising an error
for the SECOND memory requirement request. However the error does not
propagate back to the virtgpu_cross_domain code here. The result is that
the request is understood to have succeeded, and the code here then
reads the size metadata from the response buffer, but that contains the
values from the FIRST memory requirement request. Those values may be
There is a fix for crosvm in review (https://crrev.com/c/6260975) to
not raise an error if the calls are not made in the expected order,
while still maintaining a single stashed buffer. However this means the
memory allocated for one of the two requests must be released, and would
have to be reallocated, at some extra runtime cost as allocating
graphics memory requires allocating physically contiguous memory.
The existing cross-domain code here acquired a simple mutex lock to
maintain a metadata cache, which was held for the duration of the first
call. This change extends the duration of the lock to the entire
allocation request so that the guest always makes the two requests in
the expected order.
BUG=b:395748805,b:355060470
TEST=ARCVM on Corsola starts up under high CPU stress
Change-Id: I6429ea28141ef440345a3eb442066173b3e04802
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/6288246
Commit-Queue: Lloyd Pique <lpique@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Lloyd Pique <lpique@google.com>
The last plane's size may include any padding bytes introduced by
virtgpu's page-alignment, but its not incorrect, and all other planes
will be exact.
BUG=b:365820897
TEST=Spot check new size calculation for YVU420_ANDROID allocation
Change-Id: I6e88905d7191dca7e68e5dfd773d2fcaac79773d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/5849473
Tested-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Chia-I Wu <olv@google.com>
Commit-Queue: Chia-I Wu <olv@google.com>
Auto-Submit: Ryan Neph <ryanneph@google.com>
Reviewed-by: Dawn Han <dawnhan@google.com>
Metadata query sent to host minigbm detects the YVU420 + LINEAR
combination and internally handle as YVU420_ANDROID to obey Android's
specific layout requirements.
This matches a similar hack applied to the virtgpu_virgl backend long
ago: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2596704
BUG=b:360937659
TEST=Fixes instagram video decode artifacts
Change-Id: I591e427a926327b841be6e280ca57eefab598965
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/5849472
Reviewed-by: Chia-I Wu <olv@google.com>
Tested-by: Ryan Neph <ryanneph@google.com>
Auto-Submit: Ryan Neph <ryanneph@google.com>
Commit-Queue: Ryan Neph <ryanneph@google.com>
The latest drv_get_os_option consumes the prop name directly without
lowering or etc. Meanwhile, to use strcmp instead of strncmp, we must
query ro.product.name instead since the .device one has suffix.
BUG=b:269982880
Change-Id: I27543975ec0c2a0bd7700ebd59c4dc5dd5dd2793
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4571850
Reviewed-by: Dawn Han <dawnhan@google.com>
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Amit Pundir <amit.pundir@linaro.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
Move mt8183_camera_quirk_ into struct cross_domain_private.
Add a helper `drv_get_os_option` in `drv_helper` to query os option.
Advertise DRM_FORMAT_MTISP_SXYZW10 as supported format in virtgpu_cross_domain.c.
Implement cross domain's own resolve_format_and_use_flags entry point.
BUG=b:269982880
TEST=tested on a kukui machine after applying the change. Camera and
screen recording works fine.
Change-Id: Ia0d6e2cc701477aa6b9542de84e24f8aeb5a29e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4304961
Commit-Queue: Dawn Han <dawnhan@google.com>
Reviewed-by: Dominik Behr <dbehr@chromium.org>
Tested-by: Dawn Han <dawnhan@google.com>
The multi-planar formats are being allocated into a single plane,
and the minigbm exynos backend is dropped. So we can use `handle` instead of handles as of now.
Remove some of the helper functions that calculate the number of planes.
There is no need to check if there is more than one kernel buffer per buffer object.
Added a new function `drv_gem_close` in `drv_helpers` that can be used by `drv_gem_bo_destroy` and `drv_prime_bo_import`. It can be used to clean the unused gem_handle.
Bug=b:266776512
TEST=camera and screenshot work fine after deploying the change #strongbad
TEST=camera and screenshot work fine after deploying the change #kukui-arc-r
TEST=camera and screenshot work fine after deploying the change, tested a couple of apps in the Google Play Store, and checked file `dma_buf/bufinfo` to see there's no object leaking. #guybrush
Change-Id: Ib63559504e4cb8f1a32ae90170925146613d694f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4297873
Commit-Queue: Dawn Han <dawnhan@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Dawn Han <dawnhan@google.com>
Remove the parameter to align with upstream gbm.
For some places that use the number of planes. The number is 1. The
multi-planar formats are being allocated into a single plane, and
minigbm exynos backend is dropped. So we can just set the plane
index to 0 if needed.
Fixed the format in i915.c.
Bug=b:266776512
TEST=camera works after deploying the change #strongbad
TEST=camera works after deploying the change #corsola
Change-Id: I0880917754c01b9d0f27d21f3c42d87f00a09f50
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4249501
Commit-Queue: Dawn Han <dawnhan@google.com>
Tested-by: Dawn Han <dawnhan@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olv@google.com>
Blob formats (aka buffers) get represented as R8 textures with height
of one and width==size. These have no particular stride requirement,
even though the host might ask for a pitch that would make sense for
a 2D R8 texture with height greater than one.
Relax the validateBufferSize check for format_blob rather than set the
stride. As blob defined: buffers of this format must have a height of
1, so height doesn't need to be checked specifically.
BUG=b:269565421
TEST=CQ
Change-Id: I7a8d4dbf292330df0c24b502abd9dbf3dceac728
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4263402
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Start from aligning with the virgl backend that most platforms stay on.
Later we can do per platform customization in cross_domain backend.
BUG=b:262928949
TEST=CtsNativeHardwareTestCases on mtk
Change-Id: Ic7f1cb2ae9c8485f24dc7da0e27933de18cc59c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4113687
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
Auto-Submit: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
On ARCVM platforms involving no vrend ctx, it's not legit to use the
legacy timeline. So no matter wait or not in cross_domain EB, we must
apply VIRTGPU_EXECBUF_RING_IDX.
BUG=b:262920670
TEST=create_fence failure from this EB is gone
Change-Id: I2ab6b620d37ef7d40a5503a98828204cc34a094b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4113686
Auto-Submit: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Venus device memory mapping setup must succeed for AHB VkBuffer.
Meanwhile, the imported AHB can be allocated with only GPU_DATA_BUFFER
flag. So we must add mappable flag in virtgpu backends accordingly.
BUG=b:246814802
TEST=Blob_BlobTest_GpuDataBufferVertexBuffer_BLOB
Change-Id: I88f63c732d3b133daf755d73ed54578605d27112
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3896159
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olv@google.com>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Rob Clark <robdclark@chromium.org>
No need to introduce host storage and mapping to the guest for buffers
that only have CPU access. Fixes slow performance of sw encoders.
BUG=b:238158981, b:239333100
TEST=cts-tradefed run cts -m CtsVideoTestCases -t android.video.cts.VideoEncoderDecoderTest#testAvcGoog0Perf0320x0240
TEST=cts-tradefed run cts -m CtsCameraTestCases -t android.hardware.camera2.cts.RecordingTest#testSupportedVideoSizes[1]
Change-Id: Iaf88a750ae215d3a02b8415ab93be06b08a7f550
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3777563
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Auto-Submit: Rob Clark <robdclark@chromium.org>
Tested-by: Rob Clark <robdclark@chromium.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
Commit-Queue: Rob Clark <robdclark@chromium.org>
Blob formats (aka buffers) get represented as R8 textures with height
of one and width==size. These actually have no particular stride
requirement, even though the host might ask for a pitch that would make
sense for a 2D R8 texture with height greater than one.
BUG=b:239335026
TEST=cts-tradefed run cts -m CtsNNAPITestCases
Change-Id: I293f03b1c4292ed50252ea272f7d9e47e6c64ee2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3770014
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Rob Clark <robdclark@chromium.org>
Auto-Submit: Rob Clark <robdclark@chromium.org>
Commit-Queue: Rob Clark <robdclark@chromium.org>
Reviewed-by: Jason Macnak <natsu@google.com>
It is used for AHBs that are SSBOs/UBOs. But I noticed this mainly
because venus's test allocation uses this as well when
VK_ANDROID_external_memory_android_hardware_buffer is enabled.
BUG=b:238663100
TEST=ANGLE
Change-Id: I72bdc73e1afdcb3f23667a77bc892e8402f25188
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3749168
Auto-Submit: Chia-I Wu <olv@google.com>
Commit-Queue: Chia-I Wu <olv@google.com>
Tested-by: Chia-I Wu <olv@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
It's better just to conditionally advertise cross domain capset
in crosvm.
This is to upstream aosp/2101455.
BUG=173630595
TEST=compile
Change-Id: Ic44176141cade44bfa0cc2fcf457ddafb7ae7195
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3707443
Reviewed-by: Rob Clark <robdclark@chromium.org>
Auto-Submit: Yiwei Zhang <zzyiwei@chromium.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
This is required for dma-buf sharing, which is a thing that can happen
for sharing across processes even if it is the same GPU device involved
on both ends. (Also, anything that gralloc allocates needs to be dmabuf
exportable, so not setting _USE_CROSS_DEVICE is just plain wrong.)
This fixes hangs in deqp-cts when using cross-domain virtgpu backend
(rather than the virgl backend)
BUG=b:230100768
TEST=Run deqp-cts
Change-Id: Ic9204feb0af52ef4a25bcfd554425cb8cd3f3fe1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3696038
Tested-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Commit-Queue: Rob Clark <robdclark@chromium.org>
Auto-Submit: Rob Clark <robdclark@chromium.org>
It makes more sense to resovle the format and use_flags together to
avoid duplicates.
Add the helper to vc4 and dumb_driver backends since that's missed
from prior frontend refactoring.
Split the resolve helper in virtgpu_virgl for the 3d and 2d paths to
make code logic cleaner.
BUG=b:199524294
TEST=CQ
Change-Id: I89b633ea484f0fc5bb9b4e0548cad017b9970cc6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3200143
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Reviewed-by: Chia-I Wu <olv@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Dominik Behr <dbehr@chromium.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
1. frontends access the driver via drv.h only
2. the renamed drv_helpers and drv_array_helpers are for driver only
3. remove extern "C" from drv_helpers.h given not exposed to gralloc
4. remove all redundant includes for those helpers
BUG=b:199524294
TEST=CQ and gralloc builds on aosp
Change-Id: I3f4d33076a6a8161804f1b7c26950ff5496507e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3195651
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olv@google.com>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
crosdomain specific metadata_cache should be protected by a backend
specific lock to reduce lock contention.
BUG=b:201110412
TEST=CQ
Change-Id: Ic3cedd7ad7903e669f7fba2b5f45d88739fbdc97
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3188471
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olv@google.com>
Only 2d virtgpu backend needs to fallback here because virtio primary
plane only allows DRM_FORMAT_XRGB8888.
Most our platforms cannot display YV12 (except msm), thus the fallback
is required for the converted DRM_FORMAT_YVU420_ANDROID. For virgl
backend, additionally append a BO_USE_LINEAR as a replacement for the
hack inside compute_virgl_bind_flags.
BUG=b:199524294
TEST=CQ
TEST=gralloctest alloc_combinations
TEST=android.media.cts.VideoDecoderRotationTest
Change-Id: Ic87838ea2aae2b0abf87ed898ad75a3d7e556471
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3166775
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Auto-Submit: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
For PCI passthrough and other use cases, it's desirable to get the
render target out of the guest. In the PCI passthrough case, the
dGPU's memory is not available to the host.
The solution that many people are interested in is to use virtgpu
to allocate, and use the dGPU to render to that guest memory. This
change adds a flag to the existing blob api, indicating to the host
that it *must* create an OS-specific handle out of guest memory upon
success.
Obviously, this is just for prototyping. Only when the lords and
princes of dri-devel/mesa-dev -- eyes filled with the light of
upstream, swords as cold as blue ice -- descend from their heavenly
abodes on top of Mount Gogigyeopbbang may we have a proper
solution.
But for now, we'll have to live in our downstream mud hut with yet
another hack. Oh well!
BUG=b:173630595
TEST=create a bunch of udmabufs
Change-Id: Ia33dc0c415be61423017003d3739c4fb7498dba5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2857886
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Jason Macnak <natsu@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
This change provides a route to the host side "cross domain"
allocator, which is specialized for resource sharing across domain
boundaries. It uses the upcoming CONTEXT_INIT ioctl to initialize
the backend when available, and multiple timelines to perform
metadata queries.
While it would be awesome to use the revolutionary Address Space
Graphics (ASG) algorithm for metadata queries, it would be
non-trivial to pull off in minigbm.
Key aspects of the cross-domain allocator are:
* Intelligently falls back to OpenGL texture allocation host-side
when external memory is not available. The fallback path is
named "virgl", even though it encompasses gfxstream and 2D mode.
More refactorings will be added in the future for further
clarity.
* Uses host Vulkan or minigbm to perform metadata query, and uses
a cache to minimize vmexits.
* No shadow memory. Only zero-copy blobs will be supported if the
blob is mappable. Shareable blobs may be compressed or tiled if
not mappable.
* A commitment to sharing code across Google projects and
cross-platform GPU virtualization.
The main goal here is to enable faster interation/testing, so this
code is just a prototype. It should be fine to merge via minigbm,
since the project has a very chill philosophy and even proudly
accepts code that doesn't make any sense (crrev.com/c/2583188)
[so long as existing users are not broken].
BUG=b:173630595
TEST=launch virtual machine with 2D mode
TEST=launch virtual machine with 3D mode
Change-Id: Ie33a46f19e5cdd82a2ac03bcf2351f4a8f294970
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2691716
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>