1 // Copyright 2009-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 // ospray
7 #include "Device.h"
8 // embree
9 #include "embree3/rtcore.h"
10 // openvkl
11 #include "openvkl/openvkl.h"
12 
13 /*! \file ISPCDevice.h Implements the "local" device for local rendering */
14 
15 namespace ospray {
16 
17 struct LocalTiledLoadBalancer;
18 
19 namespace api {
20 
21 struct OSPRAY_SDK_INTERFACE ISPCDevice : public Device
22 {
23   ISPCDevice();
24   virtual ~ISPCDevice() override;
25 
26   /////////////////////////////////////////////////////////////////////////
27   // ManagedObject Implementation /////////////////////////////////////////
28   /////////////////////////////////////////////////////////////////////////
29 
30   void commit() override;
31 
32   /////////////////////////////////////////////////////////////////////////
33   // Device Implementation ////////////////////////////////////////////////
34   /////////////////////////////////////////////////////////////////////////
35 
36   int loadModule(const char *name) override;
37 
38   // OSPRay Data Arrays ///////////////////////////////////////////////////
39 
40   OSPData newSharedData(const void *sharedData,
41       OSPDataType,
42       const vec3ul &numItems,
43       const vec3l &byteStride) override;
44 
45   OSPData newData(OSPDataType, const vec3ul &numItems) override;
46 
47   void copyData(const OSPData source,
48       OSPData destination,
49       const vec3ul &destinationIndex) override;
50 
51   // Renderable Objects ///////////////////////////////////////////////////
52 
53   OSPLight newLight(const char *type) override;
54 
55   OSPCamera newCamera(const char *type) override;
56 
57   OSPGeometry newGeometry(const char *type) override;
58   OSPVolume newVolume(const char *type) override;
59 
60   OSPGeometricModel newGeometricModel(OSPGeometry geom) override;
61   OSPVolumetricModel newVolumetricModel(OSPVolume volume) override;
62 
63   // Model Meta-Data //////////////////////////////////////////////////////
64 
65   OSPMaterial newMaterial(
66       const char *renderer_type, const char *material_type) override;
67 
68   OSPTransferFunction newTransferFunction(const char *type) override;
69 
70   OSPTexture newTexture(const char *type) override;
71 
72   // Instancing ///////////////////////////////////////////////////////////
73 
74   OSPGroup newGroup() override;
75   OSPInstance newInstance(OSPGroup group) override;
76 
77   // Top-level Worlds /////////////////////////////////////////////////////
78 
79   OSPWorld newWorld() override;
80   box3f getBounds(OSPObject) override;
81 
82   // Object + Parameter Lifetime Management ///////////////////////////////
83 
84   void setObjectParam(OSPObject object,
85       const char *name,
86       OSPDataType type,
87       const void *mem) override;
88 
89   void removeObjectParam(OSPObject object, const char *name) override;
90 
91   void commit(OSPObject object) override;
92   void release(OSPObject _obj) override;
93   void retain(OSPObject _obj) override;
94 
95   // FrameBuffer Manipulation /////////////////////////////////////////////
96 
97   OSPFrameBuffer frameBufferCreate(const vec2i &size,
98       const OSPFrameBufferFormat mode,
99       const uint32 channels) override;
100 
101   OSPImageOperation newImageOp(const char *type) override;
102 
103   const void *frameBufferMap(
104       OSPFrameBuffer fb, const OSPFrameBufferChannel) override;
105 
106   void frameBufferUnmap(const void *mapped, OSPFrameBuffer fb) override;
107 
108   float getVariance(OSPFrameBuffer) override;
109 
110   void resetAccumulation(OSPFrameBuffer _fb) override;
111 
112   // Frame Rendering //////////////////////////////////////////////////////
113 
114   OSPRenderer newRenderer(const char *type) override;
115 
116   OSPFuture renderFrame(
117       OSPFrameBuffer, OSPRenderer, OSPCamera, OSPWorld) override;
118 
119   int isReady(OSPFuture, OSPSyncEvent) override;
120   void wait(OSPFuture, OSPSyncEvent) override;
121   void cancel(OSPFuture) override;
122   float getProgress(OSPFuture) override;
123   float getTaskDuration(OSPFuture) override;
124 
125   OSPPickResult pick(
126       OSPFrameBuffer, OSPRenderer, OSPCamera, OSPWorld, const vec2f &) override;
127 
128   std::shared_ptr<LocalTiledLoadBalancer> loadBalancer;
129 
130  private:
131   RTCDevice embreeDevice = nullptr;
132   VKLDevice vklDevice = nullptr;
133 };
134 
135 extern "C" OSPError OSPRAY_DLLEXPORT ospray_module_init_ispc(
136     int16_t versionMajor, int16_t versionMinor, int16_t /*versionPatch*/);
137 
138 } // namespace api
139 } // namespace ospray
140