File: Data.ih

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 (103 lines) | stat: -rw-r--r-- 3,581 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
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "rkcommon/math/LinearSpace.ih"
#include "rkcommon/math/box.ih"

OSPRAY_BEGIN_ISPC_NAMESPACE

struct Data1D
{
  uint8 *addr;
  int64 byteStride;
  uint32 numItems;
  bool huge; // 64bit address calculation necessary
};

inline void Data1D_Constructor(Data1D *uniform self)
{
  self->addr = NULL;
  self->byteStride = 0;
  self->numItems = 0;
  self->huge = false;
}

// ok to pass-by-value, will be inlined and optimized
inline uniform bool valid(const uniform Data1D data)
{
  return data.addr != NULL;
}

// special 64-bit safe code:
#define BITS 20

template <typename T>
inline varying T get(const uniform Data1D &data, const varying int index)
{
  return *((const uniform T *)(data.addr + data.byteStride * index));
}

// ok to pass-by-value, will be inlined and optimized
#ifdef OSPRAY_TARGET_SYCL
// SYCL execution in a thread is scalar
// Old macro version (kept for compatibility with older code)
#define __define_get(T)                                                        \
  inline uniform T get_##T(const uniform Data1D data, const uniform int index) \
  {                                                                            \
    return *((const T *)(data.addr + data.byteStride * index));                \
  }
#else
#define __define_get(T)                                                        \
  inline T get_##T(const uniform Data1D data, const varying int index)         \
  {                                                                            \
    if (data.huge) {                                                           \
      T v;                                                                     \
      const int index_lo = index & ((1 << BITS) - 1);                          \
      const int index_hi = index - index_lo;                                   \
      const int scaledIndexLo = index_lo * data.byteStride;                    \
      foreach_unique (hi in index_hi) {                                        \
        /* uniform offset for upper bits */                                    \
        const uniform uint64 scaledIndexHi = (uint64)(hi)*data.byteStride;     \
        /* properly shifted base address (shifted by 64-bits) */               \
        const uint8 *uniform base_hi = data.addr + scaledIndexHi;              \
        v = *((const T *)(base_hi + scaledIndexLo));                           \
      }                                                                        \
      return v;                                                                \
    } else                                                                     \
      return *((const T *)(data.addr + data.byteStride * index));              \
  }                                                                            \
  inline uniform T get_##T(const uniform Data1D data, const uniform int index) \
  {                                                                            \
    return *((const T *)(data.addr + data.byteStride * index));                \
  }
#endif

__define_get(int32);
__define_get(vec2i);
__define_get(vec3i);
__define_get(vec4i);

__define_get(uint8);
__define_get(uint32);
__define_get(vec2ui);
__define_get(vec3ui);
__define_get(vec4ui);

__define_get(float);
__define_get(vec2f);
__define_get(vec3f);
__define_get(vec4f);

__define_get(box1f);
__define_get(box2f);
__define_get(box3f);
__define_get(box4f);

__define_get(linear3f);

#undef __define_get
#undef BITS

OSPRAY_END_ISPC_NAMESPACE