diff --git a/src/gpu/graphite/Resource.cpp b/src/gpu/graphite/Resource.cpp index d862d09da12..bfd9cc18449 100644 --- a/src/gpu/graphite/Resource.cpp +++ b/src/gpu/graphite/Resource.cpp @@ -13,9 +13,9 @@ namespace skgpu::graphite { namespace { -uint32_t create_unique_id() { - static std::atomic nextID{1}; - uint32_t id; +uint64_t create_unique_id() { + static std::atomic nextID{1}; + uint64_t id; do { id = nextID.fetch_add(1, std::memory_order_relaxed); } while (id == SK_InvalidUniqueID); @@ -118,7 +118,7 @@ void Resource::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump, } SkString resourceName("skia/gpu_resources/resource_"); - resourceName.appendU32(this->uniqueID().asUInt()); + resourceName.appendU64(this->uniqueID().asUInt()); traceMemoryDump->dumpNumericValue(resourceName.c_str(), "size", "bytes", size); traceMemoryDump->dumpStringValue(resourceName.c_str(), "type", this->getResourceType()); diff --git a/src/gpu/graphite/Resource.h b/src/gpu/graphite/Resource.h index 0f995ec55f2..0941ceb6f1a 100644 --- a/src/gpu/graphite/Resource.h +++ b/src/gpu/graphite/Resource.h @@ -247,15 +247,15 @@ public: public: UniqueID() = default; - explicit UniqueID(uint32_t id) : fID(id) {} + explicit UniqueID(uint64_t id) : fID(id) {} - uint32_t asUInt() const { return fID; } + uint64_t asUInt() const { return fID; } bool operator==(const UniqueID& other) const { return fID == other.fID; } bool operator!=(const UniqueID& other) const { return !(*this == other); } private: - uint32_t fID = SK_InvalidUniqueID; + uint64_t fID = SK_InvalidUniqueID; }; // Gets an id that is unique for this Resource object. It is static in that it does not change diff --git a/tests/graphite/GraphiteResourceCacheTest.cpp b/tests/graphite/GraphiteResourceCacheTest.cpp index 85ef7a16f40..11badf55c18 100644 --- a/tests/graphite/GraphiteResourceCacheTest.cpp +++ b/tests/graphite/GraphiteResourceCacheTest.cpp @@ -988,4 +988,13 @@ DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(GraphiteTimeLimitedPurgeTest, REPORTER_ASSERT(reporter, resourceCache->getResourceCount() < kLargeResourceCount); } +DEF_GRAPHITE_TEST(GraphiteResourceUniqueIDSize, reporter, CtsEnforcement::kNever) { + // Several backends key per-resource caches (e.g. bind groups, descriptor sets, + // framebuffers) on Resource::UniqueID, so the ID must remain unique for the + // lifetime of the process. With a 32-bit counter a long-running process could + // construct enough Resources to wrap the counter and produce a collision. + using IdType = decltype(std::declval().asUInt()); + REPORTER_ASSERT(reporter, sizeof(IdType) >= sizeof(uint64_t)); +} + } // namespace skgpu::graphite