yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
2.2 KiB94 linesraw
1// debug-swap-chain.cpp
2#include "debug-swap-chain.h"
3
4#include "debug-command-queue.h"
5#include "debug-helper-functions.h"
6#include "debug-texture.h"
7
8namespace gfx
9{
10using namespace Slang;
11
12namespace debug
13{
14
15const ISwapchain::Desc& DebugSwapchain::getDesc()
16{
17    SLANG_GFX_API_FUNC;
18    desc = baseObject->getDesc();
19    desc.queue = queue.Ptr();
20    return desc;
21}
22
23Result DebugSwapchain::getImage(GfxIndex index, ITextureResource** outResource)
24{
25    SLANG_GFX_API_FUNC;
26    maybeRebuildImageList();
27    if (index > (GfxCount)m_images.getCount())
28    {
29        GFX_DIAGNOSE_ERROR_FORMAT(
30            "`index`(%d) must not exceed total number of images (%d) in the swapchain.",
31            index,
32            (uint32_t)m_images.getCount());
33    }
34    returnComPtr(outResource, m_images[index]);
35    return SLANG_OK;
36}
37
38Result DebugSwapchain::present()
39{
40    SLANG_GFX_API_FUNC;
41    return baseObject->present();
42}
43
44int DebugSwapchain::acquireNextImage()
45{
46    SLANG_GFX_API_FUNC;
47    return baseObject->acquireNextImage();
48}
49
50Result DebugSwapchain::resize(GfxCount width, GfxCount height)
51{
52    SLANG_GFX_API_FUNC;
53    for (auto& image : m_images)
54    {
55        if (image->debugGetReferenceCount() != 1)
56        {
57            // Only warn here because tools like NSight might keep
58            // an additional reference to swapchain images.
59            GFX_DIAGNOSE_WARNING("all swapchain images must be released before calling resize().");
60            break;
61        }
62    }
63    m_images.clearAndDeallocate();
64    return baseObject->resize(width, height);
65}
66
67bool DebugSwapchain::isOccluded()
68{
69    SLANG_GFX_API_FUNC;
70    return baseObject->isOccluded();
71}
72
73Result DebugSwapchain::setFullScreenMode(bool mode)
74{
75    SLANG_GFX_API_FUNC;
76    return baseObject->setFullScreenMode(mode);
77}
78
79void DebugSwapchain::maybeRebuildImageList()
80{
81    SLANG_GFX_API_FUNC;
82    if (m_images.getCount() != 0)
83        return;
84    m_images.clearAndDeallocate();
85    for (GfxIndex i = 0; i < baseObject->getDesc().imageCount; i++)
86    {
87        RefPtr<DebugTextureResource> image = new DebugTextureResource();
88        baseObject->getImage(i, image->baseObject.writeRef());
89        m_images.add(image);
90    }
91}
92
93} // namespace debug
94} // namespace gfx