Skip to content

Commit b0c9e09

Browse files
try out barrier construction utils
1 parent 00d3a1a commit b0c9e09

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

include/nbl/asset/ECommonEnums.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,15 @@ NBL_ENUM_ADD_BITWISE_OPERATORS(ACCESS_FLAGS)
145145

146146
struct SMemoryBarrier
147147
{
148+
// TODO: pack these up into just `src` and `dst` with another struct
148149
core::bitflag<PIPELINE_STAGE_FLAGS> srcStageMask = PIPELINE_STAGE_FLAGS::NONE;
149150
core::bitflag<ACCESS_FLAGS> srcAccessMask = ACCESS_FLAGS::NONE;
150151
core::bitflag<PIPELINE_STAGE_FLAGS> dstStageMask = PIPELINE_STAGE_FLAGS::NONE;
151152
core::bitflag<ACCESS_FLAGS> dstAccessMask = ACCESS_FLAGS::NONE;
152153

153154
auto operator<=>(const SMemoryBarrier&) const = default;
154155

155-
// utilities
156+
// Make the immediately previous barrier after this one
156157
inline SMemoryBarrier prevBarrier(const core::bitflag<PIPELINE_STAGE_FLAGS> prevStageMask, const core::bitflag<ACCESS_FLAGS> prevAccessMask) const
157158
{
158159
return {
@@ -162,6 +163,12 @@ struct SMemoryBarrier
162163
.dstAccessMask = srcAccessMask
163164
};
164165
}
166+
// Make the immediately previous barrier if you know the penultimate, as in one before the last (previous)
167+
inline SMemoryBarrier prevBarrier(const SMemoryBarrier& penultimate) const
168+
{
169+
return prevBarrier(penultimate.dstStageMask,penultimate.dstAccessMask);
170+
}
171+
// Make the immediately next barrier after this one
165172
inline SMemoryBarrier nextBarrier(const core::bitflag<PIPELINE_STAGE_FLAGS> nextStageMask, const core::bitflag<ACCESS_FLAGS> nextAccessMask) const
166173
{
167174
return {
@@ -171,6 +178,11 @@ struct SMemoryBarrier
171178
.dstAccessMask = nextAccessMask
172179
};
173180
}
181+
// Make the immediately next barrier, if you know the barrier thats after the immediately next one
182+
inline SMemoryBarrier nextBarrier(const SMemoryBarrier& twoAhead) const
183+
{
184+
return prevBarrier(twoAhead.srcStageMask,twoAhead.srcAccessMask);
185+
}
174186
};
175187

176188
inline core::bitflag<ACCESS_FLAGS> allAccessesFromStages(core::bitflag<PIPELINE_STAGE_FLAGS> stages)

src/nbl/video/utilities/ISimpleManagedSurface.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,7 @@ bool ISimpleManagedSurface::immediateBlit(const image_barrier_t& contents, IQueu
122122
// When transitioning the image to VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR or VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, there is no need to delay subsequent processing,
123123
// or perform any visibility operations (as vkQueuePresentKHR performs automatic visibility operations).
124124
// To achieve this, the dstAccessMask member of the VkImageMemoryBarrier should be set to 0, and the dstStageMask parameter should be set to VK_PIPELINE_STAGE_2_NONE
125-
.dep = {
126-
.srcStageMask = preBarriers[0].barrier.dep.dstStageMask,
127-
.srcAccessMask = preBarriers[0].barrier.dep.dstAccessMask,
128-
.dstStageMask = asset::PIPELINE_STAGE_FLAGS::NONE, // Present isn't a stage
129-
.dstAccessMask = asset::ACCESS_FLAGS::NONE // it doesn't perform accesses known to VK
130-
}
125+
.dep = preBarriers[0].barrier.dep.nextBarrier(asset::PIPELINE_STAGE_FLAGS::NONE,asset::ACCESS_FLAGS::NONE)
131126
},
132127
.image = preBarriers[0].image,
133128
.subresourceRange = preBarriers[0].subresourceRange,
@@ -136,12 +131,7 @@ bool ISimpleManagedSurface::immediateBlit(const image_barrier_t& contents, IQueu
136131
},
137132
{
138133
.barrier = {
139-
.dep = {
140-
.srcStageMask = preBarriers[1].barrier.dep.dstStageMask,
141-
.srcAccessMask = preBarriers[1].barrier.dep.dstAccessMask,
142-
.dstStageMask = contents.barrier.dep.dstStageMask,
143-
.dstAccessMask = contents.barrier.dep.dstAccessMask
144-
},
134+
.dep = preBarriers[1].barrier.dep.nextBarrier(contents.barrier.dep.dstStageMask,contents.barrier.dep.dstAccessMask),
145135
.ownershipOp = IGPUCommandBuffer::SOwnershipTransferBarrier::OWNERSHIP_OP::RELEASE,
146136
.otherQueueFamilyIndex = contents.barrier.otherQueueFamilyIndex
147137
},

0 commit comments

Comments
 (0)