This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/draw/intern/draw_command_shared.hh
Miguel Pozo 59b9bb0849 Draw: Custom IDs
This pull request adds a new tipe of resource handles (thin handles).
These are intended for cases where a resource buffer with more than one
entry for each object is needed (for example, one entry per material
slot).
While it's already possible to have multiple regular handles for the
same object, they have a non-trivial overhead in terms of uploaded
data (matrix, bounds, object info) and computation (visibility
culling).
Thin handles store an indirection buffer pointing to their "parent"
regular handle, therefore multiple thin handles can share the same
per-object data and visibility culling computation.

Thin handles can only be used in their own Pass type (PassMainThin),
so passes that don't need them don't have to pay the overhead.

This pull request also includes the update of the Workbench Next
pre-pass to use PassMainThin, which is the main reason for the
implementation of this feature.

The main change from the previous PR is that the thin handles are now
stored directly in the main resource_id_buf, to avoid wasting an extra
 bind slot.

Pull Request #105261
2023-03-01 21:42:25 +01:00

87 lines
2.2 KiB
C++

/* 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 {
#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 overridden). */
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;
/* Custom extra value to be used by the engines. */
uint custom_id;
/* Number of instances. */
uint instance_len;
};
BLI_STATIC_ASSERT_ALIGN(DrawPrototype, 16)
/** \} */
#ifndef GPU_SHADER
}; // namespace blender::draw::command
#endif