|
@@ -3,6 +3,7 @@
|
|
|
#pragma once
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BsVulkanPrerequisites.h"
|
|
#include "BsVulkanPrerequisites.h"
|
|
|
|
|
+#include "BsStaticAlloc.h"
|
|
|
|
|
|
|
|
namespace BansheeEngine
|
|
namespace BansheeEngine
|
|
|
{
|
|
{
|
|
@@ -30,7 +31,7 @@ namespace BansheeEngine
|
|
|
class VulkanResource
|
|
class VulkanResource
|
|
|
{
|
|
{
|
|
|
public:
|
|
public:
|
|
|
- VulkanResource(VulkanResourceManager* owner);
|
|
|
|
|
|
|
+ VulkanResource(VulkanResourceManager* owner, bool concurrency);
|
|
|
virtual ~VulkanResource();
|
|
virtual ~VulkanResource();
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -39,13 +40,13 @@ namespace BansheeEngine
|
|
|
*
|
|
*
|
|
|
* A resource can only be used by a single command buffer at a time.
|
|
* A resource can only be used by a single command buffer at a time.
|
|
|
*/
|
|
*/
|
|
|
- virtual void notifyUsed(VulkanCmdBuffer& buffer, VulkanUseFlags flags);
|
|
|
|
|
|
|
+ virtual void notifyUsed(VulkanCmdBuffer* buffer, VulkanUseFlags flags);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Notifies the resource that it is no longer used by on the GPU. This makes the resource usable on other command
|
|
* Notifies the resource that it is no longer used by on the GPU. This makes the resource usable on other command
|
|
|
* buffers again.
|
|
* buffers again.
|
|
|
*/
|
|
*/
|
|
|
- virtual void notifyDone();
|
|
|
|
|
|
|
+ virtual void notifyDone(VulkanCmdBuffer* buffer);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Checks is the resource currently used on a device.
|
|
* Checks is the resource currently used on a device.
|
|
@@ -54,7 +55,7 @@ namespace BansheeEngine
|
|
|
* done on the device but this method may still report true. If you need to know the latest state
|
|
* done on the device but this method may still report true. If you need to know the latest state
|
|
|
* call VulkanCommandBufferManager::refreshStates() before checking for usage.
|
|
* call VulkanCommandBufferManager::refreshStates() before checking for usage.
|
|
|
*/
|
|
*/
|
|
|
- bool isUsed() const { return mCmdBufferId != -1; }
|
|
|
|
|
|
|
+ bool isUsed() const { return mNumHandles > 0; }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Destroys the resource and frees its memory. If the resource is currently being used on a device, the
|
|
* Destroys the resource and frees its memory. If the resource is currently being used on a device, the
|
|
@@ -63,10 +64,31 @@ namespace BansheeEngine
|
|
|
void destroy();
|
|
void destroy();
|
|
|
|
|
|
|
|
protected:
|
|
protected:
|
|
|
|
|
+ /** Possible states of this object. */
|
|
|
|
|
+ enum class State
|
|
|
|
|
+ {
|
|
|
|
|
+ Normal,
|
|
|
|
|
+ Shared,
|
|
|
|
|
+ Destroyed
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /** Information about use of this resource on a specific command buffer. */
|
|
|
|
|
+ struct UseHandle
|
|
|
|
|
+ {
|
|
|
|
|
+ VulkanCmdBuffer* buffer;
|
|
|
|
|
+ VulkanUseFlags flags;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
VulkanResourceManager* mOwner;
|
|
VulkanResourceManager* mOwner;
|
|
|
- VulkanUseFlags mFlags;
|
|
|
|
|
- UINT32 mCmdBufferId = -1;
|
|
|
|
|
- bool mIsDestroyed = false;
|
|
|
|
|
|
|
+ UINT32 mQueueFamily;
|
|
|
|
|
+ State mState;
|
|
|
|
|
+
|
|
|
|
|
+ UseHandle* mHandles;
|
|
|
|
|
+ UINT32 mNumHandles;
|
|
|
|
|
+ UINT32 mHandleCapacity;
|
|
|
|
|
+
|
|
|
|
|
+ static const UINT32 INITIAL_HANDLE_CAPACITY = 2;
|
|
|
|
|
+ StaticAlloc<sizeof(UseHandle) * INITIAL_HANDLE_CAPACITY> mAlloc;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/** Creates and destroys annd VulkanResource%s on a single device. */
|
|
/** Creates and destroys annd VulkanResource%s on a single device. */
|
|
@@ -78,11 +100,13 @@ namespace BansheeEngine
|
|
|
/**
|
|
/**
|
|
|
* Creates a new Vulkan resource of the specified type. User must call VulkanResource::destroy() when done using
|
|
* Creates a new Vulkan resource of the specified type. User must call VulkanResource::destroy() when done using
|
|
|
* the resource.
|
|
* the resource.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param[in] concurrency If true, the resource is allowed to be used on multiple queue types at once.
|
|
|
*/
|
|
*/
|
|
|
template<class Type, class... Args>
|
|
template<class Type, class... Args>
|
|
|
- VulkanResource* create(Args &&...args)
|
|
|
|
|
|
|
+ VulkanResource* create(bool concurrency, Args &&...args)
|
|
|
{
|
|
{
|
|
|
- VulkanResource* resource = new (bs_alloc(sizeof(Type))) Type(std::forward<Args>(args)...);
|
|
|
|
|
|
|
+ VulkanResource* resource = new (bs_alloc(sizeof(Type))) Type(this, concurrency, std::forward<Args>(args)...);
|
|
|
|
|
|
|
|
#if BS_DEBUG_MODE
|
|
#if BS_DEBUG_MODE
|
|
|
mResources.insert(resource);
|
|
mResources.insert(resource);
|