mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 14:18:31 +09:00
[Perf] (MG_Backend/DirectVulkan): skip the per-draw sampled-texture walk when the bound set is unchanged (texture-bind generation + program state version); CollectSampledTextures 5.0%->0.2%, fps 228->249
This commit is contained in:
@@ -102,6 +102,10 @@ namespace MobileGL {
|
||||
const ImageTextureBinding& GetImageTextureBinding(Int unit) const;
|
||||
void NoteTextureUnitTouched(Int unit) { m_textureState.NoteUnitTouched(unit); }
|
||||
Int GetMaxTouchedTextureUnit() const { return m_textureState.GetMaxTouchedUnit(); }
|
||||
// Monotonic counter bumped whenever a texture bind/unbind/delete changes which
|
||||
// texture is bound at a unit; lets a backend skip re-resolving an unchanged
|
||||
// per-draw sampled-texture set.
|
||||
Uint64 GetTextureBindGeneration() const { return m_textureState.GetTextureBindGeneration(); }
|
||||
Bool ValidateTextureName(Uint index) const;
|
||||
Bool ValidateTextureObject(Uint index) const;
|
||||
Int GetActiveTextureUnit() const;
|
||||
|
||||
@@ -104,6 +104,10 @@ namespace MobileGL::MG_State::GLState {
|
||||
imageBinding.Bind(nullptr, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R8);
|
||||
}
|
||||
}
|
||||
// Deleting a texture unbinds it from every unit above; treat that as a binding
|
||||
// change so a cached sampled-texture set (which may hold this raw pointer) is
|
||||
// re-resolved instead of dangling.
|
||||
BumpTextureBindGeneration();
|
||||
m_textureObjects.erase(index);
|
||||
}
|
||||
m_indexGenerator.Delete(index);
|
||||
|
||||
@@ -63,10 +63,20 @@ namespace MobileGL::MG_State::GLState {
|
||||
// can stop there instead of walking all MAX_TEXTURE_IMAGE_UNITS units.
|
||||
void NoteUnitTouched(Int unit) {
|
||||
if (unit > m_maxTouchedUnit && unit < MAX_TEXTURE_IMAGE_UNITS) m_maxTouchedUnit = unit;
|
||||
// Every texture/sampler bind entry point (glBindTexture / glBindTextureUnit /
|
||||
// glBindTextures / glBindSampler) routes through here, so bumping the generation here
|
||||
// - plus in MarkTextureObjectForDeletion for delete-unbind - covers every change to
|
||||
// which texture is bound at which unit. A backend that has cached the per-draw
|
||||
// sampled-texture set can compare this against a snapshot to skip re-resolving it when
|
||||
// no bind changed (the block atlas + lightmap stay bound across a whole terrain batch).
|
||||
++m_textureBindGeneration;
|
||||
}
|
||||
Int GetMaxTouchedUnit() const { return m_maxTouchedUnit; }
|
||||
Uint64 GetTextureBindGeneration() const { return m_textureBindGeneration; }
|
||||
void BumpTextureBindGeneration() { ++m_textureBindGeneration; }
|
||||
|
||||
private:
|
||||
Uint64 m_textureBindGeneration = 0;
|
||||
Int m_maxTouchedUnit = -1;
|
||||
Int m_activeTextureUnit = 0;
|
||||
Array<TextureUnit, MAX_TEXTURE_IMAGE_UNITS> m_textureUnits;
|
||||
|
||||
Reference in New Issue
Block a user