Add vertex buffer creation and upload
This commit is contained in:
parent
210ca8233a
commit
075431545a
1 changed files with 49 additions and 0 deletions
|
@ -40,6 +40,9 @@ static VkCommandBuffer current_cmd = VK_NULL_HANDLE;
|
||||||
static VkPipeline pipeline = VK_NULL_HANDLE;
|
static VkPipeline pipeline = VK_NULL_HANDLE;
|
||||||
static VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
|
static VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
|
||||||
|
|
||||||
|
static VkBuffer vertex_buffer = VK_NULL_HANDLE;
|
||||||
|
static VkDeviceMemory vertex_memory = VK_NULL_HANDLE;
|
||||||
|
|
||||||
VKAPI_ATTR VkBool32 VKAPI_CALL
|
VKAPI_ATTR VkBool32 VKAPI_CALL
|
||||||
gfx_vulkan_debug_callback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
gfx_vulkan_debug_callback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||||
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
||||||
|
@ -632,6 +635,35 @@ static void gfx_vulkan_create_framebuffers() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void gfx_vulkan_create_buffers() {
|
||||||
|
vkDeviceWaitIdle(device);
|
||||||
|
|
||||||
|
// create buffer
|
||||||
|
VkBufferCreateInfo create_info = {};
|
||||||
|
create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||||
|
create_info.size = 60000;
|
||||||
|
create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||||
|
create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||||
|
|
||||||
|
vkCreateBuffer(device, &create_info, nullptr, &vertex_buffer);
|
||||||
|
|
||||||
|
// allocate memory
|
||||||
|
VkMemoryRequirements memory_requirements;
|
||||||
|
vkGetBufferMemoryRequirements(device, vertex_buffer, &memory_requirements);
|
||||||
|
|
||||||
|
VkMemoryAllocateInfo allocate_info = {};
|
||||||
|
allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||||
|
allocate_info.allocationSize = memory_requirements.size;
|
||||||
|
allocate_info.memoryTypeIndex =
|
||||||
|
gfx_vulkan_find_memory_type(memory_requirements.memoryTypeBits,
|
||||||
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
||||||
|
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||||
|
|
||||||
|
vkAllocateMemory(device, &allocate_info, nullptr, &vertex_memory);
|
||||||
|
|
||||||
|
vkBindBufferMemory(device, vertex_buffer, vertex_memory, 0);
|
||||||
|
}
|
||||||
|
|
||||||
static void gfx_vulkan_renderer_init(void) {
|
static void gfx_vulkan_renderer_init(void) {
|
||||||
gfx_vulkan_create_instance();
|
gfx_vulkan_create_instance();
|
||||||
gfx_vulkan_create_device();
|
gfx_vulkan_create_device();
|
||||||
|
@ -640,6 +672,7 @@ static void gfx_vulkan_renderer_init(void) {
|
||||||
gfx_vulkan_create_sync();
|
gfx_vulkan_create_sync();
|
||||||
gfx_vulkan_create_depth();
|
gfx_vulkan_create_depth();
|
||||||
gfx_vulkan_create_framebuffers();
|
gfx_vulkan_create_framebuffers();
|
||||||
|
gfx_vulkan_create_buffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gfx_vulkan_renderer_on_resize(void) {
|
static void gfx_vulkan_renderer_on_resize(void) {
|
||||||
|
@ -731,6 +764,22 @@ static void gfx_vulkan_renderer_draw_triangles(float buf_vbo[], size_t buf_vbo_l
|
||||||
// FIXME: uh no
|
// FIXME: uh no
|
||||||
vkCmdBindPipeline(current_cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
vkCmdBindPipeline(current_cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
||||||
|
|
||||||
|
void* mapped_data = nullptr;
|
||||||
|
vkMapMemory(device, vertex_memory, 0, buf_vbo_len, 0, &mapped_data);
|
||||||
|
|
||||||
|
memcpy(mapped_data, buf_vbo, buf_vbo_len);
|
||||||
|
|
||||||
|
VkMappedMemoryRange range = {};
|
||||||
|
range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
|
||||||
|
range.memory = vertex_memory;
|
||||||
|
range.size = buf_vbo_len;
|
||||||
|
vkFlushMappedMemoryRanges(device, 1, &range);
|
||||||
|
|
||||||
|
vkUnmapMemory(device, vertex_memory);
|
||||||
|
|
||||||
|
VkDeviceSize offsets[] = {0};
|
||||||
|
vkCmdBindVertexBuffers(current_cmd, 0, 1, &vertex_buffer, offsets);
|
||||||
|
|
||||||
vkCmdDraw(current_cmd, buf_vbo_num_tris, 1, 0, 0);
|
vkCmdDraw(current_cmd, buf_vbo_num_tris, 1, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue