Skip to content

Commit 54153e6

Browse files
committed
Merge remote-tracking branch 'origin/master' into unroll-local-sync
2 parents 8b1f77d + 01ee867 commit 54153e6

6 files changed

Lines changed: 37 additions & 16 deletions

File tree

include/nbl/builtin/hlsl/cpp_compat/impl/intrinsics_impl.hlsl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(find_lsb_helper, findIL
159159

160160
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(bitReverse_helper, bitReverse, (T), (T), T)
161161
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(dot_helper, dot, (T), (T)(T), typename vector_traits<T>::scalar_type)
162-
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(transpose_helper, transpose, (T), (T), T)
163162
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(length_helper, length, (T), (T), typename vector_traits<T>::scalar_type)
164163
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(normalize_helper, normalize, (T), (T), T)
165164
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(rsqrt_helper, inverseSqrt, (T), (T), T)
@@ -204,6 +203,17 @@ template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(bitCount_helper, bitCou
204203
#undef ARG
205204
#undef AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER
206205

206+
template<typename Matrix> NBL_PARTIAL_REQ_TOP(concepts::Matrix<Matrix>)
207+
struct transpose_helper<Matrix NBL_PARTIAL_REQ_BOT(concepts::Matrix<Matrix>) >
208+
{
209+
using transposed_t = typename matrix_traits<Matrix>::transposed_type;
210+
211+
static transposed_t __call(NBL_CONST_REF_ARG(Matrix) m)
212+
{
213+
using traits = matrix_traits<Matrix>;
214+
return spirv::transpose<Matrix>(m);
215+
}
216+
};
207217
template<typename UInt64> NBL_PARTIAL_REQ_TOP(is_same_v<UInt64, uint64_t>)
208218
struct find_msb_helper<UInt64 NBL_PARTIAL_REQ_BOT(is_same_v<UInt64, uint64_t>) >
209219
{

include/nbl/builtin/hlsl/math/linalg/basic.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ MatT diagonal(typename matrix_traits<MatT>::scalar_type diagonal = 1)
2323
{
2424
MatT output;
2525
output[0][1] = 124;
26-
using RowT = matrix_traits<MatT>::row_type;
26+
using RowT = typename matrix_traits<MatT>::row_type;
2727

2828
NBL_UNROLL for (uint32_t i = 0; i < matrix_traits<MatT>::RowCount; ++i)
2929
{
@@ -84,7 +84,7 @@ matrix<T, NOut, MOut> promote_affine(const matrix<T, NIn, MIn> inMatrix)
8484
{
8585
matrix<T, NOut, MOut> retval;
8686

87-
using out_row_t = hlsl::vector<T, MOut>;
87+
using out_row_t = vector<T, MOut>;
8888

8989
NBL_UNROLL for (uint32_t row_i = 0; row_i < NIn; row_i++)
9090
{

include/nbl/builtin/hlsl/math/linalg/fast_affine.hlsl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl>
1010
#include <nbl/builtin/hlsl/concepts.hlsl>
1111
#include <nbl/builtin/hlsl/math/quaternions.hlsl>
12-
12+
#include <nbl/builtin/hlsl/math/linalg/basic.hlsl>
1313

1414
namespace nbl
1515
{
@@ -177,17 +177,23 @@ struct cofactors
177177
template<typename Mat3x4 NBL_FUNC_REQUIRES(is_matrix_v<Mat3x4>) // TODO: allow any matrix type AND our emulated ones
178178
Mat3x4 pseudoInverse3x4(NBL_CONST_REF_ARG(Mat3x4) tform, NBL_CONST_REF_ARG(matrix<scalar_type_t<Mat3x4>,3,3>) sub3x3Inv)
179179
{
180-
Mat3x4 retval;
181-
retval[0] = sub3x3Inv[0];
182-
retval[1] = sub3x3Inv[1];
183-
retval[2] = sub3x3Inv[2];
184-
retval[3] = -hlsl::mul(sub3x3Inv,tform[3]);
185-
return retval;
180+
using scalar_type = scalar_type_t<Mat3x4>;
181+
using Mat4x3 = matrix<scalar_type,4,3>;
182+
Mat4x3 retval_T;
183+
retval_T[0] = sub3x3Inv[0];
184+
retval_T[1] = sub3x3Inv[1];
185+
retval_T[2] = sub3x3Inv[2];
186+
const vector<scalar_type,3> tform3 = vector<scalar_type,3>(tform[0][3], tform[1][3], tform[2][3]);
187+
retval_T[3] = -hlsl::mul(sub3x3Inv,tform3);
188+
return hlsl::transpose(retval_T);
186189
}
187190
template<typename Mat3x4 NBL_FUNC_REQUIRES(is_matrix_v<Mat3x4>) // TODO: allow any matrix type AND our emulated ones
188191
Mat3x4 pseudoInverse3x4(NBL_CONST_REF_ARG(Mat3x4) tform)
189192
{
190-
return pseudoInverse3x4(tform,inverse(matrix<scalar_type_t<Mat3x4>,3,3>(tform)));
193+
using scalar_type = scalar_type_t<Mat3x4>;
194+
using Mat3x3 = matrix<scalar_type,3,3>;
195+
Mat3x3 tform3x3 = math::linalg::truncate<3,3,3,4,scalar_type>(tform);
196+
return pseudoInverse3x4(tform,inverse(tform3x3));
191197
}
192198

193199

include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
#include "spirv/unified1/spirv.hpp"
1111

1212
#include <nbl/builtin/hlsl/vector_utils/vector_traits.hlsl>
13+
#include <nbl/builtin/hlsl/matrix_utils/matrix_traits.hlsl>
1314
#include <nbl/builtin/hlsl/type_traits.hlsl>
1415
#include <nbl/builtin/hlsl/concepts.hlsl>
1516
#include <nbl/builtin/hlsl/concepts/vector.hlsl>
17+
#include <nbl/builtin/hlsl/concepts/matrix.hlsl>
1618

1719
namespace nbl
1820
{
@@ -331,9 +333,9 @@ template<typename Vector NBL_FUNC_REQUIRES(is_vector_v<Vector>)
331333
[[vk::ext_instruction( spv::OpDot )]]
332334
typename vector_traits<Vector>::scalar_type dot(Vector lhs, Vector rhs);
333335

334-
template<typename Matrix>
336+
template<typename Matrix NBL_FUNC_REQUIRES(is_matrix_v<Matrix>)
335337
[[vk::ext_instruction( spv::OpTranspose )]]
336-
Matrix transpose(Matrix mat);
338+
typename matrix_traits<Matrix>::transposed_type transpose(Matrix mat);
337339

338340
template<typename Integral>
339341
[[vk::ext_instruction(spv::OpBitCount)]]

include/nbl/builtin/hlsl/spirv_intrinsics/raytracing.hlsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ float2 rayQueryGetIntersectionBarycentricsKHR([[vk::ext_reference]] RayQueryKHR
7777
float2 rayQueryGetIntersectionFrontFaceKHR([[vk::ext_reference]] RayQueryKHR query, uint32_t committed);
7878

7979
// position fetch for ray tracing uses gl_HitTriangleVertexPositionsEXT -> HitTriangleVertexPositionsKHR decorated OpVariable
80+
[[vk::ext_capability(spv::CapabilityRayTracingPositionFetchKHR)]]
81+
[[vk::ext_extension("SPV_KHR_ray_tracing_position_fetch")]]
8082
[[vk::ext_builtin_input(spv::BuiltInHitTriangleVertexPositionsKHR)]]
8183
static const float32_t3 HitTriangleVertexPositionsKHR[3];
8284

src/nbl/ext/MitsubaLoader/PropertyElement.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,12 @@ std::optional<SNamedPropertyElement> CPropertyElementManager::createPropertyData
260260
}
261261
up[index] = 1.f;
262262
}
263-
// TODO: after the rm-core matrix PR we need to get rid of the tranpose (I transpose only because of GLM and HLSL mixup)
264-
const auto lookAtGLM = reinterpret_cast<const hlsl::float32_t4x4&>(glm::lookAtLH<float>(origin,target,up));
265-
const auto lookAt = hlsl::transpose(lookAtGLM);
263+
const auto lookAt = hlsl::math::linalg::rhLookAt(origin, target, up);
266264
// mitsuba understands look-at and right-handed camera little bit differently than I do
267265
const auto rotation = hlsl::inverse(hlsl::float32_t3x3(lookAt));
266+
for (auto i = 0; i < 3; i++)
267+
for (auto j = 0; j < 3; j++)
268+
result.mvalue[i][j] = rotation[i][j];
268269
// set the origin to avoid numerical issues
269270
for (auto r=0; r<3; r++)
270271
{

0 commit comments

Comments
 (0)