diff options
Diffstat (limited to 'thirdparty/embree/kernels/common/device.h')
-rw-r--r-- | thirdparty/embree/kernels/common/device.h | 121 |
1 files changed, 115 insertions, 6 deletions
diff --git a/thirdparty/embree/kernels/common/device.h b/thirdparty/embree/kernels/common/device.h index 21c42c654d..c9e8888a5a 100644 --- a/thirdparty/embree/kernels/common/device.h +++ b/thirdparty/embree/kernels/common/device.h @@ -11,10 +11,57 @@ namespace embree { class BVH4Factory; class BVH8Factory; + struct TaskArena; class Device : public State, public MemoryMonitorInterface { ALIGNED_CLASS_(16); + + public: + + /*! allocator that performs unified shared memory allocations */ + template<typename T, size_t alignment> + struct allocator + { + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + allocator() {} + + allocator(Device* device) + : device(device) {} + + __forceinline pointer allocate( size_type n ) { + assert(device); + return (pointer) device->malloc(n*sizeof(T),alignment); + } + + __forceinline void deallocate( pointer p, size_type n ) { + if (device) device->free(p); + } + + __forceinline void construct( pointer p, const_reference val ) { + new (p) T(val); + } + + __forceinline void destroy( pointer p ) { + p->~T(); + } + + Device* device = nullptr; + }; + + /*! vector class that performs aligned allocations from Device object */ + template<typename T> + using vector = vector_t<T,allocator<T,std::alignment_of<T>::value>>; + + template<typename T, size_t alignment> + using avector = vector_t<T,allocator<T,alignment>>; public: @@ -54,6 +101,18 @@ namespace embree /*! gets a property */ ssize_t getProperty(const RTCDeviceProperty prop); + /*! enter device by setting up some global state */ + virtual void enter() {} + + /*! leave device by setting up some global state */ + virtual void leave() {} + + /*! buffer allocation */ + virtual void* malloc(size_t size, size_t align); + + /*! buffer deallocation */ + virtual void free(void* ptr); + private: /*! initializes the tasking system */ @@ -62,6 +121,13 @@ namespace embree /*! shuts down the tasking system */ void exitTaskingSystem(); + std::unique_ptr<TaskArena> arena; + + public: + + // use tasking system arena to execute func + void execute(bool join, const std::function<void()>& func); + /*! some variables that can be set via rtcSetParameter1i for debugging purposes */ public: static ssize_t debug_int0; @@ -74,12 +140,55 @@ namespace embree #if defined(EMBREE_TARGET_SIMD8) std::unique_ptr<BVH8Factory> bvh8_factory; #endif - -#if USE_TASK_ARENA - std::unique_ptr<tbb::task_arena> arena; + }; + +#if defined(EMBREE_SYCL_SUPPORT) + + class DeviceGPU : public Device + { + public: + + DeviceGPU(sycl::context sycl_context, const char* cfg); + ~DeviceGPU(); + + virtual void enter() override; + virtual void leave() override; + virtual void* malloc(size_t size, size_t align) override; + virtual void free(void* ptr) override; + + /* set SYCL device */ + void setSYCLDevice(const sycl::device sycl_device); + + private: + sycl::context gpu_context; + sycl::device gpu_device; + + unsigned int gpu_maxWorkGroupSize; + unsigned int gpu_maxComputeUnits; + + public: + void* dispatchGlobalsPtr = nullptr; + + public: + inline sycl::device &getGPUDevice() { return gpu_device; } + inline sycl::context &getGPUContext() { return gpu_context; } + + inline unsigned int getGPUMaxWorkGroupSize() { return gpu_maxWorkGroupSize; } + + void init_rthw_level_zero(); + void init_rthw_opencl(); + }; + #endif - - /* ray streams filter */ - RayStreamFilterFuncs rayStreamFilters; + + struct DeviceEnterLeave + { + DeviceEnterLeave (RTCDevice hdevice); + DeviceEnterLeave (RTCScene hscene); + DeviceEnterLeave (RTCGeometry hgeometry); + DeviceEnterLeave (RTCBuffer hbuffer); + ~DeviceEnterLeave(); + private: + Device* device; }; } |