Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
138 changes: 83 additions & 55 deletions 62_CAD/DrawResourcesFiller.cpp

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions 62_CAD/DrawResourcesFiller.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ using namespace nbl::video;
using namespace nbl::core;
using namespace nbl::asset;

static_assert(sizeof(DrawObject) == 16u);
static_assert(sizeof(MainObject) == 20u);
static_assert(sizeof(DrawObject) == 8u);
static_assert(sizeof(MainObject) == 8u);
static_assert(sizeof(LineStyle) == 88u);

// ! DrawResourcesFiller
Expand Down Expand Up @@ -109,7 +109,7 @@ struct DrawResourcesFiller
// auto-submission level 0 resources (settings that mainObj references)
CPUGeneratedResource<LineStyle> lineStyles;
CPUGeneratedResource<DTMSettings> dtmSettings;
CPUGeneratedResource<float64_t3x3> customProjections;
CPUGeneratedResource<float64_t2x3> customProjections;
CPUGeneratedResource<WorldClipRect> customClipRects;

// auto-submission level 1 buffers (mainObj that drawObjs references, if all drawObjs+idxBuffer+geometryInfo doesn't fit into mem this will be broken down into many)
Expand Down Expand Up @@ -229,7 +229,7 @@ struct DrawResourcesFiller

//! Draws a fixed-geometry polyline using a custom transformation.
//! TODO: Change `polyline` input to an ID referencing a possibly cached instance in our buffers, allowing reuse and avoiding redundant uploads.
void drawFixedGeometryPolyline(const CPolylineBase& polyline, const LineStyleInfo& lineStyleInfo, const float64_t3x3& transformation, TransformationType transformationType, SIntendedSubmitInfo& intendedNextSubmit);
void drawFixedGeometryPolyline(const CPolylineBase& polyline, const LineStyleInfo& lineStyleInfo, const float64_t2x3& transformation, TransformationType transformationType, SIntendedSubmitInfo& intendedNextSubmit);

/// Use this in a begin/endMainObject scope when you want to draw different polylines that should essentially be a single main object (no self-blending between components of a single main object)
/// WARNING: make sure this function is called within begin/endMainObject scope
Expand Down Expand Up @@ -267,7 +267,7 @@ struct DrawResourcesFiller
const float32_t4& foregroundColor,
const float32_t4& backgroundColor,
const HatchFillPattern fillPattern,
const float64_t3x3& transformation,
const float64_t2x3& transformation,
TransformationType transformationType,
SIntendedSubmitInfo& intendedNextSubmit);

Expand All @@ -276,15 +276,15 @@ struct DrawResourcesFiller
const Hatch& hatch,
const float32_t4& color,
const HatchFillPattern fillPattern,
const float64_t3x3& transformation,
const float64_t2x3& transformation,
TransformationType transformationType,
SIntendedSubmitInfo& intendedNextSubmit);

// ! Solid Fill Fixed-geometry Hatch
void drawFixedGeometryHatch(
const Hatch& hatch,
const float32_t4& color,
const float64_t3x3& transformation,
const float64_t2x3& transformation,
TransformationType transformationType,
SIntendedSubmitInfo& intendedNextSubmit);

Expand Down Expand Up @@ -490,13 +490,13 @@ struct DrawResourcesFiller
void beginMainObject(MainObjectType type, TransformationType transformationType = TransformationType::TT_NORMAL);
void endMainObject();

void pushCustomProjection(const float64_t3x3& projection);
void pushCustomProjection(const float64_t2x3& projection);
void popCustomProjection();

void pushCustomClipRect(const WorldClipRect& clipRect);
void popCustomClipRect();

const std::deque<float64_t3x3>& getCustomProjectionStack() const { return activeProjections; }
const std::deque<float64_t2x3>& getCustomProjectionStack() const { return activeProjections; }
const std::deque<WorldClipRect>& getCustomClipRectsStack() const { return activeClipRects; }

smart_refctd_ptr<IGPUImageView> getMSDFsTextureArray() { return msdfTextureArray; }
Expand Down Expand Up @@ -719,7 +719,7 @@ struct DrawResourcesFiller
uint32_t addDTMSettings_SubmitIfNeeded(const DTMSettingsInfo& dtmSettings, SIntendedSubmitInfo& intendedNextSubmit);

/// Attempts to add custom projection to gpu resources. If it fails to do, due to resource limitations, auto-submits and tries again.
uint32_t addCustomProjection_SubmitIfNeeded(const float64_t3x3& projection, SIntendedSubmitInfo& intendedNextSubmit);
uint32_t addCustomProjection_SubmitIfNeeded(const float64_t2x3& projection, SIntendedSubmitInfo& intendedNextSubmit);

/// Attempts to add custom clip to gpu resources. If it fails to do, due to resource limitations, auto-submits and tries again.
uint32_t addCustomClipRect_SubmitIfNeeded(const WorldClipRect& clipRect, SIntendedSubmitInfo& intendedNextSubmit);
Expand Down Expand Up @@ -748,7 +748,7 @@ struct DrawResourcesFiller
* @param transformationType The type of transformation to apply (e.g., TT_NORMAL or TT_FIXED_SCREENSPACE_SIZE).
*
*/
float64_t3x3 getFixedGeometryFinalTransformationMatrix(const float64_t3x3& transformation, TransformationType transformationType) const;
float64_t2x3 getFixedGeometryFinalTransformationMatrix(const float64_t2x3& transformation, TransformationType transformationType) const;

/// Attempts to upload as many draw objects as possible within the given polyline section considering resource limitations
void addPolylineObjects_Internal(const CPolylineBase& polyline, const CPolylineBase::SectionInfo& section, uint32_t& currentObjectInSection, uint32_t mainObjIdx);
Expand Down Expand Up @@ -859,7 +859,7 @@ struct DrawResourcesFiller

// Invalidate all the clip projection addresses because activeProjections buffer got reset
for (auto& addr : activeProjectionIndices)
addr = InvalidCustomProjectionIndex;
addr = MainObject::getInvalidCustomTransformationIndex();
}

void resetCustomClipRects()
Expand All @@ -868,19 +868,19 @@ struct DrawResourcesFiller

// Invalidate all the clip projection addresses because activeProjections buffer got reset
for (auto& addr : activeClipRectIndices)
addr = InvalidCustomClipRectIndex;
addr = MainObject::getInvalidCustomClipRectIndex();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, custom clip tect or linestyle is only indexed by main object currently. but it may not stay that way, that's why I suggested this IndexLimits previously on discord.
you correctly implemented it but it needs to be outside mainobject

// make sure to add some good comment here for future maintainability and how we're supposed to expose IndexLimits (by minimum representation).
constexpr inline MinimumLineStyleBits = MainObject::LineStyleBitfield; // currently only referenced by main object so we'll use  
using LineStyleIndexLimits = IndexLimits<uint32_t, LineStyleIdxOrDtmSettingsIdxField::BitCount>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer your code this way btw, by asking the main object guy which directly indexes the linestyle. if I knew the code would stay this way. I'd want the limits to be queried from MainObject itself.
but I have a feeling this will change with future compute optimizations and gpu driven rendering

}

void resetLineStyles()
{
resourcesCollection.lineStyles.vector.clear();
activeLineStyleIndex = InvalidStyleIdx;
activeLineStyleIndex = MainObject::getInvalidLineStyleIndex();
}

void resetDTMSettings()
{
resourcesCollection.dtmSettings.vector.clear();
activeDTMSettingsIndex = InvalidDTMSettingsIdx;
activeDTMSettingsIndex = MainObject::getInvalidDtmSettingsIndex();
}

// MSDF Hashing and Caching Internal Functions
Expand Down Expand Up @@ -991,18 +991,18 @@ struct DrawResourcesFiller

// Active Resources we need to keep track of and push to resources buffer if needed.
LineStyleInfo activeLineStyle;
uint32_t activeLineStyleIndex = InvalidStyleIdx;
uint32_t activeLineStyleIndex = MainObject::getInvalidLineStyleIndex();

DTMSettingsInfo activeDTMSettings;
uint32_t activeDTMSettingsIndex = InvalidDTMSettingsIdx;
uint32_t activeDTMSettingsIndex = MainObject::getInvalidDtmSettingsIndex();

MainObjectType activeMainObjectType;
TransformationType activeMainObjectTransformationType;

uint32_t activeMainObjectIndex = InvalidMainObjectIdx;

// The ClipRects & Projections are stack, because user can push/pop ClipRects & Projections in any order
std::deque<float64_t3x3> activeProjections; // stack of projections stored so we can resubmit them if geometry buffer got reset.
std::deque<float64_t2x3> activeProjections; // stack of projections stored so we can resubmit them if geometry buffer got reset.
std::deque<uint32_t> activeProjectionIndices; // stack of projection gpu addresses in geometry buffer. to keep track of them in push/pops

std::deque<WorldClipRect> activeClipRects; // stack of clips stored so we can resubmit them if geometry buffer got reset.
Expand Down
44 changes: 34 additions & 10 deletions 62_CAD/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ constexpr std::array<float, (uint32_t)ExampleMode::CASE_COUNT> cameraExtents =
10.0 // CASE_12
};

constexpr ExampleMode mode = ExampleMode::CASE_2;
constexpr ExampleMode mode = ExampleMode::CASE_10;

class Camera2D
{
Expand Down Expand Up @@ -749,9 +749,8 @@ class ComputerAidedDesign final : public nbl::examples::SimpleWindowedApplicatio

tmpCmdBuffer->pipelineBarrier(E_DEPENDENCY_FLAGS::EDF_NONE, { .imgBarriers = beforeClearImageBarrier });

uint32_t pseudoStencilInvalidValue = core::bitfieldInsert<uint32_t>(0u, InvalidMainObjectIdx, AlphaBits, MainObjectIdxBits);
IGPUCommandBuffer::SClearColorValue clear = {};
clear.uint32[0] = pseudoStencilInvalidValue;
clear.uint32[0] = InvalidPseudoStencilValue;

asset::IImage::SSubresourceRange subresourceRange = {};
subresourceRange.aspectMask = asset::IImage::E_ASPECT_FLAGS::EAF_COLOR_BIT;
Expand Down Expand Up @@ -3290,10 +3289,9 @@ class ComputerAidedDesign final : public nbl::examples::SimpleWindowedApplicatio
}
else if (mode == ExampleMode::CASE_6)
{
float64_t3x3 customProjection = float64_t3x3{
float64_t2x3 customProjection = float64_t2x3{
1.0, 0.0, cos(m_timeElapsed * 0.0005) * 100.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0
0.0, 1.0, 0.0
};

/// [NOTE]: We set minClip and maxClip (in default worldspace) in such a way that minClip.y > maxClip.y so that minClipNDC.y < maxClipNDC.y
Expand Down Expand Up @@ -3752,7 +3750,7 @@ class ComputerAidedDesign final : public nbl::examples::SimpleWindowedApplicatio

LineStyleInfo style = {};
style.screenSpaceLineWidth = 4.0f;
style.color = float32_t4(0.619f, 0.325f, 0.709f, 0.5f);
style.color = float32_t4(0.2f, 0.2f, 0.2f, 0.5f);

for (uint32_t i = 0; i < 128u; ++i)
{
Expand Down Expand Up @@ -3809,7 +3807,7 @@ class ComputerAidedDesign final : public nbl::examples::SimpleWindowedApplicatio
0.0, 0.0, 1.0
};

float64_t2 scale = float64_t2{ 100.0, 100.0 };
float64_t2 scale = float64_t2{ 10.0, 10.0 };
float64_t3x3 scaleMat =
{
scale.x, 0.0, 0.0,
Expand All @@ -3821,8 +3819,34 @@ class ComputerAidedDesign final : public nbl::examples::SimpleWindowedApplicatio
polyline.addLinePoints(line0);
polyline.addLinePoints(line1);
polyline.preprocessPolylineWithStyle(style);
// drawResourcesFiller.drawPolyline(polyline, intendedNextSubmit);
drawResourcesFiller.drawFixedGeometryPolyline(polyline, style, transformation, TransformationType::TT_FIXED_SCREENSPACE_SIZE, intendedNextSubmit);
//drawResourcesFiller.drawPolyline(polyline, intendedNextSubmit);
//drawResourcesFiller.drawFixedGeometryPolyline(polyline, style, transformation, TransformationType::TT_FIXED_SCREENSPACE_SIZE, intendedNextSubmit);

constexpr int MarkerCount = 1000000;
for (int i = 0; i < MarkerCount; ++i)
{
translateMat =
{
1.0, 0.0, static_cast<float64_t>(i) / static_cast<float64_t>(MarkerCount*0.2),
0.0, 1.0, 0.0,
0.0, 0.0, 1.0
};

const float64_t rotationAngle = (core::radians(360.0) / static_cast<float64_t>(MarkerCount)) * static_cast<float64_t>(i) * 10.0;
dir = float64_t2{ std::cos(rotationAngle), std::sin(rotationAngle) };
rotateMat =
{
dir.x, -dir.y, 0.0,
dir.y, dir.x, 0.0,
0.0, 0.0, 1.0
};

transformation = nbl::hlsl::mul(rotateMat, translateMat);

transformation = nbl::hlsl::mul(rotateMat, nbl::hlsl::mul(translateMat, scaleMat));

drawResourcesFiller.drawFixedGeometryPolyline(polyline, style, float64_t2x3(transformation[0], transformation[1]), TransformationType::TT_FIXED_SCREENSPACE_SIZE, intendedNextSubmit);
}
}
}
else if (mode == ExampleMode::CASE_11)
Expand Down
Loading