From 1be8c70da6a87378cdf4ddcf47f8ab4b0541fcab Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 30 Mar 2017 18:30:23 +0100 Subject: [PATCH] Make ResourceId::id member private, add ResourceId::Null() --- qrenderdoc/Code/QRDUtils.h | 4 +++- renderdoc/api/replay/renderdoc_replay.h | 20 +++++++++++++++++--- renderdoc/core/resource_manager.cpp | 4 +++- renderdoc/replay/type_helpers.cpp | 4 +++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/qrenderdoc/Code/QRDUtils.h b/qrenderdoc/Code/QRDUtils.h index c1fee77ab..1c3808850 100644 --- a/qrenderdoc/Code/QRDUtils.h +++ b/qrenderdoc/Code/QRDUtils.h @@ -53,7 +53,9 @@ struct ToStr { // super inefficient to convert to qstr then std::string then back to qstr // but this is just a temporary measure - return QString::number(el.id).toStdString(); + uint64_t num = 0; + memcpy(&num, &el, sizeof(num)); + return QString::number(num).toStdString(); } static std::string Get(const ReplayStatus &el) diff --git a/renderdoc/api/replay/renderdoc_replay.h b/renderdoc/api/replay/renderdoc_replay.h index 869ccba56..cc409d38a 100644 --- a/renderdoc/api/replay/renderdoc_replay.h +++ b/renderdoc/api/replay/renderdoc_replay.h @@ -117,19 +117,33 @@ typedef void *(RENDERDOC_CC *pRENDERDOC_AllocArrayMem)(uint64_t sz); #include "basic_types.h" +#ifdef RENDERDOC_EXPORTS +struct ResourceId; + +namespace ResourceIDGen +{ +// the only function allowed access to ResourceId internals, for allocating a new ID +ResourceId GetNewUniqueID(); +}; +#endif + // We give every resource a globally unique ID so that we can differentiate // between two textures allocated in the same memory (after the first is freed) // // it's a struct around a uint64_t to aid in template selection struct ResourceId { - uint64_t id; - ResourceId() : id() {} - ResourceId(uint64_t val, bool) { id = val; } + inline static ResourceId Null() { return ResourceId(); } bool operator==(const ResourceId u) const { return id == u.id; } bool operator!=(const ResourceId u) const { return id != u.id; } bool operator<(const ResourceId u) const { return id < u.id; } +private: + uint64_t id; + +#ifdef RENDERDOC_EXPORTS + friend ResourceId ResourceIDGen::GetNewUniqueID(); +#endif }; #include "capture_options.h" diff --git a/renderdoc/core/resource_manager.cpp b/renderdoc/core/resource_manager.cpp index f43e997c2..afac8d927 100644 --- a/renderdoc/core/resource_manager.cpp +++ b/renderdoc/core/resource_manager.cpp @@ -31,7 +31,9 @@ static volatile int64_t globalIDCounter = 1; ResourceId GetNewUniqueID() { - return ResourceId(Atomic::Inc64(&globalIDCounter), true); + ResourceId ret; + ret.id = Atomic::Inc64(&globalIDCounter); + return ret; } void SetReplayResourceIDs() diff --git a/renderdoc/replay/type_helpers.cpp b/renderdoc/replay/type_helpers.cpp index 2958a093c..09a7d2624 100644 --- a/renderdoc/replay/type_helpers.cpp +++ b/renderdoc/replay/type_helpers.cpp @@ -41,7 +41,9 @@ string ToStrHelper::Get(const ResourceId &el) { char tostrBuf[256] = {0}; - StringFormat::snprintf(tostrBuf, 255, "ResID_%llu", el.id); + RDCCOMPILE_ASSERT(sizeof(el) == sizeof(uint64_t), "ResourceId is no longer 1:1 with uint64_t"); + + StringFormat::snprintf(tostrBuf, 255, "ResID_%llu", (uint64_t &)el); return tostrBuf; }