diff --git a/src/gpu/graphite/dawn/DawnResourceProvider.cpp b/src/gpu/graphite/dawn/DawnResourceProvider.cpp index c45e39e0c8..67424b0524 100644 --- a/src/gpu/graphite/dawn/DawnResourceProvider.cpp +++ b/src/gpu/graphite/dawn/DawnResourceProvider.cpp @@ -143,14 +143,21 @@ UniformBindGroupKey make_ubo_bind_group_key( return uniqueKey; } -BindGroupKey<1> make_texture_bind_group_key(const DawnSampler* sampler, +BindGroupKey<2> make_texture_bind_group_key(const DawnSampler* sampler, const DawnTexture* texture) { - BindGroupKey<1> uniqueKey; + BindGroupKey<2> uniqueKey; { - BindGroupKey<1>::Builder builder(&uniqueKey); + BindGroupKey<2>::Builder builder(&uniqueKey); builder[0] = sampler->uniqueID().asUInt(); builder[1] = texture->uniqueID().asUInt(); + // Resource::uniqueID() is a process-global 32-bit counter that can + // wrap after ~2^32 constructions, and this cache is not invalidated + // when an individual DawnTexture is destroyed. Mix in the actual Dawn + // texture-view handle so a wrapped ID cannot alias a stale entry. + uintptr_t view = reinterpret_cast(texture->sampleTextureView().Get()); + builder[2] = static_cast(view); + builder[3] = static_cast(view >> 32); builder.finish(); } diff --git a/src/gpu/graphite/dawn/DawnResourceProvider.h b/src/gpu/graphite/dawn/DawnResourceProvider.h index ef2eb2c494..262e0a5812 100644 --- a/src/gpu/graphite/dawn/DawnResourceProvider.h +++ b/src/gpu/graphite/dawn/DawnResourceProvider.h @@ -114,7 +114,11 @@ private: typename BindGroupKey::Hash>; BindGroupCache fUniformBufferBindGroupCache; - BindGroupCache<1> fSingleTextureSamplerBindGroups; + // Bandaid for 32-bit Resource::uniqueID() wraparound: also key on the + // 64-bit WGPUTextureView handle so a stale BindGroup whose underlying + // texture has been Destroy()ed cannot be returned for a fresh texture + // that happens to receive the same recycled 32-bit uniqueID. + BindGroupCache<2> fSingleTextureSamplerBindGroups; class IntrinsicBuffer; class IntrinsicConstantsManager;