Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
HostMemoryBlock.ipp
Go to the documentation of this file.
1#pragma once
2
5
6#include <Common/os.h>
7#include <Common/math_basics.h>
8
9#include <numeric>
10#include <new>
11#include <utility>
12
13namespace ph::editor::ghi
14{
15
18 , m_memoryBlock(nullptr)
19{}
20
21inline HostMemoryBlock::HostMemoryBlock(std::size_t blockSizeHintInBytes)
22 : HostMemoryBlock(blockSizeHintInBytes, os::get_L1_cache_line_size_in_bytes())
23{}
24
25inline HostMemoryBlock::HostMemoryBlock(std::size_t blockSizeHintInBytes, std::size_t alignmentInBytes)
26{
27 const auto alignmentSize = std::lcm(alignof(std::max_align_t), alignmentInBytes);
28 const auto blockSize = math::next_multiple(blockSizeHintInBytes, alignmentSize);
29
30 m_memoryBlock = make_aligned_memory<std::byte>(blockSize, alignmentSize);
31 if(!m_memoryBlock)
32 {
33 throw OutOfHostMemory{};
34 }
35
36 setBlockSource(m_memoryBlock.get(), blockSize);
37}
38
41{
42 swap(*this, other);
43}
44
46{
47 swap(*this, rhs);
48
49 return *this;
50}
51
52inline void swap(HostMemoryBlock& first, HostMemoryBlock& second) noexcept
53{
54 using std::swap;
55
56 swap(static_cast<GraphicsMemoryBlock&>(first), static_cast<GraphicsMemoryBlock&>(second));
57 swap(first.m_memoryBlock, second.m_memoryBlock);
58}
59
60}// end namespace ph::editor::ghi
Definition GraphicsMemoryBlock.h:13
void setBlockSource(std::byte *source, std::size_t blockSizeInBytes)
Definition GraphicsMemoryBlock.cpp:34
A chunk of cache aligned main memory.
Definition HostMemoryBlock.h:16
HostMemoryBlock()
Empty block without any allocation.
Definition HostMemoryBlock.ipp:16
HostMemoryBlock & operator=(HostMemoryBlock &&rhs) noexcept
Definition HostMemoryBlock.ipp:45
Definition ghi_exceptions.h:20
Definition PlatformDisplay.h:13
void swap(GraphicsMemoryBlock &first, GraphicsMemoryBlock &second) noexcept
Definition GraphicsMemoryBlock.cpp:52