From 1d49293b80446b89b5b12fa0eeefaf14e5051e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Tue, 5 Oct 2021 09:36:11 +0200 Subject: DRW: Move buffer & temp textures & framebuffer management to DrawManager This is a necessary step for EEVEE's new arch. This moves more data to the draw manager. This makes it easier to have the render or draw engines manage their own data. This makes more sense and cleans-up what the GPUViewport holds Also rewrites the Texture pool manager to be in C++. This also move the DefaultFramebuffer/TextureList and the engine related data to a new `DRWViewData` struct. This struct manages the per view (as in stereo view) engine data. There is a bit of cleanup in the way the draw manager is setup. We now use a temporary DRWData instead of creating a dummy viewport. Development: fclem, jbakker Differential Revision: https://developer.blender.org/D11966 --- source/blender/draw/intern/draw_manager.h | 59 +++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 7 deletions(-) (limited to 'source/blender/draw/intern/draw_manager.h') diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index c09126c98ef..1bb1ee06354 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -97,6 +97,17 @@ struct Object; #endif /* USE_PROFILE */ /* ------------ Data Structure --------------- */ +/** + * Data structure to for registered draw engines that can store draw manager + * specific data. + */ +typedef struct DRWRegisteredDrawEngine { + void /*DRWRegisteredDrawEngine*/ *next, *prev; + DrawEngineType *draw_engine; + /** Index of the type in the lists. Index is used for dupli data. */ + int index; +} DRWRegisteredDrawEngine; + /** * Data structure containing all drawcalls organized by passes and materials. * DRWPass > DRWShadingGroup > DRWCall > DRWCallState @@ -495,6 +506,35 @@ typedef struct DRWDebugSphere { float color[4]; } DRWDebugSphere; +/* ------------- Memory Pools ------------ */ + +/* Contains memory pools information */ +typedef struct DRWData { + /** Instance data. */ + DRWInstanceDataList *idatalist; + /** Mempools for drawcalls. */ + struct BLI_memblock *commands; + struct BLI_memblock *commands_small; + struct BLI_memblock *callbuffers; + struct BLI_memblock *obmats; + struct BLI_memblock *obinfos; + struct BLI_memblock *cullstates; + struct BLI_memblock *shgroups; + struct BLI_memblock *uniforms; + struct BLI_memblock *views; + struct BLI_memblock *passes; + struct BLI_memblock *images; + struct GPUUniformBuf **matrices_ubo; + struct GPUUniformBuf **obinfos_ubo; + struct GHash *obattrs_ubo_pool; + uint ubo_len; + /** Texture pool to reuse temp texture across engines. */ + /* TODO(fclem) the pool could be shared even between viewports. */ + struct DRWTexturePool *texture_pool; + /** Per stereo view data. Contains engine data and default framebuffers. */ + struct DRWViewData *view_data[2]; +} DRWData; + /* ------------- DRAW MANAGER ------------ */ typedef struct DupliKey { @@ -509,8 +549,10 @@ typedef struct DupliKey { typedef struct DRWManager { /* TODO: clean up this struct a bit. */ /* Cache generation */ - ViewportMemoryPool *vmempool; - DRWInstanceDataList *idatalist; + /* TODO(fclem) Rename to data. */ + DRWData *vmempool; + /** Active view data structure for one of the 2 stereo view. Not related to DRWView. */ + struct DRWViewData *view_data_active; /* State of the object being evaluated if already allocated. */ DRWResourceHandle ob_handle; /** True if current DST.ob_state has its matching DRWObjectInfos init. */ @@ -567,10 +609,6 @@ typedef struct DRWManager { /* Convenience pointer to text_store owned by the viewport */ struct DRWTextStore **text_store_p; - ListBase enabled_engines; /* RenderEngineType */ - void **vedata_array; /* ViewportEngineData */ - int enabled_engine_count; /* Length of enabled_engines list. */ - bool buffer_finish_called; /* Avoid bad usage of DRW_render_instance_buffer_finish */ DRWView *view_default; @@ -627,7 +665,7 @@ void drw_batch_cache_validate(Object *ob); void drw_batch_cache_generate_requested(struct Object *ob); void drw_batch_cache_generate_requested_delayed(Object *ob); -void drw_resource_buffer_finish(ViewportMemoryPool *vmempool); +void drw_resource_buffer_finish(DRWData *vmempool); /* Procedural Drawing */ GPUBatch *drw_cache_procedural_points_get(void); @@ -641,6 +679,13 @@ void drw_uniform_attrs_pool_update(struct GHash *table, struct Object *dupli_parent, struct DupliObject *dupli_source); +double *drw_engine_data_cache_time_get(GPUViewport *viewport); +void *drw_engine_data_engine_data_create(GPUViewport *viewport, void *engine_type); +void *drw_engine_data_engine_data_get(GPUViewport *viewport, void *engine_handle); +bool drw_engine_data_engines_data_validate(GPUViewport *viewport, void **engine_handle_array); +void drw_engine_data_cache_release(GPUViewport *viewport); +void drw_engine_data_free(GPUViewport *viewport); + #ifdef __cplusplus } #endif -- cgit v1.2.3 From 6d2b486e431dae57536a5a7d9b64c62144754363 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 6 Oct 2021 09:28:00 +1100 Subject: Cleanup: spelling in comments --- source/blender/draw/intern/draw_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/draw/intern/draw_manager.h') diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 1bb1ee06354..162fe9b5fd1 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -512,7 +512,7 @@ typedef struct DRWDebugSphere { typedef struct DRWData { /** Instance data. */ DRWInstanceDataList *idatalist; - /** Mempools for drawcalls. */ + /** Memory-pools for draw-calls. */ struct BLI_memblock *commands; struct BLI_memblock *commands_small; struct BLI_memblock *callbuffers; -- cgit v1.2.3 From c746eeae931780783daa0d75889ed08a15aab1ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Mon, 1 Nov 2021 11:59:03 +0100 Subject: DRW: Shading Group: Add compute dispatch with size reference This way we can reuse the same DRWPass using dispatch for multiple views. --- source/blender/draw/intern/draw_manager.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source/blender/draw/intern/draw_manager.h') diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index be04140e734..5552797ee99 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -194,8 +194,10 @@ typedef enum { /* Compute Commands. */ DRW_CMD_COMPUTE = 8, + DRW_CMD_COMPUTE_REF = 9, /* Other Commands */ + DRW_CMD_BARRIER = 11, DRW_CMD_CLEAR = 12, DRW_CMD_DRWSTATE = 13, DRW_CMD_STENCIL = 14, @@ -238,6 +240,14 @@ typedef struct DRWCommandCompute { int groups_z_len; } DRWCommandCompute; +typedef struct DRWCommandComputeRef { + int *groups_ref; +} DRWCommandComputeRef; + +typedef struct DRWCommandBarrier { + eGPUBarrier type; +} DRWCommandBarrier; + typedef struct DRWCommandDrawProcedural { GPUBatch *batch; DRWResourceHandle handle; @@ -275,6 +285,8 @@ typedef union DRWCommand { DRWCommandDrawInstanceRange instance_range; DRWCommandDrawProcedural procedural; DRWCommandCompute compute; + DRWCommandComputeRef compute_ref; + DRWCommandBarrier barrier; DRWCommandSetMutableState state; DRWCommandSetStencil stencil; DRWCommandSetSelectID select_id; -- cgit v1.2.3 From fbfbc9f15d03eadab4890bec66cd1085664ba65d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sun, 14 Nov 2021 14:34:09 +0100 Subject: DRW: Add debug line buffer This debug buffer is automatically bound if a shader is including `common_debug_lib.glsl`. One buffer is created for each shading group using such a shader. The shader can then use the functions from that file to draw debug lines. There is a hardcoded limit of line one buffer can contain. Make sure to only output lines for a few threads at most. Under the hood this uses a vertex buffer bound as SSBO that contains the number of verts and all the positions and colors packed into 1 vec4. We render by just rendering the whole buffer. All unused vertices are initialized with NaN positions and will not be drawn. --- source/blender/draw/intern/draw_manager.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source/blender/draw/intern/draw_manager.h') diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 5552797ee99..3ac88e8efa5 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -509,6 +509,11 @@ typedef struct DRWDebugSphere { float color[4]; } DRWDebugSphere; +typedef struct DRWDebugBuffer { + struct DRWDebugBuffer *next; /* linked list */ + struct GPUVertBuf *verts; +} DRWDebugBuffer; + /* ------------- Memory Pools ------------ */ /* Contains memory pools information */ @@ -646,6 +651,7 @@ typedef struct DRWManager { /* TODO(fclem): optimize: use chunks. */ DRWDebugLine *lines; DRWDebugSphere *spheres; + DRWDebugBuffer *line_buffers; } debug; } DRWManager; @@ -659,6 +665,7 @@ void *drw_viewport_engine_data_ensure(void *engine_type); void drw_state_set(DRWState state); +GPUVertBuf *drw_debug_line_buffer_get(void); void drw_debug_draw(void); void drw_debug_init(void); -- cgit v1.2.3 From 55af3361bfabc31ee427db704ecc93390db88149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sun, 14 Nov 2021 14:43:38 +0100 Subject: DRWView: Add frustum infos to uniform buffer This way it is possible to do some culling on GPU. --- source/blender/draw/intern/draw_manager.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source/blender/draw/intern/draw_manager.h') diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 3ac88e8efa5..519883ccbce 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -425,6 +425,11 @@ typedef struct DRWViewUboStorage { float viewcamtexcofac[4]; float viewport_size[2]; float viewport_size_inv[2]; + + /** Frustum culling data. */ + /** NOTE: vec3 arrays are paded to vec4. */ + float frustum_corners[8][4]; + float frustum_planes[6][4]; } DRWViewUboStorage; BLI_STATIC_ASSERT_ALIGN(DRWViewUboStorage, 16) -- cgit v1.2.3 From 68602f3d87446b15cccbf7e7b1ca4ed929dc8647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Tue, 23 Nov 2021 21:19:11 +0100 Subject: DRW: Add DRW_shgroup_vertex_buffer_ref --- source/blender/draw/intern/draw_manager.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source/blender/draw/intern/draw_manager.h') diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 519883ccbce..cfdc8b0df19 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -315,6 +315,7 @@ typedef enum { DRW_UNIFORM_BLOCK_REF, DRW_UNIFORM_TFEEDBACK_TARGET, DRW_UNIFORM_VERTEX_BUFFER_AS_STORAGE, + DRW_UNIFORM_VERTEX_BUFFER_AS_STORAGE_REF, /** Per drawcall uniforms/UBO */ DRW_UNIFORM_BLOCK_OBMATS, DRW_UNIFORM_BLOCK_OBINFOS, @@ -346,6 +347,11 @@ struct DRWUniform { GPUUniformBuf *block; GPUUniformBuf **block_ref; }; + /* DRW_UNIFORM_VERTEX_BUFFER_AS_STORAGE */ + union { + GPUVertBuf *vertbuf; + GPUVertBuf **vertbuf_ref; + }; /* DRW_UNIFORM_FLOAT_COPY */ float fvalue[4]; /* DRW_UNIFORM_INT_COPY */ -- cgit v1.2.3 From 594656e7a39d3598d7a357511742fb0b001254bc Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 1 Dec 2021 21:16:18 -0500 Subject: Fix T93525: Crash with curve/text armature bone gizmo The problem is that drw_batch_cache_generate_requested_delayed is called on the object, which uses the original object data type to choose which data type to get info for. So for curves and text it uses the incorrect type (not the evaluated mesh like we hardcoded in the armature overlay code). To fix this I hardcoded the "delayed" generation to only use the evaluated mesh. Luckily it wasn't use elsewhere besides this armature overlay system. That seems like the simplest fix for 3.0. A proper solution should rewrite this whole area anyway. Differential Revision: https://developer.blender.org/D13439 --- source/blender/draw/intern/draw_manager.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source/blender/draw/intern/draw_manager.h') diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 162fe9b5fd1..a4924711384 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -663,7 +663,12 @@ eDRWCommandType command_type_get(const uint64_t *command_type_bits, int index); void drw_batch_cache_validate(Object *ob); void drw_batch_cache_generate_requested(struct Object *ob); + +/** + * \warning Only evaluated mesh data is handled by this delayed generation. + */ void drw_batch_cache_generate_requested_delayed(Object *ob); +void drw_batch_cache_generate_requested_evaluated_mesh(Object *ob); void drw_resource_buffer_finish(DRWData *vmempool); -- cgit v1.2.3 From 499fec6f79a26c9c9d2d61b90bda2e4cec424f81 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 6 Jan 2022 13:54:52 +1100 Subject: Cleanup: spelling in comments --- source/blender/draw/intern/draw_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/draw/intern/draw_manager.h') diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index a4924711384..d27eb8be9e0 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -570,7 +570,7 @@ typedef struct DRWManager { struct Object *dupli_origin; /** Object-data referenced by the current dupli object. */ struct ID *dupli_origin_data; - /** Ghash: #DupliKey -> void pointer for each enabled engine. */ + /** Hash-map: #DupliKey -> void pointer for each enabled engine. */ struct GHash *dupli_ghash; /** TODO(fclem): try to remove usage of this. */ DRWInstanceData *object_instance_data[MAX_INSTANCE_DATA_SIZE]; -- cgit v1.2.3