Blender V4.3
session/display_driver.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "util/half.h"
8#include "util/types.h"
9
11
12/* Display driver for efficient interactive display of renders.
13 *
14 * Host applications implement this interface for viewport rendering. For best performance, we
15 * recommend:
16 * - Allocating a texture on the GPU to be interactively updated
17 * - Using the graphics interop mechanism to avoid CPU-GPU copying overhead
18 * - Using a dedicated or thread-safe graphics API context for updates, to avoid
19 * blocking the host application.
20 */
22 public:
23 DisplayDriver() = default;
24 virtual ~DisplayDriver() = default;
25
26 /* Render buffer parameters. */
27 struct Params {
28 public:
29 /* Render resolution, ignoring progressive resolution changes.
30 * The texture buffer should be allocated with this size. */
31 int2 size = make_int2(0, 0);
32
33 /* For border rendering, the full resolution of the render, and the offset within that larger
34 * render. */
37
38 bool modified(const Params &other) const
39 {
40 return !(full_offset == other.full_offset && full_size == other.full_size &&
41 size == other.size);
42 }
43 };
44
45 virtual void next_tile_begin() = 0;
46
47 /* Update the render from the rendering thread.
48 *
49 * Cycles periodically updates the render to be displayed. For multithreaded updates with
50 * potentially multiple rendering devices, it will call these methods as follows.
51 *
52 * if (driver.update_begin(params, width, height)) {
53 * parallel_for_each(rendering_device) {
54 * buffer = driver.map_texture_buffer();
55 * if (buffer) {
56 * fill(buffer);
57 * driver.unmap_texture_buffer();
58 * }
59 * }
60 * driver.update_end();
61 * }
62 *
63 * The parameters may dynamically change due to camera changes in the scene, and resources should
64 * be re-allocated accordingly.
65 *
66 * The width and height passed to update_begin() are the effective render resolution taking into
67 * account progressive resolution changes, which may be equal to or smaller than the params.size.
68 * For efficiency, changes in this resolution should be handled without re-allocating resources,
69 * but rather by using a subset of the full resolution buffer. */
70 virtual bool update_begin(const Params &params, int width, int height) = 0;
71 virtual void update_end() = 0;
72
73 /* Optionally flush outstanding display commands before ending the render loop. */
74 virtual void flush(){};
75
76 virtual half4 *map_texture_buffer() = 0;
77 virtual void unmap_texture_buffer() = 0;
78
79 /* Optionally return a handle to a native graphics API texture buffer. If supported,
80 * the rendering device may write directly to this buffer instead of calling
81 * map_texture_buffer() and unmap_texture_buffer(). */
83 public:
84 /* Dimensions of the buffer, in pixels. */
85 int buffer_width = 0;
87
88 /* OpenGL pixel buffer object. */
90
91 /* Clear the entire buffer before doing partial write to it. */
92 bool need_clear = false;
93
94 /* Enforce re-creation of the graphics interop object.
95 *
96 * When this field is true then the graphics interop will be re-created no matter what the
97 * rest of the configuration is.
98 * When this field is false the graphics interop will be re-created if the PBO or buffer size
99 * did change.
100 *
101 * This allows to ensure graphics interop is re-created when there is a possibility that an
102 * underlying PBO was re-allocated but did not change its ID. */
103 bool need_recreate = false;
104 };
105
107 {
108 return GraphicsInterop();
109 }
110
111 /* (De)activate graphics context required for editing or deleting the graphics interop
112 * object.
113 *
114 * For example, destruction of the CUDA object associated with an OpenGL requires the
115 * OpenGL context to be active. */
118
119 /* Clear the display buffer by filling it with zeros. */
120 virtual void clear() = 0;
121
122 /* Draw the render using the native graphics API.
123 *
124 * Note that this may be called in parallel to updates. The implementation is responsible for
125 * mutex locking or other mechanisms to avoid conflicts.
126 *
127 * The parameters may have changed since the last update. The implementation is responsible for
128 * deciding to skip or adjust render display for such changes.
129 *
130 * Host application drawing the render buffer should use Session.draw(), which will
131 * call this method. */
132 virtual void draw(const Params &params) = 0;
133};
134
virtual void update_end()=0
virtual void next_tile_begin()=0
virtual bool update_begin(const Params &params, int width, int height)=0
virtual GraphicsInterop graphics_interop_get()
virtual void draw(const Params &params)=0
DisplayDriver()=default
virtual half4 * map_texture_buffer()=0
virtual ~DisplayDriver()=default
virtual void clear()=0
virtual void unmap_texture_buffer()=0
virtual void graphics_interop_activate()
virtual void graphics_interop_deactivate()
#define CCL_NAMESPACE_END
ccl_device_forceinline int2 make_int2(const int x, const int y)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
__int64 int64_t
Definition stdint.h:89
bool modified(const Params &other) const
Definition half.h:61