Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_uniformbuffer.c
| Show First 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | if (ubo->buffer.size > GPU_max_ubo_size()) { | ||||
| } | } | ||||
| GPU_uniformbuffer_free(&ubo->buffer); | GPU_uniformbuffer_free(&ubo->buffer); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* Make sure we comply to the ubo alignment requirements. */ | /* Make sure we comply to the ubo alignment requirements. */ | ||||
| gpu_uniformbuffer_inputs_sort(inputs); | gpu_uniformbuffer_inputs_sort(inputs); | ||||
| for (LinkData *link = inputs->first; link; link = link->next) { | LISTBASE_FOREACH (LinkData *, link, inputs) { | ||||
| const eGPUType gputype = get_padded_gpu_type(link); | const eGPUType gputype = get_padded_gpu_type(link); | ||||
| ubo->buffer.size += gputype * sizeof(float); | ubo->buffer.size += gputype * sizeof(float); | ||||
| } | } | ||||
| /* Round up to size of vec4 */ | /* Round up to size of vec4 */ | ||||
| ubo->buffer.size = ((ubo->buffer.size + 15) / 16) * 16; | ubo->buffer.size = ((ubo->buffer.size + 15) / 16) * 16; | ||||
| /* Allocate the data. */ | /* Allocate the data. */ | ||||
| ubo->data = MEM_mallocN(ubo->buffer.size, __func__); | ubo->data = MEM_mallocN(ubo->buffer.size, __func__); | ||||
| /* Now that we know the total ubo size we can start populating it. */ | /* Now that we know the total ubo size we can start populating it. */ | ||||
| float *offset = ubo->data; | float *offset = ubo->data; | ||||
| for (LinkData *link = inputs->first; link; link = link->next) { | LISTBASE_FOREACH (LinkData *, link, inputs) { | ||||
| GPUInput *input = link->data; | GPUInput *input = link->data; | ||||
| memcpy(offset, input->vec, input->type * sizeof(float)); | memcpy(offset, input->vec, input->type * sizeof(float)); | ||||
| offset += get_padded_gpu_type(link); | offset += get_padded_gpu_type(link); | ||||
| } | } | ||||
| /* Note since we may create the UBOs in the CPU in a different thread than the main drawing one, | /* Note since we may create the UBOs in the CPU in a different thread than the main drawing one, | ||||
| * we don't create the UBO in the GPU here. This will happen when we first bind the UBO. | * we don't create the UBO in the GPU here. This will happen when we first bind the UBO. | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| /* Order them as mat4, vec4, vec3, vec2, float. */ | /* Order them as mat4, vec4, vec3, vec2, float. */ | ||||
| BLI_listbase_sort(inputs, inputs_cmp); | BLI_listbase_sort(inputs, inputs_cmp); | ||||
| /* Creates a lookup table for the different types; */ | /* Creates a lookup table for the different types; */ | ||||
| LinkData *inputs_lookup[MAX_UBO_GPU_TYPE + 1] = {NULL}; | LinkData *inputs_lookup[MAX_UBO_GPU_TYPE + 1] = {NULL}; | ||||
| eGPUType cur_type = MAX_UBO_GPU_TYPE + 1; | eGPUType cur_type = MAX_UBO_GPU_TYPE + 1; | ||||
| for (LinkData *link = inputs->first; link; link = link->next) { | LISTBASE_FOREACH (LinkData *, link, inputs) { | ||||
| GPUInput *input = link->data; | GPUInput *input = link->data; | ||||
| if (input->type == GPU_MAT3) { | if (input->type == GPU_MAT3) { | ||||
| /* Alignment for mat3 is not handled currently, so not supported */ | /* Alignment for mat3 is not handled currently, so not supported */ | ||||
| BLI_assert(!"mat3 not supported in UBO"); | BLI_assert(!"mat3 not supported in UBO"); | ||||
| continue; | continue; | ||||
| } | } | ||||
| else if (input->type > MAX_UBO_GPU_TYPE) { | else if (input->type > MAX_UBO_GPU_TYPE) { | ||||
| ▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines | |||||