File: ISPCDevice.h

package info (click to toggle)
ospray 3.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,048 kB
  • sloc: cpp: 80,569; ansic: 951; sh: 805; makefile: 170; python: 69
file content (197 lines) | stat: -rw-r--r-- 5,639 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

// ospray
#include "Device.h"
// device run-time
#include "DeviceRT.h"
// embree
#include "common/Embree.h"
#ifdef OSPRAY_ENABLE_VOLUMES
// openvkl
#include "openvkl/openvkl.h"
// comment break to prevent clang-format from reordering openvkl includes
#include "openvkl/device/openvkl.h"
#endif

/*! \file ISPCDevice.h Implements the "local" device for local rendering */

#ifdef OSPRAY_TARGET_SYCL
namespace ispc {
int ISPCDevice_programCount();
int ISPCDevice_isa();
} // namespace ispc
#endif

namespace ospray {

struct LocalTiledLoadBalancer;
struct MipMapCache;

namespace api {

struct OSPRAY_SDK_INTERFACE ISPCDevice : public Device
{
  ISPCDevice();
  ISPCDevice(std::unique_ptr<devicert::Device> device);
  virtual ~ISPCDevice() override;

  /////////////////////////////////////////////////////////////////////////
  // ManagedObject Implementation /////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////

  void commit() override;

  /////////////////////////////////////////////////////////////////////////
  // Device Implementation ////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////

  int loadModule(const char *name) override;

  // OSPRay Data Arrays ///////////////////////////////////////////////////

  OSPData newSharedData(const void *sharedData,
      OSPDataType,
      const vec3ul &numItems,
      const vec3l &byteStride,
      OSPDeleterCallback,
      const void *userPtr) override;

  OSPData newData(OSPDataType, const vec3ul &numItems) override;

  void copyData(const OSPData source,
      OSPData destination,
      const vec3ul &destinationIndex) override;

  // Renderable Objects ///////////////////////////////////////////////////

  OSPLight newLight(const char *type) override;

  OSPCamera newCamera(const char *type) override;

  OSPGeometry newGeometry(const char *type) override;
  OSPVolume newVolume(const char *type) override;

  OSPGeometricModel newGeometricModel(OSPGeometry geom) override;
  OSPVolumetricModel newVolumetricModel(OSPVolume volume) override;

  // Model Meta-Data //////////////////////////////////////////////////////

  OSPMaterial newMaterial(const char *material_type) override;

  OSPTransferFunction newTransferFunction(const char *type) override;

  OSPTexture newTexture(const char *type) override;

  // Instancing ///////////////////////////////////////////////////////////

  OSPGroup newGroup() override;
  OSPInstance newInstance(OSPGroup group) override;

  // Top-level Worlds /////////////////////////////////////////////////////

  OSPWorld newWorld() override;
  box3f getBounds(OSPObject) override;

  // Object + Parameter Lifetime Management ///////////////////////////////

  void setObjectParam(OSPObject object,
      const char *name,
      OSPDataType type,
      const void *mem) override;

  void removeObjectParam(OSPObject object, const char *name) override;

  void commit(OSPObject object) override;
  void release(OSPObject _obj) override;
  void retain(OSPObject _obj) override;

  // FrameBuffer Manipulation /////////////////////////////////////////////

  OSPFrameBuffer frameBufferCreate(const vec2i &size,
      const OSPFrameBufferFormat mode,
      const uint32 channels) override;

  OSPImageOperation newImageOp(const char *type) override;

  const void *frameBufferMap(
      OSPFrameBuffer fb, const OSPFrameBufferChannel) override;

  void frameBufferUnmap(const void *mapped, OSPFrameBuffer fb) override;

  float getVariance(OSPFrameBuffer) override;

  void resetAccumulation(OSPFrameBuffer _fb) override;

  // Frame Rendering //////////////////////////////////////////////////////

  OSPRenderer newRenderer(const char *type) override;

  OSPFuture renderFrame(
      OSPFrameBuffer, OSPRenderer, OSPCamera, OSPWorld) override;

  int isReady(OSPFuture, OSPSyncEvent) override;
  void wait(OSPFuture, OSPSyncEvent) override;
  void cancel(OSPFuture) override;
  float getProgress(OSPFuture) override;
  float getTaskDuration(OSPFuture) override;

  OSPPickResult pick(
      OSPFrameBuffer, OSPRenderer, OSPCamera, OSPWorld, const vec2f &) override;

  std::shared_ptr<LocalTiledLoadBalancer> loadBalancer;

  RTCDevice getEmbreeDevice()
  {
    return embreeDevice;
  }

#ifdef OSPRAY_ENABLE_VOLUMES
  VKLDevice getVklDevice()
  {
    return vklDevice;
  }
#endif

  inline devicert::Device &getDRTDevice()
  {
    return *drtDevice;
  }

#ifdef OSPRAY_TARGET_SYCL
  /* Compute the rounded dispatch global size for the given work group size.
   * SYCL requires that globalSize % workgroupSize == 0, this function will
   * round up globalSize and return nd_range(roundedSize, workgroupSize).
   * The kernel being launched must discard tasks that are out of bounds
   * bounds due to this rounding
   */
  sycl::nd_range<1> computeDispatchRange(
      const size_t globalSize, const size_t workgroupSize) const;
#endif

  inline MipMapCache &getMipMapCache()
  {
    return *mipMapCache;
  }

 private:
  std::unique_ptr<devicert::Device> drtDevice;

  RTCDevice embreeDevice = nullptr;
#ifdef OSPRAY_ENABLE_VOLUMES
  VKLDevice vklDevice = nullptr;
#endif

  // External SYCL context and device
  void *appSyclCtx{nullptr};
  void *appSyclDevice{nullptr};

  // Device-wide MIP map cache is needed because the same texture data objects
  // (and thus generated MIP maps) can be shared among many textures
  std::unique_ptr<MipMapCache> mipMapCache;
};

} // namespace api
} // namespace ospray