Solving the htile buffer issue

The problem

One of the remaining artifacts the tiled deferred renderer was that some cases tiles were used in lighting calculations without being in range of the light source. This artifact can be seen in the image below.

I noticed that this artifact only occurred on the bottom row and used the debug renderer to visualize the problem. As you can see in the image below the maximum intersection distance of the tiles within the tile is set to the far plane. It looked like I'm accessing data outside of the htile buffers bounds.

The minimum and maximum intersection distances are obtained from the h-tile buffer, an h-tile in this buffer is 8 by 8 pixels. The tiles I use for my bounding box generation are currently 64 x 64 pixels, with a height of 2160 this results in 270 h-tile rows but 33.75 macro tile rows, which is rounded up to 34. This contains 1/4 or 16 more pixels in height it requested data outside of the buffer. I solved this by skipping executions of nonexisting pixels in tiles that end outside of the screen.