yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
1.9 KiB73 linesraw
1// metal-query.cpp
2#include "metal-query.h"
3
4// #include "metal-util.h"
5
6namespace gfx
7{
8
9using namespace Slang;
10
11namespace metal
12{
13
14QueryPoolImpl::~QueryPoolImpl() {}
15
16static MTL::CounterSet* findCounterSet(MTL::Device* device, QueryType queryType)
17{
18    if (queryType != QueryType::Timestamp)
19    {
20        return nullptr;
21    }
22
23    static NS::String* timestampStr = MTLSTR("timestamp");
24
25    for (int i = 0; i < device->counterSets()->count(); ++i)
26    {
27        MTL::CounterSet* counterSet =
28            static_cast<MTL::CounterSet*>(device->counterSets()->object(i));
29        for (int j = 0; j < counterSet->counters()->count(); ++j)
30        {
31            MTL::Counter* counter = static_cast<MTL::Counter*>(counterSet->counters()->object(j));
32            if (counter->name()->isEqualToString(MTL::CommonCounterTimestamp))
33            {
34                return counterSet;
35            }
36        }
37    }
38    return nullptr;
39}
40
41Result QueryPoolImpl::init(DeviceImpl* device, const IQueryPool::Desc& desc)
42{
43    m_device = device;
44    m_desc = desc;
45
46    MTL::CounterSet* counterSet = findCounterSet(m_device->m_device.get(), m_desc.type);
47    if (!counterSet)
48    {
49        return SLANG_E_NOT_AVAILABLE;
50    }
51
52    NS::SharedPtr<MTL::CounterSampleBufferDescriptor> counterSampleBufferDesc =
53        NS::TransferPtr(MTL::CounterSampleBufferDescriptor::alloc()->init());
54    counterSampleBufferDesc->setStorageMode(MTL::StorageModeShared);
55    counterSampleBufferDesc->setSampleCount(m_desc.count);
56    counterSampleBufferDesc->setCounterSet(counterSet);
57
58    m_device->m_device->counterSets();
59
60    NS::Error* error;
61    m_counterSampleBuffer = NS::TransferPtr(
62        m_device->m_device->newCounterSampleBuffer(counterSampleBufferDesc.get(), &error));
63
64    return m_counterSampleBuffer ? SLANG_OK : SLANG_FAIL;
65}
66
67Result QueryPoolImpl::getResult(GfxIndex index, GfxCount count, uint64_t* data)
68{
69    return SLANG_E_NOT_IMPLEMENTED;
70}
71
72} // namespace metal
73} // namespace gfx