Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_uniform_buffer.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2020 Blender Foundation. All rights reserved. */ | * Copyright 2020 Blender Foundation. All rights reserved. */ | ||||
| /** \file | /** \file | ||||
| * \ingroup gpu | * \ingroup gpu | ||||
| */ | */ | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include <cstring> | #include <cstring> | ||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_math_base.h" | #include "BLI_math_base.h" | ||||
| #include "gpu_backend.hh" | #include "gpu_backend.hh" | ||||
| #include "gpu_node_graph.h" | #include "gpu_node_graph.h" | ||||
| #include "GPU_context.h" | |||||
| #include "GPU_material.h" | #include "GPU_material.h" | ||||
| #include "GPU_uniform_buffer.h" | #include "GPU_uniform_buffer.h" | ||||
| #include "gpu_uniform_buffer_private.hh" | #include "gpu_uniform_buffer_private.hh" | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Creation & Deletion | /** \name Creation & Deletion | ||||
| * \{ */ | * \{ */ | ||||
| Show All 26 Lines | |||||
| /** | /** | ||||
| * We need to pad some data types (vec3) on the C side | * We need to pad some data types (vec3) on the C side | ||||
| * To match the GPU expected memory block alignment. | * To match the GPU expected memory block alignment. | ||||
| */ | */ | ||||
| static eGPUType get_padded_gpu_type(LinkData *link) | static eGPUType get_padded_gpu_type(LinkData *link) | ||||
| { | { | ||||
| GPUInput *input = (GPUInput *)link->data; | GPUInput *input = (GPUInput *)link->data; | ||||
| eGPUType gputype = input->type; | eGPUType gputype = input->type; | ||||
| /* Metal cannot pack floats after vec3. */ | |||||
| if (GPU_backend_get_type() == GPU_BACKEND_METAL) { | |||||
| return (gputype == GPU_VEC3) ? GPU_VEC4 : gputype; | |||||
| } | |||||
| /* Unless the vec3 is followed by a float we need to treat it as a vec4. */ | /* Unless the vec3 is followed by a float we need to treat it as a vec4. */ | ||||
| if (gputype == GPU_VEC3 && (link->next != nullptr) && | if (gputype == GPU_VEC3 && (link->next != nullptr) && | ||||
| (((GPUInput *)link->next->data)->type != GPU_FLOAT)) { | (((GPUInput *)link->next->data)->type != GPU_FLOAT)) { | ||||
| gputype = GPU_VEC4; | gputype = GPU_VEC4; | ||||
| } | } | ||||
| return gputype; | return gputype; | ||||
| } | } | ||||
| Show All 17 Lines | |||||
| { | { | ||||
| /* Only support up to this type, if you want to extend it, make sure static void | /* Only support up to this type, if you want to extend it, make sure static void | ||||
| * inputs_sobuffer_size_compute *inputs) padding logic is correct for the new types. */ | * inputs_sobuffer_size_compute *inputs) padding logic is correct for the new types. */ | ||||
| #define MAX_UBO_GPU_TYPE GPU_MAT4 | #define MAX_UBO_GPU_TYPE GPU_MAT4 | ||||
| /* 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); | ||||
| /* Metal cannot pack floats after vec3. */ | |||||
| if (GPU_backend_get_type() == GPU_BACKEND_METAL) { | |||||
| return; | |||||
| } | |||||
| /* Creates a lookup table for the different types; */ | /* Creates a lookup table for the different types; */ | ||||
| LinkData *inputs_lookup[MAX_UBO_GPU_TYPE + 1] = {nullptr}; | LinkData *inputs_lookup[MAX_UBO_GPU_TYPE + 1] = {nullptr}; | ||||
| eGPUType cur_type = static_cast<eGPUType>(MAX_UBO_GPU_TYPE + 1); | eGPUType cur_type = static_cast<eGPUType>(MAX_UBO_GPU_TYPE + 1); | ||||
| LISTBASE_FOREACH (LinkData *, link, inputs) { | LISTBASE_FOREACH (LinkData *, link, inputs) { | ||||
| GPUInput *input = (GPUInput *)link->data; | GPUInput *input = (GPUInput *)link->data; | ||||
| if (input->type == GPU_MAT3) { | if (input->type == GPU_MAT3) { | ||||
| ▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines | |||||