Chapter 8: Final project produces two different views in iOS and macOS?

There seems to be a problem but I can’t track it down

In the debugger I discovered that the macOS version has a much reduced uv Buffer compared to the iOS version if that means anything to you.

I’ve cracked it!!

Replace:

vertexDescriptor.layouts[UVBuffer.index] = MDLVertexBufferLayout(stride: MemoryLayout<float2>.stride)

with:

vertexDescriptor.layouts[UVBuffer.index] = MDLVertexBufferLayout(stride: offset)

in VertexDescriptor.swift

Now I think that works but it is wrong too. It’s just that MemoryLayout.stride is not big enough and offset is.
I have no idea why it works for iOS and not for macOS.

Mine seems to be exactly the same on M1 Mac mini, iPad mini 6 and an M1 iPad Pro.

Also I don’t really understand why that change works for you.

These are the two buffers involved:

VertexBuffer (buffer(0)) holds

[Position, Normal, Position, Normal, Position, Normal,...]

So the stride of VertexBuffer is the length of Position + length of Normal, which is float3.stride + float3.stride (32).

UVBuffer (buffer(1)) holds

[UV, UV, UV, UV, UV, ...]

So the stride of UVBuffer is float2.stride (8)

In Common.h, are these your BufferIndices?

typedef enum {
  VertexBuffer = 0,
  UVBuffer = 1,
  UniformsBuffer = 11,
  ParamsBuffer = 12
} BufferIndices;

Screenshots after loading untouched from your repository:

first iOS

then macOS

After making only the change I described, we have iOS unchanged and macOS:

Indeed they are still different in that they point to different textures but now the macOS is coherent. The same effect occurs in the start project of the following chapter.

In the debugger for the iOS version I get:


suggesting some 34 uv values

while in the macOS (old version) I have only 9 values:

Interesting. Would you be able to zip up the project and post here please? (You’ll have to delete everything in the Models folder first - I can use mine)

Just so I can see what happens here? I can’t see why it would be different though. I have the same UV coordinates as your iOS one.

It’s the final untouched project from the chapter?

I can’t remember what your devices are.

macOS model and GPU?
iOS device and OS?

Just in case yours has some kind of corruption - here’s my final project:

Textures.zip (2.6 MB)

I had to remove everything in the Models folder because it was too big, so you’ll have to copy them over before running.

Hi Caroline
I closed all files in xCode and shut down xCode.
I rebooted my machine.
I loaded a completely untouched download of chapter 8 final (attached as zip)
I ran in iOS iPhone 14 pro simulator (got the result shown above)
I ran on my macBook (and got the result shown above)
I changed the stride as described and got the good result shown above.

My equipment is as follows:


My zip is 6.9MB and I’m told max upload is 4MB. Can I send it any other way?

All the best

Don

Did you try it on your iDevice? Sometimes Simulator doesn’t exactly reproduce what happens on the GPU. My Simulator works fine, but it is on an M1 Mac mini.

PM sent with my email address.

haha

it works correctly on my iPhone 12

the mac version needs a stride >= 32
???

That might be a possibility on the older GPUs. Although I don’t remember having this problem on my older MacBook Pro in the first edition of the book.