BsGpuParamBlockBuffer.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsCoreObject.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup RenderAPI-Internal
  9. * @{
  10. */
  11. /**
  12. * Core thread version of a GpuParamBlockBuffer.
  13. *
  14. * @note Core thread only.
  15. */
  16. class BS_CORE_EXPORT GpuParamBlockBufferCore : public CoreObjectCore
  17. {
  18. public:
  19. GpuParamBlockBufferCore(UINT32 size, GpuParamBlockUsage usage, GpuDeviceFlags deviceMask);
  20. virtual ~GpuParamBlockBufferCore();
  21. /** Writes all of the specified data to the buffer. Data size must be the same size as the buffer. */
  22. virtual void writeToGPU(const UINT8* data) = 0;
  23. /** Flushes any cached data into the actual GPU buffer. */
  24. void flushToGPU();
  25. /**
  26. * Write some data to the specified offset in the buffer.
  27. *
  28. * @note All values are in bytes. Actual hardware buffer update is delayed until rendering.
  29. */
  30. void write(UINT32 offset, const void* data, UINT32 size);
  31. /**
  32. * Read some data from the specified offset in the buffer.
  33. *
  34. * @note All values are in bytes. This reads from the cached CPU buffer and not directly from the GPU.
  35. */
  36. void read(UINT32 offset, void* data, UINT32 size);
  37. /**
  38. * Clear specified section of the buffer to zero.
  39. *
  40. * @note All values are in bytes. Actual hardware buffer update is delayed until rendering.
  41. */
  42. void zeroOut(UINT32 offset, UINT32 size);
  43. /** Returns the size of the buffer in bytes. */
  44. UINT32 getSize() const { return mSize; }
  45. /** @copydoc HardwareBufferCoreManager::createGpuParamBlockBuffer */
  46. static SPtr<GpuParamBlockBufferCore> create(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC,
  47. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  48. protected:
  49. /** @copydoc CoreObjectCore::syncToCore */
  50. void syncToCore(const CoreSyncData& data) override;
  51. GpuParamBlockUsage mUsage;
  52. UINT32 mSize;
  53. UINT8* mCachedData;
  54. bool mGPUBufferDirty;
  55. };
  56. /** @} */
  57. /** @addtogroup RenderAPI
  58. * @{
  59. */
  60. /**
  61. * Represents a GPU parameter block buffer. Parameter block buffers are bound to GPU programs which then fetch
  62. * parameters from those buffers.
  63. *
  64. * Writing or reading from this buffer will translate directly to API calls that update the GPU.
  65. *
  66. * @note Sim thread only.
  67. */
  68. class BS_CORE_EXPORT GpuParamBlockBuffer : public CoreObject
  69. {
  70. public:
  71. GpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage);
  72. virtual ~GpuParamBlockBuffer();
  73. /**
  74. * Write some data to the specified offset in the buffer.
  75. *
  76. * @note All values are in bytes. Actual hardware buffer update is delayed until rendering.
  77. */
  78. void write(UINT32 offset, const void* data, UINT32 size);
  79. /**
  80. * Read some data from the specified offset in the buffer.
  81. *
  82. * @note All values are in bytes. This reads from the cached CPU buffer and not from the GPU.
  83. */
  84. void read(UINT32 offset, void* data, UINT32 size);
  85. /**
  86. * Clear specified section of the buffer to zero.
  87. *
  88. * @note All values are in bytes. Actual hardware buffer update is delayed until rendering.
  89. */
  90. void zeroOut(UINT32 offset, UINT32 size);
  91. /** Returns internal cached data of the buffer. */
  92. const UINT8* getCachedData() const { return mCachedData; }
  93. /** Returns the size of the buffer in bytes. */
  94. UINT32 getSize() const { return mSize; }
  95. /** Retrieves a core implementation of a GPU param block buffer usable only from the core thread. */
  96. SPtr<GpuParamBlockBufferCore> getCore() const;
  97. /** @copydoc HardwareBufferManager::createGpuParamBlockBuffer */
  98. static SPtr<GpuParamBlockBuffer> create(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
  99. protected:
  100. /** @copydoc CoreObject::createCore */
  101. SPtr<CoreObjectCore> createCore() const override;
  102. /** @copydoc CoreObject::syncToCore */
  103. CoreSyncData syncToCore(FrameAlloc* allocator) override;
  104. GpuParamBlockUsage mUsage;
  105. UINT32 mSize;
  106. UINT8* mCachedData;
  107. };
  108. /** @endcond */
  109. /** @} */
  110. }