Diligent Engine  v.2.4.g
Buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 #pragma once
29 
30 // clang-format off
31 
34 
35 #include "DeviceObject.h"
36 #include "BufferView.h"
37 
39 
40 
41 // {EC47EAD3-A2C4-44F2-81C5-5248D14F10E4}
42 static const INTERFACE_ID IID_Buffer =
43  {0xec47ead3, 0xa2c4, 0x44f2, {0x81, 0xc5, 0x52, 0x48, 0xd1, 0x4f, 0x10, 0xe4}};
44 
46 
49 {
52 
57 
61 
68 
71 };
72 
75 
77  Uint32 uiSizeInBytes DEFAULT_INITIALIZER(0);
78 
80 
86 
89 
93 
96 
98 
104  Uint32 ElementByteStride DEFAULT_INITIALIZER(0);
105 
107  Uint64 CommandQueueMask DEFAULT_INITIALIZER(1);
108 
109 #if DILIGENT_CPP_INTERFACE
110  // We have to explicitly define constructors because otherwise the following initialization fails on Apple's clang:
111  // BufferDesc{1024, BIND_UNIFORM_BUFFER, USAGE_DEFAULT}
112 
113  BufferDesc()noexcept{}
114 
115  BufferDesc(Uint32 _uiSizeInBytes,
116  BIND_FLAGS _BindFlags,
117  USAGE _Usage = BufferDesc{}.Usage,
118  CPU_ACCESS_FLAGS _CPUAccessFlags = BufferDesc{}.CPUAccessFlags,
119  BUFFER_MODE _Mode = BufferDesc{}.Mode,
120  Uint32 _ElementByteStride = BufferDesc{}.ElementByteStride,
121  Uint64 _CommandQueueMask = BufferDesc{}.CommandQueueMask) noexcept :
122  uiSizeInBytes {_uiSizeInBytes },
123  BindFlags {_BindFlags },
124  Usage {_Usage },
125  CPUAccessFlags {_CPUAccessFlags },
126  Mode {_Mode },
127  ElementByteStride {_ElementByteStride},
128  CommandQueueMask {_CommandQueueMask }
129  {
130  }
131 
133 
140  bool operator == (const BufferDesc& RHS)const
141  {
142  return uiSizeInBytes == RHS.uiSizeInBytes &&
143  BindFlags == RHS.BindFlags &&
144  Usage == RHS.Usage &&
145  CPUAccessFlags == RHS.CPUAccessFlags &&
146  Mode == RHS.Mode &&
147  ElementByteStride == RHS.ElementByteStride &&
148  CommandQueueMask == RHS.CommandQueueMask;
149  }
150 #endif
151 };
152 typedef struct BufferDesc BufferDesc;
153 
156 {
158  const void* pData DEFAULT_INITIALIZER(nullptr);
159 
162 
163 
164 #if DILIGENT_CPP_INTERFACE
165 
166  BufferData() noexcept {}
167 
168  BufferData(const void* _pData,
169  Uint32 _DataSize) :
170  pData {_pData },
171  DataSize{_DataSize}
172  {}
173 #endif
174 };
175 typedef struct BufferData BufferData;
176 
177 #define DILIGENT_INTERFACE_NAME IBuffer
178 #include "../../../Primitives/interface/DefineInterfaceHelperMacros.h"
179 
180 #define IBufferInclusiveMethods \
181  IDeviceObjectInclusiveMethods; \
182  IBufferMethods Buffer
183 
185 
188 {
189 #if DILIGENT_CPP_INTERFACE
190  virtual const BufferDesc& METHOD(GetDesc)() const override = 0;
192 #endif
193 
195 
205  VIRTUAL void METHOD(CreateView)(THIS_
206  const BufferViewDesc REF ViewDesc,
207  IBufferView** ppView) PURE;
208 
210 
219  VIRTUAL IBufferView* METHOD(GetDefaultView)(THIS_
220  BUFFER_VIEW_TYPE ViewType) PURE;
221 
223 
227  VIRTUAL void* METHOD(GetNativeHandle)(THIS) PURE;
228 
230 
236  VIRTUAL void METHOD(SetState)(THIS_
237  RESOURCE_STATE State) PURE;
238 
241 };
243 
244 #include "../../../Primitives/interface/UndefInterfaceHelperMacros.h"
245 
246 #if DILIGENT_C_INTERFACE
247 
248 // clang-format off
249 
250 # define IBuffer_GetDesc(This) (const struct BufferDesc*)IDeviceObject_GetDesc(This)
251 
252 # define IBuffer_CreateView(This, ...) CALL_IFACE_METHOD(Buffer, CreateView, This, __VA_ARGS__)
253 # define IBuffer_GetDefaultView(This, ...) CALL_IFACE_METHOD(Buffer, GetDefaultView, This, __VA_ARGS__)
254 # define IBuffer_GetNativeHandle(This) CALL_IFACE_METHOD(Buffer, GetNativeHandle, This)
255 # define IBuffer_SetState(This, ...) CALL_IFACE_METHOD(Buffer, SetState, This, __VA_ARGS__)
256 # define IBuffer_GetState(This) CALL_IFACE_METHOD(Buffer, GetState, This)
257 
258 // clang-format on
259 
260 #endif
261 
262 DILIGENT_END_NAMESPACE // namespace Diligent
Diligent::BufferViewDesc
Buffer view description.
Definition: BufferView.h:88
DILIGENT_END_INTERFACE
#define DILIGENT_END_INTERFACE
Definition: DefineInterfaceHelperMacros.h:88
Diligent::INTERFACE_ID
struct INTERFACE_ID INTERFACE_ID
Definition: InterfaceID.h:54
Diligent::CPU_ACCESS_FLAGS
CPU_ACCESS_FLAGS
Allowed CPU access mode flags when mapping a resource.
Definition: GraphicsTypes.h:191
VIRTUAL
#define VIRTUAL
Definition: DefineInterfaceHelperMacros.h:83
Diligent::BufferDesc::uiSizeInBytes
Uint32 uiSizeInBytes
Size of the buffer, in bytes. For a uniform buffer, this must be multiple of 16.
Definition: Buffer.h:77
Diligent::USAGE
USAGE
Resource usage.
Definition: GraphicsTypes.h:143
DILIGENT_BEGIN_INTERFACE
#define DILIGENT_BEGIN_INTERFACE(Name, Base)
Definition: CommonDefinitions.h:97
Diligent::Uint64
uint64_t Uint64
64-bit unsigned integer
Definition: BasicTypes.h:50
Diligent::BufferDesc::BindFlags
BIND_FLAGS BindFlags
Buffer bind flags, see Diligent::BIND_FLAGS for details.
Definition: Buffer.h:85
Diligent::BufferDesc::Mode
BUFFER_MODE Mode
Buffer mode, see Diligent::BUFFER_MODE.
Definition: Buffer.h:95
Diligent::operator==
bool operator==(const Plane3D &p1, const Plane3D &p2)
Definition: AdvancedMath.hpp:442
Diligent::IDeviceObject
Base interface for all objects created by the render device Diligent::IRenderDevice.
Definition: DeviceObject.h:52
THIS
#define THIS
Definition: DefineInterfaceHelperMacros.h:81
Diligent::IBuffer
Buffer interface.
Definition: Buffer.h:187
Diligent::BufferDesc::CPUAccessFlags
CPU_ACCESS_FLAGS CPUAccessFlags
CPU access flags or 0 if no CPU access is allowed, see Diligent::CPU_ACCESS_FLAGS for details.
Definition: Buffer.h:92
Diligent::BufferData::BufferData
BufferData(const void *_pData, Uint32 _DataSize)
Definition: Buffer.h:168
PURE
#define PURE
Definition: DefineInterfaceHelperMacros.h:85
Diligent::DeviceObjectAttribs
Describes common device object attributes.
Definition: GraphicsTypes.h:1196
Diligent::BIND_FLAGS
BIND_FLAGS
Resource binding flags.
Definition: GraphicsTypes.h:115
Diligent::BufferDesc::ElementByteStride
Uint32 ElementByteStride
Buffer element stride, in bytes.
Definition: Buffer.h:104
DILIGENT_END_NAMESPACE
#define DILIGENT_END_NAMESPACE
Definition: CommonDefinitions.h:86
CONST
#define CONST
Definition: DefineInterfaceHelperMacros.h:84
Diligent::BufferDesc
struct BufferDesc BufferDesc
Definition: Buffer.h:152
Diligent::BufferData::BufferData
BufferData() noexcept
Definition: Buffer.h:166
Diligent::BufferDesc::BufferDesc
BufferDesc() noexcept
Definition: Buffer.h:113
DILIGENT_DERIVE
#define DILIGENT_DERIVE(TypeName)
Definition: CommonDefinitions.h:90
Diligent::BUFFER_MODE_FORMATTED
@ BUFFER_MODE_FORMATTED
Formated buffer. Access to the buffer will use format conversion operations. In this mode,...
Definition: Buffer.h:56
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
DEFAULT_INITIALIZER
#define DEFAULT_INITIALIZER(x)
Definition: CommonDefinitions.h:93
Diligent::BUFFER_MODE_NUM_MODES
@ BUFFER_MODE_NUM_MODES
Helper value storing the total number of modes in the enumeration.
Definition: Buffer.h:70
BufferView.h
Diligent::BUFFER_MODE_UNDEFINED
@ BUFFER_MODE_UNDEFINED
Undefined mode.
Definition: Buffer.h:51
DeviceObject.h
Diligent::BUFFER_MODE
BUFFER_MODE
Describes the buffer access mode.
Definition: Buffer.h:48
Diligent::BufferDesc
Buffer description.
Definition: Buffer.h:74
REF
#define REF
Definition: DefineGlobalFuncHelperMacros.h:39
METHOD
#define METHOD(Name)
Definition: DefineInterfaceHelperMacros.h:87
DILIGENT_TYPED_ENUM
#define DILIGENT_TYPED_ENUM(EnumName, EnumType)
Definition: CommonDefinitions.h:88
Diligent::BufferDesc::BufferDesc
BufferDesc(Uint32 _uiSizeInBytes, BIND_FLAGS _BindFlags, USAGE _Usage=BufferDesc{}.Usage, CPU_ACCESS_FLAGS _CPUAccessFlags=BufferDesc{}.CPUAccessFlags, BUFFER_MODE _Mode=BufferDesc{}.Mode, Uint32 _ElementByteStride=BufferDesc{}.ElementByteStride, Uint64 _CommandQueueMask=BufferDesc{}.CommandQueueMask) noexcept
Definition: Buffer.h:115
Diligent::BIND_NONE
@ BIND_NONE
Undefined binding.
Definition: GraphicsTypes.h:117
Diligent::BufferDesc::CommandQueueMask
Uint64 CommandQueueMask
Defines which command queues this buffer can be used with.
Definition: Buffer.h:107
Diligent::Uint8
uint8_t Uint8
8-bit unsigned integer
Definition: BasicTypes.h:53
DILIGENT_BEGIN_NAMESPACE
#define DILIGENT_BEGIN_NAMESPACE(Name)
Definition: CommonDefinitions.h:82
Diligent::BUFFER_MODE_STRUCTURED
@ BUFFER_MODE_STRUCTURED
Structured buffer. In this mode, ElementByteStride member of BufferDesc defines the structure stride.
Definition: Buffer.h:60
Diligent::BufferDesc::Usage
USAGE Usage
Buffer usage, see Diligent::USAGE for details.
Definition: Buffer.h:88
Diligent::BUFFER_MODE_RAW
@ BUFFER_MODE_RAW
Raw buffer. In this mode, the buffer is accessed as raw bytes. Formatted views of a raw buffer can al...
Definition: Buffer.h:67
Diligent::RESOURCE_STATE
RESOURCE_STATE
Resource usage state.
Definition: GraphicsTypes.h:2814
Diligent::IBufferView
Buffer view interface.
Definition: BufferView.h:155
Diligent::BUFFER_VIEW_TYPE
BUFFER_VIEW_TYPE
Buffer view type.
Definition: GraphicsTypes.h:303
Diligent::BufferData
Describes the buffer initial data.
Definition: Buffer.h:155
Diligent::CPU_ACCESS_NONE
@ CPU_ACCESS_NONE
No CPU access.
Definition: GraphicsTypes.h:193
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
THIS_
#define THIS_
Definition: DefineInterfaceHelperMacros.h:82
Diligent::USAGE_DEFAULT
@ USAGE_DEFAULT
A resource that requires read and write access by the GPU and can also be occasionally written by the...
Definition: GraphicsTypes.h:156