Merge branch 'wip/otte/for-vulkan' into 'main'

vulkan: Fix a bunch of validation-layer complaints

See merge request GNOME/gtk!6126
This commit is contained in:
Benjamin Otte 2023-06-20 18:38:41 +00:00
commit 1a07e336bf
77 changed files with 132 additions and 104 deletions

View File

@ -52,6 +52,7 @@ struct _GdkVulkanContextPrivate {
GdkMemoryFormat gdk_format;
} formats[4];
GdkMemoryDepth current_format;
GdkMemoryFormat offscreen_formats[4];
VkSwapchainKHR swapchain;
VkSemaphore draw_semaphore;
@ -693,6 +694,11 @@ gdk_vulkan_context_real_init (GInitable *initable,
if (!priv->vulkan_ref)
return FALSE;
priv->offscreen_formats[GDK_MEMORY_U8] = GDK_MEMORY_B8G8R8A8_PREMULTIPLIED;
priv->offscreen_formats[GDK_MEMORY_U16] = GDK_MEMORY_R16G16B16A16_PREMULTIPLIED;
priv->offscreen_formats[GDK_MEMORY_FLOAT16] = GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED;
priv->offscreen_formats[GDK_MEMORY_FLOAT32] = GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED;
if (surface == NULL)
{
for (i = 0; i < G_N_ELEMENTS (priv->formats); i++)
@ -748,6 +754,7 @@ gdk_vulkan_context_real_init (GInitable *initable,
{
priv->formats[GDK_MEMORY_U8].vk_format = formats[i];
priv->formats[GDK_MEMORY_U8].gdk_format = GDK_MEMORY_B8G8R8A8_PREMULTIPLIED;
priv->offscreen_formats[GDK_MEMORY_U8] = GDK_MEMORY_B8G8R8A8_PREMULTIPLIED;
};
break;
@ -827,6 +834,15 @@ out_surface:
return FALSE;
}
GdkMemoryFormat
gdk_vulkan_context_get_offscreen_format (GdkVulkanContext *context,
GdkMemoryDepth depth)
{
GdkVulkanContextPrivate *priv = gdk_vulkan_context_get_instance_private (context);
return priv->offscreen_formats[depth];
}
static void
gdk_vulkan_context_initable_init (GInitableIface *iface)
{
@ -1168,6 +1184,7 @@ gdk_display_create_vulkan_device (GdkDisplay *display,
.descriptorBindingPartiallyBound = VK_TRUE,
.descriptorBindingVariableDescriptorCount = VK_TRUE,
.descriptorBindingSampledImageUpdateAfterBind = VK_TRUE,
.descriptorBindingStorageBufferUpdateAfterBind = VK_TRUE,
}
},
NULL,

View File

@ -69,9 +69,12 @@ gdk_vulkan_handle_result (VkResult res,
#define GDK_VK_CHECK(func, ...) gdk_vulkan_handle_result (func (__VA_ARGS__), G_STRINGIFY (func))
gboolean gdk_display_ref_vulkan (GdkDisplay *display,
GError **error);
void gdk_display_unref_vulkan (GdkDisplay *display);
gboolean gdk_display_ref_vulkan (GdkDisplay *display,
GError **error);
void gdk_display_unref_vulkan (GdkDisplay *display);
GdkMemoryFormat gdk_vulkan_context_get_offscreen_format (GdkVulkanContext *context,
GdkMemoryDepth depth);
#else /* !GDK_RENDERING_VULKAN */

View File

@ -78,8 +78,8 @@ gsk_vulkan_buffer_new_map (GdkVulkanContext *context,
{
return gsk_vulkan_buffer_new_internal (context,
size,
(mode & GSK_VULKAN_READ ? VK_BUFFER_USAGE_TRANSFER_SRC_BIT : 0) |
(mode & GSK_VULKAN_WRITE ? VK_BUFFER_USAGE_TRANSFER_DST_BIT : 0));
(mode & GSK_VULKAN_READ ? VK_BUFFER_USAGE_TRANSFER_DST_BIT : 0) |
(mode & GSK_VULKAN_WRITE ? VK_BUFFER_USAGE_TRANSFER_SRC_BIT : 0));
}
void

View File

@ -488,24 +488,6 @@ gsk_memory_format_get_fallback (GdkMemoryFormat format)
}
}
GdkMemoryFormat
gsk_render_node_get_preferred_vulkan_format (GskRenderNode *node)
{
switch (gsk_render_node_get_preferred_depth (node))
{
case GDK_MEMORY_U8:
return GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
case GDK_MEMORY_U16:
return GDK_MEMORY_R16G16B16A16_PREMULTIPLIED;
case GDK_MEMORY_FLOAT16:
return GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED;
case GDK_MEMORY_FLOAT32:
return GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED;
default:
g_return_val_if_reached (GDK_MEMORY_R8G8B8A8_PREMULTIPLIED);
}
}
static gboolean
gsk_vulkan_context_supports_format (GdkVulkanContext *context,
VkFormat format)

View File

@ -1,7 +1,6 @@
#pragma once
#include <gdk/gdk.h>
#include <gsk/gskrendernode.h>
#include "gskvulkanbufferprivate.h"
#include "gskvulkancommandpoolprivate.h"
@ -22,8 +21,6 @@ void gsk_vulkan_uploader_free (GskVulk
void gsk_vulkan_uploader_reset (GskVulkanUploader *self);
void gsk_vulkan_uploader_upload (GskVulkanUploader *self);
GdkMemoryFormat gsk_render_node_get_preferred_vulkan_format (GskRenderNode *node);
GskVulkanImage * gsk_vulkan_image_new_for_swapchain (GdkVulkanContext *context,
VkImage image,
VkFormat format,

View File

@ -41,6 +41,8 @@
#define GDK_ARRAY_NO_MEMSET 1
#include "gdk/gdkarrayimpl.c"
#define N_DESCRIPTOR_SETS 3
struct _GskVulkanRender
{
GskRenderer *renderer;
@ -52,7 +54,7 @@ struct _GskVulkanRender
GskVulkanCommandPool *command_pool;
VkFence fence;
VkDescriptorSetLayout descriptor_set_layout;
VkDescriptorSetLayout descriptor_set_layouts[N_DESCRIPTOR_SETS];
VkPipelineLayout pipeline_layout;
GskVulkanUploader *uploader;
@ -60,7 +62,7 @@ struct _GskVulkanRender
GskDescriptorImageInfos descriptor_samplers;
GskDescriptorBufferInfos descriptor_buffers;
VkDescriptorPool descriptor_pool;
VkDescriptorSet descriptor_set;
VkDescriptorSet descriptor_sets[N_DESCRIPTOR_SETS];
GskVulkanPipeline *pipelines[GSK_VULKAN_N_PIPELINES];
GskVulkanImage *target;
@ -148,9 +150,9 @@ gsk_vulkan_render_new (GskRenderer *renderer,
&(VkDescriptorPoolCreateInfo) {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT,
.maxSets = 1,
.poolSizeCount = 3,
.pPoolSizes = (VkDescriptorPoolSize[3]) {
.maxSets = N_DESCRIPTOR_SETS,
.poolSizeCount = N_DESCRIPTOR_SETS,
.pPoolSizes = (VkDescriptorPoolSize[N_DESCRIPTOR_SETS]) {
{
.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.descriptorCount = DESCRIPTOR_POOL_MAXITEMS
@ -171,7 +173,7 @@ gsk_vulkan_render_new (GskRenderer *renderer,
GSK_VK_CHECK (vkCreateDescriptorSetLayout, device,
&(VkDescriptorSetLayoutCreateInfo) {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
.bindingCount = 3,
.bindingCount = 1,
.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT,
.pBindings = (VkDescriptorSetLayoutBinding[3]) {
{
@ -179,30 +181,12 @@ gsk_vulkan_render_new (GskRenderer *renderer,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.descriptorCount = DESCRIPTOR_POOL_MAXITEMS,
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT
},
{
.binding = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER,
.descriptorCount = DESCRIPTOR_POOL_MAXITEMS,
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT
},
{
.binding = 2,
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.descriptorCount = DESCRIPTOR_POOL_MAXITEMS,
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT
},
}
},
.pNext = &(VkDescriptorSetLayoutBindingFlagsCreateInfo) {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO,
.bindingCount = 3,
.pBindingFlags = (VkDescriptorBindingFlags[3]) {
VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT
| VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT
| VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT,
VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT
| VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT
| VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT,
.bindingCount = 1,
.pBindingFlags = (VkDescriptorBindingFlags[1]) {
VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT
| VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT
| VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT,
@ -210,15 +194,65 @@ gsk_vulkan_render_new (GskRenderer *renderer,
}
},
NULL,
&self->descriptor_set_layout);
&self->descriptor_set_layouts[0]);
GSK_VK_CHECK (vkCreateDescriptorSetLayout, device,
&(VkDescriptorSetLayoutCreateInfo) {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
.bindingCount = 1,
.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT,
.pBindings = (VkDescriptorSetLayoutBinding[1]) {
{
.binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER,
.descriptorCount = DESCRIPTOR_POOL_MAXITEMS,
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT
}
},
.pNext = &(VkDescriptorSetLayoutBindingFlagsCreateInfo) {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO,
.bindingCount = 1,
.pBindingFlags = (VkDescriptorBindingFlags[1]) {
VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT
| VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT
| VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT,
},
}
},
NULL,
&self->descriptor_set_layouts[1]);
GSK_VK_CHECK (vkCreateDescriptorSetLayout, device,
&(VkDescriptorSetLayoutCreateInfo) {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
.bindingCount = 1,
.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT,
.pBindings = (VkDescriptorSetLayoutBinding[1]) {
{
.binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.descriptorCount = DESCRIPTOR_POOL_MAXITEMS,
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT
},
},
.pNext = &(VkDescriptorSetLayoutBindingFlagsCreateInfo) {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO,
.bindingCount = 1,
.pBindingFlags = (VkDescriptorBindingFlags[1]) {
VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT
| VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT
| VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT,
},
}
},
NULL,
&self->descriptor_set_layouts[2]);
GSK_VK_CHECK (vkCreatePipelineLayout, device,
&(VkPipelineLayoutCreateInfo) {
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.setLayoutCount = 1,
.pSetLayouts = (VkDescriptorSetLayout[1]) {
self->descriptor_set_layout
},
.setLayoutCount = G_N_ELEMENTS (self->descriptor_set_layouts),
.pSetLayouts = self->descriptor_set_layouts,
.pushConstantRangeCount = gsk_vulkan_push_constants_get_range_count (),
.pPushConstantRanges = gsk_vulkan_push_constants_get_ranges ()
},
@ -403,10 +437,18 @@ gsk_vulkan_render_get_pipeline (GskVulkanRender *self,
return self->pipelines[type];
}
VkDescriptorSet
gsk_vulkan_render_get_descriptor_set (GskVulkanRender *self)
void
gsk_vulkan_render_bind_descriptor_sets (GskVulkanRender *self,
VkCommandBuffer command_buffer)
{
return self->descriptor_set;
vkCmdBindDescriptorSets (command_buffer,
VK_PIPELINE_BIND_POINT_GRAPHICS,
self->pipeline_layout,
0,
3,
self->descriptor_sets,
0,
NULL);
}
gsize
@ -537,11 +579,6 @@ gsk_vulkan_render_prepare_descriptor_sets (GskVulkanRender *self)
gsk_vulkan_render_pass_reserve_descriptor_sets (pass, self);
}
if (gsk_descriptor_image_infos_get_size (&self->descriptor_samplers) == 0 &&
gsk_descriptor_image_infos_get_size (&self->descriptor_images) == 0 &&
gsk_descriptor_buffer_infos_get_size (&self->descriptor_buffers) == 0)
return;
if (self->storage_buffer_memory)
{
gsk_vulkan_buffer_unmap (self->storage_buffer);
@ -553,26 +590,26 @@ gsk_vulkan_render_prepare_descriptor_sets (GskVulkanRender *self)
&(VkDescriptorSetAllocateInfo) {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
.descriptorPool = self->descriptor_pool,
.descriptorSetCount = 1,
.pSetLayouts = &self->descriptor_set_layout,
.descriptorSetCount = N_DESCRIPTOR_SETS,
.pSetLayouts = self->descriptor_set_layouts,
.pNext = &(VkDescriptorSetVariableDescriptorCountAllocateInfo) {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO,
.descriptorSetCount = 1,
.pDescriptorCounts = (uint32_t[1]) {
gsk_descriptor_image_infos_get_size (&self->descriptor_images)
+ gsk_descriptor_image_infos_get_size (&self->descriptor_samplers)
+ gsk_descriptor_buffer_infos_get_size (&self->descriptor_buffers)
.descriptorSetCount = N_DESCRIPTOR_SETS,
.pDescriptorCounts = (uint32_t[N_DESCRIPTOR_SETS]) {
MAX (1, gsk_descriptor_image_infos_get_size (&self->descriptor_images)),
MAX (1, gsk_descriptor_image_infos_get_size (&self->descriptor_samplers)),
MAX (1, gsk_descriptor_buffer_infos_get_size (&self->descriptor_buffers))
}
}
},
&self->descriptor_set);
self->descriptor_sets);
n_descriptor_sets = 0;
if (gsk_descriptor_image_infos_get_size (&self->descriptor_images) > 0)
{
descriptor_sets[n_descriptor_sets++] = (VkWriteDescriptorSet) {
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = self->descriptor_set,
.dstSet = self->descriptor_sets[0],
.dstBinding = 0,
.dstArrayElement = 0,
.descriptorCount = gsk_descriptor_image_infos_get_size (&self->descriptor_images),
@ -584,8 +621,8 @@ gsk_vulkan_render_prepare_descriptor_sets (GskVulkanRender *self)
{
descriptor_sets[n_descriptor_sets++] = (VkWriteDescriptorSet) {
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = self->descriptor_set,
.dstBinding = 1,
.dstSet = self->descriptor_sets[1],
.dstBinding = 0,
.dstArrayElement = 0,
.descriptorCount = gsk_descriptor_image_infos_get_size (&self->descriptor_samplers),
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER,
@ -596,8 +633,8 @@ gsk_vulkan_render_prepare_descriptor_sets (GskVulkanRender *self)
{
descriptor_sets[n_descriptor_sets++] = (VkWriteDescriptorSet) {
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = self->descriptor_set,
.dstBinding = 2,
.dstSet = self->descriptor_sets[2],
.dstBinding = 0,
.dstArrayElement = 0,
.descriptorCount = gsk_descriptor_buffer_infos_get_size (&self->descriptor_buffers),
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
@ -741,9 +778,10 @@ gsk_vulkan_render_free (GskVulkanRender *self)
gsk_descriptor_image_infos_clear (&self->descriptor_samplers);
gsk_descriptor_buffer_infos_clear (&self->descriptor_buffers);
vkDestroyDescriptorSetLayout (device,
self->descriptor_set_layout,
NULL);
for (i = 0; i < N_DESCRIPTOR_SETS; i++)
vkDestroyDescriptorSetLayout (device,
self->descriptor_set_layouts[i],
NULL);
vkDestroyFence (device,
self->fence,

View File

@ -14,8 +14,9 @@
#include "gdk/gdkdisplayprivate.h"
#include "gdk/gdkdrawcontextprivate.h"
#include "gdk/gdktextureprivate.h"
#include "gdk/gdkprofilerprivate.h"
#include "gdk/gdktextureprivate.h"
#include "gdk/gdkvulkancontextprivate.h"
#include <graphene.h>
@ -286,7 +287,8 @@ gsk_vulkan_renderer_render_texture (GskRenderer *renderer,
ceil (viewport->size.width),
ceil (viewport->size.height));
image = gsk_vulkan_image_new_for_offscreen (self->vulkan,
gsk_render_node_get_preferred_vulkan_format (root),
gdk_vulkan_context_get_offscreen_format (self->vulkan,
gsk_render_node_get_preferred_depth (root)),
rounded_viewport.size.width,
rounded_viewport.size.height);

View File

@ -26,6 +26,8 @@
#include "gskvulkanrendererprivate.h"
#include "gskprivate.h"
#include "gdk/gdkvulkancontextprivate.h"
#define ORTHO_NEAR_PLANE -10000
#define ORTHO_FAR_PLANE 10000
@ -1275,7 +1277,8 @@ gsk_vulkan_render_pass_render_offscreen (GdkVulkanContext *vulkan,
ceil (scale_y * viewport->size.height));
result = gsk_vulkan_image_new_for_offscreen (vulkan,
gsk_render_node_get_preferred_vulkan_format (node),
gdk_vulkan_context_get_offscreen_format (vulkan,
gsk_render_node_get_preferred_depth (node)),
view.size.width, view.size.height);
#ifdef G_ENABLE_DEBUG
@ -2436,7 +2439,6 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass *self,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer)
{
VkDescriptorSet descriptor_set;
cairo_rectangle_int_t rect;
vkCmdSetViewport (command_buffer,
@ -2469,16 +2471,7 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass *self,
},
VK_SUBPASS_CONTENTS_INLINE);
descriptor_set = gsk_vulkan_render_get_descriptor_set (render);
if (descriptor_set)
vkCmdBindDescriptorSets (command_buffer,
VK_PIPELINE_BIND_POINT_GRAPHICS,
pipeline_layout,
0,
1,
&descriptor_set,
0,
NULL);
gsk_vulkan_render_bind_descriptor_sets (render, command_buffer);
gsk_vulkan_render_pass_draw_rect (self, render, pipeline_layout, command_buffer);

View File

@ -93,7 +93,8 @@ guchar * gsk_vulkan_render_get_buffer_memory (GskVulk
gsize size,
gsize alignment,
gsize *out_offset);
VkDescriptorSet gsk_vulkan_render_get_descriptor_set (GskVulkanRender *self);
void gsk_vulkan_render_bind_descriptor_sets (GskVulkanRender *self,
VkCommandBuffer command_buffer);
void gsk_vulkan_render_draw (GskVulkanRender *self);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,6 @@
layout(set = 0, binding = 0) uniform texture2D textures[50000];
layout(set = 0, binding = 1) uniform sampler samplers[50000];
layout(set = 0, binding = 2) readonly buffer FloatBuffers {
layout(set = 1, binding = 0) uniform sampler samplers[50000];
layout(set = 2, binding = 0) readonly buffer FloatBuffers {
float floats[];
} buffers[50000];

Binary file not shown.

View File

@ -3,11 +3,6 @@
#include "common.vert.glsl"
#include "rect.vert.glsl"
struct ColorStop {
float offset;
vec4 color;
};
layout(location = 0) in vec4 inRect;
layout(location = 1) in vec2 inStart;
layout(location = 2) in vec2 inEnd;

Binary file not shown.

Binary file not shown.

Binary file not shown.