2025-11-01 00:06:42 -04:00
|
|
|
#include <config.h>
|
2025-10-25 19:28:18 -04:00
|
|
|
#include <opts.h>
|
|
|
|
|
#include <algorithm>
|
2025-11-01 00:06:42 -04:00
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <user/spMcRingBuffer.h>
|
2025-10-31 12:22:07 -04:00
|
|
|
#include <componentThread.h>
|
|
|
|
|
#include "pcloudStimulusBuffer.h"
|
2025-10-25 19:28:18 -04:00
|
|
|
|
|
|
|
|
namespace smo {
|
|
|
|
|
namespace stim_buff {
|
|
|
|
|
|
2025-11-04 00:46:07 -04:00
|
|
|
extern const SmoCallbacks* smoHooksPtr;
|
|
|
|
|
|
2025-11-01 21:33:35 -04:00
|
|
|
// OpenCL kernels are used to collate and produce our StimFrames.
|
|
|
|
|
static SpMcRingBuffer::InputEngineConstraints openClInputConstraints(
|
|
|
|
|
static_cast<size_t>(sysconf(_SC_PAGE_SIZE)), sizeof(void *));
|
|
|
|
|
|
|
|
|
|
PcloudStimulusBuffer::PcloudStimulusBuffer(
|
2025-11-04 00:46:07 -04:00
|
|
|
const std::shared_ptr<device::DeviceAttachmentSpec> &deviceAttachmentSpec,
|
2025-11-01 21:33:35 -04:00
|
|
|
std::shared_ptr<livoxProto1::Device> &device,
|
|
|
|
|
const PcloudFormatDesc& formatDesc,
|
|
|
|
|
int histbuffMs,
|
|
|
|
|
size_t nDgramsPerStagingBufferFrame)
|
|
|
|
|
: StimulusBuffer(
|
|
|
|
|
deviceAttachmentSpec,
|
|
|
|
|
static_cast<size_t>(histbuffMs / CONFIG_STIMBUFF_FRAME_PERIOD_MS),
|
|
|
|
|
openClInputConstraints,
|
|
|
|
|
device->componentThread->getIoService()),
|
2025-11-04 00:46:07 -04:00
|
|
|
device(device),
|
2025-11-01 21:33:35 -04:00
|
|
|
formatDesc(formatDesc), stagingBuffer(
|
|
|
|
|
StagingBuffer::InputEngineConstraints::ioUringConstraints,
|
|
|
|
|
OpenClConstraints(), nDgramsPerStagingBufferFrame),
|
|
|
|
|
ioUringAssemblyEngine(*this)
|
|
|
|
|
{
|
2025-11-04 00:56:46 -04:00
|
|
|
std::cout << __func__ << ": Device's component thread is "
|
|
|
|
|
<< device->componentThread->name << std::endl;
|
|
|
|
|
|
|
|
|
|
#ifndef CONFIG_WORLD_USE_BODY_THREAD
|
|
|
|
|
if (smoHooksPtr->ComponentThread_getSelf()->id != ComponentThread::WORLD)
|
|
|
|
|
#else
|
|
|
|
|
if (smoHooksPtr->ComponentThread_getSelf()->id != ComponentThread::BODY)
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
std::string errMsg = std::string(__func__) +
|
|
|
|
|
": PcloudStimulusBuffer constructor called on non-world/body thread " +
|
|
|
|
|
smoHooksPtr->ComponentThread_getSelf()->name;
|
|
|
|
|
|
|
|
|
|
std::cout << errMsg << std::endl;
|
|
|
|
|
// throw std::runtime_error(errMsg);
|
|
|
|
|
}
|
2025-11-01 21:33:35 -04:00
|
|
|
}
|
|
|
|
|
|
2025-11-01 22:03:28 -04:00
|
|
|
void PcloudStimulusBuffer::start()
|
|
|
|
|
{
|
|
|
|
|
// Call ioUringAssemblyEngine setup() as the final step
|
|
|
|
|
// ioUringAssemblyEngine.setup();
|
|
|
|
|
// Call base class start() as the final step
|
|
|
|
|
StimulusBuffer::start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PcloudStimulusBuffer::stop()
|
|
|
|
|
{
|
|
|
|
|
// Call base class stop() as the first step
|
|
|
|
|
StimulusBuffer::stop();
|
|
|
|
|
// Call ioUringAssemblyEngine stop() as the final step
|
|
|
|
|
// ioUringAssemblyEngine.finalize();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-01 21:33:35 -04:00
|
|
|
void PcloudStimulusBuffer::stimFrameProductionTimesliceInd()
|
|
|
|
|
{
|
|
|
|
|
// Release the spinlock for now
|
|
|
|
|
frameAssemblyRateLimiter.release();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-01 04:14:07 -04:00
|
|
|
class PcloudStimulusBuffer::AssembleAndProduceStimulusFrameReq
|
|
|
|
|
: public smo::PostedAsynchronousContinuation<
|
|
|
|
|
assembleAndProduceStimulusFrameReqCbFn>
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
PcloudStimulusBuffer& stimBuff;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
AssembleAndProduceStimulusFrameReq(
|
|
|
|
|
PcloudStimulusBuffer& buffer,
|
|
|
|
|
Callback<assembleAndProduceStimulusFrameReqCbFn> callback)
|
|
|
|
|
: PostedAsynchronousContinuation<assembleAndProduceStimulusFrameReqCbFn>(
|
|
|
|
|
buffer.device->componentThread, std::move(callback)),
|
|
|
|
|
stimBuff(buffer)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void callOriginalCallback()
|
|
|
|
|
{
|
|
|
|
|
stimBuff.frameAssemblyRateLimiter.release();
|
|
|
|
|
callOriginalCb(static_cast<SimultaneityStamp>(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void callOriginalCallbackWithFailure()
|
|
|
|
|
{
|
|
|
|
|
stimBuff.frameAssemblyRateLimiter.release();
|
|
|
|
|
callOriginalCb(static_cast<SimultaneityStamp>(0));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void PcloudStimulusBuffer::assembleAndProduceStimulusFrameReq(
|
|
|
|
|
smo::Callback<assembleAndProduceStimulusFrameReqCbFn> callback)
|
|
|
|
|
{
|
|
|
|
|
// Wireframe implementation - do nothing for now
|
|
|
|
|
(void)callback;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-25 19:28:18 -04:00
|
|
|
} // namespace stim_buff
|
|
|
|
|
} // namespace smo
|