Commit Graph

42 Commits

Author SHA1 Message Date
Benjamin Otte
27fbdcbecb gdk: Add A16_FLOAT and A32_FLOAT formats
We need them for mask-only textures.

For tiffs, we convert the formats to RGBA (the idea that tiff can save
everything needs to be buried I guess) as tiffs can't do alpha-only.
2023-07-22 01:33:44 +02:00
Benjamin Otte
dd641867a2 vulkan: Be more careful with supported images
Now that we can upload all these fancy formats, we need to make sure
that we actually can.
2023-07-19 21:30:35 +02:00
Benjamin Otte
4d9e7d30b0 vulkan: Add premultiply step to texture upload
When a GdkMemoryFormat is not supported natively and there's
postprocessing required, add a way to mark a VulkanImage as such via the
new postprocess flags.

Also allow texting such iamges only with new_for_upload() and detect
when that is the case and then run a postprocessing step that converts
that image to a suitable format.
This is done with a new "convert" shader/op.

This now supports all formats natively, no conversions happen on the CPU
anymore (unless the GPU is old).
2023-07-19 21:30:35 +02:00
Benjamin Otte
65224f4533 vulkan: Change fallback formats
Always fall back to a format that isn't swizzled.

That way it can be used as a target format for rendering.
2023-07-19 21:30:35 +02:00
Benjamin Otte
e7549f3359 vulkan: Redo barriers
We now store all the relevant state of the image inside the VulkanImage
struct, so we can delay barriers for as long as possible.

Whenever we want to use an image, we call the new
gsk_vulkan_image_transition() and it will add a barrier to the desired
state if one is necessary.
2023-07-16 13:16:43 +02:00
Benjamin Otte
fee497f9e1 vulkan: Track the current pipeline stage of images
This way, we can in theory properly transition images because we know
which stage to transition from.

IN practice this is happening in future commits.
2023-07-16 13:16:43 +02:00
Benjamin Otte
ca69fd2b7a vulkan: Remove GskVulkanUploader
... and all the remaining functions still using it.

It's all unused and has been replaced by upload and download ops.

With this change, all GPU operations now go via GskVulkanOp.command()
and no more side channels exist.
2023-07-16 13:16:43 +02:00
Benjamin Otte
0d5e54986a vulkan: Remove unused functions 2023-07-16 13:16:43 +02:00
Benjamin Otte
c72588748b vulkan: Implement direct upload for the cairo op 2023-07-16 12:13:00 +02:00
Benjamin Otte
48e1d48e7f vulkan: Upload cairo images "directly"
Instead of using the upload vfunc and going via the code in
GskVulkanImage, copy/paste the relevant code into the command() vfunc.

This is meant to achieve multiple things:
1. Get rid of GskVulkanUploader and its own command buffer and general
   non-integration with operations.
2. Get rid of GskVulkanOp:upload()
3. Get the upload/download code machinery for GskVulkanImage and put it
   with the actual operations.

The current code can't do direct upload/download, that will follow in a
future commit.
2023-07-16 12:13:00 +02:00
Benjamin Otte
cef87b102c vulkan: Cache framebuffer in image
Instead of recreating them every frame for every render pass, reuse the
same framebuffer.
2023-07-16 12:13:00 +02:00
Benjamin Otte
58c318a4dc vulkan: Add gskvulkanprivate.h
It's the new place for all the common stuff.

Because the old place is about to go away.
2023-07-16 12:13:00 +02:00
Benjamin Otte
94a64329c2 vulkan: Add new renderops for texture rendering
Adds 2 ops:

- Upload
  Creates a new Vulkan image and uploads data into it

- Texture
  Draws a given image

These 2 ops are then used for GskTextureNodes.
2023-07-16 12:12:36 +02:00
Benjamin Otte
2fef53b154 vulkan: Pass context, not uploader
We don't need the uploader when creating the image, only when uploading.
2023-07-16 12:12:36 +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
c35f491795 vulkan: Store the VkFormat in GskVulkanImage
... and use that info when creating renderpasses.
2023-06-19 15:08:00 +02:00
Benjamin Otte
5b64ca7e0a vulkan: Pick high depth texture for high depth nodes
If a node has a higher depth, pick the RGBA format that has that depth
as the texture format we're renderig to with render_texture().

Support for adapting the swapchain is not part of this.
2023-06-19 15:08:00 +02:00
Benjamin Otte
d61737ac7a vulkan: Add format fallback
When a GdkMemoryFormat isn't supported, pick close formats that have a
higher chance of being supported.
Make sure this works recursively and the whole loop always ends up at
R8G8B8A8_UNORM because that one is mandatory.

Roughly, follow these rules:
1. Drop the unpremultiplied
2. Expand channels to include all of RGBA
3. pick swizzle that is RGBA
4. pick next largest depth
5. pick R8G8B8A8_UNORM
2023-06-19 15:08:00 +02:00
Benjamin Otte
ba28971a18 vulkan: Allow mapping images as "read" and/or "write"
This way, we unify the code paths for memory access to textures.

We also technically gain the ability to modify images, though I have no
use case for this.
2023-06-19 15:08:00 +02:00
Benjamin Otte
7b4846bc25 vulkan: Pass format to offscreen creation function
That way, the offscreen can create images of different types.

Its not used in this commit, but will come in handy when we want to
support high bit depth.
2023-06-19 15:08:00 +02:00
Benjamin Otte
eb3ccfb404 vulkan: Remove gsk_vulkan_image_new_for_framebuffer()
Use gsk_vulkan_image_new_for_offscreen() instead, it does the same thing
pretty much.
2023-06-19 15:08:00 +02:00
Benjamin Otte
e4c37ceb34 vulkan: Allow uploading in different formats
This requires quite some code because Vulkan may not support all the
formats and then we need to detect that and fallback properly.
2023-06-19 15:08:00 +02:00
Benjamin Otte
dae1e2b117 vulkan: Create the view in vulkan_image_new()
All callers want it created anyway.

Plus, we can consolidate things in future commits.
2023-06-19 15:08:00 +02:00
Benjamin Otte
9836389fde vulkan: Repurpose debug flags for image uploads
Now that we don't use the old environment variables anymore to force
staging buffer/image uploads, we don't need them.

However, we do autodetect the fast path for avoiding a staging buffer
now, and we might want to be able to turn that off for testing.

So add GSK_DEBUG=staging that does exactly that.
2023-06-14 03:34:07 +02:00
Benjamin Otte
7f26f5a160 vulkan: Remove gsk_vulkan_image_new_from_data()
This is unused now that all the code uses map/unmap.

The only thing that map/unmap doesn't do that the old code did, was use
a staging image instead as alternative to a staging buffer for image
uploads.

However, that code is not necessary for anything, so I'm sure we can do
without.
2023-06-14 03:34:07 +02:00
Benjamin Otte
6a009b7182 vulkan: Add upload fastpath
If the memory heap that the GPU uses allows CPU access
(which is the case on basically every integrated GPU, including phones),
we can avoid a staging buffer and write directly into the image memory.

Check for this case and do that automatically.

Unfortunately we need to change the image format we use from
VK_IMAGE_TILING_OPTIMAL to VK_IMAGE_TILING_LINEAR, I haven't found a way
around that yet.
2023-06-14 03:34:07 +02:00
Benjamin Otte
c27e412ff1 vulkan: Use new upload method for texture uploads
gsk_vulkan_image_new_from_texture() now uses the direct copy via
gdk_texture_downloader_download_into().
2023-06-14 03:34:07 +02:00
Benjamin Otte
0c72f19cb1 vulkan: Add a new way to upload data into images
As an alternative to gsk_vulkan_image_new_from_data() that
takes a given data and creates an image from it, add a 3 step process:
  gsk_vulkan_image_new_for_upload()
  gsk_vulkan_image_map_memory()
  /* put data into memory */
  gsk_vulkan_image_unmap_memory()

The benefit of this approach is that it potentially avoids a copy;
instead of creating a buffer to pass and writing the data into it before
then memcpy()ing it into the image, the data can be written straight
into image memory.

So far, only the staging buffer upload is implemented.

There are also no users, those come in the next commit(s).
2023-06-14 03:34:07 +02:00
Benjamin Otte
cb4e92946b vulkan: Move some code
Add gsk_vulkan_image_new_from_texture() and use it.

Also rewrite the actual code from using Cairo surfaces to using
GdkTextureDownloader.
2023-06-14 03:34:07 +02:00
Benjamin Otte
e7c86f4608 vulkan: Constify upload function 2023-06-14 03:34:07 +02:00
Benjamin Otte
7f1bd1f047 vulkan: Handle empty child bounds in repeat node
Also add test to the testsuite for it.
2023-06-04 19:42:01 +02:00
Benjamin Otte
d2f45dae96 vulkan: offscreens are used as color attachments
... so set the corresponding flag.

Also name the function "new_for_offscreen()" because thats what this
function is about, "texture" is ambiguous.
2023-06-04 19:42:00 +02:00
Georges Basile Stavracas Neto
57587c00b4 gsk/vulkanimage: Set buffer row length and height
This doesn't make any difference now, but will allow us to copy
subregions more easily. This is not obvious, but here's a quick
explanation:

Leaving 'bufferRowLength' and 'bufferImageHeight' implies that
Vulkan will assume the size passed in the 'imageExtent' field.
Right now, this assumption is correct - the only user of this
function is the glyph cache, and it only copies and uploads
exact rects. Next commits will change that assumption, so we
must pass 'buffer*' fields, and tell Vulkan, "this part of the
buffer represents an image of width x height, and I want the
subregion (x, y, smallerWidth, smallerHeight) of this image".
2023-04-03 10:59:45 -03:00
Georges Basile Stavracas Neto
724d07ef8a gsk/vulkan/image: Use UNDEFINED for initial layout
When creating an image using gsk_vulkan_image_new_for_framebuffer(),
it passes VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL.

However, this is a mistake. The spec demands that the initial
layout must be either VK_IMAGE_LAYOUT_UNDEFINED or
VK_IMAGE_LAYOUT_PREINITIALIZED.

Apparently this was an oversight from commit b97fb75146, since the
commit message even documents that, and all other calls pass either
VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREINITIALIZED.

Create framebuffer images using VK_IMAGE_LAYOUT_UNDEFINED, which is
what was originally expected.
2023-04-03 10:59:45 -03:00
Georges Basile Stavracas Neto
a33ddd54ac gsk/vulkan/image: Cosmetics 2023-04-02 19:29:55 -03:00
Matthias Clasen
9f88dba162 gsk: Stop using g_slice 2023-03-14 14:56:42 -04:00
Matthias Clasen
3c15fa96bc vulkan: Fix image uploading by regions
This code did not make sense; it was incrementing
the wrong variable.

Pointed out in https://www.viva64.com/en/b/0793/
2021-02-04 00:12:44 -05:00
Georges Basile Stavracas Neto
0b2006b74f vulkan/image: Set HOST and TRANSFER bits for before barriers
Multiple images in the before barrier array are defined with
VK_ACCESS_TRANSFER_WRITE_BIT and VK_ACCESS_TRANSFER_READ_BIT,
which requires passing VK_PIPELINE_STAGE_TRANSFER_BIT and
VK_PIPELINE_STAGE_HOST_BIT to vkCmdPipelineBarrier().

Pass these flags correctly.
2019-10-05 12:13:22 -03:00
Benjamin Otte
d54ca3c74f gdk: Add GDK_MEMORY_DEFAULT
This is the default memory format.

I added it because it is way better than including a private header and
using GDK_MEMORY_CAIRO_FORMAT_ARGB32.
2018-03-18 05:57:07 +01:00
Benjamin Otte
ee8e42f19b gdk: Remove gdk_texture_new_from_data()
Use gdk_memory_texture_new() instead.
2018-03-18 05:57:07 +01:00
Matthias Clasen
ba21a7764b gsk: Reorganize env vars
Get rid of GSK_RENDERING_MODE and add the flags to GSK_DEBUG,
following the same pattern we use in gdk now.
2018-01-14 17:05:04 -05:00
Matthias Clasen
3771c95c72 gsk: Move Vulkan sources to a subdirectory
Following what was already done for GL.
2018-01-06 09:36:55 -05:00