2023-08-12 20:10:16 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskvulkandeviceprivate.h"
|
|
|
|
|
2023-08-21 00:18:37 +00:00
|
|
|
#include "gskgpuglobalsopprivate.h"
|
|
|
|
#include "gskgpushaderopprivate.h"
|
|
|
|
#include "gskvulkanbufferprivate.h"
|
2023-08-12 20:10:16 +00:00
|
|
|
#include "gskvulkanimageprivate.h"
|
|
|
|
|
|
|
|
#include "gdk/gdkdisplayprivate.h"
|
|
|
|
#include "gdk/gdkvulkancontextprivate.h"
|
|
|
|
|
|
|
|
struct _GskVulkanDevice
|
|
|
|
{
|
|
|
|
GskGpuDevice parent_instance;
|
|
|
|
|
|
|
|
GskVulkanAllocator *allocators[VK_MAX_MEMORY_TYPES];
|
2023-10-19 08:58:06 +00:00
|
|
|
GskVulkanAllocator *external_allocator;
|
2023-10-19 10:54:14 +00:00
|
|
|
GdkVulkanFeatures features;
|
2023-08-12 20:10:16 +00:00
|
|
|
|
2023-11-03 01:48:06 +00:00
|
|
|
guint max_immutable_samplers;
|
2023-11-03 00:59:24 +00:00
|
|
|
guint max_samplers;
|
|
|
|
guint max_buffers;
|
|
|
|
|
2023-10-18 07:33:15 +00:00
|
|
|
GHashTable *conversion_cache;
|
2023-08-21 00:18:37 +00:00
|
|
|
GHashTable *render_pass_cache;
|
2023-10-19 05:43:31 +00:00
|
|
|
GHashTable *pipeline_layouts;
|
|
|
|
GskVulkanPipelineLayout *pipeline_layout_cache;
|
2023-08-21 00:18:37 +00:00
|
|
|
|
2023-08-12 20:10:16 +00:00
|
|
|
VkCommandPool vk_command_pool;
|
2023-08-21 00:18:37 +00:00
|
|
|
VkSampler vk_samplers[GSK_GPU_SAMPLER_N_SAMPLERS];
|
2023-08-12 20:10:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GskVulkanDeviceClass
|
|
|
|
{
|
|
|
|
GskGpuDeviceClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GskVulkanDevice, gsk_vulkan_device, GSK_TYPE_GPU_DEVICE)
|
|
|
|
|
2023-10-18 07:33:15 +00:00
|
|
|
typedef struct _ConversionCacheEntry ConversionCacheEntry;
|
2023-08-21 00:18:37 +00:00
|
|
|
typedef struct _PipelineCacheKey PipelineCacheKey;
|
|
|
|
typedef struct _RenderPassCacheKey RenderPassCacheKey;
|
2023-11-03 00:59:24 +00:00
|
|
|
typedef struct _GskVulkanPipelineLayoutSetup GskVulkanPipelineLayoutSetup;
|
|
|
|
|
|
|
|
struct _GskVulkanPipelineLayoutSetup
|
|
|
|
{
|
|
|
|
gsize n_buffers;
|
|
|
|
gsize n_samplers;
|
|
|
|
gsize n_immutable_samplers;
|
|
|
|
VkSampler *immutable_samplers;
|
|
|
|
};
|
2023-08-21 00:18:37 +00:00
|
|
|
|
2023-10-19 05:43:31 +00:00
|
|
|
struct _GskVulkanPipelineLayout
|
|
|
|
{
|
|
|
|
gint ref_count;
|
|
|
|
|
2023-11-03 00:59:24 +00:00
|
|
|
VkDescriptorSetLayout vk_buffer_set_layout;
|
2023-10-19 05:43:31 +00:00
|
|
|
VkDescriptorSetLayout vk_image_set_layout;
|
|
|
|
VkPipelineLayout vk_pipeline_layout;
|
|
|
|
GHashTable *pipeline_cache;
|
|
|
|
|
2023-11-03 00:59:24 +00:00
|
|
|
GskVulkanPipelineLayoutSetup setup;
|
2023-10-19 05:43:31 +00:00
|
|
|
VkSampler samplers[];
|
|
|
|
};
|
|
|
|
|
2023-10-18 07:33:15 +00:00
|
|
|
struct _ConversionCacheEntry
|
|
|
|
{
|
|
|
|
VkFormat vk_format;
|
|
|
|
|
|
|
|
/* actual data */
|
|
|
|
VkSamplerYcbcrConversion vk_conversion;
|
|
|
|
VkSampler vk_sampler;
|
|
|
|
};
|
|
|
|
|
2023-08-21 00:18:37 +00:00
|
|
|
struct _PipelineCacheKey
|
|
|
|
{
|
|
|
|
const GskGpuShaderOpClass *op_class;
|
2023-12-31 04:38:56 +00:00
|
|
|
guint32 variation;
|
2023-08-21 00:18:37 +00:00
|
|
|
GskGpuShaderClip clip;
|
2023-12-25 04:21:13 +00:00
|
|
|
GskGpuBlend blend;
|
2023-08-21 00:18:37 +00:00
|
|
|
VkFormat format;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _RenderPassCacheKey
|
|
|
|
{
|
|
|
|
VkFormat format;
|
|
|
|
VkImageLayout from_layout;
|
|
|
|
VkImageLayout to_layout;
|
|
|
|
};
|
|
|
|
|
2023-10-18 07:33:15 +00:00
|
|
|
static guint
|
|
|
|
conversion_cache_entry_hash (gconstpointer data)
|
|
|
|
{
|
|
|
|
const ConversionCacheEntry *key = data;
|
|
|
|
|
|
|
|
return key->vk_format;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
conversion_cache_entry_equal (gconstpointer a,
|
|
|
|
gconstpointer b)
|
|
|
|
{
|
|
|
|
const ConversionCacheEntry *keya = a;
|
|
|
|
const ConversionCacheEntry *keyb = b;
|
|
|
|
|
|
|
|
return keya->vk_format == keyb->vk_format;
|
|
|
|
}
|
|
|
|
|
2023-08-21 00:18:37 +00:00
|
|
|
static guint
|
|
|
|
pipeline_cache_key_hash (gconstpointer data)
|
|
|
|
{
|
|
|
|
const PipelineCacheKey *key = data;
|
|
|
|
|
|
|
|
return GPOINTER_TO_UINT (key->op_class) ^
|
|
|
|
key->clip ^
|
2023-12-31 04:38:56 +00:00
|
|
|
(key->variation << 2) ^
|
|
|
|
(key->blend << 6) ^
|
|
|
|
(key->format << 8);
|
2023-08-21 00:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
pipeline_cache_key_equal (gconstpointer a,
|
|
|
|
gconstpointer b)
|
|
|
|
{
|
|
|
|
const PipelineCacheKey *keya = a;
|
|
|
|
const PipelineCacheKey *keyb = b;
|
|
|
|
|
|
|
|
return keya->op_class == keyb->op_class &&
|
2023-12-31 04:38:56 +00:00
|
|
|
keya->variation == keyb->variation &&
|
2023-08-21 00:18:37 +00:00
|
|
|
keya->clip == keyb->clip &&
|
2023-12-25 04:21:13 +00:00
|
|
|
keya->blend == keyb->blend &&
|
2023-08-21 00:18:37 +00:00
|
|
|
keya->format == keyb->format;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
render_pass_cache_key_hash (gconstpointer data)
|
|
|
|
{
|
|
|
|
const RenderPassCacheKey *key = data;
|
|
|
|
|
|
|
|
return (key->from_layout << 20) ^
|
|
|
|
(key->to_layout << 16) ^
|
|
|
|
(key->format);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
render_pass_cache_key_equal (gconstpointer a,
|
|
|
|
gconstpointer b)
|
|
|
|
{
|
|
|
|
const RenderPassCacheKey *keya = a;
|
|
|
|
const RenderPassCacheKey *keyb = b;
|
|
|
|
|
|
|
|
return keya->from_layout == keyb->from_layout &&
|
|
|
|
keya->to_layout == keyb->to_layout &&
|
|
|
|
keya->format == keyb->format;
|
|
|
|
}
|
|
|
|
|
2023-10-19 05:43:31 +00:00
|
|
|
static GskVulkanPipelineLayout *
|
2023-11-03 00:59:24 +00:00
|
|
|
gsk_vulkan_pipeline_layout_new (GskVulkanDevice *self,
|
|
|
|
const GskVulkanPipelineLayoutSetup *setup)
|
2023-10-19 05:43:31 +00:00
|
|
|
{
|
|
|
|
GskVulkanPipelineLayout *layout;
|
|
|
|
GdkDisplay *display;
|
2023-11-04 18:38:21 +00:00
|
|
|
gboolean descriptor_indexing;
|
|
|
|
|
|
|
|
descriptor_indexing = gsk_vulkan_device_has_feature (self, GDK_VULKAN_FEATURE_DESCRIPTOR_INDEXING);
|
2023-10-19 05:43:31 +00:00
|
|
|
|
2023-11-03 00:59:24 +00:00
|
|
|
layout = g_malloc (sizeof (GskVulkanPipelineLayout) + setup->n_immutable_samplers * sizeof (VkSampler));
|
2023-10-19 05:43:31 +00:00
|
|
|
layout->ref_count = 1;
|
|
|
|
|
2023-11-03 00:59:24 +00:00
|
|
|
layout->setup = *setup;
|
2023-11-06 04:04:36 +00:00
|
|
|
if (setup->n_immutable_samplers)
|
|
|
|
memcpy (layout->samplers, setup->immutable_samplers, setup->n_immutable_samplers * sizeof (VkSampler));
|
2023-11-03 00:59:24 +00:00
|
|
|
layout->setup.immutable_samplers = layout->samplers;
|
2023-10-19 05:43:31 +00:00
|
|
|
layout->pipeline_cache = g_hash_table_new (pipeline_cache_key_hash, pipeline_cache_key_equal);
|
|
|
|
|
|
|
|
display = gsk_gpu_device_get_display (GSK_GPU_DEVICE (self));
|
|
|
|
|
|
|
|
GSK_VK_CHECK (vkCreateDescriptorSetLayout, display->vk_device,
|
|
|
|
&(VkDescriptorSetLayoutCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
|
|
|
.bindingCount = 2,
|
2023-11-04 05:14:45 +00:00
|
|
|
.flags = 0,
|
2023-10-19 05:43:31 +00:00
|
|
|
.pBindings = (VkDescriptorSetLayoutBinding[2]) {
|
|
|
|
{
|
|
|
|
.binding = 0,
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
2023-11-06 04:04:36 +00:00
|
|
|
.descriptorCount = MAX (1, layout->setup.n_immutable_samplers),
|
2023-10-19 05:43:31 +00:00
|
|
|
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
|
2023-11-06 04:04:36 +00:00
|
|
|
.pImmutableSamplers = layout->setup.n_immutable_samplers
|
|
|
|
? layout->setup.immutable_samplers
|
|
|
|
: (VkSampler[1]) {
|
|
|
|
gsk_vulkan_device_get_vk_sampler (self, GSK_GPU_SAMPLER_DEFAULT)
|
|
|
|
},
|
2023-10-19 05:43:31 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.binding = 1,
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
2023-11-03 00:59:24 +00:00
|
|
|
.descriptorCount = layout->setup.n_samplers,
|
2023-10-19 05:43:31 +00:00
|
|
|
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT
|
|
|
|
}
|
|
|
|
},
|
2023-11-04 18:38:21 +00:00
|
|
|
.pNext = !descriptor_indexing ? NULL : &(VkDescriptorSetLayoutBindingFlagsCreateInfo) {
|
2023-10-19 05:43:31 +00:00
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO,
|
|
|
|
.bindingCount = 2,
|
|
|
|
.pBindingFlags = (VkDescriptorBindingFlags[2]) {
|
2023-11-04 05:14:45 +00:00
|
|
|
VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT,
|
2023-10-19 05:43:31 +00:00
|
|
|
VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT
|
2023-11-04 05:14:45 +00:00
|
|
|
| VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT,
|
2023-10-19 05:43:31 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&layout->vk_image_set_layout);
|
|
|
|
|
2023-11-03 00:59:24 +00:00
|
|
|
GSK_VK_CHECK (vkCreateDescriptorSetLayout, display->vk_device,
|
|
|
|
&(VkDescriptorSetLayoutCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
|
|
|
.bindingCount = 1,
|
2023-11-04 05:14:45 +00:00
|
|
|
.flags = 0,
|
2023-11-03 00:59:24 +00:00
|
|
|
.pBindings = (VkDescriptorSetLayoutBinding[1]) {
|
|
|
|
{
|
|
|
|
.binding = 0,
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
|
|
|
.descriptorCount = layout->setup.n_buffers,
|
|
|
|
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT
|
|
|
|
},
|
|
|
|
},
|
2023-11-04 18:38:21 +00:00
|
|
|
.pNext = !descriptor_indexing ? NULL : &(VkDescriptorSetLayoutBindingFlagsCreateInfo) {
|
2023-11-03 00:59:24 +00:00
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO,
|
|
|
|
.bindingCount = 1,
|
|
|
|
.pBindingFlags = (VkDescriptorBindingFlags[1]) {
|
|
|
|
VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT
|
2023-11-04 05:14:45 +00:00
|
|
|
| VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT,
|
2023-11-03 00:59:24 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&layout->vk_buffer_set_layout);
|
|
|
|
|
2023-10-19 05:43:31 +00:00
|
|
|
GSK_VK_CHECK (vkCreatePipelineLayout, display->vk_device,
|
|
|
|
&(VkPipelineLayoutCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
|
|
|
.setLayoutCount = 2,
|
|
|
|
.pSetLayouts = (VkDescriptorSetLayout[2]) {
|
|
|
|
layout->vk_image_set_layout,
|
2023-11-03 00:59:24 +00:00
|
|
|
layout->vk_buffer_set_layout,
|
2023-10-19 05:43:31 +00:00
|
|
|
},
|
|
|
|
.pushConstantRangeCount = 1,
|
|
|
|
.pPushConstantRanges = (VkPushConstantRange[1]) {
|
|
|
|
{
|
|
|
|
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
|
|
|
|
.offset = 0,
|
|
|
|
.size = sizeof (GskGpuGlobalsInstance)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&layout->vk_pipeline_layout);
|
|
|
|
|
2023-11-03 00:59:24 +00:00
|
|
|
g_hash_table_insert (self->pipeline_layouts, &layout->setup, layout);
|
2023-10-19 05:43:31 +00:00
|
|
|
|
|
|
|
return layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_pipeline_layout_unref (GskVulkanDevice *self,
|
|
|
|
GskVulkanPipelineLayout *layout)
|
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
|
|
|
|
|
|
|
layout->ref_count--;
|
|
|
|
if (layout->ref_count)
|
|
|
|
return;
|
|
|
|
|
2023-11-03 00:59:24 +00:00
|
|
|
if (!g_hash_table_remove (self->pipeline_layouts, &layout->setup))
|
2023-10-19 05:43:31 +00:00
|
|
|
{
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
display = gsk_gpu_device_get_display (GSK_GPU_DEVICE (self));
|
|
|
|
|
|
|
|
vkDestroyDescriptorSetLayout (display->vk_device,
|
|
|
|
layout->vk_image_set_layout,
|
|
|
|
NULL);
|
2023-11-03 00:59:24 +00:00
|
|
|
vkDestroyDescriptorSetLayout (display->vk_device,
|
|
|
|
layout->vk_buffer_set_layout,
|
|
|
|
NULL);
|
2023-10-19 05:43:31 +00:00
|
|
|
|
|
|
|
vkDestroyPipelineLayout (display->vk_device,
|
|
|
|
layout->vk_pipeline_layout,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, layout->pipeline_cache);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
|
|
|
g_free (key);
|
|
|
|
vkDestroyPipeline (display->vk_device, value, NULL);
|
|
|
|
}
|
|
|
|
g_hash_table_unref (layout->pipeline_cache);
|
|
|
|
|
|
|
|
g_free (layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_pipeline_layout_ref (GskVulkanDevice *self,
|
|
|
|
GskVulkanPipelineLayout *layout)
|
|
|
|
{
|
|
|
|
layout->ref_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
2023-11-03 00:59:24 +00:00
|
|
|
gsk_vulkan_pipeline_layout_setup_hash (gconstpointer data)
|
2023-10-19 05:43:31 +00:00
|
|
|
{
|
2023-11-03 00:59:24 +00:00
|
|
|
const GskVulkanPipelineLayoutSetup *setup = data;
|
|
|
|
guint result;
|
|
|
|
gsize i;
|
2023-10-19 05:43:31 +00:00
|
|
|
|
2023-11-03 00:59:24 +00:00
|
|
|
result = (setup->n_buffers << 23) |
|
|
|
|
(setup->n_samplers << 7) |
|
|
|
|
setup->n_immutable_samplers;
|
|
|
|
|
|
|
|
for (i = 0; i < setup->n_immutable_samplers; i++)
|
2023-10-19 05:43:31 +00:00
|
|
|
{
|
|
|
|
result = (result << 13) ^
|
2023-11-03 00:59:24 +00:00
|
|
|
GPOINTER_TO_SIZE (setup->immutable_samplers[i]) ^
|
|
|
|
(GPOINTER_TO_SIZE (setup->immutable_samplers[i]) >> 32);
|
2023-10-19 05:43:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2023-11-03 00:59:24 +00:00
|
|
|
gsk_vulkan_pipeline_layout_setup_equal (gconstpointer a,
|
|
|
|
gconstpointer b)
|
2023-10-19 05:43:31 +00:00
|
|
|
{
|
2023-11-03 00:59:24 +00:00
|
|
|
const GskVulkanPipelineLayoutSetup *setupa = a;
|
|
|
|
const GskVulkanPipelineLayoutSetup *setupb = b;
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
if (setupa->n_buffers != setupb->n_buffers ||
|
|
|
|
setupa->n_samplers != setupb->n_samplers ||
|
|
|
|
setupa->n_immutable_samplers != setupb->n_immutable_samplers)
|
|
|
|
return FALSE;
|
2023-10-19 05:43:31 +00:00
|
|
|
|
2023-11-03 00:59:24 +00:00
|
|
|
for (i = 0; i < setupa->n_immutable_samplers; i++)
|
2023-10-19 05:43:31 +00:00
|
|
|
{
|
2023-11-03 00:59:24 +00:00
|
|
|
if (setupa->immutable_samplers[i] != setupb->immutable_samplers[i])
|
2023-10-19 05:43:31 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2023-11-03 00:59:24 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2023-10-19 05:43:31 +00:00
|
|
|
}
|
|
|
|
|
2023-11-01 05:43:15 +00:00
|
|
|
static GskGpuImage *
|
|
|
|
gsk_vulkan_device_create_offscreen_image (GskGpuDevice *device,
|
|
|
|
gboolean with_mipmap,
|
|
|
|
GdkMemoryDepth depth,
|
|
|
|
gsize width,
|
|
|
|
gsize height)
|
|
|
|
{
|
|
|
|
GskVulkanDevice *self = GSK_VULKAN_DEVICE (device);
|
|
|
|
|
|
|
|
return gsk_vulkan_image_new_for_offscreen (self,
|
|
|
|
with_mipmap,
|
|
|
|
gdk_memory_depth_get_format (depth),
|
|
|
|
width,
|
|
|
|
height);
|
|
|
|
}
|
|
|
|
|
2023-09-25 19:12:20 +00:00
|
|
|
static GskGpuImage *
|
|
|
|
gsk_vulkan_device_create_atlas_image (GskGpuDevice *device,
|
|
|
|
gsize width,
|
|
|
|
gsize height)
|
|
|
|
{
|
|
|
|
GskVulkanDevice *self = GSK_VULKAN_DEVICE (device);
|
|
|
|
|
|
|
|
return gsk_vulkan_image_new_for_atlas (self,
|
|
|
|
width,
|
|
|
|
height);
|
|
|
|
}
|
|
|
|
|
2023-08-12 20:10:16 +00:00
|
|
|
static GskGpuImage *
|
|
|
|
gsk_vulkan_device_create_upload_image (GskGpuDevice *device,
|
2023-11-01 05:43:15 +00:00
|
|
|
gboolean with_mipmap,
|
2023-08-12 20:10:16 +00:00
|
|
|
GdkMemoryFormat format,
|
|
|
|
gsize width,
|
|
|
|
gsize height)
|
|
|
|
{
|
|
|
|
GskVulkanDevice *self = GSK_VULKAN_DEVICE (device);
|
|
|
|
|
|
|
|
return gsk_vulkan_image_new_for_upload (self,
|
2023-11-01 05:43:15 +00:00
|
|
|
with_mipmap,
|
2023-08-12 20:10:16 +00:00
|
|
|
format,
|
|
|
|
width,
|
|
|
|
height);
|
|
|
|
}
|
|
|
|
|
2023-11-24 00:27:44 +00:00
|
|
|
static GskGpuImage *
|
|
|
|
gsk_vulkan_device_create_download_image (GskGpuDevice *device,
|
|
|
|
GdkMemoryDepth depth,
|
|
|
|
gsize width,
|
|
|
|
gsize height)
|
|
|
|
{
|
|
|
|
GskVulkanDevice *self = GSK_VULKAN_DEVICE (device);
|
|
|
|
GskGpuImage *image;
|
|
|
|
|
2023-11-24 06:10:34 +00:00
|
|
|
#ifdef HAVE_DMABUF
|
|
|
|
image = gsk_vulkan_image_new_dmabuf (self,
|
|
|
|
gdk_memory_depth_get_format (depth),
|
|
|
|
width,
|
|
|
|
height);
|
|
|
|
if (image != NULL)
|
|
|
|
return image;
|
|
|
|
#endif
|
|
|
|
|
2023-11-24 00:27:44 +00:00
|
|
|
image = gsk_vulkan_image_new_for_offscreen (self,
|
|
|
|
FALSE,
|
|
|
|
gdk_memory_depth_get_format (depth),
|
|
|
|
width,
|
|
|
|
height);
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2024-01-29 12:38:25 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_device_make_current (GskGpuDevice *device)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-08-12 20:10:16 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_device_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GskVulkanDevice *self = GSK_VULKAN_DEVICE (object);
|
|
|
|
GskGpuDevice *device = GSK_GPU_DEVICE (self);
|
|
|
|
GdkDisplay *display;
|
2023-08-21 00:18:37 +00:00
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
2023-08-12 20:10:16 +00:00
|
|
|
gsize i;
|
|
|
|
|
|
|
|
g_object_steal_data (G_OBJECT (gsk_gpu_device_get_display (device)), "-gsk-vulkan-device");
|
|
|
|
|
|
|
|
display = gsk_gpu_device_get_display (device);
|
|
|
|
|
2023-10-19 05:43:31 +00:00
|
|
|
if (self->pipeline_layout_cache)
|
|
|
|
gsk_vulkan_pipeline_layout_unref (self, self->pipeline_layout_cache);
|
|
|
|
g_assert (g_hash_table_size (self->pipeline_layouts) == 0);
|
|
|
|
g_hash_table_unref (self->pipeline_layouts);
|
|
|
|
|
2023-10-18 07:33:15 +00:00
|
|
|
g_hash_table_iter_init (&iter, self->conversion_cache);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
|
|
|
ConversionCacheEntry *entry = key;
|
|
|
|
vkDestroySamplerYcbcrConversion (display->vk_device, entry->vk_conversion, NULL);
|
|
|
|
vkDestroySampler (display->vk_device, entry->vk_sampler, NULL);
|
|
|
|
g_free (key);
|
|
|
|
}
|
|
|
|
g_hash_table_unref (self->conversion_cache);
|
|
|
|
|
2023-08-21 00:18:37 +00:00
|
|
|
g_hash_table_iter_init (&iter, self->render_pass_cache);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
|
|
|
g_free (key);
|
|
|
|
vkDestroyRenderPass (display->vk_device, value, NULL);
|
|
|
|
}
|
|
|
|
g_hash_table_unref (self->render_pass_cache);
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (self->vk_samplers); i++)
|
|
|
|
{
|
2023-10-17 06:43:18 +00:00
|
|
|
if (self->vk_samplers[i] != VK_NULL_HANDLE)
|
|
|
|
vkDestroySampler (display->vk_device,
|
|
|
|
self->vk_samplers[i],
|
|
|
|
NULL);
|
2023-08-21 00:18:37 +00:00
|
|
|
}
|
|
|
|
|
2023-08-12 20:10:16 +00:00
|
|
|
vkDestroyCommandPool (display->vk_device,
|
|
|
|
self->vk_command_pool,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
for (i = 0; i < VK_MAX_MEMORY_TYPES; i++)
|
|
|
|
g_clear_pointer (&self->allocators[i], gsk_vulkan_allocator_unref);
|
2023-10-19 08:58:06 +00:00
|
|
|
g_clear_pointer (&self->external_allocator, gsk_vulkan_allocator_unref);
|
2023-08-12 20:10:16 +00:00
|
|
|
|
|
|
|
gdk_display_unref_vulkan (display);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gsk_vulkan_device_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_device_class_init (GskVulkanDeviceClass *klass)
|
|
|
|
{
|
|
|
|
GskGpuDeviceClass *gpu_device_class = GSK_GPU_DEVICE_CLASS (klass);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gpu_device_class->create_offscreen_image = gsk_vulkan_device_create_offscreen_image;
|
2023-09-25 19:12:20 +00:00
|
|
|
gpu_device_class->create_atlas_image = gsk_vulkan_device_create_atlas_image;
|
2023-08-12 20:10:16 +00:00
|
|
|
gpu_device_class->create_upload_image = gsk_vulkan_device_create_upload_image;
|
2023-11-24 00:27:44 +00:00
|
|
|
gpu_device_class->create_download_image = gsk_vulkan_device_create_download_image;
|
2024-01-29 12:38:25 +00:00
|
|
|
gpu_device_class->make_current = gsk_vulkan_device_make_current;
|
2023-08-12 20:10:16 +00:00
|
|
|
|
|
|
|
object_class->finalize = gsk_vulkan_device_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_device_init (GskVulkanDevice *self)
|
|
|
|
{
|
2023-10-18 07:33:15 +00:00
|
|
|
self->conversion_cache = g_hash_table_new (conversion_cache_entry_hash, conversion_cache_entry_equal);
|
2023-08-21 00:18:37 +00:00
|
|
|
self->render_pass_cache = g_hash_table_new (render_pass_cache_key_hash, render_pass_cache_key_equal);
|
2023-11-03 00:59:24 +00:00
|
|
|
self->pipeline_layouts = g_hash_table_new (gsk_vulkan_pipeline_layout_setup_hash, gsk_vulkan_pipeline_layout_setup_equal);
|
2023-08-12 20:10:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-11-03 01:48:06 +00:00
|
|
|
gsk_vulkan_device_create_vk_objects (GskVulkanDevice *self)
|
2023-08-12 20:10:16 +00:00
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
|
|
|
display = gsk_gpu_device_get_display (GSK_GPU_DEVICE (self));
|
|
|
|
|
|
|
|
GSK_VK_CHECK (vkCreateCommandPool, display->vk_device,
|
|
|
|
&(const VkCommandPoolCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
|
|
|
.queueFamilyIndex = display->vk_queue_family_index,
|
|
|
|
.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&self->vk_command_pool);
|
|
|
|
}
|
|
|
|
|
2023-11-03 01:48:06 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_device_setup (GskVulkanDevice *self,
|
|
|
|
GdkDisplay *display)
|
|
|
|
{
|
|
|
|
VkPhysicalDeviceVulkan12Properties vk12_props = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES,
|
|
|
|
};
|
|
|
|
VkPhysicalDeviceProperties2 vk_props = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
|
|
|
|
.pNext = &vk12_props
|
|
|
|
};
|
|
|
|
|
|
|
|
vkGetPhysicalDeviceProperties2 (display->vk_physical_device, &vk_props);
|
2023-11-06 03:08:22 +00:00
|
|
|
if (gsk_vulkan_device_has_feature (self, GDK_VULKAN_FEATURE_DESCRIPTOR_INDEXING))
|
2023-11-03 01:48:06 +00:00
|
|
|
{
|
|
|
|
self->max_buffers = vk12_props.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
|
|
|
|
self->max_samplers = vk12_props.maxPerStageDescriptorUpdateAfterBindSampledImages;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self->max_buffers = vk_props.properties.limits.maxPerStageDescriptorUniformBuffers;
|
|
|
|
self->max_samplers = vk_props.properties.limits.maxPerStageDescriptorSampledImages;
|
|
|
|
}
|
2023-11-06 03:08:22 +00:00
|
|
|
if (!gsk_vulkan_device_has_feature (self, GDK_VULKAN_FEATURE_DYNAMIC_INDEXING) ||
|
|
|
|
!gsk_vulkan_device_has_feature (self, GDK_VULKAN_FEATURE_NONUNIFORM_INDEXING))
|
|
|
|
{
|
|
|
|
/* These numbers can be improved in the shader sources by adding more
|
|
|
|
* entries to the big if() ladders */
|
|
|
|
self->max_buffers = MIN (self->max_buffers, 32);
|
|
|
|
self->max_samplers = MIN (self->max_samplers, 32);
|
|
|
|
}
|
2023-11-06 04:04:36 +00:00
|
|
|
self->max_immutable_samplers = MIN (self->max_samplers / 3, 32);
|
2023-11-03 01:48:06 +00:00
|
|
|
gsk_gpu_device_setup (GSK_GPU_DEVICE (self),
|
|
|
|
display,
|
|
|
|
vk_props.properties.limits.maxImageDimension2D);
|
|
|
|
}
|
|
|
|
|
2023-08-12 20:10:16 +00:00
|
|
|
GskGpuDevice *
|
|
|
|
gsk_vulkan_device_get_for_display (GdkDisplay *display,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GskVulkanDevice *self;
|
|
|
|
|
|
|
|
self = g_object_get_data (G_OBJECT (display), "-gsk-vulkan-device");
|
|
|
|
if (self)
|
|
|
|
return GSK_GPU_DEVICE (g_object_ref (self));
|
|
|
|
|
|
|
|
if (!gdk_display_init_vulkan (display, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
self = g_object_new (GSK_TYPE_VULKAN_DEVICE, NULL);
|
2023-10-19 10:54:14 +00:00
|
|
|
self->features = display->vulkan_features;
|
2023-08-12 20:10:16 +00:00
|
|
|
|
2023-11-03 01:48:06 +00:00
|
|
|
gsk_vulkan_device_setup (self, display);
|
|
|
|
|
|
|
|
gsk_vulkan_device_create_vk_objects (self);
|
2023-08-12 20:10:16 +00:00
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (display), "-gsk-vulkan-device", self);
|
|
|
|
|
|
|
|
return GSK_GPU_DEVICE (self);
|
|
|
|
}
|
|
|
|
|
2023-08-21 00:18:37 +00:00
|
|
|
gsize
|
2023-11-03 01:48:06 +00:00
|
|
|
gsk_vulkan_device_get_max_immutable_samplers (GskVulkanDevice *self)
|
|
|
|
{
|
|
|
|
return self->max_immutable_samplers;
|
|
|
|
}
|
|
|
|
|
|
|
|
gsize
|
|
|
|
gsk_vulkan_device_get_max_samplers (GskVulkanDevice *self)
|
|
|
|
{
|
|
|
|
return self->max_samplers;
|
|
|
|
}
|
|
|
|
|
|
|
|
gsize
|
|
|
|
gsk_vulkan_device_get_max_buffers (GskVulkanDevice *self)
|
2023-08-21 00:18:37 +00:00
|
|
|
{
|
2023-11-03 01:48:06 +00:00
|
|
|
return self->max_buffers;
|
2023-08-21 00:18:37 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:54:14 +00:00
|
|
|
gboolean
|
|
|
|
gsk_vulkan_device_has_feature (GskVulkanDevice *self,
|
|
|
|
GdkVulkanFeatures feature)
|
|
|
|
{
|
|
|
|
return (self->features & feature) == feature;
|
|
|
|
}
|
|
|
|
|
2023-08-12 20:10:16 +00:00
|
|
|
VkDevice
|
|
|
|
gsk_vulkan_device_get_vk_device (GskVulkanDevice *self)
|
|
|
|
{
|
|
|
|
return gsk_gpu_device_get_display (GSK_GPU_DEVICE (self))->vk_device;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkPhysicalDevice
|
|
|
|
gsk_vulkan_device_get_vk_physical_device (GskVulkanDevice *self)
|
|
|
|
{
|
|
|
|
return gsk_gpu_device_get_display (GSK_GPU_DEVICE (self))->vk_physical_device;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkQueue
|
|
|
|
gsk_vulkan_device_get_vk_queue (GskVulkanDevice *self)
|
|
|
|
{
|
|
|
|
return gsk_gpu_device_get_display (GSK_GPU_DEVICE (self))->vk_queue;
|
|
|
|
}
|
|
|
|
|
2023-10-19 11:36:15 +00:00
|
|
|
uint32_t
|
|
|
|
gsk_vulkan_device_get_vk_queue_family_index (GskVulkanDevice *self)
|
|
|
|
{
|
|
|
|
return gsk_gpu_device_get_display (GSK_GPU_DEVICE (self))->vk_queue_family_index;
|
|
|
|
}
|
|
|
|
|
2023-08-21 00:18:37 +00:00
|
|
|
VkDescriptorSetLayout
|
2023-10-19 05:43:31 +00:00
|
|
|
gsk_vulkan_device_get_vk_image_set_layout (GskVulkanDevice *self,
|
|
|
|
GskVulkanPipelineLayout *layout)
|
2023-08-21 00:18:37 +00:00
|
|
|
{
|
2023-10-19 05:43:31 +00:00
|
|
|
return layout->vk_image_set_layout;
|
2023-08-21 00:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VkDescriptorSetLayout
|
2023-11-03 00:59:24 +00:00
|
|
|
gsk_vulkan_device_get_vk_buffer_set_layout (GskVulkanDevice *self,
|
|
|
|
GskVulkanPipelineLayout *layout)
|
2023-08-21 00:18:37 +00:00
|
|
|
{
|
2023-11-03 00:59:24 +00:00
|
|
|
return layout->vk_buffer_set_layout;
|
2023-08-21 00:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VkPipelineLayout
|
2023-10-19 05:43:31 +00:00
|
|
|
gsk_vulkan_device_get_vk_pipeline_layout (GskVulkanDevice *self,
|
|
|
|
GskVulkanPipelineLayout *layout)
|
2023-08-21 00:18:37 +00:00
|
|
|
{
|
2023-10-19 05:43:31 +00:00
|
|
|
return layout->vk_pipeline_layout;
|
2023-08-21 00:18:37 +00:00
|
|
|
}
|
|
|
|
|
2023-08-12 20:10:16 +00:00
|
|
|
VkCommandPool
|
|
|
|
gsk_vulkan_device_get_vk_command_pool (GskVulkanDevice *self)
|
|
|
|
{
|
|
|
|
return self->vk_command_pool;
|
|
|
|
}
|
|
|
|
|
2023-10-17 06:43:18 +00:00
|
|
|
static VkSampler
|
2023-10-18 07:33:15 +00:00
|
|
|
gsk_vulkan_device_create_sampler (GskVulkanDevice *self,
|
|
|
|
VkSamplerYcbcrConversion vk_conversion,
|
|
|
|
VkFilter vk_filter,
|
2023-10-30 23:15:47 +00:00
|
|
|
VkSamplerAddressMode vk_address_mode,
|
|
|
|
VkSamplerMipmapMode vk_mipmap_mode,
|
|
|
|
float max_lod)
|
2023-10-17 06:43:18 +00:00
|
|
|
{
|
|
|
|
VkSampler result;
|
|
|
|
|
|
|
|
GSK_VK_CHECK (vkCreateSampler, gsk_vulkan_device_get_vk_device (self),
|
|
|
|
&(VkSamplerCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
|
|
|
.magFilter = vk_filter,
|
|
|
|
.minFilter = vk_filter,
|
2023-10-30 23:15:47 +00:00
|
|
|
.mipmapMode = vk_mipmap_mode,
|
2023-10-17 06:43:18 +00:00
|
|
|
.addressModeU = vk_address_mode,
|
|
|
|
.addressModeV = vk_address_mode,
|
2023-10-18 07:33:15 +00:00
|
|
|
.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
2023-10-17 06:43:18 +00:00
|
|
|
.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,
|
|
|
|
.unnormalizedCoordinates = VK_FALSE,
|
|
|
|
.maxAnisotropy = 1.0,
|
2023-10-30 23:15:47 +00:00
|
|
|
.minLod = 0.0,
|
|
|
|
.maxLod = max_lod,
|
2023-10-18 07:33:15 +00:00
|
|
|
.pNext = vk_conversion == VK_NULL_HANDLE ? NULL : &(VkSamplerYcbcrConversionInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO,
|
|
|
|
.conversion = vk_conversion
|
|
|
|
}
|
2023-10-17 06:43:18 +00:00
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-08-21 00:18:37 +00:00
|
|
|
VkSampler
|
2023-10-17 06:43:18 +00:00
|
|
|
gsk_vulkan_device_get_vk_sampler (GskVulkanDevice *self,
|
|
|
|
GskGpuSampler sampler)
|
2023-08-21 00:18:37 +00:00
|
|
|
{
|
2023-10-17 06:43:18 +00:00
|
|
|
const struct {
|
|
|
|
VkFilter filter;
|
|
|
|
VkSamplerAddressMode address_mode;
|
2023-10-30 23:15:47 +00:00
|
|
|
VkSamplerMipmapMode mipmap_mode;
|
|
|
|
float max_lod;
|
2023-10-17 06:43:18 +00:00
|
|
|
} filter_attrs[GSK_GPU_SAMPLER_N_SAMPLERS] = {
|
|
|
|
[GSK_GPU_SAMPLER_DEFAULT] = {
|
|
|
|
.filter = VK_FILTER_LINEAR,
|
|
|
|
.address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
2023-10-30 23:15:47 +00:00
|
|
|
.mipmap_mode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
|
|
|
.max_lod = 0.0f,
|
2023-10-17 06:43:18 +00:00
|
|
|
},
|
|
|
|
[GSK_GPU_SAMPLER_TRANSPARENT] = {
|
|
|
|
.filter = VK_FILTER_LINEAR,
|
|
|
|
.address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
2023-10-30 23:15:47 +00:00
|
|
|
.mipmap_mode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
|
|
|
.max_lod = 0.0f,
|
2023-10-17 06:43:18 +00:00
|
|
|
},
|
|
|
|
[GSK_GPU_SAMPLER_REPEAT] = {
|
|
|
|
.filter = VK_FILTER_LINEAR,
|
|
|
|
.address_mode = VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
2023-10-30 23:15:47 +00:00
|
|
|
.mipmap_mode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
|
|
|
.max_lod = 0.0f,
|
2023-10-17 06:43:18 +00:00
|
|
|
},
|
|
|
|
[GSK_GPU_SAMPLER_NEAREST] = {
|
|
|
|
.filter = VK_FILTER_NEAREST,
|
|
|
|
.address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
2023-10-30 23:15:47 +00:00
|
|
|
.mipmap_mode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
|
|
|
.max_lod = 0.0f,
|
|
|
|
},
|
|
|
|
[GSK_GPU_SAMPLER_MIPMAP_DEFAULT] = {
|
|
|
|
.filter = VK_FILTER_LINEAR,
|
|
|
|
.address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
|
|
|
.mipmap_mode = VK_SAMPLER_MIPMAP_MODE_LINEAR,
|
|
|
|
.max_lod = VK_LOD_CLAMP_NONE,
|
2023-10-17 06:43:18 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (self->vk_samplers[sampler] == VK_NULL_HANDLE)
|
|
|
|
{
|
|
|
|
self->vk_samplers[sampler] = gsk_vulkan_device_create_sampler (self,
|
2023-10-18 07:33:15 +00:00
|
|
|
VK_NULL_HANDLE,
|
2023-10-17 06:43:18 +00:00
|
|
|
filter_attrs[sampler].filter,
|
2023-10-30 23:15:47 +00:00
|
|
|
filter_attrs[sampler].address_mode,
|
|
|
|
filter_attrs[sampler].mipmap_mode,
|
|
|
|
filter_attrs[sampler].max_lod);
|
2023-10-17 06:43:18 +00:00
|
|
|
}
|
|
|
|
|
2023-08-21 00:18:37 +00:00
|
|
|
return self->vk_samplers[sampler];
|
|
|
|
}
|
|
|
|
|
2023-10-18 07:33:15 +00:00
|
|
|
VkSamplerYcbcrConversion
|
|
|
|
gsk_vulkan_device_get_vk_conversion (GskVulkanDevice *self,
|
|
|
|
VkFormat vk_format,
|
|
|
|
VkSampler *out_sampler)
|
|
|
|
{
|
|
|
|
ConversionCacheEntry lookup;
|
|
|
|
ConversionCacheEntry *entry;
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
|
|
|
lookup = (ConversionCacheEntry) {
|
|
|
|
.vk_format = vk_format,
|
|
|
|
};
|
|
|
|
entry = g_hash_table_lookup (self->conversion_cache, &lookup);
|
|
|
|
if (entry)
|
|
|
|
{
|
|
|
|
if (out_sampler)
|
|
|
|
*out_sampler = entry->vk_sampler;
|
|
|
|
|
|
|
|
return entry->vk_conversion;
|
|
|
|
}
|
|
|
|
|
|
|
|
display = gsk_gpu_device_get_display (GSK_GPU_DEVICE (self));
|
|
|
|
|
|
|
|
entry = g_memdup (&lookup, sizeof (ConversionCacheEntry));
|
|
|
|
|
|
|
|
GSK_VK_CHECK (vkCreateSamplerYcbcrConversion, display->vk_device,
|
|
|
|
&(VkSamplerYcbcrConversionCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO,
|
|
|
|
.format = vk_format,
|
|
|
|
.ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601,
|
|
|
|
.ycbcrRange = VK_SAMPLER_YCBCR_RANGE_ITU_FULL,
|
|
|
|
.components = (VkComponentMapping) {
|
|
|
|
VK_COMPONENT_SWIZZLE_IDENTITY,
|
|
|
|
VK_COMPONENT_SWIZZLE_IDENTITY,
|
|
|
|
VK_COMPONENT_SWIZZLE_IDENTITY,
|
|
|
|
VK_COMPONENT_SWIZZLE_IDENTITY
|
|
|
|
},
|
|
|
|
.xChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN,
|
|
|
|
.yChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN,
|
|
|
|
.chromaFilter = VK_FILTER_LINEAR,
|
|
|
|
.forceExplicitReconstruction = VK_FALSE
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&entry->vk_conversion);
|
|
|
|
|
|
|
|
entry->vk_sampler = gsk_vulkan_device_create_sampler (self,
|
|
|
|
entry->vk_conversion,
|
|
|
|
VK_FILTER_LINEAR,
|
2023-10-30 23:15:47 +00:00
|
|
|
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
|
|
|
VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
|
|
|
0.0f);
|
2023-10-18 07:33:15 +00:00
|
|
|
|
|
|
|
g_hash_table_insert (self->conversion_cache, entry, entry);
|
|
|
|
|
|
|
|
if (out_sampler)
|
|
|
|
*out_sampler = entry->vk_sampler;
|
|
|
|
|
|
|
|
return entry->vk_conversion;
|
|
|
|
}
|
|
|
|
|
2023-08-21 00:18:37 +00:00
|
|
|
VkRenderPass
|
|
|
|
gsk_vulkan_device_get_vk_render_pass (GskVulkanDevice *self,
|
|
|
|
VkFormat format,
|
|
|
|
VkImageLayout from_layout,
|
|
|
|
VkImageLayout to_layout)
|
|
|
|
{
|
|
|
|
RenderPassCacheKey cache_key;
|
|
|
|
VkRenderPass render_pass;
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
|
|
|
cache_key = (RenderPassCacheKey) {
|
|
|
|
.format = format,
|
|
|
|
.from_layout = from_layout,
|
|
|
|
.to_layout = to_layout,
|
|
|
|
};
|
|
|
|
render_pass = g_hash_table_lookup (self->render_pass_cache, &cache_key);
|
|
|
|
if (render_pass)
|
|
|
|
return render_pass;
|
|
|
|
|
|
|
|
display = gsk_gpu_device_get_display (GSK_GPU_DEVICE (self));
|
|
|
|
|
|
|
|
GSK_VK_CHECK (vkCreateRenderPass, display->vk_device,
|
|
|
|
&(VkRenderPassCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
|
|
|
|
.attachmentCount = 1,
|
|
|
|
.pAttachments = (VkAttachmentDescription[]) {
|
|
|
|
{
|
|
|
|
.format = format,
|
|
|
|
.samples = VK_SAMPLE_COUNT_1_BIT,
|
|
|
|
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
|
|
|
|
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
|
|
|
.initialLayout = from_layout,
|
|
|
|
.finalLayout = to_layout
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.subpassCount = 1,
|
|
|
|
.pSubpasses = (VkSubpassDescription []) {
|
|
|
|
{
|
|
|
|
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
.inputAttachmentCount = 0,
|
|
|
|
.colorAttachmentCount = 1,
|
|
|
|
.pColorAttachments = (VkAttachmentReference []) {
|
|
|
|
{
|
|
|
|
.attachment = 0,
|
|
|
|
.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.pResolveAttachments = (VkAttachmentReference []) {
|
|
|
|
{
|
|
|
|
.attachment = VK_ATTACHMENT_UNUSED,
|
|
|
|
.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.pDepthStencilAttachment = NULL,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.dependencyCount = 0,
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&render_pass);
|
|
|
|
|
|
|
|
g_hash_table_insert (self->render_pass_cache, g_memdup (&cache_key, sizeof (RenderPassCacheKey)), render_pass);
|
|
|
|
|
|
|
|
return render_pass;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct _GskVulkanShaderSpecialization GskVulkanShaderSpecialization;
|
|
|
|
struct _GskVulkanShaderSpecialization
|
|
|
|
{
|
|
|
|
guint32 clip;
|
2023-10-19 06:00:37 +00:00
|
|
|
guint32 n_immutable_samplers;
|
2023-11-03 01:30:12 +00:00
|
|
|
guint32 n_samplers;
|
|
|
|
guint32 n_buffers;
|
2023-12-31 04:38:56 +00:00
|
|
|
guint32 variation;
|
2023-08-21 00:18:37 +00:00
|
|
|
};
|
|
|
|
|
2023-12-25 04:21:13 +00:00
|
|
|
static VkPipelineColorBlendAttachmentState blend_attachment_states[2] = {
|
|
|
|
[GSK_GPU_BLEND_OVER] = {
|
|
|
|
.blendEnable = VK_TRUE,
|
|
|
|
.colorBlendOp = VK_BLEND_OP_ADD,
|
|
|
|
.srcColorBlendFactor = VK_BLEND_FACTOR_ONE,
|
|
|
|
.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
|
|
|
.alphaBlendOp = VK_BLEND_OP_ADD,
|
|
|
|
.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE,
|
|
|
|
.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
|
|
|
.colorWriteMask = VK_COLOR_COMPONENT_A_BIT
|
|
|
|
| VK_COLOR_COMPONENT_R_BIT
|
|
|
|
| VK_COLOR_COMPONENT_G_BIT
|
|
|
|
| VK_COLOR_COMPONENT_B_BIT
|
|
|
|
},
|
|
|
|
[GSK_GPU_BLEND_ADD] = {
|
|
|
|
.blendEnable = VK_TRUE,
|
|
|
|
.colorBlendOp = VK_BLEND_OP_ADD,
|
|
|
|
.srcColorBlendFactor = VK_BLEND_FACTOR_ONE,
|
|
|
|
.dstColorBlendFactor = VK_BLEND_FACTOR_ONE,
|
|
|
|
.alphaBlendOp = VK_BLEND_OP_ADD,
|
|
|
|
.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE,
|
|
|
|
.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE,
|
|
|
|
.colorWriteMask = VK_COLOR_COMPONENT_A_BIT
|
|
|
|
| VK_COLOR_COMPONENT_R_BIT
|
|
|
|
| VK_COLOR_COMPONENT_G_BIT
|
|
|
|
| VK_COLOR_COMPONENT_B_BIT
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-08-21 00:18:37 +00:00
|
|
|
VkPipeline
|
|
|
|
gsk_vulkan_device_get_vk_pipeline (GskVulkanDevice *self,
|
2023-10-19 05:43:31 +00:00
|
|
|
GskVulkanPipelineLayout *layout,
|
2023-08-21 00:18:37 +00:00
|
|
|
const GskGpuShaderOpClass *op_class,
|
2023-12-31 04:38:56 +00:00
|
|
|
guint32 variation,
|
2023-08-21 00:18:37 +00:00
|
|
|
GskGpuShaderClip clip,
|
2023-12-25 04:21:13 +00:00
|
|
|
GskGpuBlend blend,
|
2023-08-21 00:18:37 +00:00
|
|
|
VkFormat format,
|
|
|
|
VkRenderPass render_pass)
|
|
|
|
{
|
|
|
|
PipelineCacheKey cache_key;
|
|
|
|
VkPipeline pipeline;
|
|
|
|
GdkDisplay *display;
|
2023-11-03 06:01:52 +00:00
|
|
|
const char *version_string;
|
2023-08-21 00:18:37 +00:00
|
|
|
char *vertex_shader_name, *fragment_shader_name;
|
|
|
|
|
|
|
|
cache_key = (PipelineCacheKey) {
|
|
|
|
.op_class = op_class,
|
2023-12-31 04:38:56 +00:00
|
|
|
.variation = variation,
|
2023-08-21 00:18:37 +00:00
|
|
|
.clip = clip,
|
2023-12-25 04:21:13 +00:00
|
|
|
.blend = blend,
|
2023-08-21 00:18:37 +00:00
|
|
|
.format = format,
|
|
|
|
};
|
2023-10-19 05:43:31 +00:00
|
|
|
pipeline = g_hash_table_lookup (layout->pipeline_cache, &cache_key);
|
2023-08-21 00:18:37 +00:00
|
|
|
if (pipeline)
|
|
|
|
return pipeline;
|
|
|
|
|
|
|
|
display = gsk_gpu_device_get_display (GSK_GPU_DEVICE (self));
|
2023-11-06 01:50:25 +00:00
|
|
|
if (gsk_vulkan_device_has_feature (self, GDK_VULKAN_FEATURE_DYNAMIC_INDEXING) &&
|
|
|
|
gsk_vulkan_device_has_feature (self, GDK_VULKAN_FEATURE_NONUNIFORM_INDEXING))
|
2023-11-03 06:01:52 +00:00
|
|
|
version_string = ".1.2";
|
|
|
|
else
|
|
|
|
version_string = ".1.0";
|
|
|
|
vertex_shader_name = g_strconcat ("/org/gtk/libgsk/shaders/vulkan/",
|
|
|
|
op_class->shader_name,
|
|
|
|
version_string,
|
|
|
|
".vert.spv",
|
|
|
|
NULL);
|
|
|
|
fragment_shader_name = g_strconcat ("/org/gtk/libgsk/shaders/vulkan/",
|
|
|
|
op_class->shader_name,
|
|
|
|
version_string,
|
|
|
|
".frag.spv",
|
|
|
|
NULL);
|
2023-08-21 00:18:37 +00:00
|
|
|
|
|
|
|
GSK_VK_CHECK (vkCreateGraphicsPipelines, display->vk_device,
|
|
|
|
display->vk_pipeline_cache,
|
|
|
|
1,
|
|
|
|
&(VkGraphicsPipelineCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
|
|
|
.stageCount = 2,
|
|
|
|
.pStages = (VkPipelineShaderStageCreateInfo[2]) {
|
|
|
|
{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
|
|
|
.stage = VK_SHADER_STAGE_VERTEX_BIT,
|
|
|
|
.module = gdk_display_get_vk_shader_module (display, vertex_shader_name),
|
|
|
|
.pName = "main",
|
|
|
|
.pSpecializationInfo = &(VkSpecializationInfo) {
|
2023-12-31 04:38:56 +00:00
|
|
|
.mapEntryCount = 5,
|
|
|
|
.pMapEntries = (VkSpecializationMapEntry[5]) {
|
2023-08-21 00:18:37 +00:00
|
|
|
{
|
|
|
|
.constantID = 0,
|
|
|
|
.offset = G_STRUCT_OFFSET (GskVulkanShaderSpecialization, clip),
|
|
|
|
.size = sizeof (guint32),
|
|
|
|
},
|
2023-10-19 06:00:37 +00:00
|
|
|
{
|
|
|
|
.constantID = 1,
|
|
|
|
.offset = G_STRUCT_OFFSET (GskVulkanShaderSpecialization, n_immutable_samplers),
|
|
|
|
.size = sizeof (guint32),
|
|
|
|
},
|
2023-11-03 01:30:12 +00:00
|
|
|
{
|
|
|
|
.constantID = 2,
|
|
|
|
.offset = G_STRUCT_OFFSET (GskVulkanShaderSpecialization, n_samplers),
|
|
|
|
.size = sizeof (guint32),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.constantID = 3,
|
|
|
|
.offset = G_STRUCT_OFFSET (GskVulkanShaderSpecialization, n_buffers),
|
|
|
|
.size = sizeof (guint32),
|
|
|
|
},
|
2023-12-31 04:38:56 +00:00
|
|
|
{
|
|
|
|
.constantID = 4,
|
|
|
|
.offset = G_STRUCT_OFFSET (GskVulkanShaderSpecialization, variation),
|
|
|
|
.size = sizeof (guint32),
|
|
|
|
},
|
2023-08-21 00:18:37 +00:00
|
|
|
},
|
|
|
|
.dataSize = sizeof (GskVulkanShaderSpecialization),
|
|
|
|
.pData = &(GskVulkanShaderSpecialization) {
|
|
|
|
.clip = clip,
|
2023-11-06 04:04:36 +00:00
|
|
|
.n_immutable_samplers = MAX (1, layout->setup.n_immutable_samplers),
|
|
|
|
.n_samplers = layout->setup.n_samplers - MAX (3 * layout->setup.n_immutable_samplers, 1),
|
2023-11-03 01:30:12 +00:00
|
|
|
.n_buffers = layout->setup.n_buffers,
|
2023-12-31 04:38:56 +00:00
|
|
|
.variation = variation,
|
2023-08-21 00:18:37 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
|
|
|
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
|
|
|
|
.module = gdk_display_get_vk_shader_module (display, fragment_shader_name),
|
|
|
|
.pName = "main",
|
|
|
|
.pSpecializationInfo = &(VkSpecializationInfo) {
|
2023-12-31 04:38:56 +00:00
|
|
|
.mapEntryCount = 5,
|
|
|
|
.pMapEntries = (VkSpecializationMapEntry[5]) {
|
2023-08-21 00:18:37 +00:00
|
|
|
{
|
|
|
|
.constantID = 0,
|
|
|
|
.offset = G_STRUCT_OFFSET (GskVulkanShaderSpecialization, clip),
|
|
|
|
.size = sizeof (guint32),
|
2023-10-19 06:00:37 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.constantID = 1,
|
|
|
|
.offset = G_STRUCT_OFFSET (GskVulkanShaderSpecialization, n_immutable_samplers),
|
|
|
|
.size = sizeof (guint32),
|
|
|
|
},
|
2023-11-03 01:30:12 +00:00
|
|
|
{
|
|
|
|
.constantID = 2,
|
|
|
|
.offset = G_STRUCT_OFFSET (GskVulkanShaderSpecialization, n_samplers),
|
|
|
|
.size = sizeof (guint32),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.constantID = 3,
|
|
|
|
.offset = G_STRUCT_OFFSET (GskVulkanShaderSpecialization, n_buffers),
|
|
|
|
.size = sizeof (guint32),
|
|
|
|
},
|
2023-12-31 04:38:56 +00:00
|
|
|
{
|
|
|
|
.constantID = 4,
|
|
|
|
.offset = G_STRUCT_OFFSET (GskVulkanShaderSpecialization, variation),
|
|
|
|
.size = sizeof (guint32),
|
|
|
|
},
|
2023-08-21 00:18:37 +00:00
|
|
|
},
|
|
|
|
.dataSize = sizeof (GskVulkanShaderSpecialization),
|
|
|
|
.pData = &(GskVulkanShaderSpecialization) {
|
|
|
|
.clip = clip,
|
2023-11-06 04:04:36 +00:00
|
|
|
.n_immutable_samplers = MAX (1, layout->setup.n_immutable_samplers),
|
|
|
|
.n_samplers = layout->setup.n_samplers - MAX (3 * layout->setup.n_immutable_samplers, 1),
|
2023-11-03 01:30:12 +00:00
|
|
|
.n_buffers = layout->setup.n_buffers,
|
2023-12-31 04:38:56 +00:00
|
|
|
.variation = variation,
|
2023-08-21 00:18:37 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
.pVertexInputState = op_class->vertex_input_state,
|
|
|
|
.pInputAssemblyState = &(VkPipelineInputAssemblyStateCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
|
|
|
|
.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
|
|
|
|
.primitiveRestartEnable = VK_FALSE,
|
|
|
|
},
|
|
|
|
.pTessellationState = NULL,
|
|
|
|
.pViewportState = &(VkPipelineViewportStateCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
|
|
|
.viewportCount = 1,
|
|
|
|
.scissorCount = 1
|
|
|
|
},
|
|
|
|
.pRasterizationState = &(VkPipelineRasterizationStateCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
|
|
|
.depthClampEnable = VK_FALSE,
|
|
|
|
.rasterizerDiscardEnable = VK_FALSE,
|
|
|
|
.polygonMode = VK_POLYGON_MODE_FILL,
|
|
|
|
.cullMode = VK_CULL_MODE_NONE,
|
|
|
|
.frontFace = VK_FRONT_FACE_CLOCKWISE,
|
|
|
|
.lineWidth = 1.0f,
|
|
|
|
},
|
|
|
|
.pMultisampleState = &(VkPipelineMultisampleStateCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
|
|
|
.rasterizationSamples = 1,
|
|
|
|
},
|
|
|
|
.pDepthStencilState = &(VkPipelineDepthStencilStateCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO
|
|
|
|
},
|
|
|
|
.pColorBlendState = &(VkPipelineColorBlendStateCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
|
|
|
|
.attachmentCount = 1,
|
2023-12-25 04:21:13 +00:00
|
|
|
.pAttachments = &blend_attachment_states[blend],
|
2023-08-21 00:18:37 +00:00
|
|
|
},
|
|
|
|
.pDynamicState = &(VkPipelineDynamicStateCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
|
|
|
.dynamicStateCount = 2,
|
|
|
|
.pDynamicStates = (VkDynamicState[2]) {
|
|
|
|
VK_DYNAMIC_STATE_VIEWPORT,
|
|
|
|
VK_DYNAMIC_STATE_SCISSOR
|
|
|
|
},
|
|
|
|
},
|
2023-10-19 05:43:31 +00:00
|
|
|
.layout = layout->vk_pipeline_layout,
|
2023-08-21 00:18:37 +00:00
|
|
|
.renderPass = render_pass,
|
|
|
|
.subpass = 0,
|
|
|
|
.basePipelineHandle = VK_NULL_HANDLE,
|
|
|
|
.basePipelineIndex = -1,
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&pipeline);
|
|
|
|
|
|
|
|
g_free (fragment_shader_name);
|
|
|
|
g_free (vertex_shader_name);
|
|
|
|
|
2023-10-19 05:43:31 +00:00
|
|
|
g_hash_table_insert (layout->pipeline_cache, g_memdup (&cache_key, sizeof (PipelineCacheKey)), pipeline);
|
2023-11-20 03:54:26 +00:00
|
|
|
gdk_display_vulkan_pipeline_cache_updated (display);
|
2023-08-21 00:18:37 +00:00
|
|
|
|
|
|
|
return pipeline;
|
|
|
|
}
|
|
|
|
|
2023-10-19 05:43:31 +00:00
|
|
|
GskVulkanPipelineLayout *
|
|
|
|
gsk_vulkan_device_acquire_pipeline_layout (GskVulkanDevice *self,
|
|
|
|
VkSampler *immutable_samplers,
|
2023-11-03 00:59:24 +00:00
|
|
|
gsize n_immutable_samplers,
|
|
|
|
gsize n_samplers,
|
|
|
|
gsize n_buffers)
|
2023-10-19 05:43:31 +00:00
|
|
|
{
|
2023-11-03 00:59:24 +00:00
|
|
|
GskVulkanPipelineLayoutSetup setup;
|
2023-10-19 05:43:31 +00:00
|
|
|
GskVulkanPipelineLayout *layout;
|
2023-10-19 06:00:37 +00:00
|
|
|
|
2023-11-04 18:38:21 +00:00
|
|
|
/* round the number of samplers/buffer up a bit, so we don't (re)create
|
|
|
|
* excessive amounts of layouts */
|
2023-11-03 01:48:06 +00:00
|
|
|
n_samplers = MAX (n_samplers, 8);
|
2023-11-03 00:59:24 +00:00
|
|
|
g_assert (n_samplers <= self->max_samplers);
|
2023-11-03 01:48:06 +00:00
|
|
|
n_buffers = MAX (n_buffers, 8);
|
2023-11-03 00:59:24 +00:00
|
|
|
g_assert (n_buffers <= self->max_buffers);
|
|
|
|
setup.n_samplers = MIN (2 << g_bit_nth_msf (n_samplers - 1, -1), self->max_samplers);
|
|
|
|
setup.n_buffers = MIN (2 << g_bit_nth_msf (n_buffers - 1, -1), self->max_buffers);
|
|
|
|
setup.n_immutable_samplers = n_immutable_samplers;
|
|
|
|
setup.immutable_samplers = immutable_samplers;
|
|
|
|
|
|
|
|
layout = g_hash_table_lookup (self->pipeline_layouts, &setup);
|
2023-10-19 05:43:31 +00:00
|
|
|
if (layout)
|
|
|
|
{
|
|
|
|
gsk_vulkan_pipeline_layout_ref (self, layout);
|
|
|
|
return layout;
|
|
|
|
}
|
|
|
|
|
2023-11-03 00:59:24 +00:00
|
|
|
return gsk_vulkan_pipeline_layout_new (self, &setup);
|
2023-10-19 05:43:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_vulkan_device_release_pipeline_layout (GskVulkanDevice *self,
|
|
|
|
GskVulkanPipelineLayout *layout)
|
|
|
|
{
|
|
|
|
if (self->pipeline_layout_cache)
|
|
|
|
gsk_vulkan_pipeline_layout_unref (self, self->pipeline_layout_cache);
|
|
|
|
|
|
|
|
self->pipeline_layout_cache = layout;
|
|
|
|
}
|
|
|
|
|
2023-11-04 18:38:21 +00:00
|
|
|
void
|
|
|
|
gsk_vulkan_device_get_pipeline_sizes (GskVulkanDevice *self,
|
|
|
|
GskVulkanPipelineLayout*layout,
|
|
|
|
gsize *n_immutable_samplers,
|
|
|
|
gsize *n_samplers,
|
|
|
|
gsize *n_buffers)
|
|
|
|
{
|
|
|
|
*n_immutable_samplers = layout->setup.n_immutable_samplers;
|
|
|
|
*n_samplers = layout->setup.n_samplers;
|
|
|
|
*n_buffers = layout->setup.n_buffers;
|
|
|
|
}
|
|
|
|
|
2023-08-12 20:10:16 +00:00
|
|
|
static GskVulkanAllocator *
|
|
|
|
gsk_vulkan_device_get_allocator (GskVulkanDevice *self,
|
|
|
|
gsize index,
|
|
|
|
const VkMemoryType *type)
|
|
|
|
{
|
|
|
|
if (self->allocators[index] == NULL)
|
|
|
|
{
|
|
|
|
self->allocators[index] = gsk_vulkan_direct_allocator_new (gsk_vulkan_device_get_vk_device (self),
|
|
|
|
index,
|
|
|
|
type);
|
|
|
|
self->allocators[index] = gsk_vulkan_buddy_allocator_new (self->allocators[index],
|
|
|
|
1024 * 1024);
|
|
|
|
//allocators[index] = gsk_vulkan_stats_allocator_new (allocators[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self->allocators[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* following code found in
|
|
|
|
* https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkPhysicalDeviceMemoryProperties.html */
|
|
|
|
GskVulkanAllocator *
|
|
|
|
gsk_vulkan_device_find_allocator (GskVulkanDevice *self,
|
|
|
|
uint32_t allowed_types,
|
|
|
|
VkMemoryPropertyFlags required_flags,
|
|
|
|
VkMemoryPropertyFlags desired_flags)
|
|
|
|
{
|
|
|
|
VkPhysicalDeviceMemoryProperties properties;
|
|
|
|
uint32_t i, found;
|
|
|
|
|
|
|
|
vkGetPhysicalDeviceMemoryProperties (gsk_vulkan_device_get_vk_physical_device (self),
|
|
|
|
&properties);
|
|
|
|
|
|
|
|
found = properties.memoryTypeCount;
|
|
|
|
for (i = 0; i < properties.memoryTypeCount; i++)
|
|
|
|
{
|
|
|
|
if (!(allowed_types & (1 << i)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((properties.memoryTypes[i].propertyFlags & required_flags) != required_flags)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
found = MIN (i, found);
|
|
|
|
|
|
|
|
if ((properties.memoryTypes[i].propertyFlags & desired_flags) == desired_flags)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert (found < properties.memoryTypeCount);
|
|
|
|
|
|
|
|
return gsk_vulkan_allocator_ref (gsk_vulkan_device_get_allocator (self, i, &properties.memoryTypes[i]));
|
|
|
|
}
|
|
|
|
|
2023-10-19 08:58:06 +00:00
|
|
|
GskVulkanAllocator *
|
|
|
|
gsk_vulkan_device_get_external_allocator (GskVulkanDevice *self)
|
|
|
|
{
|
|
|
|
if (self->external_allocator == NULL)
|
|
|
|
{
|
|
|
|
self->external_allocator = gsk_vulkan_external_allocator_new (gsk_vulkan_device_get_vk_device (self));
|
|
|
|
//self->external_allocator = gsk_vulkan_stats_allocator_new (self->external_allocator);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self->external_allocator;
|
|
|
|
}
|