[Bf-blender-cvs] [81f425a36ff] master: Metal: Remove Vec3 packing from uniform buffer generation as this causes UBO misalignment in Metal.
Jason Fielder
noreply at git.blender.org
Mon Dec 19 17:11:00 CET 2022
Commit: 81f425a36ff6b6d9bbc324a16478955758f9b5ac
Author: Jason Fielder
Date: Mon Dec 19 17:08:30 2022 +0100
Branches: master
https://developer.blender.org/rB81f425a36ff6b6d9bbc324a16478955758f9b5ac
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
===================================================================
M source/blender/gpu/intern/gpu_uniform_buffer.cc
===================================================================
diff --git a/source/blender/gpu/intern/gpu_uniform_buffer.cc b/source/blender/gpu/intern/gpu_uniform_buffer.cc
index 5d9e2af631e..e7e36efd19b 100644
--- a/source/blender/gpu/intern/gpu_uniform_buffer.cc
+++ b/source/blender/gpu/intern/gpu_uniform_buffer.cc
@@ -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);
More information about the Bf-blender-cvs
mailing list