|
ngscopeclient v0.2.2
|
A buffer of memory which may be used by GPU acceleration. More...
#include <AcceleratorBuffer.h>


Public Types | |
| enum | MemoryAttributes { MEM_ATTRIB_CPU_SIDE = 0x1 , MEM_ATTRIB_GPU_SIDE = 0x2 , MEM_ATTRIB_CPU_REACHABLE = 0x4 , MEM_ATTRIB_GPU_REACHABLE = 0x8 , MEM_ATTRIB_CPU_FAST = 0x10 , MEM_ATTRIB_GPU_FAST = 0x20 } |
| Attributes that a memory buffer can have. | |
| enum | MemoryType { MEM_TYPE_NULL = 0 , MEM_TYPE_CPU_PAGED , MEM_TYPE_CPU_ONLY , MEM_TYPE_CPU_DMA_CAPABLE , MEM_TYPE_GPU_ONLY , MEM_TYPE_GPU_DMA_CAPABLE } |
| Types of memory buffer. | |
| enum | UsageHint { HINT_NEVER , HINT_UNLIKELY , HINT_LIKELY } |
Public Member Functions | |
| virtual std::string | GetType () const |
| Gets the underlying C++ object type. | |
| virtual size_t | GetElementSize () const |
| Gets the size of each entry in the container. | |
| __attribute__ ((noinline)) AcceleratorBuffer(const std | |
| Creates a new AcceleratorBuffer with no content. | |
| size_t | GetMemoryBytes () const |
| Returns the total size of the buffer (wherever it is), in bytes. | |
| size_t | GetCpuMemoryBytes () const |
| Returns the total reserved CPU memory, in bytes. | |
| size_t | GetGpuMemoryBytes () const |
| Returns the total reserved GPU memory, in bytes. | |
| bool | empty () const |
| Returns true if the container is empty. | |
| bool | IsCpuBufferStale () const |
| Returns true if the CPU-side buffer is stale. | |
| bool | IsGpuBufferStale () const |
| Returns true if the GPU-side buffer is stale. | |
| bool | HasCpuBuffer () const |
| Returns true if there is currently a CPU-side buffer. | |
| bool | HasGpuBuffer () const |
| Returns true if there is currently a GPU-side buffer. | |
| bool | IsSingleSharedBuffer () const |
| Returns true if the object contains only a single buffer. | |
| vk::Buffer | GetBuffer () |
| Returns the preferred buffer for GPU-side access. | |
| T * | GetCpuPointer () |
| Gets a pointer to the CPU-side buffer. | |
| vk::DescriptorBufferInfo | GetBufferInfo () |
| Returns a vk::DescriptorBufferInfo suitable for binding this object to. | |
| void | resize (size_t size, bool exactSize=false) |
| Change the usable size of the container. | |
| void | clear () |
| Resize the container to be empty (but don't free memory) | |
| void | reserve (size_t size) |
| Reallocates buffers so that at least size elements of storage are available. | |
| void | shrink_to_fit () |
| Frees unused memory so that m_size == m_capacity. | |
| __attribute__ ((noinline)) void CopyFrom(const std | |
| Copies our content from a std::vector. | |
| __attribute__ ((noinline)) void CopyFrom(const AcceleratorBuffer< T > &rhs | |
| Copies our content from another AcceleratorBuffer. | |
| bool | BeginHostDeviceTransferIfNeeded () |
| Starts a host-to-device transfer if we need to do one. | |
| void | ClearTransferFlags () |
Public Member Functions inherited from AcceleratorBufferBase | |
| AcceleratorBufferBase (const std::string &name="") | |
| size_t | size () const |
| Returns the actual size of the container (may be smaller than what was allocated) | |
| size_t | capacity () const |
| Returns the allocated size of the container. | |
| const std::string & | GetName () const |
| Returns the debug name of the buffer, if any. | |
Public Attributes | |
| bool | reallocateToMatch |
| std::unique_ptr< vk::raii::Event > | m_deviceHostTransferEvent |
| Event signaled upon completion of a device-host transfer. | |
| std::atomic< bool > | m_hostDeviceTransferActive |
| True if a host-device transfer has been submitted. | |
| std::unique_ptr< vk::raii::Event > | m_hostDeviceTransferEvent |
| Event signaled upon completion of a host-device transfer. | |
Public Attributes inherited from AcceleratorBufferBase | |
| size_t | m_capacity |
| Size of the allocated memory space (may be larger than m_size) | |
| size_t | m_size |
| Size of the memory actually being used. | |
Protected Member Functions | |
| bool | IsReachableFromCpu (MemoryType mt) |
| Returns true if the given buffer type can be reached from the CPU. | |
| bool | IsReachableFromGpu (MemoryType mt) |
| Returns true if the given buffer type can be reached from the GPU. | |
| bool | IsFastFromCpu (MemoryType mt) |
| Returns true if the given buffer type is fast to access from the CPU. | |
| bool | IsFastFromGpu (MemoryType mt) |
| Returns true if the given buffer type is fast to access from the GPU. | |
Protected Attributes | |
| AlignedAllocator< T, 32 > | m_cpuAllocator |
| MemoryType | m_cpuMemoryType |
| Type of the CPU-side buffer. | |
| MemoryType | m_gpuMemoryType |
| Type of the GPU-side buffer. | |
| T * | m_cpuPtr |
| CPU-side mapped pointer. | |
| std::unique_ptr< vk::raii::DeviceMemory > | m_cpuPhysMem |
| CPU-side physical memory. | |
| std::unique_ptr< vk::raii::DeviceMemory > | m_gpuPhysMem |
| GPU-side physical memory. | |
| std::unique_ptr< vk::raii::Buffer > | m_cpuBuffer |
| Buffer object for CPU-side memory. | |
| std::unique_ptr< vk::raii::Buffer > | m_gpuBuffer |
| Buffer object for GPU-side memory. | |
| bool | m_buffersAreSame |
| True if we have only one piece of physical memory accessible from both sides. | |
| bool | m_cpuPhysMemIsStale |
| True if m_cpuPtr contains stale data (m_gpuPhysMem has been modified and they point to different memory) | |
| bool | m_gpuPhysMemIsStale |
| True if m_gpuPhysMem contains stale data (m_cpuPtr has been modified and they point to different memory) | |
| int | m_tempFileHandle |
| File handle used for MEM_TYPE_CPU_PAGED. | |
| UsageHint | m_cpuAccessHint |
| Hint about how likely future CPU access is. | |
| UsageHint | m_gpuAccessHint |
| Hint about how likely future GPU access is. | |
Protected Attributes inherited from AcceleratorBufferBase | |
| std::string | m_name |
| Friendly name of the buffer (for debug tools) | |
Additional Inherited Members | |
Static Public Member Functions inherited from AcceleratorBufferBase | |
| static std::recursive_mutex & | GetMutex () |
| Get the mutex for m_objectList. | |
| static const std::set< AcceleratorBufferBase * > & | GetObjects () |
| Get the set of all objects. You must hold a lock on m_objectListMutex while working with it. | |
Static Protected Attributes inherited from AcceleratorBufferBase | |
| static std::recursive_mutex | m_objectListMutex |
| Mutex controlling access to m_objectList. | |
| static std::set< AcceleratorBufferBase * > | m_objectList |
| Set of all existing AcceleratorBufferBase objects. | |
A buffer of memory which may be used by GPU acceleration.
At any given point in time the buffer may exist as a single copy on the CPU, a single copy on the GPU, or mirrored buffers on both sides.
Hints can be provided to the buffer about future usage patterns to optimize storage location for best performance.
This buffer generally provides std::vector semantics, but does not initialize memory or call constructors on elements when calling resize() or reserve() unless the element type is not trivially copyable. All locations not explicitly written to have undefined values. Most notably, allocated buffer space between size() and capacity() is undefined and its value may not be coherent between CPU and GPU view of the buffer.
If the element type is not trivially copyable, the data cannot be shared with the GPU. This class still supports non-trivially-copyable types as a convenience for working with waveforms on the CPU.
| AcceleratorBuffer< T >::__attribute__ | ( | (noinline) | ) | const & |
Copies our content from another AcceleratorBuffer.
TODO perf counters
|
inline |
Starts a host-to-device transfer if we need to do one.
|
inline |
Returns the preferred buffer for GPU-side access.
This is the GPU buffer if we have one, otherwise the CPU buffer.
Gets the size of each entry in the container.
Implements AcceleratorBufferBase.
|
inlinevirtual |
Gets the underlying C++ object type.
Implements AcceleratorBufferBase.
Change the usable size of the container.
| size | New size |
| exactSize | True if we want to allocate exactly the requested size rather than rounding up |