mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Fix] (DirectVulkan): rewrite implicit-LOD fragment samples to explicit LOD 0 when every bound sampler is pinned to a single mip level - Adreno 650 (driver 512.502) reads outside a full-screen colour render target's allocation on its implicit-LOD sampling path and faults the GPU, which killed MC 26.2 on its own blit shader (texture(InSampler, texCoord)) between frames 344-421 on every run; this is the same driver defect the default-framebuffer blit shader already works around with textureLod, but an application's shader cannot be edited, so ForceExplicitLod0SamplePass converts OpImageSample*ImplicitLod to the explicit form at the SPIR-V level under a new CompileOptionBit that is only requested when the rewrite provably cannot move a texel (every sampler binding on a single-level view, no anisotropy, and either a LOD clamp that already pins lambda at 0 or min and mag filters that agree - an explicit LOD 0 always takes the magnification side of the min/mag decision); a single-level view now also clamps its sampler to mipmapMode NEAREST with maxLod min(maxLod, 0.25) rather than 0, since collapsing the clamp would make every fragment magnify and quietly retire the min filter; and the program's backend hash memo grows from one slot to four so a program resolved under two compile-flag sets in the same frame stops re-hashing every stage's SPIR-V once per draw
This commit is contained in:
@@ -334,16 +334,32 @@ namespace MobileGL::MG_State::GLState {
|
||||
// draw. The memo is keyed by (backendStateVersion, flags); ResetLinkArtifacts and
|
||||
// the binding setters below invalidate it by bumping m_backendStateVersion.
|
||||
Bool GetBackendHashMemo(Uint flags, Uint64& outHash) const {
|
||||
if (m_backendHashMemoVersion != m_backendStateVersion || m_backendHashMemoFlags != flags) {
|
||||
return false;
|
||||
if (m_backendHashMemoVersion != m_backendStateVersion) return false;
|
||||
for (const auto& slot : m_backendHashMemoSlots) {
|
||||
if (slot.valid && slot.flags == flags) {
|
||||
outHash = slot.hash;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
outHash = m_backendHashMemo;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
void SetBackendHashMemo(Uint flags, Uint64 hash) const {
|
||||
m_backendHashMemo = hash;
|
||||
m_backendHashMemoVersion = m_backendStateVersion;
|
||||
m_backendHashMemoFlags = flags;
|
||||
if (m_backendHashMemoVersion != m_backendStateVersion) {
|
||||
for (auto& slot : m_backendHashMemoSlots) slot.valid = false;
|
||||
m_backendHashMemoVersion = m_backendStateVersion;
|
||||
m_backendHashMemoNextSlot = 0;
|
||||
}
|
||||
for (auto& slot : m_backendHashMemoSlots) {
|
||||
if (slot.valid && slot.flags == flags) {
|
||||
slot.hash = hash;
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto& slot = m_backendHashMemoSlots[m_backendHashMemoNextSlot];
|
||||
slot.flags = flags;
|
||||
slot.hash = hash;
|
||||
slot.valid = true;
|
||||
m_backendHashMemoNextSlot = (m_backendHashMemoNextSlot + 1) % kBackendHashMemoSlotCount;
|
||||
}
|
||||
|
||||
void SetUniformSamplerOrImageUnitIndex(Uint location, Int unit) {
|
||||
@@ -527,10 +543,19 @@ namespace MobileGL::MG_State::GLState {
|
||||
Uint32 m_backendStateVersion = 0;
|
||||
|
||||
// Backend-owned content-hash memo (see GetBackendHashMemo): valid only while
|
||||
// m_backendStateVersion and the compile flags match the recorded values.
|
||||
mutable Uint64 m_backendHashMemo = 0;
|
||||
// m_backendStateVersion matches. Several slots, not one: a backend may resolve the same
|
||||
// program under more than one compile-flag set within a frame (surface rotation, and the
|
||||
// explicit-LOD sampling variant), and a single slot would then miss on every lookup and
|
||||
// re-hash the program's whole SPIR-V once per draw.
|
||||
static constexpr SizeT kBackendHashMemoSlotCount = 4;
|
||||
struct BackendHashMemoSlot {
|
||||
Uint64 hash = 0;
|
||||
Uint flags = 0;
|
||||
Bool valid = false;
|
||||
};
|
||||
mutable Array<BackendHashMemoSlot, kBackendHashMemoSlotCount> m_backendHashMemoSlots{};
|
||||
mutable SizeT m_backendHashMemoNextSlot = 0;
|
||||
mutable Uint32 m_backendHashMemoVersion = ~0u;
|
||||
mutable Uint m_backendHashMemoFlags = 0;
|
||||
Uint32 m_uboContentVersion = 0;
|
||||
Uint32 m_linkVersion = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user