| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #pragma once
- #include "BsCorePrerequisites.h"
- #include "BsCoreObject.h"
- namespace BansheeEngine
- {
- /**
- * @brief Represents a GPU parameter block buffer. Parameter block buffers
- * are bound to GPU programs which then fetch parameters from those buffers.
- *
- * Writing or reading from this buffer will translate directly to API calls
- * that update the GPU.
- *
- * @note Core thread only.
- */
- class BS_CORE_EXPORT GpuParamBlockBuffer : public CoreObject
- {
- public:
- GpuParamBlockBuffer();
- virtual ~GpuParamBlockBuffer();
- /**
- * @brief Initializes a buffer with the specified size in bytes and usage.
- * Specify dynamic usage if you plan on modifying the buffer often,
- * otherwise specify static usage.
- *
- * @see CoreObject::initialize
- *
- * @note Must be called right after construction.
- */
- void initialize(UINT32 size, GpuParamBlockUsage usage);
- /**
- * @brief Writes all of the specified data to the buffer.
- * Data size must be the same size as the buffer;
- */
- virtual void writeData(const UINT8* data) = 0;
- /**
- * @brief Copies data from the internal buffer to a pre-allocated array.
- * Be aware this generally isn't a very fast operation as reading
- * from the GPU will most definitely involve a CPU-GPU sync point.
- *
- * @param [in,out] data Array where the data will be written to. Must be of
- * "getSize()" bytes.
- */
- virtual void readData(UINT8* data) const = 0;
- /**
- * @brief Returns the size of the buffer in bytes.
- */
- UINT32 getSize() const { return mSize; }
- /**
- * @brief Returns a parameter block buffer which is used for caching
- * the parameter information on the CPU. Essentially a CPU
- * copy of the GPU buffer.
- *
- * @note Sim thread only.
- */
- GpuParamBlockPtr getParamBlock() const { return mParamBlock; }
- // TODO UNDOCUMENTED
- // TODO - Keeping a core param block along with a sim param block is redundant in some cases,
- // as it might not be used (e.g. if gpu param block buffer is only accessed from core thread)
- GpuParamBlockPtr getCoreParamBlock() const { return mCoreParamBlock; }
- void setCoreParamBlock(const GpuParamBlockPtr& paramBlock) { mCoreParamBlock = paramBlock; }
- protected:
- GpuParamBlockUsage mUsage;
- UINT32 mSize;
- GpuParamBlockPtr mParamBlock;
- GpuParamBlockPtr mCoreParamBlock;
- };
- /**
- * @brief Implementation of a GpuParamBlock buffer that doesn't use a GPU buffer
- * for storage. Used with APIs that do not support GPU parameter buffers.
- */
- class BS_CORE_EXPORT GenericGpuParamBlockBuffer : public GpuParamBlockBuffer
- {
- public:
- GenericGpuParamBlockBuffer();
- /**
- * @copydoc GpuParamBlockBuffer::writeData
- */
- void writeData(const UINT8* data);
- /**
- * @copydoc GpuParamBlockBuffer::readData.
- */
- void readData(UINT8* data) const;
- protected:
- UINT8* mData;
- /**
- * @copydoc CoreObject::initialize_internal.
- */
- virtual void initialize_internal();
- /**
- * @copydoc CoreObject::destroy_internal.
- */
- virtual void destroy_internal();
- };
- }
|