2016-12-07 13:50:52 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2017-04-18 14:14:35 +00:00
|
|
|
#include "gskprivate.h"
|
|
|
|
|
2016-12-07 13:50:52 +00:00
|
|
|
#include "gskvulkanrenderprivate.h"
|
|
|
|
|
2016-12-08 12:26:36 +00:00
|
|
|
#include "gskrendererprivate.h"
|
|
|
|
#include "gskvulkanbufferprivate.h"
|
2016-12-16 05:10:24 +00:00
|
|
|
#include "gskvulkancommandpoolprivate.h"
|
2016-12-07 13:50:52 +00:00
|
|
|
#include "gskvulkanpipelineprivate.h"
|
2016-12-08 12:26:36 +00:00
|
|
|
#include "gskvulkanrenderpassprivate.h"
|
|
|
|
|
2017-09-23 05:59:50 +00:00
|
|
|
#include "gskvulkanblendmodepipelineprivate.h"
|
2017-09-03 13:54:47 +00:00
|
|
|
#include "gskvulkanblurpipelineprivate.h"
|
2017-01-10 13:59:20 +00:00
|
|
|
#include "gskvulkanborderpipelineprivate.h"
|
2017-01-18 03:07:09 +00:00
|
|
|
#include "gskvulkanboxshadowpipelineprivate.h"
|
2016-12-18 01:18:01 +00:00
|
|
|
#include "gskvulkancolorpipelineprivate.h"
|
2017-09-01 20:58:42 +00:00
|
|
|
#include "gskvulkancolortextpipelineprivate.h"
|
2017-09-22 18:20:57 +00:00
|
|
|
#include "gskvulkancrossfadepipelineprivate.h"
|
2016-12-30 05:46:34 +00:00
|
|
|
#include "gskvulkaneffectpipelineprivate.h"
|
2016-12-26 16:11:13 +00:00
|
|
|
#include "gskvulkanlineargradientpipelineprivate.h"
|
2017-09-01 20:58:42 +00:00
|
|
|
#include "gskvulkantextpipelineprivate.h"
|
2017-09-30 02:24:53 +00:00
|
|
|
#include "gskvulkantexturepipelineprivate.h"
|
2017-09-22 17:30:26 +00:00
|
|
|
#include "gskvulkanpushconstantsprivate.h"
|
2016-12-18 01:18:01 +00:00
|
|
|
|
2023-05-20 00:56:02 +00:00
|
|
|
#define DESCRIPTOR_POOL_MAXITEMS 50000
|
|
|
|
|
|
|
|
#define GDK_ARRAY_NAME gsk_descriptor_image_infos
|
|
|
|
#define GDK_ARRAY_TYPE_NAME GskDescriptorImageInfos
|
|
|
|
#define GDK_ARRAY_ELEMENT_TYPE VkDescriptorImageInfo
|
|
|
|
#define GDK_ARRAY_BY_VALUE 1
|
|
|
|
#define GDK_ARRAY_PREALLOC 1024
|
|
|
|
#define GDK_ARRAY_NO_MEMSET 1
|
|
|
|
#include "gdk/gdkarrayimpl.c"
|
2016-12-09 01:55:47 +00:00
|
|
|
|
2023-05-25 20:21:23 +00:00
|
|
|
#define GDK_ARRAY_NAME gsk_descriptor_buffer_infos
|
|
|
|
#define GDK_ARRAY_TYPE_NAME GskDescriptorBufferInfos
|
|
|
|
#define GDK_ARRAY_ELEMENT_TYPE VkDescriptorBufferInfo
|
|
|
|
#define GDK_ARRAY_BY_VALUE 1
|
|
|
|
#define GDK_ARRAY_PREALLOC 1024
|
|
|
|
#define GDK_ARRAY_NO_MEMSET 1
|
|
|
|
#include "gdk/gdkarrayimpl.c"
|
|
|
|
|
2023-06-20 13:39:29 +00:00
|
|
|
#define N_DESCRIPTOR_SETS 3
|
|
|
|
|
2016-12-08 16:55:32 +00:00
|
|
|
struct _GskVulkanRender
|
|
|
|
{
|
|
|
|
GskRenderer *renderer;
|
|
|
|
GdkVulkanContext *vulkan;
|
|
|
|
|
2023-04-03 13:39:25 +00:00
|
|
|
double scale;
|
2017-09-30 14:42:32 +00:00
|
|
|
graphene_rect_t viewport;
|
2016-12-26 23:18:52 +00:00
|
|
|
cairo_region_t *clip;
|
2016-12-08 16:55:32 +00:00
|
|
|
|
2016-12-16 05:10:24 +00:00
|
|
|
GskVulkanCommandPool *command_pool;
|
2016-12-08 17:03:05 +00:00
|
|
|
VkFence fence;
|
2023-06-20 13:39:29 +00:00
|
|
|
VkDescriptorSetLayout descriptor_set_layouts[N_DESCRIPTOR_SETS];
|
2023-05-12 18:49:31 +00:00
|
|
|
VkPipelineLayout pipeline_layout;
|
2016-12-17 03:22:44 +00:00
|
|
|
GskVulkanUploader *uploader;
|
2016-12-09 01:55:47 +00:00
|
|
|
|
2023-05-23 03:08:13 +00:00
|
|
|
GskDescriptorImageInfos descriptor_images;
|
|
|
|
GskDescriptorImageInfos descriptor_samplers;
|
2023-05-25 20:21:23 +00:00
|
|
|
GskDescriptorBufferInfos descriptor_buffers;
|
2016-12-08 23:06:59 +00:00
|
|
|
VkDescriptorPool descriptor_pool;
|
2023-06-20 13:39:29 +00:00
|
|
|
VkDescriptorSet descriptor_sets[N_DESCRIPTOR_SETS];
|
2016-12-14 08:40:15 +00:00
|
|
|
GskVulkanPipeline *pipelines[GSK_VULKAN_N_PIPELINES];
|
2016-12-08 17:03:05 +00:00
|
|
|
|
2016-12-08 21:35:16 +00:00
|
|
|
GskVulkanImage *target;
|
|
|
|
|
2023-05-23 03:26:08 +00:00
|
|
|
VkSampler samplers[3];
|
2023-05-25 20:21:23 +00:00
|
|
|
GskVulkanBuffer *storage_buffer;
|
|
|
|
guchar *storage_buffer_memory;
|
|
|
|
gsize storage_buffer_used;
|
2017-09-30 02:38:59 +00:00
|
|
|
|
2017-09-28 00:56:01 +00:00
|
|
|
GList *render_passes;
|
2016-12-08 16:55:32 +00:00
|
|
|
GSList *cleanup_images;
|
2017-09-28 12:29:14 +00:00
|
|
|
|
|
|
|
GQuark render_pass_counter;
|
2017-09-28 14:27:58 +00:00
|
|
|
GQuark gpu_time_timer;
|
2016-12-08 16:55:32 +00:00
|
|
|
};
|
|
|
|
|
2016-12-08 12:26:36 +00:00
|
|
|
static void
|
2016-12-26 23:18:52 +00:00
|
|
|
gsk_vulkan_render_setup (GskVulkanRender *self,
|
|
|
|
GskVulkanImage *target,
|
2018-03-28 13:01:34 +00:00
|
|
|
const graphene_rect_t *rect,
|
|
|
|
const cairo_region_t *clip)
|
2016-12-08 12:26:36 +00:00
|
|
|
{
|
2023-04-03 11:54:34 +00:00
|
|
|
GdkSurface *surface = gsk_renderer_get_surface (self->renderer);
|
2016-12-26 23:18:52 +00:00
|
|
|
|
|
|
|
self->target = g_object_ref (target);
|
2016-12-08 12:26:36 +00:00
|
|
|
|
2016-12-22 18:01:07 +00:00
|
|
|
if (rect)
|
|
|
|
{
|
2017-09-30 14:42:32 +00:00
|
|
|
self->viewport = *rect;
|
2023-04-03 13:39:25 +00:00
|
|
|
self->scale = 1.0;
|
2016-12-22 18:01:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-03 13:39:25 +00:00
|
|
|
self->scale = gdk_surface_get_scale (surface);
|
2017-09-30 14:42:32 +00:00
|
|
|
self->viewport = GRAPHENE_RECT_INIT (0, 0,
|
2023-04-03 13:39:25 +00:00
|
|
|
(int) ceil (gdk_surface_get_width (surface) * self->scale),
|
|
|
|
(int) ceil (gdk_surface_get_height (surface) * self->scale));
|
2018-03-28 13:01:34 +00:00
|
|
|
}
|
|
|
|
if (clip)
|
|
|
|
{
|
2018-03-31 06:17:42 +00:00
|
|
|
cairo_rectangle_int_t extents;
|
|
|
|
cairo_region_get_extents (clip, &extents);
|
|
|
|
self->clip = cairo_region_create_rectangle (&(cairo_rectangle_int_t) {
|
|
|
|
extents.x, extents.y,
|
|
|
|
extents.width, extents.height
|
|
|
|
});
|
2018-03-28 13:01:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self->clip = cairo_region_create_rectangle (&(cairo_rectangle_int_t) {
|
|
|
|
0, 0,
|
|
|
|
gsk_vulkan_image_get_width (target),
|
|
|
|
gsk_vulkan_image_get_height (target)
|
|
|
|
});
|
2016-12-22 18:01:07 +00:00
|
|
|
}
|
2016-12-08 12:26:36 +00:00
|
|
|
}
|
2016-12-07 13:50:52 +00:00
|
|
|
|
2016-12-08 16:46:08 +00:00
|
|
|
GskVulkanRender *
|
|
|
|
gsk_vulkan_render_new (GskRenderer *renderer,
|
2016-12-08 23:06:59 +00:00
|
|
|
GdkVulkanContext *context)
|
2016-12-07 13:50:52 +00:00
|
|
|
{
|
2016-12-08 16:46:08 +00:00
|
|
|
GskVulkanRender *self;
|
2016-12-08 17:03:05 +00:00
|
|
|
VkDevice device;
|
2016-12-08 16:46:08 +00:00
|
|
|
|
2023-03-03 11:48:49 +00:00
|
|
|
self = g_new0 (GskVulkanRender, 1);
|
2016-12-08 16:46:08 +00:00
|
|
|
|
2016-12-07 13:50:52 +00:00
|
|
|
self->vulkan = context;
|
2016-12-08 12:26:36 +00:00
|
|
|
self->renderer = renderer;
|
2023-05-23 03:08:13 +00:00
|
|
|
gsk_descriptor_image_infos_init (&self->descriptor_images);
|
|
|
|
gsk_descriptor_image_infos_init (&self->descriptor_samplers);
|
2023-05-25 20:21:23 +00:00
|
|
|
gsk_descriptor_buffer_infos_init (&self->descriptor_buffers);
|
2016-12-07 13:50:52 +00:00
|
|
|
|
2016-12-08 17:03:05 +00:00
|
|
|
device = gdk_vulkan_context_get_device (self->vulkan);
|
|
|
|
|
2016-12-16 05:10:24 +00:00
|
|
|
self->command_pool = gsk_vulkan_command_pool_new (self->vulkan);
|
2016-12-08 17:03:05 +00:00
|
|
|
GSK_VK_CHECK (vkCreateFence, device,
|
|
|
|
&(VkFenceCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
|
2016-12-08 17:40:35 +00:00
|
|
|
.flags = VK_FENCE_CREATE_SIGNALED_BIT
|
2016-12-08 17:03:05 +00:00
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&self->fence);
|
|
|
|
|
2016-12-08 23:06:59 +00:00
|
|
|
GSK_VK_CHECK (vkCreateDescriptorPool, device,
|
|
|
|
&(VkDescriptorPoolCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
2023-05-20 00:56:02 +00:00
|
|
|
.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT,
|
2023-06-20 13:39:29 +00:00
|
|
|
.maxSets = N_DESCRIPTOR_SETS,
|
|
|
|
.poolSizeCount = N_DESCRIPTOR_SETS,
|
|
|
|
.pPoolSizes = (VkDescriptorPoolSize[N_DESCRIPTOR_SETS]) {
|
2016-12-08 23:06:59 +00:00
|
|
|
{
|
2023-05-23 03:08:13 +00:00
|
|
|
.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
|
|
|
.descriptorCount = DESCRIPTOR_POOL_MAXITEMS
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = VK_DESCRIPTOR_TYPE_SAMPLER,
|
2023-05-20 00:56:02 +00:00
|
|
|
.descriptorCount = DESCRIPTOR_POOL_MAXITEMS
|
2023-05-25 20:21:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
|
|
|
.descriptorCount = DESCRIPTOR_POOL_MAXITEMS
|
2016-12-08 23:06:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&self->descriptor_pool);
|
|
|
|
|
2017-09-22 14:02:27 +00:00
|
|
|
GSK_VK_CHECK (vkCreateDescriptorSetLayout, device,
|
|
|
|
&(VkDescriptorSetLayoutCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
2023-06-20 13:39:29 +00:00
|
|
|
.bindingCount = 1,
|
2023-05-20 00:56:02 +00:00
|
|
|
.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT,
|
2023-05-25 20:21:23 +00:00
|
|
|
.pBindings = (VkDescriptorSetLayoutBinding[3]) {
|
2017-09-22 14:02:27 +00:00
|
|
|
{
|
|
|
|
.binding = 0,
|
2023-05-23 03:08:13 +00:00
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
|
|
|
.descriptorCount = DESCRIPTOR_POOL_MAXITEMS,
|
|
|
|
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT
|
2023-06-20 13:39:29 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
.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[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]) {
|
2023-05-23 03:08:13 +00:00
|
|
|
{
|
2023-06-20 13:39:29 +00:00
|
|
|
.binding = 0,
|
2023-05-23 03:08:13 +00:00
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER,
|
2023-05-20 00:56:02 +00:00
|
|
|
.descriptorCount = DESCRIPTOR_POOL_MAXITEMS,
|
2017-09-22 14:02:27 +00:00
|
|
|
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT
|
2023-06-20 13:39:29 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
.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]) {
|
2023-05-25 20:21:23 +00:00
|
|
|
{
|
2023-06-20 13:39:29 +00:00
|
|
|
.binding = 0,
|
2023-05-25 20:21:23 +00:00
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
|
|
|
.descriptorCount = DESCRIPTOR_POOL_MAXITEMS,
|
|
|
|
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT
|
|
|
|
},
|
2023-05-20 00:56:02 +00:00
|
|
|
},
|
|
|
|
.pNext = &(VkDescriptorSetLayoutBindingFlagsCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO,
|
2023-06-20 13:39:29 +00:00
|
|
|
.bindingCount = 1,
|
|
|
|
.pBindingFlags = (VkDescriptorBindingFlags[1]) {
|
2023-05-20 00:56:02 +00:00
|
|
|
VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT
|
|
|
|
| VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT
|
|
|
|
| VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT,
|
|
|
|
},
|
2017-09-22 14:02:27 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
NULL,
|
2023-06-20 13:39:29 +00:00
|
|
|
&self->descriptor_set_layouts[2]);
|
2017-09-22 14:02:27 +00:00
|
|
|
|
2023-05-12 18:49:31 +00:00
|
|
|
GSK_VK_CHECK (vkCreatePipelineLayout, device,
|
|
|
|
&(VkPipelineLayoutCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
2023-06-20 13:39:29 +00:00
|
|
|
.setLayoutCount = G_N_ELEMENTS (self->descriptor_set_layouts),
|
|
|
|
.pSetLayouts = self->descriptor_set_layouts,
|
2023-05-12 18:49:31 +00:00
|
|
|
.pushConstantRangeCount = gsk_vulkan_push_constants_get_range_count (),
|
|
|
|
.pPushConstantRanges = gsk_vulkan_push_constants_get_ranges ()
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&self->pipeline_layout);
|
2016-12-14 07:00:58 +00:00
|
|
|
|
2017-09-30 02:38:59 +00:00
|
|
|
GSK_VK_CHECK (vkCreateSampler, device,
|
|
|
|
&(VkSamplerCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
|
|
|
.magFilter = VK_FILTER_LINEAR,
|
|
|
|
.minFilter = VK_FILTER_LINEAR,
|
2023-05-13 04:02:51 +00:00
|
|
|
.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
|
|
|
.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
2017-09-30 02:38:59 +00:00
|
|
|
.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
|
|
|
.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,
|
|
|
|
.unnormalizedCoordinates = VK_FALSE,
|
|
|
|
.maxAnisotropy = 1.0,
|
|
|
|
},
|
|
|
|
NULL,
|
2023-05-23 03:08:13 +00:00
|
|
|
&self->samplers[GSK_VULKAN_SAMPLER_DEFAULT]);
|
2017-09-30 02:38:59 +00:00
|
|
|
|
2017-09-30 03:01:34 +00:00
|
|
|
GSK_VK_CHECK (vkCreateSampler, device,
|
|
|
|
&(VkSamplerCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
|
|
|
.magFilter = VK_FILTER_LINEAR,
|
|
|
|
.minFilter = VK_FILTER_LINEAR,
|
|
|
|
.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
|
|
|
.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
|
|
|
.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
|
|
|
.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,
|
|
|
|
.unnormalizedCoordinates = VK_FALSE,
|
|
|
|
.maxAnisotropy = 1.0,
|
|
|
|
},
|
|
|
|
NULL,
|
2023-05-23 03:08:13 +00:00
|
|
|
&self->samplers[GSK_VULKAN_SAMPLER_REPEAT]);
|
|
|
|
|
2023-05-23 03:26:08 +00:00
|
|
|
GSK_VK_CHECK (vkCreateSampler, device,
|
|
|
|
&(VkSamplerCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
|
|
|
.magFilter = VK_FILTER_NEAREST,
|
|
|
|
.minFilter = VK_FILTER_NEAREST,
|
|
|
|
.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
|
|
|
.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
|
|
|
.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
|
|
|
.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,
|
|
|
|
.unnormalizedCoordinates = VK_FALSE,
|
|
|
|
.maxAnisotropy = 1.0,
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&self->samplers[GSK_VULKAN_SAMPLER_NEAREST]);
|
|
|
|
|
2017-09-30 03:01:34 +00:00
|
|
|
|
2016-12-17 03:22:44 +00:00
|
|
|
self->uploader = gsk_vulkan_uploader_new (self->vulkan, self->command_pool);
|
|
|
|
|
2017-09-28 12:29:14 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
self->render_pass_counter = g_quark_from_static_string ("render-passes");
|
2017-09-28 14:27:58 +00:00
|
|
|
self->gpu_time_timer = g_quark_from_static_string ("gpu-time");
|
2017-09-28 12:29:14 +00:00
|
|
|
#endif
|
|
|
|
|
2016-12-08 16:46:08 +00:00
|
|
|
return self;
|
2016-12-07 13:50:52 +00:00
|
|
|
}
|
|
|
|
|
2023-05-24 14:55:18 +00:00
|
|
|
VkFence
|
|
|
|
gsk_vulkan_render_get_fence (GskVulkanRender *self)
|
|
|
|
{
|
|
|
|
return self->fence;
|
|
|
|
}
|
|
|
|
|
2016-12-08 12:26:36 +00:00
|
|
|
void
|
|
|
|
gsk_vulkan_render_add_cleanup_image (GskVulkanRender *self,
|
|
|
|
GskVulkanImage *image)
|
|
|
|
{
|
|
|
|
self->cleanup_images = g_slist_prepend (self->cleanup_images, image);
|
|
|
|
}
|
|
|
|
|
2017-09-30 15:04:16 +00:00
|
|
|
void
|
2017-09-30 14:37:55 +00:00
|
|
|
gsk_vulkan_render_add_render_pass (GskVulkanRender *self,
|
|
|
|
GskVulkanRenderPass *pass)
|
|
|
|
{
|
|
|
|
self->render_passes = g_list_prepend (self->render_passes, pass);
|
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
gsk_profiler_counter_inc (gsk_renderer_get_profiler (self->renderer), self->render_pass_counter);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-12-08 12:26:36 +00:00
|
|
|
void
|
|
|
|
gsk_vulkan_render_add_node (GskVulkanRender *self,
|
|
|
|
GskRenderNode *node)
|
|
|
|
{
|
2017-09-28 00:56:01 +00:00
|
|
|
GskVulkanRenderPass *pass;
|
2023-05-10 00:46:57 +00:00
|
|
|
graphene_vec2_t scale;
|
|
|
|
|
|
|
|
graphene_vec2_init (&scale, self->scale, self->scale);
|
2017-09-28 00:56:01 +00:00
|
|
|
|
|
|
|
pass = gsk_vulkan_render_pass_new (self->vulkan,
|
|
|
|
self->target,
|
2023-05-10 00:46:57 +00:00
|
|
|
&scale,
|
2017-09-30 14:42:32 +00:00
|
|
|
&self->viewport,
|
2017-09-28 00:56:01 +00:00
|
|
|
self->clip,
|
|
|
|
VK_NULL_HANDLE);
|
|
|
|
|
2017-09-30 14:37:55 +00:00
|
|
|
gsk_vulkan_render_add_render_pass (self, pass);
|
2017-09-28 12:29:14 +00:00
|
|
|
|
2017-09-28 00:56:01 +00:00
|
|
|
gsk_vulkan_render_pass_add (pass, self, node);
|
2016-12-08 12:26:36 +00:00
|
|
|
}
|
|
|
|
|
2017-09-28 00:56:01 +00:00
|
|
|
void
|
|
|
|
gsk_vulkan_render_upload (GskVulkanRender *self)
|
2016-12-08 12:26:36 +00:00
|
|
|
{
|
2017-09-28 00:56:01 +00:00
|
|
|
GList *l;
|
2016-12-08 12:26:36 +00:00
|
|
|
|
2017-09-28 00:56:01 +00:00
|
|
|
/* gsk_vulkan_render_pass_upload may call gsk_vulkan_render_add_node_for_texture,
|
|
|
|
* prepending new render passes to the list. Therefore, we walk the list from
|
|
|
|
* the end.
|
|
|
|
*/
|
|
|
|
for (l = g_list_last (self->render_passes); l; l = l->prev)
|
2016-12-08 12:26:36 +00:00
|
|
|
{
|
2017-09-28 00:56:01 +00:00
|
|
|
GskVulkanRenderPass *pass = l->data;
|
|
|
|
gsk_vulkan_render_pass_upload (pass, self, self->uploader);
|
2016-12-08 12:26:36 +00:00
|
|
|
}
|
|
|
|
|
2017-09-28 00:56:01 +00:00
|
|
|
gsk_vulkan_uploader_upload (self->uploader);
|
2016-12-08 12:26:36 +00:00
|
|
|
}
|
|
|
|
|
2016-12-14 08:40:15 +00:00
|
|
|
GskVulkanPipeline *
|
|
|
|
gsk_vulkan_render_get_pipeline (GskVulkanRender *self,
|
2023-06-17 17:15:05 +00:00
|
|
|
GskVulkanPipelineType type,
|
|
|
|
VkRenderPass render_pass)
|
2016-12-14 08:40:15 +00:00
|
|
|
{
|
|
|
|
static const struct {
|
|
|
|
const char *name;
|
2017-09-22 14:35:19 +00:00
|
|
|
guint num_textures;
|
2017-09-22 17:30:26 +00:00
|
|
|
GskVulkanPipeline * (* create_func) (GdkVulkanContext *context, VkPipelineLayout layout, const char *name, VkRenderPass render_pass);
|
2016-12-14 08:40:15 +00:00
|
|
|
} pipeline_info[GSK_VULKAN_N_PIPELINES] = {
|
2017-09-30 02:24:53 +00:00
|
|
|
{ "texture", 1, gsk_vulkan_texture_pipeline_new },
|
|
|
|
{ "texture-clip", 1, gsk_vulkan_texture_pipeline_new },
|
|
|
|
{ "texture-clip-rounded", 1, gsk_vulkan_texture_pipeline_new },
|
2017-09-22 14:35:19 +00:00
|
|
|
{ "color", 0, gsk_vulkan_color_pipeline_new },
|
|
|
|
{ "color-clip", 0, gsk_vulkan_color_pipeline_new },
|
|
|
|
{ "color-clip-rounded", 0, gsk_vulkan_color_pipeline_new },
|
|
|
|
{ "linear", 0, gsk_vulkan_linear_gradient_pipeline_new },
|
|
|
|
{ "linear-clip", 0, gsk_vulkan_linear_gradient_pipeline_new },
|
|
|
|
{ "linear-clip-rounded", 0, gsk_vulkan_linear_gradient_pipeline_new },
|
|
|
|
{ "color-matrix", 1, gsk_vulkan_effect_pipeline_new },
|
|
|
|
{ "color-matrix-clip", 1, gsk_vulkan_effect_pipeline_new },
|
|
|
|
{ "color-matrix-clip-rounded", 1, gsk_vulkan_effect_pipeline_new },
|
|
|
|
{ "border", 0, gsk_vulkan_border_pipeline_new },
|
|
|
|
{ "border-clip", 0, gsk_vulkan_border_pipeline_new },
|
|
|
|
{ "border-clip-rounded", 0, gsk_vulkan_border_pipeline_new },
|
|
|
|
{ "inset-shadow", 0, gsk_vulkan_box_shadow_pipeline_new },
|
|
|
|
{ "inset-shadow-clip", 0, gsk_vulkan_box_shadow_pipeline_new },
|
|
|
|
{ "inset-shadow-clip-rounded", 0, gsk_vulkan_box_shadow_pipeline_new },
|
|
|
|
{ "outset-shadow", 0, gsk_vulkan_box_shadow_pipeline_new },
|
|
|
|
{ "outset-shadow-clip", 0, gsk_vulkan_box_shadow_pipeline_new },
|
|
|
|
{ "outset-shadow-clip-rounded", 0, gsk_vulkan_box_shadow_pipeline_new },
|
|
|
|
{ "blur", 1, gsk_vulkan_blur_pipeline_new },
|
|
|
|
{ "blur-clip", 1, gsk_vulkan_blur_pipeline_new },
|
|
|
|
{ "blur-clip-rounded", 1, gsk_vulkan_blur_pipeline_new },
|
|
|
|
{ "mask", 1, gsk_vulkan_text_pipeline_new },
|
|
|
|
{ "mask-clip", 1, gsk_vulkan_text_pipeline_new },
|
|
|
|
{ "mask-clip-rounded", 1, gsk_vulkan_text_pipeline_new },
|
2017-09-30 21:57:36 +00:00
|
|
|
{ "texture", 1, gsk_vulkan_color_text_pipeline_new },
|
|
|
|
{ "texture-clip", 1, gsk_vulkan_color_text_pipeline_new },
|
|
|
|
{ "texture-clip-rounded", 1, gsk_vulkan_color_text_pipeline_new },
|
2017-09-22 18:20:57 +00:00
|
|
|
{ "crossfade", 2, gsk_vulkan_cross_fade_pipeline_new },
|
|
|
|
{ "crossfade-clip", 2, gsk_vulkan_cross_fade_pipeline_new },
|
|
|
|
{ "crossfade-clip-rounded", 2, gsk_vulkan_cross_fade_pipeline_new },
|
2023-06-27 04:05:33 +00:00
|
|
|
{ "blend-mode", 2, gsk_vulkan_blend_mode_pipeline_new },
|
|
|
|
{ "blend-mode-clip", 2, gsk_vulkan_blend_mode_pipeline_new },
|
|
|
|
{ "blend-mode-clip-rounded", 2, gsk_vulkan_blend_mode_pipeline_new },
|
2016-12-14 08:40:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
g_return_val_if_fail (type < GSK_VULKAN_N_PIPELINES, NULL);
|
|
|
|
|
|
|
|
if (self->pipelines[type] == NULL)
|
2017-09-22 17:30:26 +00:00
|
|
|
self->pipelines[type] = pipeline_info[type].create_func (self->vulkan,
|
2023-05-12 18:49:31 +00:00
|
|
|
self->pipeline_layout,
|
2017-09-22 17:30:26 +00:00
|
|
|
pipeline_info[type].name,
|
2023-06-17 17:15:05 +00:00
|
|
|
render_pass);
|
2016-12-14 08:40:15 +00:00
|
|
|
|
|
|
|
return self->pipelines[type];
|
|
|
|
}
|
|
|
|
|
2023-06-20 13:39:29 +00:00
|
|
|
void
|
|
|
|
gsk_vulkan_render_bind_descriptor_sets (GskVulkanRender *self,
|
|
|
|
VkCommandBuffer command_buffer)
|
2016-12-09 01:55:47 +00:00
|
|
|
{
|
2023-06-20 13:39:29 +00:00
|
|
|
vkCmdBindDescriptorSets (command_buffer,
|
|
|
|
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
self->pipeline_layout,
|
|
|
|
0,
|
|
|
|
3,
|
|
|
|
self->descriptor_sets,
|
|
|
|
0,
|
|
|
|
NULL);
|
2017-09-30 02:38:59 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 01:55:47 +00:00
|
|
|
gsize
|
2023-05-23 03:08:13 +00:00
|
|
|
gsk_vulkan_render_get_sampler_descriptor (GskVulkanRender *self,
|
|
|
|
GskVulkanRenderSampler render_sampler)
|
|
|
|
{
|
|
|
|
VkSampler sampler = self->samplers[render_sampler];
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
/* If this ever shows up in profiles, add a hash table */
|
|
|
|
for (i = 0; i < gsk_descriptor_image_infos_get_size (&self->descriptor_samplers); i++)
|
|
|
|
{
|
|
|
|
if (gsk_descriptor_image_infos_get (&self->descriptor_samplers, i)->sampler == sampler)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert (i < DESCRIPTOR_POOL_MAXITEMS);
|
|
|
|
|
|
|
|
gsk_descriptor_image_infos_append (&self->descriptor_samplers,
|
|
|
|
&(VkDescriptorImageInfo) {
|
|
|
|
.sampler = sampler,
|
|
|
|
});
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
gsize
|
|
|
|
gsk_vulkan_render_get_image_descriptor (GskVulkanRender *self,
|
|
|
|
GskVulkanImage *image)
|
2016-12-09 01:55:47 +00:00
|
|
|
{
|
2023-05-20 00:56:02 +00:00
|
|
|
gsize result;
|
2016-12-09 01:55:47 +00:00
|
|
|
|
2023-05-23 03:08:13 +00:00
|
|
|
result = gsk_descriptor_image_infos_get_size (&self->descriptor_images);
|
|
|
|
gsk_descriptor_image_infos_append (&self->descriptor_images,
|
|
|
|
&(VkDescriptorImageInfo) {
|
|
|
|
.sampler = VK_NULL_HANDLE,
|
|
|
|
.imageView = gsk_vulkan_image_get_image_view (image),
|
|
|
|
.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
|
|
|
|
});
|
2017-09-30 02:38:59 +00:00
|
|
|
|
2023-05-20 00:56:02 +00:00
|
|
|
g_assert (result < DESCRIPTOR_POOL_MAXITEMS);
|
2017-09-30 02:38:59 +00:00
|
|
|
|
2023-05-20 00:56:02 +00:00
|
|
|
return result;
|
2016-12-09 01:55:47 +00:00
|
|
|
}
|
|
|
|
|
2023-05-25 20:21:23 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_render_ensure_storage_buffer (GskVulkanRender *self)
|
|
|
|
{
|
|
|
|
if (self->storage_buffer_memory != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (self->storage_buffer == NULL)
|
|
|
|
{
|
|
|
|
self->storage_buffer = gsk_vulkan_buffer_new_storage (self->vulkan,
|
|
|
|
/* random */
|
|
|
|
sizeof (float) * 1024 * 1024);
|
|
|
|
}
|
|
|
|
|
|
|
|
self->storage_buffer_memory = gsk_vulkan_buffer_map (self->storage_buffer);
|
|
|
|
|
|
|
|
if (gsk_vulkan_render_get_buffer_descriptor (self, self->storage_buffer) != 0)
|
|
|
|
{
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gsize
|
|
|
|
gsk_vulkan_render_get_buffer_descriptor (GskVulkanRender *self,
|
|
|
|
GskVulkanBuffer *buffer)
|
|
|
|
{
|
|
|
|
gsize result;
|
|
|
|
|
|
|
|
gsk_vulkan_render_ensure_storage_buffer (self);
|
|
|
|
|
|
|
|
result = gsk_descriptor_buffer_infos_get_size (&self->descriptor_buffers);
|
|
|
|
gsk_descriptor_buffer_infos_append (&self->descriptor_buffers,
|
|
|
|
&(VkDescriptorBufferInfo) {
|
|
|
|
.buffer = gsk_vulkan_buffer_get_buffer (buffer),
|
|
|
|
.offset = 0,
|
|
|
|
.range = VK_WHOLE_SIZE
|
|
|
|
});
|
|
|
|
|
|
|
|
g_assert (result < DESCRIPTOR_POOL_MAXITEMS);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gsize
|
|
|
|
round_up (gsize number, gsize divisor)
|
|
|
|
{
|
|
|
|
return (number + divisor - 1) / divisor * divisor;
|
|
|
|
}
|
|
|
|
|
|
|
|
guchar *
|
|
|
|
gsk_vulkan_render_get_buffer_memory (GskVulkanRender *self,
|
|
|
|
gsize size,
|
|
|
|
gsize alignment,
|
|
|
|
gsize *out_offset)
|
|
|
|
{
|
|
|
|
guchar *result;
|
|
|
|
|
|
|
|
g_assert (alignment >= sizeof (float));
|
|
|
|
|
|
|
|
gsk_vulkan_render_ensure_storage_buffer (self);
|
|
|
|
|
|
|
|
self->storage_buffer_used = round_up (self->storage_buffer_used, alignment);
|
|
|
|
result = self->storage_buffer_memory + self->storage_buffer_used;
|
|
|
|
*out_offset = self->storage_buffer_used / sizeof (float);
|
|
|
|
|
|
|
|
self->storage_buffer_used += size;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-12-09 01:55:47 +00:00
|
|
|
static void
|
2017-09-30 02:38:59 +00:00
|
|
|
gsk_vulkan_render_prepare_descriptor_sets (GskVulkanRender *self)
|
2016-12-09 01:55:47 +00:00
|
|
|
{
|
|
|
|
VkDevice device;
|
2023-06-08 04:55:40 +00:00
|
|
|
VkWriteDescriptorSet descriptor_sets[3];
|
|
|
|
gsize n_descriptor_sets;
|
2017-09-28 00:56:01 +00:00
|
|
|
GList *l;
|
2016-12-09 01:55:47 +00:00
|
|
|
|
|
|
|
device = gdk_vulkan_context_get_device (self->vulkan);
|
|
|
|
|
|
|
|
for (l = self->render_passes; l; l = l->next)
|
|
|
|
{
|
2017-09-28 00:56:01 +00:00
|
|
|
GskVulkanRenderPass *pass = l->data;
|
|
|
|
gsk_vulkan_render_pass_reserve_descriptor_sets (pass, self);
|
2016-12-09 01:55:47 +00:00
|
|
|
}
|
|
|
|
|
2023-05-25 20:21:23 +00:00
|
|
|
if (self->storage_buffer_memory)
|
|
|
|
{
|
|
|
|
gsk_vulkan_buffer_unmap (self->storage_buffer);
|
|
|
|
self->storage_buffer_memory = NULL;
|
2023-06-18 16:38:48 +00:00
|
|
|
self->storage_buffer_used = 0;
|
2023-05-25 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 17:10:12 +00:00
|
|
|
GSK_VK_CHECK (vkAllocateDescriptorSets, device,
|
|
|
|
&(VkDescriptorSetAllocateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
|
|
|
|
.descriptorPool = self->descriptor_pool,
|
2023-06-20 13:39:29 +00:00
|
|
|
.descriptorSetCount = N_DESCRIPTOR_SETS,
|
|
|
|
.pSetLayouts = self->descriptor_set_layouts,
|
2023-05-20 00:56:02 +00:00
|
|
|
.pNext = &(VkDescriptorSetVariableDescriptorCountAllocateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO,
|
2023-06-20 13:39:29 +00:00
|
|
|
.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))
|
2023-05-20 00:56:02 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-06 17:10:12 +00:00
|
|
|
},
|
2023-06-20 13:39:29 +00:00
|
|
|
self->descriptor_sets);
|
2023-05-20 00:56:02 +00:00
|
|
|
|
2023-06-08 04:55:40 +00:00
|
|
|
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,
|
2023-06-20 13:39:29 +00:00
|
|
|
.dstSet = self->descriptor_sets[0],
|
2023-06-08 04:55:40 +00:00
|
|
|
.dstBinding = 0,
|
|
|
|
.dstArrayElement = 0,
|
|
|
|
.descriptorCount = gsk_descriptor_image_infos_get_size (&self->descriptor_images),
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
|
|
|
.pImageInfo = gsk_descriptor_image_infos_get_data (&self->descriptor_images)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (gsk_descriptor_image_infos_get_size (&self->descriptor_samplers) > 0)
|
|
|
|
{
|
|
|
|
descriptor_sets[n_descriptor_sets++] = (VkWriteDescriptorSet) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
2023-06-20 13:39:29 +00:00
|
|
|
.dstSet = self->descriptor_sets[1],
|
|
|
|
.dstBinding = 0,
|
2023-06-08 04:55:40 +00:00
|
|
|
.dstArrayElement = 0,
|
|
|
|
.descriptorCount = gsk_descriptor_image_infos_get_size (&self->descriptor_samplers),
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER,
|
|
|
|
.pImageInfo = gsk_descriptor_image_infos_get_data (&self->descriptor_samplers)
|
|
|
|
};
|
|
|
|
}
|
2023-05-25 20:21:23 +00:00
|
|
|
if (gsk_descriptor_buffer_infos_get_size (&self->descriptor_buffers) > 0)
|
|
|
|
{
|
|
|
|
descriptor_sets[n_descriptor_sets++] = (VkWriteDescriptorSet) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
2023-06-20 13:39:29 +00:00
|
|
|
.dstSet = self->descriptor_sets[2],
|
|
|
|
.dstBinding = 0,
|
2023-05-25 20:21:23 +00:00
|
|
|
.dstArrayElement = 0,
|
|
|
|
.descriptorCount = gsk_descriptor_buffer_infos_get_size (&self->descriptor_buffers),
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
|
|
|
.pBufferInfo = gsk_descriptor_buffer_infos_get_data (&self->descriptor_buffers)
|
|
|
|
};
|
|
|
|
}
|
2023-06-08 04:55:40 +00:00
|
|
|
|
2023-05-20 00:56:02 +00:00
|
|
|
vkUpdateDescriptorSets (device,
|
2023-06-08 04:55:40 +00:00
|
|
|
n_descriptor_sets,
|
|
|
|
descriptor_sets,
|
2023-05-20 00:56:02 +00:00
|
|
|
0, NULL);
|
2016-12-09 01:55:47 +00:00
|
|
|
}
|
|
|
|
|
2016-12-08 12:26:36 +00:00
|
|
|
void
|
2017-09-30 02:38:59 +00:00
|
|
|
gsk_vulkan_render_draw (GskVulkanRender *self)
|
2016-12-08 12:26:36 +00:00
|
|
|
{
|
2017-09-28 00:56:01 +00:00
|
|
|
GList *l;
|
2016-12-08 12:26:36 +00:00
|
|
|
|
2017-09-28 14:27:58 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2018-01-14 20:11:33 +00:00
|
|
|
if (GSK_RENDERER_DEBUG_CHECK (self->renderer, SYNC))
|
2017-09-28 14:27:58 +00:00
|
|
|
gsk_profiler_timer_begin (gsk_renderer_get_profiler (self->renderer), self->gpu_time_timer);
|
|
|
|
#endif
|
|
|
|
|
2017-09-30 02:38:59 +00:00
|
|
|
gsk_vulkan_render_prepare_descriptor_sets (self);
|
2016-12-08 12:26:36 +00:00
|
|
|
|
2017-09-28 00:56:01 +00:00
|
|
|
for (l = self->render_passes; l; l = l->next)
|
2016-12-26 23:18:52 +00:00
|
|
|
{
|
2017-09-28 00:56:01 +00:00
|
|
|
GskVulkanRenderPass *pass = l->data;
|
|
|
|
VkCommandBuffer command_buffer;
|
|
|
|
gsize wait_semaphore_count;
|
|
|
|
gsize signal_semaphore_count;
|
|
|
|
VkSemaphore *wait_semaphores;
|
|
|
|
VkSemaphore *signal_semaphores;
|
|
|
|
|
|
|
|
wait_semaphore_count = gsk_vulkan_render_pass_get_wait_semaphores (pass, &wait_semaphores);
|
|
|
|
signal_semaphore_count = gsk_vulkan_render_pass_get_signal_semaphores (pass, &signal_semaphores);
|
|
|
|
|
|
|
|
command_buffer = gsk_vulkan_command_pool_get_buffer (self->command_pool);
|
|
|
|
|
2023-05-12 18:49:31 +00:00
|
|
|
gsk_vulkan_render_pass_draw (pass, self, self->pipeline_layout, command_buffer);
|
2017-09-28 00:56:01 +00:00
|
|
|
|
|
|
|
gsk_vulkan_command_pool_submit_buffer (self->command_pool,
|
|
|
|
command_buffer,
|
|
|
|
wait_semaphore_count,
|
|
|
|
wait_semaphores,
|
|
|
|
signal_semaphore_count,
|
|
|
|
signal_semaphores,
|
|
|
|
l->next != NULL ? VK_NULL_HANDLE : self->fence);
|
2016-12-26 23:18:52 +00:00
|
|
|
}
|
2016-12-08 12:26:36 +00:00
|
|
|
|
2018-01-14 20:11:33 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
if (GSK_RENDERER_DEBUG_CHECK (self->renderer, SYNC))
|
2016-12-08 18:56:56 +00:00
|
|
|
{
|
2017-09-28 14:27:58 +00:00
|
|
|
GskProfiler *profiler;
|
|
|
|
gint64 gpu_time;
|
|
|
|
|
2016-12-08 18:56:56 +00:00
|
|
|
GSK_VK_CHECK (vkWaitForFences, gdk_vulkan_context_get_device (self->vulkan),
|
|
|
|
1,
|
|
|
|
&self->fence,
|
|
|
|
VK_TRUE,
|
|
|
|
INT64_MAX);
|
2017-09-28 14:27:58 +00:00
|
|
|
|
|
|
|
profiler = gsk_renderer_get_profiler (self->renderer);
|
|
|
|
gpu_time = gsk_profiler_timer_end (profiler, self->gpu_time_timer);
|
|
|
|
gsk_profiler_timer_set (profiler, self->gpu_time_timer, gpu_time);
|
2016-12-08 18:56:56 +00:00
|
|
|
}
|
2018-01-14 20:11:33 +00:00
|
|
|
#endif
|
2016-12-07 13:50:52 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 20:39:00 +00:00
|
|
|
GdkTexture *
|
2016-12-22 18:01:07 +00:00
|
|
|
gsk_vulkan_render_download_target (GskVulkanRender *self)
|
|
|
|
{
|
2023-04-14 19:27:42 +00:00
|
|
|
GdkTexture *texture;
|
|
|
|
|
|
|
|
texture = gsk_vulkan_image_download (self->target, self->uploader);
|
2016-12-22 18:01:07 +00:00
|
|
|
gsk_vulkan_uploader_reset (self->uploader);
|
|
|
|
|
2023-04-14 19:27:42 +00:00
|
|
|
return texture;
|
2016-12-22 18:01:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-08 17:40:35 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_render_cleanup (GskVulkanRender *self)
|
2016-12-07 13:50:52 +00:00
|
|
|
{
|
2016-12-08 17:03:05 +00:00
|
|
|
VkDevice device = gdk_vulkan_context_get_device (self->vulkan);
|
|
|
|
|
2016-12-08 17:40:35 +00:00
|
|
|
/* XXX: Wait for fence here or just in reset()? */
|
|
|
|
GSK_VK_CHECK (vkWaitForFences, device,
|
|
|
|
1,
|
|
|
|
&self->fence,
|
|
|
|
VK_TRUE,
|
|
|
|
INT64_MAX);
|
|
|
|
|
|
|
|
GSK_VK_CHECK (vkResetFences, device,
|
|
|
|
1,
|
|
|
|
&self->fence);
|
2016-12-16 05:10:24 +00:00
|
|
|
|
2016-12-17 03:22:44 +00:00
|
|
|
gsk_vulkan_uploader_reset (self->uploader);
|
|
|
|
|
2016-12-16 05:10:24 +00:00
|
|
|
gsk_vulkan_command_pool_reset (self->command_pool);
|
2016-12-08 12:26:36 +00:00
|
|
|
|
2017-01-06 15:31:03 +00:00
|
|
|
GSK_VK_CHECK (vkResetDescriptorPool, device,
|
|
|
|
self->descriptor_pool,
|
|
|
|
0);
|
2023-05-23 03:08:13 +00:00
|
|
|
gsk_descriptor_image_infos_set_size (&self->descriptor_images, 0);
|
|
|
|
gsk_descriptor_image_infos_set_size (&self->descriptor_samplers, 0);
|
2023-05-25 20:21:23 +00:00
|
|
|
gsk_descriptor_buffer_infos_set_size (&self->descriptor_buffers, 0);
|
2016-12-09 01:55:47 +00:00
|
|
|
|
2017-09-28 00:56:01 +00:00
|
|
|
g_list_free_full (self->render_passes, (GDestroyNotify) gsk_vulkan_render_pass_free);
|
2016-12-08 17:40:35 +00:00
|
|
|
self->render_passes = NULL;
|
2016-12-08 19:19:56 +00:00
|
|
|
g_slist_free_full (self->cleanup_images, g_object_unref);
|
2016-12-08 17:40:35 +00:00
|
|
|
self->cleanup_images = NULL;
|
2016-12-08 21:35:16 +00:00
|
|
|
|
2016-12-26 23:18:52 +00:00
|
|
|
g_clear_pointer (&self->clip, cairo_region_destroy);
|
2016-12-08 21:35:16 +00:00
|
|
|
g_clear_object (&self->target);
|
2016-12-08 17:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_vulkan_render_free (GskVulkanRender *self)
|
|
|
|
{
|
|
|
|
VkDevice device;
|
2016-12-14 08:40:15 +00:00
|
|
|
guint i;
|
2016-12-08 17:40:35 +00:00
|
|
|
|
|
|
|
gsk_vulkan_render_cleanup (self);
|
|
|
|
|
|
|
|
device = gdk_vulkan_context_get_device (self->vulkan);
|
2016-12-08 16:46:08 +00:00
|
|
|
|
2016-12-14 08:40:15 +00:00
|
|
|
for (i = 0; i < GSK_VULKAN_N_PIPELINES; i++)
|
|
|
|
g_clear_object (&self->pipelines[i]);
|
2016-12-08 23:06:59 +00:00
|
|
|
|
2016-12-17 03:22:44 +00:00
|
|
|
g_clear_pointer (&self->uploader, gsk_vulkan_uploader_free);
|
|
|
|
|
2023-05-20 00:56:02 +00:00
|
|
|
|
2023-05-12 18:49:31 +00:00
|
|
|
vkDestroyPipelineLayout (device,
|
|
|
|
self->pipeline_layout,
|
|
|
|
NULL);
|
2016-12-14 07:00:58 +00:00
|
|
|
|
2016-12-08 23:06:59 +00:00
|
|
|
vkDestroyDescriptorPool (device,
|
|
|
|
self->descriptor_pool,
|
|
|
|
NULL);
|
2023-05-23 03:08:13 +00:00
|
|
|
gsk_descriptor_image_infos_clear (&self->descriptor_images);
|
|
|
|
gsk_descriptor_image_infos_clear (&self->descriptor_samplers);
|
2023-05-25 20:21:23 +00:00
|
|
|
gsk_descriptor_buffer_infos_clear (&self->descriptor_buffers);
|
2016-12-08 23:06:59 +00:00
|
|
|
|
2023-06-20 13:39:29 +00:00
|
|
|
for (i = 0; i < N_DESCRIPTOR_SETS; i++)
|
|
|
|
vkDestroyDescriptorSetLayout (device,
|
|
|
|
self->descriptor_set_layouts[i],
|
|
|
|
NULL);
|
2017-09-22 14:02:27 +00:00
|
|
|
|
2016-12-08 17:03:05 +00:00
|
|
|
vkDestroyFence (device,
|
|
|
|
self->fence,
|
|
|
|
NULL);
|
2016-12-16 05:10:24 +00:00
|
|
|
|
2023-05-23 03:08:13 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (self->samplers); i++)
|
|
|
|
{
|
|
|
|
vkDestroySampler (device,
|
|
|
|
self->samplers[i],
|
|
|
|
NULL);
|
|
|
|
}
|
2017-09-30 03:01:34 +00:00
|
|
|
|
2016-12-16 05:10:24 +00:00
|
|
|
gsk_vulkan_command_pool_free (self->command_pool);
|
2016-12-08 17:03:05 +00:00
|
|
|
|
2023-03-03 11:48:49 +00:00
|
|
|
g_free (self);
|
2016-12-07 13:50:52 +00:00
|
|
|
}
|
2016-12-08 16:55:32 +00:00
|
|
|
|
2016-12-08 17:40:35 +00:00
|
|
|
gboolean
|
|
|
|
gsk_vulkan_render_is_busy (GskVulkanRender *self)
|
|
|
|
{
|
|
|
|
return vkGetFenceStatus (gdk_vulkan_context_get_device (self->vulkan), self->fence) != VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-12-22 18:01:07 +00:00
|
|
|
gsk_vulkan_render_reset (GskVulkanRender *self,
|
|
|
|
GskVulkanImage *target,
|
2018-03-28 13:01:34 +00:00
|
|
|
const graphene_rect_t *rect,
|
|
|
|
const cairo_region_t *clip)
|
2016-12-08 17:40:35 +00:00
|
|
|
{
|
|
|
|
gsk_vulkan_render_cleanup (self);
|
|
|
|
|
2018-03-28 13:01:34 +00:00
|
|
|
gsk_vulkan_render_setup (self, target, rect, clip);
|
2016-12-08 17:40:35 +00:00
|
|
|
}
|
|
|
|
|
2016-12-08 16:55:32 +00:00
|
|
|
GskRenderer *
|
|
|
|
gsk_vulkan_render_get_renderer (GskVulkanRender *self)
|
|
|
|
{
|
|
|
|
return self->renderer;
|
|
|
|
}
|