Celtoys / Remotery

Single C file, Realtime CPU/GPU Profiler with Remote Web Viewer
Apache License 2.0
3.11k stars 264 forks source link

Metal broken #230

Closed fhoenig closed 2 years ago

fhoenig commented 2 years ago

Hi Don- Metal build is broken at version > v1.0.0.

dwilliamson commented 2 years ago

I haven't worked with Metal for years, now, so unable to check its status (no HW to test).

We have multiple Metal users at the moment so hopefully some fixes will come through.

PRs are always welcome.

fhoenig commented 2 years ago

Understandable. Actually 1.0 is also not working. Seems like some major changes broke most of it. On a first quick look I can see that some calls are not the right size of parameters etc.

Using the CPU only side of the tool, it looks pretty awesome though :-) I just wanted something quick, since I've been using Microprofile and there is no Metal. Neither does it exist in Tracy.

dwilliamson commented 2 years ago

A quick look over the code doesn't point to anything obvious.

It's unfortunate that you can only sample Metal at the command buffer level, though. But I guess that's tiled GPUs for you.

fhoenig commented 2 years ago

I did this in the main file and some other stuff in the .m file. It seems to work, but hits an assert on shutdown.

assert(allocator->nb_inuse == 0); // remotery.c ObjectAllocator_Destructor

9514c9514
<     rmtTryMallocArray(Metal, *metal);
---
>     rmtTryMalloc(Metal, *metal);
9519c9519,9520
<     return error;
---
>     //return error;
>     return RMT_ERROR_NONE;
9646c9647
< RMT_API void _rmt_BeginMetalSample(rmtPStr name, rmtU32* hash_cache)
---
> RMT_API rmtError _rmt_BeginMetalSample(rmtPStr name, rmtU32* hash_cache)
9651c9652
<         return;
---
>         return RMT_ERROR_UNKNOWN;
9663d9663
<             rmtError error;
9666,9667d9665
<             if (error != RMT_ERROR_NONE)
<                 return;
9677a9676
>     return RMT_ERROR_NONE;
dwilliamson commented 2 years ago

Yeah, that's a known assert and not caused by your change. Safe to comment it out as it's really only for debug to track unreleased allocations.

fhoenig commented 2 years ago

Okay got it.

Btw, not sure if I broke this, but properties don't show up in the web GUI.

rmt_PropertyDefine_U64(entityCount, 0, NoFlags, "Entity Count");

void gameupdate(int frameNumber)
{
    rmt_PropertySet_U64(entityCount, world.size());   
}
dwilliamson commented 2 years ago

You need to call these once at the end of each of your frames:

rmt_PropertySnapshotAll();
rmt_PropertyFrameResetAll();
fhoenig commented 2 years ago

Okay good. Out of context here but in case I get the time to commit this, making sure I understand all.

dwilliamson commented 2 years ago

Right now that API is in flux because I'm uncomfortable requiring people call a per-frame function to kick this all off. However, there's no way to do automatic frame resets of some of your properties if you don't tell Remotery when your frame is.

fhoenig commented 2 years ago

Still nothing shows up. I tried to put them in all threads.

dwilliamson commented 2 years ago

Those calls need to be only on one of your main threads. This is very odd; we have builds across all of the Apple platforms showing properties at the moment. What happens if you add it to a group?

rmt_PropertyDefine_Group(Groupy, "Groupy");
rmt_PropertyDefine_U64(entityCount, 0, NoFlags, "Entity Count", &Groupy);
fhoenig commented 2 years ago

Nothing.

rmt_PropertyDefine_Group(GamePlay, "GamePlay");
rmt_PropertyDefine_U64(entityCount, 0, NoFlags, "Entity Count", &GamePlay);

// gameplay thread func
void gameupdate(int frameNumber)
{
    //Log::debug("gameplay frame %llu", frameNumber);
    rmt_PropertySet_U64(entityCount, world.size());
}
rmt_SetCurrentThreadName("Main");
    while (running)
    {
        rmt_MarkFrame();

        rmt_BeginCPUSample(EventLoop, 0);

     // do stuff

        rmt_EndCPUSample();
        rmt_PropertySnapshotAll();
        rmt_PropertyFrameResetAll();

    }

I am on main branch.

dwilliamson commented 2 years ago

Thanks for you help on this, I have copied over your fixes.

If you are still having issues with properties, can you compile and run sample/dump.c and see if it works? If so, try to copy what it's doing. If nothing works, please open a new Issue.