Repository: google/filament
File: filament/backend/src/vulkan/VulkanCommands.h (C/C++)

Code before:
    std::pair<std::string, Timestamp> const& top() const;
    bool empty() const noexcept;

private:
    std::list<std::pair<std::string, Timestamp>> mMarkers;
};

#endif // FVK_DEBUG_GROUP_MARKERS

// The submission fence has shared ownership semantics because it is potentially wrapped by a
// DriverApi fence object and should not be destroyed until both the DriverApi object is freed and
// we're done waiting on the most recent submission of the given command buffer.
struct VulkanCommandBuffer {
    VulkanCommandBuffer(VulkanContext* mContext,
            VkDevice device, VkQueue queue, VkCommandPool pool, bool isProtected);

    VulkanCommandBuffer(VulkanCommandBuffer const&) = delete;
    VulkanCommandBuffer& operator=(VulkanCommandBuffer const&) = delete;

    ~VulkanCommandBuffer();

    inline void acquire(fvkmemory::resource_ptr<fvkmemory::Resource> resource) {
        mResources.push_back(resource);
    }

    inline void trackStageBlock(std::unique_ptr<VulkanStage::Block> stageBlock) {
        mStageBlocks.push_back(std::move(stageBlock));
    }

    inline void releaseStageBlocks() { mStageBlocks.clear(); }

    void reset() noexcept;

    inline void insertWait(VkSemaphore sem) {
        mWaitSemaphores.push_back(sem);
    }

    void pushMarker(char const* marker) noexcept;
    void popMarker() noexcept;
    void insertEvent(char const* marker) noexcept;

    void begin() noexcept;
    VkSemaphore submit();

    inline void setComplete() {
        mFenceStatus->setStatus(VK_SUCCESS);
    }

    VkResult getStatus() {
        return mFenceStatus->getStatus();
    }

Review comment (suggestion):
If you can make `VulkanStage::Block` a `fvkmemory::Resource`, then you can essentially just use `acquire` from the line above.

Code after:

private:
    std::list<std::pair<std::string, Timestamp>> mMarkers;
};

#endif // FVK_DEBUG_GROUP_MARKERS

// The submission fence has shared ownership semantics because it is potentially wrapped by a
// DriverApi fence object and should not be destroyed until both the DriverApi object is freed and
// we're done waiting on the most recent submission of the given command buffer.
struct VulkanCommandBuffer {
    VulkanCommandBuffer(VulkanContext* mContext,
            VkDevice device, VkQueue queue, VkCommandPool pool, bool isProtected);

    VulkanCommandBuffer(VulkanCommandBuffer const&) = delete;
    VulkanCommandBuffer& operator=(VulkanCommandBuffer const&) = delete;

    ~VulkanCommandBuffer();

    inline void acquire(fvkmemory::resource_ptr<fvkmemory::Resource> resource) {
        mResources.push_back(resource);
    }

    void reset() noexcept;

    inline void insertWait(VkSemaphore sem) {
        mWaitSemaphores.push_back(sem);
    }

    void pushMarker(char const* marker) noexcept;
    void popMarker() noexcept;
    void insertEvent(char const* marker) noexcept;

    void begin() noexcept;
    VkSemaphore submit();

    inline void setComplete() {
        mFenceStatus->setStatus(VK_SUCCESS);
    }

    VkResult getStatus() {
        return mFenceStatus->getStatus();
    }

    std::shared_ptr<VulkanCmdFence> getFenceStatus() const {
        return mFenceStatus;
    }

    VkFence getVkFence() const {
        return mFence;
    }