summaryrefslogtreecommitdiffstats
path: root/tools/gfx/vulkan/vk-swap-chain.h
blob: 166140ccecf707f1744e44392703ba70c981be1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// vk-swap-chain.h
#pragma once

#include "vk-base.h"
#include "vk-command-queue.h"
#include "vk-device.h"
#include "vk-texture.h"

namespace gfx
{

using namespace Slang;

namespace vk
{

class SwapchainImpl : public ISwapchain, public ComObject
{
public:
    SLANG_COM_OBJECT_IUNKNOWN_ALL
    ISwapchain* getInterface(const Guid& guid);

public:
    VkSwapchainKHR m_swapChain;
    VkSurfaceKHR m_surface;
    VkSemaphore m_nextImageSemaphore; // Semaphore to signal after `acquireNextImage`.
    ISwapchain::Desc m_desc;
    VkFormat m_vkformat;
    RefPtr<CommandQueueImpl> m_queue;
    ShortList<RefPtr<TextureResourceImpl>> m_images;
    RefPtr<DeviceImpl> m_renderer;
    VulkanApi* m_api;
    uint32_t m_currentImageIndex = 0;
    WindowHandle m_windowHandle;
#if SLANG_APPLE_FAMILY
    void* m_metalLayer;
#endif

    void destroySwapchainAndImages();

    void getWindowSize(int* widthOut, int* heightOut) const;

    Result createSwapchainAndImages();

public:
    ~SwapchainImpl();

    static Index _indexOfFormat(List<VkSurfaceFormatKHR>& formatsIn, VkFormat format);

    Result init(DeviceImpl* renderer, const ISwapchain::Desc& desc, WindowHandle window);

    virtual SLANG_NO_THROW const Desc& SLANG_MCALL getDesc() override { return m_desc; }
    virtual SLANG_NO_THROW Result SLANG_MCALL
    getImage(GfxIndex index, ITextureResource** outResource) override;
    virtual SLANG_NO_THROW Result SLANG_MCALL resize(GfxCount width, GfxCount height) override;
    virtual SLANG_NO_THROW Result SLANG_MCALL present() override;
    virtual SLANG_NO_THROW int SLANG_MCALL acquireNextImage() override;
    virtual SLANG_NO_THROW bool SLANG_MCALL isOccluded() override { return false; }
    virtual SLANG_NO_THROW Result SLANG_MCALL setFullScreenMode(bool mode) override;
};

} // namespace vk
} // namespace gfx