renderdoc icon indicating copy to clipboard operation
renderdoc copied to clipboard

Overlay to show discarded fragments

Open JuanDiegoMontoya opened this issue 2 years ago • 5 comments

Description

The ability to see how many fragments were discarded per pixel in a draw or pass can be useful to debug the execution of shaders containing discard statements (or in the case of HLSL, calls to clip). For example, it can be used to ensure that stochastic alpha masked/cutout geometry is being rendered correctly. It can also help debug fullscreen passes that are intended to execute only for certain pixels on the screen (e.g., the shading pass in a deferred renderer, a screen-space reflections shader, or a subsurface scattering shader). This could also be used to debug instances where nothing is rendering because too many fragments are being discarded.

In my specific case, this feature would help debug a renderer which rasterizes proxy geometry (as a sort of acceleration structure), then traces a ray per pixel inside the volume, starting at the volume's surface. The rays discard in the event that they hit no geometry inside the volume.

As far as I can tell, none of the current overlays are affected by discarding, so they don't help with the aforementioned situations. I also could not find any

Without this feature, it is still possible, but rather cumbersome to debug discarded fragments by replacing them with a bright color. However, this fails for debugging cases with overlapping geometry.

The overlay would create a heatmap of discarded fragments (each discarded fragment adds to the heat at that pixel), much in the style of the quad overdraw overlay. There could be an option to view the heatmap for just the draw or the entire pass, as the user desires.

Environment

  • RenderDoc version: 1.22
  • Operating System: Windows 10
  • Graphics API: OpenGL

JuanDiegoMontoya avatar Nov 15 '22 11:11 JuanDiegoMontoya

I imagine the main difficulty in implementing this (compared to the other overlays) is that it would require somehow patching the shader to insert an extra buffer/image write just before each discard statement.

JuanDiegoMontoya avatar Nov 15 '22 11:11 JuanDiegoMontoya

This should be implementable without any shader patching on any API. The draw can be run to an off-screen target to generate a pass/fail stencil mask (unconditional stencil pass means passing fragments would write and any discarded fragments wouldn't) which can be tested against to render the overlay.

I would not implement it as a heatmap, it would function the same as all the other 'test' overlays showing a pass or a fail - the overlays are intended for quick debugging & sanity checking, not detailed introspection.

baldurk avatar Nov 15 '22 11:11 baldurk

Yeah, the heatmap is not strictly necessary for my request. It would just be a consequence of how I thought it would be implemented. Your idea sounds good ❤️

JuanDiegoMontoya avatar Nov 15 '22 12:11 JuanDiegoMontoya

While looking for something complete unrelated I did stumble upon this obscure website, describing GL_INTEL_performance_queries which has counters for a metric like @JuanDiegoMontoya is asking for, or at least sounds very similar.

http://zaynar.co.uk/docs/gl-intel-performance-queries.html Not sure if its of any help or worth to be implemented to enable that kind of thing at least on intel gpus.

deccer avatar Nov 18 '22 23:11 deccer

Intel HW perf counters are already supported #2034. Of course that only gives you a number, not a nice picture.

Trass3r avatar Jan 13 '23 14:01 Trass3r