Page MenuHome

Workbench Next
ClosedPublic

Authored by Miguel Pozo (pragma37) on Dec 20 2022, 5:04 PM.

Details

Summary

Rewrite of the Workbench engine using C++ and the new Draw Manager API.

The new engine can be enabled in Blender Preferences > Experimental > Workbench Next.
After that, the engine can be selected in Properties > Scene > Render Engine.
When Workbench Next is the active engine, it also handles the Solid viewport mode rendering.

The rewrite aims to be functionally equivalent to the current Workbench engine, but it also includes some small fixes/tweaks:

  • In Front rendered objects now work correctly with DoF and Shadows.
  • The Sampling > Viewport setting is actually used when the viewport is in Render Mode.
  • In Texture mode, textured materials also use the material properties. (Previously, only non textured materials would)

To do:

  • Sculpt PBVH.
  • Volume rendering.
  • Hair rendering.
  • Use the "no_geom" shader versions for shadow rendering.
  • Decide the final API for custom visibility culling (Needed for shadows).
  • Profile/optimize.

Known Issues:

  • Matcaps are not loaded until they’re shown elsewhere. (e.g. when opening the Viewort Shading UI)
  • Outlines are drawn between different materials of the same object. (Each material submesh has its own object handle)

Diff Detail

Repository
rB Blender
Branch
tmp-workbench-rewrite2
Build Status
Buildable 25110
Build 25110: arc lint + arc unit

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
Miguel Pozo (pragma37) requested review of this revision.Dec 20 2022, 5:04 PM
Miguel Pozo (pragma37) retitled this revision from Rewrite of the Workbench engine using C++ and the new Draw Manager API. to Workbench Next.Dec 20 2022, 5:07 PM
Miguel Pozo (pragma37) edited the summary of this revision. (Show Details)
Hans Goudey (HooglyBoogly) added inline comments.
source/blender/draw/engines/workbench/workbench_resources.cc
18

This initialization is unnecessary, Vector will be default initialized either way

  • Merge branch 'master' into tmp-workbench-rewrite2
  • Optimize Workbench Next Shadows
  • MeshPass replace sub_pass_get() with draw()
  • Optimization: Convert composite compute shader to fragment
Clément Foucault (fclem) requested changes to this revision.Jan 9 2023, 4:37 PM
Clément Foucault (fclem) added inline comments.
source/blender/draw/engines/workbench/shaders/infos/workbench_composite_info.hh
61

Comment style: /* */

81

Fixes compilation on Metal.

source/blender/draw/engines/workbench/shaders/workbench_next_composite_frag.glsl
44 ↗(On Diff #59000)

Left over commented code.

79 ↗(On Diff #59000)

Fix MSL compilation.

source/blender/draw/engines/workbench/shaders/workbench_next_merge_depth_frag.glsl
7

You need .depth_write(DepthWrite::ANY) in the create info.

source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc
17

Gonna be nitpicky, https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Comments applies to the whole diff.

source/blender/draw/engines/workbench/workbench_effect_cavity.cc
64–70

Better use math::cos/sin and use C++ functional cast float(dphi).

source/blender/draw/engines/workbench/workbench_engine.cc
323

This is commented but not needed. It isn't clear why you changed depth_tx into a draw::Textiure. Maybe a comment on top of its declaration would make sense.

376

Don't use a static. Move it to a member of Instance. Also this function should also be part of the Instance class.

607

Split to write functions.

source/blender/draw/engines/workbench/workbench_mesh_passes.cc
101–104

Style: Split different class blocks using these type of comments:

/** \} */

/* -------------------------------------------------------------------- */
/** \name OpaquePass
 * \{ */
source/blender/draw/engines/workbench/workbench_private.hh
13

Needs to be guarded by extern "C" {. Otherwise, it triggers an error on Clang.

123

Style: Use comment on top of variable. Not after.

170

Yes. Maybe better to do it in master directly and update this patch after.

Also as a side note. Don't forget to add TODO to thoses. It is easy to forget them if not tagged properly.

250

Set first to 0. IIRC some compiler start enum numbering differently. Use Uppercase for enum names. Use MAX instead of Length.

282

The last two dimensions are not obvious. Add comment on top.

285

Same here. Dimensions not obvious.

309

Doesn't hurt to set default values. Same goes for DofPass.

312

Un-initialized var!

354

Doesn't follow https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Class_Layout. If that's meant to be private, move to the bottom of the class.

Also prefer being explicit about private/public even if class is private by default.

source/blender/draw/engines/workbench/workbench_resources.cc
44–48

Can use new matrix API. Also can use float3x3 and finaly convert to float4x4 by just using functional cast.

source/blender/draw/engines/workbench/workbench_shadow.cc
103–104

You are already in blender namespace.

320

use std::swap instead.

This revision now requires changes to proceed.Jan 9 2023, 4:37 PM
Miguel Pozo (pragma37) marked 20 inline comments as done.
  • Clarify TODO comments
  • Fix comments style
  • Fix workbench_next_merge depth
  • Remove commented-out code
  • Replace sinf/cosf with math::sin/cos
  • Move get_dummy_gpu_materials to Instance
  • Split render output writing into their own functions
  • Class separators
  • Fix Clang compilation
  • Remove blender:: namespace
  • Use std::swap
  • Use functional type casting
  • Fix MSL compilation
  • Code standards
source/blender/draw/engines/workbench/shaders/workbench_next_composite_frag.glsl
79 ↗(On Diff #59000)

Oops! Is there any way I can catch these things myself on Windows?

source/blender/draw/engines/workbench/shaders/workbench_next_merge_depth_frag.glsl
7

Oops! Thanks!

source/blender/draw/engines/workbench/workbench_engine.cc
323

I just removed it.
I had to convert it to a Texture to use stencil_view.

376

Ok, I had just put it aside since it's basically irrelevant noise.
Are in-function static variables forbidden?

source/blender/draw/engines/workbench/workbench_private.hh
170

Actually, you wrote that one in the initial prototype. XD

312

I think it isn't, as long as the class doesn't declare a constructor:
https://godbolt.org/z/c95c9rPqd

Would you prefer if I add explicit default values to everything regardless?

354

Done, but I think this kind of rigid order can make code less readable. The CavityEffect class is a good example:

From:

class CavityEffect {
  int sample_;
  int sample_count_;
  bool curvature_enabled_;
  bool cavity_enabled_;

  /* This value must be kept in sync with the one declared at
   * workbench_composite_info.hh (cavity_samples) */
  static const int max_samples_ = 512;
  UniformArrayBuffer<float4, max_samples_> samples_buf;
  void load_samples_buf(int ssao_samples);

 public:
  void init(const SceneState &scene_state, struct SceneResources &resources);
  void setup_resolve_pass(PassSimple &pass, struct SceneResources &resources);
};

To:

class CavityEffect {
  /* This value must be kept in sync with the one declared at
   * workbench_composite_info.hh (cavity_samples) */
  static const int max_samples_ = 512;

  int sample_;
  int sample_count_;
  bool curvature_enabled_;
  bool cavity_enabled_;

  UniformArrayBuffer<float4, max_samples_> samples_buf;

 public:
  void init(const SceneState &scene_state, struct SceneResources &resources);
  void setup_resolve_pass(PassSimple &pass, struct SceneResources &resources);

 private:
  void load_samples_buf(int ssao_samples);
};

In the first block you have all the samples_buf related declarations together, but in the second they're spread over the whole class so it's harder to follow their correlation.
Here's not a big issue since the class is tiny, though.

source/blender/draw/engines/workbench/workbench_resources.cc
18

I have the habit of always explicitly initializing local variables.
There are other places where I do this in this patch, should I remove them?

Miguel Pozo (pragma37) edited the summary of this revision. (Show Details)Jan 10 2023, 3:57 PM
source/blender/draw/engines/workbench/shaders/workbench_next_composite_frag.glsl
79 ↗(On Diff #59000)

Unfortunately no :/ but would be nice to compile a list of things to avoid in GLSL code.

source/blender/draw/engines/workbench/workbench_private.hh
170

Typical lazy me.

312

Yes it is encouraged. Since it is easy to skip adding default values if someone ever add a constructor.

Miguel Pozo (pragma37) marked 5 inline comments as done.
  • Merge branch 'master' into tmp-workbench-rewrite2
  • Remove UNUSED macros (Needed after D16828)
  • Add explicit initializations to all classes/structs
  • Don't create an extra handle for shadows
  • Merge branch 'master' into tmp-workbench-rewrite2
  • Add Freeze Culling support
  • Don't override local variable
  • Fix textures after D14365
  • Add texture usage flags
  • Add texture mirror extension type support (see D16432)
source/blender/draw/engines/workbench/workbench_resources.cc
18

It's not a big deal I guess, but I think it's better to remove it, since it implies Vector doesn't do that itself.

Clément Foucault (fclem) requested changes to this revision.Mon, Jan 23, 12:51 PM

There is still missing support for clipped alpha texturing support. Open udim-monster demo file and switch to solid view. Compare Workbench against Workbench-Next.

source/blender/draw/engines/workbench/workbench_engine.cc
461

ved->info Needs to be cleared in the normal case.

This revision now requires changes to proceed.Mon, Jan 23, 12:51 PM
  • Remove leftover View from engine data
  • Fix alpha cutout
This revision is now accepted and ready to land.Mon, Jan 23, 4:54 PM
  • Add Workbench Next check to hard-coded Workbench checks
Miguel Pozo (pragma37) edited the summary of this revision. (Show Details)Mon, Jan 23, 5:33 PM
  • Merge branch 'master' into tmp-workbench-rewrite2
This revision was automatically updated to reflect the committed changes.