27#include <glm/vec2.hpp>
29#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
30#include <vulkan/vulkan.hpp>
32#define HVT_FUNCTION_PROTOTYPES
35#define HVT_ENTRY_ATTR __declspec(dllexport)
37#include "../RVSVulkan/SourcesVulkan/HvtStreamingAPI.h"
39#include "../RVSVulkan/RVSConfig/include/Config.h"
42enum class HvtHandleType {
47template<
typename OurType,
typename HvtHandle, HvtHandleType htype>
50 static constexpr HvtHandleType staticType = htype;
52 static OurType* check(HvtHandle hvtHandle) {
54 if(h && staticType == h->type) {
55 return static_cast<OurType*
>(h);
57 throw HvtResult::HVT_ERROR_INVALID_HANDLE;
61 static OurType* opt_check(HvtHandle hvtHandle) {
65 return check(hvtHandle);
68 HvtHandle to_handle(){
69 return reinterpret_cast<HvtHandle
>(
this);
75struct Semaphore :
public Handle<Semaphore, HvtSemaphore, HvtHandleType::SEMAPHORE>
77 vk::UniqueSemaphore sem;
83 using Clock = std::chrono::steady_clock;
84 static constexpr auto numSlots = 3;
86 JsonStreamer(std::span<const uint8_t, VK_UUID_SIZE> uuid);
90 void destroySemaphore(
Semaphore* sem)
const;
91 void startStreaming();
93 void releaseStreamsFrames(
Semaphore* waitSem);
97 void initVk(std::span<const uint8_t, VK_UUID_SIZE> uuid);
98 uint32_t findMemoryType(uint32_t typeFilter, vk::MemoryPropertyFlags properties);
100 void initVkResources();
102 template<
typename Closure>
103 void oneTimeSubmit(Closure&& func, vk::SubmitInfo submitInfo = vk::SubmitInfo({},{},{},{}));
106 vk::UniqueImage image;
107 vk::UniqueDeviceMemory memory;
111 std::ifstream colorFile;
112 std::ifstream depthFile;
113 size_t colorFrameStride;
114 size_t colorFrameSize;
115 size_t depthFrameStride;
116 size_t depthFrameSize;
118 glm::ivec2 resolution;
119 HvtProjectionType projectionType;
123 float anear;
float afar;
125 vk::Format colorFormat;
126 vk::Format depthFormat;
127 vk::UniqueDeviceMemory stagingMemory;
128 vk::UniqueBuffer stagingBuffer;
129 char* stagingMapping =
nullptr;
131 std::array<ImageSlot, numSlots> colorSlots;
132 std::array<ImageSlot, numSlots> depthSlots;
133 bool importedColor =
false;
134 bool importedDepth =
false;
136 Clock::duration framePeriod;
138 int streamedFrame = -1;
140 int frameIndex(Clock::duration time)
const;
141 bool nextFrameReady(Clock::duration time)
const;
144 void streamingLoop();
145 void uploadFrame(vk::CommandBuffer cmd,
int streamId, ReadStream &stream,
int frame);
146 void swapStreamingToPending();
147 void swapPendingToReading();
149 std::optional<rvs::Config> config;
151 std::vector<ReadStream> readStreams;
153 vk::UniqueInstance instance;
154 vk::PhysicalDevice phyDevice = VK_NULL_HANDLE;
155 vk::UniqueDevice device;
156 uint32_t queueFamilyIndex;
159 std::mutex queueMutex;
162 std::array<Semaphore*, numSlots> usageWaitSemaphores{};
163 uint32_t slotReadingIndex = 0;
164 uint32_t slotPendingIndex = 1;
165 uint32_t slotStreamingIndex = 2;
166 std::atomic_bool newDataInPending =
false;
167 std::mutex indicesMutex;
169 std::atomic_bool running =
false;
170 std::thread streamingThread;
Parameters for query of the current frames infos.
Description of an RGBD stream.
Export info for images of a stream.
Union of possible intrinsics types data.