Alternative solution to #141392 / #141564.
As a recap, the DST global lock (which prevented running drawing code
from multiple threads concurrently) was removed for 4.5 (#134690).
One unforeseen issue is that Images (and their GPUTextures) are shared
across dependency graphs (and therefore multiple threads), meaning we
are running into data race issues with them.
@fclem did #141392 and I continued it #141564. However, this is only a
partial solution, parts of the GPUTexture API and the whole BKE_image
API are still unsafe.
Trying to solve all the possible underlying issues seems unrealistic for
4.5 given the time frame and that the extension of the code affected by
this issue is quite large.
So this PR just brings the 4.4 locking behavior instead, which, while
risky on its own, seems much safer to me than the alternative.
This effectively undoes the improvements from #134690 by disabling
concurrent rendering, but instead of reverting all the code, it just
ensures we hold the lock in the same places we did in 4.4.
This means there's some redundant code that is not technically needed
anymore, like the `submission_mutex`, but it's probably best to make as
few modifications as possible, given how close we are to release and
that this is only intended as a temporary measure.
Pull Request: https://projects.blender.org/blender/blender/pulls/141618
Change `eCustomDataType` to `bke::AttrType` for uses of the attribute
API (the `AttributeAccessor` one anyway). I didn't touch any values that
might be saved in files; those should be handled on a case by case basis.
Part of #122398
Pull Request: https://projects.blender.org/blender/blender/pulls/141301
Cleanup and simplification of GPUMaterial and GPUPass compilation.
See #133674 for details/goals.
- Remove the `draw_manage_shader` thread.
Deferred compilation is now handled by the gpu::ShaderCompiler
through the batch compilation API.
Batch management is handled by the `GPUPassCache`.
- Simplify `GPUMaterial` status tracking so it just queries the
`GPUPass` status.
- Split the `GPUPass` and the `GPUCodegen` code.
- Replaced the (broken) `GPU_material_recalc_flag_get` with the new
`GPU_pass_compilation_timestamp`.
- Add the `GPU_pass_cache_wait_for_all` and
`GPU_shader_batch_wait_for_all`, and remove the busy waits from
EEVEE.
- Remove many unused functions, properties, includes...
Pull Request: https://projects.blender.org/blender/blender/pulls/135637
`DRW_gpencil_engine_needed` only checks whether grease pencil is
excluded in the viewport or whether there's grease pencil ID exists,
this can not handle cases where grease pencil strokes are generated from
other types of object in geometry nodes. Now this function is split into
two `gpencil_engine_needed_viewport` and
`gpencil_excluded` calls to provide more granulated logic for
places that need them.
Pull Request: https://projects.blender.org/blender/blender/pulls/138386
This was caused by missing depth of objects.
The old implementation was relying on the external engine
to provide the correct depth of the objects.
This patch does exactly this.
The downside is that, if overlays are present, the prepass
will be also drawn by the overlay engine.
Pull Request: https://projects.blender.org/blender/blender/pulls/138004
Tests were calling the submission mutex without
init. Adding functions to expose only setting
up the submission mutex instead of the full
DRW context (which is uneeded here).
This removes the old `DrawEngineType` and use the new `DrawEngine`
virtual class instead.
This removes a lot of boilerplate functions that were only there for
legacy reason.
To this end, some engines that were based on static functions have been
refactored into `Instance` classes. This was particularly cumbersome
for the Grease pencil engine which needed some more refactoring.
The `Engine` class that is in each namespace is a workaround to isolate
the internal implementation (i.e. the `Instance`) to the engine
modules. Without this, the whole engine is getting included in each
compile unit that includes the `Instance` class. Eventually, if we get
rid of these intricate dependencies, we could remove the `Engine` class.
Pull Request: https://projects.blender.org/blender/blender/pulls/136001
This refactor part of `draw_manager_c.cc` to make it more understandable
and less bug prone.
- Splits the context handing to `draw_gpu_context.cc`
- Rename `draw_manager_c.cc` to `draw_context.cc`
- Merge `DRWContextState` into `DRWContext`
- Merge lots of static functions into `DRWContext` to avoid global access
- Deduplicate code between entry point functions
- Move context init logic to `DRWContext` constructor
- Move resource init logic to `DRWContext::acquire_data`
- Move extraction `TaskGraph` out of `DRWContext`
- Reduce / centralize complexity of enabling draw engines
- Reduce the amount of `drw_get` calls
- Remove unused code
Pull Request: https://projects.blender.org/blender/blender/pulls/135821
This removes the use of `system_gpu_context_mutex`
which was making render command submission threadsafe.
The only issue is the concurent usage of GPUShader objects.
To fix this, we only guard the submission section which
are the only parts that uses the GPUShaders.
Removing this critical section all together requires some changes
in the GPUShader. See #135406
Rel #134690
Pull Request: https://projects.blender.org/blender/blender/pulls/135595
This avoid having to flush explicitely and the need for syncing.
It also removes a lot of complexity in the process.
These updates are not granular and do not need to so much
boiler plate code.
The depsgraph update counter now becomes atomic to avoid
undefined behavior when a depsgraph is being destroyed and
its memory reused (same thinking as the non-copy-on-eval IDs).
I tested some use cases (object update, sculpt update,
shading update) and they are all working.
Pull Request: https://projects.blender.org/blender/blender/pulls/135580
The owner of the context is now always the local context.
The `DRWContext` is now a temporary object that owns
no data.
The draw debug API is being put in a non-working state by
this PR as it conflicts with the new lifetime / ownership of
the `DRWContext` class.
A new design with a global (threadsafe) debug module is needed
to add back support for these debug features. Note that these
are not user facing features.
Some parts of EEVEE are still calling the global context and that
caused crashes in the volume probe baking pipeline where
the context is not yet known. Sort circuiting these function
calls in this case fixes the issue, but a more longer term
solution would be to alway have a `DRWContext` available inside
`eevee::Instance`.
I did some testing and didn't find much of a difference in frame time.
However, we should still strive to remove all global access in the future
to avoid potential overhead of `thread_local`.
Pull Request: https://projects.blender.org/blender/blender/pulls/135521
Especially through DRW_render.hh, there were a lot of unnecessary
includes almost everywhere in the module. This typically makes
dependencies less explicit and slows down compile times, so switch
to including what files actual use.
Pull Request: https://projects.blender.org/blender/blender/pulls/133450
Depth only drawing was not always enabling the overlay engine
(now responsible for depth prepass). And the depth prepass
was not populated if overlays were turned off.
Implementation of the proposal in: #121535
When drawing with "project to surface" turned on, it is now possible to restrict the projection to only the selected objects.
This is really useful for drawing onto surfaces that has a lot of detail meshes that you don't want to project onto.
Performing an off-screen draw call while drawing the viewport isn't
supported, add a check that raises an exception when called from Python
instead of crashing.
Ref: !118780
Overall the transition to C++ in the draw module is awkwardly half
complete, but moving more code to a C++ namespace makes cleaning up
this code in other ways much easier, and the next C++ cleanup steps
are clear anyway.