From 0c1bb18a1b345f785553919dbf8cce739193f894 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 6 Oct 2025 16:02:54 +0100 Subject: [PATCH] Prepare to remove live<->replay resource id map lookups * Resources will be given the ID to use on replay in order to match the original IDs. Any internal replay-time resources are given the same namespaced IDs as before. * We add a new per-ID query to check if something is replay-only or not. --- renderdoc/api/replay/resourceid.h | 6 ++---- renderdoc/core/core.cpp | 2 +- renderdoc/core/resource_manager.cpp | 11 +++++++++-- renderdoc/core/resource_manager.h | 1 + 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/renderdoc/api/replay/resourceid.h b/renderdoc/api/replay/resourceid.h index 4786c8648..76e59f18f 100644 --- a/renderdoc/api/replay/resourceid.h +++ b/renderdoc/api/replay/resourceid.h @@ -45,10 +45,8 @@ DOCUMENT(R"(This is an opaque identifier that uniquely locates a resource. .. note:: These IDs do not overlap ever - textures, buffers, shaders and samplers will all have unique IDs - and do not reuse the namespace. Likewise the IDs assigned for resources during capture are not - re-used on replay - the corresponding resources created on replay to stand-in for capture-time - resources are given unique IDs and a mapping is stored to between the capture-time resource and - the replay-time one. + and do not reuse the namespace. The IDs assigned for resources during capture are also used + during replay. Any internal/synthesised resources created during replay will have distinct IDs. )"); struct ResourceId { diff --git a/renderdoc/core/core.cpp b/renderdoc/core/core.cpp index 9e2fe914c..935004e3d 100644 --- a/renderdoc/core/core.cpp +++ b/renderdoc/core/core.cpp @@ -104,7 +104,7 @@ rdcstr DoStringise(const ResourceId &el) // hardcode empty/null ResourceId to both avoid special case below and fast-path a common case as // a string literal. if(num == 0) - return PREFIX "0"; + return PREFIX "0"_lit; // enough for prefix and a 64-bit value in decimal char str[48] = {}; diff --git a/renderdoc/core/resource_manager.cpp b/renderdoc/core/resource_manager.cpp index e27bbfba8..f2706bddd 100644 --- a/renderdoc/core/resource_manager.cpp +++ b/renderdoc/core/resource_manager.cpp @@ -30,6 +30,7 @@ namespace ResourceIDGen { static int64_t globalIDCounter = 1; +static ResourceId baseReplayID; ResourceId GetNewUniqueID() { @@ -38,16 +39,22 @@ ResourceId GetNewUniqueID() return ret; } +bool IsReplayOnlyID(ResourceId id) +{ + return baseReplayID < id; +} + void SetReplayResourceIDs() { - // separate replay IDs from live IDs by adding a value when replaying. - // 1000000000000000000 live IDs before we overlap replay IDs gives + // separate replay-only IDs from captured IDs by adding a value when replaying. + // 1000000000000000000 capture-time IDs before we overlap replay IDs gives // almost 32 years generating 100000 IDs per frame at 10000 FPS. // only add this value once (since we're not |'ing on a bit) if(globalIDCounter < 1000000000000000000LL) globalIDCounter = RDCMAX(int64_t(globalIDCounter), int64_t(globalIDCounter + 1000000000000000000LL)); + baseReplayID = GetNewUniqueID(); } }; diff --git a/renderdoc/core/resource_manager.h b/renderdoc/core/resource_manager.h index a9311f1be..788fb46da 100644 --- a/renderdoc/core/resource_manager.h +++ b/renderdoc/core/resource_manager.h @@ -296,6 +296,7 @@ inline bool MarkReferenced(std::unordered_map &refs, R namespace ResourceIDGen { ResourceId GetNewUniqueID(); +bool IsReplayOnlyID(ResourceId id); void SetReplayResourceIDs(); };