godot/thirdparty/embree/kernels/geometry/pointi.h

// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "primitive.h"

namespace embree
{
  template<int M>
  struct PointMi
  {};

  template<>
  __forceinline void PointMi<4>::gather(Vec4vf4& p0, const Points* geom) const
  {}

  template<>
  __forceinline void PointMi<4>::gather(Vec4vf4& p0, Vec3vf4& n0, const Points* geom) const
  {}

  template<>
  __forceinline void PointMi<4>::gatheri(Vec4vf4& p0, const Points* geom, const int itime) const
  {}

  template<>
  __forceinline void PointMi<4>::gatheri(Vec4vf4& p0, Vec3vf4& n0, const Points* geom, const int itime) const
  {}

  template<>
  __forceinline void PointMi<4>::gather(Vec4vf4& p0, const Points* geom, float time) const
  {}

  template<>
  __forceinline void PointMi<4>::gather(Vec4vf4& p0, Vec3vf4& n0, const Points* geom, float time) const
  {}

#if defined(__AVX__)

  template<>
  __forceinline void PointMi<8>::gather(Vec4vf8& p0, const Points* geom) const
  {
    const vfloat4 a0 = vfloat4::loadu(geom->vertexPtr(primID(0)));
    const vfloat4 a1 = vfloat4::loadu(geom->vertexPtr(primID(1)));
    const vfloat4 a2 = vfloat4::loadu(geom->vertexPtr(primID(2)));
    const vfloat4 a3 = vfloat4::loadu(geom->vertexPtr(primID(3)));
    const vfloat4 a4 = vfloat4::loadu(geom->vertexPtr(primID(4)));
    const vfloat4 a5 = vfloat4::loadu(geom->vertexPtr(primID(5)));
    const vfloat4 a6 = vfloat4::loadu(geom->vertexPtr(primID(6)));
    const vfloat4 a7 = vfloat4::loadu(geom->vertexPtr(primID(7)));
    transpose(a0, a1, a2, a3, a4, a5, a6, a7, p0.x, p0.y, p0.z, p0.w);
  }

  template<>
  __forceinline void PointMi<8>::gather(Vec4vf8& p0, Vec3vf8& n0, const Points* geom) const
  {
    const vfloat4 a0 = vfloat4::loadu(geom->vertexPtr(primID(0)));
    const vfloat4 a1 = vfloat4::loadu(geom->vertexPtr(primID(1)));
    const vfloat4 a2 = vfloat4::loadu(geom->vertexPtr(primID(2)));
    const vfloat4 a3 = vfloat4::loadu(geom->vertexPtr(primID(3)));
    const vfloat4 a4 = vfloat4::loadu(geom->vertexPtr(primID(4)));
    const vfloat4 a5 = vfloat4::loadu(geom->vertexPtr(primID(5)));
    const vfloat4 a6 = vfloat4::loadu(geom->vertexPtr(primID(6)));
    const vfloat4 a7 = vfloat4::loadu(geom->vertexPtr(primID(7)));
    transpose(a0, a1, a2, a3, a4, a5, a6, a7, p0.x, p0.y, p0.z, p0.w);
    const vfloat4 b0 = vfloat4(geom->normal(primID(0)));
    const vfloat4 b1 = vfloat4(geom->normal(primID(1)));
    const vfloat4 b2 = vfloat4(geom->normal(primID(2)));
    const vfloat4 b3 = vfloat4(geom->normal(primID(3)));
    const vfloat4 b4 = vfloat4(geom->normal(primID(4)));
    const vfloat4 b5 = vfloat4(geom->normal(primID(5)));
    const vfloat4 b6 = vfloat4(geom->normal(primID(6)));
    const vfloat4 b7 = vfloat4(geom->normal(primID(7)));
    transpose(b0, b1, b2, b3, b4, b5, b6, b7, n0.x, n0.y, n0.z);
  }

  template<>
  __forceinline void PointMi<8>::gatheri(Vec4vf8& p0, const Points* geom, const int itime) const
  {
    const vfloat4 a0 = vfloat4::loadu(geom->vertexPtr(primID(0), itime));
    const vfloat4 a1 = vfloat4::loadu(geom->vertexPtr(primID(1), itime));
    const vfloat4 a2 = vfloat4::loadu(geom->vertexPtr(primID(2), itime));
    const vfloat4 a3 = vfloat4::loadu(geom->vertexPtr(primID(3), itime));
    const vfloat4 a4 = vfloat4::loadu(geom->vertexPtr(primID(4), itime));
    const vfloat4 a5 = vfloat4::loadu(geom->vertexPtr(primID(5), itime));
    const vfloat4 a6 = vfloat4::loadu(geom->vertexPtr(primID(6), itime));
    const vfloat4 a7 = vfloat4::loadu(geom->vertexPtr(primID(7), itime));
    transpose(a0, a1, a2, a3, a4, a5, a6, a7, p0.x, p0.y, p0.z, p0.w);
  }

  template<>
  __forceinline void PointMi<8>::gatheri(Vec4vf8& p0, Vec3vf8& n0, const Points* geom, const int itime) const
  {
    const vfloat4 a0 = vfloat4::loadu(geom->vertexPtr(primID(0), itime));
    const vfloat4 a1 = vfloat4::loadu(geom->vertexPtr(primID(1), itime));
    const vfloat4 a2 = vfloat4::loadu(geom->vertexPtr(primID(2), itime));
    const vfloat4 a3 = vfloat4::loadu(geom->vertexPtr(primID(3), itime));
    const vfloat4 a4 = vfloat4::loadu(geom->vertexPtr(primID(4), itime));
    const vfloat4 a5 = vfloat4::loadu(geom->vertexPtr(primID(5), itime));
    const vfloat4 a6 = vfloat4::loadu(geom->vertexPtr(primID(6), itime));
    const vfloat4 a7 = vfloat4::loadu(geom->vertexPtr(primID(7), itime));
    transpose(a0, a1, a2, a3, a4, a5, a6, a7, p0.x, p0.y, p0.z, p0.w);
    const vfloat4 b0 = vfloat4(geom->normal((size_t)primID(0), (size_t)itime));
    const vfloat4 b1 = vfloat4(geom->normal((size_t)primID(1), (size_t)itime));
    const vfloat4 b2 = vfloat4(geom->normal((size_t)primID(2), (size_t)itime));
    const vfloat4 b3 = vfloat4(geom->normal((size_t)primID(3), (size_t)itime));
    const vfloat4 b4 = vfloat4(geom->normal((size_t)primID(4), (size_t)itime));
    const vfloat4 b5 = vfloat4(geom->normal((size_t)primID(5), (size_t)itime));
    const vfloat4 b6 = vfloat4(geom->normal((size_t)primID(6), (size_t)itime));
    const vfloat4 b7 = vfloat4(geom->normal((size_t)primID(7), (size_t)itime));
    transpose(b0, b1, b2, b3, b4, b5, b6, b7, n0.x, n0.y, n0.z);
  }

  template<>
  __forceinline void PointMi<8>::gather(Vec4vf8& p0, const Points* geom, float time) const
  {
    float ftime;
    const int itime = geom->timeSegment(time, ftime);

    Vec4vf8 a0;
    gatheri(a0, geom, itime);
    Vec4vf8 b0;
    gatheri(b0, geom, itime + 1);
    p0 = lerp(a0, b0, vfloat8(ftime));
  }

  template<>
  __forceinline void PointMi<8>::gather(Vec4vf8& p0, Vec3vf8& n0, const Points* geom, float time) const
  {
    float ftime;
    const int itime = geom->timeSegment(time, ftime);

    Vec4vf8 a0, b0;
    Vec3vf8 norm0, norm1;
    gatheri(a0, norm0, geom, itime);
    gatheri(b0, norm1, geom, itime + 1);
    p0 = lerp(a0, b0, vfloat8(ftime));
    n0 = lerp(norm0, norm1, vfloat8(ftime));
  }
#endif

  template<int M>
  typename PointMi<M>::Type PointMi<M>::type;

  Point4i;
  Point8i;
  
}  // namespace embree