From 5e3bb454d50091e581d5d1d03af34e38277694b3 Mon Sep 17 00:00:00 2001 From: ladevieq Date: Thu, 12 Jan 2023 00:47:59 +0100 Subject: WIP new rendering api --- api-test/command-buffer.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 api-test/command-buffer.cpp (limited to 'api-test/command-buffer.cpp') diff --git a/api-test/command-buffer.cpp b/api-test/command-buffer.cpp new file mode 100644 index 0000000..9e37f95 --- /dev/null +++ b/api-test/command-buffer.cpp @@ -0,0 +1,54 @@ +#include "command-buffer.hpp" + +#include + +#include "vulkan-loader.hpp" + +#include"vk-device.hpp" + +#ifdef _DEBUG +#define VKCHECK(result) assert(result == VK_SUCCESS); +#else +#define VKCHECK(result) result; +#endif + +void command_buffer::start() const { + VkCommandBufferBeginInfo begin_info { + .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, + .pNext = nullptr, + .flags = 0U, + .pInheritanceInfo = nullptr + }; + + VKCHECK(vkBeginCommandBuffer(handle, &begin_info)) +} + +void command_buffer::stop() const { + VKCHECK(vkEndCommandBuffer(handle)) +} + +void transfer_command_buffer::copy(::handle buffer_handle, ::handle texture_handle) { + const auto& buffer = vkdevice::get_buffer(buffer_handle); + const auto& texture = vkdevice::get_texture(texture_handle); + VkImageSubresourceLayers image_subresource_layers { + .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, + .mipLevel = 0, + .baseArrayLayer = 0, + .layerCount = 1, + }; + + VkBufferImageCopy buffer_to_image_copy { + .bufferOffset = 0, + .bufferRowLength = 0, + .bufferImageHeight = 0, + .imageSubresource = image_subresource_layers, + .imageOffset = { .x = 0, .y = 0, .z = 0 }, + .imageExtent = { + .width = texture.desc.width, + .height = texture.desc.height, + .depth = texture.desc.depth, + }, + }; + + vkCmdCopyBufferToImage(handle, buffer.handle, texture.handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &buffer_to_image_copy); +} -- cgit v1.3