summaryrefslogtreecommitdiff
path: root/tools/gfx/metal/metal-command-queue.cpp
blob: c8b36ff1ea8fdfbd1dd9727a79a5c7354273a2ff (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
69
70
71
72
73
74
75
// metal-command-queue.cpp
#include "metal-command-queue.h"

#include "metal-command-buffer.h"
#include "metal-fence.h"

namespace gfx
{

using namespace Slang;

namespace metal 
{

ICommandQueue* CommandQueueImpl::getInterface(const Guid& guid)
{
    if (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_ICommandQueue)
        return static_cast<ICommandQueue*>(this);
    return nullptr;
}

CommandQueueImpl::~CommandQueueImpl()
{
}

void CommandQueueImpl::init(DeviceImpl* renderer)
{
    m_renderer = renderer;

    MTL::Device* device = m_renderer->m_device;
    m_commandQueue = device->newCommandQueue(8);
}

void CommandQueueImpl::waitOnHost()
{
}

Result CommandQueueImpl::getNativeHandle(InteropHandle* outHandle)
{
    outHandle->api = InteropHandleAPI::Metal;
    outHandle->handleValue = reinterpret_cast<intptr_t>(m_commandQueue);
    return SLANG_OK;
}

const CommandQueueImpl::Desc& CommandQueueImpl::getDesc() { return m_desc; }

Result CommandQueueImpl::waitForFenceValuesOnDevice(
    GfxCount fenceCount, IFence** fences, uint64_t* waitValues)
{
    return SLANG_E_NOT_IMPLEMENTED;
}

void CommandQueueImpl::queueSubmitImpl(
    uint32_t count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal)
{
    for (uint32_t i = 0; i < count; ++i)
    {
        CommandBufferImpl* cmdBufImpl = static_cast<CommandBufferImpl*>(commandBuffers[i]);
        cmdBufImpl->m_commandBuffer->presentDrawable(m_renderer->m_drawable);
        cmdBufImpl->m_commandBuffer->commit();
    }
}

void CommandQueueImpl::executeCommandBuffers(
    GfxCount count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal)
{
    if (count == 0 && fence == nullptr)
    {
        return;
    }
    queueSubmitImpl(count, commandBuffers, fence, valueToSignal);
}

} // namespace metal
} // namespace gfx