diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2022-10-27 23:22:55 +0200 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2022-10-27 23:22:55 +0200 |
| commit | b47e177898657e435cb5bc913a4a783fddbe1f3d (patch) | |
| tree | df0a042b5ed9e98d7653462466dd3c6147127bc3 /api-test/main.cpp | |
| parent | cee4f9c528a91691d94c52ec1849f3ad1245b081 (diff) | |
Api prototype
Diffstat (limited to 'api-test/main.cpp')
| -rw-r--r-- | api-test/main.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
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 <cassert> +#include <cstdio> +#include <vk_mem_alloc.h> + +#include "window.hpp" +#include "vk-device.hpp" +// #include "resource-manager.hpp" + +#define ENABLE_RENDERDOC + +#ifdef ENABLE_RENDERDOC +#include <renderdoc.h> + +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; +} |
