Commit Graph

110 Commits

Author SHA1 Message Date
Benjamin Otte
93d681ae77 vulkan: Add a Vulkan downloader
This is using the Vulkan renderer.

It also allows claiming support for all the formats that only Vulkan
supports, but that neither GL nor native mmap can handle.
2024-01-07 07:22:52 +01:00
Benjamin Otte
62d917eb08 vulkan: Use vulkan feature flags for incremental present
I did it because it unifies the code.

But it also gains the benefit of being debuggable because it can
now be turned off via GDK_VULKAN_SKIP=incremental-present
2024-01-07 07:22:52 +01:00
Benjamin Otte
d4c4e4bbc5 gpu: sync dmabufs via semaphores
This ensures both that we signal a semaphore for a dmabuf when we export
an image and that we import semaphores for dmabufs and wait on them.

Fixes Vulkan node-editor displaying the Vulkan renderer in the sidebar.
2024-01-07 07:22:52 +01:00
Benjamin Otte
38c0e2bdf6 gpu: Update the pipeline cache
When a new shader was compiled, queue a save of the pipeline cache.
2024-01-07 07:22:52 +01:00
Benjamin Otte
96e579501f gpu: Add GDK_VULKAN_SKIP env var
The variable forces skipping of optional Vulkan features. This is useful
for testing.

Also debug-print the features in use.
2024-01-07 07:22:51 +01:00
Benjamin Otte
7dcb7d7d0f gpu: Add Vulkan feature flags for more advanced features
Code continues if those features aren't available, buit is probably
broken.
2024-01-07 07:22:51 +01:00
Benjamin Otte
ee93f88268 vulkan: Add support for enumerating dmabuf formats
This code does not add a downloader, so we do not claim support for all
the new formats.

It just queries the formats. But this can be used to import dmabufs
directly into the Vulkaan renderer.
2024-01-07 07:22:51 +01:00
Benjamin Otte
223d1343de gpu: Add GdkDisplay::vulkan_features
use it to collect the optional features we are interested in and turn
them on only if available.

For now we add the dmabuf features, but we don't use them yet.
2024-01-07 07:22:51 +01:00
Benjamin Otte
e3c70645f9 vulkan: Turn Vulkan instances into init/ref/unref
This is not yet used.
2024-01-07 07:22:49 +01:00
Benjamin Otte
c21ca4811e vulkan: Require Vulkan 1.3
Some dmabuf formats were added in Vulkan 1.3.

Note that this does not require the Vulkan drivers to be version 1.3 -
it just means compilation against libvulkan 1.3
2023-12-21 17:21:54 +01:00
Benjamin Otte
310ab7b531 Remove G_ENABLE_DEBUG around debug checks
It started out as busywork, but it does many separate things. If I could
start over, I'd take them apart into multiple commits:

1. Remove G_ENABLE_DEBUG around GDK_DEBUG_*() calls
   This is not needed at all, the calls themselves take care of it.

2. Remove G_ENABLE_DEBUG around profiling code
   This now enables profiling support in release builds.

3. Stop poking _gdk_debug_flags and use GDK_DEBUG_CHECK()
   This was old code that was never updated.

4. Make !G_ENABLE_DEBUG turn off GDK_DEBUG_CHECK()
   The code used to
     #define GDK_DEBUG_CHECK(...) false
     #define GDK_DEBUG(...)
   which would compile away all the code inside those macros. This
   means a lot of variable definitions and debug utility functions
   would suddenly no longer be used and cause compiler errors.
2023-11-05 11:16:23 +01:00
Benjamin Otte
008d9e5327 vulkan: Actually check for GDK_DEBUG=vulkan-disable
The dmabuf code would happily init Vulkan even if it was told we don't
want it.
2023-10-20 14:26:59 +02:00
Benjamin Otte
60c20fa6ed vulkan: Require Vulkan 1.2
We need to inist on the nonuniform access beuing available and that
requires Vulkan 1.2.

Also simplifies the descriptor indexing stuff, because that's all part
of Vulkan 1.2, too.
2023-09-15 16:34:00 +02:00
Benjamin Otte
c8f385e3bc vulkancontext: Do proper refcounting
- fix a memleak
- call unref() instead of new()
- remove idle handler on dispose

What was I doing when I wrote the pipeline cache code?
2023-07-31 16:51:03 +02:00
Matthias Clasen
69cf0a75c5 gdk: Build fix 2023-07-28 09:06:14 +03:00
Benjamin Otte
6e75e26a0c vulkan: Add new error code 2023-07-22 01:33:44 +02:00
Benjamin Otte
0f289fddf7 vulkan: Fix leaks with pipeline cache
In particular, we were leaking the actual cache and then created a new
one.
2023-07-19 21:30:35 +02:00
Benjamin Otte
83960622e3 vulkan: Store shaders in the display
Have a resource path => vkShaderModule hash table instead of doing fancy
custom objects.

A benefit is that shader modules are now shared between all renderers
and pipelines.
2023-07-16 12:12:36 +02:00
José Roberto de Souza
526c0404c2 vulkan: Wait for device to be idle before create/recreating swapchain
Wait for device to be idle because this function is also called in
window resizes.
And if we destroy old swapchain it also destroy the old VkImages,
those images could be in use by a vulkan render.

This fixes a issue reported in Mesa repository when running
GTK with Xe KMD.

Fixes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/9044
Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
2023-07-13 05:40:55 -07:00
Benjamin Otte
684a015c98 vulkan: Add a pipeline cache
Make the display handle the cache, because we only need one.

We store the cache in
  $CACHE_DIR/gtk-4.0/vulkan-pipeline-cache/$UUID.$VERSION
so we regenerate caches for each different device (different UUID) and
each different driver version.

We also keep track of the etag of the cache file, so if 2 different
applications update the cache, we can detect that.
Vulkan allows merging caches, so the 2nd app reloads the new cache file
and merges it into its cache before saving.
2023-06-26 20:28:11 +02:00
Benjamin Otte
299c6a3d6f vulkan: Take offscreen fromat from context
We want to create offscreens in compatible formats, and in particular we
want to ideally use the same format as rendering would use.
2023-06-20 20:15:12 +02:00
Benjamin Otte
015cebc046 vulkan: Set descriptorBindingStorageBufferUpdateAfterBind
It's necessary now that we use storage buffers for gradients:

[ VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-descriptorBindingStorageBufferUpdateAfterBind-03008 ] Object 0: handle = 0x1e72d70, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x943cc552 | vkCreateDescriptorSetLayout(): pBindings[0] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT for VK_DESCRIPTOR_TYPE_STORAGE_BUFFER since descriptorBindingStorageBufferUpdateAfterBind is not enabled. The Vulkan spec states: If VkPhysicalDeviceDescriptorIndexingFeatures::descriptorBindingStorageBufferUpdateAfterBind is not enabled, all bindings with descriptor type VK_DESCRIPTOR_TYPE_STORAGE_BUFFER must not use VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-descriptorBindingStorageBufferUpdateAfterBind-03008)
2023-06-20 20:15:12 +02:00
Benjamin Otte
4045a0edd1 vulkan: Check for descriptor indexing extension
By checking if the extension is supported and avoiding devices when it
isn't, we avoid critical warnings later.
2023-06-19 15:08:00 +02:00
Benjamin Otte
636591c080 vulkan: Refactor function
Instead of checking for one specific extension, instead pass the
extension to check for by name.

This way we can reuse it for different extensions.
2023-06-19 15:08:00 +02:00
Benjamin Otte
aa6c670f15 vulkan: Add support for high bit depth 2023-06-19 15:08:00 +02:00
Benjamin Otte
63edecd857 vulkan: Make gsk_renderer_realize() work with NULL surface
Pretty much copy what GL does and just use the default display to create
GPU-related resources without the need for a display.

This also adds gdk_display_create_vulkan_context() but I've
kept it private because the Vulkan API is generally considered in flux,
in particular with our pending attempts to redo how renderers work.
2023-06-19 14:13:03 +02:00
Benjamin Otte
090cd2238a gdk: Replace prefers_high_depth with depth
Now that we track depth, we can also pass it into the GDK frame code.

For now it's just passed along, code acts the same as with
prefers_high_depth.
2023-06-18 14:28:39 +02:00
Benjamin Otte
0f1b039306 vulkan: Implement bindless texture rendering
Instead of having a descriptor set per operation, we just have one
descriptor set and bind all our images into it.

Then the shaders get to use an index into the large texture array
instead.

Getting this to work - because it's a Vulkan extension that needs to be
manually enabled, even though it's officially part of Vulkan 1.2 - is
insane.
2023-06-04 19:42:01 +02:00
Jordan Petridis
0197149ba3 vulkan: Correct error enum version guards
Vulkan 218 introduced these errors by they were marked as
the beta till version 238.

00671c64ba (diff-e222ae95c2b0d5082b94d6086fb1c24da18ee31384c1a39840df3b9152023ee6)

Followup to f9b2d3104a
2023-05-01 09:41:35 +03:00
Georges Basile Stavracas Neto
9c013d40c1 gdk/vulkancontext: Use more appropriate present mode
Check if the driver supports MAILBOX and prefer using it; in its
absense, checkif the driver supports IMMEDIATE and prefer using
it; finally, if neither of them are supported, use the guaranteed
to be supported FIFO mode.
2023-04-13 13:54:45 -03:00
Georges Basile Stavracas Neto
5c27a0dd2b vulkan: Support fractional scaling
Basically what GL does, but without any debug or feature flag
to gatekeep it, since the Vulkan backend itself is experimental
already.

Ceil surface sizes, and floor coordinates, to the fractional scale
value.
2023-04-03 11:10:27 -03:00
Georges Basile Stavracas Neto
6e80c8b07e gdk/vulkancontext: Accept Khronos validation layers
The Lunarg validation layers seem to have been deprecated in favour
of the Khronos ones. There's no reason not to have both, to accept
loading both - simultaneously, even.
2023-03-30 17:13:35 -03:00
Georges Basile Stavracas Neto
c0449e3245 gdk/vulkancontext: Pass all painted rects
Instead of passing a single, potentially massive rectangle that is
just the extents of the damage rect, collect and pass all damage
rects individually.
2023-03-30 17:13:35 -03:00
Jordan Petridis
f9b2d3104a vulkan: Update error codes enum 2023-03-20 16:16:30 +02:00
Emmanuele Bassi
03db707f3c vulkan: Add missing enumeration
Check for VK_ERROR_COMPRESSION_EXHAUSTED_EXT.
2022-11-26 15:18:42 +00:00
Matthias Clasen
4aabc45685 Drop gdkintl.h
This header was merely including gi18n-lib.h.
Just do that directly.
2022-09-23 23:33:42 -04:00
Matthias Clasen
1d48f96fc5 gdk: Use the new debug macros 2022-09-23 18:11:48 -04:00
Matthias Clasen
1b96828667 Make vulkan-validate always available
There is no need to restrict this debug builds.
2022-09-21 20:49:53 -04:00
Matthias Clasen
bddf9f9ca3 docs: Cosmetics
Do a round of "the the" removal.
2021-10-18 08:35:54 -04:00
Benjamin Otte
dc6e831524 gdk: hdr => high depth
The term "hdr" is so overloaded, we shouldn't use them anywhere, except
from maybe describing all of this work in blog posts and other marketing
materials.

So do renames:
* hdr => high_depth
* request_hdr => prefers_high_depth

This more accurately describes what is going on.
2021-10-06 22:50:07 +02:00
Benjamin Otte
7ede468849 gdk: Add a request_hdr argument to begin_frame()
It's not used by anyone, it's just there.

gdk_draw_context_begin_frame_full() has been added so renderers can
make use of it.
2021-10-06 03:44:58 +02:00
Benjamin Otte
a29474567a gdk: Remove gdkinternals.h 2021-09-24 22:50:29 +02:00
Benjamin Otte
27cad85247 gdk: Include Vulkan error code in vulkan_strerror() 2021-08-12 14:19:30 +02:00
Matthias Clasen
fff2b3c710 gdk: Clean up docs syntax
Replace leftover gtk-doc syntax (#Type) with backquotes.
2021-05-22 17:25:26 -04:00
Matthias Clasen
9132f1831c docs: Rework the gdk docs
Convert links, make things more concise.
2021-03-11 16:37:31 +00:00
Emmanuele Bassi
f22ec063a1 Fix the Vulkan header check for VK_RESULT_RANGE_SIZE
The VK_RESULT_RANGE_SIZE enumeration value was removed in 1.2.140, not
1.2.142.

Fixes: #3522
2020-12-28 18:41:18 +00:00
Matthias Clasen
4310f24a4e Fix warnings with Vulkan < 162
Tiring to watch the Vulkan people stumble through
ABI and API compat, but what can you do.
2020-12-21 20:00:16 -05:00
Timm Bäder
3c2484142d vulkancontext: Remove usage of VK_ERROR_INCOMPATIBLE_VERSION_KHR
According to
https://www.khronos.org/registry/vulkan/specs/1.0-wsi_extensions/html/chap46.html
this has been removed. It also breaks the build on my system
2020-12-16 08:26:46 +01:00
Matthias Clasen
b9d4654fca vulkan: Fix swapchain creation
We end up with a surface that has size 0x0 at the
time we create the Vulkan context, and that is a
size that Vulkan doesn't like, so ensure we request
at least 1x1.

Fixes: #3147
2020-09-10 13:55:16 -04:00
Benjamin Otte
d375dce9f5 Replace "gchar" with "char" 2020-07-25 00:47:36 +02:00