8 #ifndef LLUVIA_CORE_BUFFER_BUFFER_H_
9 #define LLUVIA_CORE_BUFFER_BUFFER_H_
25 #include <type_traits>
132 template <
typename T>
188 template <
typename T>
189 std::unique_ptr<T, ll::Buffer::BufferMapDeleter>
map()
192 if (!m_memory->isPageMappable(m_allocInfo.
page)) {
197 typedef typename std::conditional<std::is_array<T>::value,
typename std::remove_all_extents<T>::type, T>::type baseType;
199 auto ptr = m_memory->mapBuffer(*
this);
204 return std::unique_ptr<T, ll::Buffer::BufferMapDeleter> {
static_cast<baseType*
>(ptr), deleter};
207 template <
typename T>
211 const auto objSize =
sizeof(obj);
216 auto ptr = map<std::remove_const_t<std::remove_reference_t<T>>>();
218 std::memcpy(
static_cast<void*
>(ptr.get()), &obj, objSize);
221 template <
typename T>
225 const auto vecSize = vec.size() *
sizeof(T);
230 auto ptr = map<std::remove_const_t<std::remove_reference_t<T>>>();
232 std::memcpy(
static_cast<void*
>(ptr.get()), vec.data(), vecSize);
238 const uint64_t requestedSize);
242 vk::Buffer m_vkBuffer;
250 uint64_t m_requestedSize;
255 std::shared_ptr<ll::Memory> m_memory;
Structures and methods for storing memory allocation information.
Object class and related enums.
Objects to manage raw portions of allocated memory.
Definition: Buffer.h:57
uint32_t getUsageFlagsUnsafe() const noexcept
Gets the usage flags casted to an integer type.
ll::MemoryAllocationInfo getAllocationInfo() const noexcept
Gets the allocation information.
Buffer & operator=(Buffer &&buffer)=delete
Buffer(Buffer &&b)=delete
ll::BufferUsageFlags getUsageFlags() const noexcept
Gets the Vulkan buffer usage flags.
friend class ll::ComputeGraph
Definition: Buffer.h:258
Buffer(const Buffer &b)=delete
ll::ObjectType getType() const noexcept override
Gets the object type.
std::unique_ptr< T, ll::Buffer::BufferMapDeleter > map()
Maps the memory content of this object to host-visible memory.
Definition: Buffer.h:189
void mapAndSetFromVector(const std::vector< T > &vec)
Definition: Buffer.h:222
bool isMappable() const noexcept
Determines if this buffer is mappable to host-visible memory.
const std::shared_ptr< ll::Memory > & getMemory() const noexcept
Gets the memory this buffer was allocated from.
uint64_t getSize() const noexcept
Gets the size of the buffer in bytes.
void mapAndSet(T &&obj)
Definition: Buffer.h:208
Buffer & operator=(const Buffer &buffer)=delete
Class for command buffer.
Definition: CommandBuffer.h:63
Class representing compute nodes.
Definition: ComputeNode.h:38
Class to manage allocation of objects into a specific type of memory.
Definition: Memory.h:92
Base class for all types that can be used in computer shaders.
Definition: Object.h:94
Class that contains all the state required to run compute operations on a compute device.
Definition: Session.h:51
error related classes and methods.
ObjectType
Object types.
Definition: Object.h:29
void throwSystemError(ll::ErrorCode errorCode, T &&msg)
Throws a std::system_error exception with error code and message.
Definition: error.h:173
std::error_code createErrorCode(ll::ErrorCode errorCode)
Creates an error code.
Definition: error.h:138
Deleter for unmapping buffers from host memory.
Definition: Buffer.h:130
ll::Buffer * buffer
Definition: Buffer.h:138
void operator()([[maybe_unused]] T *ptr) const
Definition: Buffer.h:133
Structure to hold the allocation information of objects in memory.
Definition: MemoryAllocationInfo.h:19
uint32_t page
page number within memory
Definition: MemoryAllocationInfo.h:31