1
$\begingroup$

I should preface with currently this question is mostly asking about Metal and iOS GPUs. That being said if this is GPU or OS specific and you can go into detail about other platforms that would be great to as this application will eventually be cross platform.

I am drawing some geometry in two draw calls.

  1. Opaque geometry is drawn. Discards happen. No particular triangle draw order. Fragments in this draw call occupy only 5% of the screens pixels.
  2. Transparent geometry is drawn. No discards happen. Triangles are drawn in depth order. Fragments in this call occupy a bulk of the screen pixels.

The question is essentially should I convert draw call 1 to ordered triangles with alpha=0 where I would generally discard. There will be a cost to ordering the triangles in draw 1 however it will not be two costly.

The reason I am unsure is that I know the second you call discard on a fragment you remove the possibility of Metal preforming early depth test which is allegedly quite an optimization. What I dont know is if discards disable early depth test on draw call 1 do they also disable the optimization for draw call 2's geometry?

Does the fragment stage happen after each draw calls vertex phase or after all of them?

Do you think I should explore sorting the triangles and using alpha blending on draw call 1? Again this would be a negligible CPU cost would it actually help the GPU?

$\endgroup$

1 Answer 1

1
$\begingroup$

I don't know what Apple have done with Metal per se, but as the iOS devices have PowerVR-derived GPUs, normally I would think that doing as much opaque-only drawing "up front" would usually be beneficial, but if, as in your case, only 5% of the screen is covered by opaque geometry, I'm not sure how much the software overhead will affect things.

The reason I am unsure is that I know the second you call discard on a fragment you remove the possibility of Metal preforming early depth test which is allegedly quite an optimization. What I dont know is if discards disable early depth test on draw call 1 do they also disable the optimization for draw call 2's geometry?

With PowerVR devices, a depth test can "always" be done as the first step in the pipeline, so any geometry that was submitted earlier in the scene can cull later things prior to fragment shading.

With alpha-tested (AKA "punch-though"), the Z-test can thus be done against previous geometry, but there may be a cost of then doing the texturing/shading and feeding that back to update the depths for subsequent geometry.

If you aren't doing alpha-test/discards, and are doing your own sorting, then this feedback is not required (but obviously there may be more shading/texturing work to perform).

(Such a pity, though, that we removed the OIT feature from the early PowerVR hardware)

Does the fragment stage happen after each draw calls vertex phase or after all of them?

I'm not sure what you are asking, but for a given scene, all the vertex shading (across multiple calls) is performed**, the geometry buffered, and only then rendering commences on the entire scene.

**There are some caveats here but that probably doesn't affect you.

Do you think I should explore sorting the triangles and using alpha blending on draw call 1? Again this would be a negligible CPU cost would it actually help the GPU?

Are you asking "should I profile/time the results and see what is best for my use case?". Probably "yes".

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.