[Bf-blender-cvs] [4e1b09f122e] tmp-drw-callbatching: DRW: Move Shading Group Extra DRWState to own DRWCommand

Clément Foucault noreply at git.blender.org
Sat Aug 17 14:51:02 CEST 2019


Commit: 4e1b09f122ee2a01127a2459ae286e713f860ab3
Author: Clément Foucault
Date:   Sun Jun 23 12:25:07 2019 +0200
Branches: tmp-drw-callbatching
https://developer.blender.org/rB4e1b09f122ee2a01127a2459ae286e713f860ab3

DRW: Move Shading Group Extra DRWState to own DRWCommand

===================================================================

M	source/blender/draw/intern/draw_manager.h
M	source/blender/draw/intern/draw_manager_data.c
M	source/blender/draw/intern/draw_manager_exec.c

===================================================================

diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h
index d9ef67346ee..154b35077a0 100644
--- a/source/blender/draw/intern/draw_manager.h
+++ b/source/blender/draw/intern/draw_manager.h
@@ -155,11 +155,10 @@ typedef enum {
   DRW_CMD_DRAW_RANGE = 1,
   DRW_CMD_DRAW_INSTANCE = 2,
   DRW_CMD_DRAW_PROCEDURAL = 3,
-  /* First 2 bits are for draw commands.
-   * DRW_shgroup_is_empty uses this fact. */
   /* Other Commands */
-  DRW_CMD_STENCIL = 2 << 2,
-  DRW_CMD_SELECTID = 3 << 2,
+  DRW_CMD_DRWSTATE = 13,
+  DRW_CMD_STENCIL = 14,
+  DRW_CMD_SELECTID = 15,
   /* Needs to fit in 4bits */
 } eDRWCommandType;
 
@@ -189,24 +188,28 @@ typedef struct DRWCommandDrawProcedural {
   uint vert_count;
 } DRWCommandDrawProcedural;
 
-typedef struct DRWCommandSetSelectID {
-  GPUVertBuf *select_buf;
-  uint select_id;
-} DRWCommandSetSelectID;
+typedef struct DRWCommandSetMutableState {
+  /** State changes (or'd or and'd with the pass's state) */
+  DRWState enable;
+  DRWState disable;
+} DRWCommandSetMutableState;
 
 typedef struct DRWCommandSetStencil {
   uint mask;
 } DRWCommandSetStencil;
 
+typedef struct DRWCommandSetSelectID {
+  GPUVertBuf *select_buf;
+  uint select_id;
+} DRWCommandSetSelectID;
+
 typedef union DRWCommand {
-  /* Only sortable type */
   DRWCommandDraw draw;
   DRWCommandDrawRange range;
   DRWCommandDrawInstance instance;
   DRWCommandDrawProcedural procedural;
-  /* Stencil */
+  DRWCommandSetMutableState state;
   DRWCommandSetStencil stencil;
-  /* Select */
   DRWCommandSetSelectID select_id;
 } DRWCommand;
 
@@ -268,10 +271,6 @@ struct DRWShadingGroup {
     struct DRWCommandChunk *first, *last;
   } cmd;
 
-  /** State changes for this batch only (or'd with the pass's state) */
-  DRWState state_extra;
-  /** State changes for this batch only (and'd with the pass's state) */
-  DRWState state_extra_disable;
   union {
     struct {
       int objectinfo;                /* Equal to 1 if the shader needs obinfos. */
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index e8045dbc044..db7da537528 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -674,6 +674,16 @@ static void drw_command_set_stencil_mask(DRWShadingGroup *shgroup, uint mask)
   cmd->mask = mask;
 }
 
+static void drw_command_set_mutable_state(DRWShadingGroup *shgroup,
+                                          DRWState enable,
+                                          DRWState disable)
+{
+  /* TODO Restrict what state can be changed. */
+  DRWCommandSetMutableState *cmd = drw_command_create(shgroup, DRW_CMD_DRWSTATE);
+  cmd->enable = enable;
+  cmd->disable = disable;
+}
+
 void DRW_shgroup_call_ex(DRWShadingGroup *shgroup,
                          Object *ob,
                          float (*obmat)[4],
@@ -1090,8 +1100,6 @@ static DRWShadingGroup *drw_shgroup_create_ex(struct GPUShader *shader, DRWPass
   BLI_LINKS_APPEND(&pass->shgroups, shgroup);
 
   shgroup->shader = shader;
-  shgroup->state_extra = 0;
-  shgroup->state_extra_disable = ~0x0;
   shgroup->cmd.first = NULL;
   shgroup->cmd.last = NULL;
   shgroup->pass_handle = pass->handle;
@@ -1205,12 +1213,12 @@ DRWShadingGroup *DRW_shgroup_transform_feedback_create(struct GPUShader *shader,
  */
 void DRW_shgroup_state_enable(DRWShadingGroup *shgroup, DRWState state)
 {
-  shgroup->state_extra |= state;
+  drw_command_set_mutable_state(shgroup, state, ~0x0);
 }
 
 void DRW_shgroup_state_disable(DRWShadingGroup *shgroup, DRWState state)
 {
-  shgroup->state_extra_disable &= ~state;
+  drw_command_set_mutable_state(shgroup, 0x0, state);
 }
 
 void DRW_shgroup_stencil_mask(DRWShadingGroup *shgroup, uint mask)
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index a2d6f6f9155..83183148274 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -67,6 +67,9 @@ typedef struct DRWCommandsState {
   /* Selection ID state. */
   GPUVertBuf *select_buf;
   uint select_id;
+  /* Drawing State */
+  DRWState drw_state_enabled;
+  DRWState drw_state_disabled;
 } DRWCommandsState;
 
 /* -------------------------------------------------------------------- */
@@ -1174,6 +1177,8 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
       .obmat_loc = -1,
       .obinv_loc = -1,
       .mvp_loc = -1,
+      .drw_state_enabled = 0,
+      .drw_state_disabled = ~0x0,
   };
 
   const bool shader_changed = (DST.shader != shgroup->shader);
@@ -1195,10 +1200,10 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
   release_ubo_slots(shader_changed);
   release_texture_slots(shader_changed);
 
-  drw_state_set((pass_state & shgroup->state_extra_disable) | shgroup->state_extra);
-
   draw_update_uniforms(shgroup, &state, &use_tfeedback);
 
+  drw_state_set(pass_state);
+
   /* Rendering Calls */
   {
     DRWCommandIterator iter;
@@ -1212,6 +1217,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
     while ((cmd = draw_command_iter_step(&iter, &cmd_type))) {
 
       switch (cmd_type) {
+        case DRW_CMD_DRWSTATE:
         case DRW_CMD_STENCIL:
           draw_call_batching_flush(shgroup, &state);
           break;
@@ -1227,6 +1233,11 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
       }
 
       switch (cmd_type) {
+        case DRW_CMD_DRWSTATE:
+          state.drw_state_enabled |= cmd->state.enable;
+          state.drw_state_disabled &= ~cmd->state.disable;
+          drw_state_set((pass_state & state.drw_state_disabled) | state.drw_state_enabled);
+          break;
         case DRW_CMD_STENCIL:
           drw_stencil_set(cmd->stencil.mask);
           break;



More information about the Bf-blender-cvs mailing list