Blender Git Loki
Git Commits -> Revision eed45d2
Revision eed45d2 by Kévin Dietrich (master) December 27, 2021, 15:35 (GMT) |
OpenSubDiv: add support for an OpenGL evaluator This evaluator is used in order to evaluate subdivision at render time, allowing for faster renders of meshes with a subdivision surface modifier placed at the last position in the modifier list. When evaluating the subsurf modifier, we detect whether we can delegate evaluation to the draw code. If so, the subdivision is first evaluated on the GPU using our own custom evaluator (only the coarse data needs to be initially sent to the GPU), then, buffers for the final `MeshBufferCache` are filled on the GPU using a set of compute shaders. However, some buffers are still filled on the CPU side, if doing so on the GPU is impractical (e.g. the line adjacency buffer used for x-ray, whose logic is hardly GPU compatible). This is done at the mesh buffer extraction level so that the result can be readily used in the various OpenGL engines, without having to write custom geometry or tesselation shaders. We use our own subdivision evaluation shaders, instead of OpenSubDiv's vanilla one, in order to control the data layout, and interpolation. For example, we store vertex colors as compressed 16-bit integers, while OpenSubDiv's default evaluator only work for float types. In order to still access the modified geometry on the CPU side, for use in modifiers or transform operators, a dedicated wrapper type is added `MESH_WRAPPER_TYPE_SUBD`. Subdivision will be lazily evaluated via `BKE_object_get_evaluated_mesh` which will create such a wrapper if possible. If the final subdivision surface is not needed on the CPU side, `BKE_object_get_evaluated_mesh_no_subsurf` should be used. Enabling or disabling GPU subdivision can be done through the user preferences (under Viewport -> Subdivision). See patch description for benchmarks. Reviewed By: campbellbarton, jbakker, fclem, brecht, #eevee_viewport Differential Revision: https://developer.blender.org/D12406 |
Commit Details:
Full Hash: eed45d2a239a2a18a2420ba15dfb55e0f8dc5630
Parent Commit: 31e120e
Lines Changed: +7712, -707
26 Added Paths:
/intern/opensubdiv/internal/evaluator/evaluator_cache_impl.cc (+47, -0) (View)
/intern/opensubdiv/internal/evaluator/evaluator_cache_impl.h (+38, -0) (View)
/intern/opensubdiv/internal/evaluator/eval_output.cc (+35, -0) (View)
/intern/opensubdiv/internal/evaluator/eval_output.h (+582, -0) (View)
/intern/opensubdiv/internal/evaluator/eval_output_cpu.cc (+23, -0) (View)
/intern/opensubdiv/internal/evaluator/eval_output_cpu.h (+66, -0) (View)
/intern/opensubdiv/internal/evaluator/eval_output_gpu.cc (+120, -0) (View)
/intern/opensubdiv/internal/evaluator/eval_output_gpu.h (+71, -0) (View)
/intern/opensubdiv/internal/evaluator/patch_map.cc (+212, -0) (View)
/intern/opensubdiv/internal/evaluator/patch_map.h (+264, -0) (View)
/source/blender/blenkernel/BKE_subdiv_modifier.h (+71, -0) (View)
/source/blender/blenkernel/intern/subdiv_modifier.c (+162, -0) (View)
/source/blender/draw/intern/draw_cache_impl_subdivision.cc (+1932, -0) (View)
/source/blender/draw/intern/draw_subdivision.h (+231, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_custom_data_interp_comp.glsl (+230, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_ibo_lines_comp.glsl (+57, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_ibo_tris_comp.glsl (+43, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_lib.glsl (+176, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_normals_accumulate_comp.glsl (+56, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_normals_finalize_comp.glsl (+34, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_patch_evaluation_comp.glsl (+416, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_vbo_edge_fac_comp.glsl (+97, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_vbo_edituv_strech_angle_comp.glsl (+80, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_vbo_edituv_strech_area_comp.glsl (+31, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_vbo_lnor_comp.glsl (+52, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_vbo_sculpt_data_comp.glsl (+47, -0) (View)
/intern/opensubdiv/internal/evaluator/evaluator_cache_impl.h (+38, -0) (View)
/intern/opensubdiv/internal/evaluator/eval_output.cc (+35, -0) (View)
/intern/opensubdiv/internal/evaluator/eval_output.h (+582, -0) (View)
/intern/opensubdiv/internal/evaluator/eval_output_cpu.cc (+23, -0) (View)
/intern/opensubdiv/internal/evaluator/eval_output_cpu.h (+66, -0) (View)
/intern/opensubdiv/internal/evaluator/eval_output_gpu.cc (+120, -0) (View)
/intern/opensubdiv/internal/evaluator/eval_output_gpu.h (+71, -0) (View)
/intern/opensubdiv/internal/evaluator/patch_map.cc (+212, -0) (View)
/intern/opensubdiv/internal/evaluator/patch_map.h (+264, -0) (View)
/source/blender/blenkernel/BKE_subdiv_modifier.h (+71, -0) (View)
/source/blender/blenkernel/intern/subdiv_modifier.c (+162, -0) (View)
/source/blender/draw/intern/draw_cache_impl_subdivision.cc (+1932, -0) (View)
/source/blender/draw/intern/draw_subdivision.h (+231, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_custom_data_interp_comp.glsl (+230, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_ibo_lines_comp.glsl (+57, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_ibo_tris_comp.glsl (+43, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_lib.glsl (+176, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_normals_accumulate_comp.glsl (+56, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_normals_finalize_comp.glsl (+34, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_patch_evaluation_comp.glsl (+416, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_vbo_edge_fac_comp.glsl (+97, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_vbo_edituv_strech_angle_comp.glsl (+80, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_vbo_edituv_strech_area_comp.glsl (+31, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_vbo_lnor_comp.glsl (+52, -0) (View)
/source/blender/draw/intern/shaders/common_subdiv_vbo_sculpt_data_comp.glsl (+47, -0) (View)
75 Modified Paths:
/intern/opensubdiv/CMakeLists.txt (+11, -0) (Diff)
/intern/opensubdiv/internal/evaluator/evaluator_capi.cc (+116, -2) (Diff)
/intern/opensubdiv/internal/evaluator/evaluator_impl.cc (+157, -492) (Diff)
/intern/opensubdiv/internal/evaluator/evaluator_impl.h (+58, -11) (Diff)
/intern/opensubdiv/opensubdiv_evaluator_capi.h (+100, -1) (Diff)
/release/datafiles/userdef/userdef_default.c (+1, -1) (Diff)
/release/scripts/startup/bl_ui/space_userpref.py (+12, -0) (Diff)
/source/blender/blenkernel/BKE_mesh_wrapper.h (+3, -0) (Diff)
/source/blender/blenkernel/BKE_object.h (+11, -0) (Diff)
/source/blender/blenkernel/BKE_subdiv.h (+13, -1) (Diff)
/source/blender/blenkernel/BKE_subdiv_eval.h (+12, -2) (Diff)
/source/blender/blenkernel/BKE_subdiv_foreach.h (+2, -1) (Diff)
/source/blender/blenkernel/CMakeLists.txt (+2, -0) (Diff)
/source/blender/blenkernel/intern/mesh_normals.cc (+1, -0) (Diff)
/source/blender/blenkernel/intern/mesh_wrapper.c (+82, -3) (Diff)
/source/blender/blenkernel/intern/modifier.c (+1, -0) (Diff)
/source/blender/blenkernel/intern/multires_reshape_smooth.c (+3, -2) (Diff)
/source/blender/blenkernel/intern/multires_reshape_util.c (+1, -1) (Diff)
/source/blender/blenkernel/intern/multires_reshape_vertcos.c (+2, -1) (Diff)
/source/blender/blenkernel/intern/multires_versioning.c (+1, -1) (Diff)
/source/blender/blenkernel/intern/object.cc (+33, -3) (Diff)
/source/blender/blenkernel/intern/subdiv.c (+11, -1) (Diff)
/source/blender/blenkernel/intern/subdiv_ccg.c (+2, -1) (Diff)
/source/blender/blenkernel/intern/subdiv_deform.c (+4, -2) (Diff)
/source/blender/blenkernel/intern/subdiv_eval.c (+94, -18) (Diff)
/source/blender/blenkernel/intern/subdiv_foreach.c (+2, -1) (Diff)
/source/blender/blenkernel/intern/subdiv_mesh.c (+4, -2) (Diff)
/source/blender/draw/CMakeLists.txt (+16, -0) (Diff)
/source/blender/draw/DRW_engine.h (+4, -0) (Diff)
/source/blender/draw/engines/overlay/overlay_armature.c (+1, -1) (Diff)
/source/blender/draw/intern/draw_cache.c (+12, -12) (Diff)
/source/blender/draw/intern/draw_cache_extract.h (+17, -7) (Diff)
/source/blender/draw/intern/draw_cache_extract_mesh.cc (+102, -0) (Diff)
/source/blender/draw/intern/draw_cache_impl_mesh.c (+30, -0) (Diff)
/source/blender/draw/intern/draw_manager.c (+4, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh.h (+24, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc (+156, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc (+31, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_adjacency.cc (+67, -5) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc (+72, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc (+30, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc (+87, -6) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc (+83, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_data.cc (+59, -8) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc (+59, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc (+55, -10) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc (+91, -6) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_pos.cc (+42, -6) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_lnor.cc (+27, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc (+122, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_sculpt_data.cc (+102, -7) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc (+97, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc (+72, -17) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_vcol.cc (+94, -17) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_weights.cc (+48, -0) (Diff)
/source/blender/editors/space_view3d/view3d_draw.c (+1, -0) (Diff)
/source/blender/editors/transform/transform_snap_object.c (+1, -1) (Diff)
/source/blender/gpu/GPU_context.h (+2, -0) (Diff)
/source/blender/gpu/GPU_index_buffer.h (+12, -0) (Diff)
/source/blender/gpu/GPU_vertex_buffer.h (+6, -1) (Diff)
/source/blender/gpu/intern/gpu_context.cc (+9, -0) (Diff)
/source/blender/gpu/intern/gpu_index_buffer.cc (+17, -2) (Diff)
/source/blender/gpu/intern/gpu_index_buffer_private.hh (+4, -0) (Diff)
/source/blender/gpu/intern/gpu_vertex_buffer.cc (+17, -1) (Diff)
/source/blender/gpu/intern/gpu_vertex_buffer_private.hh (+3, -1) (Diff)
/source/blender/gpu/opengl/gl_index_buffer.cc (+10, -0) (Diff)
/source/blender/gpu/opengl/gl_index_buffer.hh (+4, -0) (Diff)
/source/blender/gpu/opengl/gl_vertex_buffer.cc (+15, -1) (Diff)
/source/blender/gpu/opengl/gl_vertex_buffer.hh (+6, -1) (Diff)
/source/blender/makesdna/DNA_mesh_types.h (+11, -1) (Diff)
/source/blender/makesdna/DNA_modifier_types.h (+7, -0) (Diff)
/source/blender/makesdna/DNA_userdef_types.h (+1, -0) (Diff)
/source/blender/makesrna/intern/rna_userdef.c (+25, -0) (Diff)
/source/blender/modifiers/intern/MOD_subsurf.c (+38, -49) (Diff)
/source/blender/windowmanager/intern/wm_init_exit.c (+7, -0) (Diff)
/intern/opensubdiv/internal/evaluator/evaluator_capi.cc (+116, -2) (Diff)
/intern/opensubdiv/internal/evaluator/evaluator_impl.cc (+157, -492) (Diff)
/intern/opensubdiv/internal/evaluator/evaluator_impl.h (+58, -11) (Diff)
/intern/opensubdiv/opensubdiv_evaluator_capi.h (+100, -1) (Diff)
/release/datafiles/userdef/userdef_default.c (+1, -1) (Diff)
/release/scripts/startup/bl_ui/space_userpref.py (+12, -0) (Diff)
/source/blender/blenkernel/BKE_mesh_wrapper.h (+3, -0) (Diff)
/source/blender/blenkernel/BKE_object.h (+11, -0) (Diff)
/source/blender/blenkernel/BKE_subdiv.h (+13, -1) (Diff)
/source/blender/blenkernel/BKE_subdiv_eval.h (+12, -2) (Diff)
/source/blender/blenkernel/BKE_subdiv_foreach.h (+2, -1) (Diff)
/source/blender/blenkernel/CMakeLists.txt (+2, -0) (Diff)
/source/blender/blenkernel/intern/mesh_normals.cc (+1, -0) (Diff)
/source/blender/blenkernel/intern/mesh_wrapper.c (+82, -3) (Diff)
/source/blender/blenkernel/intern/modifier.c (+1, -0) (Diff)
/source/blender/blenkernel/intern/multires_reshape_smooth.c (+3, -2) (Diff)
/source/blender/blenkernel/intern/multires_reshape_util.c (+1, -1) (Diff)
/source/blender/blenkernel/intern/multires_reshape_vertcos.c (+2, -1) (Diff)
/source/blender/blenkernel/intern/multires_versioning.c (+1, -1) (Diff)
/source/blender/blenkernel/intern/object.cc (+33, -3) (Diff)
/source/blender/blenkernel/intern/subdiv.c (+11, -1) (Diff)
/source/blender/blenkernel/intern/subdiv_ccg.c (+2, -1) (Diff)
/source/blender/blenkernel/intern/subdiv_deform.c (+4, -2) (Diff)
/source/blender/blenkernel/intern/subdiv_eval.c (+94, -18) (Diff)
/source/blender/blenkernel/intern/subdiv_foreach.c (+2, -1) (Diff)
/source/blender/blenkernel/intern/subdiv_mesh.c (+4, -2) (Diff)
/source/blender/draw/CMakeLists.txt (+16, -0) (Diff)
/source/blender/draw/DRW_engine.h (+4, -0) (Diff)
/source/blender/draw/engines/overlay/overlay_armature.c (+1, -1) (Diff)
/source/blender/draw/intern/draw_cache.c (+12, -12) (Diff)
/source/blender/draw/intern/draw_cache_extract.h (+17, -7) (Diff)
/source/blender/draw/intern/draw_cache_extract_mesh.cc (+102, -0) (Diff)
/source/blender/draw/intern/draw_cache_impl_mesh.c (+30, -0) (Diff)
/source/blender/draw/intern/draw_manager.c (+4, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh.h (+24, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc (+156, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc (+31, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_adjacency.cc (+67, -5) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc (+72, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc (+30, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc (+87, -6) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc (+83, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_data.cc (+59, -8) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc (+59, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc (+55, -10) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc (+91, -6) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_pos.cc (+42, -6) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_lnor.cc (+27, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc (+122, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_sculpt_data.cc (+102, -7) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc (+97, -0) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc (+72, -17) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_vcol.cc (+94, -17) (Diff)
/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_weights.cc (+48, -0) (Diff)
/source/blender/editors/space_view3d/view3d_draw.c (+1, -0) (Diff)
/source/blender/editors/transform/transform_snap_object.c (+1, -1) (Diff)
/source/blender/gpu/GPU_context.h (+2, -0) (Diff)
/source/blender/gpu/GPU_index_buffer.h (+12, -0) (Diff)
/source/blender/gpu/GPU_vertex_buffer.h (+6, -1) (Diff)
/source/blender/gpu/intern/gpu_context.cc (+9, -0) (Diff)
/source/blender/gpu/intern/gpu_index_buffer.cc (+17, -2) (Diff)
/source/blender/gpu/intern/gpu_index_buffer_private.hh (+4, -0) (Diff)
/source/blender/gpu/intern/gpu_vertex_buffer.cc (+17, -1) (Diff)
/source/blender/gpu/intern/gpu_vertex_buffer_private.hh (+3, -1) (Diff)
/source/blender/gpu/opengl/gl_index_buffer.cc (+10, -0) (Diff)
/source/blender/gpu/opengl/gl_index_buffer.hh (+4, -0) (Diff)
/source/blender/gpu/opengl/gl_vertex_buffer.cc (+15, -1) (Diff)
/source/blender/gpu/opengl/gl_vertex_buffer.hh (+6, -1) (Diff)
/source/blender/makesdna/DNA_mesh_types.h (+11, -1) (Diff)
/source/blender/makesdna/DNA_modifier_types.h (+7, -0) (Diff)
/source/blender/makesdna/DNA_userdef_types.h (+1, -0) (Diff)
/source/blender/makesrna/intern/rna_userdef.c (+25, -0) (Diff)
/source/blender/modifiers/intern/MOD_subsurf.c (+38, -49) (Diff)
/source/blender/windowmanager/intern/wm_init_exit.c (+7, -0) (Diff)