texture_runtime: Add staging buffer lock mechanism

This commit is contained in:
emufan4568
2022-09-10 12:54:48 +03:00
committed by GPUCode
parent 5d48107dd6
commit 73d6a9d585
7 changed files with 82 additions and 73 deletions

View File

@ -3,7 +3,7 @@
// Refer to the license.txt file included.
#pragma once
#include <span>
#include <memory>
#include <vector>
#include <boost/serialization/export.hpp>
@ -65,8 +65,11 @@ private:
BOOST_CLASS_EXPORT_KEY(BufferMem);
/// A managed reference to host-side memory. Fast enough to be used everywhere instead of u8*
/// Supports serialization.
/**
* A managed reference to host-side memory.
* Fast enough to be used everywhere instead of u8*
* Supports serialization.
*/
class MemoryRef {
public:
MemoryRef() = default;
@ -75,41 +78,52 @@ public:
: backing_mem(std::move(backing_mem_)), offset(0) {
Init();
}
MemoryRef(std::shared_ptr<BackingMem> backing_mem_, u64 offset_)
: backing_mem(std::move(backing_mem_)), offset(offset_) {
ASSERT(offset <= backing_mem->GetSize());
Init();
}
explicit operator bool() const {
return cptr != nullptr;
}
operator u8*() {
return cptr;
}
u8* GetPtr() {
return cptr;
}
std::byte* GetBytes() {
return reinterpret_cast<std::byte*>(cptr);
}
operator const u8*() const {
return cptr;
}
u8* GetPtr() {
return cptr;
}
const u8* GetPtr() const {
return cptr;
}
const std::byte* GetBytes() const {
return reinterpret_cast<const std::byte*>(cptr);
std::span<std::byte> GetBytes(std::size_t size) {
return std::span{reinterpret_cast<std::byte*>(cptr), size > csize ? csize : size};
}
std::span<const std::byte> GetBytes(std::size_t size) const {
return std::span{reinterpret_cast<const std::byte*>(cptr), size > csize ? csize : size};
}
std::size_t GetSize() const {
return csize;
}
MemoryRef& operator+=(u32 offset_by) {
ASSERT(offset_by < csize);
offset += offset_by;
Init();
return *this;
}
MemoryRef operator+(u32 offset_by) const {
ASSERT(offset_by < csize);
return MemoryRef(backing_mem, offset + offset_by);