Skip to main content
added 85 characters in body
Source Link
pmw1234
  • 3.5k
  • 1
  • 8
  • 17

It sounds like you want to gather timings for say 100 frames (x frames) then show that data histogram style.

You could store the histogram data directly in the shader as an array of floats and draw directly out of the array using the vertex index id, but to update the histogram the array would have to be rewritten inside the shader, then the shader reloaded and recompiled. Overall it is not a very appealing approach.

A simple approach that is much more flexible, is to write the sample data into a vertex attributes buffer. Bind the vertex buffer and at draw time, the GPU feeds the data to your shader. Each histogram gl_line requires two values, so the first value would be zero and the second value would be the timing value. Repeat that for every timing value. The histogram then becomes a series of lines where the length of the line is determined by the passed in timing, the x position of the line is determined by the vertex index id, and the height of the lines can be uniformly scaled. Finally use a vec3 offset to move the histogram anywhere on the output buffer. gl line width can be used to thicken the lines up so the entire histogram isn't minuscule in size.

Now the histogram draw is just a matter of binding the vertex buffer containing the timing data, and doing the draw call. Changing the number of values is just a matter of writing a bigger vertex buffer and changing the number of vertices in the draw call.

To update the histogram gather more data, push it out to the vertex buffer and draw.

Once this is working it is easy to get fancy with ring buffers, using quads for the histogram lines, animating, etc.

enter image description here

It sounds like you want to gather timings for say 100 frames (x frames) then show that data histogram style.

You could store the histogram data directly in the shader as an array of floats and draw directly out of the array using the vertex index id, but to update the histogram the array would have to be rewritten inside the shader, then the shader reloaded and recompiled. Overall it is not a very appealing approach.

A simple approach that is much more flexible, is to write the sample data into a vertex attributes buffer. Bind the vertex buffer and at draw time, the GPU feeds the data to your shader. Each histogram gl_line requires two values, so the first value would be zero and the second value would be the timing value. Repeat that for every timing value. The histogram then becomes a series of lines where the length of the line is determined by the passed in timing, the x position of the line is determined by the vertex index id, and the height of the lines can be uniformly scaled. Finally use a vec3 offset to move the histogram anywhere on the output buffer. gl line width can be used to thicken the lines up so the entire histogram isn't minuscule in size.

Now the histogram draw is just a matter of binding the vertex buffer containing the timing data, and doing the draw call. Changing the number of values is just a matter of writing a bigger vertex buffer and changing the number of vertices in the draw call.

To update the histogram gather more data, push it out to the vertex buffer and draw.

Once this is working it is easy to get fancy with ring buffers, using quads for the histogram lines, animating, etc.

It sounds like you want to gather timings for say 100 frames (x frames) then show that data histogram style.

You could store the histogram data directly in the shader as an array of floats and draw directly out of the array using the vertex index id, but to update the histogram the array would have to be rewritten inside the shader, then the shader reloaded and recompiled. Overall it is not a very appealing approach.

A simple approach that is much more flexible, is to write the sample data into a vertex attributes buffer. Bind the vertex buffer and at draw time, the GPU feeds the data to your shader. Each histogram gl_line requires two values, so the first value would be zero and the second value would be the timing value. Repeat that for every timing value. The histogram then becomes a series of lines where the length of the line is determined by the passed in timing, the x position of the line is determined by the vertex index id, and the height of the lines can be uniformly scaled. Finally use a vec3 offset to move the histogram anywhere on the output buffer. gl line width can be used to thicken the lines up so the entire histogram isn't minuscule in size.

Now the histogram draw is just a matter of binding the vertex buffer containing the timing data, and doing the draw call. Changing the number of values is just a matter of writing a bigger vertex buffer and changing the number of vertices in the draw call.

To update the histogram gather more data, push it out to the vertex buffer and draw.

Once this is working it is easy to get fancy with ring buffers, using quads for the histogram lines, animating, etc.

enter image description here

Source Link
pmw1234
  • 3.5k
  • 1
  • 8
  • 17

It sounds like you want to gather timings for say 100 frames (x frames) then show that data histogram style.

You could store the histogram data directly in the shader as an array of floats and draw directly out of the array using the vertex index id, but to update the histogram the array would have to be rewritten inside the shader, then the shader reloaded and recompiled. Overall it is not a very appealing approach.

A simple approach that is much more flexible, is to write the sample data into a vertex attributes buffer. Bind the vertex buffer and at draw time, the GPU feeds the data to your shader. Each histogram gl_line requires two values, so the first value would be zero and the second value would be the timing value. Repeat that for every timing value. The histogram then becomes a series of lines where the length of the line is determined by the passed in timing, the x position of the line is determined by the vertex index id, and the height of the lines can be uniformly scaled. Finally use a vec3 offset to move the histogram anywhere on the output buffer. gl line width can be used to thicken the lines up so the entire histogram isn't minuscule in size.

Now the histogram draw is just a matter of binding the vertex buffer containing the timing data, and doing the draw call. Changing the number of values is just a matter of writing a bigger vertex buffer and changing the number of vertices in the draw call.

To update the histogram gather more data, push it out to the vertex buffer and draw.

Once this is working it is easy to get fancy with ring buffers, using quads for the histogram lines, animating, etc.