diff options
author | Clément Foucault <fclem> | 2022-09-02 19:30:48 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-09-02 19:45:14 +0300 |
commit | 65ad36f5fd71904e776f3deaf77e47b3935ae178 (patch) | |
tree | 8d9db20aa88d1de2934e888e1a345db8dfa25140 /source/blender/draw/intern/draw_command_shared.hh | |
parent | fd47fe4006a54559e0bc97b056a3503bd03e31b2 (diff) |
DRWManager: New implementation.
This is a new implementation of the draw manager using modern
rendering practices and GPU driven culling.
This only ports features that are not considered deprecated or to be
removed.
The old DRW API is kept working along side this new one, and does not
interfeer with it. However this needed some more hacking inside the
draw_view_lib.glsl. At least the create info are well separated.
The reviewer might start by looking at `draw_pass_test.cc` to see the
API in usage.
Important files are `draw_pass.hh`, `draw_command.hh`,
`draw_command_shared.hh`.
In a nutshell (for a developper used to old DRW API):
- `DRWShadingGroups` are replaced by `Pass<T>::Sub`.
- Contrary to DRWShadingGroups, all commands recorded inside a pass or
sub-pass (even binds / push_constant / uniforms) will be executed in order.
- All memory is managed per object (except for Sub-Pass which are managed
by their parent pass) and not from draw manager pools. So passes "can"
potentially be recorded once and submitted multiple time (but this is
not really encouraged for now). The only implicit link is between resource
lifetime and `ResourceHandles`
- Sub passes can be any level deep.
- IMPORTANT: All state propagate from sub pass to subpass. There is no
state stack concept anymore. Ensure the correct render state is set before
drawing anything using `Pass::state_set()`.
- The drawcalls now needs a `ResourceHandle` instead of an `Object *`.
This is to remove any implicit dependency between `Pass` and `Manager`.
This was a huge problem in old implementation since the manager did not
know what to pull from the object. Now it is explicitly requested by the
engine.
- The pases need to be submitted to a `draw::Manager` instance which can
be retrieved using `DRW_manager_get()` (for now).
Internally:
- All object data are stored in contiguous storage buffers. Removing a lot
of complexity in the pass submission.
- Draw calls are sorted and visibility tested on GPU. Making more modern
culling and better instancing usage possible in the future.
- Unit Tests have been added for regression testing and avoid most API
breakage.
- `draw::View` now contains culling data for all objects in the scene
allowing caching for multiple views.
- Bounding box and sphere final setup is moved to GPU.
- Some global resources locations have been hardcoded to reduce complexity.
What is missing:
- ~~Workaround for lack of gl_BaseInstanceARB.~~ Done
- ~~Object Uniform Attributes.~~ Done (Not in this patch)
- Workaround for hardware supporting a maximum of 8 SSBO.
Reviewed By: jbakker
Differential Revision: https://developer.blender.org/D15817
Diffstat (limited to 'source/blender/draw/intern/draw_command_shared.hh')
-rw-r--r-- | source/blender/draw/intern/draw_command_shared.hh | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/source/blender/draw/intern/draw_command_shared.hh b/source/blender/draw/intern/draw_command_shared.hh new file mode 100644 index 00000000000..22d1facfb09 --- /dev/null +++ b/source/blender/draw/intern/draw_command_shared.hh @@ -0,0 +1,87 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2022 Blender Foundation. */ + +/** \file + * \ingroup draw + */ + +#ifndef GPU_SHADER +# include "BLI_span.hh" +# include "GPU_shader_shared_utils.h" + +namespace blender::draw::command { + +struct RecordingState; + +#endif + +/* -------------------------------------------------------------------- */ +/** \name Multi Draw + * \{ */ + +/** + * A DrawGroup allow to split the command stream into batch-able chunks of commands with + * the same render state. + */ +struct DrawGroup { + /** Index of next DrawGroup from the same header. */ + uint next; + + /** Index of the first instances after sorting. */ + uint start; + /** Total number of instances (including inverted facing). Needed to issue the draw call. */ + uint len; + /** Number of non inverted scaling instances in this Group. */ + uint front_facing_len; + + /** GPUBatch values to be copied to DrawCommand after sorting (if not overriden). */ + int vertex_len; + int vertex_first; + int base_index; + + /** Atomic counters used during command sorting. */ + uint total_counter; + +#ifndef GPU_SHADER + /* NOTE: Union just to make sure the struct has always the same size on all platform. */ + union { + struct { + /** For debug printing only. */ + uint front_proto_len; + uint back_proto_len; + /** Needed to create the correct draw call. */ + GPUBatch *gpu_batch; + }; + struct { +#endif + uint front_facing_counter; + uint back_facing_counter; + uint _pad0, _pad1; +#ifndef GPU_SHADER + }; + }; +#endif +}; +BLI_STATIC_ASSERT_ALIGN(DrawGroup, 16) + +/** + * Representation of a future draw call inside a DrawGroup. This #DrawPrototype is then + * converted into #DrawCommand on GPU after visibility and compaction. Multiple + * #DrawPrototype might get merged into the same final #DrawCommand. + */ +struct DrawPrototype { + /* Reference to parent DrawGroup to get the GPUBatch vertex / instance count. */ + uint group_id; + /* Resource handle associated with this call. Also reference visibility. */ + uint resource_handle; + /* Number of instances. */ + uint instance_len; + uint _pad0; +}; +BLI_STATIC_ASSERT_ALIGN(DrawPrototype, 16) + +/** \} */ + +#ifndef GPU_SHADER +}; // namespace blender::draw::command +#endif |