Skip to content

[RFC] Handle image spacing by creating a pre-spaced image in the texture cache? #2312

@glennw

Description

@glennw

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:

  • The image shader is more complex than otherwise, making it more difficult to unify with other similar shaders (e.g. brush_image and ps_text_run).
  • As soon as an image uses spacing, we move it to be in the alpha pass, and don't get the benefit of drawing an otherwise opaque image.

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:

  1. In the case of spacing, create a texture cache entry that has the source image, and the spacing pre-rendered. This would mean (a) remove all spacing support from the image shader, and (b) those images get marked as alpha, leaving the original source image marked as opaque, simplifying some of the logic.
  2. Detect when there is a small(ish) number of instances are required, and draw those as separate instances instead. This would allow us to use the opaque pass for images with spacing in this case.
  3. For the case of a small (e.g. 1x4) image repeated a lot, we could pre-render that into a persistent RT cached entry, where we manually apply the repeat 64 times. Then, we would greatly reduce the number of CPU-side instances we'd need to create for this case.

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?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions