Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
TargetPool.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
24#pragma once
25
26#include "../../core/Types.hpp"
28#include "../rhi/GfxEnums.hpp"
29
30#include <vector>
31
32namespace esengine {
33
34class GfxDevice;
35
36namespace rg {
37
46constexpr TargetHandle kNoTarget = static_cast<TargetHandle>(-1);
47
53 bool linearFilter = true;
54 bool depthStencil = false;
59 bool gbuffer = false;
61 bool storage = false;
62};
63
65public:
66 explicit TargetPool(GfxDevice& device);
68
69 TargetPool(const TargetPool&) = delete;
70 TargetPool& operator=(const TargetPool&) = delete;
71
76 TargetHandle acquire(const TargetShape& shape);
77
79 void release(TargetHandle handle);
80
82 bool holds(TargetHandle handle) const;
83
86
93
102 void age();
103
106 void clear();
107
109 u32 count() const;
110
113 u64 bytes() const;
114
123 static constexpr u32 kIdleTicksBeforeEvict = 120;
124
126 static constexpr u64 kIdleByteBudget = 256ull * 1024 * 1024;
127
128 void setIdleByteBudget(u64 bytes) { idle_byte_budget_ = bytes; }
129 u64 idleByteBudget() const { return idle_byte_budget_; }
130
133 static constexpr u32 kBudgetGraceTicks = 4;
134
135private:
136 struct Entry {
138 TargetShape shape;
139 bool inUse = false;
141 u32 idle = 0;
144 u32 generation = 0;
145 };
146
150 static constexpr u32 kSlotBits = 16;
151 static constexpr u32 kSlotMask = (1u << kSlotBits) - 1;
152
154 const Entry* resolve(TargetHandle handle) const;
155
156 GfxDevice& device_;
157 std::vector<Entry> entries_;
158 u64 idle_byte_budget_ = kIdleByteBudget;
159};
160
161} // namespace rg
162} // namespace esengine
GPU framebuffer abstraction for render-to-texture.
Backend-agnostic graphics enumerations.
Core type definitions and utilities for ESEngine.
Abstract graphics device interface.
Definition GfxDevice.hpp:75
void setIdleByteBudget(u64 bytes)
static constexpr u64 kIdleByteBudget
Bytes of unborrowed targets the pool keeps, whatever their age: past it the longest idle are destroye...
void release(TargetHandle handle)
TargetPool(GfxDevice &device)
TextureHandle gbufferTextureOf(TargetHandle handle) const
TextureHandle albedoTextureOf(TargetHandle handle) const
TargetPool & operator=(const TargetPool &)=delete
static constexpr u32 kIdleTicksBeforeEvict
Ticks a target may go unborrowed before the pool destroys it.
TextureHandle textureOf(TargetHandle handle) const
bool holds(TargetHandle handle) const
TargetHandle acquire(const TargetShape &shape)
Borrow a target of this shape, reusing one or creating it.
static constexpr u32 kBudgetGraceTicks
Ticks unborrowed before a target counts against that budget. More than one, since age runs once per g...
TextureHandle depthTextureOf(TargetHandle handle) const
FramebufferHandle framebufferOf(TargetHandle handle) const
TargetPool(const TargetPool &)=delete
void age()
One tick of the clock every borrowed target is aged against.
u32 TargetHandle
A borrowed target: a slot index, and the generation of what is in it.
constexpr TargetHandle kNoTarget
FramebufferHandle
Handle 0 is the default framebuffer (backbuffer); it cannot be created or deleted.
Definition GfxEnums.hpp:41
std::uint64_t u64
Unsigned 64-bit integer.
Definition Types.hpp:47
std::unique_ptr< T > Unique
Unique ownership smart pointer.
Definition Types.hpp:75
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
bool gbuffer
A second colour attachment for the surface's material (see FramebufferSpec::gbuffer).
bool storage
Written by a compute shader as a storage texture, and sampled after.