Gaia-ECS v1.0.0
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::mem::data_view_policy_soa< TDataLayout, ValueType > Struct Template Reference

View policy for accessing and storing data in the SoA way. Good for SIMD processing. More...

#include <data_layout_policy.h>

Classes

class  accessor
 Proxy used to read or assign one complete SoA value. More...
 

Public Types

using TTuple = decltype(meta::struct_to_tuple(std::declval< ValueType >()))
 Tuple representation of the reflected value fields.
 
using TargetCastType = uint8_t *
 Pointer type used to address SoA storage.
 
template<size_t Item>
using value_type = typename std::tuple_element< Item, TTuple >::type
 Type of a reflected field.
 
template<size_t Item>
using const_value_type = typename std::add_const< value_type< Item > >::type
 Const-qualified type of a reflected field.
 

Static Public Member Functions

GAIA_NODISCARD static constexpr uint32_t get_min_byte_size (uintptr_t addr, size_t cnt) noexcept
 Calculates the bytes required for an SoA value range.
 
template<typename Allocator >
static GAIA_NODISCARD uint8_t * alloc (size_t cnt) noexcept
 Allocates an SoA value range.
 
template<typename Allocator >
static void free (void *pData, size_t cap, size_t cnt) noexcept
 Releases an instrumented SoA value range.
 
static void mem_add_block (void *pData, size_t cap, size_t count)
 Registers a newly allocated SoA range with the memory sanitizer.
 
static void mem_del_block (void *pData, size_t cap, size_t count)
 Unregisters an SoA range from the memory sanitizer.
 
static void mem_push_block (void *pData, size_t cap, size_t count, size_t n)
 Makes newly appended SoA values addressable by the memory sanitizer.
 
static void mem_pop_block (void *pData, size_t cap, size_t count, size_t n)
 Poisons removed SoA values for the memory sanitizer.
 
GAIA_NODISCARD static constexpr ValueType get (std::span< const uint8_t > s, size_t idx) noexcept
 Reconstructs a value from its SoA fields.
 
template<size_t Item>
GAIA_NODISCARD static constexpr auto get (std::span< const uint8_t > s, size_t idx=0) noexcept
 Returns a read-only span over one SoA field.
 
GAIA_NODISCARD static constexpr auto set (std::span< uint8_t > s, size_t idx) noexcept
 Returns a mutable proxy for one complete value.
 
template<size_t Item>
GAIA_NODISCARD static constexpr auto set (std::span< uint8_t > s, size_t idx=0) noexcept
 Returns a mutable span over one SoA field.
 

Static Public Attributes

static constexpr DataLayout Layout = data_layout_properties<TDataLayout, ValueType>::Layout
 Physical layout.
 
static constexpr size_t Alignment = data_layout_properties<TDataLayout, ValueType>::Alignment
 Required byte alignment.
 
static constexpr size_t TTupleItems = std::tuple_size<TTuple>::value
 Number of reflected fields.
 

Detailed Description

template<DataLayout TDataLayout, typename ValueType>
struct gaia::mem::data_view_policy_soa< TDataLayout, ValueType >

View policy for accessing and storing data in the SoA way. Good for SIMD processing.

struct Foo { int x; int y; int z; }; using fooViewPolicy = data_view_policy<DataLayout::SoA, Foo>;

Memory organized as: xxxx yyyy zzzz

Member Typedef Documentation

◆ const_value_type

template<DataLayout TDataLayout, typename ValueType >
template<size_t Item>
using gaia::mem::data_view_policy_soa< TDataLayout, ValueType >::const_value_type = typename std::add_const<value_type<Item> >::type

Const-qualified type of a reflected field.

Template Parameters
ItemField index.

◆ value_type

template<DataLayout TDataLayout, typename ValueType >
template<size_t Item>
using gaia::mem::data_view_policy_soa< TDataLayout, ValueType >::value_type = typename std::tuple_element<Item, TTuple>::type

Type of a reflected field.

Template Parameters
ItemField index.

Member Function Documentation

◆ alloc()

template<DataLayout TDataLayout, typename ValueType >
template<typename Allocator >
static GAIA_NODISCARD uint8_t * gaia::mem::data_view_policy_soa< TDataLayout, ValueType >::alloc ( size_t  cnt)
inlinestaticnoexcept

Allocates an SoA value range.

Template Parameters
AllocatorAllocator adaptor type.
Parameters
cntNumber of values.
Returns
Allocated byte buffer.

◆ free()

template<DataLayout TDataLayout, typename ValueType >
template<typename Allocator >
static void gaia::mem::data_view_policy_soa< TDataLayout, ValueType >::free ( void *  pData,
size_t  cap,
size_t  cnt 
)
inlinestaticnoexcept

Releases an instrumented SoA value range.

Template Parameters
AllocatorAllocator adaptor type.
Parameters
pDataAllocated buffer, or null.
capBuffer capacity in values.
cntNumber of live values.

◆ get() [1/2]

template<DataLayout TDataLayout, typename ValueType >
GAIA_NODISCARD static constexpr ValueType gaia::mem::data_view_policy_soa< TDataLayout, ValueType >::get ( std::span< const uint8_t >  s,
size_t  idx 
)
inlinestaticconstexprnoexcept

Reconstructs a value from its SoA fields.

Parameters
sBacking byte span. Its size is the value capacity.
idxValue index.
Returns
Reconstructed value.

◆ get() [2/2]

template<DataLayout TDataLayout, typename ValueType >
template<size_t Item>
GAIA_NODISCARD static constexpr auto gaia::mem::data_view_policy_soa< TDataLayout, ValueType >::get ( std::span< const uint8_t >  s,
size_t  idx = 0 
)
inlinestaticconstexprnoexcept

Returns a read-only span over one SoA field.

Template Parameters
ItemField index.
Parameters
sBacking byte span. Its size is the value capacity.
idxFirst value index.
Returns
Field span beginning at the requested index.

◆ get_min_byte_size()

template<DataLayout TDataLayout, typename ValueType >
GAIA_NODISCARD static constexpr uint32_t gaia::mem::data_view_policy_soa< TDataLayout, ValueType >::get_min_byte_size ( uintptr_t  addr,
size_t  cnt 
)
inlinestaticconstexprnoexcept

Calculates the bytes required for an SoA value range.

Parameters
addrStarting address used for alignment calculations.
cntNumber of values.
Returns
Minimum required byte count.

◆ mem_add_block()

template<DataLayout TDataLayout, typename ValueType >
static void gaia::mem::data_view_policy_soa< TDataLayout, ValueType >::mem_add_block ( void *  pData,
size_t  cap,
size_t  count 
)
inlinestatic

Registers a newly allocated SoA range with the memory sanitizer.

Parameters
pDataBacking buffer.
capBuffer capacity in values.
countNumber of live values.

◆ mem_del_block()

template<DataLayout TDataLayout, typename ValueType >
static void gaia::mem::data_view_policy_soa< TDataLayout, ValueType >::mem_del_block ( void *  pData,
size_t  cap,
size_t  count 
)
inlinestatic

Unregisters an SoA range from the memory sanitizer.

Parameters
pDataBacking buffer.
capBuffer capacity in values.
countNumber of live values.

◆ mem_pop_block()

template<DataLayout TDataLayout, typename ValueType >
static void gaia::mem::data_view_policy_soa< TDataLayout, ValueType >::mem_pop_block ( void *  pData,
size_t  cap,
size_t  count,
size_t  n 
)
inlinestatic

Poisons removed SoA values for the memory sanitizer.

Parameters
pDataBacking buffer.
capBuffer capacity in values.
countCurrent number of live values.
nNumber of values being removed.

◆ mem_push_block()

template<DataLayout TDataLayout, typename ValueType >
static void gaia::mem::data_view_policy_soa< TDataLayout, ValueType >::mem_push_block ( void *  pData,
size_t  cap,
size_t  count,
size_t  n 
)
inlinestatic

Makes newly appended SoA values addressable by the memory sanitizer.

Parameters
pDataBacking buffer.
capBuffer capacity in values.
countCurrent number of live values.
nNumber of values being appended.

◆ set() [1/2]

template<DataLayout TDataLayout, typename ValueType >
GAIA_NODISCARD static constexpr auto gaia::mem::data_view_policy_soa< TDataLayout, ValueType >::set ( std::span< uint8_t >  s,
size_t  idx 
)
inlinestaticconstexprnoexcept

Returns a mutable proxy for one complete value.

Parameters
sBacking byte span. Its size is the value capacity.
idxValue index.
Returns
Mutable value proxy.

◆ set() [2/2]

template<DataLayout TDataLayout, typename ValueType >
template<size_t Item>
GAIA_NODISCARD static constexpr auto gaia::mem::data_view_policy_soa< TDataLayout, ValueType >::set ( std::span< uint8_t >  s,
size_t  idx = 0 
)
inlinestaticconstexprnoexcept

Returns a mutable span over one SoA field.

Template Parameters
ItemField index.
Parameters
sBacking byte span. Its size is the value capacity.
idxFirst value index.
Returns
Field span beginning at the requested index.

The documentation for this struct was generated from the following file: