File: LocalFB.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 (123 lines) | stat: -rw-r--r-- 3,808 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
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

// ospray
#include "fb/FrameBuffer.h"
// rkcommon
#include "rkcommon/containers/AlignedVector.h"
#include "rkcommon/utility/ArrayView.h"
// ispc shared
#include "LocalFBShared.h"
#include "TileShared.h"

namespace ospray {

struct SparseFrameBuffer;
struct LiveVarianceFrameOp;
struct LiveColorConversionFrameOp;

struct OSPRAY_SDK_INTERFACE LocalFrameBuffer
    : public AddStructShared<FrameBuffer, ispc::LocalFB>
{
  LocalFrameBuffer(api::ISPCDevice &device,
      const vec2i &size,
      ColorBufferFormat colorBufferFormat,
      const uint32 channels);

  ~LocalFrameBuffer() override;

  virtual void commit() override;

  // Return the number of render tasks in the x and y direction
  // This is the kernel launch dims to render the image
  virtual vec2i getNumRenderTasks() const override;

  virtual uint32_t getTotalRenderTasks() const override;

  virtual utility::ArrayView<uint32_t> getRenderTaskIDs(
      const float errorThreshold, const uint32_t spp) override;

  virtual float getVariance() const override;

  // common function to help printf-debugging, every derived class should
  // override this!
  virtual std::string toString() const override;

  devicert::AsyncEvent postProcess() override;

  const void *mapBuffer(OSPFrameBufferChannel channel) override;

  void unmap(const void *mappedMem) override;

  void clear() override;

  /* Write the tile into this framebuffer's row-major storage. This does not
   * perform accumulation or buffering, data is taken directly from the tile and
   * written to the row-major image stored by the LocalFrameBuffer
   * Safe to call in parallel from multiple threads, as long as each thread is
   * writing different tiles
   */
  void writeTiles(const utility::ArrayView<Tile> &tiles);

  /* Write the tiles of the sparse fb into this framebuffer's row-major storage.
   * Will also copy error data from the sparseFb the full framebuffer task error
   * buffer, if variance buffer is enabled.
   * Safe to call in parallel from multiple threads, as long as each thread is
   * writing different tiles
   */
  void writeTiles(SparseFrameBuffer *sparseFb);

  // NOTE: All per-pixel data is only allocated if the corresponding channel
  //       flag was passed on construction

  // one RGBA per pixel
  BufferDeviceShadowedUq<vec4f> colorBuffer;
  // one RGBA per pixel, post-processing output
  BufferDeviceShadowedUq<vec4f> ppColorBuffer;
  // one RGBA per pixel, does not accumulate all samples, for variance
  // estimation
  BufferDeviceUq<vec4f> varianceBuffer;
  // one float per pixel
  BufferDeviceShadowedUq<float> depthBuffer;
  // accumulated world-space normal per pixel
  BufferDeviceShadowedUq<vec3f> normalBuffer;
  // accumulated, one RGB per pixel
  BufferDeviceShadowedUq<vec3f> albedoBuffer;
  // primitive ID, object ID, and instance ID
  BufferDeviceShadowedUq<uint32_t> primitiveIDBuffer;
  BufferDeviceShadowedUq<uint32_t> objectIDBuffer;
  BufferDeviceShadowedUq<uint32_t> instanceIDBuffer;

 protected:
  vec2i getTaskStartPos(const uint32_t taskID) const;

  //// Data ////

  api::ISPCDevice &device;

  vec2i numRenderTasks;

  BufferDeviceShadowedUq<uint32_t> renderTaskIDs;
  BufferDeviceShadowedUq<uint32_t> activeTaskIDs;

  // Array of frame operations
  std::vector<std::unique_ptr<LiveFrameOpInterface>> frameOps;

  // Variance frame operation
  std::unique_ptr<LiveVarianceFrameOp> varianceFrameOp;

  // Color conversion frame operation
  std::unique_ptr<LiveColorConversionFrameOp> colorConversionFrameOp;

 private:
  float errorThreshold; // remember
  // Not used, to be removed after mpi module refactor
  float taskError(const uint32_t) const override
  {
    return 0.f;
  }
};

} // namespace ospray