Post not yet marked as solved
Post marked as unsolved with 1 replies, 2,261 views
Hi,I am drawing a sphere generated with Model I/O. The MTLVertexDescriptor is generated as follows:unc makeVertexDescriptor() -> MTLVertexDescriptor {
// Create the vertex descriptor first...
let vertexDescriptor = MTLVertexDescriptor()
// Position
vertexDescriptor.attributes[0].format = .float3
vertexDescriptor.attributes[0].offset = 0
vertexDescriptor.attributes[0].bufferIndex = 0
// Normal
vertexDescriptor.attributes[1].format = .float3
vertexDescriptor.attributes[1].offset = 12
vertexDescriptor.attributes[1].bufferIndex = 0
// Texcoord
vertexDescriptor.attributes[2].format = .float2
vertexDescriptor.attributes[2].offset = 24
vertexDescriptor.attributes[2].bufferIndex = 0
// Interleave them
vertexDescriptor.layouts[0].stride = 32
vertexDescriptor.layouts[0].stepRate = 1
vertexDescriptor.layouts[0].stepFunction = .perVertex
return vertexDescriptor
}And the Model I/O mesh is created like this:func makeMesh(device: MTLDevice, vertexDescriptor: MTLVertexDescriptor) throws -> MTKMesh {
let allocator = MTKMeshBufferAllocator(device: device)
let mdlMesh = MDLMesh(sphereWithExtent: vector_float3(2.0, 2.0, 2.0),
segments: vector_uint2(50, 50),
inwardNormals: false,
geometryType: .triangles,
allocator: allocator)
let mdlVertexDescriptor = MTKModelIOVertexDescriptorFromMetal(vertexDescriptor)
guard let attributes = mdlVertexDescriptor.attributes as? [MDLVertexAttribute] else {
throw RendererError.badVertexDescriptor
}
attributes[0].name = MDLVertexAttributePosition
attributes[1].name = MDLVertexAttributeNormal
attributes[2].name = MDLVertexAttributeTextureCoordinate
mdlMesh.vertexDescriptor = mdlVertexDescriptor
return try MTKMesh(mesh: mdlMesh, device: device)
}I then assigned the MTLVertexDescriptor to my render pipeline descriptor. In my vertex shader, I have the attribute declaration:typedef struct {
packed_float3 position;
packed_float3 normal;
packed_float2 texCoord;
} Vertex;And the vertex shader is the following:vertex RasteriserData helloVertexShader(uint vertexID [[vertex_id]],
device Vertex *vertices [[buffer(0)]],
constant Uniforms &uniforms [[buffer(1)]]) {
Vertex in = vertices[vertexID];
float4 position = float4(in.position, 1.0f);
float3 normal = float3(in.normal);
...On an iPhone X on iOS 11.4, I get the following error:Execution of the command buffer was aborted due to an error during execution. Caused GPU Hang Error (IOAF code 3)However, running this code on macOS returns no errors and the code works perfectly.Moreover, on the iPhone X, if I make a small change in line 6 of the previous code block:float4 position = float4(vertices[0].position, 1.0f);It does not give this error (but as expected, it doesn't draw correctly). So how do I fix this? Changing the position to be the second attribute (using the vertex struct and vertex descriptor) still gives this same problem. Why is it working on macOS but not iOS?