0

Based on an example in Metal shading language spec:

Example:
struct Foo {
    float4 a [[color(0)]];
    int4 b [[color(1)]];
};

kernel void
my_kernel(imageblock<Foo, imageblock_layout_implicit> img_blk,
 ushort2 lid [[thread_index_in_threadgroup]] …) 
{
…
    Foo f = img_blk.read(lid); float4 r = f.a;
…
    f.a = r;
…
    img_blk.write(f, lid);
}

As the members of the imageblock alias color attachment I think after "imgblk.write(...)" the imageblock will be written to corresponding color attachment.

I experimented this on Apple's example: Forward-plus with tile shading, I tried to use imageblock.write(..) to write to the color attachments in the tile shader but I got very weird results:

  1. only pixels of the background are changed, but the result is too much darker than what I set, e.g. I set color=float4(1,0,0,1) but on screen it's float4(0.057, 0, 0, 1)
  2. color of other parts strangely depends on whether/what is written to the imageblock in the previous fragment shader pass, consider I set the values in the imageblock to constants.

Anyway it feels like imageblock.write() doesn't work right in tile shader. Or how to use it correctly?

1 Answer 1

0

Solved, there are several things lead to the weird result I got: 1. The color format was srgb 2. The numSamples the example project used were 4 3. I did imageblock write without specifying imageblock_data_rate

In the case of multisampling, one needs to read/write the imageblock for each sample

Sign up to request clarification or add additional context in comments.

1 Comment

If you answered your own question, please mark it as such so the question is removed from the unanswered pile. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.