Skip to content

Commit

Permalink
vulkan: fix fence initialization (#7038)
Browse files Browse the repository at this point in the history
Previously, we have a VulkanSync with a default constructor that
allows us to have sync objects that returns error when
actual fences are not yet present.  We need to replicate that
with VulkanFence since sync objects have been removed from the
API.

Fixes #7034
  • Loading branch information
poweifeng authored Aug 4, 2023
1 parent 2a12f71 commit f68825f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions filament/backend/src/vulkan/VulkanDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ void VulkanDriver::destroyRenderTarget(Handle<HwRenderTarget> rth) {

void VulkanDriver::createFenceR(Handle<HwFence> fh, int) {
VulkanCommandBuffer const& commandBuffer = mCommands->get();
construct<VulkanFence>(fh, commandBuffer);
construct<VulkanFence>(fh, commandBuffer.fence);
}

void VulkanDriver::createSwapChainR(Handle<HwSwapChain> sch, void* nativeWindow, uint64_t flags) {
Expand Down Expand Up @@ -579,7 +579,7 @@ Handle<HwRenderTarget> VulkanDriver::createRenderTargetS() noexcept {
}

Handle<HwFence> VulkanDriver::createFenceS() noexcept {
return allocHandle<VulkanFence>();
return initHandle<VulkanFence>();
}

Handle<HwSwapChain> VulkanDriver::createSwapChainS() noexcept {
Expand Down Expand Up @@ -664,6 +664,12 @@ void VulkanDriver::destroyFence(Handle<HwFence> fh) {

FenceStatus VulkanDriver::wait(Handle<HwFence> fh, uint64_t timeout) {
auto& cmdfence = handle_cast<VulkanFence*>(fh)->fence;
if (!cmdfence) {
// If wait is called before a fence actually exists, we return timeout. This matches the
// current behavior in OpenGLDriver, but we should eventually reconsider a different error
// code.
return FenceStatus::TIMEOUT_EXPIRED;
}

// Internally we use the VK_INCOMPLETE status to mean "not yet submitted".
// When this fence gets submitted, its status changes to VK_NOT_READY.
Expand Down
4 changes: 3 additions & 1 deletion filament/backend/src/vulkan/VulkanHandles.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ struct VulkanRenderPrimitive : public HwRenderPrimitive {
};

struct VulkanFence : public HwFence {
explicit VulkanFence(const VulkanCommandBuffer& commands) : fence(commands.fence) {}
VulkanFence() = default;
explicit VulkanFence(std::shared_ptr<VulkanCmdFence> fence) : fence(fence) {}

std::shared_ptr<VulkanCmdFence> fence;
};

Expand Down

0 comments on commit f68825f

Please sign in to comment.