-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zero-copy importer plugin APIs #240
base: master
Are you sure you want to change the base?
Conversation
98c057b
to
b4666a6
Compare
414347d
to
0e5385f
Compare
8c0503e
to
41d57f0
Compare
8889ee2
to
e09b741
Compare
6f62217
to
a4bf0e6
Compare
It's great to see how the design nicely fermented over the three and half (!!) years. This is a completely opt-in feature for all plugins involved, so if the plugin decides to not do anything about it, it doesn't have to. The actual enforcements will come later.
Because there's no format ever that would support zero-copy everything (except the upcoming Magnum blobs, hah!), it makes no sense to force zero-copy globally. Instead, zero-copy can be forced just for particular data of interest. For example a glTF can zero-copy-import mesh and animation data, but not always image data (except if it embeds an uncompressed KTX), and never scene or material data, which are stored in the textual JSON.
Codecov Report
@@ Coverage Diff @@
## master #240 +/- ##
=======================================
Coverage 79.97% 79.98%
=======================================
Files 511 511
Lines 32354 32363 +9
=======================================
+ Hits 25875 25885 +10
+ Misses 6479 6478 -1
Continue to review full report at Codecov.
|
Meant to be used from within plugin implementations to avoid copies in the delegated importers. TODO: the heck, why can't I call a protected function from a subclass but another instance? TODO: figure out a way to test this TODO: update docs and behavior for the ZeroCopy flag TODO: adapt AnySceneImporter also
The end goal for this:
Utility::Directory::mapRead()
to memory-map a huge image / audio / scene fileAnimationData
,MeshData
,ImageData
... work directly on the memory-mapped dataThe progress, as of 2021-10-24:
TODO:
doOpenData()
to accept an r-value Array andDataFlags
describing whether it's temporary, owned by the importer, makeopenFile()
then pass over the allocated array ownership there -- 116d327openData()
with the same signature and the usual assertions from the publicopenData()
so proxy plugins such asAnyImageImporter
or opening images from within other plugins can make use of the memory ownership annotations as wellopenMemory()
as a zero-copy counterpart toopenData()
inTrade::AbstractImporter
+DataFlag::ExternallyOwned
, delegate to the above new `doOpenData() -- 27044a4DataFlag::Mutable
todoOpenData()
magnum-sceneconverter
-- 03aeb49magnum-sceneconverter
memory-map also referenced files via a callbackimplementthese interfaces will eventually get deprecated and merged intoopenMemory()
as a zero-copy counterpart toopenData()
inAudio::AbstractImporter
Trade::AbstractImporter
doOpenData()
andopenMemory()
equivalently inText::AbstractFont
as wellredesign-- done in Mesh Data rework #371 insteadTrade::MeshData2D
/Trade::MeshData3D
to eat an array (view) instead of vectorsadd an ability to put an array view to-- done in Mesh Data rework #371 insteadTrade::ImageData2D
/ ... (convert it to an array with a custom no-op deleter internally)implementdone differently in Mesh Data rework #371Trade::AbstractImporter::mesh2DMemory()
/ ... that's able to pass through the mapped data in case the file was opened viaopenMemory()
implementdone differently in Mesh Data rework #371Trade::AbstractImporter::image2DMemory()
/ ... that's able to pass through the mapped data in case the file was opened viaopenMemory()
implementthese interfaces will eventually get deprecated and merged intoAudio::Importer::data()
that's able to pass through the mapped data in case the file was opened viaopenMemory()
Trade::AbstractImporter
ImporterFlag::ZeroCopy
flag, which will enable importers to pass the input data fromopenMemory()
through toAnimationData
/MeshData
/ImageData
/ ... without copiesImporterFlag::ForceZeroCopyThing
for animations, images, mesh index/vertex buffers, ... that turns the above opt-in behavior to enforcedImporterFeature::ZeroCopyThing
with which the importer advertises ability to zero-copy certain data, which then gets assert for presence if the corresponding flag gets setImporterFeature::ZeroCopyScenes
andImporterFlag::ForceZeroCopyScenes
once SceneData rework #525 is inSkinData
needs to exposejointDataFlags()
&inverseBindMatrixDataFlags()
YUp
etc flags?), bump importer plugin interfaces for thatAnyImageImporter
etc. flag propagation now needs to handle the cases of the flag not being supported in the target and provide a runtime error instead of an assertImporterFlag::YUp
&ImageConverterFlag::YUp
to control whether images get Y-flipped on import and on conversion (otherwise it's not really possible to implement zero-copy import), similarly forZBackward
(andXLeft
?)ImageFlag::YUp
to annotate what orientation the image is in so this information doesn't get lost afterImporterFlag::YDown
/ImageConverterFlag::YDown
and a presence of neither meaning "keep it in whatever orientation it was" to make the zero-copy import not annoying to set uppixels()
behave -- they should probably return the view with X right, Y down, Z forward always to be consistent? That'll break existing code tho.WavAudioImporter
onceTrade::AbstractImporter
can do audio as wellFreeTypeFont
TgaImporter
once theYUp
flag is in (it also converts from ARGB or something, what to do ?)DdsImporter
once theYUp
flag is inKtxImporter
once theYUp
flag is inStanfordImporter
in progress,zerocopy
branch(impossible)TinyGltfImageImporter
CgltfImporter
ImageView::slice()
and then upload a slice to GPU memoryOpen questions / followup tasks: