Skip to content

Commit

Permalink
Add more functionality for Vulkan descriptor-sets
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 15, 2025
1 parent b918c60 commit b50ce07
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 8 deletions.
41 changes: 41 additions & 0 deletions Backends/Graphics5/Vulkan/Sources/kope/vulkan/descriptorset.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,44 @@
#include <kope/vulkan/texture_functions.h>

#include <kope/util/align.h>

void kope_vulkan_descriptor_set_set_texture_view(kope_g5_device *device, kope_vulkan_descriptor_set *set, const kope_g5_texture_view *texture_view,
uint32_t index) {
VkDescriptorImageInfo image_info = {
.imageView = texture_view->texture->vulkan.image_view,
.imageLayout = VK_IMAGE_LAYOUT_GENERAL,
};

VkWriteDescriptorSet write = {
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = set->descriptor_set,
.dstBinding = index,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.pImageInfo = &image_info,
};

vkUpdateDescriptorSets(device->vulkan.device, 1, &write, 0, NULL);
}

void kope_vulkan_descriptor_set_set_sampler(kope_g5_device *device, kope_vulkan_descriptor_set *set, kope_g5_sampler *sampler, uint32_t index) {
VkDescriptorImageInfo image_info = {
.sampler = sampler->vulkan.sampler,
.imageLayout = VK_IMAGE_LAYOUT_GENERAL,
};

VkWriteDescriptorSet write = {
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = set->descriptor_set,
.dstBinding = index,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER,
.pImageInfo = &image_info,
};

vkUpdateDescriptorSets(device->vulkan.device, 1, &write, 0, NULL);
}

void kope_vulkan_descriptor_set_prepare_buffer(kope_g5_command_list *list, kope_g5_buffer *buffer) {}

void kope_vulkan_descriptor_set_prepare_texture(kope_g5_command_list *list, const kope_g5_texture_view *texture_view) {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@ extern "C" {
void kope_vulkan_descriptor_set_set_buffer_view_cbv(kope_g5_device *device, kope_vulkan_descriptor_set *set, kope_g5_buffer *buffer, uint32_t index);
void kope_vulkan_descriptor_set_set_buffer_view_srv(kope_g5_device *device, kope_vulkan_descriptor_set *set, kope_g5_buffer *buffer, uint32_t index);
void kope_vulkan_descriptor_set_set_bvh_view_srv(kope_g5_device *device, kope_vulkan_descriptor_set *set, kope_g5_raytracing_hierarchy *bvh, uint32_t index);
void kope_vulkan_descriptor_set_set_texture_view_srv(kope_g5_device *device, uint32_t offset, const kope_g5_texture_view *texture_view);
void kope_vulkan_descriptor_set_set_texture_view(kope_g5_device *device, kope_vulkan_descriptor_set *set, const kope_g5_texture_view *texture_view,
uint32_t index);
void kope_vulkan_descriptor_set_set_texture_array_view_srv(kope_g5_device *device, kope_vulkan_descriptor_set *set, const kope_g5_texture_view *texture_view,
uint32_t index);
void kope_vulkan_descriptor_set_set_texture_cube_view_srv(kope_g5_device *device, kope_vulkan_descriptor_set *set, const kope_g5_texture_view *texture_view,
uint32_t index);
void kope_vulkan_descriptor_set_set_texture_view_uav(kope_g5_device *device, kope_vulkan_descriptor_set *set, const kope_g5_texture_view *texture_view,
uint32_t index);
void kope_vulkan_descriptor_set_set_sampler(kope_g5_device *device, kope_vulkan_descriptor_set *set, kope_g5_sampler *sampler, uint32_t index);

void kope_vulkan_descriptor_set_prepare_cbv_buffer(kope_g5_command_list *list, kope_g5_buffer *buffer, uint32_t offset, uint32_t size);
void kope_vulkan_descriptor_set_prepare_srv_texture(kope_g5_command_list *list, const kope_g5_texture_view *texture_view);
void kope_vulkan_descriptor_set_prepare_uav_texture(kope_g5_command_list *list, const kope_g5_texture_view *texture_view);
void kope_vulkan_descriptor_set_prepare_buffer(kope_g5_command_list *list, kope_g5_buffer *buffer);
void kope_vulkan_descriptor_set_prepare_texture(kope_g5_command_list *list, const kope_g5_texture_view *texture_view);

#ifdef __cplusplus
}
Expand Down
86 changes: 85 additions & 1 deletion Backends/Graphics5/Vulkan/Sources/kope/vulkan/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,91 @@ void kope_vulkan_device_create_descriptor_set(kope_g5_device *device, VkDescript
assert(result == VK_SUCCESS);
}

void kope_vulkan_device_create_sampler(kope_g5_device *device, const kope_g5_sampler_parameters *parameters, kope_g5_sampler *sampler) {}
static VkSamplerAddressMode convert_address_mode(kope_g5_address_mode mode) {
switch (mode) {
case KOPE_G5_ADDRESS_MODE_CLAMP_TO_EDGE:
return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
case KOPE_G5_ADDRESS_MODE_REPEAT:
return VK_SAMPLER_ADDRESS_MODE_REPEAT;
case KOPE_G5_ADDRESS_MODE_MIRROR_REPEAT:
return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
}

return VK_SAMPLER_ADDRESS_MODE_REPEAT;
}

static VkFilter convert_filter(kope_g5_filter_mode filter) {
switch (filter) {
case KOPE_G5_FILTER_MODE_NEAREST:
return VK_FILTER_NEAREST;
case KOPE_G5_FILTER_MODE_LINEAR:
return VK_FILTER_LINEAR;
}

return VK_FILTER_NEAREST;
}

static VkFilter convert_mipmap_filter(kope_g5_mipmap_filter_mode filter) {
switch (filter) {
case KOPE_G5_MIPMAP_FILTER_MODE_NEAREST:
return VK_FILTER_NEAREST;
case KOPE_G5_MIPMAP_FILTER_MODE_LINEAR:
return VK_FILTER_LINEAR;
}

return VK_FILTER_NEAREST;
}

static VkCompareOp convert_compare_function(kope_g5_compare_function func) {
switch (func) {
case KOPE_G5_COMPARE_FUNCTION_NEVER:
return VK_COMPARE_OP_NEVER;
case KOPE_G5_COMPARE_FUNCTION_LESS:
return VK_COMPARE_OP_LESS;
case KOPE_G5_COMPARE_FUNCTION_EQUAL:
return VK_COMPARE_OP_EQUAL;
case KOPE_G5_COMPARE_FUNCTION_LESS_EQUAL:
return VK_COMPARE_OP_LESS_OR_EQUAL;
case KOPE_G5_COMPARE_FUNCTION_GREATER:
return VK_COMPARE_OP_GREATER;
case KOPE_G5_COMPARE_FUNCTION_NOT_EQUAL:
return VK_COMPARE_OP_NOT_EQUAL;
case KOPE_G5_COMPARE_FUNCTION_GREATER_EQUAL:
return VK_COMPARE_OP_GREATER_OR_EQUAL;
case KOPE_G5_COMPARE_FUNCTION_ALWAYS:
return VK_COMPARE_OP_ALWAYS;
}

return VK_COMPARE_OP_ALWAYS;
}

void kope_vulkan_device_create_sampler(kope_g5_device *device, const kope_g5_sampler_parameters *parameters, kope_g5_sampler *sampler) {
VkSamplerCreateInfo sampler_create_info = {
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
.pNext = NULL,
.flags = 0,

.addressModeU = convert_address_mode(parameters->address_mode_u),
.addressModeV = convert_address_mode(parameters->address_mode_v),
.addressModeW = convert_address_mode(parameters->address_mode_w),

.mipmapMode = convert_mipmap_filter(parameters->mipmap_filter),

.magFilter = convert_filter(parameters->mag_filter),
.minFilter = convert_filter(parameters->min_filter),

.compareEnable = parameters->compare != KOPE_G5_COMPARE_FUNCTION_ALWAYS,
.compareOp = convert_compare_function(parameters->compare),

.anisotropyEnable = parameters->max_anisotropy > 1,
.maxAnisotropy = parameters->max_anisotropy,

.maxLod = parameters->lod_max_clamp,
.minLod = parameters->lod_min_clamp,
};

vkCreateSampler(device->vulkan.device, &sampler_create_info, NULL, &sampler->vulkan.sampler);
}

void kope_vulkan_device_create_raytracing_volume(kope_g5_device *device, kope_g5_buffer *vertex_buffer, uint64_t vertex_count, kope_g5_buffer *index_buffer,
uint32_t index_count, kope_g5_raytracing_volume *volume) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern "C" {
#endif

typedef struct kope_vulkan_sampler {
int nothing;
VkSampler sampler;
} kope_vulkan_sampler;

#ifdef __cplusplus
Expand Down

0 comments on commit b50ce07

Please sign in to comment.