Diligent Engine API Reference
BufferD3D11Impl.h
1 /* Copyright 2015-2018 Egor Yusov
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
12  *
13  * In no event and under no legal theory, whether in tort (including negligence),
14  * contract, or otherwise, unless required by applicable law (such as deliberate
15  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
16  * liable for any damages, including any direct, indirect, special, incidental,
17  * or consequential damages of any character arising as a result of this License or
18  * out of the use or inability to use the software (including but not limited to damages
19  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
20  * all other commercial damages or losses), even if such Contributor has been advised
21  * of the possibility of such damages.
22  */
23 
24 #pragma once
25 
28 
29 #include "BufferD3D11.h"
30 #include "RenderDeviceD3D11.h"
31 #include "BufferBase.h"
32 #include "BufferViewD3D11Impl.h"
33 
34 namespace Diligent
35 {
36 
38 
39 enum class D3D11BufferState
40 {
41  Undefined = 0x00,
42  ShaderResource = 0x01,
43  ConstantBuffer = 0x02,
44  VertexBuffer = 0x04,
45  IndexBuffer = 0x08,
46  UnorderedAccess = 0x10,
47  AnyInput = ShaderResource | ConstantBuffer | VertexBuffer | IndexBuffer
48 };
49 
51 class BufferD3D11Impl : public BufferBase<IBufferD3D11, BufferViewD3D11Impl, FixedBlockMemoryAllocator>
52 {
53 public:
55  BufferD3D11Impl(IReferenceCounters *pRefCounters,
56  FixedBlockMemoryAllocator &BuffViewObjMemAllocator,
57  class RenderDeviceD3D11Impl *pDeviceD3D11,
58  const BufferDesc& BuffDesc,
59  const BufferData &BuffData = BufferData());
60  BufferD3D11Impl(IReferenceCounters *pRefCounters,
61  FixedBlockMemoryAllocator &BuffViewObjMemAllocator,
62  class RenderDeviceD3D11Impl *pDeviceD3D11,
63  const BufferDesc& BuffDesc,
64  ID3D11Buffer *pd3d11Buffer);
65 
66  ~BufferD3D11Impl();
67 
68  virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final;
69 
70  virtual void UpdateData( IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData )override final;
71  virtual void CopyData( IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size )override final;
72  virtual void Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData )override final;
73  virtual void Unmap( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags )override final;
74  virtual ID3D11Buffer *GetD3D11Buffer()override final{ return m_pd3d11Buffer; }
75 
76  virtual void* GetNativeHandle()override final { return GetD3D11Buffer(); }
77 
78  void ResetState(D3D11BufferState State){m_State = static_cast<Uint32>(State);}
79  void AddState(D3D11BufferState State){m_State |= static_cast<Uint32>(State);}
80  void ClearState(D3D11BufferState State){m_State &= ~static_cast<Uint32>(State);}
81  bool CheckState(D3D11BufferState State){return (m_State & static_cast<Uint32>(State)) ? true : false;}
82 
83 private:
84  virtual void CreateViewInternal( const struct BufferViewDesc &ViewDesc, IBufferView **ppView, bool bIsDefaultView )override;
85 
86  void CreateUAV( struct BufferViewDesc &UAVDesc, ID3D11UnorderedAccessView **ppD3D11UAV );
87  void CreateSRV( struct BufferViewDesc &SRVDesc, ID3D11ShaderResourceView **ppD3D11SRV );
88 
89  friend class DeviceContextD3D11Impl;
90  CComPtr<ID3D11Buffer> m_pd3d11Buffer;
91 
92  Uint32 m_State = static_cast<Uint32>(D3D11BufferState::Undefined);
93 };
94 
95 }
Describes the buffer initial data.
Definition: Buffer.h:176
virtual void CopyData(IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size) override final
Base implementation of IBuffer::CopyData(); validates input parameters.
Definition: BufferD3D11Impl.cpp:175
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Template class implementing base functionality for a buffer object.
Definition: BufferBase.h:46
virtual void Unmap(IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags) override final
Base implementation of IBuffer::Unmap()
Definition: BufferD3D11Impl.cpp:209
virtual void UpdateData(IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData) override final
Base implementation of IBuffer::UpdateData(); validates input parameters.
Definition: BufferD3D11Impl.cpp:158
Buffer interface.
Definition: Buffer.h:200
Device context interface.
Definition: DeviceContext.h:443
virtual void * GetNativeHandle() override final
Returns native buffer handle specific to the underlying graphics API.
Definition: BufferD3D11Impl.h:76
Buffer description.
Definition: Buffer.h:57
Memory allocator that allocates memory in a fixed-size chunks.
Definition: FixedBlockMemoryAllocator.h:50
Implementation of the Diligent::IRenderDeviceD3D11 interface.
Definition: RenderDeviceD3D11Impl.h:38
virtual void QueryInterface(const Diligent::INTERFACE_ID &IID, IObject **ppInterface) override final
Queries the specific interface, see IObject::QueryInterface() for details.
virtual ID3D11Buffer * GetD3D11Buffer() override final
Returns a pointer to the ID3D11Buffer interface of the internal Direct3D11 object.
Definition: BufferD3D11Impl.h:74
Implementation of the Diligent::IBufferD3D11 interface.
Definition: BufferD3D11Impl.h:51
virtual void Map(IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData) override final
Base implementation of IBuffer::Map(); validates input parameters.
Definition: BufferD3D11Impl.cpp:192
MAP_TYPE
Resource mapping type.
Definition: GraphicsTypes.h:125