32template <
typename Tag>
39 explicit operator bool()
const {
return value != 0; }
49template <
typename Tag>
56template <
typename Tag>
63template <
typename Tag>
99template <
typename Tag>
107 std::lock_guard<std::mutex> lock(
m_mutex );
140 std::lock_guard<std::mutex> lock(
m_mutex );
152 std::lock_guard<std::mutex> lock(
m_mutex );
158 entry->
alive =
false;
176 std::lock_guard<std::mutex> lock(
m_mutex );
202 template <
typename POOL>
207 if( !handle ||
index >= aPool.m_entries.size() )
210 auto& entry = aPool.m_entries[
index];
212 return entry.alive &&
RhiHandleGeneration( handle ) == entry.generation ? &entry :
nullptr;
221template <
typename MAP,
typename Tag>
Thread-safe pool that allocates and recycles generation-tracked handles for device implementations.
std::vector< uint32_t > m_freeList
void Release(RHI_HANDLE< Tag > handle)
std::vector< Entry > m_entries
static auto findLive(POOL &aPool, RHI_HANDLE< Tag > handle) -> decltype(&aPool.m_entries[0])
Return the entry of a handle that is alive at its generation, or nullptr.
bool IsValid(RHI_HANDLE< Tag > handle) const
RHI_HANDLE< Tag > Allocate()
bool MarkPendingDestroy(RHI_HANDLE< Tag > handle)
Make a handle invalid while keeping its slot out of the free list until Release().
std::mutex m_mutex
Handles are allocated and released from both the UI and render threads, and Allocate() can reallocate...
constexpr uint32_t RHI_HANDLE_GEN_MASK
RHI_HANDLE< RHI_TAG_FRAMEBUFFER > RHI_FramebufferHandle
void RhiReleasePooledResource(MAP &aMap, RHI_HANDLE_POOL< Tag > &aPool, uint32_t aHandleValue)
Release a deferred handle whose only teardown is dropping its table entry and recycling the pool slot...
RHI_HANDLE< RHI_TAG_TEXTURE > RHI_TextureHandle
RHI_HANDLE< RHI_TAG_BUFFER > RHI_BufferHandle
RHI_HANDLE< RHI_TAG_PIPELINE > RHI_PipelineHandle
RHI_HANDLE< RHI_TAG_BIND_GROUP > RHI_BindGroupHandle
RHI_HANDLE< RHI_TAG_COMPUTE_PIPELINE > RHI_ComputePipelineHandle
RHI_HANDLE< RHI_TAG_BIND_GROUP_LAYOUT > RHI_BindGroupLayoutHandle
uint32_t RhiHandleIndex(RHI_HANDLE< Tag > h)
RHI_HANDLE< RHI_TAG_SURFACE > RHI_SurfaceHandle
RHI_HANDLE< RHI_TAG_SHADER > RHI_ShaderHandle
RHI_HANDLE< RHI_TAG_RENDER_PASS > RHI_RenderPassHandle
constexpr uint32_t RHI_HANDLE_INDEX_BITS
RHI_HANDLE< Tag > RhiMakeHandle(uint32_t index, uint32_t generation)
RHI_HANDLE< RHI_TAG_SWAPCHAIN > RHI_SwapchainHandle
uint32_t RhiHandleGeneration(RHI_HANDLE< Tag > h)
constexpr uint32_t RHI_HANDLE_INDEX_MASK
constexpr uint32_t RHI_HANDLE_GEN_BITS
Opaque GPU resource handle, typed by a tag struct so handles of different kinds cannot be mixed.
bool operator==(const RHI_HANDLE &other) const =default