From 19f6f130f9bc60cb89155dcff11c34c52714416f Mon Sep 17 00:00:00 2001 From: quou Date: Mon, 30 Dec 2024 10:17:36 +1100 Subject: Staged_Buffer --- video.cpp | 38 ++++++++++++++++++++++++++++++++++++++ video.hpp | 17 +++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/video.cpp b/video.cpp index 09261b5..d5efb34 100644 --- a/video.cpp +++ b/video.cpp @@ -3900,3 +3900,41 @@ Vram_Allocator::Allocation Vram_Allocator::alloc( void Vram_Allocator::free(Allocation& alloc) { alloc.chunk->free = true; } + +void Staged_Buffer::init( + Device* dev, + const char* name, + int s, + int flags +) { + size = s; + stage = dev->create_buffer( + name, + size, + Buffer_Flags::copy_src | + Buffer_Flags::cpu_readwrite + ); + gpuonly = dev->create_buffer( + name, + size, + Buffer_Flags::copy_dst | + flags + ); +} + +void Staged_Buffer::destroy(Device* dev) { + dev->destroy_buffer(stage); + dev->destroy_buffer(gpuonly); +} + +void* Staged_Buffer::map(Device* dev) { + return dev->map_buffer(stage, 0, size); +} + +void Staged_Buffer::unmap(Device* dev) { + dev->unmap_buffer(stage); +} + +void Staged_Buffer::update(Context& ctx) { + ctx.copy(gpuonly, stage); +} diff --git a/video.hpp b/video.hpp index aa196a7..60127f3 100644 --- a/video.hpp +++ b/video.hpp @@ -492,4 +492,21 @@ struct Shader : public Asset { int descriptor_stage(int slot); }; +struct Staged_Buffer { + Buffer_Id stage; + Buffer_Id gpuonly; + int size; + + void init( + Device* dev, + const char* name, + int size, + int flags + ); + void destroy(Device* dev); + void* map(Device* dev); + void unmap(Device* dev); + void update(Context& ctx); +}; + #endif -- cgit v1.2.3-54-g00ecf