make creating transfer commands easier
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include "core/output_device/gryphn_output_device.h"
|
#include "core/output_device/gryphn_output_device.h"
|
||||||
#include "output_device/vulkan_output_devices.h"
|
#include "output_device/vulkan_output_devices.h"
|
||||||
#include "output_device/vulkan_physical_device.h"
|
#include "output_device/vulkan_physical_device.h"
|
||||||
|
#include "commands/command_buffer/vulkan_command_buffer.h"
|
||||||
|
|
||||||
VkBufferUsageFlags vkGryphnBufferType(gnBufferType type) {
|
VkBufferUsageFlags vkGryphnBufferType(gnBufferType type) {
|
||||||
VkBufferUsageFlags usageFlags = 0;
|
VkBufferUsageFlags usageFlags = 0;
|
||||||
@@ -57,38 +58,12 @@ gnReturnCode VkCreateBuffer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void VkCopyBuffer(VkBuffer source, VkBuffer destination, size_t size, VkCommandPool pool, VkDevice device, VkQueue queue) {
|
void VkCopyBuffer(VkBuffer source, VkBuffer destination, size_t size, VkCommandPool pool, VkDevice device, VkQueue queue) {
|
||||||
VkCommandBufferAllocateInfo allocInfo = {
|
VkCommandBuffer transferBuffer = VkBeginTransferOperation(device, pool);
|
||||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
|
||||||
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
|
||||||
.commandPool = pool,
|
|
||||||
.commandBufferCount = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
VkCommandBuffer commandBuffer;
|
|
||||||
vkAllocateCommandBuffers(device, &allocInfo, &commandBuffer);
|
|
||||||
|
|
||||||
VkCommandBufferBeginInfo beginInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
|
||||||
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
|
|
||||||
};
|
|
||||||
vkBeginCommandBuffer(commandBuffer, &beginInfo);
|
|
||||||
|
|
||||||
|
|
||||||
VkBufferCopy copyRegion = {
|
VkBufferCopy copyRegion = {
|
||||||
.size = size
|
.size = size
|
||||||
};
|
};
|
||||||
vkCmdCopyBuffer(commandBuffer, source, destination, 1, ©Region);
|
vkCmdCopyBuffer(transferBuffer, source, destination, 1, ©Region);
|
||||||
vkEndCommandBuffer(commandBuffer);
|
VkEndTransferOperation(transferBuffer, pool, queue, device);
|
||||||
|
|
||||||
VkSubmitInfo submitInfo = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
|
|
||||||
.commandBufferCount = 1,
|
|
||||||
.pCommandBuffers = &commandBuffer
|
|
||||||
};
|
|
||||||
|
|
||||||
vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE);
|
|
||||||
vkQueueWaitIdle(queue);
|
|
||||||
vkFreeCommandBuffers(device, pool, 1, &commandBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gnReturnCode gnCreateBufferFn(gnBufferHandle buffer, gnOutputDeviceHandle device, gnBufferInfo info) {
|
gnReturnCode gnCreateBufferFn(gnBufferHandle buffer, gnOutputDeviceHandle device, gnBufferInfo info) {
|
||||||
|
@@ -44,3 +44,37 @@ gnReturnCode gnEndCommandBufferFn(struct gnCommandBuffer_t* commandBuffer) {
|
|||||||
return GN_FAIELD_TO_END_RECORDING;
|
return GN_FAIELD_TO_END_RECORDING;
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
VkCommandBuffer VkBeginTransferOperation(VkDevice device, VkCommandPool pool) {
|
||||||
|
VkCommandBufferAllocateInfo allocInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
||||||
|
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
||||||
|
.commandPool = pool,
|
||||||
|
.commandBufferCount = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
VkCommandBuffer commandBuffer;
|
||||||
|
vkAllocateCommandBuffers(device, &allocInfo, &commandBuffer);
|
||||||
|
|
||||||
|
VkCommandBufferBeginInfo beginInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||||
|
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
|
||||||
|
};
|
||||||
|
vkBeginCommandBuffer(commandBuffer, &beginInfo);
|
||||||
|
return commandBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VkEndTransferOperation(VkCommandBuffer transferBuffer, VkCommandPool pool, VkQueue syncQueue, VkDevice device) {
|
||||||
|
vkEndCommandBuffer(transferBuffer);
|
||||||
|
|
||||||
|
VkSubmitInfo submitInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
|
||||||
|
.commandBufferCount = 1,
|
||||||
|
.pCommandBuffers = &transferBuffer
|
||||||
|
};
|
||||||
|
|
||||||
|
vkQueueSubmit(syncQueue, 1, &submitInfo, VK_NULL_HANDLE);
|
||||||
|
vkQueueWaitIdle(syncQueue);
|
||||||
|
vkFreeCommandBuffers(device, pool, 1, &transferBuffer);
|
||||||
|
}
|
||||||
|
@@ -10,3 +10,6 @@ typedef struct gnPlatformCommandBuffer_t {
|
|||||||
gnBufferHandle boundIndexBuffer;
|
gnBufferHandle boundIndexBuffer;
|
||||||
gnGraphicsPipeline boundGraphicsPipeline;
|
gnGraphicsPipeline boundGraphicsPipeline;
|
||||||
} gnPlatformCommandBuffer;
|
} gnPlatformCommandBuffer;
|
||||||
|
|
||||||
|
VkCommandBuffer VkBeginTransferOperation(VkDevice device, VkCommandPool pool);
|
||||||
|
void VkEndTransferOperation(VkCommandBuffer transferBuffer, VkCommandPool pool, VkQueue syncQueue, VkDevice device);
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "stdlib.h"
|
|
||||||
#include "utils/gryphn_image_format.h"
|
#include "utils/gryphn_image_format.h"
|
||||||
#include "utils/gryphn_error_code.h"
|
#include "utils/gryphn_error_code.h"
|
||||||
#include <core/gryphn_handles.h>
|
#include <core/gryphn_handles.h>
|
||||||
|
Reference in New Issue
Block a user