Commit Graph

36 Commits

Author SHA1 Message Date
Yiwei Zhang 62f79f9ec1 venus: add more tracepoints for perf analysis
This change adds the tracepoints that can help understand app behavior
for debugging and performance optimization purposes.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17497>
2022-07-15 20:57:41 +00:00
Yiwei Zhang f96e25ae05 venus: suballocate more for layering
Previously we suballocate only for host visible memory type to reduce
the kvm mem slot usage. That is no longer an issue given the limit has
been raised. However, we should still suballocate to make layering
clients performant. So we just suballocate regardless of mem type.

This change also increases the allowed suballocation size request from
64K to 128K, which makes layering clients happier.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17497>
2022-07-15 20:57:41 +00:00
Oleksandr Gabrylchuk 02fab4cf9e venus: Implement guest vram blob type.
Add support of GUEST_VRAM type of blob. These are dedicated heap memory
allocations required for vk support on hypervisors that don't support
runtime injections of host memory into guest physical address space.

The flow of usage:
1) Host VM reserves dedicated heap memory
2) Device get info about memory reservations and report it to guest
using mmio registers
3) Guest virtio-gpu driver on starts checks mmio registers for
physical address and length of reserved region. Then it reserves it
in guest.
4) On each call of vkAllocateMemory() guest driver gets chunk of
required memory and send it to host using sg list. It uses one sg
entry for 1 blob call. Heap is managed on guest using drm memory
manager (drm_mm).

Signed-off-by: Oleksandr.Gabrylchuk <Oleksandr.Gabrylchuk@opensynergy.com>
Signed-off-by: Andrii Pauk <Andrii.Pauk@opensynergy.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14536>
2022-03-01 17:25:56 +00:00
Chia-I Wu 8a30b1541c venus: use 64KB alignment for suballocations
TGL CCS surface addresses must be aligned to 64KB.

Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15001>
2022-02-11 21:26:45 +00:00
Yiwei Zhang 8665910a63 venus: move bo allocation for mappable memory to vn_MapMemory
This change defers the bo allocation for non-external mappable memory
direct allocation.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13874>
2021-12-04 01:48:16 +00:00
Yiwei Zhang 19d6b497fb venus: track memory type property flags in vn_device_memory
Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13874>
2021-12-04 01:48:16 +00:00
Yiwei Zhang 86b3a4e6aa venus: defer roundtrip waiting to vkFreeMemory time
bo allocations for the below cases are after device memory allocation:

1. direct non-external mappable memory allocation
2. pool grow
3. exportable memory allocation

For (1) and (2), the bo is for mapping, which is a pure kernel operation
to happen later. So roundtrip waiting can be deferred until free memory.

For (3), the bo is for either fd export or mapping, which are both pure
kernel operations. So roundtrip waiting can also be deferred until free
memory.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13874>
2021-12-04 01:48:16 +00:00
Yiwei Zhang 9fa3e3df9e venus: simplify device memory pool alloc and refcount
The behavior we stick to is that the base_bo is always created for pool
memory so that to keep it alive during suballocates and frees.

This CL does the below:
1. rename pool_alloc to pool_suballocate and align the api interface
2. rename simple_alloc to pool_grow_alloc to make it pool specific
3. refactor pool_free and simple_free into a pair of pool_ref and
   pool_unref to simplify that vkFreeMemory is only called after the
   pool bo gets destroyed.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13874>
2021-12-04 01:48:16 +00:00
Yiwei Zhang e019780626 venus: refactor vn_device_memory_simple_alloc
Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13874>
2021-12-04 01:48:16 +00:00
Yiwei Zhang fc237f80c6 venus: add struct vn_image_memory_requirements
This aligns with vn_buffer_memory_requirements and can potentially
simplify future image memory requirements cache init.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13428>
2021-10-28 00:23:14 +00:00
Yiwei Zhang b108e096d1 venus: add struct vn_buffer_memory_requirements
This will simplify later buffer cache api.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13428>
2021-10-28 00:23:14 +00:00
Yiwei Zhang 5a2513a515 venus: assign valid memoryTypeIndex of exportable ahb memory for image
The current AHB spec leaves the input memoryTypeIndex undefined when
allocating exportable AHB memory backing an external image.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13537>
2021-10-28 00:02:54 +00:00
Yiwei Zhang 97aa90dec2 venus: workaround a blob_mem mappable size check issue
For blob_mem allocated from virtgpu_virgl backend, the guest mappable
size queried can be smaller than the size returned from image memory
requirement query from the host side. Here we temporarily workaround
until we switch to use cross-domain backend in minigbm.

Cc: 21.2.3 mesa-stable

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12687>
2021-09-01 22:38:48 +00:00
Yiwei Zhang b816167312 venus: fix all missing vn_object_base_fini
Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12498>
2021-08-23 18:51:38 +00:00
Chia-I Wu 22cb100ea0 venus: break up vn_device.h
Break it up into vn_{device,instance,physical_device}.h.  Suggested by
Ryan Neph.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12144>
2021-08-02 22:45:45 +00:00
Chia-I Wu 567bbfd56b venus: suballocate memory in more cases
When a dedicated allocation is not required, ignore it and suballocate.

Fixes dEQP-VK.api.invariance.random.

Cc: 21.2 mesa-stable
Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12072>
2021-07-27 03:53:52 +00:00
Chia-I Wu f06b0df741 venus: clean up vn_AllocateMemory
Mainly to add vn_device_memory_should_suballocate.

Cc: 21.2 mesa-stable
Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12072>
2021-07-27 03:53:52 +00:00
Yiwei Zhang 3a894d00bc venus: refactor gralloc buffer and drm modifier properties query
1. Code clean up
2. Fixed a misused allocator
3. Add error logs for external memory interop

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11195>
2021-06-05 22:50:23 +00:00
Yiwei Zhang d08930f2fa venus: support AHB prop query with host dma_buf size
Upon instance creation, venus experimental features are cached in the
vn_instance. If memoryResourceAllocationSize feature is supported, chain
VkMemoryResourceAllocationSizeProperties100000MESA to the pNext of
VkMemoryResourcePropertiesMESA to get the host allocation size of the
dma_buf fd.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11048>
2021-06-03 19:23:04 +00:00
Chia-I Wu 551d7032df venus: silence compiler warnings
Silence warnings in release builds.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11166>
2021-06-03 17:48:30 +00:00
Chia-I Wu 4bd7a3829e venus: fix asserts on mem bo
They failed to check the result before asserting.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11154>
2021-06-03 05:53:24 +00:00
Chia-I Wu 67ad9f7580 venus: add vn_device_memory_alloc as a helper
It is used for the most common case (non-ahb, non-import, and
non-suballocate).

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11154>
2021-06-03 05:53:24 +00:00
Yiwei Zhang beb80858d8 venus: refactor for property query of dma_buf fd
With a TODO to route host storage size instead of that from the guest.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11055>
2021-05-29 04:48:50 +00:00
Yiwei Zhang ccefcb0baf venus: fix misaligned bo_flags between import and query
For importing an dma_buf fd, export info is not required. Leaving the
bo_flags missing VIRTGPU_BLOB_FLAG_USE_SHAREABLE bit as well as the
VIRTGPU_BLOB_FLAG_USE_CROSS_DEVICE bit. Upon querying fd properties,
DMA_BUF handle type will be specified which generates a new bo_flags
not matching the prior one.

This patch aligns the above 2 bits for the dma_buf import path.

Test: vkGetAndroidHardwareBufferPropertiesANDROID should succeed with
      a valid AHB with AHARDWAREBUFFER_FORMAT_BLOB format.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11055>
2021-05-29 04:48:50 +00:00
Yiwei Zhang 1df4c960c6 venus: rename dmabuf to dma_buf when it represents a type
Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11055>
2021-05-29 04:48:50 +00:00
Yiwei Zhang 7370f33953 venus: implement AHB allocation and import (part 2/2)
TODO left to fix plane count > 1 case for external memory.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10960>
2021-05-26 20:26:19 +00:00
Yiwei Zhang 1743892f24 venus: implement AHB allocation and import (part 1/2)
This patch refactors the struct look up logic for memory allocation, and
it prepares the necessary info for ahb allocation and import.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10960>
2021-05-26 20:26:19 +00:00
Yiwei Zhang 4958ce582c venus: refactor device memory fd import
This patch wraps up fd import logic, which will be used later by ahb
import. This patch also removes a redundant check in need_bo.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10960>
2021-05-26 20:26:19 +00:00
Chia-I Wu b39ea79c95 venus: merge bo create and init ops
There is no good reason to seprate them.  I also plan to adopt
util_sparse_array, which requires the kernel BO to be created first (to
use its gem_handle/res_id as the key).

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10437>
2021-04-28 12:58:58 -07:00
Chia-I Wu 0d703b9d64 venus: pass vn_renderer in vn_renderer_bo functions
We will move vn_renderer_bo_ops to vn_renderer in the following commit.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10437>
2021-04-28 12:58:58 -07:00
Chia-I Wu 6db21119b7 venus: add dev->renderer pointer
dev->instance->renderer is slower to type and to follow.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10437>
2021-04-28 12:58:58 -07:00
Yiwei Zhang 95844b0978 venus: use VK_EXT_image_drm_format_modifier
This commit contains a hack to retrieve extended buffer info, which will
be fixed by moving the logic into gralloc HAL implementation.

With this hack, the rendering result is correct.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10259>
2021-04-27 00:15:39 +00:00
Yiwei Zhang e91c95dba8 venus: force a roundtrip after vn_renderer_bo_create_dmabuf
This is to ensure the kernel operations and the later ring operations
are in the right order.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10390>
2021-04-21 21:40:32 +00:00
Yiwei Zhang 8bbe55533f venus: close the import memory fd on success
VkImportMemoryFdInfoKHR takes fd ownership on a successful import.
Internally, vn_renderer_bo_create_dmabuf doesn't rely on the fd to
extend the life cycle of the bo or the host resource, and it won't
close the fd. Thus, we shall close the fd when the import succeeds.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10390>
2021-04-21 21:40:32 +00:00
Yiwei Zhang 1932207902 venus: implement dma_buf fd import and properties query
This change is for supporting VK_ANDROID_native_buffer implementation,
and it does not advertise VK_KHR_external_memory_fd.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10195>
2021-04-15 00:58:00 +00:00
Chia-I Wu 49a15148fa venus: split out vn_device_memory.[ch]
Move VkDeviceMemory functions to the new files.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Acked-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10117>
2021-04-09 16:58:46 +00:00