Fix: GPU: Ensures length of curves GPUIndexBuf to be multiple of 4

Exception is thrown in gpu_storage_buffer.cc

To reproduce create legacy Bezier curve and convert it to new Curves.
Code is from #116617

Pull Request: https://projects.blender.org/blender/blender/pulls/118951
This commit is contained in:
laurynas 2024-03-03 16:39:11 +01:00 committed by Clément Foucault
parent 3d136d0d00
commit bf17fc8d79
2 changed files with 13 additions and 5 deletions

View File

@ -454,11 +454,14 @@ static void curves_batch_cache_ensure_procedural_indices(const bke::CurvesGeomet
GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
GPU_vertbuf_data_alloc(vbo, 1);
GPUIndexBuf *ibo = GPU_indexbuf_build_curves_on_device(
prim_type, curves.curves_num(), verts_per_curve);
GPUIndexBuf *ibo = nullptr;
eGPUBatchFlag owns_flag = GPU_BATCH_OWNS_VBO;
if (curves.curves_num()) {
ibo = GPU_indexbuf_build_curves_on_device(prim_type, curves.curves_num(), verts_per_curve);
owns_flag |= GPU_BATCH_OWNS_INDEX;
}
cache.final[subdiv].proc_hairs[thickness_res - 1] = GPU_batch_create_ex(
prim_type, vbo, ibo, GPU_BATCH_OWNS_VBO | GPU_BATCH_OWNS_INDEX);
prim_type, vbo, ibo, owns_flag);
}
static bool curves_ensure_attributes(const Curves &curves,

View File

@ -270,7 +270,12 @@ GPUIndexBuf *GPU_indexbuf_build_curves_on_device(GPUPrimType prim_type,
tris ? GPU_SHADER_INDEXBUF_TRIS :
(lines ? GPU_SHADER_INDEXBUF_LINES : GPU_SHADER_INDEXBUF_POINTS));
GPU_shader_bind(shader);
GPUIndexBuf *ibo = GPU_indexbuf_build_on_device(curves_num * dispatch_x_dim);
int index_len = curves_num * dispatch_x_dim;
/* Buffer's size in bytes is required to be multiple of 16.
* Here is made an assumption that buffer's index_type is GPU_INDEX_U32.
* This will make buffer size multiple of 16 after multiplying by sizeof(uint32_t). */
int multiple_of_4 = ceil_to_multiple_u(index_len, 4);
GPUIndexBuf *ibo = GPU_indexbuf_build_on_device(multiple_of_4);
int resolution;
if (tris) {
resolution = 6;