Skip to content

Commit

Permalink
Improve Vulkan buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 13, 2025
1 parent a140b1b commit 22d737b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
32 changes: 20 additions & 12 deletions Backends/Graphics5/Vulkan/Sources/kope/vulkan/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,39 @@ void kope_vulkan_buffer_destroy(kope_g5_buffer *buffer) {
}

void *kope_vulkan_buffer_try_to_lock_all(kope_g5_buffer *buffer) {
void *data = NULL;
VkResult result = vkMapMemory(buffer->vulkan.device, buffer->vulkan.memory, 0, buffer->vulkan.size, 0, &data);
buffer->vulkan.locked_data_offset = 0;
buffer->vulkan.locked_data_size = UINT64_MAX;

VkResult result = vkMapMemory(buffer->vulkan.device, buffer->vulkan.memory, 0, buffer->vulkan.size, 0, &buffer->vulkan.locked_data);
assert(result == VK_SUCCESS);
return data;
return buffer->vulkan.locked_data;
}

void *kope_vulkan_buffer_lock_all(kope_g5_buffer *buffer) {
void *data = NULL;
VkResult result = vkMapMemory(buffer->vulkan.device, buffer->vulkan.memory, 0, buffer->vulkan.size, 0, &data);
buffer->vulkan.locked_data_offset = 0;
buffer->vulkan.locked_data_size = UINT64_MAX;

VkResult result = vkMapMemory(buffer->vulkan.device, buffer->vulkan.memory, 0, buffer->vulkan.size, 0, &buffer->vulkan.locked_data);
assert(result == VK_SUCCESS);
return data;
return buffer->vulkan.locked_data;
}

void *kope_vulkan_buffer_try_to_lock(kope_g5_buffer *buffer, uint64_t offset, uint64_t size) {
void *data = NULL;
VkResult result = vkMapMemory(buffer->vulkan.device, buffer->vulkan.memory, offset, size, 0, &data);
buffer->vulkan.locked_data_offset = offset;
buffer->vulkan.locked_data_size = size;

VkResult result = vkMapMemory(buffer->vulkan.device, buffer->vulkan.memory, offset, size, 0, &buffer->vulkan.locked_data);
assert(result == VK_SUCCESS);
return data;
return buffer->vulkan.locked_data;
}

void *kope_vulkan_buffer_lock(kope_g5_buffer *buffer, uint64_t offset, uint64_t size) {
void *data = NULL;
VkResult result = vkMapMemory(buffer->vulkan.device, buffer->vulkan.memory, offset, size, 0, &data);
buffer->vulkan.locked_data_offset = offset;
buffer->vulkan.locked_data_size = size;

VkResult result = vkMapMemory(buffer->vulkan.device, buffer->vulkan.memory, offset, size, 0, &buffer->vulkan.locked_data);
assert(result == VK_SUCCESS);
return data;
return buffer->vulkan.locked_data;
}

void kope_vulkan_buffer_unlock(kope_g5_buffer *buffer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ typedef struct kope_vulkan_buffer {
VkBuffer buffer;
VkDeviceMemory memory;
uint64_t size;

void *locked_data;
uint64_t locked_data_offset;
uint64_t locked_data_size;
} kope_vulkan_buffer;

#ifdef __cplusplus
Expand Down

0 comments on commit 22d737b

Please sign in to comment.