Skip to content

Commit

Permalink
[WIP] use C++11 alignas for struct alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
freibold committed Nov 25, 2024
1 parent 6886428 commit c8fecb9
Show file tree
Hide file tree
Showing 23 changed files with 30 additions and 86 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ kernels/config.h
kernels/hash.h
include/embree4/rtcore_config.h
build
build*
out
4 changes: 1 addition & 3 deletions common/math/vec2fa.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ namespace embree
/// SSE Vec2fa Type
////////////////////////////////////////////////////////////////////////////////

struct __aligned(16) Vec2fa
struct alignas(16) Vec2fa
{
ALIGNED_STRUCT_(16);

typedef float Scalar;
enum { N = 2 };
union {
Expand Down
4 changes: 1 addition & 3 deletions common/math/vec2fa_sycl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ namespace embree
/// SSE Vec2fa Type
////////////////////////////////////////////////////////////////////////////////

struct __aligned(16) Vec2fa
struct alignas(16) Vec2fa
{
//ALIGNED_STRUCT_(16);

typedef float Scalar;
enum { N = 2 };
struct { float x,y; };
Expand Down
4 changes: 1 addition & 3 deletions common/math/vec3ba.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ namespace embree
/// SSE Vec3ba Type
////////////////////////////////////////////////////////////////////////////////

struct __aligned(16) Vec3ba
struct alignas(16) Vec3ba
{
ALIGNED_STRUCT_(16);

union {
__m128 m128;
struct { int x,y,z; };
Expand Down
4 changes: 1 addition & 3 deletions common/math/vec3ba_sycl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ namespace embree
/// SSE Vec3ba Type
////////////////////////////////////////////////////////////////////////////////

struct __aligned(16) Vec3ba
struct alignas(16) Vec3ba
{
//ALIGNED_STRUCT_(16);

struct { bool x,y,z; };

typedef bool Scalar;
Expand Down
8 changes: 2 additions & 6 deletions common/math/vec3fa.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ namespace embree
/// SSE Vec3fa Type
////////////////////////////////////////////////////////////////////////////////

struct __aligned(16) Vec3fa
struct alignas(16) Vec3fa
{
ALIGNED_STRUCT_(16);

typedef float Scalar;
enum { N = 3 };
union {
Expand Down Expand Up @@ -421,10 +419,8 @@ namespace embree
/// SSE Vec3fx Type
////////////////////////////////////////////////////////////////////////////////

struct __aligned(16) Vec3fx
struct alignas(16) Vec3fx
{
ALIGNED_STRUCT_(16);

typedef float Scalar;
enum { N = 3 };
union {
Expand Down
8 changes: 2 additions & 6 deletions common/math/vec3fa_sycl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ namespace embree
/// SSE Vec3fa Type
////////////////////////////////////////////////////////////////////////////////

struct __aligned(16) Vec3fa
struct alignas(16) Vec3fa
{
//ALIGNED_STRUCT_(16);

typedef float Scalar;
enum { N = 3 };
struct { float x,y,z, do_not_use; };
Expand Down Expand Up @@ -303,10 +301,8 @@ namespace embree
/// SSE Vec3fx Type
////////////////////////////////////////////////////////////////////////////////

struct __aligned(16) Vec3fx
struct alignas(16) Vec3fx
{
//ALIGNED_STRUCT_(16);

typedef float Scalar;
enum { N = 3 };
struct { float x,y,z; union { int a; unsigned u; float w; }; };
Expand Down
4 changes: 1 addition & 3 deletions common/math/vec3ia.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ namespace embree
/// SSE Vec3ia Type
////////////////////////////////////////////////////////////////////////////////

struct __aligned(16) Vec3ia
struct alignas(16) Vec3ia
{
ALIGNED_STRUCT_(16);

union {
__m128i m128;
struct { int x,y,z; };
Expand Down
4 changes: 1 addition & 3 deletions common/math/vec3ia_sycl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ namespace embree
/// SSE Vec3ia Type
////////////////////////////////////////////////////////////////////////////////

struct __aligned(16) Vec3ia
struct alignas(16) Vec3ia
{
ALIGNED_STRUCT_(16);

struct { int x,y,z; };

typedef int Scalar;
Expand Down
7 changes: 2 additions & 5 deletions common/tasking/taskschedulerinternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ namespace embree
hide is also in the API namespace when requested. */
RTC_NAMESPACE_BEGIN

struct TaskScheduler : public RefCount
struct alignas(64) TaskScheduler : public RefCount
{
ALIGNED_STRUCT_(64);
friend class Device;

static const size_t TASK_STACK_SIZE = 4*1024; //!< task structure stack
Expand Down Expand Up @@ -172,10 +171,8 @@ namespace embree
};

/*! thread local structure for each thread */
struct Thread
struct alignas(64) Thread
{
ALIGNED_STRUCT_(64);

Thread (size_t threadIndex, const Ref<TaskScheduler>& scheduler)
: threadIndex(threadIndex), task(nullptr), scheduler(scheduler) {}

Expand Down
8 changes: 2 additions & 6 deletions kernels/bvh/bvh_builder_subdiv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ namespace embree
typedef FastAllocator::CachedAllocator Allocator;

template<int N>
struct BVHNSubdivPatch1BuilderSAH : public Builder
struct alignas(64) BVHNSubdivPatch1BuilderSAH : public Builder
{
ALIGNED_STRUCT_(64);

typedef BVHN<N> BVH;
typedef typename BVH::NodeRef NodeRef;

Expand Down Expand Up @@ -211,10 +209,8 @@ namespace embree
};

template<int N>
struct BVHNSubdivPatch1MBlurBuilderSAH : public Builder
struct alignas(64) BVHNSubdivPatch1MBlurBuilderSAH : public Builder
{
ALIGNED_STRUCT_(64);

typedef BVHN<N> BVH;
typedef typename BVH::NodeRef NodeRef;
typedef typename BVH::NodeRecordMB4D NodeRecordMB4D;
Expand Down
6 changes: 1 addition & 5 deletions kernels/common/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace embree
device->refInc();

ptr = alloc(ptr_in, shared, EmbreeMemoryType::SHARED);

#if defined(EMBREE_SYCL_SUPPORT)
dshared = true;
dptr = ptr;
Expand All @@ -57,14 +56,11 @@ namespace embree
#endif
{
ptr = alloc(ptr_in, shared, EmbreeMemoryType::SHARED);
}

#if defined(EMBREE_SYCL_SUPPORT)
if (!dptr) {
dshared = true;
dptr = ptr;
}
#endif
}
}

/*! Buffer destruction */
Expand Down
1 change: 1 addition & 0 deletions kernels/common/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ namespace embree

Device::~Device ()
{
std::cout << "destructor device" << std::endl;
setCacheSize(0);
exitTaskingSystem();
}
Expand Down
4 changes: 1 addition & 3 deletions kernels/common/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ namespace embree
};

/*! Base class all geometries are derived from */
class Geometry : public RefCount
class alignas(16) Geometry : public RefCount
{
ALIGNED_CLASS_(16);

friend class Scene;
public:

Expand Down
4 changes: 1 addition & 3 deletions kernels/common/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ namespace embree
struct TaskGroup;

/*! Base class all scenes are derived from */
class Scene : public AccelN
class alignas(16) Scene : public AccelN
{
ALIGNED_CLASS_(std::alignment_of<Scene>::value);

public:
template<typename Ty, bool mblur = false>
class Iterator
Expand Down
1 change: 0 additions & 1 deletion kernels/common/scene_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace embree
/*! Instanced acceleration structure */
struct Instance : public Geometry
{
//ALIGNED_STRUCT_(16);
static const Geometry::GTypeMask geom_type = Geometry::MTY_INSTANCE;

public:
Expand Down
1 change: 0 additions & 1 deletion kernels/common/scene_instance_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace embree
/*! Instanced acceleration structure */
struct InstanceArray : public Geometry
{
//ALIGNED_STRUCT_(16);
static const Geometry::GTypeMask geom_type = Geometry::MTY_INSTANCE_ARRAY;

public:
Expand Down
1 change: 0 additions & 1 deletion kernels/common/scene_line_segments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ namespace embree
flags[i] |= hasRight * RTC_CURVE_FLAG_NEIGHBOR_RIGHT;
hasLeft = hasRight;
}
std::cout << "flags.buffer->commit()" << std::endl;
flags.buffer->commit();
}
segments.clearLocalModified();
Expand Down
10 changes: 3 additions & 7 deletions kernels/subdiv/catmullclark_ring.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@

namespace embree
{
struct __aligned(64) FinalQuad {
struct alignas(64) FinalQuad {
Vec3fa vtx[4];
};

template<typename Vertex, typename Vertex_t = Vertex>
struct __aligned(64) CatmullClark1RingT
struct alignas(64) CatmullClark1RingT
{
ALIGNED_STRUCT_(64);

int border_index; //!< edge index where border starts
unsigned int face_valence; //!< number of adjacent quad faces
unsigned int edge_valence; //!< number of adjacent edges (2*face_valence)
Expand Down Expand Up @@ -518,10 +516,8 @@ namespace embree
typedef CatmullClark1RingT<Vec3fa,Vec3fa_t> CatmullClark1Ring3fa;

template<typename Vertex, typename Vertex_t = Vertex>
struct __aligned(64) GeneralCatmullClark1RingT
struct alignas(64) GeneralCatmullClark1RingT
{
ALIGNED_STRUCT_(64);

typedef CatmullClark1RingT<Vertex,Vertex_t> CatmullClark1Ring;

struct Face
Expand Down
6 changes: 2 additions & 4 deletions kernels/subdiv/tessellation_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ namespace embree
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

struct __aligned(64) ThreadWorkState
struct alignas(64) ThreadWorkState
{
ALIGNED_STRUCT_(64);

std::atomic<size_t> counter;
ThreadWorkState* next;
bool allocated;
Expand All @@ -56,7 +54,7 @@ namespace embree
}
};

class __aligned(64) SharedLazyTessellationCache
class alignas(64) SharedLazyTessellationCache
{
public:

Expand Down
4 changes: 0 additions & 4 deletions kernels/sycl/rthwif_embree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,6 @@ __forceinline void trav_loop(intel_ray_query_t& query, Ray& ray, Scene* scene0,

SYCL_EXTERNAL __attribute__((always_inline)) void rtcIntersectRTHW(sycl::global_ptr<RTCTraversableTy> htraversable, sycl::private_ptr<RTCRayQueryContext> ucontext, sycl::private_ptr<RTCRayHit> rayhit_i, sycl::private_ptr<RTCIntersectArguments> args)
{
#if 0
Scene* scene = (Scene*) htraversable.get();

Scene* scenes[RTC_MAX_INSTANCE_LEVEL_COUNT];
Expand Down Expand Up @@ -824,12 +823,10 @@ SYCL_EXTERNAL __attribute__((always_inline)) void rtcIntersectRTHW(sycl::global_
}

intel_ray_query_abandon(query);
#endif
}

SYCL_EXTERNAL __attribute__((always_inline)) void rtcOccludedRTHW(sycl::global_ptr<RTCTraversableTy> htraversable, sycl::private_ptr<RTCRayQueryContext> ucontext, sycl::private_ptr<RTCRay> ray_i, sycl::private_ptr<RTCOccludedArguments> args)
{
#if 0
Scene* scene = (Scene*) htraversable.get();

Scene* scenes[RTC_MAX_INSTANCE_LEVEL_COUNT];
Expand Down Expand Up @@ -880,7 +877,6 @@ SYCL_EXTERNAL __attribute__((always_inline)) void rtcOccludedRTHW(sycl::global_p
ray_i->tfar = -INFINITY;

intel_ray_query_abandon(query);
#endif
}

RTC_NAMESPACE_END;
6 changes: 2 additions & 4 deletions tutorials/closest_point/closest_point_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ unsigned int g_line_index_buffer[g_num_point_queries] = {
// ======================================================================== //
// User defined instancing //
// ======================================================================== //
struct Instance
struct alignas(16) Instance
{
ALIGNED_STRUCT_(16)
RTCGeometry geometry;
RTCScene object;
int userID;
Expand Down Expand Up @@ -227,9 +226,8 @@ void updateInstance (RTCScene scene, Instance* instance)
// triangle mesh geometry //
// ======================================================================== //

struct TriangleMesh
struct alignas(16) TriangleMesh
{
ALIGNED_STRUCT_(16)
Vertex* vertices;
Triangle* triangles;
unsigned int num_vertices;
Expand Down
Loading

0 comments on commit c8fecb9

Please sign in to comment.