Stimulus[Buffer|Frame]: initial impl, unoptimized for mem use
This commit is contained in:
@@ -2,13 +2,15 @@
|
|||||||
#define _SP_MC_RING_BUFFER_H
|
#define _SP_MC_RING_BUFFER_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <algorithm>
|
#include <string>
|
||||||
|
#include <new>
|
||||||
|
#include <user/stimulusFrame.h>
|
||||||
#include <user/sequenceLock.h>
|
#include <user/sequenceLock.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
|
namespace stim_buff {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Single-producer, multi-consumer ring buffer w/per-slot sequence locks
|
* @brief Single-producer, multi-consumer ring buffer w/per-slot sequence locks
|
||||||
@@ -20,120 +22,83 @@ namespace smo {
|
|||||||
*/
|
*/
|
||||||
class SpMcRingBuffer
|
class SpMcRingBuffer
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
class InputEngineConstraints
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
InputEngineConstraints(
|
|
||||||
size_t slotStartAlignmentNBytes_,
|
|
||||||
size_t slotPadToNBytes_)
|
|
||||||
: slotStartAlignmentNBytes(slotStartAlignmentNBytes_),
|
|
||||||
slotPadToNBytes(slotPadToNBytes_)
|
|
||||||
{}
|
|
||||||
|
|
||||||
~InputEngineConstraints() = default;
|
|
||||||
|
|
||||||
// Input-engine layout/constraints
|
|
||||||
size_t slotStartAlignmentNBytes; // power-of-2 alignment (e.g., 4096)
|
|
||||||
size_t slotPadToNBytes; // minimum size per slot
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** EXPLANATION:
|
/** EXPLANATION:
|
||||||
* Constructor initializes the ring buffer with the given constraints and
|
* Constructor initializes the ring buffer with the given constraints and
|
||||||
* number of slots. Calculates stride and allocates data buffer and sequence
|
* number of buffers. Allocates slots vector with properly constructed
|
||||||
* locks array.
|
* StimulusFrame instances.
|
||||||
*/
|
*/
|
||||||
explicit SpMcRingBuffer(
|
explicit SpMcRingBuffer(
|
||||||
size_t nSlots_,
|
size_t nBuffers_,
|
||||||
const InputEngineConstraints& constraints_)
|
const StagingBuffer::IOEngineConstraints& inputEngineConstraints,
|
||||||
: nSlots(nSlots_), strideNBytes(0), bufferNBytes(0),
|
const StagingBuffer::IOEngineConstraints& outputEngineConstraints,
|
||||||
constraints(constraints_)
|
size_t nSlotsPerStimFrame)
|
||||||
|
: nBuffers(nBuffers_),
|
||||||
|
// Default-construct all frames
|
||||||
|
slots(nBuffers)
|
||||||
{
|
{
|
||||||
if (nSlots == 0)
|
if (nBuffers == 0)
|
||||||
{
|
{
|
||||||
throw std::invalid_argument(std::string(__func__)
|
throw std::invalid_argument(std::string(__func__)
|
||||||
+ ": SpMcRingBuffer: nSlots must be > 0");
|
+ ": SpMcRingBuffer: nBuffers must be > 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
computeStrideAndBufferSize();
|
// Re-invoke constructors w/placement new on default-constructed frames
|
||||||
// Allocate data buffer: bufferNBytes (aligned up to alignment)
|
for (size_t i = 0; i < nBuffers; ++i)
|
||||||
data.resize(bufferNBytes);
|
{
|
||||||
// Initialize sequence locks array: one lock per slot
|
slots[i].~StimulusFrame(); // Destroy default-constructed object
|
||||||
// Use unique_ptr array since SequenceLock is not copyable or movable
|
new (&slots[i]) StimulusFrame(
|
||||||
sequenceLocks = std::make_unique<SequenceLock[]>(nSlots);
|
inputEngineConstraints, outputEngineConstraints,
|
||||||
|
nSlotsPerStimFrame);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~SpMcRingBuffer() = default;
|
~SpMcRingBuffer() = default;
|
||||||
|
|
||||||
// Non-copyable, movable
|
// Non-copyable, non-movable (slots are non-movable)
|
||||||
SpMcRingBuffer(const SpMcRingBuffer&) = delete;
|
SpMcRingBuffer(const SpMcRingBuffer&) = delete;
|
||||||
SpMcRingBuffer& operator=(const SpMcRingBuffer&) = delete;
|
SpMcRingBuffer& operator=(const SpMcRingBuffer&) = delete;
|
||||||
SpMcRingBuffer(SpMcRingBuffer&&) = default;
|
SpMcRingBuffer(SpMcRingBuffer&&) = delete;
|
||||||
SpMcRingBuffer& operator=(SpMcRingBuffer&&) = default;
|
SpMcRingBuffer& operator=(SpMcRingBuffer&&) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Get a reference to data at the specified slot
|
* @brief Get a reference to the StimulusFrame at the specified slot
|
||||||
*
|
*
|
||||||
* @tparam T The type of data stored in the slot
|
|
||||||
* @param slotIndex The index of the slot (0-based)
|
* @param slotIndex The index of the slot (0-based)
|
||||||
* @return Reference to T at the slot
|
* @return Reference to StimulusFrame at the slot
|
||||||
* @throws std::out_of_range if slotIndex >= nSlots
|
* @throws std::out_of_range if slotIndex >= nBuffers
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
StimulusFrame& getDataAtSlot(size_t slotIndex)
|
||||||
T& getDataAtSlot(size_t slotIndex)
|
|
||||||
{
|
{
|
||||||
if (slotIndex >= nSlots)
|
if (slotIndex >= nBuffers)
|
||||||
{
|
{
|
||||||
throw std::out_of_range(std::string(__func__)
|
throw std::out_of_range(std::string(__func__)
|
||||||
+ ": SpMcRingBuffer: slotIndex must be < nSlots");
|
+ ": SpMcRingBuffer: slotIndex must be < nBuffers");
|
||||||
}
|
}
|
||||||
|
return slots[slotIndex];
|
||||||
size_t offset = slotIndex * strideNBytes;
|
|
||||||
return *reinterpret_cast<T*>(data.data() + offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SequenceLock& getSequenceLockAtSlot(size_t slotIndex)
|
SequenceLock& getSequenceLockAtSlot(size_t slotIndex)
|
||||||
{
|
{
|
||||||
if (slotIndex >= nSlots)
|
if (slotIndex >= nBuffers)
|
||||||
{
|
{
|
||||||
throw std::out_of_range(std::string(__func__)
|
throw std::out_of_range(std::string(__func__)
|
||||||
+ ": SpMcRingBuffer: slotIndex must be < nSlots");
|
+ ": SpMcRingBuffer: slotIndex must be < nBuffers");
|
||||||
}
|
}
|
||||||
return sequenceLocks[slotIndex];
|
return slots[slotIndex].lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
void computeStrideAndBufferSize()
|
|
||||||
{
|
|
||||||
// Stride is the maximum of alignment and padding
|
|
||||||
strideNBytes = std::max(
|
|
||||||
constraints.slotStartAlignmentNBytes,
|
|
||||||
constraints.slotPadToNBytes);
|
|
||||||
|
|
||||||
// Buffer size is nSlots * strideNBytes, aligned up to alignment
|
|
||||||
size_t rawSize = nSlots * strideNBytes;
|
|
||||||
bufferNBytes = ((rawSize + constraints.slotStartAlignmentNBytes - 1)
|
|
||||||
/ constraints.slotStartAlignmentNBytes)
|
|
||||||
* constraints.slotStartAlignmentNBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Buffer data
|
|
||||||
std::vector<uint8_t> data;
|
|
||||||
|
|
||||||
// Sequence locks array: one lock per slot
|
|
||||||
// Use unique_ptr array since SequenceLock is not copyable or movable
|
|
||||||
std::unique_ptr<SequenceLock[]> sequenceLocks;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Layout/invariants
|
// Layout/invariants
|
||||||
size_t nSlots;
|
size_t nBuffers;
|
||||||
size_t strideNBytes;
|
|
||||||
size_t bufferNBytes;
|
private:
|
||||||
InputEngineConstraints constraints;
|
// Frames vector: each frame contains a sequence lock and staging buffer
|
||||||
|
std::vector<StimulusFrame> slots;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace stim_buff
|
||||||
} // namespace smo
|
} // namespace smo
|
||||||
|
|
||||||
#endif // _SP_MC_RING_BUFFER_H
|
#endif // _SP_MC_RING_BUFFER_H
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ public:
|
|||||||
class IOEngineConstraints
|
class IOEngineConstraints
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
// Default constructor creates uninitialized constraints
|
||||||
|
IOEngineConstraints() = default;
|
||||||
|
|
||||||
IOEngineConstraints(
|
IOEngineConstraints(
|
||||||
size_t slotStartAlignmentByteVal_,
|
size_t slotStartAlignmentByteVal_,
|
||||||
size_t slotPadToNBytes_,
|
size_t slotPadToNBytes_,
|
||||||
@@ -65,6 +68,12 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** EXPLANATION:
|
||||||
|
* Default constructor creates uninitialized buffer.
|
||||||
|
* Must be properly initialized using placement new with the parameterized constructor.
|
||||||
|
*/
|
||||||
|
StagingBuffer() = default;
|
||||||
|
|
||||||
/** EXPLANATION:
|
/** EXPLANATION:
|
||||||
* We use the input and output engine constraints to determine the total
|
* We use the input and output engine constraints to determine the total
|
||||||
* amount of memory required internally to assemble a single frame with
|
* amount of memory required internally to assemble a single frame with
|
||||||
@@ -144,6 +153,8 @@ private:
|
|||||||
struct MmapDeleter
|
struct MmapDeleter
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
|
// Default constructor for use with default-constructed StagingBuffer
|
||||||
|
MmapDeleter() : size(0) {}
|
||||||
MmapDeleter(size_t s) : size(s) {}
|
MmapDeleter(size_t s) : size(s) {}
|
||||||
|
|
||||||
void operator()(uint8_t* ptr) const
|
void operator()(uint8_t* ptr) const
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <user/spMcRingBuffer.h>
|
#include <user/spMcRingBuffer.h>
|
||||||
|
#include <user/stagingBuffer.h>
|
||||||
#include "stimulusFrame.h"
|
#include "stimulusFrame.h"
|
||||||
#include "deviceAttachmentSpec.h"
|
#include "deviceAttachmentSpec.h"
|
||||||
|
|
||||||
@@ -28,15 +29,16 @@ public:
|
|||||||
const std::shared_ptr<device::DeviceAttachmentSpec>
|
const std::shared_ptr<device::DeviceAttachmentSpec>
|
||||||
&deviceAttachmentSpec,
|
&deviceAttachmentSpec,
|
||||||
int histbuffMs,
|
int histbuffMs,
|
||||||
const SpMcRingBuffer::InputEngineConstraints& ringBufferConstraints)
|
const StagingBuffer::IOEngineConstraints& inputEngineConstraints,
|
||||||
|
const StagingBuffer::IOEngineConstraints& outputEngineConstraints,
|
||||||
|
size_t nSlotsPerStimFrame)
|
||||||
: parent(parent),
|
: parent(parent),
|
||||||
deviceAttachmentSpec(deviceAttachmentSpec),
|
deviceAttachmentSpec(deviceAttachmentSpec),
|
||||||
histbuffMs(histbuffMs),
|
histbuffMs(histbuffMs),
|
||||||
frames_(static_cast<size_t>(histbuffMs / CONFIG_STIMBUFF_FRAME_PERIOD_MS)),
|
|
||||||
ringBufferConstraints(ringBufferConstraints),
|
|
||||||
ringBuffer(
|
ringBuffer(
|
||||||
static_cast<size_t>(histbuffMs / CONFIG_STIMBUFF_FRAME_PERIOD_MS),
|
static_cast<size_t>(histbuffMs / CONFIG_STIMBUFF_FRAME_PERIOD_MS),
|
||||||
ringBufferConstraints)
|
inputEngineConstraints, outputEngineConstraints,
|
||||||
|
nSlotsPerStimFrame)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual ~StimulusBuffer() = default;
|
virtual ~StimulusBuffer() = default;
|
||||||
@@ -51,10 +53,6 @@ public:
|
|||||||
StimulusProducer& parent;
|
StimulusProducer& parent;
|
||||||
std::shared_ptr<device::DeviceAttachmentSpec> deviceAttachmentSpec;
|
std::shared_ptr<device::DeviceAttachmentSpec> deviceAttachmentSpec;
|
||||||
int histbuffMs;
|
int histbuffMs;
|
||||||
std::vector<StimulusFrame> frames_;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
SpMcRingBuffer::InputEngineConstraints ringBufferConstraints;
|
|
||||||
SpMcRingBuffer ringBuffer;
|
SpMcRingBuffer ringBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#define _ATTACHMENT_SUPPORT_STIMULUS_FRAME_H
|
#define _ATTACHMENT_SUPPORT_STIMULUS_FRAME_H
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <user/stagingBuffer.h>
|
||||||
|
#include <user/sequenceLock.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
namespace stim_buff {
|
namespace stim_buff {
|
||||||
@@ -61,7 +63,32 @@ typedef uint64_t SimultaneityStamp;
|
|||||||
class StimulusFrame
|
class StimulusFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/** EXPLANATION:
|
||||||
|
* Default constructor creates uninitialized frame.
|
||||||
|
* Must be properly initialized using placement new with the parameterized constructor.
|
||||||
|
*/
|
||||||
|
StimulusFrame() = default;
|
||||||
|
|
||||||
|
StimulusFrame(
|
||||||
|
const StagingBuffer::IOEngineConstraints& inputEngineConstraints,
|
||||||
|
const StagingBuffer::IOEngineConstraints& outputEngineConstraints,
|
||||||
|
size_t nSlots)
|
||||||
|
: stagingBuffer(
|
||||||
|
inputEngineConstraints, outputEngineConstraints, nSlots)
|
||||||
|
{}
|
||||||
|
|
||||||
|
~StimulusFrame() = default;
|
||||||
|
|
||||||
|
// Non-copyable, movable
|
||||||
|
StimulusFrame(const StimulusFrame&) = delete;
|
||||||
|
StimulusFrame& operator=(const StimulusFrame&) = delete;
|
||||||
|
StimulusFrame(StimulusFrame&&) = default;
|
||||||
|
StimulusFrame& operator=(StimulusFrame&&) = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SequenceLock lock;
|
||||||
SimultaneityStamp simultaneityStamp;
|
SimultaneityStamp simultaneityStamp;
|
||||||
|
StagingBuffer stagingBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace stim_buff
|
} // namespace stim_buff
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <user/stimulusBuffer.h>
|
#include <user/stimulusBuffer.h>
|
||||||
|
#include <user/stagingBuffer.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
namespace stim_buff {
|
namespace stim_buff {
|
||||||
@@ -21,9 +22,12 @@ public:
|
|||||||
StimulusProducer& parent,
|
StimulusProducer& parent,
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec>& deviceAttachmentSpec,
|
const std::shared_ptr<device::DeviceAttachmentSpec>& deviceAttachmentSpec,
|
||||||
int histbuffMs,
|
int histbuffMs,
|
||||||
const SpMcRingBuffer::InputEngineConstraints& ringBufferConstraints)
|
const StagingBuffer::IOEngineConstraints& inputEngineConstraints,
|
||||||
|
const StagingBuffer::IOEngineConstraints& outputEngineConstraints,
|
||||||
|
size_t nSlotsPerStimFrame)
|
||||||
: StimulusBuffer(
|
: StimulusBuffer(
|
||||||
parent, deviceAttachmentSpec, histbuffMs, ringBufferConstraints)
|
parent, deviceAttachmentSpec, histbuffMs,
|
||||||
|
inputEngineConstraints, outputEngineConstraints, nSlotsPerStimFrame)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~MeshStimulusBuffer() = default;
|
~MeshStimulusBuffer() = default;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <user/stimulusBuffer.h>
|
#include <user/stimulusBuffer.h>
|
||||||
|
#include <user/stagingBuffer.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
namespace stim_buff {
|
namespace stim_buff {
|
||||||
@@ -21,9 +22,12 @@ public:
|
|||||||
StimulusProducer& parent,
|
StimulusProducer& parent,
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec>& deviceAttachmentSpec,
|
const std::shared_ptr<device::DeviceAttachmentSpec>& deviceAttachmentSpec,
|
||||||
int histbuffMs,
|
int histbuffMs,
|
||||||
const SpMcRingBuffer::InputEngineConstraints& ringBufferConstraints)
|
const StagingBuffer::IOEngineConstraints& inputEngineConstraints,
|
||||||
|
const StagingBuffer::IOEngineConstraints& outputEngineConstraints,
|
||||||
|
size_t nSlotsPerStimFrame)
|
||||||
: StimulusBuffer(
|
: StimulusBuffer(
|
||||||
parent, deviceAttachmentSpec, histbuffMs, ringBufferConstraints)
|
parent, deviceAttachmentSpec, histbuffMs,
|
||||||
|
inputEngineConstraints, outputEngineConstraints, nSlotsPerStimFrame)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~PcloudAmbienceStimulusBuffer() = default;
|
~PcloudAmbienceStimulusBuffer() = default;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <user/stimulusBuffer.h>
|
#include <user/stimulusBuffer.h>
|
||||||
|
#include <user/stagingBuffer.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
namespace stim_buff {
|
namespace stim_buff {
|
||||||
@@ -22,9 +23,12 @@ public:
|
|||||||
const std::shared_ptr<device::DeviceAttachmentSpec>
|
const std::shared_ptr<device::DeviceAttachmentSpec>
|
||||||
&deviceAttachmentSpec,
|
&deviceAttachmentSpec,
|
||||||
int histbuffMs,
|
int histbuffMs,
|
||||||
const SpMcRingBuffer::InputEngineConstraints& ringBufferConstraints)
|
const StagingBuffer::IOEngineConstraints& inputEngineConstraints,
|
||||||
|
const StagingBuffer::IOEngineConstraints& outputEngineConstraints,
|
||||||
|
size_t nSlotsPerStimFrame)
|
||||||
: StimulusBuffer(
|
: StimulusBuffer(
|
||||||
parent, deviceAttachmentSpec, histbuffMs, ringBufferConstraints)
|
parent, deviceAttachmentSpec, histbuffMs,
|
||||||
|
inputEngineConstraints, outputEngineConstraints, nSlotsPerStimFrame)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~PcloudIntensityStimulusBuffer() = default;
|
~PcloudIntensityStimulusBuffer() = default;
|
||||||
|
|||||||
@@ -7,8 +7,9 @@
|
|||||||
#include <componentThread.h>
|
#include <componentThread.h>
|
||||||
#include <asynchronousLoop.h>
|
#include <asynchronousLoop.h>
|
||||||
#include <user/stimulusFrame.h>
|
#include <user/stimulusFrame.h>
|
||||||
#include "pcloudStimulusProducer.h"
|
|
||||||
#include <user/frameAssemblyDesc.h>
|
#include <user/frameAssemblyDesc.h>
|
||||||
|
#include <livoxProto1/device.h>
|
||||||
|
#include "pcloudStimulusProducer.h"
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
namespace stim_buff {
|
namespace stim_buff {
|
||||||
@@ -16,8 +17,15 @@ namespace stim_buff {
|
|||||||
extern const SmoCallbacks* smoHooksPtr;
|
extern const SmoCallbacks* smoHooksPtr;
|
||||||
|
|
||||||
// OpenCL kernels are used to collate and produce our StimFrames.
|
// OpenCL kernels are used to collate and produce our StimFrames.
|
||||||
static SpMcRingBuffer::InputEngineConstraints openClInputConstraints(
|
static StagingBuffer::IOEngineConstraints openClInputConstraints(
|
||||||
static_cast<size_t>(sysconf(_SC_PAGE_SIZE)), sizeof(void *));
|
// slotStartAlignmentByteVal (page alignment)
|
||||||
|
sizeof(float) * 3,
|
||||||
|
// slotPadToNBytes (pointer size)
|
||||||
|
sizeof(void *),
|
||||||
|
// frameStartAlignmentByteVal (page alignment)
|
||||||
|
static_cast<size_t>(sysconf(_SC_PAGE_SIZE)),
|
||||||
|
// framePadToNBytes (pointer size)
|
||||||
|
static_cast<size_t>(sysconf(_SC_PAGE_SIZE)));
|
||||||
|
|
||||||
static StagingBuffer::IOEngineConstraints openClIntensityInputConstraints(
|
static StagingBuffer::IOEngineConstraints openClIntensityInputConstraints(
|
||||||
// slotStartAlignmentByteVal (page alignment)
|
// slotStartAlignmentByteVal (page alignment)
|
||||||
@@ -27,7 +35,17 @@ static StagingBuffer::IOEngineConstraints openClIntensityInputConstraints(
|
|||||||
// frameStartAlignmentByteVal (page alignment)
|
// frameStartAlignmentByteVal (page alignment)
|
||||||
static_cast<size_t>(sysconf(_SC_PAGE_SIZE)),
|
static_cast<size_t>(sysconf(_SC_PAGE_SIZE)),
|
||||||
// framePadToNBytes (pointer size)
|
// framePadToNBytes (pointer size)
|
||||||
sizeof(void *));
|
static_cast<size_t>(sysconf(_SC_PAGE_SIZE)));
|
||||||
|
|
||||||
|
static StagingBuffer::IOEngineConstraints openClAmbienceInputConstraints(
|
||||||
|
// slotStartAlignmentByteVal (page alignment)
|
||||||
|
sizeof(float),
|
||||||
|
// slotPadToNBytes (pointer size)
|
||||||
|
sizeof(void *),
|
||||||
|
// frameStartAlignmentByteVal (page alignment)
|
||||||
|
static_cast<size_t>(sysconf(_SC_PAGE_SIZE)),
|
||||||
|
// framePadToNBytes (pointer size)
|
||||||
|
static_cast<size_t>(sysconf(_SC_PAGE_SIZE)));
|
||||||
|
|
||||||
PcloudStimulusProducer::PcloudStimulusProducer(
|
PcloudStimulusProducer::PcloudStimulusProducer(
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec> &deviceAttachmentSpec,
|
const std::shared_ptr<device::DeviceAttachmentSpec> &deviceAttachmentSpec,
|
||||||
@@ -37,6 +55,7 @@ PcloudStimulusProducer::PcloudStimulusProducer(
|
|||||||
: StimulusProducer(
|
: StimulusProducer(
|
||||||
deviceAttachmentSpec,
|
deviceAttachmentSpec,
|
||||||
device->componentThread->getIoService()),
|
device->componentThread->getIoService()),
|
||||||
|
nDgramsPerStagingBufferFrame(nDgramsPerStagingBufferFrame),
|
||||||
device(device),
|
device(device),
|
||||||
formatDesc(formatDesc),
|
formatDesc(formatDesc),
|
||||||
openClCollatingAndMeshingEngine(*this),
|
openClCollatingAndMeshingEngine(*this),
|
||||||
@@ -46,6 +65,10 @@ assemblyBuffer(
|
|||||||
nDgramsPerStagingBufferFrame),
|
nDgramsPerStagingBufferFrame),
|
||||||
ioUringAssemblyEngine(*this, nDgramsPerStagingBufferFrame),
|
ioUringAssemblyEngine(*this, nDgramsPerStagingBufferFrame),
|
||||||
collationBuffer(
|
collationBuffer(
|
||||||
|
StagingBuffer::IOEngineConstraints::openClInputConstraints,
|
||||||
|
StagingBuffer::IOEngineConstraints::openClInputConstraints,
|
||||||
|
nDgramsPerStagingBufferFrame),
|
||||||
|
tempStimulusFrame(
|
||||||
StagingBuffer::IOEngineConstraints::openClInputConstraints,
|
StagingBuffer::IOEngineConstraints::openClInputConstraints,
|
||||||
StagingBuffer::IOEngineConstraints::openClInputConstraints,
|
StagingBuffer::IOEngineConstraints::openClInputConstraints,
|
||||||
nDgramsPerStagingBufferFrame)
|
nDgramsPerStagingBufferFrame)
|
||||||
@@ -181,30 +204,47 @@ PcloudStimulusProducer::getOrCreateAttachedStimulusBuffer(
|
|||||||
// Parse qualeIfaceApi to determine buffer type
|
// Parse qualeIfaceApi to determine buffer type
|
||||||
const std::string& qualeIfaceApi = deviceAttachmentSpec->qualeIfaceApi;
|
const std::string& qualeIfaceApi = deviceAttachmentSpec->qualeIfaceApi;
|
||||||
|
|
||||||
|
// Calculate nPointsPerStimFrame based on return mode
|
||||||
|
size_t nPointsPerDgram = livoxProto1::Device::getNPointsPerDgram(
|
||||||
|
static_cast<int>(device->currentReturnMode));
|
||||||
|
size_t nPointsPerStimFrame = this->nDgramsPerStagingBufferFrame
|
||||||
|
* nPointsPerDgram;
|
||||||
|
|
||||||
if (qualeIfaceApi == "mesh")
|
if (qualeIfaceApi == "mesh")
|
||||||
{
|
{
|
||||||
|
std::cout << __func__ << ": $$$$$$$ Creating MeshStimulusBuffer" << std::endl;
|
||||||
auto meshBuffer = std::make_shared<MeshStimulusBuffer>(
|
auto meshBuffer = std::make_shared<MeshStimulusBuffer>(
|
||||||
*this, deviceAttachmentSpec, histbuffMs, openClInputConstraints);
|
*this, deviceAttachmentSpec, histbuffMs,
|
||||||
|
openClInputConstraints, openClInputConstraints,
|
||||||
|
nPointsPerStimFrame);
|
||||||
|
|
||||||
|
std::cout << __func__ << ": $$$$$$$ Created MeshStimulusBuffer" << std::endl;
|
||||||
meshStimulusBuffer = meshBuffer;
|
meshStimulusBuffer = meshBuffer;
|
||||||
attachedStimulusBuffers.push_back(meshBuffer);
|
attachedStimulusBuffers.push_back(meshBuffer);
|
||||||
return meshBuffer;
|
return meshBuffer;
|
||||||
}
|
}
|
||||||
else if (qualeIfaceApi == "pcloudIntensity")
|
else if (qualeIfaceApi == "pcloudIntensity")
|
||||||
{
|
{
|
||||||
|
std::cout << __func__ << ": $$$$$$$ Creating PcloudIntensityStimulusBuffer" << std::endl;
|
||||||
auto intensityBuffer = std::make_shared<PcloudIntensityStimulusBuffer>(
|
auto intensityBuffer = std::make_shared<PcloudIntensityStimulusBuffer>(
|
||||||
*this, deviceAttachmentSpec, histbuffMs,
|
*this, deviceAttachmentSpec, histbuffMs,
|
||||||
openClInputConstraints);
|
openClIntensityInputConstraints, openClIntensityInputConstraints,
|
||||||
|
nPointsPerStimFrame);
|
||||||
|
|
||||||
|
std::cout << __func__ << ": $$$$$$$ Created PcloudIntensityStimulusBuffer" << std::endl;
|
||||||
intensityStimulusBuffer = intensityBuffer;
|
intensityStimulusBuffer = intensityBuffer;
|
||||||
attachedStimulusBuffers.push_back(intensityBuffer);
|
attachedStimulusBuffers.push_back(intensityBuffer);
|
||||||
return intensityBuffer;
|
return intensityBuffer;
|
||||||
}
|
}
|
||||||
else if (qualeIfaceApi == "pcloudAmbience")
|
else if (qualeIfaceApi == "pcloudAmbience")
|
||||||
{
|
{
|
||||||
|
std::cout << __func__ << ": $$$$$$$ Creating PcloudAmbienceStimulusBuffer" << std::endl;
|
||||||
auto ambienceBuffer = std::make_shared<PcloudAmbienceStimulusBuffer>(
|
auto ambienceBuffer = std::make_shared<PcloudAmbienceStimulusBuffer>(
|
||||||
*this, deviceAttachmentSpec, histbuffMs, openClInputConstraints);
|
*this, deviceAttachmentSpec, histbuffMs,
|
||||||
|
openClAmbienceInputConstraints, openClAmbienceInputConstraints,
|
||||||
|
nDgramsPerStagingBufferFrame);
|
||||||
|
|
||||||
|
std::cout << __func__ << ": $$$$$$$ Created PcloudAmbienceStimulusBuffer" << std::endl;
|
||||||
ambienceStimulusBuffer = ambienceBuffer;
|
ambienceStimulusBuffer = ambienceBuffer;
|
||||||
attachedStimulusBuffers.push_back(ambienceBuffer);
|
attachedStimulusBuffers.push_back(ambienceBuffer);
|
||||||
return ambienceBuffer;
|
return ambienceBuffer;
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ protected:
|
|||||||
public:
|
public:
|
||||||
void produceFrameReq(smo::Callback<produceFrameReqCbFn> callback);
|
void produceFrameReq(smo::Callback<produceFrameReqCbFn> callback);
|
||||||
|
|
||||||
|
size_t nDgramsPerStagingBufferFrame;
|
||||||
std::shared_ptr<livoxProto1::Device> device;
|
std::shared_ptr<livoxProto1::Device> device;
|
||||||
PcloudFormatDesc formatDesc;
|
PcloudFormatDesc formatDesc;
|
||||||
OpenClCollatingAndMeshingEngine openClCollatingAndMeshingEngine;
|
OpenClCollatingAndMeshingEngine openClCollatingAndMeshingEngine;
|
||||||
|
|||||||
Reference in New Issue
Block a user