Skip to content

Commit

Permalink
Added alignment definitions to RTCHitNt and RTCRayNt
Browse files Browse the repository at this point in the history
Added alignment definitions to RTCHitNt and RTCRayNt templates so they match the C definitions provided. As the alignment calculation is nasty without requiring the alignof keyword, or constexpr functions, this could instead be hidden behind a macro. Maybe RTC_ALIGN_SOA_AT_LEAST(N, MIN)?

The code is equivalent to:
```
constexpr std::size_t AlignSOAAtLeast(unsigned N, std::size_t min_alignment) noexcept {
    if (std::has_single_bit<unsigned>(N)) {
        return std::max<std::size_t>(min_alignment, N * alignof(float));
    } else {
        return min_alignment;
    }
}
```
Checking this works is as simple as adding a few static assertions:
```
static_assert(alignof(embree::RTCRayNt<1>) == alignof(embree::RTCRay));
static_assert(alignof(embree::RTCRayNt<4>) == alignof(embree::RTCRay4));
static_assert(alignof(embree::RTCRayNt<8>) == alignof(embree::RTCRay8));
static_assert(alignof(embree::RTCRayNt<16>) == alignof(embree::RTCRay16));
```
  • Loading branch information
dbs4261 authored and freibold committed Apr 30, 2024
1 parent 17fa6e8 commit 819aedb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/embree4/rtcore_ray.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ RTC_FORCEINLINE RTCRayN* RTCRayHitN_RayN(RTCRayHitN* rayhit, unsigned int N) { r
RTC_FORCEINLINE RTCHitN* RTCRayHitN_HitN(RTCRayHitN* rayhit, unsigned int N) { return (RTCHitN*)&((float*)rayhit)[12*N]; }

/* Helper structure for a ray packet of compile-time size N */
template<int N>
struct RTCRayNt
template<unsigned int N>
struct RTC_ALIGN((N && !(N & (N - 1)) ? (N * 4 > 16 ? N * 4 : 16) : 16)) RTCRayNt
{
float org_x[N];
float org_y[N];
Expand All @@ -245,8 +245,8 @@ struct RTCRayNt
};

/* Helper structure for a hit packet of compile-time size N */
template<int N>
struct RTCHitNt
template<unsigned int N>
struct RTC_ALIGN((N && !(N & (N - 1)) ? (N * 4 > 16 ? N * 4 : 16) : 16)) RTCHitNt
{
float Ng_x[N];
float Ng_y[N];
Expand Down

0 comments on commit 819aedb

Please sign in to comment.