Skip to content

CAD DTM Rendering #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 95 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
f098335
DTM setup
Przemog1 Feb 26, 2025
8058cff
Simple triangle draw
Przemog1 Feb 27, 2025
03faeed
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla-…
Przemog1 Mar 7, 2025
2b07a42
Barycentrics
Przemog1 Mar 8, 2025
0232ee8
Drawing triangle sdf
Przemog1 Mar 13, 2025
83d8de4
Added dtmSettingsBuff
Przemog1 Mar 14, 2025
d4647d5
Added `finalizeDTMSettingsCopiesToGPU` function
Przemog1 Mar 14, 2025
16951a3
Stippled outline
Przemog1 Mar 19, 2025
a215f45
Contour drawing setup
Przemog1 Mar 20, 2025
8900f9c
Implemented height shading
Przemog1 Mar 26, 2025
5a87097
Fixes
Przemog1 Mar 26, 2025
3237e4b
Implemented transparent height shading
Przemog1 Mar 26, 2025
78c716c
Fixes
Przemog1 Mar 27, 2025
10791e9
Implemented anty aliasing between height shading sections
Przemog1 Mar 29, 2025
1d9e6d0
switch from dtm to good'ol linework
Erfan-Ahmadi Mar 30, 2025
ad43e20
[WIP] putting all data into a single buffer and addressing with BDA
Erfan-Ahmadi Mar 31, 2025
cf63282
[WIP] save work
Erfan-Ahmadi Mar 31, 2025
d776d24
[WIP] add getMinimumRequiredResourcesBufferSize function, still not c…
Erfan-Ahmadi Mar 31, 2025
4dc28d5
[WIP] more drawResource auto-submission logic fixes
Erfan-Ahmadi Apr 1, 2025
2abd6b9
compiles but probably has runtime errors
Erfan-Ahmadi Apr 1, 2025
ab8f303
[62.CAD] compile error fix
Erfan-Ahmadi Apr 1, 2025
8f2ae9c
small shader fixes
Erfan-Ahmadi Apr 1, 2025
97b1693
more fixes
Erfan-Ahmadi Apr 1, 2025
7636062
fixes to cad example
Erfan-Ahmadi Apr 2, 2025
eec41cb
fixed hatches and polyline connector's auto submission logic
Erfan-Ahmadi Apr 2, 2025
692df5f
fix glyph and image auto-submission logic
Erfan-Ahmadi Apr 2, 2025
cf05dca
Fix ClipProjectionIndices reset
Erfan-Ahmadi Apr 2, 2025
3304cde
auto-submission more mature, corrects resource references on the go b…
Erfan-Ahmadi Apr 2, 2025
e7b63ee
small fix
Erfan-Ahmadi Apr 2, 2025
468dab1
another small fix
Erfan-Ahmadi Apr 2, 2025
bb793be
[temp] lower mem to test auto-submit
Erfan-Ahmadi Apr 2, 2025
bcb5fa3
fixed linestyle index fetching
Erfan-Ahmadi Apr 2, 2025
da76699
fixed acquireMainObjectIndex
Erfan-Ahmadi Apr 2, 2025
ed920b0
Fix DTM Rendering
Erfan-Ahmadi Apr 2, 2025
9d23afd
Fixed auto-submission bug with self-blending in a beautiful and simpl…
Erfan-Ahmadi Apr 3, 2025
126afa8
updates to comments regarding auto-submit
Erfan-Ahmadi Apr 3, 2025
6830c08
update TODO, need to handle it, after figuring out compute stages and…
Erfan-Ahmadi Apr 3, 2025
416d7b3
Saving work
Przemog1 Apr 4, 2025
b4f941a
Merge pull request #189 from Devsh-Graphics-Programming/gpu_driven_cad
Przemog1 Apr 4, 2025
06f72c5
Fixed anti aliasing
Przemog1 Apr 8, 2025
e4e7f1e
multiple draw calls to allow dtms and linework simultaneously.
Erfan-Ahmadi Apr 10, 2025
2528e75
Implemented anti aliasing
Przemog1 Apr 11, 2025
fd4e576
Triangle dilation
Przemog1 Apr 12, 2025
6c907e4
Added few todos
Przemog1 Apr 14, 2025
f173c71
Refactor
Przemog1 Apr 14, 2025
1db627c
Fix DISCRETE_FIXED_LENGTH_INTERVALS + Refactors
Erfan-Ahmadi Apr 15, 2025
432b931
clear function for Mesh
Erfan-Ahmadi Apr 15, 2025
88dcf44
Fixed non-stippled lines
Przemog1 Apr 15, 2025
9064439
getIntervalHeightAndColor small fix
Erfan-Ahmadi Apr 15, 2025
9707b33
Separated DTMSettingsInfo struct
Przemog1 Apr 15, 2025
fdbf20c
Fixes
Przemog1 Apr 17, 2025
c865357
Saving work
Przemog1 Apr 19, 2025
95ed1ad
apply inverse gamma on colors
Erfan-Ahmadi Apr 21, 2025
244b0d0
screenToWorldRatio doesn't need to be double, only used to transform …
Erfan-Ahmadi Apr 21, 2025
b36e702
cleanups and setup work for multiple contours
Erfan-Ahmadi Apr 21, 2025
2462d0a
multiple contours in fragment shader
Erfan-Ahmadi Apr 22, 2025
287688e
Small example 62 update
Przemog1 Apr 22, 2025
4346a60
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla-…
Przemog1 Apr 22, 2025
daa51f6
Refactor
Przemog1 Apr 22, 2025
8a771a6
Fixed blending
Przemog1 Apr 23, 2025
fa5d7f1
Added `line_style.hlsl` file
Przemog1 Apr 24, 2025
9ddaa81
emulated float64 bug repro
Erfan-Ahmadi Apr 25, 2025
12f3d84
grid dtm tasks
Erfan-Ahmadi Apr 30, 2025
3e1cd3e
Fix and separate custom clip projection
Erfan-Ahmadi May 1, 2025
6e27153
small example edit
Erfan-Ahmadi May 1, 2025
496cec4
Merge branch 'grid_dtm' into dtm
Erfan-Ahmadi May 1, 2025
6706df6
plus should be drawn, emulated fp64 bug
Erfan-Ahmadi May 2, 2025
c9d2abf
Fixed Geometry and Fixed Screenspace sized polylines handle
Erfan-Ahmadi May 2, 2025
7381460
drawFixedGeometryPolyline add case to example
Erfan-Ahmadi May 2, 2025
1db6e04
small fixes on transformation type
Erfan-Ahmadi May 2, 2025
7521f57
fix vtx shader typo
Erfan-Ahmadi May 2, 2025
7ab6f5d
small example edit
Erfan-Ahmadi May 3, 2025
f88f6b6
Preparation work for backing up and restoring draw resources cache (f…
Erfan-Ahmadi May 4, 2025
4ec4938
CacheAndReplay Feature
Erfan-Ahmadi May 5, 2025
8677f1f
sync with builtin-shaders work
Erfan-Ahmadi May 5, 2025
8b56599
Small Fix to avoid msdf evictions of glyphs that were re-used
Erfan-Ahmadi May 12, 2025
48b3125
small typo fix, oops
Erfan-Ahmadi May 12, 2025
daf6810
Support for StaticImages [VRAM Limitation Eviction Untested] + MSDF I…
Erfan-Ahmadi May 13, 2025
ce29c74
[WIP] Images.h and ImagesMemorySubAllocator, TODO: postDestroyCleanup…
Erfan-Ahmadi May 14, 2025
bd9ee8e
Better Image Test + PostCleanup free + Fixing command buffer usage af…
Erfan-Ahmadi May 14, 2025
fcff2ac
Small edits and refactor
Erfan-Ahmadi May 14, 2025
093099f
Test and verify overflow submit works with images bound to non dedica…
Erfan-Ahmadi May 15, 2025
fc20a29
Grid DTM fundamentals
Przemog1 May 15, 2025
dc3ec8c
Resolved conflicts, merged dtm
Przemog1 May 15, 2025
8a8ff67
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla-…
Przemog1 May 15, 2025
0b010ea
Updated media submodule
Przemog1 May 15, 2025
ab6dd2e
Corrections
Przemog1 May 15, 2025
34a61a3
Fix overflow submits in a beautiful way
Erfan-Ahmadi May 16, 2025
ada9c8b
Cache&Replay with static images
Erfan-Ahmadi May 16, 2025
2632c3a
use OrientedBoundingBox2D for images
Erfan-Ahmadi May 18, 2025
e2fef3a
start Georeferenced Images work and refactoring similar functionality…
Erfan-Ahmadi May 20, 2025
a714352
small fix
Erfan-Ahmadi May 20, 2025
596751c
small fix2
Erfan-Ahmadi May 20, 2025
2cbc2b0
[Untested] more work on Georeferenced images creation and recreating/…
Erfan-Ahmadi May 20, 2025
f1fb1b5
Adds Cache iteration test
Fletterio May 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 62_CAD/CTriangleMesh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "CTriangleMesh.h"
66 changes: 66 additions & 0 deletions 62_CAD/CTriangleMesh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#pragma once

#include <nabla.h>
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
#include "shaders/globals.hlsl"

using namespace nbl;

struct DTMSettingsInfo
{
LineStyleInfo outlineLineStyleInfo;
LineStyleInfo contourLineStyleInfo;
// TODO: heights


};

class CTriangleMesh final
{
public:
using index_t = uint32_t;
using vertex_t = TriangleMeshVertex;

struct DrawData
{
PushConstants pushConstants;
uint64_t indexBufferOffset;
uint64_t indexCount;
};

inline void setVertices(core::vector<vertex_t>&& vertices)
{
m_vertices = std::move(vertices);
}
inline void setIndices(core::vector<uint32_t>&& indices)
{
m_indices = std::move(indices);
}

inline const core::vector<vertex_t>& getVertices() const
{
return m_vertices;
}
inline const core::vector<uint32_t>& getIndices() const
{
return m_indices;
}

inline size_t getVtxBuffByteSize() const
{
return sizeof(vertex_t) * m_vertices.size();
}
inline size_t getIdxBuffByteSize() const
{
return sizeof(index_t) * m_indices.size();
}
inline size_t getIdxCnt() const
{
return m_indices.size();
}


private:
core::vector<vertex_t> m_vertices;
core::vector<index_t> m_indices;
};
140 changes: 135 additions & 5 deletions 62_CAD/DrawResourcesFiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void DrawResourcesFiller::allocateGeometryBuffer(ILogicalDevice* logicalDevice,

IGPUBuffer::SCreationParams geometryCreationParams = {};
geometryCreationParams.size = size;
geometryCreationParams.usage = bitflag(IGPUBuffer::EUF_STORAGE_BUFFER_BIT) | IGPUBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT | IGPUBuffer::EUF_TRANSFER_DST_BIT;
geometryCreationParams.usage = bitflag(IGPUBuffer::EUF_STORAGE_BUFFER_BIT) | IGPUBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT | IGPUBuffer::EUF_TRANSFER_DST_BIT | IGPUBuffer::EUF_INDEX_BUFFER_BIT;
gpuDrawBuffers.geometryBuffer = logicalDevice->createBuffer(std::move(geometryCreationParams));
gpuDrawBuffers.geometryBuffer->setObjectDebugName("geometryBuffer");

Expand Down Expand Up @@ -116,6 +116,24 @@ void DrawResourcesFiller::allocateStylesBuffer(ILogicalDevice* logicalDevice, ui
}
}

void DrawResourcesFiller::allocateDTMSettingsBuffer(ILogicalDevice* logicalDevice, uint32_t dtmSettingsCount)
{
maxDtmSettings = dtmSettingsCount;
size_t dtmSettingsBufferSize = dtmSettingsCount * sizeof(DTMSettings);

IGPUBuffer::SCreationParams dtmSettingsCreationParams = {};
dtmSettingsCreationParams.size = dtmSettingsBufferSize;
dtmSettingsCreationParams.usage = IGPUBuffer::EUF_STORAGE_BUFFER_BIT | IGPUBuffer::EUF_TRANSFER_DST_BIT;
gpuDrawBuffers.dtmSettingsBuffer = logicalDevice->createBuffer(std::move(dtmSettingsCreationParams));
gpuDrawBuffers.dtmSettingsBuffer->setObjectDebugName("dtmSettingsBuffer");

IDeviceMemoryBacked::SDeviceMemoryRequirements memReq = gpuDrawBuffers.dtmSettingsBuffer->getMemoryReqs();
memReq.memoryTypeBits &= logicalDevice->getPhysicalDevice()->getDeviceLocalMemoryTypeBits();
auto stylesBufferMem = logicalDevice->allocate(memReq, gpuDrawBuffers.dtmSettingsBuffer.get());

cpuDrawBuffers.dtmSettingsBuffer = ICPUBuffer::create({ dtmSettingsBufferSize });
}

void DrawResourcesFiller::allocateMSDFTextures(ILogicalDevice* logicalDevice, uint32_t maxMSDFs, uint32_t2 msdfsExtent)
{
msdfLRUCache = std::unique_ptr<MSDFsLRUCache>(new MSDFsLRUCache(maxMSDFs));
Expand Down Expand Up @@ -172,7 +190,7 @@ void DrawResourcesFiller::drawPolyline(const CPolylineBase& polyline, const Line

uint32_t styleIdx = addLineStyle_SubmitIfNeeded(lineStyleInfo, intendedNextSubmit);

uint32_t mainObjIdx = addMainObject_SubmitIfNeeded(styleIdx, intendedNextSubmit);
uint32_t mainObjIdx = addMainObject_SubmitIfNeeded(styleIdx, InvalidDTMSettingsIdx, intendedNextSubmit);

drawPolyline(polyline, mainObjIdx, intendedNextSubmit);
}
Expand Down Expand Up @@ -218,6 +236,52 @@ void DrawResourcesFiller::drawPolyline(const CPolylineBase& polyline, uint32_t p
}
}

void DrawResourcesFiller::drawTriangleMesh(const CTriangleMesh& mesh, CTriangleMesh::DrawData& drawData, const DTMSettingsInfo& dtmSettingsInfo, SIntendedSubmitInfo& intendedNextSubmit)
{
ICPUBuffer::SCreationParams geometryBuffParams;

// concatenate the index and vertex buffer into the geometry buffer
const size_t indexBuffByteSize = mesh.getIdxBuffByteSize();
const size_t vtxBuffByteSize = mesh.getVtxBuffByteSize();
const size_t geometryBufferDataToAddByteSize = indexBuffByteSize + vtxBuffByteSize;

// copy into gemoetry cpu buffer insteaed

// TODO: rename, its not just points
const uint32_t maxGeometryBufferPoints = static_cast<uint32_t>(maxGeometryBufferSize - currentGeometryBufferSize);

// TODO: assert of geometry buffer size, do i need to check if size of objects to be added <= maxGeometryBufferPoints?
// TODO: auto submit instead of assert
assert(geometryBufferDataToAddByteSize <= maxGeometryBufferPoints);

// TODO: vertices need to be aligned to 8?
uint64_t vtxBufferAddress;
{
void* dst = reinterpret_cast<char*>(cpuDrawBuffers.geometryBuffer->getPointer()) + currentGeometryBufferSize;
void* dst1 = dst;

drawData.indexBufferOffset = currentGeometryBufferSize;
memcpy(dst, mesh.getIndices().data(), indexBuffByteSize);
currentGeometryBufferSize += indexBuffByteSize;

dst = reinterpret_cast<char*>(cpuDrawBuffers.geometryBuffer->getPointer()) + currentGeometryBufferSize;
drawData.pushConstants.triangleMeshVerticesBaseAddress = geometryBufferAddress + currentGeometryBufferSize;
memcpy(dst, mesh.getVertices().data(), vtxBuffByteSize);
currentGeometryBufferSize += vtxBuffByteSize;
}

drawData.indexCount = mesh.getIdxCnt();

// call addMainObject_SubmitIfNeeded, use its index in push constants

uint32_t dtmSettingsIndex = addDTMSettings_SubmitIfNeeded(dtmSettingsInfo, intendedNextSubmit);

drawData.pushConstants.triangleMeshMainObjectIndex = addMainObject_SubmitIfNeeded(InvalidStyleIdx, dtmSettingsIndex, intendedNextSubmit);

// TODO: use this function later for auto submit
//submitCurrentDrawObjectsAndReset(intendedNextSubmit, 0);
}

// TODO[Erfan]: Makes more sense if parameters are: solidColor + fillPattern + patternColor
void DrawResourcesFiller::drawHatch(
const Hatch& hatch,
Expand Down Expand Up @@ -260,7 +324,7 @@ void DrawResourcesFiller::drawHatch(
lineStyle.screenSpaceLineWidth = nbl::hlsl::bit_cast<float, uint32_t>(textureIdx);
const uint32_t styleIdx = addLineStyle_SubmitIfNeeded(lineStyle, intendedNextSubmit);

uint32_t mainObjIdx = addMainObject_SubmitIfNeeded(styleIdx, intendedNextSubmit);
uint32_t mainObjIdx = addMainObject_SubmitIfNeeded(styleIdx, InvalidDTMSettingsIdx, intendedNextSubmit);
uint32_t currentObjectInSection = 0u; // Object here refers to DrawObject used in vertex shader. You can think of it as a Cage.
while (currentObjectInSection < hatch.getHatchBoxCount())
{
Expand Down Expand Up @@ -315,6 +379,7 @@ bool DrawResourcesFiller::finalizeAllCopiesToGPU(SIntendedSubmitInfo& intendedNe
success &= finalizeMainObjectCopiesToGPU(intendedNextSubmit);
success &= finalizeGeometryCopiesToGPU(intendedNextSubmit);
success &= finalizeLineStyleCopiesToGPU(intendedNextSubmit);
success &= finalizeDTMSettingsCopiesToGPU(intendedNextSubmit);
success &= finalizeTextureCopies(intendedNextSubmit);
return success;
}
Expand All @@ -335,10 +400,27 @@ uint32_t DrawResourcesFiller::addLineStyle_SubmitIfNeeded(const LineStyleInfo& l
return outLineStyleIdx;
}

uint32_t DrawResourcesFiller::addMainObject_SubmitIfNeeded(uint32_t styleIdx, SIntendedSubmitInfo& intendedNextSubmit)
uint32_t DrawResourcesFiller::addDTMSettings_SubmitIfNeeded(const DTMSettingsInfo& dtmSettings, SIntendedSubmitInfo& intendedNextSubmit)
{
uint32_t outDTMSettingIdx = addDTMSettings_Internal(dtmSettings, intendedNextSubmit);
if (outDTMSettingIdx == InvalidStyleIdx)
{
finalizeAllCopiesToGPU(intendedNextSubmit);
submitDraws(intendedNextSubmit);
resetGeometryCounters();
resetMainObjectCounters();
resetLineStyleCounters();
outDTMSettingIdx = addDTMSettings_Internal(dtmSettings, intendedNextSubmit);
assert(outDTMSettingIdx != InvalidDTMSettingsIdx);
}
return outDTMSettingIdx;
}

uint32_t DrawResourcesFiller::addMainObject_SubmitIfNeeded(uint32_t styleIdx, uint32_t dtmSettingsIdx, SIntendedSubmitInfo& intendedNextSubmit)
{
MainObject mainObject = {};
mainObject.styleIdx = styleIdx;
mainObject.dtmSettingsIdx = dtmSettingsIdx;
mainObject.clipProjectionAddress = acquireCurrentClipProjectionAddress(intendedNextSubmit);
uint32_t outMainObjectIdx = addMainObject_Internal(mainObject);
if (outMainObjectIdx == InvalidMainObjectIdx)
Expand Down Expand Up @@ -440,7 +522,8 @@ bool DrawResourcesFiller::finalizeLineStyleCopiesToGPU(SIntendedSubmitInfo& inte
SBufferRange<IGPUBuffer> stylesRange = { sizeof(LineStyle) * inMemLineStylesCount, sizeof(LineStyle) * remainingLineStyles, gpuDrawBuffers.lineStylesBuffer };
if (stylesRange.size > 0u)
{
const LineStyle* srcLineStylesData = reinterpret_cast<LineStyle*>(cpuDrawBuffers.lineStylesBuffer->getPointer()) + inMemLineStylesCount;
LineStyle* srcLineStylesData = reinterpret_cast<LineStyle*>(cpuDrawBuffers.lineStylesBuffer->getPointer()) + inMemLineStylesCount;

if (m_utilities->updateBufferRangeViaStagingBuffer(intendedNextSubmit, stylesRange, srcLineStylesData))
inMemLineStylesCount = currentLineStylesCount;
else
Expand All @@ -452,6 +535,26 @@ bool DrawResourcesFiller::finalizeLineStyleCopiesToGPU(SIntendedSubmitInfo& inte
return success;
}

bool DrawResourcesFiller::finalizeDTMSettingsCopiesToGPU(SIntendedSubmitInfo& intendedNextSubmit)
{
bool success = true;
// Copy LineStyles
uint32_t remainingLineStyles = currentDTMSettingsCount - inMemDTMSettingsCount;
SBufferRange<IGPUBuffer> dtmSettingsRange = { sizeof(DTMSettings) * inMemDTMSettingsCount, sizeof(DTMSettings) * remainingLineStyles, gpuDrawBuffers.dtmSettingsBuffer };
if (dtmSettingsRange.size > 0u)
{
const DTMSettings* srcDTMSettingsData = reinterpret_cast<DTMSettings*>(cpuDrawBuffers.dtmSettingsBuffer->getPointer()) + inMemDTMSettingsCount;
if (m_utilities->updateBufferRangeViaStagingBuffer(intendedNextSubmit, dtmSettingsRange, srcDTMSettingsData))
inMemDTMSettingsCount = currentDTMSettingsCount;
else
{
// TODO: Log
success = false;
}
}
return success;
}

bool DrawResourcesFiller::finalizeTextureCopies(SIntendedSubmitInfo& intendedNextSubmit)
{
msdfTextureArrayIndicesUsed.clear(); // clear msdf textures used in the frame, because the frame finished and called this function.
Expand Down Expand Up @@ -684,6 +787,33 @@ uint32_t DrawResourcesFiller::addLineStyle_Internal(const LineStyleInfo& lineSty
return currentLineStylesCount++;
}

uint32_t DrawResourcesFiller::addDTMSettings_Internal(const DTMSettingsInfo& dtmSettingsInfo, SIntendedSubmitInfo& intendedNextSubmit)
{
DTMSettings dtmSettings;

// TODO: this needs to be redone.. what if submit happens after that line?
// we need to make sure somehow that function below will not submit, we need both outline and contour styles in GPU memory
dtmSettings.outlineLineStyleIdx = addLineStyle_SubmitIfNeeded(dtmSettingsInfo.outlineLineStyleInfo, intendedNextSubmit);
dtmSettings.contourLineStyleIdx = addLineStyle_SubmitIfNeeded(dtmSettingsInfo.contourLineStyleInfo, intendedNextSubmit);

DTMSettings* settingsArray = reinterpret_cast<DTMSettings*>(cpuDrawBuffers.dtmSettingsBuffer->getPointer());
for (uint32_t i = 0u; i < currentDTMSettingsCount; ++i)
{
const DTMSettings& itr = settingsArray[i];
if (itr == dtmSettings)
return i;
}

if (currentDTMSettingsCount >= maxDtmSettings)
return InvalidDTMSettingsIdx;

void* dst = settingsArray + currentDTMSettingsCount;
memcpy(dst, &dtmSettings, sizeof(DTMSettings));
return currentDTMSettingsCount++;

return InvalidDTMSettingsIdx;
}

uint64_t DrawResourcesFiller::acquireCurrentClipProjectionAddress(SIntendedSubmitInfo& intendedNextSubmit)
{
if (clipProjectionAddresses.empty())
Expand Down
27 changes: 25 additions & 2 deletions 62_CAD/DrawResourcesFiller.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include "Polyline.h"
#include "CTriangleMesh.h"
#include "Hatch.h"
#include "IndexAllocator.h"
#include <nbl/video/utilities/SIntendedSubmitInfo.h>
Expand All @@ -26,6 +27,7 @@ struct DrawBuffers
smart_refctd_ptr<BufferType> drawObjectsBuffer;
smart_refctd_ptr<BufferType> geometryBuffer;
smart_refctd_ptr<BufferType> lineStylesBuffer;
smart_refctd_ptr<BufferType> dtmSettingsBuffer;
};

// ! DrawResourcesFiller
Expand Down Expand Up @@ -56,6 +58,8 @@ struct DrawResourcesFiller
void allocateGeometryBuffer(ILogicalDevice* logicalDevice, size_t size);

void allocateStylesBuffer(ILogicalDevice* logicalDevice, uint32_t lineStylesCount);

void allocateDTMSettingsBuffer(ILogicalDevice* logicalDevice, uint32_t dtmSettingsCount);

void allocateMSDFTextures(ILogicalDevice* logicalDevice, uint32_t maxMSDFs, uint32_t2 msdfsExtent);

Expand All @@ -76,6 +80,8 @@ struct DrawResourcesFiller

void drawPolyline(const CPolylineBase& polyline, uint32_t polylineMainObjIdx, SIntendedSubmitInfo& intendedNextSubmit);

void drawTriangleMesh(const CTriangleMesh& mesh, CTriangleMesh::DrawData& drawData, const DTMSettingsInfo& dtmSettings, SIntendedSubmitInfo& intendedNextSubmit);

// ! Convinience function for Hatch with MSDF Pattern and a solid background
void drawHatch(
const Hatch& hatch,
Expand Down Expand Up @@ -142,7 +148,7 @@ struct DrawResourcesFiller
return false;
};

uint32_t mainObjIdx = addMainObject_SubmitIfNeeded(InvalidStyleIdx, intendedNextSubmit);
uint32_t mainObjIdx = addMainObject_SubmitIfNeeded(InvalidStyleIdx, InvalidDTMSettingsIdx, intendedNextSubmit);

ImageObjectInfo info = {};
info.topLeft = topLeftPos;
Expand Down Expand Up @@ -191,12 +197,15 @@ struct DrawResourcesFiller
resetGeometryCounters();
resetMainObjectCounters();
resetLineStyleCounters();
resetDTMSettingsCounters();
}

DrawBuffers<ICPUBuffer> cpuDrawBuffers;
DrawBuffers<IGPUBuffer> gpuDrawBuffers;

uint32_t addLineStyle_SubmitIfNeeded(const LineStyleInfo& lineStyle, SIntendedSubmitInfo& intendedNextSubmit);

uint32_t addDTMSettings_SubmitIfNeeded(const DTMSettingsInfo& dtmSettings, SIntendedSubmitInfo& intendedNextSubmit);

// TODO[Przemek]: Read after reading the fragment shader comments and having a basic understanding of the relationship between "mainObject" and our programmable blending resolve:
// Use `addMainObject_SubmitIfNeeded` to push your single mainObject you'll be using for the enitre triangle mesh (this will ensure overlaps between triangles of the same mesh is resolved correctly)
Expand All @@ -206,7 +215,7 @@ struct DrawResourcesFiller
// Never call this function multiple times in a row before indexing it in a drawable, because future auto-submits may invalidate mainObjects, so do them one by one, for example:
// Valid: addMainObject1 --> addXXX(mainObj1) ---> addMainObject2 ---> addXXX(mainObj2) ....
// Invalid: addMainObject1 ---> addMainObject2 ---> addXXX(mainObj1) ---> addXXX(mainObj2) ....
uint32_t addMainObject_SubmitIfNeeded(uint32_t styleIdx, SIntendedSubmitInfo& intendedNextSubmit);
uint32_t addMainObject_SubmitIfNeeded(uint32_t styleIdx, uint32_t dtmSettingsIdx, SIntendedSubmitInfo& intendedNextSubmit);

// we need to store the clip projection stack to make sure the front is always available in memory
void pushClipProjectionData(const ClipProjectionData& clipProjectionData);
Expand Down Expand Up @@ -238,6 +247,8 @@ struct DrawResourcesFiller
bool finalizeGeometryCopiesToGPU(SIntendedSubmitInfo& intendedNextSubmit);

bool finalizeLineStyleCopiesToGPU(SIntendedSubmitInfo& intendedNextSubmit);

bool finalizeDTMSettingsCopiesToGPU(SIntendedSubmitInfo& intendedNextSubmit);

bool finalizeCustomClipProjectionCopiesToGPU(SIntendedSubmitInfo& intendedNextSubmit);

Expand All @@ -254,6 +265,8 @@ struct DrawResourcesFiller

uint32_t addLineStyle_Internal(const LineStyleInfo& lineStyleInfo);

uint32_t addDTMSettings_Internal(const DTMSettingsInfo& dtmSettings, SIntendedSubmitInfo& intendedNextSubmit);

// Gets the current clip projection data (the top of stack) gpu addreess inside the geometryBuffer
// If it's been invalidated then it will request to upload again with a possible auto-submit on low geometry buffer memory.
uint64_t acquireCurrentClipProjectionAddress(SIntendedSubmitInfo& intendedNextSubmit);
Expand Down Expand Up @@ -311,6 +324,12 @@ struct DrawResourcesFiller
inMemLineStylesCount = 0u;
}

void resetDTMSettingsCounters()
{
currentDTMSettingsCount = 0u;
inMemDTMSettingsCount = 0u;
}

MainObject* getMainObject(uint32_t idx)
{
MainObject* mainObjsArray = reinterpret_cast<MainObject*>(cpuDrawBuffers.mainObjectsBuffer->getPointer());
Expand Down Expand Up @@ -429,6 +448,10 @@ struct DrawResourcesFiller
uint32_t currentLineStylesCount = 0u;
uint32_t maxLineStyles = 0u;

uint32_t inMemDTMSettingsCount = 0u;
uint32_t currentDTMSettingsCount = 0u;
uint32_t maxDtmSettings = 0u;

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

std::deque<ClipProjectionData> clipProjections; // stack of clip projectios stored so we can resubmit them if geometry buffer got reset.
Expand Down
Loading