diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-05-26 15:51:44 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-05-26 15:52:45 +0300 |
commit | 55e3930b253e4c6687ff94b474cc9973e0c00520 (patch) | |
tree | e42fb398ce0540134e2b02c9ba0abc1b052ceef4 /source/blender/draw/intern/draw_cache_impl_subdivision.cc | |
parent | 38a2576acef020566497f1d0c8c2c492de74b769 (diff) |
Fix T98392: GPU subdivision crash with knife tools
The face dots normals may not be always requested, thus leading to a
crash by null pointer dereference.
Diffstat (limited to 'source/blender/draw/intern/draw_cache_impl_subdivision.cc')
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_subdivision.cc | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/source/blender/draw/intern/draw_cache_impl_subdivision.cc b/source/blender/draw/intern/draw_cache_impl_subdivision.cc index e3842ec2231..3a5593fa2a5 100644 --- a/source/blender/draw/intern/draw_cache_impl_subdivision.cc +++ b/source/blender/draw/intern/draw_cache_impl_subdivision.cc @@ -69,6 +69,7 @@ enum { SHADER_PATCH_EVALUATION, SHADER_PATCH_EVALUATION_FVAR, SHADER_PATCH_EVALUATION_FACE_DOTS, + SHADER_PATCH_EVALUATION_FACE_DOTS_WITH_NORMALS, SHADER_COMP_CUSTOM_DATA_INTERP_1D, SHADER_COMP_CUSTOM_DATA_INTERP_2D, SHADER_COMP_CUSTOM_DATA_INTERP_3D, @@ -107,7 +108,8 @@ static const char *get_shader_code(int shader_type) } case SHADER_PATCH_EVALUATION: case SHADER_PATCH_EVALUATION_FVAR: - case SHADER_PATCH_EVALUATION_FACE_DOTS: { + case SHADER_PATCH_EVALUATION_FACE_DOTS: + case SHADER_PATCH_EVALUATION_FACE_DOTS_WITH_NORMALS: { return datatoc_common_subdiv_patch_evaluation_comp_glsl; } case SHADER_COMP_CUSTOM_DATA_INTERP_1D: @@ -163,6 +165,9 @@ static const char *get_shader_name(int shader_type) case SHADER_PATCH_EVALUATION_FACE_DOTS: { return "subdiv patch evaluation face dots"; } + case SHADER_PATCH_EVALUATION_FACE_DOTS_WITH_NORMALS: { + return "subdiv patch evaluation face dots with normals"; + } case SHADER_COMP_CUSTOM_DATA_INTERP_1D: { return "subdiv custom data interp 1D"; } @@ -206,6 +211,13 @@ static GPUShader *get_patch_evaluation_shader(int shader_type) "#define OPENSUBDIV_GLSL_COMPUTE_USE_1ST_DERIVATIVES\n" "#define FDOTS_EVALUATION\n"; } + else if (shader_type == SHADER_PATCH_EVALUATION_FACE_DOTS_WITH_NORMALS) { + defines = + "#define OSD_PATCH_BASIS_GLSL\n" + "#define OPENSUBDIV_GLSL_COMPUTE_USE_1ST_DERIVATIVES\n" + "#define FDOTS_EVALUATION\n" + "#define FOTS_NORMALS\n"; + } else { defines = "#define OSD_PATCH_BASIS_GLSL\n" @@ -1625,7 +1637,9 @@ void draw_subdiv_build_fdots_buffers(const DRWSubdivCache *cache, get_patch_param_format()); evaluator->wrapPatchParamBuffer(evaluator, &patch_param_buffer_interface); - GPUShader *shader = get_patch_evaluation_shader(SHADER_PATCH_EVALUATION_FACE_DOTS); + GPUShader *shader = get_patch_evaluation_shader( + fdots_nor ? SHADER_PATCH_EVALUATION_FACE_DOTS_WITH_NORMALS : + SHADER_PATCH_EVALUATION_FACE_DOTS); GPU_shader_bind(shader); int binding_point = 0; @@ -1638,7 +1652,11 @@ void draw_subdiv_build_fdots_buffers(const DRWSubdivCache *cache, GPU_vertbuf_bind_as_ssbo(patch_index_buffer, binding_point++); GPU_vertbuf_bind_as_ssbo(patch_param_buffer, binding_point++); GPU_vertbuf_bind_as_ssbo(fdots_pos, binding_point++); - GPU_vertbuf_bind_as_ssbo(fdots_nor, binding_point++); + /* F-dots normals may not be requested, still reserve the binding point. */ + if (fdots_nor) { + GPU_vertbuf_bind_as_ssbo(fdots_nor, binding_point); + } + binding_point++; GPU_indexbuf_bind_as_ssbo(fdots_indices, binding_point++); GPU_vertbuf_bind_as_ssbo(cache->extra_coarse_face_data, binding_point++); BLI_assert(binding_point <= MAX_GPU_SUBDIV_SSBOS); |