Gfx: Detect persistent mapping overwrites

Created on 22 Jun 2017  路  2Comments  路  Source: gfx-rs/gfx

Persistent mapping is a bit tricky. It's tempting to fill out an Upload buffer, then copy data out of it via Encoder, and consider this to be a self-contained operation:

let writer = factory.write_mapping(upload_buffer);
writer[i] = something;
encoder.copy_buffer(&upload_buffer, buffer, ...);
encoder.draw(...); //using `buffer`

However, repeating the same operation could get your upload buffer contents being overwritten before they are really uploaded to GPU. Technically, it's totally the user's fault to mis-use the mapping, and it's still safe from our perspective.

However, I don't think there is a reasonable test case that involves overwriting the persistent buffer data before it gets submitted. Thus, we should consider testing for this scenario and either erroring out, or even panicing. We could limit ourselves to just tracking a single continuous slice of data in the buffer mapping, conservatively (we don't have to detect all cases, that would be too expensive).

cc @Bastacyclop @dati91

OpenGL average hal ready for work feature medium

Most helpful comment

I can think of two approaches that could be combined:

  • Single continuous slice tracking could be instead replaced by one or multiple higher level abstractions in render that would both simplify common operations and make overwriting impossible by design.
  • A complete and expensive tracking could be useful as an opt-in debug feature (like some kind of validation layer I guess)

All 2 comments

I understand the reasoning behind trying to avoid this but I would like to avoid restricting it towards some linear tracking approach. Tracking used subranges would be neat but too expensive as mentioned.
A possible I see with tracking a single continuous subslice are buffer to image copies (e.g glyph atlas: writing multiple glyphs to an upload buffer and copying it to an image). With a single subslice users would have to write all glyphs first in the upload buffer and submit one large buffer copy to avoid conflicts. With the current approach it would be possible to specify subregions in the buffer.

(Note: this is mostly targeted towards corell as atm we could rather just call update_texture for the mentioned example)

Therefore I would propose to rather have something like this as an optional layer in render.

I can think of two approaches that could be combined:

  • Single continuous slice tracking could be instead replaced by one or multiple higher level abstractions in render that would both simplify common operations and make overwriting impossible by design.
  • A complete and expensive tracking could be useful as an opt-in debug feature (like some kind of validation layer I guess)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

kvark picture kvark  路  4Comments

seivan picture seivan  路  4Comments

Limeth picture Limeth  路  3Comments

kvark picture kvark  路  3Comments

Fluci picture Fluci  路  5Comments