-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Retain asset without data for RENDER_WORLD-only assets #21732
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
base: main
Are you sure you want to change the base?
Conversation
|
I wonder if it would be better having an enum like this just to have some more information enum RenderAssetData {
Available(Vec<u8>),
Unavailable,
SentToRenderWorld
} |
|
maybe ... i tried to avoid changing the api of the main-world types (particularly |
| /// If an asset is set to the `RENDER_WORLD` but not the `MAIN_WORLD`, the asset will be | ||
| /// unloaded from the asset server once it's been extracted and prepared in the render world. | ||
| /// If an asset is set to the `RENDER_WORLD` but not the `MAIN_WORLD`, the asset data (pixel data, | ||
| /// mersh vertex data, etc) will be removed from the cpu-side asset once it's been extracted and prepared |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// mersh vertex data, etc) will be removed from the cpu-side asset once it's been extracted and prepared | |
| /// mesh vertex data, etc) will be removed from the cpu-side asset once it's been extracted and prepared |
| #[inline] | ||
| pub fn indices(&self) -> Option<&Indices> { | ||
| self.indices.as_ref() | ||
| self.indices.as_ref().expect("Mesh has been extracted to RenderWorld. To access vertex attributes, the mesh must have RenderAssetUsages::MAIN_WORLD").as_ref() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we swap these methods to return Result and avoid the expects here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could … it is a usage error though, rather than “something that can happen and you should deal with”, like result usually implies.
I don’t feel strongly, will change if you prefer it.
Objective
when
RenderAssetswithRenderAssetUsages::RENDER_WORLDand withoutRenderAssetUsages::MAIN_WORLDare extracted, the asset is removed from the assets collection. this causes some issues:AssetServer::get_handleSolution
extraction:
take_gpu_datato theRenderAssettrait. use it to pull the data out of the asset for transfer, and leave the empty asset in the collection. default implementation justclones the asset.Mesh/RenderMesh:
Mesh::attributesandMesh::indicesoptionsexpectoperations which access or modify the vertex data or indices if it has been extracted. accessing the vertex data after extraction is always a code error. fixes Somehow prevent confusion caused by Assets being removed due to not having RenderAssetUsages::MAIN_WORLD #19737 by resulting in the errorMesh has been extracted to RenderWorld. To access vertex attributes, the mesh must have RenderAssetUsages::MAIN_WORLDAabbwhen gpu data is taken and store the result. this allows extracted meshes to still use frustum culling (otherwise using multiple copies of an extracted mesh now panics ascompute_aabbrelied on vertex positions). there's a bit of a tradeoff here: users may not need the Aabb and we needlessly compute it. but i think users almost always do want them, and computing once (for extracted meshes) is cheaper than the alternative, keeping position data and computing a freshAabbevery time the mesh is used on a new entity.Image/GpuImage:
images are a little more complex because the data can be deliberately
Nonefor render-targets / GPU-written textures where we only want an uninitialized gpu-side texture.Image::dataon extractionGpuImagewhether any data was found initiallycorner case / issue: when used with
RenderAssetBytesPerFrameLimiterthere may be no previous gpu asset if it is still queued pending upload due to the bandwidth limit. this can result in a modified image with initial data skipping thehad_datacheck, resulting in a blank texture. i think this is sufficiently rare that it's not a real problem, users would still hit the panic if the asset is transferred in time and the problem/solution should be clear when they do hit it.ShaderStorageBuffer/GpuShaderStorageBuffer
follows the same pattern as Image/GpuImage:
ShaderStorageBuffer::dataon extractionGpuShaderStorageBufferwhether any data was found initiallywe don't have the queue issue here because
GpuShaderStorageBufferdoesn't implementbyte_lenso we can't end up queueing them.other RenderAssets
i didn't modify the other
RenderAssettypes (GpuAutoExposureCompensationCurve,GpuLineGizmo,RenderWireframeMaterial,PreparedMaterial,PreparedMaterial2d,PreparedUiMaterial) on the assumption that cloning these is cheap enough anyway.Testing
only really tested within my work project. i can add some explicit tests if required.