14 #if defined(LUG_SYSTEM_WINDOWS) 16 #elif defined(LUG_SYSTEM_LINUX) 18 #elif defined(LUG_SYSTEM_ANDROID) 63 if (acquireImageData_.imageIdx == -1) {
64 acquireImageData = &acquireImageData_;
82 LUG_LOG.error(
"Window::beginFrame: Failed to initialise Gui framebuffers");
88 View* renderView_ =
static_cast<View*
>(renderView.get());
104 acquireImageData_.imageIdx = -1;
122 imageReadyVkSemaphores,
124 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT}
129 bool uiResult =
false;
130 bool presentQueueResult =
false;
135 std::vector<VkSemaphore> waitSemaphores(
_renderViews.size());
139 View* renderView_ =
static_cast<View*
>(renderView.get());
156 { VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT });
159 std::vector<VkPipelineStageFlags> waitDstStageMasks(waitSemaphores.size(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
168 && presentQueueResult
173 std::unique_ptr<View> renderView = std::make_unique<View>(
_renderer,
this);
197 std::unique_ptr<Window>
200 std::unique_ptr<Window> window(
new Window(renderer));
202 if (!window->init(initInfo)) {
214 VkResult result{VK_SUCCESS};
217 #if defined(LUG_SYSTEM_WINDOWS) // Win32 surface 219 #elif defined(LUG_SYSTEM_LINUX) // Linux surface 221 #elif defined(LUG_SYSTEM_ANDROID) // Android Surface 225 if (!surfaceBuilder.build(
_surface, &result)) {
226 LUG_LOG.error(
"RendererWindow: Can't initialize surface: {}", result);
234 VkResult result{VK_SUCCESS};
237 LUG_ASSERT(info !=
nullptr,
"PhysicalDeviceInfo cannot be null");
243 if (result != VK_SUCCESS) {
244 LUG_LOG.error(
"RendererWindow: Can't get surface capabilities: {}", result);
248 uint32_t formatsCount = 0;
249 result = vkGetPhysicalDeviceSurfaceFormatsKHR(info->
handle, static_cast<VkSurfaceKHR>(
_surface), &formatsCount,
nullptr);
251 if (result != VK_SUCCESS) {
252 LUG_LOG.error(
"RendererWindow: Can't retrieve formats count: {}", result);
259 if (result != VK_SUCCESS) {
260 LUG_LOG.error(
"RendererWindow: Can't retrieve formats: {}", result);
264 uint32_t presentModesCount = 0;
265 result = vkGetPhysicalDeviceSurfacePresentModesKHR(info->
handle, static_cast<VkSurfaceKHR>(
_surface), &presentModesCount,
nullptr);
267 if (result != VK_SUCCESS) {
268 LUG_LOG.error(
"RendererWindow: Can't retrieve present modes count: {}", result);
275 if (result != VK_SUCCESS) {
276 LUG_LOG.error(
"RendererWindow: Can't retrieve present modes: {}", result);
286 LUG_LOG.error(
"RendererWindow: Failed to initialise Gui");
297 LUG_ASSERT(info !=
nullptr,
"PhysicalDeviceInfo cannot be null");
301 VkResult result{VK_SUCCESS};
303 VkBool32 supported = 0;
304 result = vkGetPhysicalDeviceSurfaceSupportKHR(info->
handle, queueFamily.getIdx(),
static_cast<VkSurfaceKHR
>(
_surface), &supported);
306 if (result != VK_SUCCESS) {
307 LUG_LOG.error(
"RendererWindow: Can't check if queue supports presentation: {}", result);
311 queueFamily.supportsPresentation(!!supported);
319 LUG_LOG.error(
"Window::initPresentQueue: Can't find presentation queue family");
324 LUG_LOG.error(
"Window::initPresentQueue: Can't find presentation queue");
331 VkResult result{VK_SUCCESS};
334 LUG_LOG.error(
"Window::initPresentQueue: Can't create a command pool: {}", result);
347 swapchainBuilder.setImageUsage(VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
348 swapchainBuilder.setImageColorSpace(VK_COLOR_SPACE_SRGB_NONLINEAR_KHR);
349 swapchainBuilder.setMinImageCount(3);
354 swapchainBuilder.setImageExtent(
360 swapchainBuilder.setImageExtent(
370 swapchainBuilder.setPreTransform(VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR);
375 swapchainBuilder.setSurface(static_cast<VkSurfaceKHR>(
_surface));
376 swapchainBuilder.setOldSwapchain(static_cast<VkSwapchainKHR>(
_swapchain));
384 if (!graphicsQueueFamily) {
385 LUG_LOG.error(
"RendererWindow: Can't find graphics queue");
400 for (uint32_t i = 0; i < frameDataSize; ++i) {
401 for (uint32_t j = 0; j <
_framesData[i].cmdBuffers.size(); ++j) {
407 VkResult result{VK_SUCCESS};
408 if (!swapchainBuilder.build(
_swapchain, &result)) {
409 LUG_LOG.error(
"Window::initPresentQueue: Can't create swapchain: {}", result);
428 commandBufferBuilder.
setLevel(VK_COMMAND_BUFFER_LEVEL_PRIMARY);
432 for (uint32_t i = 0; i < frameDataSize; ++i) {
435 VkResult result{VK_SUCCESS};
436 if (!semaphoreBuilder.build(
_framesData[i].allDrawsFinishedSemaphore, &result)) {
437 LUG_LOG.error(
"Window::initFramesData: Can't create semaphore: {}", result);
447 VkResult result{VK_SUCCESS};
448 if (!semaphoreBuilder.build(
_framesData[i].imageReadySemaphores[j], &result)) {
449 LUG_LOG.error(
"Window::initFramesData: Can't create semaphore: {}", result);
457 VkResult result{VK_SUCCESS};
459 if (!commandBufferBuilder.build(
_framesData[i].cmdBuffers, &result)) {
460 LUG_LOG.error(
"Window::initFramesData: Can't create the command buffer: {}", result);
466 for (uint32_t i = 0; i < frameDataSize + 1; ++i) {
469 VkResult result{VK_SUCCESS};
471 LUG_LOG.error(
"Window::initFramesData: Can't create semaphore: {}", result);
485 for (uint32_t i = 0; i < frameDataSize; ++i) {
489 if (!cmdBuffer.
begin(VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
498 pipelineBarrier.imageMemoryBarriers[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
499 pipelineBarrier.imageMemoryBarriers[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
500 pipelineBarrier.imageMemoryBarriers[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
503 cmdBuffer.pipelineBarrier(
pipelineBarrier, VK_DEPENDENCY_BY_REGION_BIT);
508 VkClearColorValue clearColor;
509 std::memset(&clearColor, 0,
sizeof(clearColor));
511 const VkImageSubresourceRange range{
512 VK_IMAGE_ASPECT_COLOR_BIT,
520 vkCmdClearColorImage(
521 static_cast<VkCommandBuffer>(cmdBuffer),
523 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
534 pipelineBarrier.imageMemoryBarriers[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
535 pipelineBarrier.imageMemoryBarriers[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
536 pipelineBarrier.imageMemoryBarriers[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
537 pipelineBarrier.imageMemoryBarriers[0].newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
540 cmdBuffer.pipelineBarrier(
pipelineBarrier, VK_DEPENDENCY_BY_REGION_BIT);
543 if (!cmdBuffer.
end()) {
554 for (uint32_t i = 0; i < frameDataSize; ++i) {
558 if (!cmdBuffer.
begin(VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
564 pipelineBarrier.imageMemoryBarriers[0].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
565 pipelineBarrier.imageMemoryBarriers[0].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
566 pipelineBarrier.imageMemoryBarriers[0].oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
567 pipelineBarrier.imageMemoryBarriers[0].newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
570 cmdBuffer.pipelineBarrier(
pipelineBarrier, VK_DEPENDENCY_BY_REGION_BIT);
572 if (!cmdBuffer.
end()) {
645 renderView->destroy();
648 _renderViews.clear();
struct lug::Graphics::Vulkan::Renderer::Preferences::Swapchain swapchain
API::Semaphore completeSemaphore
Display * getDisplay() const
const std::vector< Queue > & getQueues() const
struct lug::Graphics::Vulkan::PhysicalDeviceInfo::Swapchain swapchain
Resource::SharedPtr< Camera::Camera > getCamera() const
VkSurfaceCapabilitiesKHR capabilities
const API::QueueFamily * getQueueFamily(VkQueueFlags flags, bool supportPresentation=false) const
bool pollEvent(lug::Window::Event &) override
Checks if an event is available from the window implementation, and fill it in the event parameter...
#define LUG_ASSERT(assertion, message)
void beginFrame(const lug::System::Time &elapsedTime)
const API::QueueFamily * _presentQueueFamily
virtual bool initDepthBuffers(const std::vector< API::ImageView > &imageViews)=0
std::vector< AcquireImageData > _acquireImageDatas
bool endFrame(const std::vector< VkSemaphore > &waitSemaphores, uint32_t currentImageIndex)
lug::Window::Window::InitInfo windowInitInfo
bool buildBeginCommandBuffer()
void pipelineBarrier(const CmdPipelineBarrier ¶meters, VkDependencyFlags dependencyFlags=VK_DEPENDENCY_BY_REGION_BIT, VkPipelineStageFlags srcStageMask=VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VkPipelineStageFlags dstStageMask=VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) const
bool buildEndCommandBuffer()
bool submit(const CommandBuffer &commandBuffer, const std::vector< VkSemaphore > &signalSemaphores={}, const std::vector< VkSemaphore > &waitSemaphores={}, const std::vector< VkPipelineStageFlags > &waitDstStageMasks={}, VkFence fence=VK_NULL_HANDLE) const
API::Swapchain _swapchain
const API::Semaphore & getDrawCompleteSemaphore(uint32_t currentImageIndex) const
void setLevel(VkCommandBufferLevel level)
std::vector< VkPresentModeKHR > presentModes
bool beginFrame(const lug::System::Time &elapsedTime) override final
std::vector< FrameData > _framesData
const std::vector< ImageView > & getImagesViews() const
static std::unique_ptr< Window > create(lug::Graphics::Vulkan::Renderer &renderer, Window::InitInfo &initInfo)
Type type
The type of the event.
lug::Graphics::Vulkan::Gui _guiInstance
HINSTANCE getHinstance() const
const std::vector< QueueFamily > & getQueueFamilies() const
::lug::Graphics::Render::View * createView(::lug::Graphics::Render::View::InitInfo &initInfo) override final
bool buildCommandBuffers()
const API::Queue * _presentQueue
bool present(const Queue *presentQueue, uint32_t imageIndex, VkSemaphore semaphore=VK_NULL_HANDLE) const
Technique::Technique * getRenderTechnique()
bool init(const InitInfo &initInfo)
std::vector< VkSurfaceFormatKHR > formats
bool render() override final
virtual bool initFramebuffers(const std::vector< API::ImageView > &imageViews)=0
const API::Instance & getInstance() const
ANativeWindow * getWindow()
std::vector< View::InitInfo > renderViewsInitInfo
bool processEvent(const lug::Window::Event event)
const Vulkan::API::Semaphore & getSemaphore(uint32_t currentImageIndex) const
PhysicalDeviceInfo * getPhysicalDeviceInfo()
lug::Graphics::Vulkan::Renderer & _renderer
API::Semaphore allDrawsFinishedSemaphore
bool initSwapchainCapabilities()
std::vector< API::Semaphore > imageReadySemaphores
const std::vector< Image > & getImages() const
bool getNextImage(uint32_t *imageIndex, VkSemaphore semaphore=VK_NULL_HANDLE)
bool endFrame() override final
API::Device & getDevice()
bool init(Window::InitInfo &initInfo)
void setOutOfDate(bool outOfDate)
std::vector< std::unique_ptr< View > > _renderViews
bool init(const std::vector< API::ImageView > &imageViews)
Preferences & getPreferences()
API::CommandPool _commandPool
bool initFramebuffers(const std::vector< API::ImageView > &)
std::vector< API::CommandBuffer > cmdBuffers
bool begin(VkCommandBufferUsageFlags flags=VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) const
virtual bool pollEvent(lug::Window::Event &event)
Checks if an event is available from the window implementation, and fill it in the event parameter...
void setPreferences(const Renderer::Preferences::Swapchain &preferences)
uint32_t _currentImageIndex