[Bf-blender-cvs] [3d877c8a0d0] master: Select Engine: port shader to use 'GPUShaderCreateInfo'

Germano Cavalcante noreply at git.blender.org
Fri Apr 29 15:15:29 CEST 2022


Commit: 3d877c8a0d06ee539db541c6d410852f94fc618d
Author: Germano Cavalcante
Date:   Fri Apr 29 02:14:16 2022 -0300
Branches: master
https://developer.blender.org/rB3d877c8a0d06ee539db541c6d410852f94fc618d

Select Engine: port shader to use 'GPUShaderCreateInfo'

Simple port with a few cosmetic changes:
- Attribute named "color" for indices VBO is now called "index"
- The indices VBO is now composed of `int`s instead of `uint`s (this simplifies the source)

Differential Revision: https://developer.blender.org/D14800

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/select/select_engine.c
A	source/blender/draw/engines/select/shaders/infos/select_id_info.hh
A	source/blender/draw/engines/select/shaders/select_id_frag.glsl
A	source/blender/draw/engines/select/shaders/select_id_vert.glsl
D	source/blender/draw/engines/select/shaders/selection_id_3D_vert.glsl
D	source/blender/draw/engines/select/shaders/selection_id_frag.glsl
M	source/blender/draw/intern/draw_cache_impl_subdivision.cc
M	source/blender/draw/intern/draw_subdivision.h
M	source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc
M	source/blender/gpu/CMakeLists.txt

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index beae1c92d6e..68c1671b1bf 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -419,8 +419,8 @@ set(GLSL_SRC
   engines/gpencil/gpencil_defines.h
   engines/gpencil/gpencil_shader_shared.h
 
-  engines/select/shaders/selection_id_3D_vert.glsl
-  engines/select/shaders/selection_id_frag.glsl
+  engines/select/shaders/select_id_vert.glsl
+  engines/select/shaders/select_id_frag.glsl
 
   engines/basic/shaders/conservative_depth_geom.glsl
   engines/basic/shaders/depth_vert.glsl
diff --git a/source/blender/draw/engines/select/select_engine.c b/source/blender/draw/engines/select/select_engine.c
index 0b3db521e74..88ae5ac707e 100644
--- a/source/blender/draw/engines/select/select_engine.c
+++ b/source/blender/draw/engines/select/select_engine.c
@@ -33,11 +33,6 @@ static struct {
   uint runtime_new_objects;
 } e_data = {NULL}; /* Engine data */
 
-/* Shaders */
-extern char datatoc_common_view_lib_glsl[];
-extern char datatoc_selection_id_3D_vert_glsl[];
-extern char datatoc_selection_id_frag_glsl[];
-
 /* -------------------------------------------------------------------- */
 /** \name Utils
  * \{ */
@@ -88,26 +83,12 @@ static void select_engine_init(void *vedata)
 
   /* Prepass */
   if (!sh_data->select_id_flat) {
-    const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
-    sh_data->select_id_flat = GPU_shader_create_from_arrays({
-        .vert = (const char *[]){sh_cfg_data->lib,
-                                 datatoc_common_view_lib_glsl,
-                                 datatoc_selection_id_3D_vert_glsl,
-                                 NULL},
-        .frag = (const char *[]){datatoc_selection_id_frag_glsl, NULL},
-        .defs = (const char *[]){sh_cfg_data->def, NULL},
-    });
+    sh_data->select_id_flat = GPU_shader_create_from_info_name(
+        sh_cfg == GPU_SHADER_CFG_CLIPPED ? "select_id_flat_clipped" : "select_id_flat");
   }
   if (!sh_data->select_id_uniform) {
-    const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
-    sh_data->select_id_uniform = GPU_shader_create_from_arrays({
-        .vert = (const char *[]){sh_cfg_data->lib,
-                                 datatoc_common_view_lib_glsl,
-                                 datatoc_selection_id_3D_vert_glsl,
-                                 NULL},
-        .frag = (const char *[]){datatoc_selection_id_frag_glsl, NULL},
-        .defs = (const char *[]){sh_cfg_data->def, "#define UNIFORM_ID\n", NULL},
-    });
+    sh_data->select_id_uniform = GPU_shader_create_from_info_name(
+        sh_cfg == GPU_SHADER_CFG_CLIPPED ? "select_id_uniform_clipped" : "select_id_uniform");
   }
 
   if (!stl->g_data) {
diff --git a/source/blender/draw/engines/select/shaders/infos/select_id_info.hh b/source/blender/draw/engines/select/shaders/infos/select_id_info.hh
new file mode 100644
index 00000000000..ad0de61ffc3
--- /dev/null
+++ b/source/blender/draw/engines/select/shaders/infos/select_id_info.hh
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "gpu_shader_create_info.hh"
+
+/* -------------------------------------------------------------------- */
+/** \name Select ID fo Edit Mesh selection
+ * \{ */
+
+GPU_SHADER_INTERFACE_INFO(select_id_iface, "").flat(Type::INT, "id");
+
+GPU_SHADER_CREATE_INFO(select_id_flat)
+    .push_constant(Type::FLOAT, "sizeVertex")
+    .push_constant(Type::INT, "offset")
+    .vertex_in(0, Type::VEC3, "pos")
+    .vertex_in(1, Type::INT, "index")
+    .vertex_out(select_id_iface)
+    .fragment_out(0, Type::UINT, "fragColor")
+    .vertex_source("select_id_vert.glsl")
+    .fragment_source("select_id_frag.glsl")
+    .additional_info("draw_modelmat")
+    .do_static_compilation(true);
+
+GPU_SHADER_CREATE_INFO(select_id_uniform)
+    .define("UNIFORM_ID")
+    .push_constant(Type::FLOAT, "sizeVertex")
+    .push_constant(Type::INT, "id")
+    .vertex_in(0, Type::VEC3, "pos")
+    .fragment_out(0, Type::UINT, "fragColor")
+    .vertex_source("select_id_vert.glsl")
+    .fragment_source("select_id_frag.glsl")
+    .additional_info("draw_modelmat")
+    .do_static_compilation(true);
+
+GPU_SHADER_CREATE_INFO(select_id_flat_clipped)
+    .additional_info("select_id_flat")
+    .additional_info("drw_clipped")
+    .do_static_compilation(true);
+
+GPU_SHADER_CREATE_INFO(select_id_uniform_clipped)
+    .additional_info("select_id_uniform")
+    .additional_info("drw_clipped")
+    .do_static_compilation(true);
+/** \} */
diff --git a/source/blender/draw/engines/select/shaders/select_id_frag.glsl b/source/blender/draw/engines/select/shaders/select_id_frag.glsl
new file mode 100644
index 00000000000..aecf57b4766
--- /dev/null
+++ b/source/blender/draw/engines/select/shaders/select_id_frag.glsl
@@ -0,0 +1,4 @@
+void main()
+{
+  fragColor = floatBitsToUint(intBitsToFloat(id));
+}
diff --git a/source/blender/draw/engines/select/shaders/select_id_vert.glsl b/source/blender/draw/engines/select/shaders/select_id_vert.glsl
new file mode 100644
index 00000000000..7b3b0f9984d
--- /dev/null
+++ b/source/blender/draw/engines/select/shaders/select_id_vert.glsl
@@ -0,0 +1,15 @@
+#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl)
+#pragma BLENDER_REQUIRE(common_view_lib.glsl)
+
+void main()
+{
+#ifndef UNIFORM_ID
+  id = offset + index;
+#endif
+
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
+  gl_PointSize = sizeVertex;
+
+  view_clipping_distances(world_pos);
+}
diff --git a/source/blender/draw/engines/select/shaders/selection_id_3D_vert.glsl b/source/blender/draw/engines/select/shaders/selection_id_3D_vert.glsl
deleted file mode 100644
index 9b0107cffdb..00000000000
--- a/source/blender/draw/engines/select/shaders/selection_id_3D_vert.glsl
+++ /dev/null
@@ -1,26 +0,0 @@
-
-uniform float sizeVertex;
-
-in vec3 pos;
-
-#ifndef UNIFORM_ID
-uniform int offset;
-in uint color;
-
-flat out uint id;
-#endif
-
-void main()
-{
-#ifndef UNIFORM_ID
-  id = floatBitsToUint(intBitsToFloat(offset)) + color;
-#endif
-
-  vec3 world_pos = point_object_to_world(pos);
-  gl_Position = point_world_to_ndc(world_pos);
-  gl_PointSize = sizeVertex;
-
-#ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance(world_pos);
-#endif
-}
diff --git a/source/blender/draw/engines/select/shaders/selection_id_frag.glsl b/source/blender/draw/engines/select/shaders/selection_id_frag.glsl
deleted file mode 100644
index a84bbbb2cac..00000000000
--- a/source/blender/draw/engines/select/shaders/selection_id_frag.glsl
+++ /dev/null
@@ -1,15 +0,0 @@
-
-#ifdef UNIFORM_ID
-uniform int id;
-#  define _id floatBitsToUint(intBitsToFloat(id))
-#else
-flat in uint id;
-#  define _id id
-#endif
-
-out uint fragColor;
-
-void main()
-{
-  fragColor = _id;
-}
diff --git a/source/blender/draw/intern/draw_cache_impl_subdivision.cc b/source/blender/draw/intern/draw_cache_impl_subdivision.cc
index 4a39ca6dacb..7c72b77af1f 100644
--- a/source/blender/draw/intern/draw_cache_impl_subdivision.cc
+++ b/source/blender/draw/intern/draw_cache_impl_subdivision.cc
@@ -361,7 +361,7 @@ static GPUVertFormat *get_origindex_format()
 {
   static GPUVertFormat format;
   if (format.attr_len == 0) {
-    GPU_vertformat_attr_add(&format, "color", GPU_COMP_U32, 1, GPU_FETCH_INT);
+    GPU_vertformat_attr_add(&format, "index", GPU_COMP_I32, 1, GPU_FETCH_INT);
   }
   return &format;
 }
@@ -442,15 +442,15 @@ static uint tris_count_from_number_of_loops(const uint number_of_loops)
  * \{ */
 
 void draw_subdiv_init_origindex_buffer(GPUVertBuf *buffer,
-                                       int *vert_origindex,
+                                       int32_t *vert_origindex,
                                        uint num_loops,
                                        uint loose_len)
 {
   GPU_vertbuf_init_with_format_ex(buffer, get_origindex_format(), GPU_USAGE_STATIC);
   GPU_vertbuf_data_alloc(buffer, num_loops + loose_len);
 
-  int *vbo_data = (int *)GPU_vertbuf_get_data(buffer);
-  memcpy(vbo_data, vert_origindex, num_loops * sizeof(int));
+  int32_t *vbo_data = (int32_t *)GPU_vertbuf_get_data(buffer);
+  memcpy(vbo_data, vert_origindex, num_loops * sizeof(int32_t));
 }
 
 GPUVertBuf *draw_subdiv_build_origindex_buffer(int *vert_origindex, uint num_loops)
diff --git a/source/blender/draw/intern/draw_subdivision.h b/source/blender/draw/intern/draw_subdivision.h
index 8d7bc3dc495..e5f64a99092 100644
--- a/source/blender/draw/intern/draw_subdivision.h
+++ b/source/blender/draw/intern/draw_subdivision.h
@@ -206,7 +206,7 @@ void draw_subdiv_init_mesh_render_data(DRWSubdivCache *cache,
                                        const struct ToolSettings *toolsettings);
 
 void draw_subdiv_init_origindex_buffer(struct GPUVertBuf *buffer,
-                                       int *vert_origindex,
+                                       int32_t *vert_origindex,
                                        uint num_loops,
                                        uint loose_len);
 
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc
index be4c292e842..c7d36098140 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc
@@ -22,12 +22,11 @@ static void extract_select_idx_init_impl(const MeshRenderData *UNUSED(mr),
   GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf);
   static GPUVertFormat format = {0};
   if (format.attr_len == 0) {
-    /* TODO: rename "color" to something more descriptive. */
-    GPU_vertformat_attr_add(&format, "color", GPU_COMP_U32, 1, GPU_FETCH_INT);
+    GPU_vertformat_attr_add(&format, "index", GPU_COMP_I32, 1, GPU_FETCH_INT);
   }
   GPU_vertbuf_init_with_format(vbo, &format);
   GPU_vertbuf_data_alloc(vbo, len);
-  *(uint32_t **)tls_data = (uint32_t *)GPU_vertbuf_get_data(vbo);
+  *(int32_t **)tls_data = (int32_t *)GPU_vertbuf_get_data(vbo);
 }
 
 static void extract_select_idx_init(const MeshRenderData *mr,
@@ -52,7 +51,7 @@ static void extract_poly_idx_i

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list