[WIP] Move to shared_ptr.
This commit is contained in:
parent
98660a11fa
commit
1bee73e46f
|
|
@ -65,6 +65,11 @@ struct Buffer
|
|||
}
|
||||
|
||||
void Destroy();
|
||||
~Buffer()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void Write(usize offset, usize size, const void *data);
|
||||
|
||||
void Allocate(const Device *device, usize size, vk::BufferUsageFlags bufferUsage,
|
||||
|
|
|
|||
|
|
@ -222,4 +222,4 @@ struct fmt::formatter<eastl::fixed_string<TType, TCount, TOverflow>> : nested_fo
|
|||
};
|
||||
|
||||
template <concepts::Manageable T>
|
||||
using Ref = eastl::intrusive_ptr<T>;
|
||||
using Ref = std::shared_ptr<T>;
|
||||
|
|
@ -106,6 +106,10 @@ struct Image
|
|||
}
|
||||
|
||||
void Destroy();
|
||||
~Image()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
static bool
|
||||
Conforms(const Image &)
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ struct View
|
|||
[[nodiscard]] bool
|
||||
IsValid() const
|
||||
{
|
||||
return m_Image;
|
||||
return Cast<bool>(m_Image);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -67,6 +67,11 @@ struct View
|
|||
|
||||
m_Image->DestroyView(Take(m_View));
|
||||
}
|
||||
|
||||
~View()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
};
|
||||
|
||||
struct ImageView : View<Image>
|
||||
|
|
|
|||
|
|
@ -82,8 +82,6 @@ class CommitManager
|
|||
};
|
||||
};
|
||||
|
||||
static_assert(sizeof(Entry) == 24);
|
||||
|
||||
eastl::vector<Entry> m_Data;
|
||||
FreeList<Entry> m_FreeList;
|
||||
eastl::intrusive_hash_map<typename Entry::key_type, Entry, 31, typename Entry::Hash> m_InUse;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ static Ref<TTo>
|
|||
CastImage(const concepts::ImageRef auto &from)
|
||||
{
|
||||
assert(TTo::Conforms(*from.get()));
|
||||
return Recast<TTo *>(from.get());
|
||||
return std::reinterpret_pointer_cast<TTo>(from);
|
||||
}
|
||||
|
||||
struct Texture2DCreateInfo
|
||||
|
|
|
|||
|
|
@ -27,66 +27,19 @@ class Manager
|
|||
/**
|
||||
* Constructor for the Manager class template.
|
||||
* @param device Device with which resources are created.
|
||||
* @param maxCount Max number of resources that can be created (maxCount <= Handle::INDEX_MASK)
|
||||
*/
|
||||
explicit Manager(const Device *device, const u32 maxCount)
|
||||
: m_Data{maxCount}
|
||||
, m_Device{device}
|
||||
explicit Manager(const Device *device, const u32)
|
||||
: m_Device{device}
|
||||
{
|
||||
for (auto &element : m_Data)
|
||||
{
|
||||
m_FreeList.Push(element);
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~Manager()
|
||||
{
|
||||
if constexpr (concepts::DeviceDestructible<Type>)
|
||||
{
|
||||
for (auto &element : m_Data)
|
||||
{
|
||||
element.Destroy(m_Device);
|
||||
}
|
||||
}
|
||||
|
||||
m_Device = nullptr;
|
||||
}
|
||||
|
||||
// TODO: Work on deletion!!
|
||||
void
|
||||
Sweep()
|
||||
requires concepts::DeviceDestructible<Type>
|
||||
{
|
||||
for (i64 i = m_Data.size() - 1; i >= 0; --i)
|
||||
{
|
||||
if (auto *pIter = &m_Data[i]; !pIter->IsReferenced())
|
||||
{
|
||||
pIter->Destroy(m_Device);
|
||||
m_FreeList.Push(*pIter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Sweep()
|
||||
requires concepts::SelfDestructible<Type>
|
||||
{
|
||||
for (i64 i = m_Data.size() - 1; i >= 0; --i)
|
||||
{
|
||||
if (auto *pIter = &m_Data[i]; !pIter->IsValid())
|
||||
{
|
||||
pIter->Destroy();
|
||||
m_FreeList.Push(*pIter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PIN_MEMORY(Manager);
|
||||
|
||||
private:
|
||||
eastl::vector<Type> m_Data; // Data also keeps the freelist during 'not use'.
|
||||
FreeList<Type> m_FreeList;
|
||||
|
||||
protected:
|
||||
const Device *m_Device;
|
||||
|
||||
|
|
@ -97,15 +50,9 @@ class Manager
|
|||
[[nodiscard]] Handle
|
||||
Alloc()
|
||||
{
|
||||
ERROR_IF(m_FreeList.Empty(), "Max buffers allocated.") THEN_ABORT(-1);
|
||||
|
||||
Type &pAlloc = m_FreeList.Pop();
|
||||
memset(&pAlloc, 0, sizeof pAlloc);
|
||||
if constexpr (concepts::SelfDestructible<Type>)
|
||||
{
|
||||
pAlloc.m_Device = m_Device;
|
||||
}
|
||||
return {&pAlloc};
|
||||
auto object = std::make_shared<Type>();
|
||||
object->m_Device = m_Device;
|
||||
return object;
|
||||
}
|
||||
};
|
||||
} // namespace systems
|
||||
|
|
@ -138,10 +138,7 @@ class ResourceManager
|
|||
void
|
||||
Update()
|
||||
{
|
||||
m_Views.Sweep();
|
||||
m_Images.Sweep();
|
||||
m_Buffers.Sweep();
|
||||
m_Samplers.Sweep();
|
||||
// TODO: Remove
|
||||
}
|
||||
|
||||
~ResourceManager() = default;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ static Ref<TTo>
|
|||
CastView(const concepts::ImageViewRef auto &from)
|
||||
{
|
||||
assert(TTo::ImageType::Conforms(*from->m_Image.get()));
|
||||
return Recast<TTo *>(from.get());
|
||||
return std::reinterpret_pointer_cast<TTo>(from);
|
||||
}
|
||||
|
||||
template <concepts::Image TImage = Image>
|
||||
|
|
|
|||
Loading…
Reference in New Issue