Commit Graph

83 Commits

Author SHA1 Message Date
Simon Ser 377668aaf6 render/vulkan: check that requested size is smaller than max
Fail with a clearer error when the requested size is too large.
Without this, we allocate a buffer with a size smaller than what
was requested.

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3975
2023-01-19 18:50:59 +00:00
Brett Ernst 1ba322e9ff vulkan: increase max stage size to support large buffers 2023-01-18 19:45:26 -08:00
llyyr 10e16db738 render/vulkan: use correct source offset in read_pixels 2023-01-18 06:56:49 +05:30
Kirill Primak faa31d123f render/vulkan: always finish buffer addon on texture destroy 2022-12-22 12:42:08 +03:00
Kirill Primak 0702eb9219 render/vulkan: remove NULL renderer check on texture destroy 2022-12-22 11:45:12 +03:00
Simon Ser 8456ac6fa9 render/vulkan: wait for DMA-BUF fences
The Vulkan spec doesn't guarantee that the driver will wait for
implicitly synchronized client buffers before texturing from them.
radv happens to perform the wait, but anv doesn't.

Fix this by extracting implicit fences from DMA-BUFs, importing
them into Vulkan as a VkSemaphore objects, and make the render pass
wait on these VkSemaphores.
2022-12-06 14:54:09 +00:00
Simon Ser a37a22e344 render/vulkan: use initializers for VkSubmitInfo 2022-12-03 09:53:32 +01:00
Simon Ser 666c45bb29 render/vulkan: remove stage_cb conditional
We always have a stage_cb at this point.
2022-12-03 09:39:12 +01:00
Simon Ser dd5be430b4 render/vulkan: remove pre_cb in vulkan_end()
pre_cb was an alias for stage_cb->vk. Let's just use a single
variable instead.

Additionally, early return when vulkan_record_stage_cb() fails.
We were crashing in vkCmdPipelineBarrier() if that happened.
2022-12-03 09:36:18 +01:00
Simon Ser 27e057319a render/vulkan: fix vkCmdClearAttachments validation error
Skip clears with an empty scissor.

Fixes the following validation error:

    00:00:09.734 [wlr] [render/vulkan/vulkan.c:61] Validation Error: [ VUID-vkCmdClearAttachments-rect-02682 ] Object 0: handle = 0x62600001b100, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0xadbd476f | CmdClearAttachments(): pRects[0].rect.extent.width is zero. The Vulkan spec states: The rect member of each element of pRects must have an extent.width greater than 0 (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkCmdClearAttachments-rect-02682) (VUID-vkCmdClearAttachments-rect-02682)
2022-12-03 09:30:30 +01:00
Simon Ser d6ff20268b render/vulkan: fix comma 2022-12-02 23:26:34 +01:00
Simon Ser 56326c7998 render/vulkan: use initializers for VkImageMemoryBarrier 2022-12-02 23:26:01 +01:00
Simon Ser 79aea58834 render/vulkan: fix missing pSignalSemaphores for stage CB
We were filling VkTimelineSemaphoreSubmitInfoKHR.pSignalSemaphoreValues,
but we were missing VkSubmitInfo.pSignalSemaphores.

This was causing VkTimelineSemaphoreSubmitInfoKHR.pSignalSemaphoreValues
to be ignored. By chance, the render command buffer was using the
next timeline point, so we were waiting for that instead.
2022-12-02 19:28:13 +00:00
Simon Ser 47a038c90e render/vulkan: move VkDescriptorSetAllocateInfo down
Move it down, right before it's used.
2022-12-02 18:28:55 +00:00
Simon Ser 337ef33edc render/vulkan: make shm/dmabuf split clearer in wlr_vk_format_props
struct wlr_vk_format_props contains a mix of properties for shm
and dmabuf, and it's not immediately clear which fields are for
which kind of buffer. Use a nested struct to group the fields.
2022-12-02 15:18:59 +00:00
Simon Ser db9d277614 render/vulkan: make vulkan_format_props_find_modifier() return value const 2022-12-02 15:18:59 +00:00
Simon Ser b4ad4671dc render/vulkan: check for barrier array alloc failure 2022-12-02 15:14:27 +00:00
Simon Ser bc7f8de842 render/vulkan: improve message on format prop error
Use a more appropriate message on
vkGetPhysicalDeviceImageFormatProperties2() error.
2022-12-02 16:10:42 +01:00
Simon Ser 338a9616bd render/vulkan: simplify vulkan_format_props_query() 2022-12-02 16:10:41 +01:00
Simon Ser a3874cac6c render/vulkan: extract DMA-BUF format query to separate function 2022-12-02 16:09:58 +01:00
Simon Ser 21c4516838 render/vulkan: add 64-bit UNORM and SFLOAT formats 2022-12-02 10:36:36 +01:00
Simon Ser 9f938f7f2a render/vulkan: add more packed formats 2022-12-02 10:35:45 +01:00
Simon Ser 171c9081d1 render/vulkan: add more 8 bits per channel formats 2022-12-02 10:28:52 +01:00
Simon Ser ad165f7daf render/vulkan: explain format mapping with DRM 2022-12-02 10:24:00 +01:00
Simon Ser 8b9a48c984 render/vulkan: drop "_format" in wlr_vk_format fields
"format" is already in the name, no need to repeat ourselves.
`format->vk_format` sounds a bit redundant.
2022-12-02 10:24:00 +01:00
Alexander Orzechowski db0e962368 wlr_texture: Expose owning renderer 2022-12-01 04:41:43 -05:00
Simon Ser d2238bf722 render/vulkan: import semaphore to DMA-BUF instead of blocking
Right now the Vulkan renderer blocks until the frame is complete
after rendering. This is necessary because Vulkan doesn't
interoperate well with implicit sync we use everywhere else.

Use the new kernel API to import a sync_file into a DMA-BUF to
avoid blocking.
2022-11-28 23:50:41 +00:00
Simon Ser 10f543d579 render/vulkan: release stage buffers after command buffer completes
We need to wait for the pending command buffer to complete before
re-using stage buffers. Otherwise we'll overwrite the stage buffer
with new contents before the texture is fully uploaded.
2022-11-28 23:50:41 +00:00
Simon Ser 2a414c896e render/vulkan: destroy textures after command buffer completes
We need to wait for any pending command buffer to complete before
we're able to fully destroy a struct wlr_vk_texture: the Vulkan
spec requires the VkDescriptorSet to be kept alive.

So far we've done this in vulkan_end(), after blocking until the
command buffer completes. We'll soon stop blocking, so move this
logic in get_command_buffer(), where we check which commands buffers
have completed in a non-blocking fashion.
2022-11-28 23:50:41 +00:00
Simon Ser 0730552e85 render/vulkan: drop unused fields from wlr_vk_format_modifier_props
export_imported is never used, and dmabuf_flags is already checked
in query_modifier_support().
2022-11-28 10:22:56 +01:00
Manuel Stoeckl c02872e033 render/vulkan: align staging buffers for texture upload
vkCmdCopyBufferToImage requires that the buffer offset be a multiple
of the texel block size, which for single plane uncompressed formats
is the same as the number of bytes per pixel. This commit adds an
alignment parameter to vulkan_get_stage_span which ensures that the
provided span (and the sequence of image copy operations derived which
use it) have this alignment.
2022-11-25 12:29:02 -05:00
Manuel Stoeckl 3ed69b4946 render/vulkan: add support for RGB565 texture format
Since this does not have a matching _SRGB-type vulkan format, add a
new shader variant/pipeline to perform the sRGB->linear texture
conversion.
2022-11-25 14:19:27 +00:00
Simon Ser 99134c26b8 render: stop pulling <wlr/backend.h>
Let's just forward-declare struct wlr_backend instead.

We need to fixup the Vulkan renderer: it needs makedev(), which
got included by chance via <wlr/backend.h> → <wlr/backend/session.h>
→ <libudev.h>.
2022-11-24 21:50:28 +00:00
Manuel Stoeckl b97ef59393 render/vulkan: update shm texture data in one batch 2022-11-21 17:55:46 -05:00
Simon Ser d6e2ab5145 render/vulkan: detect device loss 2022-11-15 15:50:19 +00:00
Simon Ser 23540b5579 render: allow wlr_renderer_impl.begin to fail
Make it return a bool to indicate success/failure. Adapt the
various implementations to check errors.
2022-11-15 15:50:19 +00:00
zccrs 5b34fe5513 render/vulkan: add wlr_vk_texture_has_alpha
Allow to get whether has alpha channel of the VkImage, it can help an
optimization to disable blending when the texture doesn't have alpha.
Because the VkFormat isn't enough because it's always set to
VK_FORMAT_B8G8R8A8_SRGB or VK_FORMAT_R8G8B8A8_SRGB.
2022-11-15 10:58:45 +08:00
Simon Ser 6baf045590 render/texture: constify wlr_texture_update_from_buffer() 2022-11-11 23:11:17 +00:00
Simon Zeni f3ba14e491 render/vulkan: remove hardcoded validation layers
Users should use the VK_INSTANCE_LAYERS env var to set layers at runtime
2022-11-11 22:56:37 +00:00
Simon Ser e1ba64c4b7 render/vulkan: use initializer for VkBufferImageCopy
Missed that one it seems.
2022-11-11 19:26:48 +00:00
Simon Ser d112c2d922 render/vulkan: wait for device to become idle in vulkan_destroy()
It's not safe to destroy any resources which might still be in-use
by the GPU. Wait for any asynchronous tasks to complete before
destroying everything.
2022-11-11 19:18:04 +00:00
Simon Ser f4f3c15c1e render/vulkan: always wait for last stage to complete before rendering
When we have multiple command buffers in flight, we need to make
sure we don't start rendering before the previous texture uploads
are complete.
2022-11-11 19:18:04 +00:00
Simon Ser 7fdcb45e66 render/vulkan: use command buffer pool for stage 2022-11-11 19:18:04 +00:00
Simon Ser f1eae0eeeb render/vulkan: add a command buffer pool
Before re-using a VkCommandBuffer, we need to wait for its
operations to complete. Right now we unconditionally wait for
rendering to complete in vulkan_end(), however we have plans to
fix this [1]. To fully avoid blocking, we need to handle multiple
command buffers in flight at the same time (e.g. for multi-output,
or for rendering followed by texture uploads).

Implement a pool of command buffers. When we need to render, we
pick a command buffer from the pool which has completed its
operations. If we don't find one, try to allocate a new command
buffer. If we don't have slots in the pool anymore, block like we
did before.

[1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3574
2022-11-11 19:18:04 +00:00
Simon Ser a8a194d695 render/vulkan: switch to timeline semaphores
Up until now we were using a VkFence for GPU-to-CPU
synchronization. This has some limitations that become a blocker
when trying to have multiple command buffers in flight at once
(e.g. for multi-output). It's desirable to implement a command
buffer pool [1], but VkFence cannot be used to track command buffer
completion for individual subpasses.

Let's just switch to timeline semaphores [2], which fix this issue,
make synchronization a lot more ergonomic and are a core Vulkan 1.2
feature.

[1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3802
[2]: https://www.khronos.org/blog/vulkan-timeline-semaphores
2022-11-11 19:18:04 +00:00
Simon Ser f92d1499cd render/vulkan: add helper to load command function pointer
If NULL is returned by vkGetDeviceProcAddr(), either the driver
is buggy, either the wlroots code is buggy. For a valid device and
command name, drivers are not allowed to return NULL per the spec.

This mirrors what the GLES2 renderer does in load_gl_proc().
2022-11-11 19:18:04 +00:00
zccrs 270914d379 render/vulkan: add some interfaces to allow compositors to integrate
Added wlr_vk_renderer_get_* functions to allow get the VkInstance,
VkPhysicalDevice, VkDevice, queue family of a wlr_vk_renderer.

Added wlr_vk_renderer_get_current_image_attribs function to allow get
the VkImage of current renderer buffer to use on compositors.

Added wlr_renderer_is_vk function, it's like the wlr_renderer_is_gles2,
returns true if the wlr_renderer is a wlr_vk_renderer.

Added wlr_vk_image_get_attribs function to get a VkImage and it's
extras information (e.g. a VkImageLayout and VkImageFormat of the
VkImage) from a wlr_texture.
2022-11-08 12:56:38 +01:00
Simon Ser 6c31f3b078 render/vulkan: use wl_array for wlr_vk_shared_buffer.allocs
Avoids the need to open-code the realloc() logic.
2022-11-07 21:22:33 +00:00
Simon Ser 9a5cc36818 render/vulkan: simplify texture VkPipelineShaderStageCreateInfo
I simplified the quad VkPipelineShaderStageCreateInfo in [1], but
missed the one for texture.

[1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3823
2022-11-07 14:24:39 +01:00
Simon Ser cfb768aab9 render/vulkan: use struct initializers
Instead of filling the fields one by one, use a struct initializer.
This avoids repeating the name of the variable and is more
consistent with the wlroots code style.
2022-11-06 14:20:34 +00:00