Skip to content

Commit

Permalink
rendervulkan: address several warnings from GCC's new -Wnrvo warning
Browse files Browse the repository at this point in the history
Three functions edited to enable complete (n)rvo
  • Loading branch information
sharkautarch committed Aug 31, 2024
1 parent d4ca0b9 commit 2be93c6
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/rendervulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,8 +1199,13 @@ int32_t CVulkanDevice::findMemoryType( VkMemoryPropertyFlags properties, uint32_
}

std::unique_ptr<CVulkanCmdBuffer> CVulkanDevice::commandBuffer()
{
std::unique_ptr<CVulkanCmdBuffer> cmdBuffer;
{
auto finalizeCmdBuffer = [this](std::unique_ptr<CVulkanCmdBuffer> cmdBuffer, void (*preInitHook)(CVulkanDevice*) = [](CVulkanDevice*) { return; } ) {
preInitHook(this);
cmdBuffer->begin();
return cmdBuffer;
};

if (m_unusedCmdBufs.empty())
{
VkCommandBuffer rawCmdBuffer;
Expand All @@ -1218,16 +1223,14 @@ std::unique_ptr<CVulkanCmdBuffer> CVulkanDevice::commandBuffer()
return nullptr;
}

cmdBuffer = std::make_unique<CVulkanCmdBuffer>(this, rawCmdBuffer, queue(), queueFamily());
return finalizeCmdBuffer(std::make_unique<CVulkanCmdBuffer>(this, rawCmdBuffer, queue(), queueFamily()));
}
else
{
cmdBuffer = std::move(m_unusedCmdBufs.back());
m_unusedCmdBufs.pop_back();
return finalizeCmdBuffer(std::move(m_unusedCmdBufs.back()), [](CVulkanDevice* obj) {
obj->m_unusedCmdBufs.pop_back();
});
}

cmdBuffer->begin();
return cmdBuffer;
}

uint64_t CVulkanDevice::submitInternal( CVulkanCmdBuffer* cmdBuffer )
Expand Down Expand Up @@ -1337,8 +1340,8 @@ int VulkanTimelineSemaphore_t::GetFd() const

std::shared_ptr<VulkanTimelineSemaphore_t> CVulkanDevice::CreateTimelineSemaphore( uint64_t ulStartPoint, bool bShared )
{
std::shared_ptr<VulkanTimelineSemaphore_t> pSemaphore = std::make_unique<VulkanTimelineSemaphore_t>();
pSemaphore->pDevice = this;
VulkanTimelineSemaphore_t semaphore{};
semaphore.pDevice = this;

VkSemaphoreCreateInfo createInfo =
{
Expand All @@ -1362,19 +1365,20 @@ std::shared_ptr<VulkanTimelineSemaphore_t> CVulkanDevice::CreateTimelineSemaphor
};

VkResult res;
if ( ( res = vk.CreateSemaphore( m_device, &createInfo, nullptr, &pSemaphore->pVkSemaphore ) ) != VK_SUCCESS )
if ( ( res = vk.CreateSemaphore( m_device, &createInfo, nullptr, &semaphore.pVkSemaphore ) ) != VK_SUCCESS )
{
vk_errorf( res, "vkCreateSemaphore failed" );
return nullptr;
}

return pSemaphore;
return std::make_shared<VulkanTimelineSemaphore_t>( semaphore );
}

std::shared_ptr<VulkanTimelineSemaphore_t> CVulkanDevice::ImportTimelineSemaphore( gamescope::CTimeline *pTimeline )
{
std::shared_ptr<VulkanTimelineSemaphore_t> pSemaphore = std::make_unique<VulkanTimelineSemaphore_t>();
pSemaphore->pDevice = this;
VulkanTimelineSemaphore_t semaphore{};
semaphore.pDevice = this;


const VkSemaphoreTypeCreateInfo typeInfo =
{
Expand All @@ -1389,7 +1393,7 @@ std::shared_ptr<VulkanTimelineSemaphore_t> CVulkanDevice::ImportTimelineSemaphor
};

VkResult res;
if ( ( res = vk.CreateSemaphore( m_device, &createInfo, nullptr, &pSemaphore->pVkSemaphore ) ) != VK_SUCCESS )
if ( ( res = vk.CreateSemaphore( m_device, &createInfo, nullptr, &semaphore.pVkSemaphore ) ) != VK_SUCCESS )
{
vk_errorf( res, "vkCreateSemaphore failed" );
return nullptr;
Expand All @@ -1406,7 +1410,7 @@ std::shared_ptr<VulkanTimelineSemaphore_t> CVulkanDevice::ImportTimelineSemaphor
{
.sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR,
.pNext = nullptr,
.semaphore = pSemaphore->pVkSemaphore,
.semaphore = semaphore.pVkSemaphore,
.flags = 0, // not temporary
.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT,
.fd = dup( pTimeline->GetSyncobjFd() ),
Expand All @@ -1417,7 +1421,7 @@ std::shared_ptr<VulkanTimelineSemaphore_t> CVulkanDevice::ImportTimelineSemaphor
return nullptr;
}

return pSemaphore;
return std::make_shared<VulkanTimelineSemaphore_t>( semaphore );
}

void CVulkanCmdBuffer::AddDependency( std::shared_ptr<VulkanTimelineSemaphore_t> pTimelineSemaphore, uint64_t ulPoint )
Expand Down

0 comments on commit 2be93c6

Please sign in to comment.