Skip to content

Commit 88d5cfb

Browse files
committed
[62.CAD] made the clipProjAddresses a stack/deque too, to revive the prev address after pop when there is no auto-submission+reset
1 parent a9ad4b2 commit 88d5cfb

File tree

3 files changed

+124
-125
lines changed

3 files changed

+124
-125
lines changed

62_CAD/DrawBuffers.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,13 @@ void DrawBuffersFiller::drawHatch(
178178
/* something that gets you the texture id */
179179
SIntendedSubmitInfo& intendedNextSubmit)
180180
{
181+
// TODO[Optimization Idea]: don't draw hatch twice if both colors are visible: instead do the msdf inside the alpha resolve by detecting mainObj being a hatch
182+
// https://discord.com/channels/593902898015109131/856835291712716820/1228337893366300743
183+
// TODO: Come back to this idea when doing color resolve for ecws (they don't have mainObj/style Index, instead they have uv into a texture
184+
185+
// if backgroundColor is visible
181186
drawHatch(hatch, backgroundColor /* , invalid texture id to get solid fill */, intendedNextSubmit);
187+
// if foregroundColor is visible
182188
// drawHatch(hatch, foregroundColor, /* valid texture id to get foreground pattern msdf fill */, intendedNextSubmit);
183189
}
184190

@@ -240,7 +246,7 @@ uint32_t DrawBuffersFiller::addMainObject_SubmitIfNeeded(uint32_t styleIdx, SInt
240246
{
241247
MainObject mainObject = {};
242248
mainObject.styleIdx = styleIdx;
243-
mainObject.clipProjectionAddress = getCurrentClipProjectionAddress(intendedNextSubmit);
249+
mainObject.clipProjectionAddress = acquireCurrentClipProjectionAddress(intendedNextSubmit);
244250
uint32_t outMainObjectIdx = addMainObject_Internal(mainObject);
245251
if (outMainObjectIdx == InvalidMainObjectIdx)
246252
{
@@ -251,8 +257,9 @@ uint32_t DrawBuffersFiller::addMainObject_SubmitIfNeeded(uint32_t styleIdx, SInt
251257
resetGeometryCounters();
252258
// mainObjects needs to be reset because we submitted every previous main object
253259
resetMainObjectCounters();
254-
// getCurrentClipProjectionAddress again here because clip projection exists in the geometry buffer, and reseting geometry counters will invalidate the current clip proj and requires repush
255-
mainObject.clipProjectionAddress = getCurrentClipProjectionAddress(intendedNextSubmit);
260+
261+
// acquireCurrentClipProjectionAddress again here because clip projection should exist in the geometry buffer, and reseting geometry counters will invalidate the current clip proj and requires repush
262+
mainObject.clipProjectionAddress = acquireCurrentClipProjectionAddress(intendedNextSubmit);
256263
outMainObjectIdx = addMainObject_Internal(mainObject);
257264
assert(outMainObjectIdx != InvalidMainObjectIdx);
258265
}
@@ -262,12 +269,14 @@ uint32_t DrawBuffersFiller::addMainObject_SubmitIfNeeded(uint32_t styleIdx, SInt
262269

263270
void DrawBuffersFiller::pushClipProjectionData(const ClipProjectionData& clipProjectionData)
264271
{
265-
clipProjectionStack.push(clipProjectionData);
272+
clipProjections.push(clipProjectionData);
273+
clipProjectionAddresses.push_back(InvalidClipProjectionAddress);
266274
}
267275

268276
void DrawBuffersFiller::popClipProjectionData()
269277
{
270-
clipProjectionStack.pop();
278+
clipProjections.pop();
279+
clipProjectionAddresses.pop_back();
271280
}
272281

273282
void DrawBuffersFiller::finalizeMainObjectCopiesToGPU(SIntendedSubmitInfo& intendedNextSubmit)
@@ -320,13 +329,13 @@ void DrawBuffersFiller::submitCurrentObjectsAndReset(SIntendedSubmitInfo& intend
320329
// We don't reset counters for styles because we will be reusing them
321330
resetGeometryCounters();
322331

323-
uint32_t newClipProjectionAddress = getCurrentClipProjectionAddress(intendedNextSubmit);
332+
uint32_t newClipProjectionAddress = acquireCurrentClipProjectionAddress(intendedNextSubmit);
324333
// If there clip projection stack is non-empty, then it means we need to re-push the clipProjectionData (because it exists in geometry data)
325334
if (newClipProjectionAddress != InvalidClipProjectionAddress)
326335
{
327336
// then modify the mainObject data
328337
getMainObject(mainObjectIndex)->clipProjectionAddress = newClipProjectionAddress;
329-
// we need to modify inMemMainObjectCount to this mainObjIndex so it re-uploads the current mainObject (because we modified it)
338+
// we need to rewind back inMemMainObjectCount to this mainObjIndex so it re-uploads the current mainObject (because we modified it)
330339
inMemMainObjectCount = min(inMemMainObjectCount, mainObjectIndex);
331340
}
332341
}
@@ -365,11 +374,15 @@ uint32_t DrawBuffersFiller::addLineStyle_Internal(const LineStyleInfo& lineStyle
365374
return currentLineStylesCount++;
366375
}
367376

368-
inline uint64_t DrawBuffersFiller::getCurrentClipProjectionAddress(SIntendedSubmitInfo& intendedNextSubmit)
377+
inline uint64_t DrawBuffersFiller::acquireCurrentClipProjectionAddress(SIntendedSubmitInfo& intendedNextSubmit)
369378
{
370-
if (clipProjectionStackTopAddressInGPU == InvalidClipProjectionAddress && !clipProjectionStack.empty())
371-
clipProjectionStackTopAddressInGPU = addClipProjectionData_SubmitIfNeeded(clipProjectionStack.top(), intendedNextSubmit);
372-
return clipProjectionStackTopAddressInGPU;
379+
if (clipProjectionAddresses.empty())
380+
return InvalidClipProjectionAddress;
381+
382+
if (clipProjectionAddresses.back() == InvalidClipProjectionAddress)
383+
clipProjectionAddresses.back() = addClipProjectionData_SubmitIfNeeded(clipProjections.top(), intendedNextSubmit);
384+
385+
return clipProjectionAddresses.back();
373386
}
374387

375388
uint64_t DrawBuffersFiller::addClipProjectionData_SubmitIfNeeded(const ClipProjectionData& clipProjectionData, SIntendedSubmitInfo& intendedNextSubmit)

62_CAD/DrawBuffers.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct DrawBuffersFiller
137137

138138
// Gets the current clip projection data (the top of stack) gpu addreess inside the geometryBuffer
139139
// If it's been invalidated then it will request to upload again with a possible auto-submit on low geometry buffer memory.
140-
uint64_t getCurrentClipProjectionAddress(SIntendedSubmitInfo& intendedNextSubmit);
140+
uint64_t acquireCurrentClipProjectionAddress(SIntendedSubmitInfo& intendedNextSubmit);
141141

142142
uint64_t addClipProjectionData_SubmitIfNeeded(const ClipProjectionData& clipProjectionData, SIntendedSubmitInfo& intendedNextSubmit);
143143

@@ -176,7 +176,9 @@ struct DrawBuffersFiller
176176
inMemGeometryBufferSize = 0u;
177177
currentGeometryBufferSize = 0u;
178178

179-
clipProjectionStackTopAddressInGPU = InvalidClipProjectionAddress;
179+
// Invalidate all the clip projection addresses because geometry buffer got reset
180+
for (auto& clipProjAddr : clipProjectionAddresses)
181+
clipProjAddr = InvalidClipProjectionAddress;
180182
}
181183

182184
void resetLineStyleCounters()
@@ -214,6 +216,6 @@ struct DrawBuffersFiller
214216

215217
uint64_t geometryBufferAddress = 0u; // Actual BDA offset 0 of the gpu buffer
216218

217-
std::stack<ClipProjectionData> clipProjectionStack;
218-
uint64_t clipProjectionStackTopAddressInGPU = InvalidClipProjectionAddress;
219+
std::stack<ClipProjectionData> clipProjections; // stack of clip projectios stored so we can resubmit them if geometry buffer got reset.
220+
std::deque<uint64_t> clipProjectionAddresses; // stack of clip projection gpu addresses in geometry buffer. to keep track of them in push/pops
219221
};

0 commit comments

Comments
 (0)