I am very new to metal so bear with me as I am transitioning from the ugly state machine calls of OpenGL to modern graphics frameworks. I really want to make sure I understand how everything works and works together.
I have read most of Apples documentation but it does a better job describing the function of individual components than how they come together.
I am trying to understand essentially whether I should have multiple renderPipelines and renderEncoders are needed in my situation.
To describe my pipeline at a high level here is what goes on:
- Retrieve the previous frame's contents from an offscreen texture that was rendered to and draw some new contents onto it.
- Swith to rendering on the screen. Draw the texture from step 1 to the screen.
- Do some post processing (in native resolution).
- Draw the UI ontop as quads. (essentailly a repeat of 2)
So in essence there will be the following vertex/fragment shader pairs
- Draw the entities (step 1)
- Draw quads on a specefied area (step 2 and 4)
- Post processing shader 1 (step 3) uses different inputs than D and cant be done in the same shader
- Post processing shader 2 (step 3) uses different inputs than C and can't be done in the same shader
There will be the following texture groups
- Texture for each UI element
- Texture for the offscreen drawing done in step 1
- Potentially more offscreen textures will be used in post processing depening on metals preformance
Ultimately my confusions are this:
- Q1. Render Pipelines take only one vertex and one fragment function so does this mean I need have 4 render pipelines even though I only have 3 unique steps to my drawing procedure?
- Q2. How am I supposed to use multiple pipelines in one encoder? Wouldn't each sucessive call on
.setRenderPipelineStateoverride the previous one? - Q3. Would you recommend keeping all of my
.setFragmentTexturecalls right after creating my encoder or do I need to set those only right before they are needed. - Q4. Is it valid to keep my depthState constant even as I switch between pipelineStates? How do I ensure that my entities on step 1 are rendered with depth but make sure depth information is lost between frames so entities are all on top of the previous contents?
- Q5. What do I do with render step 3 where I have two post processing steps? Do those have to be seperate pipelines?
- Q6. How can I efficiently build my pipeline knowing that steps 2 and 4 are essentially the same just with different inputs?
I guess it would help me if someone would walk me through what renderPipelineObjects I will need and for what. It would also be useful to understand what some of the renderCommandEncoder commands might look like at a psuedocode level.