[Bf-blender-cvs] [f4b6db1f6dd] tmp-gpu-shader-descriptor-2: gpu_shader_2D_nodelink + gpu_shader_2D_nodelink_inst.

Jeroen Bakker noreply at git.blender.org
Tue Jan 11 09:40:57 CET 2022


Commit: f4b6db1f6dda5433eddfed8b77f5cf8eb68f9866
Author: Jeroen Bakker
Date:   Tue Jan 11 09:28:03 2022 +0100
Branches: tmp-gpu-shader-descriptor-2
https://developer.blender.org/rBf4b6db1f6dda5433eddfed8b77f5cf8eb68f9866

gpu_shader_2D_nodelink + gpu_shader_2D_nodelink_inst.

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

M	source/blender/editors/space_node/drawnode.cc
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_batch.h
A	source/blender/gpu/GPU_shader_shared.h
M	source/blender/gpu/intern/gpu_shader_builtin.c
M	source/blender/gpu/intern/gpu_shader_shared_utils.h
M	source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl
A	source/blender/gpu/shaders/infos/gpu_shader_2D_nodelink_info.hh
M	source/blender/gpu/shaders/infos/gpu_shader_todo_info.hh

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

diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc
index ba1c0b41a98..9f0bc5cacef 100644
--- a/source/blender/editors/space_node/drawnode.cc
+++ b/source/blender/editors/space_node/drawnode.cc
@@ -51,7 +51,9 @@
 #include "GPU_immediate.h"
 #include "GPU_matrix.h"
 #include "GPU_platform.h"
+#include "GPU_shader_shared.h"
 #include "GPU_state.h"
+#include "GPU_uniform_buffer.h"
 
 #include "DRW_engine.h"
 
@@ -1873,23 +1875,29 @@ static void nodelink_batch_draw(const SpaceNode &snode)
   }
 
   GPU_blend(GPU_BLEND_ALPHA);
+  NodeLinkInstanceData node_link_data;
 
-  float colors[6][4] = {{0.0f}};
-  UI_GetThemeColor4fv(TH_WIRE_INNER, colors[nodelink_get_color_id(TH_WIRE_INNER)]);
-  UI_GetThemeColor4fv(TH_WIRE, colors[nodelink_get_color_id(TH_WIRE)]);
-  UI_GetThemeColor4fv(TH_ACTIVE, colors[nodelink_get_color_id(TH_ACTIVE)]);
-  UI_GetThemeColor4fv(TH_EDGE_SELECT, colors[nodelink_get_color_id(TH_EDGE_SELECT)]);
-  UI_GetThemeColor4fv(TH_REDALERT, colors[nodelink_get_color_id(TH_REDALERT)]);
+  UI_GetThemeColor4fv(TH_WIRE_INNER, node_link_data.colors[nodelink_get_color_id(TH_WIRE_INNER)]);
+  UI_GetThemeColor4fv(TH_WIRE, node_link_data.colors[nodelink_get_color_id(TH_WIRE)]);
+  UI_GetThemeColor4fv(TH_ACTIVE, node_link_data.colors[nodelink_get_color_id(TH_ACTIVE)]);
+  UI_GetThemeColor4fv(TH_EDGE_SELECT,
+                      node_link_data.colors[nodelink_get_color_id(TH_EDGE_SELECT)]);
+  UI_GetThemeColor4fv(TH_REDALERT, node_link_data.colors[nodelink_get_color_id(TH_REDALERT)]);
+  node_link_data.expandSize = snode.runtime->aspect * LINK_WIDTH;
+  node_link_data.arrowSize = ARROW_SIZE;
+
+  GPUUniformBuf *ubo = GPU_uniformbuf_create_ex(sizeof(node_link_data), &node_link_data, __func__);
 
   GPU_vertbuf_data_len_set(g_batch_link.inst_vbo, g_batch_link.count);
   GPU_vertbuf_use(g_batch_link.inst_vbo); /* force update. */
 
   GPU_batch_program_set_builtin(g_batch_link.batch, GPU_SHADER_2D_NODELINK_INST);
-  GPU_batch_uniform_4fv_array(g_batch_link.batch, "colors", 6, colors);
-  GPU_batch_uniform_1f(g_batch_link.batch, "expandSize", snode.runtime->aspect * LINK_WIDTH);
-  GPU_batch_uniform_1f(g_batch_link.batch, "arrowSize", ARROW_SIZE);
+  GPU_batch_uniformbuf_bind(g_batch_link.batch, "node_link_data", ubo);
   GPU_batch_draw(g_batch_link.batch);
 
+  GPU_uniformbuf_unbind(ubo);
+  GPU_uniformbuf_free(ubo);
+
   nodelink_batch_reset();
 
   GPU_blend(GPU_BLEND_NONE);
@@ -2060,19 +2068,32 @@ void node_draw_link_bezier(const bContext &C,
         copy_v4_v4(colors[2], link_preselection_highlight_color);
       }
 
+      NodeLinkData node_link_data;
+      for (int i = 0; i < 4; i++) {
+        copy_v2_v2(node_link_data.bezierPts[i], vec[i]);
+      }
+      for (int i = 0; i < 3; i++) {
+        copy_v2_v2(node_link_data.colors[i], colors[i]);
+      }
+      node_link_data.doArrow = drawarrow;
+      node_link_data.doMuted = drawmuted;
+      node_link_data.dim_factor = dim_factor;
+      node_link_data.thickness = thickness;
+      node_link_data.dash_factor = dash_factor;
+      node_link_data.dash_alpha = dash_alpha;
+      node_link_data.expandSize = snode.runtime->aspect * LINK_WIDTH;
+      node_link_data.arrowSize = ARROW_SIZE;
+
       GPUBatch *batch = g_batch_link.batch_single;
+      GPUUniformBuf *ubo = GPU_uniformbuf_create_ex(
+          sizeof(node_link_data), &node_link_data, __func__);
+
       GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_NODELINK);
-      GPU_batch_uniform_2fv_array(batch, "bezierPts", 4, vec);
-      GPU_batch_uniform_4fv_array(batch, "colors", 3, colors);
-      GPU_batch_uniform_1f(batch, "expandSize", snode.runtime->aspect * LINK_WIDTH);
-      GPU_batch_uniform_1f(batch, "arrowSize", ARROW_SIZE);
-      GPU_batch_uniform_1i(batch, "doArrow", drawarrow);
-      GPU_batch_uniform_1i(batch, "doMuted", drawmuted);
-      GPU_batch_uniform_1f(batch, "dim_factor", dim_factor);
-      GPU_batch_uniform_1f(batch, "thickness", thickness);
-      GPU_batch_uniform_1f(batch, "dash_factor", dash_factor);
-      GPU_batch_uniform_1f(batch, "dash_alpha", dash_alpha);
+      GPU_batch_uniformbuf_bind(batch, "node_link_data", ubo);
       GPU_batch_draw(batch);
+
+      GPU_uniformbuf_unbind(ubo);
+      GPU_uniformbuf_free(ubo);
     }
   }
 }
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index ac61f905fe5..7a1b394516f 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -137,6 +137,7 @@ set(SRC
   GPU_primitive.h
   GPU_select.h
   GPU_shader.h
+  GPU_shader_shared.h
   GPU_state.h
   GPU_texture.h
   GPU_uniform_buffer.h
@@ -202,6 +203,8 @@ if(NOT WITH_SYSTEM_GLEW)
 endif()
 
 set(GLSL_SRC
+  GPU_shader_shared.h
+
   shaders/gpu_shader_depth_only_frag.glsl
   shaders/gpu_shader_uniform_color_frag.glsl
   shaders/gpu_shader_checker_frag.glsl
@@ -434,6 +437,7 @@ shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_outline_aa_info.hh
 shaders/infos/gpu_shader_2D_area_edges_info.hh
 shaders/infos/gpu_shader_instance_varying_color_varying_size_info.hh
 shaders/infos/gpu_shader_3D_point_info.hh
+shaders/infos/gpu_shader_2D_nodelink_info.hh
 #shaders/infos/gpu_shader_todo_info.hh
 )
 
diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h
index a8bc4f271c9..b193b45d65c 100644
--- a/source/blender/gpu/GPU_batch.h
+++ b/source/blender/gpu/GPU_batch.h
@@ -30,6 +30,7 @@
 
 #include "GPU_index_buffer.h"
 #include "GPU_shader.h"
+#include "GPU_uniform_buffer.h"
 #include "GPU_vertex_buffer.h"
 
 #define GPU_BATCH_VBO_MAX_LEN 16
@@ -170,6 +171,8 @@ void GPU_batch_program_set_builtin_with_config(GPUBatch *batch,
   GPU_shader_uniform_4fv_array((batch)->shader, name, len, val);
 #define GPU_batch_uniform_mat4(batch, name, val) \
   GPU_shader_uniform_mat4((batch)->shader, name, val);
+#define GPU_batch_uniformbuf_bind(batch, name, ubo) \
+  GPU_uniformbuf_bind(ubo, GPU_shader_get_uniform_block_binding((batch)->shader, name));
 #define GPU_batch_texture_bind(batch, name, tex) \
   GPU_texture_bind(tex, GPU_shader_get_texture_binding((batch)->shader, name));
 
diff --git a/source/blender/gpu/GPU_shader_shared.h b/source/blender/gpu/GPU_shader_shared.h
new file mode 100644
index 00000000000..99a3cfe8557
--- /dev/null
+++ b/source/blender/gpu/GPU_shader_shared.h
@@ -0,0 +1,24 @@
+
+#ifndef USE_GPU_SHADER_CREATE_INFO
+#  include "intern/gpu_shader_shared_utils.h"
+#endif
+
+struct NodeLinkData {
+  float4 colors[3];
+  float2 bezierPts[4];
+  bool1 doArrow;
+  bool1 doMuted;
+  float dim_factor;
+  float thickness;
+  float dash_factor;
+  float dash_alpha;
+  float expandSize;
+  float arrowSize;
+};
+
+struct NodeLinkInstanceData {
+  float4 colors[6];
+  float expandSize;
+  float arrowSize;
+  float2 pad;
+};
diff --git a/source/blender/gpu/intern/gpu_shader_builtin.c b/source/blender/gpu/intern/gpu_shader_builtin.c
index 24ca691be78..12fd234121c 100644
--- a/source/blender/gpu/intern/gpu_shader_builtin.c
+++ b/source/blender/gpu/intern/gpu_shader_builtin.c
@@ -41,6 +41,9 @@
 #include "GPU_texture.h"
 #include "GPU_uniform_buffer.h"
 
+/* TODO(jbakker): Need a better way to retrieve create_infos. */
+#include "gpu_shader_create_info_private.hh"
+
 /* Adjust these constants as needed. */
 #define MAX_DEFINE_LENGTH 256
 #define MAX_EXT_DEFINE_LENGTH 512
@@ -145,6 +148,8 @@ typedef struct {
   const char *frag;
   /** Optional. */
   const char *defs;
+
+  const char *create_info;
 } GPUShaderStages;
 
 static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = {
@@ -394,19 +399,11 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = {
             .vert = datatoc_gpu_shader_2D_widget_shadow_vert_glsl,
             .frag = datatoc_gpu_shader_2D_widget_shadow_frag_glsl,
         },
-    [GPU_SHADER_2D_NODELINK] =
-        {
-            .name = "GPU_SHADER_2D_NODELINK",
-            .vert = datatoc_gpu_shader_2D_nodelink_vert_glsl,
-            .frag = datatoc_gpu_shader_2D_nodelink_frag_glsl,
-        },
-    [GPU_SHADER_2D_NODELINK_INST] =
-        {
-            .name = "GPU_SHADER_2D_NODELINK_INST",
-            .vert = datatoc_gpu_shader_2D_nodelink_vert_glsl,
-            .frag = datatoc_gpu_shader_2D_nodelink_frag_glsl,
-            .defs = "#define USE_INSTANCE\n",
-        },
+    [GPU_SHADER_2D_NODELINK] = {.name = "GPU_SHADER_2D_NODELINK",
+                                .create_info = "gpu_shader_2D_nodelink"},
+
+    [GPU_SHADER_2D_NODELINK_INST] = {.name = "GPU_SHADER_2D_NODELINK_INST",
+                                     .create_info = "gpu_shader_2D_nodelink_inst"},
 
     [GPU_SHADER_GPENCIL_STROKE] =
         {
@@ -429,14 +426,20 @@ GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader,
 
     /* common case */
     if (sh_cfg == GPU_SHADER_CFG_DEFAULT) {
-      *sh_p = GPU_shader_create_from_arrays_named(
-          stages->name,
-          {
-              .vert = (const char *[]){stages->vert, NULL},
-              .geom = (const char *[]){stages->geom, NULL},
-              .frag = (const char *[]){datatoc_gpu_shader_colorspace_lib_glsl, stages->frag, NULL},
-              .defs = (const char *[]){stages->defs, NULL},
-          });
+      if (stages->create_info != NULL) {
+        *sh_p = GPU_shader_create_from_info(gpu_shader_create_info_get(stages->create_info));
+      }
+      else {
+        *sh_p = GPU_shader_create_from_arrays_named(
+            stages->name,
+            {
+                .vert = (const char *[]){stages->vert, NULL},
+                .geom = (const char *[]){stages->geom, NULL},
+                .frag =
+                    (const char *[]){datatoc_gpu_shader_colorspace_lib_glsl, stages->frag, NULL},
+                .defs = (const char *[]){stages->defs, NULL},
+            });
+      }
     }
     else if (sh_cfg == GPU_SHADER_CFG_CLIPPED) {
       /* Remove eventually, for now ensure support for each shader has been added. */
@@ -451,14 +454,20 @@ GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader,
       const char *world_clip_lib = datatoc_gpu_shader_cfg_world_clip_lib_glsl;
       const char *world_clip_def = "#define 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list