Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up[RFC] Handle image spacing by creating a pre-spaced image in the texture cache? #2312
Comments
|
also @mstange |
|
Spacing, in particular, is something that is unfortunate to pay the shader cost for on all images, since it's rarely used. Paying the cost on spaced images by pre-rendering that image once, and removing the cost from the image shader seems like a win on the vast majority of content. |
|
I like this a lot. For rare cases where the spacing is very big, we can always detect it and fall back to the code that creates an instance per primitive. |
|
In terms of performance and cleanness, having an instance per image repeat makes most sense to me. If the web author requests a google of repeats, and we populate those in the instance data, we are screwed for sure. However, what if we don't have instance data? So here is another one: This way we aren't going to be stuck preparing the work for GPU. In the worst case, the GPU will be slow to process those vertices, but a similar effect is surely achievable by other means (generating a thousand large-radius box shadows, for example), so we don't need to try to hard to avoid this specifically for spaced images. |
|
I don't have strong opinions on these suggestions, but they sound reasonable to me, and they're listed in decreasing order of usefulness. Spaced repeats are used extremely rarely. The CSS property/value combination |
|
Didn't Servo hit this exact problem years ago? :) I think prerendering the spacing into the texture cache seems like the way to go.
I'm worried about the vertex shading and rasterization engine load for large repeats of 1px images. We hit this fairly early on in Servo, as above. |
Is this a hypothetical valid use-case we are talking about or just a malicious/benchmarking web page? If the former, can I see a link? If the latter, we should really be fine with doing lots of GPU work, as long as we don't hang/crash. |
|
I remember it being a problem years ago in Servo. I don't remember the pages offhand. But people do have tiny repeated backgrounds. Google brings up http://supernovathemes.com/55-small-lite-background-images-for-website-you-can-repeat/ |
|
This was implemented in #2664. |
Some complexity in the image shader comes from the support for spacing.
This is not a massive issue, but it does complicate a few things:
A naive solution is to just produce a CPU instance per repetition. However, web authors often take a 1px wide image and repeat it thousands of times across a page, which causes a huge number of instances to be required.
Instead, we could take advantage of the recently landed support for persistent caching of render tasks in the texture cache. We could, for instance:
Those optimizations are somewhat orthogonal, but all based on the idea of pre-rendering some spacing or repeating into the texture cache when needed. I think this could simplify our image shader quite a bit, and also allow us to draw more cases in the opaque pass.
Thoughts?