gloo gloo - 1 year ago 139
Swift Question

Difference between packed vs normal data type

In Metal what is the difference between a

and a

Answer Source

From what I gather from the documentation:

Packed datatypes are arrays, whereas their unpacked counter parts are structs.

Here's their usage:

packed_float4 packedFloat4;
packedFloat4[0] = 0.0f;
packedFloat4[1] = 1.0f;
packedFloat4[2] = 2.0f;
packedFloat4[3] = 3.0f;

packed_float4 anotherPackedFloat4 = [0.0f, 1.0f, 2.0f, 3.0f] //array initalizer


float4 f;
f.x = 0; //equivalent to f.r = 0;
f.y = 1; //equivalent to f.g = 1;
f.z = 2; //equivalent to f.b = 2;
f.w = 3; //equivalent to f.a = 3;

float4 anotherFloat4 = float4(0.0f, 1.0f, 2.0f, 3.0f) //constructor call
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download