最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

metal - How can I get pixel coordinates in the fragment tile function? - Stack Overflow

programmeradmin5浏览0评论

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;
}

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;
}
Share Improve this question asked Mar 20 at 23:00 Hamid YusifliHamid Yusifli 10.2k2 gold badges29 silver badges53 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

After some searching, I found the answer to my question:

  • 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;
}
发布评论

评论列表(0)

  1. 暂无评论