| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- #pragma once
- #include "BsCorePrerequisites.h"
- #include "BsCoreObject.h"
- namespace BansheeEngine
- {
- /**
- * @brief Core thread version of a GPU param block buffer.
- *
- * @see GpuParamBlockBuffer
- *
- * @note Core thread only.
- */
- class BS_CORE_EXPORT GpuParamBlockBufferCore : public CoreObjectCore
- {
- public:
- GpuParamBlockBufferCore(UINT32 size, GpuParamBlockUsage usage);
- virtual ~GpuParamBlockBufferCore();
- /**
- * @brief Writes all of the specified data to the buffer.
- * Data size must be the same size as the buffer;
- */
- virtual void writeToGPU(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 readFromGPU(UINT8* data) const = 0;
- /**
- * @brief Flushes any cached data into the actual GPU buffer.
- */
- void flushToGPU();
- /**
- * @brief Write some data to the specified offset in the buffer.
- *
- * @note All values are in bytes.
- * Actual hardware buffer update is delayed until rendering.
- */
- void write(UINT32 offset, const void* data, UINT32 size);
- /**
- * @brief Read some data from the specified offset in the buffer.
- *
- * @note All values are in bytes.
- * This reads from the cached CPU buffer. Actual hardware buffer can be read
- * from the core thread.
- */
- void read(UINT32 offset, void* data, UINT32 size);
- /**
- * @brief Clear specified section of the buffer to zero.
- *
- * @note All values are in bytes.
- * Actual hardware buffer update is delayed until rendering.
- */
- void zeroOut(UINT32 offset, UINT32 size);
- /**
- * @brief Returns the size of the buffer in bytes.
- */
- UINT32 getSize() const { return mSize; }
- /**
- * @copydoc HardwareBufferCoreManager::createGpuParamBlockBuffer
- */
- static SPtr<GpuParamBlockBufferCore> create(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
- protected:
- /**
- * @copydoc CoreObjectCore::syncToCore
- */
- virtual void syncToCore(const CoreSyncData& data) override;
- GpuParamBlockUsage mUsage;
- UINT32 mSize;
- UINT8* mCachedData;
- bool mGPUBufferDirty;
- };
- /**
- * @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 Sim thread only.
- */
- class BS_CORE_EXPORT GpuParamBlockBuffer : public CoreObject
- {
- public:
- GpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage);
- virtual ~GpuParamBlockBuffer();
- /**
- * @brief Write some data to the specified offset in the buffer.
- *
- * @note All values are in bytes.
- * Actual hardware buffer update is delayed until rendering.
- */
- void write(UINT32 offset, const void* data, UINT32 size);
- /**
- * @brief Read some data from the specified offset in the buffer.
- *
- * @note All values are in bytes.
- * This reads from the cached CPU buffer. Actual hardware buffer can be read
- * from the core thread.
- */
- void read(UINT32 offset, void* data, UINT32 size);
- /**
- * @brief Clear specified section of the buffer to zero.
- *
- * @note All values are in bytes.
- * Actual hardware buffer update is delayed until rendering.
- */
- void zeroOut(UINT32 offset, UINT32 size);
- /**
- * @brief Returns internal cached data of the buffer.
- */
- const UINT8* getCachedData() const { return mCachedData; }
- /**
- * @brief Returns the size of the buffer in bytes.
- */
- UINT32 getSize() const { return mSize; }
- /**
- * @brief Retrieves a core implementation of a GPU param block buffer usable only from the
- * core thread.
- */
- SPtr<GpuParamBlockBufferCore> getCore() const;
- /**
- * @copydoc HardwareBufferManager::createGpuParamBlockBuffer
- */
- static GpuParamBlockBufferPtr create(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
- protected:
- /**
- * @copydoc CoreObject::createCore
- */
- SPtr<CoreObjectCore> createCore() const override;
- /**
- * @copydoc CoreObject::syncToCore
- */
- virtual CoreSyncData syncToCore(FrameAlloc* allocator) override;
- GpuParamBlockUsage mUsage;
- UINT32 mSize;
- UINT8* mCachedData;
- };
- /**
- * @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 GenericGpuParamBlockBufferCore : public GpuParamBlockBufferCore
- {
- public:
- GenericGpuParamBlockBufferCore(UINT32 size, GpuParamBlockUsage usage);
- ~GenericGpuParamBlockBufferCore();
- /**
- * @copydoc GpuParamBlockBufferCore::writeData
- */
- void writeToGPU(const UINT8* data) override;
- /**
- * @copydoc GpuParamBlockBufferCore::readData.
- */
- void readFromGPU(UINT8* data) const override;
- protected:
- UINT8* mData;
- /**
- * @copydoc CoreObjectCore::initialize
- */
- virtual void initialize() override;
- };
- }
|