From 42ad1634bfb513fda9d27ec4f5876755d3d80965 Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Tue, 3 Feb 2026 02:17:09 +0800 Subject: [PATCH] [Perf] (MG_State|MG_Util): Do not bump resource version when nothing changes. --- .../GLState/SamplerState/SamplerObject.cpp | 20 +++++++++++++++++++ .../GLState/TextureState/TextureObject.cpp | 12 +++++++++++ .../VertexArrayState/VertexArrayObject.cpp | 15 ++++++++++++++ MobileGL/MG_Util/Types.h | 2 ++ 4 files changed, 49 insertions(+) diff --git a/MobileGL/MG_State/GLState/SamplerState/SamplerObject.cpp b/MobileGL/MG_State/GLState/SamplerState/SamplerObject.cpp index 9721be49..ddf60478 100644 --- a/MobileGL/MG_State/GLState/SamplerState/SamplerObject.cpp +++ b/MobileGL/MG_State/GLState/SamplerState/SamplerObject.cpp @@ -14,36 +14,50 @@ namespace MobileGL { SamplerObject::SamplerObject(Uint externalIndex) : m_externalIndex(externalIndex) {} void SamplerObject::SetWrapS(SamplerWrapMode mode) { + if (mode == m_samplerParameters.wrapS) return; + m_samplerParameters.wrapS = mode; ++m_version; } void SamplerObject::SetWrapT(SamplerWrapMode mode) { + if (mode == m_samplerParameters.wrapT) return; + m_samplerParameters.wrapT = mode; ++m_version; } void SamplerObject::SetWrapR(SamplerWrapMode mode) { + if (mode == m_samplerParameters.wrapR) return; + m_samplerParameters.wrapR = mode; ++m_version; } void SamplerObject::SetMinFilter(SamplerFilterMode mode) { + if (mode == m_samplerParameters.minFilter) return; + m_samplerParameters.minFilter = mode; ++m_version; } void SamplerObject::SetMagFilter(SamplerFilterMode mode) { + if (mode == m_samplerParameters.magFilter) return; + m_samplerParameters.magFilter = mode; ++m_version; } void SamplerObject::SetMipmapMode(SamplerMipmapMode mode) { + if (mode == m_samplerParameters.mipmapMode) return; + m_samplerParameters.mipmapMode = mode; ++m_version; } void SamplerObject::SetLodRange(Float minLod, Float maxLod) { + if (minLod == m_samplerParameters.minLod && maxLod == m_samplerParameters.maxLod) return; + if (minLod > maxLod) { THROW_EXCEPTION("minLod cannot be greater than maxLod"); } @@ -53,16 +67,22 @@ namespace MobileGL { } void SamplerObject::SetLodBias(Float bias) { + if (bias == m_samplerParameters.lodBias) return; + m_samplerParameters.lodBias = bias; ++m_version; } void SamplerObject::SetSamplerCompareFunc(SamplerCompareFunc func) { + if (func == m_samplerParameters.compareFunc) return; + m_samplerParameters.compareFunc = func; ++m_version; } void SamplerObject::SetCompareMode(SamplerCompareMode mode) { + if (mode == m_samplerParameters.compareMode) return; + m_samplerParameters.compareMode = mode; ++m_version; } diff --git a/MobileGL/MG_State/GLState/TextureState/TextureObject.cpp b/MobileGL/MG_State/GLState/TextureState/TextureObject.cpp index b28b2c89..d2e23714 100644 --- a/MobileGL/MG_State/GLState/TextureState/TextureObject.cpp +++ b/MobileGL/MG_State/GLState/TextureState/TextureObject.cpp @@ -44,6 +44,8 @@ namespace MobileGL { } void TextureObjectBase::SetInternalFormat(TextureInternalFormat format) { + if (format == m_internalFormat) return; + m_internalFormat = format; ++m_textureParamsVersion; } @@ -57,6 +59,8 @@ namespace MobileGL { } void TextureObjectBase::SetBorderColor(const FloatVec4& color) { + if (color == m_borderColor) return; + m_borderColor = color; ++m_textureParamsVersion; } @@ -83,6 +87,8 @@ namespace MobileGL { } void TextureObjectBase::SetSwizzleParam(TextureSwizzleParam param, TextureSwizzleParam value) { + if (GetSwizzleParam(param) == value) return; + switch (param) { case TextureSwizzleParam::Red: m_swizzleParams.r() = value; @@ -105,6 +111,8 @@ namespace MobileGL { } void TextureObjectBase::SetSwizzleParamRGBA(const Vec4& values) { + if (values == m_swizzleParams) return; + m_swizzleParams = values; ++m_textureParamsVersion; } @@ -114,11 +122,15 @@ namespace MobileGL { } void TextureObjectBase::SetBaseLevel(Uint baseLevel) { + if (baseLevel == m_levelRange.x()) return; + m_levelRange.x() = baseLevel; ++m_textureParamsVersion; } void TextureObjectBase::SetMaxLevel(Uint maxLevel) { + if (maxLevel == m_levelRange.y()) return; + m_levelRange.y() = maxLevel; ++m_textureParamsVersion; } diff --git a/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp b/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp index e75c58b0..0914222c 100644 --- a/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp +++ b/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp @@ -28,12 +28,18 @@ namespace MobileGL { void VertexArrayObject::EnableAttribute(Uint index) { if (index >= MAX_VERTEX_ATTRIBS) return; + + if (!m_attributes[index].Enabled) return; + m_attributes[index].Enabled = true; BumpAttributeSwitchVersion(index); } void VertexArrayObject::DisableAttribute(Uint index) { if (index >= MAX_VERTEX_ATTRIBS) return; + + if (!m_attributes[index].Enabled) return; + m_attributes[index].Enabled = false; BumpAttributeSwitchVersion(index); } @@ -47,6 +53,12 @@ namespace MobileGL { SizeT offset, Bool isInteger) { if (index >= MAX_VERTEX_ATTRIBS) return; + if (m_attributes[index].Size == size && m_attributes[index].Type == type && + m_attributes[index].Normalized == normalized && m_attributes[index].Stride == stride && + m_attributes[index].Offset == offset && m_attributes[index].IsInteger == isInteger) { + return; + } + if (size < 1 || size > 4) { return; } @@ -64,6 +76,9 @@ namespace MobileGL { void VertexArrayObject::BindAttributeBuffer(Uint index, const SharedPtr& buffer) { if (index >= MAX_VERTEX_ATTRIBS) return; + + if (m_attributes[index].Buffer == buffer) return; + m_attributes[index].Buffer = buffer; BumpAttributeBufferVersion(index); } diff --git a/MobileGL/MG_Util/Types.h b/MobileGL/MG_Util/Types.h index 316fb174..ec390275 100644 --- a/MobileGL/MG_Util/Types.h +++ b/MobileGL/MG_Util/Types.h @@ -147,6 +147,8 @@ namespace MobileGL { BindingSlot() : m_target((TargetEnum)0), m_boundObject(nullptr) {} explicit BindingSlot(TargetEnum target) : m_target(target), m_boundObject(nullptr) {} void Bind(SharedPtr object) { + if (m_boundObject == object) return; + m_boundObject = object; ++m_version; }