34#define DEBUG_UBO_BINDING
205 write_mask,
blend, culling_test, depth_test, stencil_test, stencil_op, provoking_vert);
290 DST.
state &= ~DRW_STATE_DEPTH_TEST_ENABLED;
343 return (culling->
mask & view->culling_mask) != 0;
358 const float (*frustum_planes)[4],
362 if (bsphere->
radius < 0.0f) {
368 float radius_sum = bsphere->
radius + frustum_bsphere->
radius;
369 if (center_dist_sq >
square_f(radius_sum)) {
377 for (
int p = 0; p < 6; p++) {
379 if (dist < -bsphere->radius) {
389 for (
int p = 0; p < 6; p++) {
391 for (
int v = 0;
v < 8;
v++) {
410 for (
int c = 0; c < 8; c++) {
442 for (
int i = 6; i--;) {
443 float frustum_plane_local[4], bb_near[3], bb_far[3];
444 mul_v4_m4v4(frustum_plane_local, tobmat, view->frustum_planes[i]);
464 memcpy(planes, view->frustum_planes,
sizeof(
float[6][4]));
469 view = view->parent ? view->parent :
view;
473 if (!view->is_dirty) {
486 &view->frustum_bsphere, view->frustum_planes, &cull->
bsphere);
488#ifdef DRW_DEBUG_CULLING
489 if (
G.debug_value != 0) {
501 if (view->visibility_fn) {
502 culled = !view->visibility_fn(!culled, cull->
user_data);
509 view->is_dirty =
false;
526 if (obmat_loc != -1) {
529 if (obinv_loc != -1) {
542 blender::gpu::Batch *geom,
550 inst_count =
max_ii(0, inst_count);
552 if (baseinst_loc != -1) {
569 if (
state->inst_count == 0) {
572 if (
state->baseinst_loc == -1) {
591#define MAX_UNIFORM_STACK_SIZE 64
594 int array_uniform_loc = -1;
596 float mat4_stack[4 * 4];
600 DRWUniform *uni = unichunk->uniforms + unichunk->uniform_used - 1;
602 for (
int i = 0; i < unichunk->uniform_used; i++, uni--) {
609 if (array_uniform_loc == -1) {
616 array_index -= uni->
length;
617 memcpy(&mat4_stack[array_index], uni->
fvalue,
sizeof(
float) * uni->
length);
619 if (array_index <= 0) {
621 array_uniform_loc = -1;
640 static_cast<const int *
>(uni->
pvalue));
654 static_cast<const float *
>(uni->
pvalue));
745 blender::gpu::Batch *
batch,
748 const bool is_instancing = (
batch->inst[0] !=
nullptr);
754 int *select_id =
state->select_buf->data<
int>().
data();
757 if (!is_instancing) {
767 while (start < tot) {
812 if (neg_scale !=
state->neg_scale) {
813 state->neg_scale = neg_scale;
818 if (
state->resource_chunk != chunk) {
819 if (
state->chunkid_loc != -1) {
822 if (
state->obmats_loc != -1) {
826 if (
state->obinfos_loc != -1) {
830 if (
state->obattrs_loc != -1) {
834 state->resource_chunk = chunk;
837 if (
state->resourceid_loc != -1) {
839 if (
state->resource_id !=
id) {
841 state->resource_id = id;
851 state->batch =
nullptr;
852 state->inst_count = 0;
853 state->base_inst = -1;
858 blender::gpu::Batch *
batch,
864 bool do_base_instance)
871 if (
state->obmats_loc == -1 && (
state->obmat_loc != -1 ||
state->obinv_loc != -1)) {
876 if (
state->select_buf !=
nullptr) {
890 state->baseinst_loc);
897 blender::gpu::Batch *
batch,
899 GPUStorageBuf *indirect_buf)
914 state->neg_scale =
false;
915 state->resource_chunk = 0;
916 state->resource_id = -1;
917 state->base_inst = 0;
918 state->inst_count = 0;
919 state->batch =
nullptr;
921 state->select_id = -1;
922 state->select_buf =
nullptr;
934 if ((
state->neg_scale != neg_scale) ||
935 (
state->resource_chunk != chunk) ||
942 state->inst_count = 1;
943 state->base_inst = id;
948 else if (
id !=
state->base_inst +
state->inst_count) {
951 state->inst_count = 1;
952 state->base_inst = id;
967 if (
state->neg_scale) {
970 if (
state->obmats_loc != -1) {
973 if (
state->obinfos_loc != -1) {
976 if (
state->obattrs_loc != -1) {
979 if (
state->vlattrs_loc != -1) {
990 state.obinfos_loc = -1;
991 state.obattrs_loc = -1;
992 state.vlattrs_loc = -1;
993 state.baseinst_loc = -1;
994 state.chunkid_loc = -1;
995 state.resourceid_loc = -1;
996 state.obmat_loc = -1;
997 state.obinv_loc = -1;
998 state.obattrs_ubo =
nullptr;
1003 bool use_tfeedback =
false;
1005 if (shader_changed) {
1060 cmd->clear.g / 255.0f,
1061 cmd->clear.b / 255.0f,
1062 cmd->clear.a / 255.0f},
1164 if (use_tfeedback) {
1182 if (pass->original) {
1183 start_group = pass->original->shgroups.
first;
1184 end_group = pass->original->shgroups.
last;
1187 if (start_group ==
nullptr) {
1194 "DRW_render_instance_buffer_finish had not been called before drawing");
1218 if (shgroup == end_group) {
1256 for (; pass; pass = pass->next) {
#define BLI_assert_msg(a, msg)
MINLINE int max_ii(int a, int b)
MINLINE float square_f(float a)
MINLINE float plane_point_side_v3(const float plane[4], const float co[3])
void aabb_get_near_far_from_plane(const float plane_no[3], const float bbmin[3], const float bbmax[3], float bb_near[3], float bb_afar[3])
void mul_v4_m4v4(float r[4], const float mat[4][4], const float v[4])
void transpose_m4_m4(float R[4][4], const float M[4][4])
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void BLI_memblock_iternew(BLI_memblock *mblk, BLI_memblock_iter *iter) ATTR_NONNULL()
void * BLI_memblock_iterstep(BLI_memblock_iter *iter) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
#define UNUSED_VARS_NDEBUG(...)
#define SET_FLAG_FROM_TEST(value, test, flag)
void GPU_batch_draw_advanced(blender::gpu::Batch *batch, int vertex_first, int vertex_count, int instance_first, int instance_count)
void GPU_batch_draw_indirect(blender::gpu::Batch *batch, GPUStorageBuf *indirect_buf, intptr_t offset)
void GPU_batch_set_shader(blender::gpu::Batch *batch, GPUShader *shader)
void GPU_compute_dispatch(GPUShader *shader, uint groups_x_len, uint groups_y_len, uint groups_z_len)
void GPU_draw_list_append(GPUDrawList *list, blender::gpu::Batch *batch, int i_first, int i_count)
void GPU_draw_list_submit(GPUDrawList *list)
GPUFrameBuffer * GPU_framebuffer_active_get()
void GPU_framebuffer_clear(GPUFrameBuffer *framebuffer, eGPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, unsigned int clear_stencil)
bool GPU_select_load_id(unsigned int id)
void GPU_shader_uniform_int_ex(GPUShader *shader, int location, int length, int array_size, const int *value)
bool GPU_shader_transform_feedback_enable(GPUShader *shader, blender::gpu::VertBuf *vertbuf)
void GPU_shader_uniform_float_ex(GPUShader *shader, int location, int length, int array_size, const float *value)
void GPU_shader_transform_feedback_disable(GPUShader *shader)
void GPU_shader_bind(GPUShader *shader)
void GPU_memory_barrier(eGPUBarrier barrier)
void GPU_program_point_size(bool enable)
@ GPU_BLEND_ADDITIVE_PREMULT
@ GPU_BLEND_ALPHA_UNDER_PREMUL
@ GPU_BLEND_ALPHA_PREMULT
void GPU_line_width(float width)
void GPU_line_smooth(bool enable)
eGPUDepthTest GPU_depth_test_get()
void GPU_stencil_write_mask_set(uint write_mask)
void GPU_depth_range(float near, float far)
void GPU_stencil_reference_set(uint reference)
@ GPU_STENCIL_OP_COUNT_DEPTH_FAIL
@ GPU_STENCIL_OP_COUNT_DEPTH_PASS
void GPU_stencil_compare_mask_set(uint compare_mask)
void GPU_front_facing(bool invert)
void GPU_point_size(float size)
@ GPU_DEPTH_GREATER_EQUAL
void GPU_state_set(eGPUWriteMask write_mask, eGPUBlend blend, eGPUFaceCullTest culling_test, eGPUDepthTest depth_test, eGPUStencilTest stencil_test, eGPUStencilOp stencil_op, eGPUProvokingVertex provoking_vert)
bool GPU_depth_mask_get()
void GPU_clip_distances(int distances_enabled)
void GPU_provoking_vertex(eGPUProvokingVertex vert)
void GPU_shadow_offset(bool enable)
void GPU_storagebuf_bind(GPUStorageBuf *ssbo, int slot)
void GPU_storagebuf_debug_unbind_all()
void GPU_texture_bind_ex(GPUTexture *texture, GPUSamplerState state, int unit)
void GPU_texture_image_unbind_all()
void GPU_texture_image_bind(GPUTexture *texture, int unit)
void GPU_texture_unbind_all()
void GPU_vertbuf_bind_as_ssbo(blender::gpu::VertBuf *verts, int binding)
void GPU_vertbuf_bind_as_texture(blender::gpu::VertBuf *verts, int binding)
uint GPU_vertbuf_get_vertex_len(const blender::gpu::VertBuf *verts)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void DRW_debug_sphere(const float center[3], float radius, const float color[4])
GPUUniformBuf * drw_ensure_layer_attribute_buffer()
DRWSparseUniformBuf * DRW_uniform_attrs_pool_find_ubo(GHash *table, const GPUUniformAttrList *key)
void DRW_sparse_uniform_buffer_unbind(DRWSparseUniformBuf *buffer, int chunk)
void DRW_sparse_uniform_buffer_bind(DRWSparseUniformBuf *buffer, int chunk, int location)
BLI_INLINE void * DRW_memblock_elem_from_handle(BLI_memblock *memblock, const DRWResourceHandle *handle)
@ DRW_UNIFORM_VERTEX_BUFFER_AS_TEXTURE_REF
@ DRW_UNIFORM_BLOCK_OBINFOS
@ DRW_UNIFORM_TFEEDBACK_TARGET
@ DRW_UNIFORM_TEXTURE_REF
@ DRW_UNIFORM_MODEL_MATRIX
@ DRW_UNIFORM_VERTEX_BUFFER_AS_STORAGE
@ DRW_UNIFORM_MODEL_MATRIX_INVERSE
@ DRW_UNIFORM_VERTEX_BUFFER_AS_STORAGE_REF
@ DRW_UNIFORM_BASE_INSTANCE
@ DRW_UNIFORM_BLOCK_OBMATS
@ DRW_UNIFORM_RESOURCE_ID
@ DRW_UNIFORM_STORAGE_BLOCK_REF
@ DRW_UNIFORM_VERTEX_BUFFER_AS_TEXTURE
@ DRW_UNIFORM_RESOURCE_CHUNK
@ DRW_UNIFORM_BLOCK_OBATTRS
@ DRW_UNIFORM_STORAGE_BLOCK
@ DRW_UNIFORM_BLOCK_VLATTRS
BLI_INLINE uint32_t DRW_handle_chunk_get(const DRWResourceHandle *handle)
eDRWCommandType command_type_get(const uint64_t *command_type_bits, int index)
@ DRW_CMD_COMPUTE_INDIRECT
@ DRW_CMD_DRAW_INSTANCE_RANGE
@ DRW_CMD_DRAW_PROCEDURAL
BLI_INLINE uint32_t DRW_handle_negative_scale_get(const DRWResourceHandle *handle)
BLI_INLINE uint32_t DRW_handle_id_get(const DRWResourceHandle *handle)
uint32_t DRWResourceHandle
BLI_INLINE void draw_legacy_matrix_update(DRWShadingGroup *shgroup, DRWResourceHandle *handle, float obmat_loc, float obinv_loc)
bool DRW_culling_plane_test(const DRWView *view, const float plane[4])
static void draw_call_batching_finish(DRWShadingGroup *shgroup, DRWCommandsState *state)
static bool draw_culling_sphere_test(const BoundSphere *frustum_bsphere, const float(*frustum_planes)[4], const BoundSphere *bsphere)
static void draw_update_uniforms(DRWShadingGroup *shgroup, DRWCommandsState *state, bool *use_tfeedback)
bool DRW_culling_sphere_test(const DRWView *view, const BoundSphere *bsphere)
static void drw_draw_pass_ex(DRWPass *pass, DRWShadingGroup *start_group, DRWShadingGroup *end_group)
BLI_INLINE void draw_geometry_execute(DRWShadingGroup *shgroup, blender::gpu::Batch *geom, int vert_first, int vert_count, int inst_first, int inst_count, int baseinst_loc)
static void draw_call_batching_flush(DRWShadingGroup *shgroup, DRWCommandsState *state)
void DRW_draw_pass(DRWPass *pass)
static bool draw_culling_plane_test(const BoundBox *corners, const float plane[4])
void drw_state_set(DRWState state)
void DRW_view_set_active(const DRWView *view)
static void draw_call_single_do(DRWShadingGroup *shgroup, DRWCommandsState *state, blender::gpu::Batch *batch, DRWResourceHandle handle, int vert_first, int vert_count, int inst_first, int inst_count, bool do_base_instance)
void DRW_culling_frustum_planes_get(const DRWView *view, float planes[6][4])
static void draw_call_batching_do(DRWShadingGroup *shgroup, DRWCommandsState *state, DRWCommandDraw *call)
static DRWCommand * draw_command_iter_step(DRWCommandIterator *iter, eDRWCommandType *cmd_type)
static void drw_stencil_state_set(uint write_mask, uint reference, uint compare_mask)
void DRW_culling_frustum_corners_get(const DRWView *view, BoundBox *corners)
static void draw_command_iter_begin(DRWCommandIterator *iter, DRWShadingGroup *shgroup)
static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
static void drw_state_validate()
static bool draw_call_is_culled(const DRWResourceHandle *handle, DRWView *view)
void DRW_state_reset_ex(DRWState state)
static void draw_call_resource_bind(DRWCommandsState *state, const DRWResourceHandle *handle)
BLI_INLINE void draw_select_buffer(DRWShadingGroup *shgroup, DRWCommandsState *state, blender::gpu::Batch *batch, const DRWResourceHandle *handle)
void DRW_draw_pass_subset(DRWPass *pass, DRWShadingGroup *start_group, DRWShadingGroup *end_group)
BLI_INLINE void draw_indirect_call(DRWShadingGroup *shgroup, DRWCommandsState *state)
static void drw_update_view()
void DRW_state_lock(DRWState state)
BLI_INLINE void draw_geometry_bind(DRWShadingGroup *shgroup, blender::gpu::Batch *geom)
bool DRW_culling_min_max_test(const DRWView *view, float obmat[4][4], float min[3], float max[3])
static bool draw_culling_box_test(const float(*frustum_planes)[4], const BoundBox *bbox)
static void draw_call_indirect(DRWShadingGroup *shgroup, DRWCommandsState *state, blender::gpu::Batch *batch, DRWResourceHandle handle, GPUStorageBuf *indirect_buf)
bool DRW_culling_box_test(const DRWView *view, const BoundBox *bbox)
void DRW_select_load_id(uint id)
const DRWView * DRW_view_get_active()
static void draw_compute_culling(DRWView *view)
static void draw_call_batching_start(DRWCommandsState *state)
void DRW_stats_query_start(const char *name)
void DRW_stats_query_end()
#define DRW_STATE_WRITE_STENCIL_ENABLED
@ DRW_STATE_STENCIL_EQUAL
@ DRW_STATE_BLEND_BACKGROUND
@ DRW_STATE_STENCIL_ALWAYS
@ DRW_STATE_IN_FRONT_SELECT
@ DRW_STATE_DEPTH_GREATER_EQUAL
@ DRW_STATE_WRITE_STENCIL_SHADOW_FAIL
@ DRW_STATE_PROGRAM_POINT_SIZE
@ DRW_STATE_SHADOW_OFFSET
@ DRW_STATE_BLEND_ADD_FULL
@ DRW_STATE_BLEND_ALPHA_UNDER_PREMUL
@ DRW_STATE_DEPTH_LESS_EQUAL
@ DRW_STATE_WRITE_STENCIL_SHADOW_PASS
@ DRW_STATE_FIRST_VERTEX_CONVENTION
@ DRW_STATE_STENCIL_NEQUAL
@ DRW_STATE_BLEND_ALPHA_PREMUL
@ DRW_STATE_DEPTH_GREATER
@ DRW_STATE_WRITE_STENCIL
#define DRW_STATE_RASTERIZER_ENABLED
#define DRW_STATE_STENCIL_TEST_ENABLED
#define DRW_STATE_DEPTH_TEST_ENABLED
#define DRW_STATE_BLEND_ENABLED
#define DRW_STATE_DEFAULT
void GPU_compute_dispatch_indirect(GPUShader *shader, GPUStorageBuf *indirect_buf_)
eGPUFrameBufferBits clear_channels
GPUStorageBuf * indirect_buf
blender::gpu::Batch * batch
GPUStorageBuf * indirect_buf
blender::gpu::Batch * batch
blender::gpu::Batch * batch
blender::gpu::Batch * batch
blender::gpu::Batch * batch
blender::gpu::Batch * batch
DRWCommandChunk * curr_chunk
blender::gpu::VertBuf * select_buf
blender::gpu::VertBuf * select_buf
DRWSparseUniformBuf * obattrs_ubo
DRWState drw_state_disabled
blender::gpu::Batch * batch
DRWState drw_state_enabled
GPUUniformBuf ** obinfos_ubo
BLI_memblock * cullstates
GPUUniformBuf * vlattrs_ubo
GPUUniformBuf ** matrices_ubo
bool buffer_finish_called
blender::gpu::Batch * batch
struct DRWCommandChunk * first
struct DRWShadingGroup::@288 cmd
struct DRWCommandChunk * last
DRWUniformChunk * uniforms
GPUUniformBuf * clipping_ubo
DRWCommandComputeIndirect compute_indirect
DRWCommandSetStencil stencil
DRWCommandComputeRef compute_ref
DRWCommandDrawInstance instance
DRWCommandDrawRange range
DRWCommandSetMutableState state
DRWCommandCompute compute
DRWCommandBarrier barrier
DRWCommandDrawInstanceRange instance_range
DRWCommandDrawIndirect draw_indirect
DRWCommandDrawProcedural procedural
DRWCommandSetSelectID select_id