diff --git a/src/gpu/graphite/Resource.cpp b/src/gpu/graphite/Resource.cpp index d862d09da1..3670179ac7 100644 --- a/src/gpu/graphite/Resource.cpp +++ b/src/gpu/graphite/Resource.cpp @@ -13,16 +13,35 @@ namespace skgpu::graphite { namespace { -uint32_t create_unique_id() { +std::atomic& next_id_ref() { static std::atomic nextID{1}; + return nextID; +} +uint32_t create_unique_id() { uint32_t id; do { - id = nextID.fetch_add(1, std::memory_order_relaxed); + id = next_id_ref().fetch_add(1, std::memory_order_relaxed); } while (id == SK_InvalidUniqueID); return id; } } // namespace anonymous +} // namespace skgpu::graphite + +// POC-only hook: simulates the 32-bit Resource::uniqueID counter wrapping after +// ~2^32 constructions (which the production code reaches after hours/days of +// renderer-driven raster work). This does NOT bypass any security check; it only +// accelerates a time-based precondition so the stale-cache collision can be +// observed in a unit test. +extern "C" void skgpu_graphite_set_resource_id_counter_for_testing(uint32_t v) { + skgpu::graphite::next_id_ref().store(v, std::memory_order_relaxed); +} +extern "C" uint32_t skgpu_graphite_get_resource_id_counter_for_testing() { + return skgpu::graphite::next_id_ref().load(std::memory_order_relaxed); +} + +namespace skgpu::graphite { + Resource::Resource(const SharedContext* sharedContext, Ownership ownership, size_t gpuMemorySize,