Commit Graph

709 Commits

Author SHA1 Message Date
Simon Ser 09f5a00585 render/vulkan: fix YCbCr format check in vulkan_texture_from_pixels() 2023-05-23 20:31:42 +02:00
Simon Ser d7bebb0a4c render/vulkan: drop unnecessary comments
Some comments in here are noise.
2023-05-22 18:53:15 +02:00
Simon Ser 17b10746b4 render/pixel-format: add YVYU and VYUY 2023-05-21 20:28:45 +00:00
Simon Ser 96f3f3c92e render/pixel-format: add support for block-based formats
Some formats like sub-sampled YCbCr use a block of bytes to
store the color values for more than one pixel. Update our format
table to be able to handle such formats.
2023-05-21 20:28:45 +00:00
Tobias Predel e449c1dec8 wlr_drm_format_set_copy: Do not allocate heap
Address Sanitizer reported two memory leaks because of
fmt not being freed in wlr_drm_format_set_copy.

This commit fixes the memory leak by removing the
allocation to the heap. The struct is allocated to the
stack anyway.
2023-05-14 17:50:08 +02:00
Manuel Stoeckl 10dd416694 render/vulkan: allow rendering to non-8-bit buffers
This is implemented by a two-subpass rendering scheme; the first
subpass draws (and blends) onto a linear R16G16B16A16_SFLOAT buffer,
while the second subpass performs linear->srgb conversion, writing
onto the actual output buffer.
2023-05-12 15:09:02 +00:00
Simon Ser 8cdc4b7a31 render/vulkan: wait for idle queue before destroying render buffer
This fixes the following validation errors when shutting down Sway:

    00:00:01.263 [wlr] [render/vulkan/vulkan.c:65] Validation Error: [ VUID-vkDestroyFramebuffer-framebuffer-00892 ] Object 0: handle = 0x62e00003c400, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xdb308312 | Cannot call vkDestroyFramebuffer on VkFramebuffer 0x2e2cd000000002b[] that is currently in use by a command buffer. The Vulkan spec states: All submitted commands that refer to framebuffer must have completed execution (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkDestroyFramebuffer-framebuffer-00892) (VUID-vkDestroyFramebuffer-framebuffer-00892)
    00:00:01.264 [wlr] [render/vulkan/vulkan.c:65] Validation Error: [ VUID-vkDestroyImage-image-01000 ] Object 0: handle = 0x62e00003c400, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xf2d29b5a | Cannot call vkDestroyImage on VkImage 0x3fbcd60000000028[] that is currently in use by a command buffer. The Vulkan spec states: All submitted commands that refer to image, either directly or via a VkImageView, must have completed execution (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkDestroyImage-image-01000) (VUID-vkDestroyImage-image-01000)
2023-05-12 16:13:24 +02:00
Alexander Orzechowski 47e175ae7f wlr_drm_format_set_intersect: Clear destination before trying to write to it 2023-05-11 14:43:22 -04:00
Alexander Orzechowski 300bd80772 wlr_drm_format_set: Store formats on array 2023-05-11 18:25:52 +02:00
Alexander Orzechowski 90d08f8f1c wlr_drm_format: Rework wlr_drm_format_intersect
Now it takes a reference to a destination format
2023-05-11 18:24:43 +02:00
Alexander Orzechowski 340700cb70 wlr_drm_format: Change wlr_drm_format_dup to copy 2023-05-11 18:24:43 +02:00
Alexander Orzechowski 099a147439 wlr_drm_format: Change wlr_drm_format_create to init 2023-05-11 18:24:40 +02:00
Alexander Orzechowski e427e019c4 wlr_drm_format: Don't take double pointer in wlr_drm_format_add 2023-05-11 03:51:01 -04:00
Alexander Orzechowski e6879616e7 wlr_drm_format: Make structure constant length
Don't store modifiers as part of the struct.
2023-05-11 03:51:01 -04:00
Alexander Orzechowski b45396c790 wlr_drm_format: Introduce drm_format_finish 2023-05-11 03:51:01 -04:00
Simon Ser e353c5c631 render/vulkan: enable NV12 on big-endian
This format doesn't change its layout on big endian because it's
not packed and has 8-bit channels.
2023-05-11 07:25:32 +00:00
Simon Ser 095a63a11c render/vulkan: improve logging when creating texture
Remove debug logs when a texture is created, since this happens
pretty often. Use drmGetFormatName() and drmGetFormatModifierName()
to log DRM formats and modifiers.
2023-05-09 12:39:20 +02:00
Manuel Stoeckl e6fc5d1e49 render/vulkan: increase next descriptor pool size
This ensures that the pool sizes grow exponentially, making the number
of pools needed logarithmic in the number of descriptors, instead of
linear. Since the first pool's size is 256, this change only has an
effect when the compositor creates a large number of textures.
2023-05-06 18:16:45 +00:00
Simon Ser b03f71fe5f render/vulkan: add support for NV12 2023-05-04 20:07:20 +00:00
Alexander Orzechowski 5adb1be3a7 drm_format_set_intersect: Require initialized dst and remove assert
The usages in linux_dmabuf zero out the dst before passing it so this
change should be fine.
2023-05-04 18:19:33 +00:00
Alexander Orzechowski 1ee75786b4 drm_format_set_union: Require initialized dst and remove assert 2023-05-04 18:19:33 +00:00
Simon Ser 403eac51c4 render/vulkan: fix code style for function brackets 2023-05-04 13:31:29 +02:00
Austin Shafer ec37d55a5e Add union function for format sets 2023-05-03 12:06:48 -04:00
Simon Ser a93fc8afd6 render: introduce blend mode
Allow callers to pick the blend mode when rendering a rect. The
"none" mode can be used to disable blending and clear rects.
2023-05-02 21:32:51 +02:00
Simon Ser 6b7d1d732a render/pixman: fix scaling in render_pass_add_texture()
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3642
Fixes: 6830bfc17f ("render/pixman: implement render pass API")
2023-05-02 15:49:17 +00:00
Simon Ser f5a5712a02 render/vulkan: use VK_KHR_synchronization2
This simplifies the vkQueueSubmit call, removing the need to pass
timeline semaphore point values as separate arrays.
2023-04-28 15:36:39 +00:00
Simon Ser 6830bfc17f render/pixman: implement render pass API 2023-04-25 17:26:35 +02:00
Simon Ser 6ce371a317 render/pixman: add begin_pixman_data_ptr_access()
This logic is used twice.
2023-04-25 17:26:35 +02:00
Simon Ser 471249ae4f render/pass: add legacy render pass implementation
Add a render pass implementation which leverages the legacy
rendering API. This is helpful during the migration.
2023-04-25 17:25:10 +02:00
Simon Ser 4a1ad32534 render: add render pass helpers 2023-04-25 17:25:10 +02:00
Simon Ser 756dedae20 Add a new renderer API
Goals:

- Extensibility: we need to be able to add new params to the calls
  to render a texture/rect. For instance we'll need to add fences to
  the render texture operation for explicit sync purposes.
- No implicit state: no more bind_buffer, begin, end.
- No matrices: these hurt Pixman and we don't need them.
- Clip regions for optimized damage repainting.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3188
2023-04-25 17:25:10 +02:00
Simon Ser d795824346 render/vulkan: fix signedness of strcmp() return value
strcmp() returns a signed integer.
2023-04-19 15:29:53 +02:00
Simon Ser 62e60ba889 render/vulkan: use initializer in vulkan_change_layout_queue() 2023-04-19 15:29:26 +02:00
Simon Ser 74e8fd8a9a render/vulkan: remove extra newline 2023-04-19 15:29:11 +02:00
Simon Ser 92b726ef67 render/vulkan: use full names for extension command fields
This makes grepping much easier.
2023-04-18 15:58:55 +00:00
Manuel Stoeckl 40dde59475 render/gles2: use byte-aligned rows for glReadPixels
Setting the GLESv2 parameter GL_PACK_ALIGNMENT to 1 ensures that the
stride of the glReadPixels output matches the value computed in
`pack_stride`. Since the default value of GL_PACK_ALIGNMENT is 4, this
does not make a difference under normal use; but without this patch
the stride can be incorrect; for example, with RGB565 buffers and
screenshots of regions with odd width.
2023-04-12 14:04:25 +00:00
Simon Ser 59d2743c0c render/vulkan: avoid double-close on sync_file FD after semaphore import
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3610
2023-03-26 07:19:01 +00:00
Brett Ernst 7d9938c957 drm_format_set: fix realloc size 2023-03-16 18:13:11 -07:00
Simon Ser 40117e1e0d render/vulkan: prefer render node for wlr_renderer_get_drm_fd()
Instead of returning a primary node from wlr_renderer_get_drm_fd(),
prefer to return a render node if any.
2023-02-28 14:25:21 +00:00
Jan Beich 59acc69737 vulkan: silence -Wint-conversion on 32-bit architectures
render/vulkan/renderer.c:388:70: error: incompatible pointer to integer conversion passing 'void *' to parameter of type 'VkFence' (aka 'unsigned long long') [-Werror,-Wint-conversion]
        VkResult res = vkQueueSubmit(renderer->dev->queue, 1, &submit_info, NULL);
                                                                            ^~~~
render/vulkan/renderer.c:1141:81: error: incompatible pointer to integer conversion passing 'void *' to parameter of type 'VkFence' (aka 'unsigned long long') [-Werror,-Wint-conversion]
        VkResult res = vkQueueSubmit(renderer->dev->queue, submit_count, submit_infos, NULL);
                                                                                       ^~~~
/usr/include/sys/_null.h:34:14: note: expanded from macro 'NULL'
 #define NULL    ((void *)0)
                 ^~~~~~~~~~~
/usr/local/include/vulkan/vulkan_core.h:4054:49: note: passing argument to parameter 'fence' here
    VkFence                                     fence);
                                                ^

Fixes: a8a194d695 ("render/vulkan: switch to timeline semaphores")
2023-02-24 16:41:40 +00:00
Simon Ser 8619ffab21 swapchain: remove allocator listener on destroy
Past that point the wlr_allocator is gone and the listeners are
invalidated.
2023-02-24 00:07:41 +01:00
Simon Ser b33ab26fe7 render/swapchain: make public
We've had this struct for a while. It'd be useful for compositors
if they want to manage the swap chains themselves instead of being
forced to use wlr_output's. Some compositors might also want to use
a swapchain without an output.
2023-02-21 17:14:31 +01:00
Simon Zeni 782b5e6565 Revert "render/egl: skip incompatible EGL devices"
Reverts commit c73e20628a.

This caused a regression in the GLES2 renderer because `egl->exts.EXT_device_drm` is set in
`egl_init_display()`, which is invoked after `get_egl_device_from_drm_fd()`. So the function will
always return `EGL_NO_DEVICE_EXT`.
2023-02-18 11:49:51 -05:00
Eric Engestrom c73e20628a render/egl: skip incompatible EGL devices
Without EGL_EXT_device_drm, eglQueryDeviceStringEXT(EGL_DRM_DEVICE_FILE_EXT) further below is invalid.
2023-02-16 19:43:06 +00:00
Simon Ser 677a3f2f88 render/gles2: default to highp if available
The spec [1] says that the maximum value for a mediump float
is at least 2¹⁴ in section 4.5.2. However, when using a 4k
resolution texture coordinates will exceed this value. This causes
issues on drivers which implement mediump as a 16-bit [2].

Switch to highp. There's a twist: on GLES2, support for highp is
optional. So we need to guard it with cute GL_FRAGMENT_PRECISION_HIGH
ifdefs.

[1]: https://registry.khronos.org/OpenGL/specs/es/2.0/GLSL_ES_Specification_1.00.pdf
[2]: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21082
2023-02-02 22:54:13 +01:00
Simon Ser 0534d12b28 render/gles2: use correct type for shader type
Doesn't matter a lot, but let's try to be consistent with the
GL headers.
2023-02-02 22:42:42 +01:00
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 f12cdc53f3 render/egl: stop advertising render support for external-only formats
Some formats like YUV are only supported by Mesa for sampling, not
for rendering. However we always unconditionally added the INVALID
modifier to the list of render formats.

Check whether all modifiers are external-only, in that case, don't
add INVALID to the list of render formats.
2022-12-13 16:43:22 +00:00
Simon Ser 80074d95fb egl: consistently use EGLint for DMA-BUF format
EGL_EXT_image_dma_buf_import_modifiers [1] uses EGLint to carry
formats. We were casting it to int (which may not be the same
width) and uint32_t (which may change the value).

Instead, use EGLint everywhere.

[1]: https://registry.khronos.org/EGL/extensions/EXT/EGL_EXT_image_dma_buf_import_modifiers.txt
2022-12-12 23:08:48 +01:00
Simon Ser 32fc23a383 render/pixman: skip mask for opaque texture rendering 2022-12-08 16:53:14 +01:00
Simon Ser 86fc2199f8 build: unify naming for HAVE_* defines
We sometimes used HAS_, sometimes polluted the LIBINPUT_ namespace,
etc.
2022-12-06 22:39:45 +00:00
Simon Ser cb6b1193c8 render/allocator/gbm: use internal_config
Removes a project argument.
2022-12-06 22:39:45 +00:00
Simon Ser 1bd0ba3949 render: simplify renderer_autocreate_with_drm_fd()
Use early returns to remove the !renderer checks.
2022-12-06 14:58:30 +00: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 30219cf76b render/dmabuf: add dmabuf_export_sync_file() 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 Zeni 4b3bbb0c4f render/drm_format_set: fill dst in wlr_drm_format_set_copy 2022-12-02 11:47:47 -05: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 c9b378d21a render/drm-format-set: add wlr_drm_format_set_copy() 2022-12-02 14:27:07 +00: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 e31c741d2a render/pixel-format: drop unnecessary fields in the table
DRM_FORMAT_INVALID is zero. Let's just omit the fields to make the
table more readable.
2022-12-02 10:28:52 +01:00
Simon Ser e97ce5f459 render/pixel-format: add various new formats 2022-12-02 10:24:00 +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 c99c60090c linux-dmabuf-v1: add version arg to create()
To be able to add support for newer versions without breaking
changes.
2022-11-30 14:14:04 +01:00
Simon Ser 444d94ef89 linux-dmabuf-v1: add "_with_renderer" suffix to create() function
Make it clear this is a helper consuming a wlr_renderer. We'll
add a lower-level create() function which doesn't take it in the
next commit.
2022-11-30 14:14:02 +01: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 aaf828d3d2 render/dmabuf: add dmabuf_import_sync_file
References: https://lore.kernel.org/dri-devel/20220506180216.2095060-1-jason@jlekstrand.net/
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 fdb24d19ca allocator/drm_dumb: use libdrm dumb buffer helpers
References: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/272
2022-11-17 08:05:55 +00:00
Simon Ser da3616d183 render: use wlr_shm in wlr_renderer_init_wl_shm() 2022-11-15 16:30:00 +00:00
Simon Ser 6e88eeadeb render/pixel_format: import pixel_format_info_check_stride()
We'll use this function from wlr_shm too.

Add some assertions, use int32_t (since the wire protocol uses that,
and we don't want to use 16-bit integers on exotic systems) and
switch the stride check to be overflow-safe.
2022-11-15 16:30:00 +00:00
Simon Ser d6e2ab5145 render/vulkan: detect device loss 2022-11-15 15:50:19 +00:00
Simon Ser 165352e32f render/egl: enable EGL_LOSE_CONTEXT_ON_RESET
This allows the GLES2 renderer to figure out when a GPU reset
happens.
2022-11-15 15:50:19 +00:00
Simon Ser 261d6998fb render/gles2: query glGetGraphicsResetStatusKHR
Call glGetGraphicsResetStatusKHR in wlr_renderer_begin to figure
out when a GPU reset occurs. Destroy the renderer when this
happens (the OpenGL context is defunct).
2022-11-15 15:50:19 +00:00