summaryrefslogtreecommitdiffstats
path: root/tools/gfx/metal/metal-command-buffer.h
blob: 1f791d1744ed4bf60e3f442bcd40669a71db2c5e (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
64
65
66
67
68
// metal-command-buffer.h
#pragma once

#include "../simple-transient-resource-heap.h"
#include "metal-base.h"
#include "metal-command-encoder.h"
#include "metal-shader-object.h"

namespace gfx
{

using namespace Slang;

namespace metal
{

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

public:
    RefPtr<DeviceImpl> m_device;
    NS::SharedPtr<MTL::CommandBuffer> m_commandBuffer;
    RootShaderObjectImpl m_rootObject;
    // RefPtr<MutableRootShaderObjectImpl> m_mutableRootShaderObject;

    RefPtr<ResourceCommandEncoder> m_resourceCommandEncoder = nullptr;
    RefPtr<ComputeCommandEncoder> m_computeCommandEncoder = nullptr;
    RefPtr<RenderCommandEncoder> m_renderCommandEncoder = nullptr;
    RefPtr<RayTracingCommandEncoder> m_rayTracingCommandEncoder = nullptr;

    NS::SharedPtr<MTL::RenderCommandEncoder> m_metalRenderCommandEncoder;
    NS::SharedPtr<MTL::ComputeCommandEncoder> m_metalComputeCommandEncoder;
    NS::SharedPtr<MTL::BlitCommandEncoder> m_metalBlitCommandEncoder;

    // Command buffers are deallocated by its command pool,
    // so no need to free individually.
    ~CommandBufferImpl() = default;

    Result init(DeviceImpl* device, TransientResourceHeapImpl* transientHeap);

    void beginCommandBuffer();

    MTL::RenderCommandEncoder* getMetalRenderCommandEncoder(
        MTL::RenderPassDescriptor* renderPassDesc);
    MTL::ComputeCommandEncoder* getMetalComputeCommandEncoder();
    MTL::BlitCommandEncoder* getMetalBlitCommandEncoder();
    void endMetalCommandEncoder();

public:
    virtual SLANG_NO_THROW void SLANG_MCALL encodeRenderCommands(
        IRenderPassLayout* renderPass,
        IFramebuffer* framebuffer,
        IRenderCommandEncoder** outEncoder) override;
    virtual SLANG_NO_THROW void SLANG_MCALL
    encodeComputeCommands(IComputeCommandEncoder** outEncoder) override;
    virtual SLANG_NO_THROW void SLANG_MCALL
    encodeResourceCommands(IResourceCommandEncoder** outEncoder) override;
    virtual SLANG_NO_THROW void SLANG_MCALL
    encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override;
    virtual SLANG_NO_THROW void SLANG_MCALL close() override;
    virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outHandle) override;
};

} // namespace metal
} // namespace gfx