7#include <hpp/string_view.hpp>
12template<
typename Base,
typename T>
16 using ptr = std::shared_ptr<Base>;
17 using uptr = std::unique_ptr<Base>;
70 T invalid = {bgfx::kInvalidHandle};
119 return static_cast<const Base&
>(*this).fallback_handle();
126 std::function<
bool(Base&)> restore_fn,
143 std::function<
bool(Base&)> restore_fn,
std::unique_ptr< Base > uptr
std::function< bool(Base &)> restore_fn_
auto on_evict() -> std::uint64_t override
Release the GPU handle. Returns the number of GPU bytes freed. Must be idempotent.
auto is_valid() const -> bool
auto operator=(handle_impl &&) -> handle_impl &=delete
void set_name(const hpp::string_view &_name)
static auto invalid_handle() -> T
auto fallback_handle() const -> T
auto gpu_size() const -> std::uint64_t override
Approximate GPU footprint of the resource in bytes.
std::shared_ptr< Base > ptr
auto native_handle() const -> T
void make_evictable(std::uint64_t gpu_bytes, std::function< bool(Base &)> restore_fn, evict_class cls=evict_class::evictable)
auto get_fallback_handle() const -> T
auto operator=(const handle_impl &) -> handle_impl &=delete
handle_impl(const handle_impl &)=delete
void make_evictable_deferred(std::uint64_t gpu_bytes, std::function< bool(Base &)> restore_fn, evict_class cls=evict_class::evictable)
handle_impl(handle_impl &&)=delete
auto on_restore() -> bool override
Recreate the GPU handle from the CPU backing. Returns true on success.
std::weak_ptr< Base > weak_ptr
evict_class evict_class_
Eligibility class. Set once when the resource opts into eviction.
void touch() const noexcept
evict_state evict_state_
Current residency state. Written by the owning resource during evict/restore.
auto is_supported() -> bool
void restore_resource(ievictable *resource)
void register_resource(ievictable *resource)
Begin tracking a resource (assumed resident). Called from handle_impl::make_evictable.
void register_evicted_resource(ievictable *resource)
void unregister_resource(ievictable *resource)
Stop tracking a resource. Called from handle_impl's destructor.
evict_class
Eviction eligibility of a tracked resource.
@ non_evictable
No CPU backing (render targets, uniforms, ...). Never registered.
@ evictable
May be evicted by a sweep.
void set_name(index_buffer_handle _handle, const char *_name, int32_t _len)
@ evicted
GPU handle was destroyed; a CPU-side backing is retained for restore.
@ resident
GPU handle is live and usable.
void destroy(index_buffer_handle _handle)
Hash specialization for batch_key to enable use in std::unordered_map.