How can I get pixel coordinates in the fragment tile function?

In this video, tile fragment shading is recommended for image processing. In this example, the unpack function takes two arguments, one of which is RasterizerData. As I understand it, this is the data passed to us from the previous stage (Vertex) of the graphics pipeline.

However, the properties of MTLTileRenderPipelineDescriptor do not include an option for specifying a Vertex function. Therefore, in this render pass, a mix of commands is used: first, a draw command is executed to obtain UV coordinates, and then threads are dispatched.

My question is: without using a draw command, only dispatch, how can I get pixel coordinates in the fragment tile function? For the kernel tile function, everything is clear.

typedef struct
{
    float4 OPTexture        [[ color(0) ]];
    float4 IntermediateTex  [[ color(1) ]];
} FragmentIO;

fragment FragmentIO Unpack(RasterizerData in [[ stage_in ]],
                           texture2d<float, access::sample> srcImageTexture [[texture(0)]])
{
    FragmentIO out;
    
    //...
                         
    // Run necessary per-pixel operations
    out.OPTexture  = // assign computed value;
    out.IntermediateTex = // assign computed value;
    return out;
}
Accepted Answer

After some searching, I found the answer to my question. We can use the following arguments:

  • pixel_position_in_tile – (x, y) position of the fragment in the tile.

  • pixels_per_tile – (width, height) of the tile in pixels.

  • tile_index – 1D tile index.

fragment FragmentIO my_fragment(FragmentIO i,
                                                              ushort index [[tile_index]],
                                                              ushort2 pixelPositionInTile  [[pixel_position_in_tile]],
                                                              ushort2 pixelPerTile [[pixels_per_tile ]]) {
    FragmentIO fragOut;
    return fragOut;
}
How can I get pixel coordinates in the fragment tile function?
 
 
Q