impl: buffer provider metadata...
This commit is contained in:
parent
5b6ecbab1c
commit
7ef85065ba
5 changed files with 97 additions and 39 deletions
|
|
@ -29,6 +29,46 @@ namespace engine {
|
|||
namespace { // impl. details and definitions
|
||||
|
||||
const uint DEFAULT_DESCRIPTOR = 0;
|
||||
|
||||
typedef uint64_t LocalKey;
|
||||
typedef size_t HashVal;
|
||||
|
||||
const LocalKey UNSPECIFIC = 0;
|
||||
|
||||
struct TypeHandler
|
||||
{
|
||||
typedef void (*Ctor) (void*);
|
||||
typedef void (*Dtor) (void*);
|
||||
|
||||
Ctor createAttached;
|
||||
Dtor destroyAttached;
|
||||
|
||||
TypeHandler()
|
||||
: createAttached (0)
|
||||
, destroyAttached (0)
|
||||
{ }
|
||||
|
||||
template<class X>
|
||||
TypeHandler()
|
||||
: createAttached (0) /////////TODO: how to attach the ctor function??? mabye better use a class with virtual functions?
|
||||
, destroyAttached (0)
|
||||
{ }
|
||||
};
|
||||
|
||||
const TypeHandler RAW_BUFFER;
|
||||
|
||||
|
||||
class Metadata
|
||||
{
|
||||
public:
|
||||
static HashVal
|
||||
key ( size_t storageSize
|
||||
, TypeHandler instanceFunc =RAW_BUFFER
|
||||
, LocalKey specifics =UNSPECIFIC)
|
||||
{
|
||||
UNIMPLEMENTED ("combine the distinguishing properties into a single hash");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -47,9 +87,9 @@ namespace engine {
|
|||
|
||||
|
||||
BufferDescriptor
|
||||
BufferProvider::getDefaultDescriptor()
|
||||
BufferProvider::getDescriptorFor (size_t storageSize)
|
||||
{
|
||||
return BufferDescriptor (*this, DEFAULT_DESCRIPTOR);
|
||||
return BufferDescriptor (*this, Metadata::key (storageSize));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -61,8 +61,11 @@ namespace engine {
|
|||
|
||||
|
||||
/**
|
||||
* Handle for a buffer for processing data, abstracting away the actual implementation.
|
||||
* The real buffer pointer can be retrieved by dereferencing this smart-handle class.
|
||||
* Interface: a facility providing and managing working buffers for media calculations.
|
||||
* The pointer to actual buffer storage can be retrieved by
|
||||
* - optionally announcing the required buffer(s) beforehand
|
||||
* - "locking" a buffer to yield a buffer handle
|
||||
* - dereferencing this smart-handle class
|
||||
*
|
||||
* @todo as of 6/2011 buffer management within the engine is still a bit vague
|
||||
*/
|
||||
|
|
@ -82,7 +85,11 @@ namespace engine {
|
|||
|
||||
|
||||
/** describe the kind of buffer managed by this provider */
|
||||
BufferDescriptor getDefaultDescriptor(); //////////////TODO really? there is no sensible "default"
|
||||
BufferDescriptor getDescriptorFor(size_t storageSize=0);
|
||||
|
||||
template<typename BU>
|
||||
BufferDescriptor getDescriptor();
|
||||
|
||||
|
||||
|
||||
/* === API for BuffHandle internal access === */
|
||||
|
|
@ -111,5 +118,13 @@ namespace engine {
|
|||
}
|
||||
|
||||
|
||||
template<typename BU>
|
||||
BufferDescriptor
|
||||
BufferProvider::getDescriptor()
|
||||
{
|
||||
UNIMPLEMENTED ("build descriptor for automatically placing an object instance into the buffer");
|
||||
}
|
||||
|
||||
|
||||
} // namespace engine
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -63,28 +63,25 @@ namespace engine {
|
|||
{
|
||||
return was_locked_;
|
||||
}
|
||||
|
||||
bool
|
||||
was_closed() const
|
||||
{
|
||||
return was_locked_;
|
||||
}
|
||||
|
||||
void*
|
||||
accessMemory() const
|
||||
{
|
||||
return storage_.get();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
namespace { // Details of allocation and accounting
|
||||
|
||||
using lumiera::typelist::FunctionSignature;
|
||||
using std::tr1::placeholders::_1;
|
||||
using std::tr1::function;
|
||||
using std::tr1::bind;
|
||||
|
||||
/**
|
||||
* type rebinding template for issuing flexible queries
|
||||
* and forwarding them to the individual block entries
|
||||
*/
|
||||
template<typename FUN>
|
||||
struct _Query
|
||||
{
|
||||
typedef typename FunctionSignature<FUN>::Ret Result;
|
||||
};
|
||||
|
||||
function<bool(Block&)> QUERY_was_used = bind (&Block::was_used, _1 );
|
||||
const uint MAX_BUFFERS = 50;
|
||||
|
||||
} // (END) Details of allocation and accounting
|
||||
|
||||
|
|
@ -119,21 +116,27 @@ namespace engine {
|
|||
|
||||
virtual ~HeapMemProvider()
|
||||
{
|
||||
INFO (proc_mem, "discarding %uz diagnostic buffer entries", HeapMemProvider::size());
|
||||
INFO (proc_mem, "discarding %zu diagnostic buffer entries", HeapMemProvider::size());
|
||||
}
|
||||
|
||||
template<typename FUN>
|
||||
typename _Query<FUN>::Result
|
||||
accessStats (uint bufferID, FUN queryFunction)
|
||||
{
|
||||
queryFunction (access_or_create (bufferID));
|
||||
}
|
||||
|
||||
private:
|
||||
Block&
|
||||
access_or_create (uint bufferID)
|
||||
{
|
||||
UNIMPLEMENTED ("either get existing block or create new entries to fit");
|
||||
while (!withinStorageSize (bufferID))
|
||||
manage (new Block);
|
||||
|
||||
ENSURE (withinStorageSize (bufferID));
|
||||
return (*this)[bufferID];
|
||||
}
|
||||
|
||||
private:
|
||||
bool
|
||||
withinStorageSize (uint bufferID) const
|
||||
{
|
||||
if (bufferID >= MAX_BUFFERS)
|
||||
throw error::Fatal ("hardwired internal limit for test buffers exceeded");
|
||||
|
||||
return bufferID < size();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -181,21 +184,21 @@ namespace engine {
|
|||
bool
|
||||
DiagnosticBufferProvider::buffer_was_used (uint bufferID) const
|
||||
{
|
||||
pImpl_->accessStats (bufferID, QUERY_was_used);
|
||||
return pImpl_->access_or_create(bufferID).was_used();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DiagnosticBufferProvider::buffer_was_closed (uint bufferID) const
|
||||
{
|
||||
UNIMPLEMENTED ("check closed-flag of a specific buffer");
|
||||
return pImpl_->access_or_create(bufferID).was_closed();
|
||||
}
|
||||
|
||||
|
||||
void*
|
||||
DiagnosticBufferProvider::accessStorage (uint bufferID) const
|
||||
DiagnosticBufferProvider::accessMemory (uint bufferID) const
|
||||
{
|
||||
|
||||
return pImpl_->access_or_create(bufferID).accessMemory();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ namespace engine {
|
|||
* for diagnostic access or wasn't registered beforehand.
|
||||
*/
|
||||
static DiagnosticBufferProvider&
|
||||
access (BufferProvider const&);
|
||||
access (BufferProvider const& );
|
||||
|
||||
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ namespace engine {
|
|||
|
||||
bool buffer_was_used (uint bufferID) const;
|
||||
bool buffer_was_closed (uint bufferID) const;
|
||||
void* accessStorage (uint bufferID) const;
|
||||
void* accessMemory (uint bufferID) const;
|
||||
|
||||
|
||||
template<typename BU>
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ namespace test {
|
|||
CHECK (checker.object_was_attached<TestFrame> (0));
|
||||
CHECK (checker.object_was_destroyed<TestFrame> (0));
|
||||
|
||||
CHECK (testData(0) == checker.accessStorage (0));
|
||||
CHECK (testData(0) == checker.accessMemory (0));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -112,10 +112,10 @@ namespace test {
|
|||
// In real usage, a suitable memory/frame/buffer provider
|
||||
// will be preconfigured, depending on the usage context
|
||||
BufferProvider& provider = DiagnosticBufferProvider::build();
|
||||
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #829
|
||||
|
||||
BufferDescriptor desc1 = provider.getDescriptor<TestFrame>();
|
||||
BufferDescriptor desc2 = provider.getDescriptorFor(TEST_SIZE);
|
||||
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #829
|
||||
CHECK (desc1.verifyValidity());
|
||||
CHECK (desc2.verifyValidity());
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue