CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Sensor
RHIGPUReadbackPool.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#pragma once
8
9
#include <util/ue-header-guard-begin.h>
10
#include "CoreMinimal.h"
11
#include "HAL/CriticalSection.h"
12
#include "RHIGPUReadback.h"
13
#include "Templates/SharedPointer.h"
14
#include "Templates/UniquePtr.h"
15
#include <util/ue-header-guard-end.h>
16
17
// Pool of FRHIGPUTextureReadback objects shared by one ASceneCaptureSensor.
18
// The pool is owned via TSharedPtr<...,ESPMode::ThreadSafe>: the sensor holds
19
// one strong ref; every in-flight AsyncTask holds another strong ref so the
20
// pool outlives the sensor if a frame is still being consumed when the
21
// sensor ends play. Acquire/Release run from different threads (render
22
// thread for Acquire, AsyncTask for Release) and are guarded by Lock.
23
//
24
// Slots are lazy-allocated up to MaxSize; once allocated, an FRHIGPUTextureReadback
25
// instance and its underlying Vulkan staging buffer live for the rest of the
26
// pool's lifetime, recycled across frames. Eliminates the per-frame
27
// alloc/free of large staging buffers that was driving Vulkan suballocator
28
// fragmentation.
29
class
FRHIGPUReadbackPool
30
{
31
public
:
32
33
explicit
FRHIGPUReadbackPool
(
const
TCHAR *InDebugName, int32 InMaxSize = 4)
34
:
DebugName
(InDebugName),
MaxSize
(InMaxSize) {}
35
36
// Returns a raw pointer (pool retains ownership) and writes the slot index
37
// into OutSlotIndex. Returns nullptr only if every slot is in use AND we
38
// already grew to MaxSize; the caller falls back to a per-call alloc.
39
FRHIGPUTextureReadback *
Acquire
(int32 &OutSlotIndex);
40
41
// Marks the slot free. The FRHIGPUTextureReadback object stays alive and
42
// its Vulkan staging buffer is reused on the next Acquire.
43
void
Release
(int32 SlotIndex);
44
45
private
:
46
47
FCriticalSection
Lock
;
48
TArray<TUniquePtr<FRHIGPUTextureReadback>>
Slots
;
49
TArray<bool>
InUse
;
50
FString
DebugName
;
51
int32
MaxSize
;
52
};
53
54
using
FRHIGPUReadbackPoolPtr
= TSharedPtr<FRHIGPUReadbackPool, ESPMode::ThreadSafe>;
FRHIGPUReadbackPoolPtr
TSharedPtr< FRHIGPUReadbackPool, ESPMode::ThreadSafe > FRHIGPUReadbackPoolPtr
Definition
RHIGPUReadbackPool.h:54
FRHIGPUReadbackPool::Acquire
FRHIGPUTextureReadback * Acquire(int32 &OutSlotIndex)
Definition
RHIGPUReadbackPool.cpp:9
FRHIGPUReadbackPool::MaxSize
int32 MaxSize
Definition
RHIGPUReadbackPool.h:51
FRHIGPUReadbackPool::Lock
FCriticalSection Lock
Definition
RHIGPUReadbackPool.h:47
FRHIGPUReadbackPool::DebugName
FString DebugName
Definition
RHIGPUReadbackPool.h:50
FRHIGPUReadbackPool::Release
void Release(int32 SlotIndex)
Definition
RHIGPUReadbackPool.cpp:39
FRHIGPUReadbackPool::Slots
TArray< TUniquePtr< FRHIGPUTextureReadback > > Slots
Definition
RHIGPUReadbackPool.h:48
FRHIGPUReadbackPool::FRHIGPUReadbackPool
FRHIGPUReadbackPool(const TCHAR *InDebugName, int32 InMaxSize=4)
Definition
RHIGPUReadbackPool.h:33
FRHIGPUReadbackPool::InUse
TArray< bool > InUse
Definition
RHIGPUReadbackPool.h:49
Generated by
1.18.0