Search code examples
iosmetaltessellation

Metal Tessellation on subdivided quad


I am totally new to tessellation and relatively new to Metal API, and have been referring to this sample code https://developer.apple.com/library/archive/samplecode/MetalBasicTessellation/Introduction/Intro.html

I realise the max tessellation factor on iOS is 16, which is very low for my use case compared to 64 on OSX. I suppose i'll need to apply tessellation on a quad that has been sub-divided to 4 by 4 smaller sections to begin with, so that after tessellation it will end up into something like one with a tessellation factor of 64?

So, i've changed the input control points to something like this

static const float controlPointPositionsQuad[] = {
    -0.8,  0.8, 0.0, 1.0,   // upper-left
     0.0,  0.8, 0.0, 1.0,   // upper-mid
     0.0,  0.0, 0.0, 1.0,   // mid-mid
    -0.8,  0.0, 0.0, 1.0,   // mid-left

    -0.8,  0.0, 0.0, 1.0,   // mid-left
     0.0,  0.0, 0.0, 1.0,   // mid-mid
     0.0, -0.8, 0.0, 1.0,   // lower-mid
    -0.8, -0.8, 0.0, 1.0,   // lower-left

     0.0,  0.8, 0.0, 1.0,   // upper-mid
     0.8,  0.8, 0.0, 1.0,   // upper-right
     0.8,  0.0, 0.0, 1.0,   // mid-right
     0.0,  0.0, 0.0, 1.0,   // mid-mid

     0.0,  0.0, 0.0, 1.0,   // mid-mid
     0.8,  0.0, 0.0, 1.0,   // mid-right
     0.8, -0.8, 0.0, 1.0,   // lower-right
     0.0, -0.8, 0.0, 1.0,   // lower-mid
};

and for the drawPatches i changed it to 16 instead of 4. But the result is that it is only showing only the first 4 points (top left). if i change the vertex layout stride to this:

vertexDescriptor.layouts[0].stride = 16*sizeof(float);

it is still showing the same.

I don't really know what i'm doing but what i'm going for is similar to tessellating a 3d mesh, but for my case is just a quad with subdivisions. I am unable to find any tutorial / code samples that teach about this using Metal API.

Can someone please point me to the right direction? thanks!


Solution

  • Here are a few things to check:

    1. Ensure that your tessellation factor compute kernel is generating inside/edge factors for all patches by dispatching a compute grid of the appropriate size.
    2. When dispatching threadgroups to execute your tessellation factor kernel, use 1D threadgroup counts and sizes (such that the total thread count is the number of patches, and the heights of both sizes passed to the dispatch method are 1).
    3. When drawing patches, the first parameter (numberOfPatchControlPoints) should equal the number of control points in each patch (3 for triangles; 4 for quads), and the third parameter should be the number of patches to draw.