Skip to content

Commit 570c3cc

Browse files
committed
[62.CAD] test and fixes to clipProj stack push/pop in gpu and overflow
1 parent 88d5cfb commit 570c3cc

File tree

2 files changed

+109
-17
lines changed

2 files changed

+109
-17
lines changed

62_CAD/DrawBuffers.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void DrawBuffersFiller::allocateIndexBuffer(ILogicalDevice* logicalDevice, uint3
4545
void DrawBuffersFiller::allocateMainObjectsBuffer(ILogicalDevice* logicalDevice, uint32_t mainObjects)
4646
{
4747
maxMainObjects = mainObjects;
48-
size_t mainObjectsBufferSize = mainObjects * sizeof(MainObject);
48+
size_t mainObjectsBufferSize = maxMainObjects * sizeof(MainObject);
4949

5050
IGPUBuffer::SCreationParams mainObjectsCreationParams = {};
5151
mainObjectsCreationParams.size = mainObjectsBufferSize;
@@ -257,6 +257,8 @@ uint32_t DrawBuffersFiller::addMainObject_SubmitIfNeeded(uint32_t styleIdx, SInt
257257
resetGeometryCounters();
258258
// mainObjects needs to be reset because we submitted every previous main object
259259
resetMainObjectCounters();
260+
// we shouldn't reset linestyles and clip projections here because it was possibly requested to push to mem before addMainObjects
261+
// but clip projections are reset due to geometry/bda buffer being reset so we need to push again
260262

261263
// 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
262264
mainObject.clipProjectionAddress = acquireCurrentClipProjectionAddress(intendedNextSubmit);
@@ -275,6 +277,9 @@ void DrawBuffersFiller::pushClipProjectionData(const ClipProjectionData& clipPro
275277

276278
void DrawBuffersFiller::popClipProjectionData()
277279
{
280+
if (clipProjections.empty())
281+
return;
282+
278283
clipProjections.pop();
279284
clipProjectionAddresses.pop_back();
280285
}
@@ -343,8 +348,11 @@ void DrawBuffersFiller::submitCurrentObjectsAndReset(SIntendedSubmitInfo& intend
343348
uint32_t DrawBuffersFiller::addMainObject_Internal(const MainObject& mainObject)
344349
{
345350
MainObject* mainObjsArray = reinterpret_cast<MainObject*>(cpuDrawBuffers.mainObjectsBuffer->getPointer());
351+
346352
if (currentMainObjectCount >= MaxIndexableMainObjects)
347353
return InvalidMainObjectIdx;
354+
if (currentMainObjectCount >= maxMainObjects)
355+
return InvalidMainObjectIdx;
348356

349357
void* dst = mainObjsArray + currentMainObjectCount;
350358
memcpy(dst, &mainObject, sizeof(MainObject));

62_CAD/main.cpp

Lines changed: 100 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ enum class ExampleMode
3838
CASE_3, // CURVES AND LINES
3939
CASE_4, // STIPPLE PATTERN
4040
CASE_5, // Advanced Styling
41+
CASE_6, // Custom Clip Projections
4142
};
4243

43-
constexpr ExampleMode mode = ExampleMode::CASE_2;
44+
constexpr ExampleMode mode = ExampleMode::CASE_6;
4445

4546
class Camera2D
4647
{
@@ -1091,15 +1092,13 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
10911092
if (!inBetweenSubmit)
10921093
cb->endDebugMarker();
10931094

1094-
cb->end();
1095-
10961095
if (inBetweenSubmit)
10971096
{
10981097
intendedSubmitInfo.overflowSubmit();
1099-
drawBuffer.reset();
11001098
}
11011099
else
11021100
{
1101+
cb->end();
11031102
IQueue::SSubmitInfo submitInfo = static_cast<IQueue::SSubmitInfo>(intendedSubmitInfo);
11041103
if (getGraphicsQueue()->submit({ &submitInfo, 1u }) == IQueue::RESULT::SUCCESS)
11051104
{
@@ -1650,16 +1649,6 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
16501649
}
16511650
else if (mode == ExampleMode::CASE_4)
16521651
{
1653-
ClipProjectionData newClipProj = {};
1654-
newClipProj.projectionToNDC = m_Camera.constructViewProjection();
1655-
newClipProj.minClipNDC = float32_t2(0.0, -1.0);
1656-
newClipProj.maxClipNDC = float32_t2(+1.0, +1.0);
1657-
drawBuffer.pushClipProjectionData(newClipProj);
1658-
drawBuffer.pushClipProjectionData(newClipProj);
1659-
newClipProj.minClipNDC = float32_t2(-1.0, -1.0);
1660-
newClipProj.maxClipNDC = float32_t2(+1.0, +0.5);
1661-
drawBuffer.pushClipProjectionData(newClipProj);
1662-
16631652
constexpr uint32_t CURVE_CNT = 16u;
16641653
constexpr uint32_t SPECIAL_CASE_CNT = 6u;
16651654

@@ -1806,8 +1795,6 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
18061795

18071796
for (uint32_t i = 0u; i < CURVE_CNT; i++)
18081797
drawBuffer.drawPolyline(polylines[i], lineStyleInfos[i], intendedNextSubmit);
1809-
1810-
drawBuffer.popClipProjectionData();
18111798
}
18121799
else if (mode == ExampleMode::CASE_5)
18131800
{
@@ -2367,6 +2354,103 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
23672354

23682355
#endif
23692356

2357+
}
2358+
else if (mode == ExampleMode::CASE_6)
2359+
{
2360+
// left half of screen should be red and right half should be green
2361+
const auto& cameraProj = m_Camera.constructViewProjection();
2362+
ClipProjectionData showLeft = {};
2363+
showLeft.projectionToNDC = cameraProj;
2364+
showLeft.minClipNDC = float32_t2(-1.0, -1.0);
2365+
showLeft.maxClipNDC = float32_t2(0.0, +1.0);
2366+
ClipProjectionData showRight = {};
2367+
showRight.projectionToNDC = cameraProj;
2368+
showRight.minClipNDC = float32_t2(0.0, -1.0);
2369+
showRight.maxClipNDC = float32_t2(+1.0, +1.0);
2370+
2371+
LineStyleInfo leftLineStyle = {};
2372+
leftLineStyle.screenSpaceLineWidth = 3.0f;
2373+
leftLineStyle.worldSpaceLineWidth = 0.0f;
2374+
leftLineStyle.color = float32_t4(1.0f, 0.1f, 0.1f, 0.9f);
2375+
leftLineStyle.isRoadStyleFlag = false;
2376+
LineStyleInfo rightLineStyle = {};
2377+
rightLineStyle.screenSpaceLineWidth = 6.0f;
2378+
rightLineStyle.worldSpaceLineWidth = 0.0f;
2379+
rightLineStyle.color = float32_t4(0.1f, 1.0f, 0.1f, 0.9f);
2380+
rightLineStyle.isRoadStyleFlag = false;
2381+
2382+
CPolyline polyline3;
2383+
{
2384+
std::vector<float64_t2> linePoints;
2385+
linePoints.push_back({ -20.0, 20.0 });
2386+
linePoints.push_back({ 20.0, 70.0 });
2387+
linePoints.push_back({ 20.0, -40.0 });
2388+
polyline3.addLinePoints(linePoints);
2389+
}
2390+
CPolyline polyline1;
2391+
{
2392+
std::vector<float64_t2> linePoints;
2393+
linePoints.push_back({ -20.0, 0.0 });
2394+
linePoints.push_back({ -20.0, 50.0 });
2395+
linePoints.push_back({ 20.0, 0.0 });
2396+
linePoints.push_back({ 20.0, 50.0 });
2397+
polyline1.addLinePoints(linePoints);
2398+
}
2399+
CPolyline polyline2;
2400+
{
2401+
2402+
std::vector<shapes::QuadraticBezier<double>> quadBeziers;
2403+
curves::EllipticalArcInfo myCurve;
2404+
{
2405+
myCurve.majorAxis = { 20.0, 0.0 };
2406+
myCurve.center = { 0.0, -25.0 };
2407+
myCurve.angleBounds = {
2408+
nbl::core::PI<double>() * 0.0,
2409+
nbl::core::PI<double>() * 2.0
2410+
};
2411+
myCurve.eccentricity = 1.0;
2412+
}
2413+
2414+
curves::Subdivision::AddBezierFunc addToBezier = [&](shapes::QuadraticBezier<double>&& info) -> void
2415+
{
2416+
quadBeziers.push_back(info);
2417+
};
2418+
2419+
curves::Subdivision::adaptive(myCurve, 1e-3, addToBezier, 10u);
2420+
polyline2.addQuadBeziers(quadBeziers);
2421+
}
2422+
2423+
// we do redundant and nested push/pops to test
2424+
drawBuffer.pushClipProjectionData(showLeft);
2425+
{
2426+
drawBuffer.drawPolyline(polyline1, leftLineStyle, intendedNextSubmit);
2427+
2428+
drawBuffer.pushClipProjectionData(showRight);
2429+
{
2430+
drawBuffer.drawPolyline(polyline1, rightLineStyle, intendedNextSubmit);
2431+
drawBuffer.drawPolyline(polyline2, rightLineStyle, intendedNextSubmit);
2432+
}
2433+
drawBuffer.popClipProjectionData();
2434+
2435+
drawBuffer.drawPolyline(polyline2, leftLineStyle, intendedNextSubmit);
2436+
2437+
drawBuffer.pushClipProjectionData(showRight);
2438+
{
2439+
drawBuffer.drawPolyline(polyline3, rightLineStyle, intendedNextSubmit);
2440+
drawBuffer.drawPolyline(polyline2, rightLineStyle, intendedNextSubmit);
2441+
2442+
drawBuffer.pushClipProjectionData(showLeft);
2443+
{
2444+
drawBuffer.drawPolyline(polyline1, leftLineStyle, intendedNextSubmit);
2445+
}
2446+
drawBuffer.popClipProjectionData();
2447+
}
2448+
drawBuffer.popClipProjectionData();
2449+
2450+
drawBuffer.drawPolyline(polyline2, leftLineStyle, intendedNextSubmit);
2451+
}
2452+
drawBuffer.popClipProjectionData();
2453+
23702454
}
23712455

23722456
drawBuffer.finalizeAllCopiesToGPU(intendedNextSubmit);

0 commit comments

Comments
 (0)