Nebula
Loading...
Searching...
No Matches
barrier.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
10//------------------------------------------------------------------------------
11#include "ids/id.h"
12#include "util/array.h"
14#include "coregraphics/buffer.h"
16#include "coregraphics/config.h"
17#include <tuple>
18namespace CoreGraphics
19{
20
22
23struct CmdBufferId;
25{
28
36
44
49
54
59
64
69
74
79
84
89
90 const bool Overlaps(const TextureSubresourceInfo& rhs) const
91 {
92 return ((this->bits & rhs.bits) != 0) && (this->mip <= rhs.mip && this->mip + this->mipCount >= rhs.mip) && (this->layer <= rhs.layer && this->layer + this->layerCount >= rhs.layer);
93 }
94};
95
97{
99
104
109
110 const bool Overlaps(const BufferSubresourceInfo& rhs) const
111 {
112 return (this->offset <= rhs.offset && this->offset + this->size >= rhs.offset);
113 }
114};
115
123
132
138
144
158
160{
163 {
164 n_assert(this->textures.IsEmpty());
165 n_assert(this->buffers.IsEmpty());
166 }
167
169 void Init(const char* name, CmdBufferId cmdBuf)
170 {
171 this->name = name;
172 this->cmdBuf = cmdBuf;
175 }
176
179 {
180 // If the barrier boundaries don't match, flush the barriers
181 if (this->fromStage != fromStage || this->toStage != toStage)
182 {
183 this->Flush();
184 this->fromStage = fromStage;
185 this->toStage = toStage;
186 }
187 TextureBarrierInfo info = { .tex = tex, .subres = TextureSubresourceInfo::Texture(bits, tex) };
188 textures.Append(info);
189 }
190
193 {
194 // If the barrier boundaries don't match, flush the barriers
195 if (this->fromStage != fromStage || this->toStage != toStage)
196 {
197 this->Flush();
198 this->fromStage = fromStage;
199 this->toStage = toStage;
200 }
201 BufferBarrierInfo info = { .buf = buf, .subres = CoreGraphics::BufferSubresourceInfo() };
202 buffers.Append(info);
203 }
204
206 void Flush()
207 {
208 if (!this->textures.IsEmpty())
210 if (!this->buffers.IsEmpty())
212 this->buffers.Clear();
213 this->textures.Clear();
214 }
215
216 const char* name;
221
222private:
223
224};
225
237
241void DestroyBarrier(const BarrierId id);
242
244void BarrierReset(const BarrierId id);
245
247void BarrierPush(
255void BarrierPush(
262void BarrierPush(
272
273
274//------------------------------------------------------------------------------
279{
280 Util::Array<Util::String> comps = str.Tokenize("|");
282 for (IndexT i = 0; i < comps.Size(); i++)
283 {
284 if (comps[i] == "Auto") { bits = CoreGraphics::ImageBits::Auto; break; }
285 else if (comps[i] == "Color") bits |= CoreGraphics::ImageBits::ColorBits;
286 else if (comps[i] == "Depth") bits |= CoreGraphics::ImageBits::DepthBits;
287 else if (comps[i] == "Stencil") bits |= CoreGraphics::ImageBits::StencilBits;
288 else if (comps[i] == "Metadata") bits |= CoreGraphics::ImageBits::MetaBits;
289 else if (comps[i] == "Plane0") bits |= CoreGraphics::ImageBits::Plane0Bits;
290 else if (comps[i] == "Plane1") bits |= CoreGraphics::ImageBits::Plane1Bits;
291 else if (comps[i] == "Plane2") bits |= CoreGraphics::ImageBits::Plane2Bits;
292
293 else
294 {
295 n_error("Invalid access string '%s'\n", comps[i].AsCharPtr());
297 }
298 }
299 return bits;
300}
301
302//------------------------------------------------------------------------------
307{
308 if (str == "Undefined") return CoreGraphics::ImageLayout::Undefined;
309 else if (str == "General") return CoreGraphics::ImageLayout::General;
310 else if (str == "ColorRenderTexture") return CoreGraphics::ImageLayout::ColorRenderTexture;
311 else if (str == "DepthRenderTexture") return CoreGraphics::ImageLayout::DepthStencilRenderTexture;
312 else if (str == "DepthStencilRead") return CoreGraphics::ImageLayout::DepthStencilRead;
313 else if (str == "ShaderRead") return CoreGraphics::ImageLayout::ShaderRead;
314 else if (str == "TransferSource") return CoreGraphics::ImageLayout::TransferSource;
315 else if (str == "TransferDestination") return CoreGraphics::ImageLayout::TransferDestination;
316 else if (str == "Preinitialized") return CoreGraphics::ImageLayout::Preinitialized;
317 else if (str == "Present") return CoreGraphics::ImageLayout::Present;
319}
320} // namespace CoreGraphics
Nebula's dynamic array class.
Definition array.h:60
const SizeT Size() const
get number of elements in array
Definition array.h:880
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
A StringAtom.
Definition stringatom.h:22
void __cdecl n_error(const char *msg,...)
This function is called when a serious situation is encountered which requires abortion of the applic...
Definition debug.cc:138
#define n_assert(exp)
Definition debug.h:50
#define ID_24_8_TYPE(x)
Definition id.h:132
Acceleration structures are used to enable ray tracing on the GPU by dividing the scene into a BVH.
Definition accelerationstructure.h:24
void BarrierPop(const CoreGraphics::CmdBufferId buf)
pop barrier, reverses the from-to stages and any access flags in the buffers and texture barriers
Definition vkbarrier.cc:255
ImageLayout
Definition config.h:97
void BarrierReset(const BarrierId id)
reset resources previously set in barrier
Definition vkbarrier.cc:152
void BarrierRepeat(const CoreGraphics::CmdBufferId buf)
repeat barrier in queue
Definition vkbarrier.cc:268
QueueType
Definition config.h:40
void DestroyBarrier(const BarrierId id)
destroy barrier object
Definition vkbarrier.cc:143
ImageBits
Definition config.h:82
BarrierId CreateBarrier(const BarrierCreateInfo &info)
create barrier object
Definition vkbarrier.cc:39
BarrierDomain
Definition config.h:185
void BarrierPush(const CoreGraphics::CmdBufferId buf, CoreGraphics::PipelineStage fromStage, CoreGraphics::PipelineStage toStage, CoreGraphics::BarrierDomain domain, const Util::FixedArray< TextureBarrierInfo, true > &textures, const Util::FixedArray< BufferBarrierInfo, true > &buffers)
Push barrier to stack.
Definition vkbarrier.cc:179
PipelineStage
Definition config.h:191
void CmdBarrier(const CmdBufferId id, CoreGraphics::PipelineStage fromStage, CoreGraphics::PipelineStage toStage, CoreGraphics::BarrierDomain domain, const Util::FixedArray< TextureBarrierInfo, true > &textures, const IndexT fromQueue, const IndexT toQueue, const char *name)
Insert pipeline barrier.
Definition commandbuffer.cc:14
CoreGraphics::ImageBits ImageBitsFromString(const Util::String &str)
Definition barrier.h:278
CoreGraphics::ImageLayout ImageLayoutFromString(const Util::String &str)
Definition barrier.h:306
Compile time configuration options for the CoreGraphics subsystem.
#define NEBULA_ALL_MIPS
Definition config.h:17
#define NEBULA_WHOLE_BUFFER_SIZE
Definition config.h:16
#define NEBULA_ALL_LAYERS
Definition config.h:18
BlasId blas
Definition barrier.h:147
~AccelerationStructureBarrierInfo()
Definition barrier.h:156
enum CoreGraphics::AccelerationStructureBarrierInfo::@113 type
TlasId tlas
Definition barrier.h:148
Definition barrier.h:227
BarrierDomain domain
Definition barrier.h:229
Util::Array< BufferBarrierInfo > buffers
Definition barrier.h:235
CoreGraphics::QueueType fromQueue
Definition barrier.h:232
CoreGraphics::QueueType toQueue
Definition barrier.h:233
Util::StringAtom name
Definition barrier.h:228
CoreGraphics::PipelineStage toStage
Definition barrier.h:231
CoreGraphics::PipelineStage fromStage
Definition barrier.h:230
Util::Array< TextureBarrierInfo > textures
Definition barrier.h:234
Definition barrier.h:21
Definition barrier.h:160
Util::Array< TextureBarrierInfo > textures
Definition barrier.h:219
CmdBufferId cmdBuf
Definition barrier.h:217
CoreGraphics::PipelineStage fromStage
Definition barrier.h:218
Util::Array< BufferBarrierInfo > buffers
Definition barrier.h:220
~BarrierScope()
Make sure we have cleared the barrier scope before destroying the object.
Definition barrier.h:162
CoreGraphics::PipelineStage toStage
Definition barrier.h:218
void AddTexture(ImageBits bits, TextureId tex, CoreGraphics::PipelineStage fromStage, CoreGraphics::PipelineStage toStage)
Add texture barrier.
Definition barrier.h:178
void Init(const char *name, CmdBufferId cmdBuf)
Initiate.
Definition barrier.h:169
void Flush()
Flush all pending changes.
Definition barrier.h:206
const char * name
Definition barrier.h:216
void AddBuffer(BufferId buf, CoreGraphics::PipelineStage fromStage, CoreGraphics::PipelineStage toStage)
Add buffer barrier.
Definition barrier.h:192
Definition accelerationstructure.h:48
Definition barrier.h:125
BufferId buf
Definition barrier.h:126
SizeT size
Definition barrier.h:130
CoreGraphics::PipelineStage fromStage
Definition barrier.h:127
CoreGraphics::PipelineStage toStage
Definition barrier.h:128
IndexT offset
Definition barrier.h:129
Definition barrier.h:140
BufferSubresourceInfo subres
Definition barrier.h:142
BufferId buf
Definition barrier.h:141
Definition buffer.h:23
uint offset
Definition barrier.h:98
BufferSubresourceInfo(uint offset, uint size)
Definition barrier.h:105
BufferSubresourceInfo()
Definition barrier.h:100
const bool Overlaps(const BufferSubresourceInfo &rhs) const
Definition barrier.h:110
uint size
Definition barrier.h:98
Definition commandbuffer.h:155
Definition barrier.h:117
CoreGraphics::PipelineStage toStage
Definition barrier.h:121
TextureId tex
Definition barrier.h:118
TextureSubresourceInfo subres
Definition barrier.h:119
CoreGraphics::PipelineStage fromStage
Definition barrier.h:120
Definition barrier.h:134
TextureId tex
Definition barrier.h:135
TextureSubresourceInfo subres
Definition barrier.h:136
texture type
Definition texture.h:25
static TextureSubresourceInfo Color(TextureId tex)
Definition barrier.h:50
static TextureSubresourceInfo ColorNoMipNoLayer()
Definition barrier.h:60
TextureSubresourceInfo()
Definition barrier.h:29
static TextureSubresourceInfo DepthStencilNoLayer(uint mipCount)
Definition barrier.h:85
uint layerCount
Definition barrier.h:27
TextureSubresourceInfo(CoreGraphics::ImageBits bits, uint mip, uint mipCount, uint layer, uint layerCount)
Definition barrier.h:37
ImageBits bits
Definition barrier.h:26
uint mipCount
Definition barrier.h:27
const bool Overlaps(const TextureSubresourceInfo &rhs) const
Definition barrier.h:90
uint mip
Definition barrier.h:27
static TextureSubresourceInfo DepthStencilNoMip(uint layerCount)
Definition barrier.h:80
static TextureSubresourceInfo ColorNoMip(uint layerCount)
Definition barrier.h:65
static TextureSubresourceInfo Texture(CoreGraphics::ImageBits bits, TextureId tex)
Definition barrier.h:45
static TextureSubresourceInfo DepthStencil(TextureId tex)
Definition barrier.h:55
static TextureSubresourceInfo ColorNoLayer(uint mipCount)
Definition barrier.h:70
uint layer
Definition barrier.h:27
static TextureSubresourceInfo DepthStencilNoMipNoLayer()
Definition barrier.h:75
Definition accelerationstructure.h:98
Nebula's universal string class.
Definition string.h:50
SizeT Tokenize(const String &whiteSpace, Array< String > &outTokens) const
tokenize string into a provided String array (faster if tokens array can be reused)
Definition string.cc:203
static const int InvalidIndex
Definition types.h:54
int SizeT
Definition types.h:49
unsigned int uint
Definition types.h:31
int IndexT
Definition types.h:48