| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #pragma once
- #include "BsCorePrerequisites.h"
- #include "CoreThread/BsCoreObject.h"
- #include "RenderAPI/BsHardwareBuffer.h"
- namespace bs
- {
- /** @addtogroup RenderAPI
- * @{
- */
- /** Descriptor structure used for initialization of a GpuBuffer. */
- struct GPU_BUFFER_DESC
- {
- /** Number of elements in the buffer. */
- UINT32 elementCount;
- /**
- * Size of each individual element in the buffer, in bytes. Only needed if using non-standard buffer. If using
- * standard buffers element size is calculated from format and this must be zero.
- */
- UINT32 elementSize;
- /** Type of the buffer. Determines how is buffer seen by the GPU program and in what ways can it be used. */
- GpuBufferType type;
- /** Format if the data in the buffer. Only relevant for standard buffers, must be BF_UNKNOWN otherwise. */
- GpuBufferFormat format;
- /** Usage that tells the hardware how will be buffer be used. */
- GpuBufferUsage usage = GBU_STATIC;
- /** When true allows the GPU to write to the resource. Must be enabled if buffer type is GBT_APPENDCONSUME. */
- bool randomGpuWrite = false;
- /**
- * When true binds a counter that can be used from a GPU program on the buffer. Can only be used in combination
- * with GBT_STRUCTURED and randomGpuWrite must be enabled.
- */
- bool useCounter = false;
- };
- /**
- * Information about a GpuBuffer. Allows core and non-core versions of GpuBuffer to share the same structure for
- * properties.
- */
- class BS_CORE_EXPORT GpuBufferProperties
- {
- public:
- GpuBufferProperties(const GPU_BUFFER_DESC& desc);
- /**
- * Returns the type of the GPU buffer. Type determines which kind of views (if any) can be created for the buffer,
- * and how is data read or modified in it.
- */
- GpuBufferType getType() const { return mDesc.type; }
- /** Returns format used by the buffer. Only relevant for standard buffers. */
- GpuBufferFormat getFormat() const { return mDesc.format; }
- /** Returns buffer usage which determines how are planning on updating the buffer contents. */
- GpuBufferUsage getUsage() const { return mDesc.usage; }
- /** Return whether the buffer supports random reads and writes within the GPU programs. */
- bool getRandomGpuWrite() const { return mDesc.randomGpuWrite; }
- /** Returns whether the buffer supports counter use within GPU programs. */
- bool getUseCounter() const { return mDesc.useCounter; }
- /** Returns number of elements in the buffer. */
- UINT32 getElementCount() const { return mDesc.elementCount; }
- /** Returns size of a single element in the buffer in bytes. */
- UINT32 getElementSize() const { return mDesc.elementSize; }
- protected:
- friend class GpuBuffer;
- GPU_BUFFER_DESC mDesc;
- };
- /**
- * Handles a generic GPU buffer that you may use for storing any kind of data you wish to be accessible to the GPU.
- * These buffers may be bounds to GPU program binding slots and accessed from a GPU program, or may be used by fixed
- * pipeline in some way.
- *
- * Buffer types:
- * - Raw buffers containing a block of bytes that are up to the GPU program to interpret.
- * - Structured buffer containing an array of structures compliant to a certain layout. Similar to raw buffer but
- * easier to interpret the data.
- * - Random read/write buffers that allow you to write to random parts of the buffer from within the GPU program, and
- * then read it later. These can only be bound to pixel and compute stages.
- * - Append/Consume buffers also allow you to write to them, but in a stack-like fashion, usually where one set of
- * programs produces data while other set consumes it from the same buffer. Append/Consume buffers are structured
- * by default.
- *
- * @note Sim thread only.
- */
- class BS_CORE_EXPORT GpuBuffer : public CoreObject
- {
- public:
- virtual ~GpuBuffer() { }
- /** Returns properties describing the buffer. */
- const GpuBufferProperties& getProperties() const { return mProperties; }
- /** Retrieves a core implementation of a GPU buffer usable only from the core thread. */
- SPtr<ct::GpuBuffer> getCore() const;
- /** Returns the size of a single element in the buffer, of the provided format, in bytes. */
- static UINT32 getFormatSize(GpuBufferFormat format);
- /** @copydoc HardwareBufferManager::createGpuBuffer */
- static SPtr<GpuBuffer> create(const GPU_BUFFER_DESC& desc);
- protected:
- friend class HardwareBufferManager;
- GpuBuffer(const GPU_BUFFER_DESC& desc);
- /** @copydoc CoreObject::createCore */
- SPtr<ct::CoreObject> createCore() const override;
- GpuBufferProperties mProperties;
- };
- /** @} */
- namespace ct
- {
- /** @addtogroup RenderAPI-Internal
- * @{
- */
- /**
- * Core thread version of a bs::GpuBuffer.
- *
- * @note Core thread only.
- */
- class BS_CORE_EXPORT GpuBuffer : public CoreObject, public HardwareBuffer
- {
- public:
- virtual ~GpuBuffer();
- /** Returns properties describing the buffer. */
- const GpuBufferProperties& getProperties() const { return mProperties; }
- /** @copydoc HardwareBufferManager::createGpuBuffer */
- static SPtr<GpuBuffer> create(const GPU_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
- protected:
- GpuBuffer(const GPU_BUFFER_DESC& desc, UINT32 deviceMask);
- GpuBufferProperties mProperties;
- };
- /** @} */
- }
- }
|