Commit Graph

161 Commits

Author SHA1 Message Date
Matthias Clasen
6059eaf355 gdk: Reorganize dmabuf initialization
Change the xxx_get_downloader() functions to init_dmabuf_xxx(),
and make them initialize both xxx_dmabuf_formats and xxx_downloader.
2024-09-17 09:46:01 +02:00
Matthias Clasen
bdee95c32c Merge branch 'wip/otte/for-main' into 'main'
gpu: Don't crash when there's no ops

Closes #6992

See merge request GNOME/gtk!7710
2024-09-12 00:27:29 +00:00
Benjamin Otte
1ff9d1545d Revert "vulkan: Set VK_SWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXT"
This reverts commit ffae0010c4.

The commit doesn't work with the nvidia driver and it's not necessary to
use it, so drop it for now.

Fixes #6992
2024-09-11 08:17:43 +02:00
Emmanuel Gil Peyrot
6dd55e381d vulkan: Fix error string
This one got added in 66ba1f76ba but didn’t end
the sentence with a dot, and didn’t have its enum name between parentheses so
that people can debug more easily which error code got generated.
2024-09-10 22:46:29 +00:00
Emmanuel Gil Peyrot
abd8d40bf9 vulkan: Add another two error codes
Those two come from the VK_KHR_pipeline_binary extension and have been added in
Vulkan 1.3.294.
2024-09-10 22:45:41 +00:00
Matthias Clasen
75fa51ef6d Cosmetics
Fix a typo
2024-09-08 19:35:53 -04:00
Benjamin Otte
ffae0010c4 vulkan: Set VK_SWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXT
It seems Mesa doesn't support that yet, but having it doesn't hurt.

And it allows drivers to allocate less memory for the swapchains,
because we don't need all the 4 images we request in minImageCount.
But drivers tend to take that minimum image count as gospel, so we need
to use a higher number to not cause lag in corner cases.
2024-09-08 16:22:49 +02:00
Benjamin Otte
6c72a223f5 vulkan: Enable VK_EXT_swapchain_maintenance1 if available
This just adds the plumbing, usage will happen later.

For testing, GDK_VULKAN_DISABLE=swapchain-maintenance will turn it off.
2024-09-08 16:22:49 +02:00
Benjamin Otte
5a027594c3 vulkan: Add gdk_vulkan_context_has_feature()
A siimplification that will come in handy in the future.
2024-09-08 16:22:49 +02:00
Benjamin Otte
d8926de40e vulkan: Don't print errors on vkCreateInstance() failure
We handle the error case right below with a proper GError, there's no
need to use the fallback error reporting.

Fixes #6947
2024-08-23 20:04:46 +02:00
Matthias Clasen
26a2966a7b gdk: Beef up gdk_parse_debug_var
Add a docstring for the variable itself, and print it as part
of the help message. Update all callers to provide a docstring.
2024-08-19 20:40:32 -04:00
Matthias Clasen
cde094a0df Add a GDK_DISABLE env var
This is taking over the feature-disabling keys from GDK_DEBUG.
2024-08-19 20:40:32 -04:00
Benjamin Otte
4e77667ab8 vulkan: Round damage rectangles properly
We need to round outwards and a 1x1 rectangle with offset 0.5,0.5 should
end up as a 3x3 rectangle with offset 0,0 when rounded, not as a 2x2
rectangle.
2024-08-13 00:36:11 +02:00
Benjamin Otte
0a92f741b3 vulkan: Remove 2 unneeded return_if_fail() checks
I want to deprecate that function, so getting rid of calls to it sounds
like a good idea.
2024-08-10 01:40:45 +02:00
Simon McVittie
15a09c79f9 Fix debug format strings for non-LP64 platforms
Unfortunately the format string for a size_t, `%zu`, is not portable
to all Windows compilers, and the appropriate format string for the
fundamental type that implements size_t varies between platforms
(typically `%u` on 32-bit platforms, `%lu` on 64-bit Linux or
`%llu` on 64-bit Windows).

In gtk-demo, cast the number of search results to long, to avoid
breaking up a translatable string.

Elsewhere, use GLib's abstraction for this.

Signed-off-by: Simon McVittie <smcv@debian.org>
2024-07-27 18:14:31 +01:00
Simon McVittie
e2a7dc5427 vulkan: Fix compiler warnings on 32-bit
Vulkan handles are pointers on 64-bit, but 64-bit integers on 32-bit.

Signed-off-by: Simon McVittie <smcv@debian.org>
2024-07-27 15:14:57 +01:00
Jordan Petridis
cc5526e019
gdkvulkancontext: set the VkSemaphore to VK_NULL_HANDLE
Vulkan objects are integers on 32bit and it's failing when it's set to
just NULL.

```
../gdk/gdkvulkancontext.c:677:24: error: assignment to ‘VkSemaphore’ {aka ‘long long unsigned int’} from ‘void *’ makes integer from pointer without a cast [-Wint-conversion]
  677 |   priv->draw_semaphore = NULL;
```
2024-07-23 18:01:56 +02:00
Benjamin Otte
14a7b4b4b4 vulkan: Remove unused features
Now that we don't use the fancy features anymore, we don't need to
enable them.
And that also means we don't need an env var to disable it for testing.
2024-07-22 19:40:24 +02:00
Benjamin Otte
496211727d vulkan: dmabufs require ycbcr
So make sure that GDK_VULKAN_DISABLE=ycbcr also disables dmabufs.
2024-07-22 01:28:39 +02:00
Benjamin Otte
4966f8cdf8 vulkan: Add an acquire semaphore to frames
Vulkan requires us waiting on the image acquired from
vkAcquireNextImageKHR() before we start rendering to it, as that
function is allowed to return images that are still in use by the
compositor.
Because of that requirement, vkAcquireNextImageKHR() requires a
semaphore or fence to be passed that it can signal once it's done.

We now use a side channel to begin_frame() - calling
set_draw_semaphore() - to pass that semaphore so that the
vkAcquireNextImageKHR() call inside begin_frame() can use it, and then
we can wait on it later when we submit.

And yes, this is insanely convoluted, the Vulkan developers should
totally have thought about GTK's internal designs before coming up
with that idea.
2024-07-17 22:59:23 +02:00
Benjamin Otte
86e735cd5c Merge branch 'wip/otte/for-main' into 'main'
vulkan: Remove draw semaphore

Closes #6861

See merge request GNOME/gtk!7460
2024-07-14 21:11:06 +00:00
Benjamin Otte
b08a17064e vulkan: Remove draw semaphore
That's unused (or wrongly used) leftover code from 2017.

The validation layers also don't like it.
2024-07-14 21:54:40 +02:00
Matthias Clasen
53d99f5521 Use the surface colorstate in begin_frame
begin_frame is the place where we make decisions about the format,
depth and colorstate for our rendering. Make these calls take the
surface color state into account.

In particular, if the surface colorstate is suitable for GL_SRGB,
and we don't need high depth, set things up for that.
2024-07-14 12:51:05 -04:00
Benjamin Otte
a61d7f3864 vulkan: Remove GDK_DEBUG=vulkan-validate
The modern incantation to get validation layers enabled is via

VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation

Vulkan has a bunch of environment variables to toggle stuff, let's use
those instead of doing our own.
2024-07-13 08:52:28 -04:00
Benjamin Otte
527f305690 vulkan: Compare different depths by their Vulkan format
GdkMemoryFormats can be identical for different Vulkan formats, in
particular in the srgb vs non-srgb case.
2024-07-11 14:57:20 +02:00
Benjamin Otte
b05c9c26bd vulkan: Add support for SRGB formats 2024-07-11 14:57:20 +02:00
Benjamin Otte
1b1e7f4296 drawcontext: Make begin_frame() set colorstate + depth
Make begin_frame() set a rendering colorstate and depth, and provide it
to the renderers via gdk_draw_context_get_depth() and
gdk_draw_context_get_color_state().

This allows the draw contexts to define their own values, so that ie the
Cairo and GL renderer can choose different settings for rendering (in
particular, GL can choose GL_SRGB and do the srgb conversion; while
Cairo relies on the renderer).
2024-07-11 14:57:20 +02:00
Benjamin Otte
1bbf5f7a17 gdk: Add GDK_MEMORY_NONE depth
That's basically the "undefined" value. We need that when drawing
nothing, which so far only happens with empty container nodes.

But empty container nodes can be children of other nodes, and that makes
things propagate. So instead of catching them, force the whole rest of
the code to deal with an undefined depth.

We also can't just set a random depth, because that will cause merging
to fail.
2024-07-11 14:57:20 +02:00
Benjamin Otte
33d87bc22e gdk: Add GDK_N_DEPTHS to the enum
We are indexing arrays by the number of depths, and when adding depths
we don't want to forget to grow those arrays.
2024-07-01 20:07:22 +02:00
Benjamin Otte
16692f9f5e vulkan: Remove unused function 2024-06-29 07:14:03 -04:00
Benjamin Otte
4f453ab521 vulkan: Rename variable
It's not a format.
2024-06-29 07:13:54 -04:00
Matthias Clasen
d141cb7b72 Fix an oversight
This snuck in as part of 098d67f8befdb00d75.
2024-06-11 16:41:22 -04:00
Matthias Clasen
42c6e0249f vulkan: Fix updating swap chains
gdk_vulkan_context_check_swapchain uses priv->current_format,
so we must update it first, and undo that if check_swapchain
falls. This fixes handling of high-depth back buffers in gsk.
2024-06-09 15:59:56 -04:00
Matthias Clasen
54eb85f814 vulkan: Add a getter for the memory format
We need this to accurately set up the gpu image for the
backbuffer in gsk.
2024-06-09 15:59:56 -04:00
Maximiliano Sandoval
ee4a817121
gdk: docs: Document error quarks 2024-05-31 11:47:30 +02:00
Chun-wei Fan
5935bc95b7 gdkvulkancontext.c: Use pointers to hash VkShaderModule
VkShaderModule's may or may not be pointers depending on the target
platform, so use pointers to hash those handles to be safe, and retrieve
them from hashes accordingly.

Fixes build on 32-bit Windows at least.
2024-05-29 18:03:13 +08:00
Benjamin Otte
b3c6a98132 vulkan: Add a missing extension
We need to enable this one, too.

Thanks validation layers!
2024-05-16 02:24:17 +02:00
Doğukan Korkmaztürk
7c3de4a2da vulkan: Recreate swapchain when it is necessary or beneficial
Currently, GTK does not check the result of vkAcquireNextImageKHR() and
assumes that it always succeeds. As a result, the vkQueuePresentKHR() is
unconditionally set to wait for the semaphore passed to
vkAcquireNextImageKHR() earlier.

However, if vkAcquireNextImageKHR() fails for some reason, the semaphore
passed to it does not get signalled. This causes the presentation
command to wait for the semaphore to be signalled indefinitely, which
causes GTK to hang.

This change adds error handling around vkAcquireNextImageKHR() to make
GTK recreate the Vulkan swapchain when it is necessary or beneficial and
helps avoiding situations that could cause indefinite waits.
2024-05-04 22:14:33 -04:00
Matthias Clasen
1bbca0cd25 vulkan: Don't forget to update the cache size
In order for the size change check to make sense, vk_pipeline_cache_size
needs to correspond to the size of the cache we last wrote to disk.

We were forgetting to update it after saving the cache, so the
check was ineffective.
2024-04-30 08:28:39 -04:00
Matthias Clasen
83784c17a3 vulkan: Improve logging around caches
Add some more logging around the pipeline cache.
2024-04-30 08:28:39 -04:00
Matthias Clasen
119a07e055 vulkan: Add a profiler mark for pipeline cache save
This is a rare event, and the file isn't small, so show it in profiles.
2024-04-30 07:36:42 -04:00
Matthias Clasen
6022fbcdf8 vulkan: Add profiling to Vulkan initialization
This helps understanding where our startup time is spent.
2024-04-29 18:28:03 -04:00
Matthias Clasen
74a1c0916a Add a missing deprecation note
GdkVulkanContext is deprecated and only exposed in the api because
we need it as return type of the (deprecated)
gdk_surface_create_vulkan_context() API.
2024-04-18 12:49:18 -04:00
Benjamin Otte
afd5ea53d8 vulkan: Rename env var from GDK_VULKAN_SKIP to GDK_VULKAN_DISABLE
It's a better name.
2024-03-16 14:03:36 +01:00
Benjamin Otte
802110bfe5 vulkan: Change function prototype
The function cannot return an error, so don't make that possible.
2024-03-16 13:44:02 +01:00
Matthias Clasen
b1ccb4103d Grr, vulkan
The can always make it worse with another define.
2024-03-02 21:47:49 -05:00
Matthias Clasen
66ba1f76ba vulkan: Add another error code
Handle VK_ERROR_INVALID_VIDEO_STD_PARAMETERS_KHR.
2024-03-02 20:20:16 -05:00
Benjamin Otte
f2ec3e336f vulkan: Vulkan requires listing of all dependencies
So we list them.
Vulkan can be soooooo stupid.

Shuts up the validation layer.
2024-02-09 04:28:32 +01:00
Matthias Clasen
59578c6d18 Fix typos throughout
These were pointed out by codespell.
2024-01-07 20:44:05 -05:00
Benjamin Otte
7830535c04 vulkan: Guard dmabuf code with HAVE_DMABUF 2024-01-07 15:07:15 +01:00