BsGpuParamBlockBuffer.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsCoreObject.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Represents a GPU parameter block buffer. Parameter block buffers
  8. * are bound to GPU programs which then fetch parameters from those buffers.
  9. *
  10. * Writing or reading from this buffer will translate directly to API calls
  11. * that update the GPU.
  12. *
  13. * @note Core thread only.
  14. */
  15. class BS_CORE_EXPORT GpuParamBlockBuffer : public CoreObject
  16. {
  17. public:
  18. GpuParamBlockBuffer();
  19. virtual ~GpuParamBlockBuffer();
  20. /**
  21. * @brief Initializes a buffer with the specified size in bytes and usage.
  22. * Specify dynamic usage if you plan on modifying the buffer often,
  23. * otherwise specify static usage.
  24. *
  25. * @see CoreObject::initialize
  26. *
  27. * @note Must be called right after construction.
  28. */
  29. void initialize(UINT32 size, GpuParamBlockUsage usage);
  30. /**
  31. * @brief Writes all of the specified data to the buffer.
  32. * Data size must be the same size as the buffer;
  33. */
  34. virtual void writeData(const UINT8* data) = 0;
  35. /**
  36. * @brief Copies data from the internal buffer to a pre-allocated array.
  37. * Be aware this generally isn't a very fast operation as reading
  38. * from the GPU will most definitely involve a CPU-GPU sync point.
  39. *
  40. * @param [in,out] data Array where the data will be written to. Must be of
  41. * "getSize()" bytes.
  42. */
  43. virtual void readData(UINT8* data) const = 0;
  44. /**
  45. * @brief Returns the size of the buffer in bytes.
  46. */
  47. UINT32 getSize() const { return mSize; }
  48. /**
  49. * @brief Returns a parameter block buffer which is used for caching
  50. * the parameter information. Essentially a CPU copy of the GPU buffer.
  51. *
  52. * @note Thread safe but it's up to the caller to ensure this is only called from
  53. * one thread.
  54. */
  55. GpuParamBlockPtr getParamBlock() const { return mParamBlock; }
  56. /**
  57. * @copydoc HardwareBufferManager::createGpuParamBlockBuffer
  58. */
  59. static GpuParamBlockBufferPtr create(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
  60. protected:
  61. GpuParamBlockUsage mUsage;
  62. UINT32 mSize;
  63. GpuParamBlockPtr mParamBlock;
  64. };
  65. /**
  66. * @brief Implementation of a GpuParamBlock buffer that doesn't use a GPU buffer
  67. * for storage. Used with APIs that do not support GPU parameter buffers.
  68. */
  69. class BS_CORE_EXPORT GenericGpuParamBlockBuffer : public GpuParamBlockBuffer
  70. {
  71. public:
  72. GenericGpuParamBlockBuffer();
  73. /**
  74. * @copydoc GpuParamBlockBuffer::writeData
  75. */
  76. void writeData(const UINT8* data);
  77. /**
  78. * @copydoc GpuParamBlockBuffer::readData.
  79. */
  80. void readData(UINT8* data) const;
  81. protected:
  82. UINT8* mData;
  83. /**
  84. * @copydoc CoreObject::initialize_internal.
  85. */
  86. virtual void initialize_internal();
  87. /**
  88. * @copydoc CoreObject::destroy_internal.
  89. */
  90. virtual void destroy_internal();
  91. };
  92. }