# The Industry's Foundation for High Performance Graphics

1. ## How many instances of vertex and fragment shader?

Hey guys,
I have a few (theoretical) questions from an university exam which is where I need your help with:

Given an OpenGL program which draws 100 triangles separately. At a resolution of 1920x1080 pixels, each of the 100 triangles is displayed on average with 20 pixels.

1) How many instances of the vertex shader are processed?

2) How many instances of the fragment shader are processed?

3) How does the number of vertex / fragment shaders change if the resolution is reduced to e.g. 1280x720 pixels? (Does it increase or decrease?)

I would be very glad if you could help me with these questions as I'm not an expert on OpenGL and shaders, but I'd like to be prepared for the exam in the best possible way

2. You could write that program and then get an exact answer (for a single implementation; see the text about "implementation dependent reasons".)

3. Well I actually study something completely different which is why I have no clue about how to write a program

But thanks for the articles, very informative.

The way I see it: 1 vertex = 1 vertex shader and 1 pixel = 1 fragment shader.
That would mean that the answer to these questions are 300 instances of the vertex shader and 2000 instances of the fragment shader.
And a reduced resolution would not affect the number of shaders.

I hope I got it correctly

4. Originally Posted by newitgirl
And a reduced resolution would not affect the number of shaders.
If the triangles cover the same proportion of the screen regardless of resolution, then a reduced resolution would result in each triangle covering fewer pixels. (1920*1080)/(1280*720)=2.25, so you'd expect the number of pixels to drop from 2000 to 2000/2.25 = 888.88.

5. That would mean that the answer to these questions are 300 instances of the vertex shader
300 is the maximum number of invocations, but depending on how you send those triangles, it could be less. If there is any vertex sharing between them (either through triangle strips/fans or through reuse of multiple indices), you will get fewer VS invocation. The minimum number of VS invocations needed to generate 100 triangles is 102.

So the accuracy of this statement depends on what "separately" means.

1 pixel = 1 fragment shader
Thanks to the existence of helper FS invocations, you generally get more fragment shader invocations than actual pixels. Also, multisampling is permitted to (or in some cases, required) to generate fragment shader invocations for multiple samples in the same pixel.

There is a reason your Stack Overflow question was closed as a duplicate of this SO question. That answer goes into explicit detail about how all this works, and it's not as simple as you believe it to be.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•