[Fix] (MG_Backend/DirectVulkan): key the sampled-set walk-skip on a program lifetime id, not the recyclable GL name, so a deleted+recreated program can't false-hit the cache

This commit is contained in:
2026-07-13 04:58:05 -04:00
parent f098983c9f
commit 7fe5247626
4 changed files with 24 additions and 8 deletions
@@ -7,6 +7,7 @@
// End of Source File Header
#include "ProgramObject.h"
#include <atomic>
#include <MG_Backend/BackendObjects.h>
#include <MG_State/GLState/VertexArrayState/VertexArrayObject.h>
#include <MG_Util/Converters/GLToStr/GLEnumConverter.h>
@@ -122,6 +123,12 @@ namespace {
}
namespace MobileGL::MG_State::GLState {
static std::atomic<Uint64> s_nextProgramLifetimeId = 1;
Uint64 ProgramObject::AllocateLifetimeId() {
return s_nextProgramLifetimeId.fetch_add(1, std::memory_order_relaxed);
}
void ProgramObject::ResetLinkArtifacts() {
// Relinking regenerates the SPIR-V, so any backend-cached state keyed on
// m_backendStateVersion (e.g. the content-hash memo) must be invalidated,
@@ -16,7 +16,7 @@
namespace MobileGL::MG_State::GLState {
class ProgramObject {
public:
ProgramObject(Uint externalIndex) : m_externalIndex(externalIndex) {}
ProgramObject(Uint externalIndex) : m_externalIndex(externalIndex), m_lifetimeId(AllocateLifetimeId()) {}
bool ShaderIsAttached(const SharedPtr<ShaderObject>& shader);
bool AttachShader(const SharedPtr<ShaderObject>& shader);
SizeT DetachShader(const SharedPtr<ShaderObject>& shader);
@@ -340,6 +340,11 @@ namespace MobileGL::MG_State::GLState {
}
Uint GetExternalIndex() const { return m_externalIndex; }
// Globally-unique, never-reused id for this program object's lifetime. Unlike the GL
// name (external index), which is freed to a LIFO list and immediately handed back by
// the next glCreateProgram, this distinguishes a deleted-and-recreated program from the
// original, so an identity cache can't false-hit on name recycling.
Uint64 GetLifetimeId() const { return m_lifetimeId; }
private:
void ResetLinkArtifacts();
@@ -349,7 +354,10 @@ namespace MobileGL::MG_State::GLState {
void AddDefaultFragmentShaderIfMissing();
Bool ValidateFragmentOutputLocations();
static Uint64 AllocateLifetimeId();
const Uint m_externalIndex = 0;
const Uint64 m_lifetimeId = 0;
Vector<SharedPtr<ShaderObject>> m_shaders;
Vector<SharedPtr<ShaderObject>> m_detachedShaders; // Store detached shaders and remove on next link