HoviTron Video Pipeline
Public Member Functions | Static Public Member Functions | Static Public Attributes
BuffersControllerWarping Class Reference

Control the data to be transmitted to the warping pipeline. More...

#include <BuffersControllerWarping.h>

Inheritance diagram for BuffersControllerWarping:
BuffersController

Public Member Functions

 BuffersControllerWarping (VulkanContext *context, VulkanRenderPass *renderpass, VulkanPipelineWarping *pipeline, InputProvider *input, VulkanWrapper *wraps, int inputView)
 
void init () override
 
void cleanUp () override
 
void bindBuffers (vk::CommandBuffer &commandBuffer, int index, InputProvider::StreamFrameInfo &frameInfos, int view) override
 
void updateUniformBuffer (uint32_t currentImage, int view) override
 
void updateAllUniformBuffer (uint32_t currentImage, int view) override
 
vk::VertexInputBindingDescription getBindingDescription () override
 
std::vector< vk::VertexInputAttributeDescription > getAttributeDescription () override
 
uint32_t getIndiceCount () override
 
void update (std::span< InputProvider::StreamFrameInfo > infos, int view) override
 
virtual void init ()=0
 
virtual void cleanUp ()=0
 
virtual void bindBuffers (vk::CommandBuffer &commandBuffer, int index, InputProvider::StreamFrameInfo &frameInfos, int view)=0
 
virtual void updateAllUniformBuffer (uint32_t currentImage, int view)=0
 
virtual void updateUniformBuffer (uint32_t currentImage, int view)=0
 
virtual void update (std::span< InputProvider::StreamFrameInfo > infos, int inputView)=0
 
virtual vk::VertexInputBindingDescription getBindingDescription ()=0
 
virtual std::vector< vk::VertexInputAttributeDescription > getAttributeDescription ()=0
 
virtual uint32_t getIndiceCount ()=0
 

Static Public Member Functions

static void updateSettings (const InputProvider::StreamFrameInfo &infos, int view, const InputProvider::StreamParameters &streamParams, VulkanWrapper *wrapper, RVScamExtrinsics &extrinsics, RvsSynParam &params)
 

Static Public Attributes

static std::vector< uint32_t > indices
 

Additional Inherited Members

- Protected Member Functions inherited from BuffersController
virtual void createVertexBuffer ()=0
 
virtual void createIndexBuffer ()=0
 
virtual void createUniformBuffer (int size)=0
 
virtual void createDescriptorPool ()=0
 
virtual void createDescriptorSets ()=0
 
void copyBuffer (vk::Buffer srcBuffer, vk::Buffer dstBuffer, vk::DeviceSize size)
 
- Protected Attributes inherited from BuffersController
int inputView = 0
 
VulkanContextcontext = nullptr
 
VulkanRenderPassrenderpass = nullptr
 

Detailed Description

Control the data to be transmitted to the warping pipeline.

Class that manages ressources for the warping pipeline. From vertex+indices buffers to samplers and uniforms buffers. It is also in charge of the descriptor set.

Definition at line 145 of file BuffersControllerWarping.h.

Constructor & Destructor Documentation

◆ BuffersControllerWarping()

BuffersControllerWarping::BuffersControllerWarping ( VulkanContext context,
VulkanRenderPass renderpass,
VulkanPipelineWarping pipeline,
InputProvider input,
VulkanWrapper wraps,
int  inputView 
)

Constructor

Definition at line 34 of file BuffersControllerWarping.cpp.

35{
36 this->context = context;
37 this->pipeline = pipeline;
38 this->inputView = inputView;
39 this->wrapper = wraps;
40 this->renderpass = renderpass;
41 this->input = inputP;
42
43 this->idStep = inputView;
44 auto activation = wrapper->getCameraActivation();
45 for (int i = 0; i <= inputView; i++) {
46 if (!activation[i]) {
47 this->inputView++;
48 inputView++;
49 }
50 }
51
52 streamParams = input->enumerateStreamsParameters()[inputView];
53
54 textureStreamImages = input->enumerateStreamImages(inputView, false);
55 depthStreamImages = input->enumerateStreamImages(inputView, true);
56 attachmentSize = wrapper->multiviewSetup ? wrapper->getViewNumber() : wrapper->getAttachmentSize();
57
58 assert(textureStreamImages.size() == depthStreamImages.size());
59
60 memset(&rvsSynParam, 0, sizeof(rvsSynParam));
61 memset(&rvsSynGeom, 0, sizeof(rvsSynGeom));
62 memset(&rvsSynFrag, 0, sizeof(rvsSynFrag));
63
64 if (streamParams.depthFormat == vk::Format::eR32Sfloat) {
65 rvsSynParam.lin_depth = 1; //do like exr format
66 }
67 else {
68 rvsSynParam.lin_depth = 0;
69 }
70}
VulkanRenderPass * renderpass
const bool multiviewSetup
std::vector< bool > getCameraActivation()

Member Function Documentation

◆ bindBuffers()

void BuffersControllerWarping::bindBuffers ( vk::CommandBuffer &  commandBuffer,
int  index,
InputProvider::StreamFrameInfo frameInfos,
int  view 
)
overridevirtual

Bind buffers

Implements BuffersController.

Definition at line 343 of file BuffersControllerWarping.cpp.

344{
345 int index = wrapper->multiviewSetup ? view : currentSwapIndex;
346 vk::Buffer vertexBuffers[] = { vertexBuffer };
347 vk::DeviceSize offsets[] = { 0 };
348 commandBuffer.bindVertexBuffers( 0, 1, vertexBuffers, offsets);
349 commandBuffer.bindIndexBuffer(indexBuffer, 0, vk::IndexType::eUint32);
350
351 auto idDescriptorSet = index + frameInfos.imageIndex * attachmentSize;
352 commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline->pipelineLayout, 0, 1, &descriptorSets[idDescriptorSet], 0, nullptr);
353}
vk::PipelineLayout pipelineLayout

◆ cleanUp()

void BuffersControllerWarping::cleanUp ( )
overridevirtual

Clean up ressources for the warping pipeline

Implements BuffersController.

Definition at line 295 of file BuffersControllerWarping.cpp.

296{
297
298 if (idStep == 0) {
299 context->device.destroyBuffer(vertexBuffer);
300 context->device.freeMemory(vertexBufferMemory, nullptr);
301
302 context->device.destroyBuffer(indexBuffer);
303 context->device.freeMemory(indexBufferMemory, nullptr);
304 }
305
306 for (size_t i = 0; i < uniformBuffersFrag.size(); i++) {
307 context->device.destroyBuffer(uniformBuffersFrag[i], nullptr);
308 context->device.freeMemory(uniformBuffersFragMemory[i], nullptr);
309 }
310
311 for (size_t i = 0; i < uniformBuffersGeom.size(); i++) {
312 context->device.destroyBuffer(uniformBuffersGeom[i], nullptr);
313 context->device.freeMemory(uniformBuffersGeomMemory[i], nullptr);
314 }
315
316 for (size_t i = 0; i < uniformBuffers.size(); i++) {
317 context->device.destroyBuffer(uniformBuffers[i], nullptr);
318 context->device.freeMemory(uniformBuffersMemory[i], nullptr);
319 }
320
321 for (size_t i = 0; i < uniformBuffersCam.size(); i++) {
322 context->device.destroyBuffer(uniformBuffersCam[i], nullptr);
323 context->device.freeMemory(uniformBuffersCamMemory[i], nullptr);
324 }
325
326 uniformBuffers.clear();
327 uniformBuffersMemory.clear();
328
329 uniformBuffersCam.clear();
330 uniformBuffersCamMemory.clear();
331
332 uniformBuffersGeom.clear();
333 uniformBuffersGeomMemory.clear();
334
335 uniformBuffersFrag.clear();
336 uniformBuffersFragMemory.clear();
337
338 context->device.destroyDescriptorPool(descriptorPool);
339}
vk::Device device
Definition: VulkanContext.h:87

◆ getAttributeDescription()

std::vector< vk::VertexInputAttributeDescription > BuffersControllerWarping::getAttributeDescription ( )
overridevirtual

Return the vk::VertexInputAttributeDescription of the warping pipeline

Implements BuffersController.

Definition at line 411 of file BuffersControllerWarping.cpp.

412{
413 std::vector<vk::VertexInputAttributeDescription> attributeDescriptions{
414 vk::VertexInputAttributeDescription(
415 0, //location
416 0, //binding
417 vk::Format::eR32Sfloat, //format
418 0 //offset
419 )};
420 return attributeDescriptions;
421}

◆ getBindingDescription()

vk::VertexInputBindingDescription BuffersControllerWarping::getBindingDescription ( )
overridevirtual

Return the vk::VertexInputBindingDescription of the warping pipeline

Implements BuffersController.

Definition at line 401 of file BuffersControllerWarping.cpp.

402{
403 vk::VertexInputBindingDescription bindingDescription{
404 0, //binding
405 sizeof(glm::vec1), // stride
406 vk::VertexInputRate::eVertex //inputRate
407 };
408 return bindingDescription;
409}

◆ getIndiceCount()

uint32_t BuffersControllerWarping::getIndiceCount ( )
overridevirtual

Return the number of indices that need to be draw

Implements BuffersController.

Definition at line 423 of file BuffersControllerWarping.cpp.

424{
425 return indiceCount;
426}

◆ init()

void BuffersControllerWarping::init ( )
overridevirtual

Init the required ressources for the warping pipeline

Implements BuffersController.

Definition at line 72 of file BuffersControllerWarping.cpp.

73{
74 if(idStep == 0){
75 createVertexBuffer();
76 createIndexBuffer();
77 }
78 createUniformBuffer(attachmentSize);
79 createDescriptorPool();
80 createDescriptorSets();
81}

◆ update()

void BuffersControllerWarping::update ( std::span< InputProvider::StreamFrameInfo infos,
int  view 
)
overridevirtual

Update the content of the structs with the informations givent by the input provider

Implements BuffersController.

Definition at line 549 of file BuffersControllerWarping.cpp.

549 {
550
551 auto frameInfo = infos[inputView];
552
553 // Do common update
554 updateSettings(frameInfo, view, streamParams, wrapper, rvsCamExtrinsics, rvsSynParam);
555
556
557 // Patch remaining structs
558 rvsSynGeom.w = streamParams.depthResolution.x; //float(inputView->get_depth().cols);//float(m_space_transformer->getInputParameters().getSize().width);
559 rvsSynGeom.h = streamParams.depthResolution.y;
560
561 rvsSynFrag.max_depth = streamParams.farDepth;
562 rvsSynFrag.pixelThresh = wrapper->params.pixelThreshold;
563 rvsSynGeom.pixelThresh = wrapper->params.pixelThreshold;
564 rvsSynFrag.maxMul = wrapper->params.maxMult;
565
566
567 //scaleFactor
568 rvsSynParam.scaleFactor = wrapper->params.scaleFactor;
569 rvsSynGeom.scaleFactor = wrapper->params.scaleFactor;
570 rvsSynFrag.scaleFactor = wrapper->params.scaleFactor;
571
572
573 if (wrapper->getViewNumber() == 4 && view % 2 == 1 && wrapper->params.projectionType == InputProvider::ProjectionType::PROJECTION_PERSPECTIVE) {
574 rvsSynGeom.pixelThresh *= std::get<InputProvider::PerspectiveIntrinsics>(wrapper->params.getVirtualIntrinsics(view - 1)).focals.x / rvsSynParam.n_f.x;
575 }
576
577 rvsSynFrag.maxMul = wrapper->params.maxMult;
578}
static void updateSettings(const InputProvider::StreamFrameInfo &infos, int view, const InputProvider::StreamParameters &streamParams, VulkanWrapper *wrapper, RVScamExtrinsics &extrinsics, RvsSynParam &params)
InputProvider::ProjectionType projectionType
const InputProvider::Intrinsics getVirtualIntrinsics(int view)
RenderingParameters params

◆ updateAllUniformBuffer()

void BuffersControllerWarping::updateAllUniformBuffer ( uint32_t  currentImage,
int  view 
)
overridevirtual

Update the content of all buffers

Implements BuffersController.

Definition at line 368 of file BuffersControllerWarping.cpp.

369{
370
371 //camera extrinsics !!
372 int index = wrapper->multiviewSetup ? view : currentImage;
373 updateCameraBuffer(index);
374
375
376 RvsSynParam ubo = rvsSynParam;//rvs::SynthesizedView::getInstance().rvsSynParam;
377
378
379 void* data;
380 context->device.mapMemory(uniformBuffersMemory[index], 0, sizeof(ubo), {}, &data);
381 memcpy(data, &ubo, sizeof(ubo));
382 context->device.unmapMemory(uniformBuffersMemory[index]);
383
384 RvsSynGeom uboGeom = rvsSynGeom;//rvs::SynthesizedView::getInstance().rvsSynGeom;
385 void* dataGeom;
386 context->device.mapMemory(uniformBuffersGeomMemory[index], 0, sizeof(uboGeom), {}, &dataGeom);
387 memcpy(dataGeom, &uboGeom, sizeof(uboGeom));
388 context->device.unmapMemory(uniformBuffersGeomMemory[index]);
389
390 RvsSynFrag uboFrag = rvsSynFrag;//rvs::SynthesizedView::getInstance().rvsSynFrag;
391 void* dataFrag;
392 context->device.mapMemory(uniformBuffersFragMemory[index], 0, sizeof(uboFrag), {}, &dataFrag);
393 memcpy(dataFrag, &uboFrag, sizeof(uboFrag));
394 context->device.unmapMemory(uniformBuffersFragMemory[index]);
395
396}
Struct that contains datas for the fragment shader of the warping pipeline.
Struct that contains datas for the geometry shader of the warping pipeline.
Struct that contains parameters for the vertex shader in the warping pipeline.

◆ updateSettings()

void BuffersControllerWarping::updateSettings ( const InputProvider::StreamFrameInfo infos,
int  view,
const InputProvider::StreamParameters streamParams,
VulkanWrapper wrapper,
RVScamExtrinsics extrinsics,
RvsSynParam params 
)
static

Update the requested structrures with the provided information

Definition at line 452 of file BuffersControllerWarping.cpp.

458 {
459 //translation to glm ?
460 //Input coordinate are in OMAF system
461 //in OMAF rotation vector is rotation against z axis, y axis, and x axis
462 auto R_from = glmEulerAnglesDegreeToRotationMatrix(frameInfo.extrinsics.rotation);
463 //------------ Virtual camera parameter may not be in OMAF but can be converted to it using the conversion at wrapper->params.conversionToOMAF
464 // (in general it would be openxr coordinate system)
465 // and the rotation is defined as rotation against x axis, y axis, z axis
466 auto R_start = glmEulerAnglesDegreeToRotationMatrixNotOMAF(wrapper->params.getStartingRotation());
467 auto R_to = glmEulerAnglesDegreeToRotationMatrixNotOMAF(wrapper->params.getVirtualExtrinsics(view).rotation);
468 R_to = (R_start * R_to * glm::transpose(R_start)) * R_start ;
469 R_to = wrapper->params.conversionToOMAF * R_to * glm::transpose(wrapper->params.conversionToOMAF);
470
471 auto R = glm::transpose(R_to) * R_from;
472
473 rvsCamExtrinsics.R = glm::mat4(R);
474
475 auto t_from = frameInfo.extrinsics.position;
476 auto t_start = wrapper->params.getStartingPosition();
477 auto t_to = wrapper->params.getVirtualExtrinsics(view).position;
478 t_to = t_start + R_start * t_to;// *glm::transpose(R_start); //
479
480 t_to = wrapper->params.conversionToOMAF * t_to;
481 auto T = -glm::transpose(R_to) * (t_to - t_from);
482
483 rvsCamExtrinsics.t = glm::vec4(T,1);
484
485 //
486 rvsSynParam.w = streamParams.depthResolution.x; //float(inputView->get_depth().cols);//float(m_space_transformer->getInputParameters().getSize().width);
487 //rvsSynGeom.w = streamParams.depthResolution.x; //float(inputView->get_depth().cols);//float(m_space_transformer->getInputParameters().getSize().width);
488 rvsSynParam.h = streamParams.depthResolution.y; //float(inputView->get_depth().rows);//float(m_space_transformer->getInputParameters().getSize().height);
489 //rvsSynGeom.h = streamParams.depthResolution.y;
490 rvsSynParam.n_h = wrapper->params.virtualViewDef[view].y;
491 rvsSynParam.n_w = wrapper->params.virtualViewDef[view].x;
492
493 switch (streamParams.projectionType) {
494 case InputProvider::ProjectionType::PROJECTION_PERSPECTIVE: {
495 rvsSynParam.erp_in = false;
496 rvsSynParam.f = std::get<InputProvider::PerspectiveIntrinsics>(frameInfo.intrinsics).focals / (float(streamParams.colorResolution.x)/ streamParams.depthResolution.x);
497 rvsSynParam.p = std::get<InputProvider::PerspectiveIntrinsics>(frameInfo.intrinsics).principle / (float(streamParams.colorResolution.x) / streamParams.depthResolution.x);
498 break;
499 }
500
501 case InputProvider::ProjectionType::PROJECTION_EQUIRECTANGULAR: {
502 rvsSynParam.erp_in = true;
503 auto hor_range = std::get<InputProvider::EquirectangularIntrinsics>(frameInfo.intrinsics).horizontalRange;
504 auto ver_range = std::get<InputProvider::EquirectangularIntrinsics>(frameInfo.intrinsics).verticalRange;
505 auto constexpr radperdeg = 0.01745329252f;
506 rvsSynParam.phi0 = radperdeg * hor_range[1];
507 rvsSynParam.theta0 = radperdeg * ver_range[1];
508 rvsSynParam.dphi_du = -radperdeg * (hor_range[1] - hor_range[0]) / rvsSynParam.w;
509 rvsSynParam.dtheta_dv = -radperdeg * (ver_range[1] - ver_range[0]) / rvsSynParam.h;
510 break;
511 }
512 default:
513 throw std::runtime_error("Unsupported projection type for input");
514 break;
515 }
516
517
518 //for virtual camera
519 switch (wrapper->params.projectionType) {
520 case InputProvider::ProjectionType::PROJECTION_PERSPECTIVE: {
521 rvsSynParam.erp_out = false;
522 rvsSynParam.n_p = std::get<InputProvider::PerspectiveIntrinsics>(wrapper->params.getVirtualIntrinsics(view)).principle;
523 rvsSynParam.n_f = std::get<InputProvider::PerspectiveIntrinsics>(wrapper->params.getVirtualIntrinsics(view)).focals;
524 break;
525 }
526 case InputProvider::ProjectionType::PROJECTION_EQUIRECTANGULAR: {
527 rvsSynParam.erp_out = true;
528 auto ver_range = std::get < InputProvider::EquirectangularIntrinsics>(wrapper->params.getVirtualIntrinsics(view)).verticalRange;
529 auto hor_range = std::get < InputProvider::EquirectangularIntrinsics>(wrapper->params.getVirtualIntrinsics(view)).horizontalRange;
530 auto constexpr degperrad = 57.295779513f;
531 rvsSynParam.u0 = (hor_range[0] + hor_range[1]) / (hor_range[1] - hor_range[0]);
532 rvsSynParam.v0 = -(ver_range[0] + ver_range[1]) / (ver_range[1] - ver_range[0]);
533 rvsSynParam.du_dphi = -2.f * degperrad / (hor_range[1] - hor_range[0]);
534 rvsSynParam.dv_dtheta = +2.f * degperrad / (ver_range[1] - ver_range[0]);
535 break;
536 }
537 default: {
538 throw std::runtime_error("Unsupported projection type for input");
539 break; }
540 }
541 //rvsSynFrag.max_depth = streamParams.farDepth;
542 //rvsSynFrag.pixelThresh = wrapper->params.pixelThreshold;
543 rvsSynParam.min_depth = streamParams.nearDepth;
544 rvsSynParam.max_depth = streamParams.farDepth;
545 //rvsSynGeom.pixelThresh = wrapper->params.pixelThreshold;
546 //rvsSynFrag.maxMul = wrapper->params.maxMult;
547}
const InputProvider::Extrinsics getVirtualExtrinsics(int view)
const glm::mat3x3 conversionToOMAF
const glm::vec3 getStartingPosition()
const glm::vec3 getStartingRotation()
std::vector< glm::vec2 > virtualViewDef

◆ updateUniformBuffer()

void BuffersControllerWarping::updateUniformBuffer ( uint32_t  currentImage,
int  view 
)
overridevirtual

Update the content of the buffers that were changed

Implements BuffersController.

Definition at line 363 of file BuffersControllerWarping.cpp.

364{
365 int index = wrapper->multiviewSetup ? view : currentImage;
366 updateCameraBuffer(currentImage);
367};

Field Documentation

◆ indices

std::vector<uint32_t> BuffersControllerWarping::indices
inlinestatic

list of the indices

Definition at line 167 of file BuffersControllerWarping.h.


The documentation for this class was generated from the following files: