2008-07-16 05:09:04 +02:00
|
|
|
/*
|
|
|
|
|
BUFFHANDLE.hpp - Buffer handling support for the render engine
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-07-16 05:09:04 +02:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-07-16 05:09:04 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2008-07-16 05:09:04 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-07-16 05:09:04 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-07-16 05:09:04 +02:00
|
|
|
*/
|
|
|
|
|
|
2008-07-17 16:17:43 +02:00
|
|
|
/** @file buffhandle.hpp
|
2011-11-25 17:29:06 +01:00
|
|
|
** A front-end to support the buffer management within the render nodes.
|
2008-07-17 16:17:43 +02:00
|
|
|
** When pulling data from predecessor nodes and calculating new data, each render node
|
2011-11-25 17:29:06 +01:00
|
|
|
** needs several input and output buffers. These may be allocated and provided by various
|
2011-07-09 02:17:37 +02:00
|
|
|
** different "buffer providers" (for example the frame cache). Typically, the real buffers
|
|
|
|
|
** will be passed as parameters to the actual job instance when scheduled, drawing on the
|
|
|
|
|
** results of prerequisite jobs. Yet the actual job implementation remains agnostic with
|
|
|
|
|
** respect to the way actual buffers are provided; the invocation just pushes BuffHandle
|
|
|
|
|
** objects around. The actual render function gets an array of C-pointers to the actual
|
|
|
|
|
** buffers, and for accessing those buffers, the node needs to keep a table of buffer
|
|
|
|
|
** pointers, and for releasing the buffers later on, we utilise the buffer handles.
|
|
|
|
|
**
|
2011-11-25 17:29:06 +01:00
|
|
|
** These buffer handles are based on a buffer descriptor record, which is opaque as far
|
|
|
|
|
** as the client is concerned. BufferDescriptor acts as a representation of the type or
|
|
|
|
|
** kind of buffer. The only way to obtain such a BufferDescriptor is from a concrete
|
|
|
|
|
** BufferProvider implementation. A back-link to this owning and managing provider is
|
|
|
|
|
** embedded into the BufferDescriptor, allowing to retrieve an buffer handle, corresponding
|
|
|
|
|
** to an actual buffer provided and managed behind the scenes. There is no automatic
|
|
|
|
|
** resource management; clients are responsible to invoke BuffHandle#release when done.
|
|
|
|
|
**
|
|
|
|
|
** @see BufferProvider
|
|
|
|
|
** @see BufferProviderProtocol_test usage demonstration
|
|
|
|
|
** @see OutputSlot
|
2011-11-26 00:09:59 +01:00
|
|
|
** @see bufftable.hpp storage for the buffer table
|
2009-09-05 04:10:51 +02:00
|
|
|
** @see engine::RenderInvocation
|
2008-07-16 05:09:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef ENGINE_BUFFHANDLE_H
|
|
|
|
|
#define ENGINE_BUFFHANDLE_H
|
|
|
|
|
|
|
|
|
|
|
2008-12-27 00:53:35 +01:00
|
|
|
#include "lib/error.hpp"
|
2011-12-02 16:10:03 +01:00
|
|
|
#include "proc/streamtype.hpp"
|
2009-09-04 01:59:44 +02:00
|
|
|
#include "lib/bool-checkable.hpp"
|
2008-07-16 05:09:04 +02:00
|
|
|
|
|
|
|
|
|
2011-12-02 16:10:03 +01:00
|
|
|
namespace proc {
|
2008-07-16 05:09:04 +02:00
|
|
|
namespace engine {
|
2008-07-17 16:17:43 +02:00
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
namespace error = lumiera::error;
|
2011-11-24 03:33:23 +01:00
|
|
|
using error::LUMIERA_ERROR_LIFECYCLE;
|
|
|
|
|
|
2011-11-14 01:43:29 +01:00
|
|
|
typedef size_t HashVal; ////////////TICKET #722
|
|
|
|
|
|
2011-11-20 01:35:52 +01:00
|
|
|
class BuffHandle;
|
2011-09-04 01:54:36 +02:00
|
|
|
class BufferProvider;
|
|
|
|
|
|
2008-07-16 05:09:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-09-04 01:54:36 +02:00
|
|
|
* An opaque descriptor to identify the type and further properties of a data buffer.
|
|
|
|
|
* For each kind of buffer, there is somewhere a BufferProvider responsible for the
|
|
|
|
|
* actual storage management. This provider may "lock" a buffer for actual use,
|
|
|
|
|
* returning a BuffHandle.
|
2011-10-17 02:00:48 +02:00
|
|
|
* @note this descriptor and especially the #subClassification_ is really owned
|
|
|
|
|
* by the BufferProvider, which may use (and even change) the opaque contents
|
|
|
|
|
* to organise the internal buffer management.
|
2008-07-16 05:09:04 +02:00
|
|
|
*/
|
2011-09-04 01:54:36 +02:00
|
|
|
class BufferDescriptor
|
2008-07-16 05:09:04 +02:00
|
|
|
{
|
2011-11-25 18:20:01 +01:00
|
|
|
protected:
|
2011-09-04 01:54:36 +02:00
|
|
|
BufferProvider* provider_;
|
2011-11-14 01:43:29 +01:00
|
|
|
HashVal subClassification_;
|
2009-09-04 01:59:44 +02:00
|
|
|
|
2011-11-15 04:47:31 +01:00
|
|
|
BufferDescriptor(BufferProvider& manager, HashVal detail)
|
2011-09-04 01:54:36 +02:00
|
|
|
: provider_(&manager)
|
|
|
|
|
, subClassification_(detail)
|
|
|
|
|
{ }
|
2009-09-04 01:59:44 +02:00
|
|
|
|
2011-09-04 01:54:36 +02:00
|
|
|
friend class BufferProvider;
|
2011-11-25 18:20:01 +01:00
|
|
|
friend class BuffHandle;
|
2009-09-04 01:59:44 +02:00
|
|
|
|
2011-09-04 01:54:36 +02:00
|
|
|
public:
|
|
|
|
|
// using standard copy operations
|
2011-06-22 02:42:50 +02:00
|
|
|
|
2011-09-17 18:25:45 +02:00
|
|
|
bool verifyValidity() const;
|
2011-11-21 02:28:44 +01:00
|
|
|
size_t determineBufferSize() const;
|
2011-11-14 01:43:29 +01:00
|
|
|
|
|
|
|
|
operator HashVal() const { return subClassification_; }
|
2008-07-16 05:09:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-09-04 01:54:36 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
class BuffHandle
|
|
|
|
|
: public lib::BoolCheckable<BuffHandle>
|
|
|
|
|
{
|
2011-12-02 16:10:03 +01:00
|
|
|
typedef StreamType::ImplFacade::DataBuffer Buff;
|
2011-09-04 01:54:36 +02:00
|
|
|
|
|
|
|
|
BufferDescriptor descriptor_;
|
|
|
|
|
Buff* pBuffer_;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
2011-09-16 01:58:13 +02:00
|
|
|
typedef Buff* PBuff;
|
|
|
|
|
|
2011-09-04 01:54:36 +02:00
|
|
|
/** @internal a buffer handle may be obtained by "locking"
|
|
|
|
|
* a buffer from the corresponding BufferProvider */
|
2011-11-15 04:47:31 +01:00
|
|
|
BuffHandle(BufferDescriptor const& typeInfo, void* storage = 0)
|
2011-09-04 01:54:36 +02:00
|
|
|
: descriptor_(typeInfo)
|
2011-11-15 04:47:31 +01:00
|
|
|
, pBuffer_(static_cast<PBuff>(storage))
|
2011-09-04 01:54:36 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
// using standard copy operations
|
|
|
|
|
|
|
|
|
|
|
2011-09-19 01:42:37 +02:00
|
|
|
|
2011-11-25 18:20:01 +01:00
|
|
|
void emit();
|
|
|
|
|
void release();
|
2011-09-19 01:42:37 +02:00
|
|
|
|
|
|
|
|
|
2011-09-18 15:28:58 +02:00
|
|
|
template<typename BU>
|
|
|
|
|
BU& create();
|
|
|
|
|
|
2011-09-19 01:42:37 +02:00
|
|
|
template<typename BU>
|
|
|
|
|
BU& accessAs();
|
|
|
|
|
|
2011-09-18 15:28:58 +02:00
|
|
|
|
2011-11-15 04:47:31 +01:00
|
|
|
//////////////////////////////////////////TICKET #249 this operator looks obsolete. The Buff type is a placeholder type,
|
|
|
|
|
//////////////////////////////////////////TODO it should never be accessed directly from within Lumiera engine code
|
2011-09-04 01:54:36 +02:00
|
|
|
Buff&
|
|
|
|
|
operator* () const
|
|
|
|
|
{
|
|
|
|
|
ENSURE (pBuffer_);
|
|
|
|
|
return *pBuffer_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
isValid() const
|
|
|
|
|
{
|
|
|
|
|
return bool(pBuffer_)
|
2011-09-17 18:25:45 +02:00
|
|
|
&& descriptor_.verifyValidity();
|
2011-09-04 01:54:36 +02:00
|
|
|
}
|
|
|
|
|
|
2011-11-15 04:47:31 +01:00
|
|
|
HashVal
|
|
|
|
|
entryID() const
|
|
|
|
|
{
|
2011-11-25 18:20:01 +01:00
|
|
|
return HashVal(descriptor_);
|
2011-11-15 04:47:31 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-18 15:28:58 +02:00
|
|
|
size_t
|
|
|
|
|
size() const
|
|
|
|
|
{
|
2011-11-21 02:28:44 +01:00
|
|
|
return descriptor_.determineBufferSize();
|
2011-09-18 15:28:58 +02:00
|
|
|
}
|
|
|
|
|
|
2011-11-25 20:23:31 +01:00
|
|
|
private:
|
|
|
|
|
template<typename BU>
|
|
|
|
|
void takeOwnershipFor();
|
|
|
|
|
void takeOwnershipFor(BufferDescriptor const& type);
|
|
|
|
|
|
|
|
|
|
void emergencyCleanup();
|
2011-09-04 01:54:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2011-09-19 01:42:37 +02:00
|
|
|
|
2011-09-04 01:54:36 +02:00
|
|
|
|
2011-12-02 16:10:03 +01:00
|
|
|
}} // namespace proc::engine
|
2008-07-16 05:09:04 +02:00
|
|
|
#endif
|