Skip to content

Mesh loaders kevin #199

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 8 commits into
base: master
Choose a base branch
from
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
5 changes: 2 additions & 3 deletions 67_RayQueryGeometry/app_resources/common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ struct SGeomInfo
{
uint64_t vertexBufferAddress;
uint64_t indexBufferAddress;
uint64_t normalBufferAddress;

uint32_t vertexStride : 29;
uint32_t objType : 29;
uint32_t indexType : 2; // 16 bit, 32 bit or none

Choose a reason for hiding this comment

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

none should be inferred from indexBufferAddress==0 so you only need 1 bit

uint32_t smoothNormals : 1; // flat for cube, rectangle, disk

Choose a reason for hiding this comment

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

this should be inferred from normalBufferAddress!=0ull

uint32_t padding;
Expand All @@ -35,8 +36,6 @@ enum ObjectType : uint32_t // matches c++
OT_SPHERE,
OT_CYLINDER,
OT_RECTANGLE,
OT_DISK,
OT_ARROW,
OT_CONE,
OT_ICOSPHERE,

Expand Down
39 changes: 14 additions & 25 deletions 67_RayQueryGeometry/app_resources/render.comp.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ float3 unpackNormals3x10(uint32_t v)
float3 calculateSmoothNormals(int instID, int primID, SGeomInfo geom, float2 bary)
{
const uint indexType = geom.indexType;
const uint vertexStride = geom.vertexStride;
const uint objType = geom.objType;

const uint64_t vertexBufferAddress = geom.vertexBufferAddress;
const uint64_t indexBufferAddress = geom.indexBufferAddress;
const uint64_t normalBufferAddress = geom.normalBufferAddress;
Comment on lines 33 to +35
Copy link
Member

@devshgraphicsprogramming devshgraphicsprogramming Jul 17, 2025

Choose a reason for hiding this comment

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

where are you handling calculating smooth vertex normals vs cross product from positions


uint32_t3 indices;
switch (indexType)
Expand All @@ -51,42 +52,30 @@ float3 calculateSmoothNormals(int instID, int primID, SGeomInfo geom, float2 bar
}

float3 n0, n1, n2;
switch (instID)
switch (objType)
{
case OT_CUBE:
{
// TODO: document why the alignment is 2 here and nowhere else? isnt the `vertexStride` aligned to more than 2 anyway?
uint32_t v0 = vk::RawBufferLoad<uint32_t>(vertexBufferAddress + indices[0] * vertexStride, 2u);
uint32_t v1 = vk::RawBufferLoad<uint32_t>(vertexBufferAddress + indices[1] * vertexStride, 2u);
uint32_t v2 = vk::RawBufferLoad<uint32_t>(vertexBufferAddress + indices[2] * vertexStride, 2u);

n0 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v0).xyz);
n1 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v1).xyz);
n2 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v2).xyz);
}
break;
case OT_SPHERE:
case OT_RECTANGLE:
case OT_CYLINDER:
case OT_ARROW:
//case OT_ARROW:
case OT_CONE:
{
uint32_t v0 = vk::RawBufferLoad<uint32_t>(vertexBufferAddress + indices[0] * vertexStride);
uint32_t v1 = vk::RawBufferLoad<uint32_t>(vertexBufferAddress + indices[1] * vertexStride);
uint32_t v2 = vk::RawBufferLoad<uint32_t>(vertexBufferAddress + indices[2] * vertexStride);
uint32_t v0 = vk::RawBufferLoad<uint32_t>(normalBufferAddress + indices[0] * 4);
uint32_t v1 = vk::RawBufferLoad<uint32_t>(normalBufferAddress + indices[1] * 4);
uint32_t v2 = vk::RawBufferLoad<uint32_t>(normalBufferAddress + indices[2] * 4);

n0 = normalize(unpackNormals3x10(v0));
n1 = normalize(unpackNormals3x10(v1));
n2 = normalize(unpackNormals3x10(v2));
n0 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v0).xyz);
n1 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v1).xyz);
n2 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v2).xyz);
}
break;
case OT_RECTANGLE:
case OT_DISK:
case OT_ICOSPHERE:
default:
{
n0 = normalize(vk::RawBufferLoad<float3>(vertexBufferAddress + indices[0] * vertexStride));
n1 = normalize(vk::RawBufferLoad<float3>(vertexBufferAddress + indices[1] * vertexStride));
n2 = normalize(vk::RawBufferLoad<float3>(vertexBufferAddress + indices[2] * vertexStride));
n0 = normalize(vk::RawBufferLoad<float3>(normalBufferAddress + indices[0] * 12));
n1 = normalize(vk::RawBufferLoad<float3>(normalBufferAddress + indices[1] * 12));
n2 = normalize(vk::RawBufferLoad<float3>(normalBufferAddress + indices[2] * 12));
}
}

Expand Down
66 changes: 66 additions & 0 deletions 67_RayQueryGeometry/include/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,70 @@ using namespace nbl::examples;

#include "app_resources/common.hlsl"

namespace nbl::scene
{
enum ObjectType : uint8_t
{
OT_CUBE,
OT_SPHERE,
OT_CYLINDER,
OT_RECTANGLE,
OT_CONE,
OT_ICOSPHERE,

OT_COUNT,
OT_UNKNOWN = std::numeric_limits<uint8_t>::max()
};

static constexpr uint32_t s_smoothNormals[OT_COUNT] = { 0, 1, 1, 0, 1, 1 };

Choose a reason for hiding this comment

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

you can deduce from the Geometry not having a normal view


struct ObjectMeta
{
ObjectType type = OT_UNKNOWN;
std::string_view name = "Unknown";
};

struct ObjectDrawHookCpu
{
nbl::core::matrix3x4SIMD model;
ObjectMeta meta;
};

enum GeometryShader
{
GP_BASIC = 0,
GP_CONE,
GP_ICO,

GP_COUNT
};

struct ReferenceObjectCpu
{
ObjectMeta meta;
core::matrix3x4SIMD transform;
core::smart_refctd_ptr<ICPUPolygonGeometry> data;
};
Comment on lines +35 to +61

Choose a reason for hiding this comment

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

clean this up, there's no geometry shader, the model and transform matrices are probably not used


struct ReferenceObjectGpu
{
struct Bindings
{
nbl::asset::SBufferBinding<IGPUBuffer> vertex, index;
};

ObjectMeta meta;
Bindings bindings;
uint32_t vertexStride;
nbl::asset::E_INDEX_TYPE indexType = nbl::asset::E_INDEX_TYPE::EIT_UNKNOWN;
uint32_t indexCount = {};

const bool useIndex() const
{
return bindings.index.buffer && (indexType != E_INDEX_TYPE::EIT_UNKNOWN);
}
Comment on lines +65 to +79

Choose a reason for hiding this comment

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

lots unused stuff, or things which can be deduces from IGPUPolygonGeometry

};
}


#endif // _NBL_THIS_EXAMPLE_COMMON_H_INCLUDED_
Loading