BsGpuParamBlockBuffer.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 bs
  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. /**
  22. * Writes all of the specified data to the buffer. Data size must be the same size as the buffer.
  23. *
  24. * @param[in] data Data to write. Must match the size of the buffer.
  25. * @param[in] queueIdx Device queue to perform the write operation on. See @ref queuesDoc.
  26. */
  27. virtual void writeToGPU(const UINT8* data, UINT32 queueIdx = 0) = 0;
  28. /**
  29. * Flushes any cached data into the actual GPU buffer.
  30. *
  31. * @param[in] queueIdx Device queue to perform the write operation on. See @ref queuesDoc.
  32. */
  33. void flushToGPU(UINT32 queueIdx = 0);
  34. /**
  35. * Write some data to the specified offset in the buffer.
  36. *
  37. * @note All values are in bytes. Actual hardware buffer update is delayed until rendering or until
  38. * flushToGPU() is called.
  39. */
  40. void write(UINT32 offset, const void* data, UINT32 size);
  41. /**
  42. * Read some data from the specified offset in the buffer.
  43. *
  44. * @note All values are in bytes. This reads from the cached CPU buffer and not directly from the GPU.
  45. */
  46. void read(UINT32 offset, void* data, UINT32 size);
  47. /**
  48. * Clear specified section of the buffer to zero.
  49. *
  50. * @note All values are in bytes. Actual hardware buffer update is delayed until rendering or until
  51. * flushToGPU() is called.
  52. */
  53. void zeroOut(UINT32 offset, UINT32 size);
  54. /** Returns the size of the buffer in bytes. */
  55. UINT32 getSize() const { return mSize; }
  56. /** @copydoc HardwareBufferCoreManager::createGpuParamBlockBuffer */
  57. static SPtr<GpuParamBlockBufferCore> create(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC,
  58. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  59. protected:
  60. /** @copydoc CoreObjectCore::syncToCore */
  61. void syncToCore(const CoreSyncData& data) override;
  62. GpuParamBlockUsage mUsage;
  63. UINT32 mSize;
  64. UINT8* mCachedData;
  65. bool mGPUBufferDirty;
  66. };
  67. /** @} */
  68. /** @addtogroup RenderAPI
  69. * @{
  70. */
  71. /**
  72. * Represents a GPU parameter block buffer. Parameter block buffers are bound to GPU programs which then fetch
  73. * parameters from those buffers.
  74. *
  75. * Writing or reading from this buffer will translate directly to API calls that update the GPU.
  76. *
  77. * @note Sim thread only.
  78. */
  79. class BS_CORE_EXPORT GpuParamBlockBuffer : public CoreObject
  80. {
  81. public:
  82. GpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage);
  83. virtual ~GpuParamBlockBuffer();
  84. /**
  85. * Write some data to the specified offset in the buffer.
  86. *
  87. * @note All values are in bytes. Actual hardware buffer update is delayed until rendering.
  88. */
  89. void write(UINT32 offset, const void* data, UINT32 size);
  90. /**
  91. * Read some data from the specified offset in the buffer.
  92. *
  93. * @note All values are in bytes. This reads from the cached CPU buffer and not from the GPU.
  94. */
  95. void read(UINT32 offset, void* data, UINT32 size);
  96. /**
  97. * Clear specified section of the buffer to zero.
  98. *
  99. * @note All values are in bytes. Actual hardware buffer update is delayed until rendering.
  100. */
  101. void zeroOut(UINT32 offset, UINT32 size);
  102. /** Returns internal cached data of the buffer. */
  103. const UINT8* getCachedData() const { return mCachedData; }
  104. /** Returns the size of the buffer in bytes. */
  105. UINT32 getSize() const { return mSize; }
  106. /** Retrieves a core implementation of a GPU param block buffer usable only from the core thread. */
  107. SPtr<GpuParamBlockBufferCore> getCore() const;
  108. /** @copydoc HardwareBufferManager::createGpuParamBlockBuffer */
  109. static SPtr<GpuParamBlockBuffer> create(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
  110. protected:
  111. /** @copydoc CoreObject::createCore */
  112. SPtr<CoreObjectCore> createCore() const override;
  113. /** @copydoc CoreObject::syncToCore */
  114. CoreSyncData syncToCore(FrameAlloc* allocator) override;
  115. GpuParamBlockUsage mUsage;
  116. UINT32 mSize;
  117. UINT8* mCachedData;
  118. };
  119. /** @endcond */
  120. /** @} */
  121. }