Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_instance_data.c
| Show All 18 Lines | |||||
| /** \file | /** \file | ||||
| * \ingroup draw | * \ingroup draw | ||||
| */ | */ | ||||
| /** | /** | ||||
| * DRW Instance Data Manager | * DRW Instance Data Manager | ||||
| * This is a special memory manager that keeps memory blocks ready to send as vbo data in one continuous allocation. | * This is a special memory manager that keeps memory blocks ready to send as vbo data in one continuous allocation. | ||||
| * This way we avoid feeding gawain each instance data one by one and unnecessary memcpy. | * This way we avoid feeding gawain each instance data one by one and unnecessary memcpy. | ||||
| * Since we loose which memory block was used each DRWShadingGroup we need to redistribute them in the same order/size | * Since we loose which memory block was used each #DRWShadingGroup we need to redistribute them in the same order/size | ||||
| * to avoid to realloc each frame. | * to avoid to realloc each frame. | ||||
| * This is why DRWInstanceDatas are sorted in a list for each different data size. | * This is why #DRWInstanceDatas are sorted in a list for each different data size. | ||||
| **/ | */ | ||||
| #include "draw_instance_data.h" | #include "draw_instance_data.h" | ||||
| #include "DRW_engine.h" | #include "DRW_engine.h" | ||||
| #include "DRW_render.h" /* For DRW_shgroup_get_instance_count() */ | #include "DRW_render.h" /* For DRW_shgroup_get_instance_count() */ | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_mempool.h" | #include "BLI_mempool.h" | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * This manager allows to distribute existing batches for instancing | * This manager allows to distribute existing batches for instancing | ||||
| * attributes. This reduce the number of batches creation. | * attributes. This reduce the number of batches creation. | ||||
| * Querying a batch is done with a vertex format. This format should | * Querying a batch is done with a vertex format. This format should | ||||
| * be static so that it's pointer never changes (because we are using | * be static so that it's pointer never changes (because we are using | ||||
| * this pointer as identifier [we don't want to check the full format | * this pointer as identifier [we don't want to check the full format | ||||
| * that would be too slow]). | * that would be too slow]). | ||||
| **/ | */ | ||||
| static void instance_batch_free(GPUBatch *batch, void *UNUSED(user_data)) | static void instance_batch_free(GPUBatch *batch, void *UNUSED(user_data)) | ||||
| { | { | ||||
| if (batch->verts[0] == NULL) { | if (batch->verts[0] == NULL) { | ||||
| /** XXX This is a false positive case. | /** XXX This is a false positive case. | ||||
| * The batch has been requested but not init yet | * The batch has been requested but not init yet | ||||
| * and there is a chance that it might become init. | * and there is a chance that it might become init. | ||||
| **/ | */ | ||||
| return; | return; | ||||
| } | } | ||||
| /* Free all batches that have the same key before they are reused. */ | /* Free all batches that have the same key before they are reused. */ | ||||
| /* TODO: Make it thread safe! Batch freeing can happen from another thread. */ | /* TODO: Make it thread safe! Batch freeing can happen from another thread. */ | ||||
| /* XXX we need to iterate over all idatalists unless we make some smart | /* XXX we need to iterate over all idatalists unless we make some smart | ||||
| * data structure to store the locations to update. */ | * data structure to store the locations to update. */ | ||||
| for (DRWInstanceDataList *idatalist = g_idatalists.first; idatalist; idatalist = idatalist->next) { | for (DRWInstanceDataList *idatalist = g_idatalists.first; idatalist; idatalist = idatalist->next) { | ||||
| DRWInstancingBuffer *ibuf = idatalist->instancing.ibufs; | DRWInstancingBuffer *ibuf = idatalist->instancing.ibufs; | ||||
| ▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | |||||
| static void DRW_instance_data_free(DRWInstanceData *idata) | static void DRW_instance_data_free(DRWInstanceData *idata) | ||||
| { | { | ||||
| BLI_mempool_destroy(idata->mempool); | BLI_mempool_destroy(idata->mempool); | ||||
| } | } | ||||
| /** | /** | ||||
| * Return a pointer to the next instance data space. | * Return a pointer to the next instance data space. | ||||
| **/ | */ | ||||
| void *DRW_instance_data_next(DRWInstanceData *idata) | void *DRW_instance_data_next(DRWInstanceData *idata) | ||||
| { | { | ||||
| return BLI_mempool_alloc(idata->mempool); | return BLI_mempool_alloc(idata->mempool); | ||||
| } | } | ||||
| DRWInstanceData *DRW_instance_data_request(DRWInstanceDataList *idatalist, uint attr_size) | DRWInstanceData *DRW_instance_data_request(DRWInstanceDataList *idatalist, uint attr_size) | ||||
| { | { | ||||
| BLI_assert(attr_size > 0 && attr_size <= MAX_INSTANCE_DATA_SIZE); | BLI_assert(attr_size > 0 && attr_size <= MAX_INSTANCE_DATA_SIZE); | ||||
| ▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines | |||||