Skip to content

Commit 90e00b6

Browse files
authored
Add reporting of RHI live objects if enabled (#471)
* Add reporting of RHI live objects if enabled * Add missing cstdio include * disable SLANG_RHI_ENABLE_REF_OBJECT_TRACKING * Cast to void * * formatting
1 parent 486b249 commit 90e00b6

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

include/slang-rhi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3292,7 +3292,7 @@ class IRHI
32923292
}
32933293

32943294
/// Reports current set of live objects.
3295-
/// Currently this just calls D3D's ReportLiveObjects.
3295+
/// Lists all live RHI objects as well as D3D's live objects (using ReportLiveObjects).
32963296
virtual SLANG_NO_THROW Result SLANG_MCALL reportLiveObjects() = 0;
32973297

32983298
/// Set the global task pool for the RHI.

src/core/smart-pointer.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
#include "smart-pointer.h"
22

3+
#include <cstdio>
4+
35
namespace rhi {
46

7+
#if SLANG_RHI_ENABLE_REF_OBJECT_TRACKING
8+
void RefObjectTracker::reportLiveObjects()
9+
{
10+
if (!objects.empty())
11+
{
12+
printf("Found %zu live RHI objects!\n", objects.size());
13+
for (auto obj : objects)
14+
{
15+
printf("Live object: %p\n", static_cast<void*>(obj));
16+
}
17+
}
18+
}
19+
#endif
20+
521
#if SLANG_RHI_DEBUG
622
std::atomic<uint64_t> RefObject::s_objectCount = 0;
723
#endif

src/core/smart-pointer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ struct RefObjectTracker
3131
objects.erase(obj);
3232
}
3333

34+
void reportLiveObjects();
35+
3436
static RefObjectTracker& instance()
3537
{
3638
static RefObjectTracker tracker;

src/rhi.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ Result RHI::createBlob(const void* data, size_t size, ISlangBlob** outBlob)
391391

392392
Result RHI::reportLiveObjects()
393393
{
394+
#if SLANG_RHI_ENABLE_REF_OBJECT_TRACKING
395+
RefObjectTracker::instance().reportLiveObjects();
396+
#endif
394397
#if SLANG_RHI_ENABLE_D3D11 | SLANG_RHI_ENABLE_D3D12
395398
SLANG_RETURN_ON_FAIL(reportD3DLiveObjects());
396399
#endif

0 commit comments

Comments
 (0)