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
41 changes: 25 additions & 16 deletions 62_CAD/DrawResourcesFiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2395,8 +2395,9 @@ void DrawResourcesFiller::addPolylineConnectors_Internal(const CPolylineBase& po
// Add DrawObjs
DrawObject* drawObjectsToBeFilled = resourcesCollection.drawObjects.increaseCountAndGetPtr(objectsToUpload);
DrawObject drawObj = {};
drawObj.mainObjIndex = mainObjIdx;
drawObj.type_subsectionIdx = uint32_t(static_cast<uint16_t>(ObjectType::POLYLINE_CONNECTOR) | 0 << 16);
drawObj.setMainObjIndex(mainObjIdx);
drawObj.setType(ObjectType::POLYLINE_CONNECTOR);
drawObj.setSubsectionIdx(0);
drawObj.geometryAddress = geometryBufferOffset;
for (uint32_t i = 0u; i < objectsToUpload; ++i)
{
Expand Down Expand Up @@ -2451,8 +2452,9 @@ void DrawResourcesFiller::addLines_Internal(const CPolylineBase& polyline, const
// Add DrawObjs
DrawObject* drawObjectsToBeFilled = resourcesCollection.drawObjects.increaseCountAndGetPtr(objectsToUpload);
DrawObject drawObj = {};
drawObj.mainObjIndex = mainObjIdx;
drawObj.type_subsectionIdx = uint32_t(static_cast<uint16_t>(ObjectType::LINE) | 0 << 16);
drawObj.setMainObjIndex(mainObjIdx);
drawObj.setType(ObjectType::LINE);
drawObj.setSubsectionIdx(0);
drawObj.geometryAddress = geometryBufferOffset;
for (uint32_t i = 0u; i < objectsToUpload; ++i)
{
Expand Down Expand Up @@ -2508,13 +2510,15 @@ void DrawResourcesFiller::addQuadBeziers_Internal(const CPolylineBase& polyline,
// Add DrawObjs
DrawObject* drawObjectsToBeFilled = resourcesCollection.drawObjects.increaseCountAndGetPtr(cagesCount);
DrawObject drawObj = {};
drawObj.mainObjIndex = mainObjIdx;
drawObj.setMainObjIndex(mainObjIdx);
drawObj.geometryAddress = geometryBufferOffset;
for (uint32_t i = 0u; i < objectsToUpload; ++i)
{
for (uint16_t subObject = 0; subObject < CagesPerQuadBezier; subObject++)
{
drawObj.type_subsectionIdx = uint32_t(static_cast<uint16_t>(ObjectType::QUAD_BEZIER) | (subObject << 16));
assert(subObject < 4); // there can be maximum 4 subsections
drawObj.setType(ObjectType::QUAD_BEZIER);
drawObj.setSubsectionIdx(subObject);
drawObjectsToBeFilled[i * CagesPerQuadBezier + subObject] = drawObj;
}
drawObj.geometryAddress += sizeof(QuadraticBezierInfo);
Expand Down Expand Up @@ -2561,8 +2565,9 @@ void DrawResourcesFiller::addHatch_Internal(const Hatch& hatch, uint32_t& curren
// Add DrawObjs
DrawObject* drawObjectsToBeFilled = resourcesCollection.drawObjects.increaseCountAndGetPtr(objectsToUpload);
DrawObject drawObj = {};
drawObj.mainObjIndex = mainObjIndex;
drawObj.type_subsectionIdx = uint32_t(static_cast<uint16_t>(ObjectType::CURVE_BOX) | (0 << 16));
drawObj.setMainObjIndex(mainObjIndex);
drawObj.setType(ObjectType::CURVE_BOX);
drawObj.setSubsectionIdx(0);
drawObj.geometryAddress = geometryBufferOffset;
for (uint32_t i = 0u; i < objectsToUpload; ++i)
{
Expand Down Expand Up @@ -2603,8 +2608,9 @@ bool DrawResourcesFiller::addFontGlyph_Internal(const GlyphInfo& glyphInfo, uint
// Add DrawObjs
DrawObject* drawObjectsToBeFilled = resourcesCollection.drawObjects.increaseCountAndGetPtr(1u);
DrawObject drawObj = {};
drawObj.mainObjIndex = mainObjIdx;
drawObj.type_subsectionIdx = uint32_t(static_cast<uint16_t>(ObjectType::FONT_GLYPH) | (0 << 16));
drawObj.setMainObjIndex(mainObjIdx);
drawObj.setType(ObjectType::FONT_GLYPH);
drawObj.setSubsectionIdx(0);
drawObj.geometryAddress = geometryBufferOffset;
drawObjectsToBeFilled[0u] = drawObj;

Expand Down Expand Up @@ -2640,8 +2646,9 @@ bool DrawResourcesFiller::addGridDTM_Internal(const GridDTMInfo& gridDTMInfo, ui
// Add DrawObjs
DrawObject* drawObjectsToBeFilled = resourcesCollection.drawObjects.increaseCountAndGetPtr(1u);
DrawObject drawObj = {};
drawObj.mainObjIndex = mainObjIdx;
drawObj.type_subsectionIdx = uint32_t(static_cast<uint16_t>(ObjectType::GRID_DTM) | (0 << 16));
drawObj.setMainObjIndex(mainObjIdx);
drawObj.setType(ObjectType::GRID_DTM);
drawObj.setSubsectionIdx(0);
drawObj.geometryAddress = geometryBufferOffset;
drawObjectsToBeFilled[0u] = drawObj;

Expand Down Expand Up @@ -2677,8 +2684,9 @@ bool DrawResourcesFiller::addImageObject_Internal(const ImageObjectInfo& imageOb
// Add DrawObjs
DrawObject* drawObjectsToBeFilled = resourcesCollection.drawObjects.increaseCountAndGetPtr(1u);
DrawObject drawObj = {};
drawObj.mainObjIndex = mainObjIdx;
drawObj.type_subsectionIdx = uint32_t(static_cast<uint16_t>(ObjectType::STATIC_IMAGE) | (0 << 16)); // TODO: use custom pack/unpack function
drawObj.setMainObjIndex(mainObjIdx);
drawObj.setType(ObjectType::STATIC_IMAGE);
drawObj.setSubsectionIdx(0);
drawObj.geometryAddress = geometryBufferOffset;
drawObjectsToBeFilled[0u] = drawObj;

Expand Down Expand Up @@ -2714,8 +2722,9 @@ bool DrawResourcesFiller::addGeoreferencedImageInfo_Internal(const Georeferenced
// Add DrawObjs
DrawObject* drawObjectsToBeFilled = resourcesCollection.drawObjects.increaseCountAndGetPtr(1u);
DrawObject drawObj = {};
drawObj.mainObjIndex = mainObjIdx;
drawObj.type_subsectionIdx = uint32_t(static_cast<uint16_t>(ObjectType::STREAMED_IMAGE) | (0 << 16)); // TODO: use custom pack/unpack function
drawObj.setMainObjIndex(mainObjIdx);
drawObj.setType(ObjectType::STREAMED_IMAGE);
drawObj.setSubsectionIdx(0);
drawObj.geometryAddress = geometryBufferOffset;
drawObjectsToBeFilled[0u] = drawObj;

Expand Down
2 changes: 1 addition & 1 deletion 62_CAD/DrawResourcesFiller.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using namespace nbl::video;
using namespace nbl::core;
using namespace nbl::asset;

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

Expand Down
37 changes: 32 additions & 5 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 @@ -3752,7 +3752,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 +3809,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 +3821,35 @@ 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, transformation, TransformationType::TT_FIXED_SCREENSPACE_SIZE, intendedNextSubmit);
}
}
}
else if (mode == ExampleMode::CASE_11)
Expand Down
23 changes: 18 additions & 5 deletions 62_CAD/shaders/globals.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <nbl/builtin/hlsl/cpp_compat/matrix.hlsl>
#include <nbl/builtin/hlsl/shapes/beziers.hlsl>
#include <nbl/builtin/hlsl/tgmath.hlsl>
#include <nbl/builtin/hlsl/utils/bitfield.hlsl>

#ifdef __HLSL_VERSION
#include <nbl/builtin/hlsl/math/equations/quadratic.hlsl>
Expand Down Expand Up @@ -159,9 +160,21 @@ struct MainObject

struct DrawObject
{
uint32_t type_subsectionIdx; // packed two uint16 into uint32
uint32_t mainObjIndex;
uint64_t geometryAddress;
uint32_t packedData;
uint32_t geometryAddress; // geometry has 8 byte alignment, max 34GB of data to reference

using TypeField = utils::BitField<uint32_t, 0, 4>; // 16 different object types
using SubsectionField = utils::BitField<uint32_t, 4, 2>; // 4 max subsections
using MainObjField = utils::BitField<uint32_t, 6, 26>; // 67M main objects max

ObjectType getType() { return (ObjectType)TypeField::get(packedData); }
void setType(ObjectType objType) { packedData = TypeField::set(packedData, (uint32_t)objType); }

uint32_t getSubsectionIdx() { return SubsectionField::get(packedData); }
void setSubsectionIdx(uint32_t subsectionIdx) { packedData = SubsectionField::set(packedData, subsectionIdx); }

uint32_t getMainObjIndex() { return MainObjField::get(packedData); }
void setMainObjIndex(uint32_t mainObjIdx) { packedData = MainObjField::set(packedData, mainObjIdx); }
};

// Goes into geometry buffer, needs to be aligned by 8
Expand Down Expand Up @@ -618,15 +631,15 @@ MainObject loadMainObject(const uint32_t index)
}
DrawObject loadDrawObject(const uint32_t index)
{
return vk::RawBufferLoad<DrawObject>(globals.pointers.drawObjects + index * sizeof(DrawObject), 8u);
return vk::RawBufferLoad<DrawObject>(globals.pointers.drawObjects + index * sizeof(DrawObject), 4u);
}
#else
static_assert(alignof(LineStyle)==4u);
static_assert(alignof(DTMSettings)==4u);
static_assert(alignof(pfloat64_t3x3)==8u);
static_assert(alignof(WorldClipRect)==8u);
static_assert(alignof(MainObject)==4u);
static_assert(alignof(DrawObject)==8u);
static_assert(alignof(DrawObject)==4u);
#endif


Expand Down
Loading