Metal: Remove Vec3 packing from uniform buffer generation as this causes UBO misalignment in Metal.

Authored by Apple: Michael Parkin-White

Ref T96261

Reviewed By: fclem
Differential Revision: https://developer.blender.org/D16721
This commit is contained in:
Jason Fielder 2022-12-19 17:08:30 +01:00 committed by Clément Foucault
parent 1a986f7eba
commit 81f425a36f
Notes: blender-bot 2023-02-14 06:54:28 +01:00
Referenced by issue #96261, Metal Viewport
1 changed files with 10 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#include "gpu_backend.hh"
#include "gpu_node_graph.h"
#include "GPU_context.h"
#include "GPU_material.h"
#include "GPU_uniform_buffer.h"
@ -56,6 +57,10 @@ static eGPUType get_padded_gpu_type(LinkData *link)
{
GPUInput *input = (GPUInput *)link->data;
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. */
if (gputype == GPU_VEC3 && (link->next != nullptr) &&
(((GPUInput *)link->next->data)->type != GPU_FLOAT)) {
@ -89,6 +94,11 @@ static void buffer_from_list_inputs_sort(ListBase *inputs)
/* Order them as mat4, vec4, vec3, vec2, float. */
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; */
LinkData *inputs_lookup[MAX_UBO_GPU_TYPE + 1] = {nullptr};
eGPUType cur_type = static_cast<eGPUType>(MAX_UBO_GPU_TYPE + 1);