summaryrefslogtreecommitdiffstats
path: root/tools/gfx/simple-transient-resource-heap.h
blob: 1a72614818a8e24e2124b03566e440b384dd3b90 (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
// simple-render-pass-layout.h
#pragma once

// Provide a simple no-op implementation for `ITransientResourceHeap` for targets that
// already support version management.

#include "renderer-shared.h"
#include "slang-gfx.h"

namespace gfx
{
template<typename TDevice, typename TCommandBuffer>
class SimpleTransientResourceHeap : public TransientResourceHeapBase
{
public:
    Slang::RefPtr<TDevice> m_device;
    Slang::ComPtr<IBufferResource> m_constantBuffer;

public:
    Result init(TDevice* device, const ITransientResourceHeap::Desc& desc)
    {
        m_device = device;
        IBufferResource::Desc bufferDesc = {};
        bufferDesc.type = IResource::Type::Buffer;
        bufferDesc.allowedStates =
            ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopyDestination);
        bufferDesc.defaultState = ResourceState::ConstantBuffer;
        bufferDesc.sizeInBytes = desc.constantBufferSize;
        bufferDesc.memoryType = MemoryType::Upload;
        SLANG_RETURN_ON_FAIL(
            device->createBufferResource(bufferDesc, nullptr, m_constantBuffer.writeRef()));
        return SLANG_OK;
    }
    virtual SLANG_NO_THROW Result SLANG_MCALL
    createCommandBuffer(ICommandBuffer** outCommandBuffer) override
    {
        Slang::RefPtr<TCommandBuffer> newCmdBuffer = new TCommandBuffer();
        newCmdBuffer->init(m_device, this);
        returnComPtr(outCommandBuffer, newCmdBuffer);
        return SLANG_OK;
    }

    virtual SLANG_NO_THROW Result SLANG_MCALL synchronizeAndReset() override
    {
        ++getVersionCounter();
        return SLANG_OK;
    }
};
} // namespace gfx