Automatic batch freezing.
This commit is contained in:
		@ -837,6 +837,32 @@ static void rk_pack_batch(
 | 
				
			|||||||
    batch.state = RK_BATCH_STATE_PACKED;
 | 
					    batch.state = RK_BATCH_STATE_PACKED;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static bool rk_compare_replace(
 | 
				
			||||||
 | 
					    void * __restrict _dst,
 | 
				
			||||||
 | 
					    void const * __restrict _src,
 | 
				
			||||||
 | 
					    unsigned const size) {
 | 
				
			||||||
 | 
					    rk_ulong hash = 0;
 | 
				
			||||||
 | 
					    rk_ulong * dst = reinterpret_cast<rk_ulong *>(_dst);
 | 
				
			||||||
 | 
					    rk_ulong const * src = reinterpret_cast<rk_ulong const *>(_src);
 | 
				
			||||||
 | 
					    unsigned count = size / sizeof(rk_ulong);
 | 
				
			||||||
 | 
					    unsigned remain = (size - count * sizeof(rk_ulong));
 | 
				
			||||||
 | 
					    if (count) {
 | 
				
			||||||
 | 
					        do {
 | 
				
			||||||
 | 
					            hash |= *dst ^ *src;
 | 
				
			||||||
 | 
					            *dst++ = *src++;
 | 
				
			||||||
 | 
					        } while(--count > 0);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    rk_ubyte * rdst = reinterpret_cast<rk_ubyte *>(dst);
 | 
				
			||||||
 | 
					    rk_ubyte const * rsrc = reinterpret_cast<rk_ubyte const *>(src);
 | 
				
			||||||
 | 
					    if (remain) {
 | 
				
			||||||
 | 
					        do {
 | 
				
			||||||
 | 
					            hash |= *rdst ^ *rsrc;
 | 
				
			||||||
 | 
					            *rdst++ = *rsrc++;
 | 
				
			||||||
 | 
					        } while(--remain > 0);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return (hash != 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void rk_fill_batch(
 | 
					void rk_fill_batch(
 | 
				
			||||||
    rk_batch_t _batch,
 | 
					    rk_batch_t _batch,
 | 
				
			||||||
    rk_uint count,
 | 
					    rk_uint count,
 | 
				
			||||||
@ -861,30 +887,28 @@ void rk_fill_batch(
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    bool const is_empty = (batch->state < RK_BATCH_STATE_FILLED);
 | 
					    bool const is_empty = (batch->state < RK_BATCH_STATE_FILLED);
 | 
				
			||||||
 | 
					    bool const resized = (count != batch->count);
 | 
				
			||||||
    bool const got_everything = (flags && meshes && got_all_params);
 | 
					    bool const got_everything = (flags && meshes && got_all_params);
 | 
				
			||||||
    bool const need_sorting = (is_empty || flags || meshes || count != batch->count);
 | 
					 | 
				
			||||||
    if (is_empty && !got_everything) {
 | 
					    if (is_empty && !got_everything) {
 | 
				
			||||||
        rk_printf("rk_fill_batch(): cannot freeze and empty batch.");
 | 
					        rk_printf("rk_fill_batch(): cannot freeze and empty batch.");
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
    } else if (count > batch->count && !got_everything) {
 | 
					    } else if (count > batch->count && !got_everything) {
 | 
				
			||||||
        rk_printf("rk_fill_batch(): cannot grow a frozen batch.");
 | 
					        rk_printf("rk_fill_batch(): cannot grow a frozen batch.");
 | 
				
			||||||
    } else {
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    batch->count = count;
 | 
					    batch->count = count;
 | 
				
			||||||
    }
 | 
					    bool const cmp_flags =
 | 
				
			||||||
    if (flags) {
 | 
					        (flags && rk_compare_replace(batch->flags, flags, batch->count * sizeof(rk_instance_flags)));
 | 
				
			||||||
        memcpy(batch->flags, flags, batch->count * sizeof(rk_instance_flags));
 | 
					    bool const cmp_meshes =
 | 
				
			||||||
    }
 | 
					        (meshes && rk_compare_replace(batch->meshes, meshes, batch->count * sizeof(rk_mesh)));
 | 
				
			||||||
    if (meshes) {
 | 
					    bool const need_sorting = (cmp_flags || cmp_meshes || resized);
 | 
				
			||||||
        memcpy(batch->meshes, meshes, batch->count * sizeof(rk_mesh));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (batch->nparams) {
 | 
					    if (batch->nparams) {
 | 
				
			||||||
        rk_parameter const * const last_param = batch->params + batch->nparams;
 | 
					        rk_parameter const * const last_param = batch->params + batch->nparams;
 | 
				
			||||||
        if (got_any_params) {
 | 
					        if (got_any_params) {
 | 
				
			||||||
            rk_ubyte const * const * src = params;
 | 
					            rk_ubyte const * const * src = params;
 | 
				
			||||||
            for (rk_parameter const * dst = batch->params; dst < last_param; ++dst, ++src) {
 | 
					            for (rk_parameter const * dst = batch->params; dst < last_param; ++dst, ++src) {
 | 
				
			||||||
                dst->dirty = (need_sorting || *src);
 | 
					                dst->dirty =
 | 
				
			||||||
                if (*src) {
 | 
					                    (*src && rk_compare_replace(dst->source, *src, batch->count * dst->src_size)) || need_sorting;
 | 
				
			||||||
                    memcpy(dst->source, *src, batch->count * dst->src_size);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else if (need_sorting) {
 | 
					        } else if (need_sorting) {
 | 
				
			||||||
            for (rk_parameter const * dst = batch->params; dst < last_param; ++dst) {
 | 
					            for (rk_parameter const * dst = batch->params; dst < last_param; ++dst) {
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user