Commit Graph

203 Commits

Author SHA1 Message Date
Kenny Levinsen
1f13bc72fe render/vulkan: Garbage collect unused buffers
Perform a primitive garbage collection of buffers that have not been
used in the past 10 seconds, an arbitrarily selected number.

As garbage collection also makes span buffer allocation happen much more
often, logging on allocation activity leads to a lot of log noise so get
rid of that while at it.
2024-11-07 09:49:29 +00:00
Simon Ser
3bbfae73ae render/vulkan: add support for explicit sync 2024-10-28 17:51:21 +00:00
Simon Ser
9351c78d70 render/vulkan: add render_pass_destroy()
De-duplicate the cleanup logic.
2024-10-28 17:51:21 +00:00
Simon Ser
7ce868bcf6 render/vulkan: make VK_KHR_external_semaphore_fd optional
We already block instead of using sync_file when the driver
doesn't support import/export.
2024-10-03 19:24:30 +02:00
Simon Ser
3da6fac1f2 render/vulkan: check size when creating shm texture 2024-09-29 15:22:56 +00:00
Simon Ser
d55c175777 render/vulkan: log size when importing too-large DMA-BUF 2024-09-29 15:22:56 +00:00
Alexander Orzechowski
3187479c07 render/color: Invert ownership model of color_transform types.
Color transform can have multiple types and these different types
want to store different metadata. We previously stored this metadata
directly on wlr_color_transform even for transforms that don't use it.

Instead, let's take the prior art from wlr_scene where each scene node
is built on a base node. Notice how wlr_color_transform_lut3d now has
a `struct wlr_color_transform base`. This is advantageous in multiple
ways:

1. We don't allocate memory for metadata that will never be used.
2. This is more type safe: Compositors can pass around a
struct wlr_color_transform_lut3d if they know they only want to use a
3d_lut.
3. This is more scalable. As we add more transform types, we don't have
to keep growing a monolithic struct.
2024-08-24 14:33:22 -04:00
Simon Ser
fa2abbeefb render/color: return tranform in wlr_color_transform_ref()
This is more consistent with the rest of the wlroots APIs and is
more concise.
2024-08-24 11:07:58 +02:00
Simon Ser
52dce29e06 render/vulkan: use non-coherent memory for read_pixels()
The spec for VkMemoryPropertyFlagBits says:

> device coherent accesses may be slower than equivalent accesses
> without device coherence [...] it is generally inadvisable to
> use device coherent or device uncached memory except when really
> needed

We don't really need coherent memory so let's not require it and
invalidate the memory range after mapping instead.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3868
2024-08-22 18:19:22 +02:00
chenyongxing
015bb8512e render/vulkan: Fix draw rect clip region invalid in blend none mod 2024-07-16 14:24:46 +08:00
Kenny Levinsen
bf67eb342b render/vulkan: vkMapMemory stage spans up front
We always need these mapped for CPU access, so map it up front instead
of duplicating lazy mapping at each site of use.
2024-06-26 21:10:46 +00:00
Kenny Levinsen
bf0246e50c render/vulkan: Fix 3dlut stage span map offset
The mapping is shared between all users of the stage span, so it should
always map the whole thing and apply the allocation offset to the mapped
pointer.
2024-06-26 21:10:46 +00:00
Kenny Levinsen
6da71b6a89 render/vulkan: Unref color transform on pass submit
We increment the ref counter of the color transform at the start of the
render pass. Decrement it at the end to not leak the color transform.
2024-06-26 22:43:15 +02:00
Kenny Levinsen
bc82835756 render/vulkan: Use new span map handling for 3dlut
The use of stage spans for 3dluts was missed when the new cached
mappings were introduced, meaning that it would try to map and unmap
memory that might already have a cached mapping.

Vulkan does not support mapping memory multiple times, so make sure the
3dlut code also uses the cached mapping to avoid segfaults after unmap.
2024-06-26 13:14:07 +02:00
Kenny Levinsen
53464074e9 render/vulkan: Unmap span before freeing memory 2024-06-26 13:13:40 +02:00
Kenny Levinsen
47c578945c render/vulkan: Recycle memory maps for stage spans
Remapping buffers on every use causes a lot of unwanted pagefaults.
Reuse the mapping to significantly speed up the memcpy.
2024-06-24 15:55:10 +00:00
Simon Ser
2c4d3ad12d render/vulkan: don't use UNDEFINED layout for imported DMA-BUFs
UNDEFINED when used as source layout means that the contents of
the underlying memory becomes undefined. This isn't what we want
here: we don't want to mutate the imported pixel data.

The Vulkan spec isn't really clear what the proper value should be
here, but after discussing with driver developers [1] it seems like
UNDEFINED isn't the right one. The recommendation is to use GENERAL
instead.

[1]: https://github.com/ValveSoftware/gamescope/issues/356
2024-05-14 13:14:28 +02:00
Kirill Primak
f0b7fb72a8 render/vulkan: don't free a descriptor set from an already destroyed lut3d dummy pool 2024-05-09 19:07:54 +03:00
Kirill Primak
073c3e8837 render/vulkan: free render format setups on destroy 2024-05-09 18:47:02 +03:00
Kirill Primak
e20ae113f8 render/vulkan: free pipeline layouts on destroy 2024-05-09 18:46:55 +03:00
Kirill Primak
00bc75439f render/vulkan: fix texture clip region leak 2024-05-09 18:40:31 +03:00
Manuel Stoeckl
82b4bc3f5f renderer: add field to indicate color transform support 2024-04-26 17:17:36 +00:00
Manuel Stoeckl
ffdbfdbbbd render/vulkan: add support for output color transforms 2024-04-26 17:17:36 +00:00
Manuel Stoeckl
e443434876 render/vulkan: create plain framebuffers on demand
This change makes it possible to support both the direct srgb-format
pipeline and indirect (color-managed, or non-srgb-format) pipeline
for the same render buffer.
2024-04-26 17:17:36 +00:00
Manuel Stoeckl
adbfd3c321 render/vulkan: add lut3d output shader option
While a corresponding pipeline is created, it is not yet used.
2024-04-26 17:17:36 +00:00
Manuel Stoeckl
c64144a39b render/vulkan: add dummy 3d lookup table to output shader
Later commits will add shader options that use a real 3d
lookup table.
2024-04-26 17:17:36 +00:00
Simon Ser
ebef710746 renderer: replace get_render_buffer_caps() with struct field 2024-04-22 11:38:30 +02:00
Simon Ser
85c1eda721 render: unify getter for texture formats
Instead of having separate getters for shm formats and DMA-BUF
formats, use the same pattern as wlr_output_impl.get_primary_formats
with a single function which takes buffer caps as input.
2024-04-21 11:27:29 +00:00
John Lindgren
b1b34cd665 vulkan: perform sRGB-to-linear conversion correctly for premultiplied values
Pre-multipled sRGB values need to be un-multiplied before conversion
to linear and then re-multiplied after. Compare shaders/texture.frag.

This fixes an issue in labwc where titlebar corners (rendered as
ARGB textures) did not match the rest of the titlebar (rendered as
a solid wlr_scene_rect).

Note: 0.17 has other instances in render/vulkan/renderer.c that need
the same fix.
2024-04-11 09:24:03 +00:00
Biswapriyo Nath
dd2061b073 render/vulkan: Fix clang compiler error in 32 bit ARM Android
This adds proper calling convention attribute for callbacks used in vulkan
and fixes the following compiler error.

../src/render/vulkan/vulkan.c:175:22: error: incompatible function pointer types
initializing 'PFN_vkDebugUtilsMessengerCallbackEXT' (aka 'unsigned int (*)
(enum VkDebugUtilsMessageSeverityFlagBitsEXT, unsigned int, const struct
VkDebugUtilsMessengerCallbackDataEXT *, void *) __attribute__((pcs("aapcs-vfp")))')
with an expression of type 'VkBool32 (*)(VkDebugUtilsMessageSeverityFlagBitsEXT,
VkDebugUtilsMessageTypeFlagsEXT, const VkDebugUtilsMessengerCallbackDataEXT *, void *)'
(aka 'unsigned int (*)(enum VkDebugUtilsMessageSeverityFlagBitsEXT, unsigned int,
const struct VkDebugUtilsMessengerCallbackDataEXT *, void *)')
[-Wincompatible-function-pointer-types]
    .pfnUserCallback = &debug_callback,
                       ^~~~~~~~~~~~~~~
2024-04-10 14:03:38 +00:00
Kenny Levinsen
4d68d3759b render/vulkan: Avoid double-free on calloc error
In query_modifier_support, the calloc for either or both of render_mods
and texture_mods may fail, in which case both are freed for convenience.
However, if one is non-NULL, vulkan_format_props_finish will try to free
it again.

NULL them to avoid double-free.
2024-02-22 23:07:58 +01:00
Simon Ser
842093bb84 Define _POSIX_C_SOURCE globally
Stop trying to maintain a per-file _POSIX_C_SOURCE. Instead,
require POSIX.1-2008 globally. A lot of core source files depend
on that already.

Some care must be taken on a few select files where we need a bit
more than POSIX. Some files need XSI extensions (_XOPEN_SOURCE) and
some files need BSD extensions (_DEFAULT_SOURCE). In both cases,
these feature test macros imply _POSIX_C_SOURCE. Make sure to not
define both these macros and _POSIX_C_SOURCE explicitly to avoid
POSIX requirement conflicts (e.g. _POSIX_C_SOURCE says POSIX.1-2001
but _XOPEN_SOURCE says POSIX.1-2008).

Additionally, there is one special case in render/vulkan/vulkan.c.
That file needs major()/minor(), and these are system-specific.
On FreeBSD, _POSIX_C_SOURCE hides system-specific symbols so we need
to make sure it's not defined for this file. On Linux, we can
explicitly include <sys/sysmacros.h> and ensure that apart from
symbols defined there the file only uses POSIX toys.
2024-02-15 15:41:12 +01:00
Leo Li
71fb55f3bf render/pixel-format: Move has_alpha into it's own array
Some opaque pixel formats (nv12, p010) require per-plane bytes_per_block
info. However, it doesn't make sense to store them in
wlr_pixel_format_info, as they will never be useful (currently, this
info is used for shm, which doesn't have a concept of multi-planar
buffers.)

Let's define a separate array and function for determining whether a
pixel format has alpha.
2024-01-31 13:47:17 -05:00
Félix Poisot
5ae8ce807a render/vulkan: correct sRBG gamma expansion in shader 2024-01-26 13:50:55 +00:00
Kirill Primak
3eb89e5325 render/vulkan: fix possible double free 2024-01-17 15:44:37 +00:00
Simon Ser
a0b1329ee6 Fix bool return types
This makes wlroots build in C23 mode.

C23 is more strict and rejects implicit conversions from bool to a
pointer.
2024-01-04 22:24:06 +01:00
Manuel Stoeckl
d6859da3b4 render/vulkan: use _SRGB image view when possible
This is the last of a set of commits which ensures that both textures
and render buffers can be accessed through _UNORM and _SRGB image
views. While _UNORM image views are not yet used for 8-bpc image
formats, they will be needed in the future to support color transforms
for both textures and render buffers.
2023-12-04 15:13:31 +00:00
Manuel Stoeckl
566c413d8f render/vulkan: constify vulkan_format_props_find_modifier 2023-12-04 15:13:31 +00:00
Manuel Stoeckl
88a4b9eefd render/vulkan: create VkImage with option for _SRGB view, if possible 2023-12-04 15:13:31 +00:00
Manuel Stoeckl
fd4548bb93 render/vulkan: detect which _UNORM formats support _SRGB views 2023-12-04 15:13:31 +00:00
Manuel Stoeckl
acc70ee3a5 render/vulkan: extract shm texture format query into function 2023-12-04 15:13:31 +00:00
Manuel Stoeckl
eab89d6c76 render/vulkan: track and use _UNORM variants of _SRGB formats
Later commits will start using _SRGB image views again,
where appropriate.
2023-12-04 15:13:31 +00:00
Alexander Orzechowski
d3a339a03e renderer: Drop buffer binding 2023-11-30 20:11:50 -05:00
Alexander Orzechowski
3ed1268f64 render: Nuke old read pixels API
Sadly, the new API is not backwards compatible with the old API. Since
we have already switched all users in wlroots to the new API compositors
are already practically mandated to implement the new API. Let's get rid
of the old one since there is no point.
2023-11-30 20:01:12 -05:00
Alexander Orzechowski
c5a3c5ca4c render: Implement texture_preferred_read_format 2023-11-30 20:01:12 -05:00
Alexander Orzechowski
09f16b2a9c render/vulkan: Implement texture_read_pixels 2023-11-30 19:56:54 -05:00
Simon Ser
9a0a4ce221 render/vulkan: drop current_command_buffer
This was used by the legacy rendering API. Since begin()/end()
only need to set current_render_buffer and nothing else, we can
drop all of these bits.
2023-11-28 12:56:30 +00:00
Simon Ser
b2aac3390d render/vulkan: drop legacy rendering API 2023-11-22 11:36:17 +01:00
Manuel Stoeckl
dbe7fb7027 render/vulkan: undo alpha premult for 8-bpc ARGB/ABGR
When a texel from the Vulkan format VK_FORMAT_B8G8R8A8_SRGB is read,
the sRGB to linear conversion is applied independently to the R, G,
and B channels; the A channel has no influence on this. However,
DRM_FORMAT_ARGB8888 buffers are, per Wayland protocol, not encoded
in this fashion; one must first unpremultiply the color channels
before doing sRGB to linear conversion. This commit switches to
handling ARGB8888 and ABGR8888 formats using the general fragment
shader conversion from electrical to optical values.
2023-11-21 11:08:55 +00:00
eri
3232697252 render/vulkan: use VK_KHR_global_priority
References: #3386
2023-10-26 16:17:57 +00:00