mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 22:28:32 +09:00
[Perf] (MG_Backend/DirectVulkan): cache resolved VkSampler per binding to skip the per-draw sampler key hash, keyed on a new sampler lifetime id
This commit is contained in:
@@ -8,10 +8,19 @@
|
||||
|
||||
#include "SamplerObject.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
SamplerObject::SamplerObject(Uint externalIndex) : m_externalIndex(externalIndex) {}
|
||||
static std::atomic<Uint64> s_nextSamplerLifetimeId = 1;
|
||||
|
||||
Uint64 SamplerObject::AllocateLifetimeId() {
|
||||
return s_nextSamplerLifetimeId.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
SamplerObject::SamplerObject(Uint externalIndex)
|
||||
: m_externalIndex(externalIndex), m_lifetimeId(AllocateLifetimeId()) {}
|
||||
|
||||
void SamplerObject::SetWrapS(SamplerWrapMode mode) {
|
||||
if (mode == m_samplerParameters.wrapS) return;
|
||||
@@ -138,6 +147,10 @@ namespace MobileGL {
|
||||
Uint16 SamplerObject::GetVersion() const {
|
||||
return m_version;
|
||||
}
|
||||
|
||||
Uint64 SamplerObject::GetLifetimeId() const {
|
||||
return m_lifetimeId;
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -99,10 +99,18 @@ namespace MobileGL {
|
||||
SamplerCompareFunc GetSamplerCompareFunc() const;
|
||||
Uint GetExternalIndex() const;
|
||||
Uint16 GetVersion() const;
|
||||
// Globally-unique, never-reused id for this sampler object's lifetime. Lets a
|
||||
// cache distinguish a freed-and-reallocated sampler (same heap address, GL name,
|
||||
// or version count) from the original - the sampler analogue of the texture
|
||||
// lifetime id. Used by the Vulkan backend's per-binding sampler fast path.
|
||||
Uint64 GetLifetimeId() const;
|
||||
const SamplerParameters& GetAllSamplerParameters() const;
|
||||
|
||||
private:
|
||||
static Uint64 AllocateLifetimeId();
|
||||
|
||||
const Uint m_externalIndex;
|
||||
const Uint64 m_lifetimeId;
|
||||
Uint16 m_version = 0;
|
||||
SamplerParameters m_samplerParameters;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user