BsD3D11GpuBufferView.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "BsGpuBufferView.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup D3D11
  9. * @{
  10. */
  11. /**
  12. * Represents a specific view of a GpuBuffer. Different views all of the same buffer be used in different situations
  13. * (for example for reading from a shader, or for a unordered read/write operation).
  14. */
  15. class BS_D3D11_EXPORT D3D11GpuBufferView : public GpuBufferView
  16. {
  17. public:
  18. D3D11GpuBufferView();
  19. virtual ~D3D11GpuBufferView();
  20. /** @copydoc GpuBufferView::initialize */
  21. void initialize(const SPtr<GpuBufferCore>& buffer, GPU_BUFFER_DESC& desc) override;
  22. /** Returns the DX11 shader resource view object for the buffer. */
  23. ID3D11ShaderResourceView* getSRV() const { return mSRV; }
  24. /** Returns the DX11 unordered access view object for the buffer. */
  25. ID3D11UnorderedAccessView* getUAV() const { return mUAV; }
  26. private:
  27. /**
  28. * Creates a DX11 shader resource view that allows a buffer to be bound to a shader for reading (the most common
  29. * option).
  30. *
  31. * @param[in] buffer Buffer to create the view for.
  32. * @param[in] firstElement Index of the first element the view manages. Interpretation of this value depends on
  33. * exact buffer type. It may be byte offset for raw buffers, or number of elements for
  34. * structured buffers.
  35. * @param[in] elementWidth Width of a single element in the buffer. Size of the structure in structured buffers
  36. * and ignored for raw buffers as they always operate on single byte basis.
  37. * @param[in] numElements Number of elements the view manages, starting after the "firstElement". This means
  38. * number of bytes for raw buffers or number of structures for structured buffers.
  39. * @return Constructed DX11 shader resource view object.
  40. */
  41. ID3D11ShaderResourceView* createSRV(D3D11GpuBufferCore* buffer, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements);
  42. /**
  43. * Creates a DX11 unordered access view that allows a buffer to be bound to a shader for random reading or writing.
  44. *
  45. * @param[in] buffer Buffer to create the view for.
  46. * @param[in] firstElement Index of the first element the view manages. Interpretation of this value depends on
  47. * exact buffer type. It may be byte offset for raw buffers, or number of elements for
  48. * structured buffers.
  49. * @param[in] numElements Number of elements the view manages, starting after the @p firstElement. This means
  50. * number of bytes for raw buffers or number of structures for structured buffers.
  51. * @return Constructed DX11 unordered access view object.
  52. */
  53. ID3D11UnorderedAccessView* createUAV(D3D11GpuBufferCore* buffer, UINT32 firstElement, UINT32 numElements, bool useCounter);
  54. ID3D11ShaderResourceView* mSRV;
  55. ID3D11UnorderedAccessView* mUAV;
  56. };
  57. /** @} */
  58. }