From b47e177898657e435cb5bc913a4a783fddbe1f3d Mon Sep 17 00:00:00 2001 From: ladevieq Date: Thu, 27 Oct 2022 23:22:55 +0200 Subject: Api prototype --- api-test/main.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 api-test/main.cpp (limited to 'api-test/main.cpp') diff --git a/api-test/main.cpp b/api-test/main.cpp new file mode 100644 index 0000000..61db6be --- /dev/null +++ b/api-test/main.cpp @@ -0,0 +1,77 @@ +#include +#include +#include + +#include "window.hpp" +#include "vk-device.hpp" +// #include "resource-manager.hpp" + +#define ENABLE_RENDERDOC + +#ifdef ENABLE_RENDERDOC +#include + +RENDERDOC_API_1_4_1 *rdoc_api = nullptr; +#endif + +int main() { + +#ifdef ENABLE_RENDERDOC + if (HMODULE mod = GetModuleHandleA("renderdoc.dll")) { + auto RENDERDOC_GetAPI = + (pRENDERDOC_GetAPI)GetProcAddress(mod, "RENDERDOC_GetAPI"); + int ret = + RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_1_2, (void **)&rdoc_api); + assert(ret == 1); + } +#endif + + window wnd { 1280U, 720U }; + +#ifdef ENABLE_RENDERDOC + if(rdoc_api != nullptr) rdoc_api->StartFrameCapture(nullptr, nullptr); +#endif + + vkdevice device { wnd }; + + auto gpu_texture = device.create_texture({ + .width = 1024U, + .height = 1024U, + .usages = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + .format = VK_FORMAT_R8G8B8A8_UNORM, + .type = VK_IMAGE_TYPE_2D, + }); + + auto gpu_buffer = device.get_buffer(device.create_buffer({ + .size = 1024U * sizeof(uint32_t), + .usages = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, + .memory_properties = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, + .memory_usage = VMA_MEMORY_USAGE_GPU_ONLY, + })); + + auto staging_buffer = device.get_buffer(device.create_buffer({ + .size = 1024U * sizeof(uint32_t), + .usages = VK_BUFFER_USAGE_TRANSFER_SRC_BIT, + .memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, + .memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU, + })); + + uint64_t t = 7; + (*(uint64_t*)staging_buffer.mapped_ptr) = t; + + auto command_buffer = device.get_command_buffer(); + + command_buffer.copy(staging_buffer, gpu_texture); + + device.submit(command_buffer); + +#ifdef ENABLE_RENDERDOC + if(rdoc_api != nullptr) rdoc_api->EndFrameCapture(nullptr, nullptr); +#endif + + while(wnd.isOpen) { + wnd.poll_events(); + } + + return 0; +} -- cgit v1.3