SIMD vector data types

I’ve been messing around with using Model I/O to load 3D assets and have run into an issue with getting/setting the vector data type.Specifically I’ve been trying to use vector_float3 and vector_int2 and I’m not getting back correct values.

In the case of vector_float3, I’m trying to read back the bounds of the MDLAsset.boundingBox.

I’ve created a Declare and a Structure that roughly looks like:

[code]Declare Function boundingBox Lib “ModelIO” Selector “boundingBox” (id As Integer) As MDLAxisAlignedBoundingBox

Struct MDLAxisAlignedBoundingBox
MaxBounds As vector_float3
MinBounds As vector_float3

Struct vector_float3
X As Single
Y As Single
Z As Single
When I go to read the MDLAsset’s bounding box, the MaxBounds reads correctly but the MinBounds are off by 4 bytes, with Y holding what should be the X value, Z the Y value. I’ve tried things such as

  • adding a StructureAlignment attribute of 16 for vector_float3
  • adding another Single value at the end of vector_float3 to act as padding
  • returning a Ptr for the Declare to try and retrieve it as a MemoryBlock
    but in all cases and configurations I’ve tried so far the debug outright crashes when run.

In the case of vector_int2, I’m trying to create a MDLCheckerboardTexture but cannot get/set the MDLTexture.dimensions. The values I read back are not even remotely close to what they should be, unlike vector_float3 which gives me some of the correct values. The structure I’ve used is

Struct vector_int2 X As Int32 Y As Int32
And again I’ve messed around with both Declare and struct configurations to no avail, similar to what I’ve described for vector_float3
Digging down through Apple’s docs I see simd_float3 and simd_int2 as the underlying structures, but I haven’t found anything useful down there.

Can anyone point me in the right direction?

not sure but I suspect that a clang vector isnt just a simple structure like you’re expecting

What gets me is that in Xcode (disclaimer: I am very much a beginner with Xcode so I could be interpreting this wrong) viewing the memory of, say, a vector_int2 shows the proper values stored in 8 bytes with a layout that looks something like (in Xojo parlance):
x = Memoryblock.Int32Value(0)
y = Memoryblock.Int32Value(4)

I’d love to retrieve vector_int2 as a Memoryblock, but setting up a Declare to return a Ptr instead of the struct sends me consistently to memory address 16.

sure but Xcode also happens to know about the attributes etc on the typedef for these so its not surprising that it might be doing “something special”

that said have you looked at the accelerate framework which includes method for creating and manipulating many of these types ?

I’ve looked but have yet to successfully create a Declare for a simd_make_[TYPE] function, hitting the “Undefined symbols for architecture x86_64:” error. What I’m doing is:

Declare Function simd_make_int2 Lib "???" (x As Int32, y As Int32) As Ptr

I tried various libraries and have come up empty.

This could be one of this cases where you must do thins in a plugin in Xcode since there seems to be some special things that Xcode and clang know how to handle that is part of the compiler and not just something you can declare into