24 if (shape.depthStencil) bytes += 4u;
28 if (shape.samples > 1) bytes *= (shape.samples + 1);
33 return a.width == b.width && a.height == b.height && a.format == b.format
34 && a.linearFilter == b.linearFilter && a.depthStencil == b.depthStencil
35 && a.samples == b.samples && a.gbuffer == b.gbuffer && a.storage == b.storage;
44const TargetPool::Entry* TargetPool::resolve(
TargetHandle handle)
const {
46 const u32 slot = handle & kSlotMask;
47 if (slot >= entries_.size())
return nullptr;
48 const Entry& entry = entries_[slot];
51 if (!entry.fbo || entry.generation != (handle >> kSlotBits))
return nullptr;
56 auto handleFor = [&](
usize slot) {
57 return static_cast<TargetHandle>((entries_[slot].generation << kSlotBits)
58 |
static_cast<u32>(slot));
61 for (
usize i = 0; i < entries_.size(); ++i) {
62 Entry& entry = entries_[i];
63 if (entry.inUse || !entry.fbo || !sameShape(entry.shape, shape))
continue;
87 for (
usize i = 0; i < entries_.size(); ++i) {
88 if (entries_[i].fbo)
continue;
89 entries_[i].fbo = std::move(fbo);
90 entries_[i].shape = shape;
91 entries_[i].inUse =
true;
96 if (entries_.size() > kSlotMask) {
97 ES_LOG_ERROR(
"TargetPool: {} targets is past what a handle can name", entries_.size());
102 entry.fbo = std::move(fbo);
105 entries_.push_back(std::move(entry));
106 return handleFor(entries_.size() - 1);
110 if (!resolve(handle))
return;
111 entries_[handle & kSlotMask].inUse =
false;
115 return resolve(handle) !=
nullptr;
119 const Entry* entry = resolve(handle);
124 const Entry* entry = resolve(handle);
129 const Entry* entry = resolve(handle);
134 const Entry* entry = resolve(handle);
139 const Entry* entry = resolve(handle);
144 for (
auto& entry : entries_) {
145 if (!entry.fbo || entry.inUse)
continue;
159 for (
const auto& entry : entries_) {
160 if (entry.fbo && !entry.inUse && entry.idle >=
kBudgetGraceTicks) idleBytes +=
static_cast<u64>(entry.shape.width) * entry.shape.height * texelBytes(entry.shape);
162 while (idleBytes > idle_byte_budget_) {
163 Entry* oldest =
nullptr;
164 for (
auto& entry : entries_) {
165 if (entry.fbo && !entry.inUse && entry.idle >=
kBudgetGraceTicks && (!oldest || entry.idle > oldest->idle)) oldest = &entry;
168 idleBytes -=
static_cast<u64>(oldest->shape.
width) * oldest->shape.
height * texelBytes(oldest->shape);
171 ++oldest->generation;
179 for (
auto& entry : entries_) {
180 if (!entry.fbo)
continue;
190 for (
const auto& entry : entries_) {
191 if (entry.fbo) ++live;
198 for (
const auto& entry : entries_) {
199 if (!entry.fbo)
continue;
200 total +=
static_cast<u64>(entry.shape.width) * entry.shape.height * texelBytes(entry.shape);
Abstract graphics device interface.
Logging utilities for ESEngine.
#define ES_LOG_ERROR(...)
Logs an error message.
The render targets a frame borrows from, keyed by shape — owned by the frame, not by any one graph th...
static Unique< Framebuffer > create(GfxDevice &device, const FramebufferSpec &spec)
Creates a framebuffer from specification.
Abstract graphics device interface.
void release(TargetHandle handle)
TargetPool(GfxDevice &device)
TextureHandle gbufferTextureOf(TargetHandle handle) const
TextureHandle albedoTextureOf(TargetHandle handle) const
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
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.
std::uint64_t u64
Unsigned 64-bit integer.
std::size_t usize
Size type for indexing and sizes.
std::uint32_t u32
Unsigned 32-bit integer.
Framebuffer creation parameters.
GfxPixelFormat colorFormat
Color attachment format. RGBA16F needs GfxDevice::supportsFloatTargets.
bool gbuffer
A second colour attachment (RGBA8) drawn in the same pass: the surface's material,...
bool depthStencil
Whether to create depth/stencil attachment.
bool linearFilter
Texture filter mode: false=GL_NEAREST, true=GL_LINEAR.
u32 samples
Number of samples for MSAA (1 = no multisampling).
u32 height
Framebuffer height in pixels.
bool storage
The colour attachment can also be written by a compute shader (GfxDevice::supportsCompute).
u32 width
Framebuffer width in pixels.
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.