From 8e7615d38b1c134bbf3d586292d6274ff4e4d5ea Mon Sep 17 00:00:00 2001 From: keptsecret Date: Tue, 10 Mar 2026 16:26:56 +0700 Subject: [PATCH 1/6] fix spirv qualifiers for HitTriangleVertexPositionsKHR --- include/nbl/builtin/hlsl/spirv_intrinsics/raytracing.hlsl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/nbl/builtin/hlsl/spirv_intrinsics/raytracing.hlsl b/include/nbl/builtin/hlsl/spirv_intrinsics/raytracing.hlsl index 2e77ef6d25..86a5eb2299 100644 --- a/include/nbl/builtin/hlsl/spirv_intrinsics/raytracing.hlsl +++ b/include/nbl/builtin/hlsl/spirv_intrinsics/raytracing.hlsl @@ -77,6 +77,8 @@ float2 rayQueryGetIntersectionBarycentricsKHR([[vk::ext_reference]] RayQueryKHR float2 rayQueryGetIntersectionFrontFaceKHR([[vk::ext_reference]] RayQueryKHR query, uint32_t committed); // position fetch for ray tracing uses gl_HitTriangleVertexPositionsEXT -> HitTriangleVertexPositionsKHR decorated OpVariable +[[vk::ext_capability(spv::CapabilityRayTracingPositionFetchKHR)]] +[[vk::ext_extension("SPV_KHR_ray_tracing_position_fetch")]] [[vk::ext_builtin_input(spv::BuiltInHitTriangleVertexPositionsKHR)]] static const float32_t3 HitTriangleVertexPositionsKHR[3]; From b9ec10e1b7998f28ddae82a32e1624771d4c9362 Mon Sep 17 00:00:00 2001 From: keptsecret Date: Wed, 11 Mar 2026 11:58:44 +0700 Subject: [PATCH 2/6] fix transpose when matrix N!=M --- .../hlsl/cpp_compat/impl/intrinsics_impl.hlsl | 12 +++++++++++- include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl | 6 ++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/nbl/builtin/hlsl/cpp_compat/impl/intrinsics_impl.hlsl b/include/nbl/builtin/hlsl/cpp_compat/impl/intrinsics_impl.hlsl index cbaa0a7b7b..61081ea327 100644 --- a/include/nbl/builtin/hlsl/cpp_compat/impl/intrinsics_impl.hlsl +++ b/include/nbl/builtin/hlsl/cpp_compat/impl/intrinsics_impl.hlsl @@ -159,7 +159,6 @@ template AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(find_lsb_helper, findIL template AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(bitReverse_helper, bitReverse, (T), (T), T) template AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(dot_helper, dot, (T), (T)(T), typename vector_traits::scalar_type) -template AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(transpose_helper, transpose, (T), (T), T) template AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(length_helper, length, (T), (T), typename vector_traits::scalar_type) template AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(normalize_helper, normalize, (T), (T), T) template AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(rsqrt_helper, inverseSqrt, (T), (T), T) @@ -204,6 +203,17 @@ template AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(bitCount_helper, bitCou #undef ARG #undef AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER +template NBL_PARTIAL_REQ_TOP(concepts::Matrix) +struct transpose_helper) > +{ + using transposed_t = typename matrix_traits::transposed_type; + + static transposed_t __call(NBL_CONST_REF_ARG(Matrix) m) + { + using traits = matrix_traits; + return spirv::transpose(m); + } +}; template NBL_PARTIAL_REQ_TOP(is_same_v) struct find_msb_helper) > { diff --git a/include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl b/include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl index 9190a4ec73..3497babfeb 100644 --- a/include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl +++ b/include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl @@ -10,9 +10,11 @@ #include "spirv/unified1/spirv.hpp" #include +#include #include #include #include +#include namespace nbl { @@ -331,9 +333,9 @@ template) [[vk::ext_instruction( spv::OpDot )]] typename vector_traits::scalar_type dot(Vector lhs, Vector rhs); -template +template) [[vk::ext_instruction( spv::OpTranspose )]] -Matrix transpose(Matrix mat); +typename matrix_traits::transposed_type transpose(Matrix mat); template [[vk::ext_instruction(spv::OpBitCount)]] From cb13a6bbaf0bc0de0ab00a1a92709b6e02c2feaf Mon Sep 17 00:00:00 2001 From: keptsecret Date: Wed, 11 Mar 2026 11:59:48 +0700 Subject: [PATCH 3/6] fix pseudoInverse3x4, some bugs in linalg/basic.hlsl --- .../nbl/builtin/hlsl/math/linalg/basic.hlsl | 4 ++-- .../builtin/hlsl/math/linalg/fast_affine.hlsl | 22 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/nbl/builtin/hlsl/math/linalg/basic.hlsl b/include/nbl/builtin/hlsl/math/linalg/basic.hlsl index 64f923a521..61dd2544b1 100644 --- a/include/nbl/builtin/hlsl/math/linalg/basic.hlsl +++ b/include/nbl/builtin/hlsl/math/linalg/basic.hlsl @@ -23,7 +23,7 @@ MatT diagonal(typename matrix_traits::scalar_type diagonal = 1) { MatT output; output[0][1] = 124; - using RowT = matrix_traits::row_type; + using RowT = typename matrix_traits::row_type; NBL_UNROLL for (uint32_t i = 0; i < matrix_traits::RowCount; ++i) { @@ -84,7 +84,7 @@ matrix promote_affine(const matrix inMatrix) { matrix retval; - using out_row_t = hlsl::vector; + using out_row_t = vector; NBL_UNROLL for (uint32_t row_i = 0; row_i < NIn; row_i++) { diff --git a/include/nbl/builtin/hlsl/math/linalg/fast_affine.hlsl b/include/nbl/builtin/hlsl/math/linalg/fast_affine.hlsl index 605a107b83..1559a29d8b 100644 --- a/include/nbl/builtin/hlsl/math/linalg/fast_affine.hlsl +++ b/include/nbl/builtin/hlsl/math/linalg/fast_affine.hlsl @@ -9,7 +9,7 @@ #include #include #include - +#include namespace nbl { @@ -177,17 +177,23 @@ struct cofactors template) // TODO: allow any matrix type AND our emulated ones Mat3x4 pseudoInverse3x4(NBL_CONST_REF_ARG(Mat3x4) tform, NBL_CONST_REF_ARG(matrix,3,3>) sub3x3Inv) { - Mat3x4 retval; - retval[0] = sub3x3Inv[0]; - retval[1] = sub3x3Inv[1]; - retval[2] = sub3x3Inv[2]; - retval[3] = -hlsl::mul(sub3x3Inv,tform[3]); - return retval; + using scalar_type = scalar_type_t; + using Mat4x3 = matrix; + Mat4x3 retval_T; + retval_T[0] = sub3x3Inv[0]; + retval_T[1] = sub3x3Inv[1]; + retval_T[2] = sub3x3Inv[2]; + const vector tform3 = vector(tform[0][3], tform[1][3], tform[2][3]); + retval_T[3] = -hlsl::mul(sub3x3Inv,tform3); + return hlsl::transpose(retval_T); } template) // TODO: allow any matrix type AND our emulated ones Mat3x4 pseudoInverse3x4(NBL_CONST_REF_ARG(Mat3x4) tform) { - return pseudoInverse3x4(tform,inverse(matrix,3,3>(tform))); + using scalar_type = scalar_type_t; + using Mat3x3 = matrix; + Mat3x3 tform3x3 = math::linalg::truncate<3,3,3,4,scalar_type>(tform); + return pseudoInverse3x4(tform,inverse(tform3x3)); } From c545a597751aa72f91bfb985d5d06e98de046e26 Mon Sep 17 00:00:00 2001 From: keptsecret Date: Thu, 12 Mar 2026 15:00:01 +0700 Subject: [PATCH 4/6] fixes lookAt calculation for loading toWorld property in mitsuba scene --- src/nbl/ext/MitsubaLoader/PropertyElement.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/nbl/ext/MitsubaLoader/PropertyElement.cpp b/src/nbl/ext/MitsubaLoader/PropertyElement.cpp index 5ea0353a48..1f2d741dbb 100644 --- a/src/nbl/ext/MitsubaLoader/PropertyElement.cpp +++ b/src/nbl/ext/MitsubaLoader/PropertyElement.cpp @@ -258,10 +258,14 @@ std::optional CPropertyElementManager::createPropertyData up[index] = 1.f; } // TODO: after the rm-core matrix PR we need to get rid of the tranpose (I transpose only because of GLM and HLSL mixup) - const auto lookAtGLM = reinterpret_cast(glm::lookAtLH(origin,target,up)); - const auto lookAt = hlsl::transpose(lookAtGLM); + //const auto lookAtGLM = reinterpret_cast(glm::lookAtLH(origin,target,up)); + //const auto lookAt = hlsl::transpose(lookAtGLM); + const auto lookAt = hlsl::math::linalg::rhLookAt(origin, target, up); // mitsuba understands look-at and right-handed camera little bit differently than I do const auto rotation = hlsl::inverse(hlsl::float32_t3x3(lookAt)); + for (auto i = 0; i < 3; i++) + for (auto j = 0; j < 3; j++) + result.mvalue[i][j] = rotation[i][j]; // set the origin to avoid numerical issues for (auto r=0; r<3; r++) { From 1e907f4e74bf5f2028ff6a057b9f7363a721ec8f Mon Sep 17 00:00:00 2001 From: keptsecret Date: Thu, 12 Mar 2026 15:46:00 +0700 Subject: [PATCH 5/6] remove obsolete comments --- src/nbl/ext/MitsubaLoader/PropertyElement.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/nbl/ext/MitsubaLoader/PropertyElement.cpp b/src/nbl/ext/MitsubaLoader/PropertyElement.cpp index 1f2d741dbb..bcfeb5160e 100644 --- a/src/nbl/ext/MitsubaLoader/PropertyElement.cpp +++ b/src/nbl/ext/MitsubaLoader/PropertyElement.cpp @@ -257,9 +257,6 @@ std::optional CPropertyElementManager::createPropertyData } up[index] = 1.f; } - // TODO: after the rm-core matrix PR we need to get rid of the tranpose (I transpose only because of GLM and HLSL mixup) - //const auto lookAtGLM = reinterpret_cast(glm::lookAtLH(origin,target,up)); - //const auto lookAt = hlsl::transpose(lookAtGLM); const auto lookAt = hlsl::math::linalg::rhLookAt(origin, target, up); // mitsuba understands look-at and right-handed camera little bit differently than I do const auto rotation = hlsl::inverse(hlsl::float32_t3x3(lookAt)); From 140948104f5f39f07bdab339e41f82d59fc9a115 Mon Sep 17 00:00:00 2001 From: keptsecret Date: Fri, 13 Mar 2026 10:12:11 +0700 Subject: [PATCH 6/6] latest example --- examples_tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples_tests b/examples_tests index 1c36ceb370..147b5d1e44 160000 --- a/examples_tests +++ b/examples_tests @@ -1 +1 @@ -Subproject commit 1c36ceb370be1c402a8c8a3d76aa21d31a48f3ab +Subproject commit 147b5d1e4425f2c2411b2e93d0d828c96517d970