Skip to content

File plugin.hpp

File List > native_renderer > plugin.hpp

Go to the documentation of this file

#pragma once

#include "illixr/data_format/pose_prediction.hpp"
#include "illixr/phonebook.hpp"
#include "illixr/switchboard.hpp"
#include "illixr/threadloop.hpp"
#include "illixr/vk/display_provider.hpp"
#include "illixr/vk/render_pass.hpp"
#include "illixr/vk/vulkan_utils.hpp"

#include 
#include 

namespace ILLIXR {
class MY_EXPORT_API native_renderer : public threadloop {
public:
    [[maybe_unused]] native_renderer(const std::string& name, phonebook* pb);
    ~native_renderer() override;

    void _p_thread_setup() override;

    void _p_one_iteration() override;

private:
    [[maybe_unused]] void recreate_swapchain();

    void create_swapchain_framebuffers();

    void record_src_command_buffer(vulkan::image_index_t buffer_index);

    void record_post_processing_command_buffer(vulkan::image_index_t buffer_index, uint32_t swapchain_image_index_);
    void create_sync_objects();

    void create_depth_image(vulkan::vk_image& depth_image);

    void create_offscreen_target(vulkan::vk_image& image);

    void create_offscreen_pool();

    void create_offscreen_framebuffers();

    void create_app_pass();

    void create_timewarp_pass();

    const std::shared_ptr<switchboard>                  switchboard_;
    const std::shared_ptr<spdlog::logger>               log_;
    const std::shared_ptr<data_format::pose_prediction> pose_prediction_;
    const std::shared_ptr<vulkan::display_provider>     display_sink_;
    const std::shared_ptr<vulkan::timewarp>             timewarp_;
    const std::shared_ptr<vulkan::app>                  app_;
    const std::shared_ptr<const relative_clock>         clock_;

    uint32_t width_      = 0;
    uint32_t height_     = 0;
    bool     export_dma_ = false;

    std::stack<std::function<void()>> deletion_queue_;

    VkCommandPool   command_pool_{};
    VkCommandBuffer app_command_buffer_{};
    VkCommandBuffer timewarp_command_buffer_{};

    std::vector<std::array<vulkan::vk_image, 2>> depth_images_{};
    std::vector<std::array<vulkan::vk_image, 2>> depth_attachment_images_{};

    VkExportMemoryAllocateInfo                offscreen_export_mem_alloc_info_{};
    VmaPoolCreateInfo                         offscreen_pool_create_info_{};
    VmaPool                                   offscreen_pool_{};
    std::vector<std::array<VkFramebuffer, 2>> offscreen_framebuffers_{};

    std::vector<std::array<vulkan::vk_image, 2>> offscreen_images_{};

    std::vector<VkFramebuffer> swapchain_framebuffers_{};

    VkRenderPass app_pass_{};

    VkRenderPass timewarp_pass_{};
    VkSemaphore  image_available_semaphore_{};
    VkSemaphore  app_render_finished_semaphore_{};
    VkSemaphore  timewarp_render_finished_semaphore_{};

    VkFence frame_fence_{};

    uint32_t swapchain_image_index_    = UINT32_MAX; // set to UINT32_MAX after present
    uint64_t timeline_semaphore_value_ = 1;

    int                                                         fps_{};
    switchboard::reader<switchboard::event_wrapper<time_point>> vsync_;
    time_point                                                  last_fps_update_;

    std::shared_ptr<vulkan::buffer_pool<data_format::pose::fast_head_pose_type>> buffer_pool_;
};
} // namespace ILLIXR