BsD3D11HardwareBuffer.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsD3D11Prerequisites.h"
  5. #include "RenderAPI/BsHardwareBuffer.h"
  6. namespace bs { namespace ct
  7. {
  8. /** @addtogroup D3D11
  9. * @{
  10. */
  11. /** Class containing common functionality for all DirectX 11 hardware buffers. */
  12. class D3D11HardwareBuffer : public HardwareBuffer
  13. {
  14. public:
  15. /** Available types of DX11 buffers. */
  16. enum BufferType
  17. {
  18. /** Contains geometry vertices and their properties. */
  19. BT_VERTEX = 0x1,
  20. /** Contains triangle to vertex mapping. */
  21. BT_INDEX = 0x2,
  22. /** Contains GPU program parameters. */
  23. BT_CONSTANT = 0x4,
  24. /** Special value signifying a buffer is of generic type. Not an actual buffer. */
  25. BT_GROUP_GENERIC = 0x8,
  26. /** Generic buffer that holds one or more user-defined structures laid out sequentially. */
  27. BT_STRUCTURED = BT_GROUP_GENERIC | 0x10,
  28. /** Generic buffer that holds raw block of bytes with no defined structure. */
  29. BT_RAW = BT_GROUP_GENERIC | 0x20,
  30. /** Generic buffer that is used for holding parameters used for indirect rendering. */
  31. BT_INDIRECTARGUMENT = BT_GROUP_GENERIC | 0x40,
  32. /** Generic buffer that allows the GPU program to use append/consume functionality. */
  33. BT_APPENDCONSUME = BT_GROUP_GENERIC | 0x80,
  34. /** Generic buffer that contains primitive types. */
  35. BT_STANDARD = BT_GROUP_GENERIC | 0x100
  36. };
  37. D3D11HardwareBuffer(BufferType btype, GpuBufferUsage usage, UINT32 elementCount, UINT32 elementSize,
  38. D3D11Device& device, bool systemMemory = false, bool streamOut = false, bool randomGpuWrite = false,
  39. bool useCounter = false);
  40. ~D3D11HardwareBuffer();
  41. /** @copydoc HardwareBuffer::readData */
  42. void readData(UINT32 offset, UINT32 length, void* dest, UINT32 deviceIdx = 0, UINT32 queueIdx = 0) override;
  43. /** @copydoc HardwareBuffer::writeData */
  44. void writeData(UINT32 offset, UINT32 length, const void* source,
  45. BufferWriteType writeFlags = BWT_NORMAL, UINT32 queueIdx = 0) override;
  46. /** @copydoc HardwareBuffer::copyData */
  47. void copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, UINT32 dstOffset,
  48. UINT32 length, bool discardWholeBuffer = false, const SPtr<CommandBuffer>& commandBuffer = nullptr) override;
  49. /** Returns the internal DX11 buffer object. */
  50. ID3D11Buffer* getD3DBuffer() const { return mD3DBuffer; }
  51. protected:
  52. /** @copydoc HardwareBuffer::map */
  53. void* map(UINT32 offset, UINT32 length, GpuLockOptions options, UINT32 deviceIdx, UINT32 queueIdx) override;
  54. /** @copydoc HardwareBuffer::unmap */
  55. void unmap() override;
  56. BufferType mBufferType;
  57. bool mRandomGpuWrite;
  58. bool mUseCounter;
  59. UINT32 mElementCount;
  60. UINT32 mElementSize;
  61. GpuBufferUsage mUsage;
  62. ID3D11Buffer* mD3DBuffer;
  63. bool mUseTempStagingBuffer;
  64. D3D11HardwareBuffer* mpTempStagingBuffer;
  65. bool mStagingUploadNeeded;
  66. D3D11Device& mDevice;
  67. D3D11_BUFFER_DESC mDesc;
  68. };
  69. /** @} */
  70. }}