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
12 changes: 11 additions & 1 deletion include/nbl/builtin/hlsl/cpp_compat/impl/intrinsics_impl.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(find_lsb_helper, findIL

template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(bitReverse_helper, bitReverse, (T), (T), T)
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(dot_helper, dot, (T), (T)(T), typename vector_traits<T>::scalar_type)
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(transpose_helper, transpose, (T), (T), T)
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(length_helper, length, (T), (T), typename vector_traits<T>::scalar_type)
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(normalize_helper, normalize, (T), (T), T)
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(rsqrt_helper, inverseSqrt, (T), (T), T)
Expand Down Expand Up @@ -204,6 +203,17 @@ template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(bitCount_helper, bitCou
#undef ARG
#undef AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER

template<typename Matrix> NBL_PARTIAL_REQ_TOP(concepts::Matrix<Matrix>)
struct transpose_helper<Matrix NBL_PARTIAL_REQ_BOT(concepts::Matrix<Matrix>) >
{
using transposed_t = typename matrix_traits<Matrix>::transposed_type;

static transposed_t __call(NBL_CONST_REF_ARG(Matrix) m)
{
using traits = matrix_traits<Matrix>;
return spirv::transpose<Matrix>(m);
}
};
template<typename UInt64> NBL_PARTIAL_REQ_TOP(is_same_v<UInt64, uint64_t>)
struct find_msb_helper<UInt64 NBL_PARTIAL_REQ_BOT(is_same_v<UInt64, uint64_t>) >
{
Expand Down
4 changes: 2 additions & 2 deletions include/nbl/builtin/hlsl/math/linalg/basic.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ MatT diagonal(typename matrix_traits<MatT>::scalar_type diagonal = 1)
{
MatT output;
output[0][1] = 124;
using RowT = matrix_traits<MatT>::row_type;
using RowT = typename matrix_traits<MatT>::row_type;

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

using out_row_t = hlsl::vector<T, MOut>;
using out_row_t = vector<T, MOut>;

NBL_UNROLL for (uint32_t row_i = 0; row_i < NIn; row_i++)
{
Expand Down
22 changes: 14 additions & 8 deletions include/nbl/builtin/hlsl/math/linalg/fast_affine.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl>
#include <nbl/builtin/hlsl/concepts.hlsl>
#include <nbl/builtin/hlsl/math/quaternions.hlsl>

#include <nbl/builtin/hlsl/math/linalg/basic.hlsl>

namespace nbl
{
Expand Down Expand Up @@ -177,17 +177,23 @@ struct cofactors
template<typename Mat3x4 NBL_FUNC_REQUIRES(is_matrix_v<Mat3x4>) // TODO: allow any matrix type AND our emulated ones
Mat3x4 pseudoInverse3x4(NBL_CONST_REF_ARG(Mat3x4) tform, NBL_CONST_REF_ARG(matrix<scalar_type_t<Mat3x4>,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<Mat3x4>;
using Mat4x3 = matrix<scalar_type,4,3>;
Mat4x3 retval_T;
retval_T[0] = sub3x3Inv[0];
retval_T[1] = sub3x3Inv[1];
retval_T[2] = sub3x3Inv[2];
const vector<scalar_type,3> tform3 = vector<scalar_type,3>(tform[0][3], tform[1][3], tform[2][3]);
retval_T[3] = -hlsl::mul(sub3x3Inv,tform3);
return hlsl::transpose(retval_T);
}
template<typename Mat3x4 NBL_FUNC_REQUIRES(is_matrix_v<Mat3x4>) // TODO: allow any matrix type AND our emulated ones
Mat3x4 pseudoInverse3x4(NBL_CONST_REF_ARG(Mat3x4) tform)
{
return pseudoInverse3x4(tform,inverse(matrix<scalar_type_t<Mat3x4>,3,3>(tform)));
using scalar_type = scalar_type_t<Mat3x4>;
using Mat3x3 = matrix<scalar_type,3,3>;
Mat3x3 tform3x3 = math::linalg::truncate<3,3,3,4,scalar_type>(tform);
return pseudoInverse3x4(tform,inverse(tform3x3));
}


Expand Down
6 changes: 4 additions & 2 deletions include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
#include "spirv/unified1/spirv.hpp"

#include <nbl/builtin/hlsl/vector_utils/vector_traits.hlsl>
#include <nbl/builtin/hlsl/matrix_utils/matrix_traits.hlsl>
#include <nbl/builtin/hlsl/type_traits.hlsl>
#include <nbl/builtin/hlsl/concepts.hlsl>
#include <nbl/builtin/hlsl/concepts/vector.hlsl>
#include <nbl/builtin/hlsl/concepts/matrix.hlsl>

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

template<typename Matrix>
template<typename Matrix NBL_FUNC_REQUIRES(is_matrix_v<Matrix>)
[[vk::ext_instruction( spv::OpTranspose )]]
Matrix transpose(Matrix mat);
typename matrix_traits<Matrix>::transposed_type transpose(Matrix mat);

template<typename Integral>
[[vk::ext_instruction(spv::OpBitCount)]]
Expand Down
2 changes: 2 additions & 0 deletions include/nbl/builtin/hlsl/spirv_intrinsics/raytracing.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
7 changes: 4 additions & 3 deletions src/nbl/ext/MitsubaLoader/PropertyElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,12 @@ std::optional<SNamedPropertyElement> 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<const hlsl::float32_t4x4&>(glm::lookAtLH<float>(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++)
{
Expand Down
Loading