Jump to content

Runtimes, how they are generated, why they are being targeted by materials, and versioning


photo

Recommended Posts

Posted

Hello everyone,

this is a post full of questions targeting the same subject: runtimes.

We've had some internal debates lately about what they are, if we should version them or care about them. I wanted to sum up what I know of what they are, so you can debunk some of my beliefs, and I wanted to ask a few things about how to work with them.

What I understand about them:
 

  1. A runtime file is a binary file in a Unigine-specific format used for faster loading times but also to represent the import options stored in a *.meta file since those are lost during build.
  2. Unigine loads all runtime assets first, look through their *.meta file to identify which source asset they are meant to override (since their GUID differs from the source asset).
  3. Runtimes are exclusively stored in .runtimes folders in the project data folder or, for umounts, in the mounted folder. They should never leave this folder, since they might be tagged as being completely different assets by Unigine.
  4. A runtime's meta file is completely different from a source asset meta file (JSON versus XML, and even the role of the file itself).
  5. Runtimes are referenced in an asset's meta file, I imagine to know which runtime is needed for each asset when building the project.
  6. When building, runtimes are preferred over their source asset. So my *.dds texture is not in the built project, but its runtime is, if it has one.

Thansk to 2) I have done some funny hacks where I changed the target GUID fro the runtime textures, choosing which asset I wanted to replace. It's useless, but good to know.

I had a few things where I'm not certain:

  1. How does Unigine manage runtimes for read-only mounted folders (while in editor) ? It can't generate the .runtimes folder in the folder, so where are the generated runtimes ? Does it create them ?
  2. How is computed an asset's GUID ? Does the path or its name matters ?
  3. Are runtimes GUID related in any way to the source asset GUID ? 
  4. Why not referencing the .runtimes in the built project guids.db file ?
  5. We've had some problems in asset links recently, and we've find out that the materials were showing, in red, the GUID of the runtime, not the source asset (in editor). Should the materials not target the source assets GUID instead ? Isn't that dangerous for any asset to refer to a runtime's GUID, since this asset may not exist depending on the source asset options ?
  6. Is the generation of runtimes related to the hardware ? Can we fear different outcomes from different setups ? I had in the past problems with our VMs not beign able to import some *.dds files, but I wanted to make sure the end result would always be the same.
  7. Due to some 2.19 migation problems, I pushed for versioning the runtimes, to allow stronger machines to import assets for the VMs. What is your politic concerning the versioning of runtime assets ?
Posted

Hello,

Before answering, I would like to clarify a few terms — I hope it makes the whole picture clearer:

  • Let's separate the Engine and the Editor: the Editor is built on top of the Engine and in some cases it adds its own behaviour.
  • The Editor manages runtime creation, deletion and movement, and uses the Engine to save them into a dedicated folder and to keep information about them.
  • Here we are talking about a single Engine subsystem — `Unigine::FileSystem`. Below, "the Engine" almost always means "Unigine FileSystem".
Quote

A runtime file is a binary file in a Unigine-specific format used for faster loading times but also to represent the import options stored in a \*.meta file since those are lost during build.

It is not always a binary file. A runtime file is always in a Unigine native format, that's true, but the format can be text-based: `.node` and `.prop` runtimes are XML.

Quote

Unigine loads all runtime assets first, look through their \*.meta file to identify which source asset they are meant to override (since their GUID differs from the source asset).

Not exactly. Loading all runtime files would take too long on a big project. That is why the Engine never reads the runtime files themselves at startup: it only walks over the files it has found on disk and reads the `.meta` file of each runtime file that really exists.

Quote

3. Runtimes are exclusively stored in .runtimes folders in the project data folder or, for umounts, in the mounted folder. They should never leave this folder, since they might be tagged as being completely different assets by Unigine.
4. A runtime's meta file is completely different from a source asset meta file (JSON versus XML, and even the role of the file itself).

Both points are correct.

Quote

5. Runtimes are referenced in an asset's meta file, I imagine to know which runtime is needed for each asset when building the project.

Not exactly. The `.meta` file (XML) of a source asset belongs to the Editor: only the Editor reads and writes it. The Engine restores the references from `guids.db` and from the `.meta` (JSON) files of the runtimes (unless the `-skip_guidsdb` option is set). To be precise, at startup the Engine does read the source asset `.meta` (XML) in some cases, but only to restore a GUID.

I would also like to mention the startup command line option "-skip_guidsdb", because the Editor uses it by default. If you run your Unigine-based application without this flag, the following code works even if "my.png" does not exist on disk:

ImagePtr img = Image::create("my.png");

In that case the Engine loads the runtime file instead: the link between "my.png" and its runtime file comes from `guids.db` and from the `.meta` file of the runtime.

Quote

1. How does Unigine manage runtimes for read-only mounted folders (while in editor) ? It can't generate the .runtimes folder in the folder, so where are the generated runtimes ? Does it create them ?

The FileSystem only reads them, nothing else. Runtimes are generated from source assets and they must be stored in the same mount as the asset, so for a read-only mount the Editor cannot create them at all — they have to be prepared in advance, while the mount is still writable.

If a source asset is not fully imported — for example the asset has changed and the "hash" value in its `.meta` file (XML) no longer matches — the Editor does not show it in the Asset Browser, because it does not consider it a valid asset.

Quote

2. How is computed an asset's GUID ? Does the path or its name matters ?

Neither matters. The GUID is simply generated, and it is re-generated only if the new value collides with an already known GUID.

Quote

3. Are runtimes GUID related in any way to the source asset GUID ?

A runtime GUID is not calculated from the source asset GUID — it is generated as well. But there are two details worth knowing:

  • For a runtime file the relation between the GUID and the path is reversed: the file name is the GUID, so the Engine gets the GUID of a runtime from its file name.
  • When the Editor creates the primary runtime of an asset, it usually gives the current asset GUID to the runtime and generates a new GUID for the asset itself. See my example in question 5 below.
Quote

4. Why not referencing the .runtimes in the built project guids.db file ?

There is no need for it. The GUID of a runtime file is its file name, so the Engine always knows it without any database, and the link to the source asset is stored in the runtime `.meta` (JSON), which we read anyway.

Quote

5. We've had some problems in asset links recently, and we've find out that the materials were showing, in red, the GUID of the runtime, not the source asset (in editor).

This is expected behaviour: the runtime GUID is used there.

Quote

Should the materials not target the source assets GUID instead ? Isn't that dangerous for any asset to refer to a runtime's GUID, since this asset may not exist depending on the source asset options ?

This is intentional. Could you describe a situation where you think it becomes dangerous? Meanwhile, let me show how the Editor manipulates GUIDs to keep such references valid, using a `.mesh` file as an example:

  1. `123.mesh` has no runtime and its GUID is "A". Some `.node` files refer to the GUID "A".
  2. The user changes the asset options, so the Editor creates a runtime for `123.mesh`. It assigns a newly generated GUID, say "B", to `123.mesh` itself, and gives the GUID "A" to the new runtime file. The `.node` files still refer to "A", so now they point to the runtime file.
  3. Later the user removes the runtime of `123.mesh`. The Editor deletes it and assigns the GUID "A" back to `123.mesh`.

So the references stay valid whether the runtime exists or not.

Quote

6. Is the generation of runtimes related to the hardware ? Can we fear different outcomes from different setups ? I had in the past problems with our VMs not beign able to import some \*.dds files, but I wanted to make sure the end result would always be the same.

Texture runtimes are generated on the GPU when it is possible, only to make the import faster, but the result is expected to be the same. Also, since SDK 2.16 we use our own `.texture` format for texture runtime files instead of `.dds`.

Quote

7. Due to some 2.19 migation problems, I pushed for versioning the runtimes, to allow stronger machines to import assets for the VMs. What is your politic concerning the versioning of runtime assets ?

We ALWAYS store runtime files in the version control system and commit them to git or svn together with the asset.

On top of that, the Editor has checks — and we have verified them — so that even if an asset and its runtime get out of sync, the Editor regenerates the runtime files. We added this because it used to be a frequent problem: an artist could commit an asset but forget to commit its runtimes.
 

  • Thanks 1
Posted

Wown thanks Victor. It actually dispels a lot of beliefs I had over the management of runtimes. 

 

31 minutes ago, victor said:

This is intentional. Could you describe a situation where you think it becomes dangerous? Meanwhile, let me show how the Editor manipulates GUIDs to keep such references valid, using a `.mesh` file as an example:

  1. `123.mesh` has no runtime and its GUID is "A". Some `.node` files refer to the GUID "A".
  2. The user changes the asset options, so the Editor creates a runtime for `123.mesh`. It assigns a newly generated GUID, say "B", to `123.mesh` itself, and gives the GUID "A" to the new runtime file. The `.node` files still refer to "A", so now they point to the runtime file.
  3. Later the user removes the runtime of `123.mesh`. The Editor deletes it and assigns the GUID "A" back to `123.mesh`.

So the references stay valid whether the runtime exists or not.

Well, I thought it was dangerous when I believed the ID used was created when generating the runtime. But as it stands, the ID is actually exchanged between the runtime and the source asset. So it's not.

Question 8:

Maybe there is an additional element I assumed I understood, but maybe not. In assets, we have the guid, and ids associated with "runtimes" (one beign the soruce asset, the other the generated runtime). The GUID example can easily be tested by changing the "unchanged" property on assets, and I can see the ids change.

<guid>7bee413711bf15dd4127235ed304c9cd150f83c8</guid>
  <type>texture</type>
  <hash>ba09bfcb</hash>
  <runtimes>
  <runtime id="d161d566696f0cb86a8bff171e76e4ebca319a94" name="brick_black_04_b_alb.png" link="0" type="6"/>
  <runtime id="538a62d5301d81933ba640fae299f39c5b425487" name="brick_black_04_b_alb.texture" link="1" type="6"/>
 </runtimes>

However, the asset guid doesn't change, and is different from the others. What is the relationship between the asset guid, and these ids ? I have a tendency to confuse them I believe. Is the file "guid" used ? 

Question 9:

A follow-up to your answer:

58 minutes ago, victor said:

The FileSystem only reads them, nothing else. Runtimes are generated from source assets and they must be stored in the same mount as the asset, so for a read-only mount the Editor cannot create them at all — they have to be prepared in advance, while the mount is still writable.

If a source asset is not fully imported — for example the asset has changed and the "hash" value in its `.meta` file (XML) no longer matches — the Editor does not show it in the Asset Browser, because it does not consider it a valid asset.

What is the hash supposed to represent ? The need to regenerate a runtime ? Am I right in assuming that a file in a read-only mount point, whose IDs only reference the source asset as runtime, but which should have a runtime (due to import options or format), will be used as is ? Or is it going to be considered as an invalid asset ?

Question 10:

Another follow-up.

1 hour ago, victor said:

Not exactly. The `.meta` file (XML) of a source asset belongs to the Editor: only the Editor reads and writes it. The Engine restores the references from `guids.db` and from the `.meta` (JSON) files of the runtimes (unless the `-skip_guidsdb` option is set). To be precise, at startup the Engine does read the source asset `.meta` (XML) in some cases, but only to restore a GUID.

I would also like to mention the startup command line option "-skip_guidsdb", because the Editor uses it by default. If you run your Unigine-based application without this flag, the following code works even if "my.png" does not exist on disk:

ImagePtr img = Image::create("my.png");

In that case the Engine loads the runtime file instead: the link between "my.png" and its runtime file comes from `guids.db` and from the `.meta` file of the runtime.

So in an application without this option, the guids.db contains the names of source assets with their guids (even if they have been removed from the build), which can be used alongside the JSON meta file from the runtime to identify the relationship between an asset name and its runtime ? The Engine virtual filesystem will still consider the assets that have been replaced by runtimes as being present in the virtual folders ?

So if I were to iterate over all files in a virtual folders, will I see my source assets, despite them not being actually there ? And If I load/open them, I will have the content of the runtime ?

Question 11:

We've had some problems with svn and GUIDs recently when moving folders around, and importing packages. We've lost many links between materials and textures. Can moving textures around, from outside the editor, create problems ? Even if we keep the meta files ? It's generally the materials losing track of the textures, or the nodes losing track of the meshes

Question 12:

Since we're speaking about materials, why do they have their GUID inside their definition file, but also a *.meta file ? Is there some behavior that might require both ?

Question 13:

1 hour ago, victor said:

We ALWAYS store runtime files in the version control system and commit them to git or svn together with the asset.

On top of that, the Editor has checks — and we have verified them — so that even if an asset and its runtime get out of sync, the Editor regenerates the runtime files. We added this because it used to be a frequent problem: an artist could commit an asset but forget to commit its runtimes.

Apart from our VMs freezing while importing assets, what kind of problems the absence of any runtime will appear further down the roads ?
The obvious I could see is that since the real GUID referenced in materials (or such) is the one from the runtime, we could have a harder time finding the assets a material was supposed to point too when debugging our assets.

Posted

Hello Kevin,

Quote

However, the asset guid doesn't change, and is different from the others. What is the relationship between the asset guid, and these ids ? I have a tendency to confuse them I believe. Is the file "guid" used ?

Please don't pay attention to `<asset><guid>`. I hope we will remove it in the future, because it's only needed while the Editor is running. It's used only in Editor's internal code and nowhere else. Of course, we currently check it to avoid duplicates, but this GUID actually means "an ID of one specific source asset", a source asset contains a .meta file with its asset description, where it's a hash, the asset import options and the `<runtimes>` section, which I will describe below.

The `<runtimes>` section consists of:

  • A mandatory `<runtime>` line with `link="0"`. It's an asset GUID with some extra information (type, link, etc.), and this GUID is a file ID from `Unigine::FileSystem`.
  • An optional line, or several lines, with runtime GUIDs, which are file IDs from `Unigine::FileSystem`.

An ID is from `Unigine::FileSystem` except (!) for properties and materials. When a `<runtime>` points to a material or a property file, it contains the ID of the material or the property respectively. This is a special behaviour we have for some internal reasons.

Quote

What is the hash supposed to represent ? The need to regenerate a runtime ?

It contains at least a hash of the source asset file and a hash of its `.meta` file. If the hash doesn't match, the reimport stage starts.

Quote

Am I right in assuming that a file in a read-only mount point, whose IDs only reference the source asset as runtime, but which should have a runtime (due to import options or format), will be used as is ? Or is it going to be considered as an invalid asset ?

Partly - let me clarify. The Editor considers such an asset invalid and doesn't allow the user to work with it in the Editor UI. But the Engine loads files from a read-only mount point, and if a file references a source asset or a runtime file from this mount point, rendering and logic will work fine - of course, only if the Engine can process these files.

We do have plans to show such invalid assets in the Asset Browser in the future, but honestly, it requires a lot of work.

Quote

So in an application without this option, the guids.db contains the names of source assets with their guids (even if they have been removed from the build), which can be used alongside the JSON meta file from the runtime to identify the relationship between an asset name and its runtime ? The Engine virtual filesystem will still consider the assets that have been replaced by runtimes as being present in the virtual folders ?

Yes and yes, you are correct.

Quote

So if I were to iterate over all files in a virtual folders, will I see my source assets, despite them not being actually there ?

To be precise, the FileSystem has no such abstraction as a virtual folder, but you will be able to iterate over all virtual files in the FileSystem, even though they don't exist physically.

Quote

And If I load/open them, I will have the content of the runtime ?

Yes, that's exactly how the FileSystem works.

Quote

Can moving textures around, from outside the editor, create problems ? Even if we keep the meta files ?

Theoretically, no.

Quote

It's generally the materials losing track of the textures, or the nodes losing track of the meshes

This is an interesting case for me, and I would like to see how it happened, because in the simple case, when you move a `.png` with its `.meta` file to another folder, everything should work. In 2.16 we even added support for the case where you move an asset file with its `.meta` file to another mount point and then start the Editor. We will double-check this feature.

Quote

Since we're speaking about materials, why do they have their GUID inside their definition file, but also a \*.meta file ? Is there some behavior that might require both ?

I've answered this above.

Quote

Apart from our VMs freezing while importing assets, what kind of problems the absence of any runtime will appear further down the roads ?

I'm not sure I understand your case - how your infrastructure and project are built, and why your VMs are freezing - but I do know that `/.runtimes/` is a mandatory part of a Unigine-based application, and every time you start the Editor without runtime files it will generate them, which may take a lot of time.

  • Thanks 1
Posted

Hello Victor,
 

2 hours ago, victor said:

An ID is from `Unigine::FileSystem` except (!) for properties and materials. When a `<runtime>` points to a material or a property file, it contains the ID of the material or the property respectively. This is a special behaviour we have for some internal reasons.

If you make the distinction between a GUID from a Filesystem and an ID for properties/materials, am I to believe materials/properties will not appear in the virtual filesystem ? 

 

2 hours ago, victor said:

This is an interesting case for me, and I would like to see how it happened, because in the simple case, when you move a `.png` with its `.meta` file to another folder, everything should work. In 2.16 we even added support for the case where you move an asset file with its `.meta` file to another mount point and then start the Editor. We will double-check this feature.

It is difficult to pinpoint the trigger mechanism for this. We will try to catch them next time and investigate a little more to understand what we did wrong. But it was a very special occasion, I was making a rollback from Unigine 2.19 to Unigine 2.18.

 

2 hours ago, victor said:

It contains at least a hash of the source asset file and a hash of its `.meta` file. If the hash doesn't match, the reimport stage starts.

So it doesn't compare with a hash of the runtime file ? The one referenced in the source asset meta file ?

 

2 hours ago, victor said:

I'm not sure I understand your case - how your infrastructure and project are built, and why your VMs are freezing - but I do know that `/.runtimes/` is a mandatory part of a Unigine-based application, and every time you start the Editor without runtime files it will generate them, which may take a lot of time.

Well there's nothing fancy in our use case of Unigine. Asset folders versioned under svn, then used to build our application through Unigine's build tool. I've exchanged with your support on the question of VMs freezing. During the 2.19 migration, dds files became replaced by runtimes, and this increased dramatically our import process. Our build machines (VMs) became stuck when importing some of those dds files. Those didn't have access to GPUs, so it was incredibly long for them with their CPU. We fixed that by basically restoring the versionning of runtimes, so stronger machines could generate the runtimes.

It increased our repository size, but accelerated our builds time (at least the first) and ensured we didn't have any new crash with 2.19. In 2.18 this isn't a problem yet, so we have debates about repository size or build times. 

A new question : I have a file A at a location L1 (which is a mount point), and its runtime B in the .runtimes folder. If I move the file A outside the mount point (or in another), is the runtime going to stay in the same runtimes folder ? Or is it going to be removed, then regenerated in the .runtimes folder associated with the new location for A ?

When does the editor decides a runtime is to be destroyed/replaced ? Based on a source asset (hash, change in options) yes, but can it be based on a runtime's meta file ? Like the runtime doesn't point to an existing asset ?

Sorry Victor, I may have a hundred questions on this subject 🙂

Posted

Hello Kevin,

Quote

If you make the distinction between a GUID from a Filesystem and an ID for properties/materials, am I to believe materials/properties will not appear in the virtual filesystem ?

They do appear - let me clarify. Material and property files are added to and processed by the virtual filesystem. The Editor tries to make the property/material ID and the ID from `Unigine::FileSystem` the same; it does this at startup. That is why the property/material ID is usually the same as the filesystem ID, but it is fine when they are different.

Quote

So it doesn't compare with a hash of the runtime file ? The one referenced in the source asset meta file ?

We use a trick to avoid calculating a hash of the runtime file. We additionally save the main hash from the asset `.meta` file into the `.meta` (JSON) of the runtime file. This way we don't need to hash the runtime itself, and we can still be sure that this runtime file belongs to its source asset.

Quote

I have a file A at a location L1 (which is a mount point), and its runtime B in the .runtimes folder. If I move the file A outside the mount point (or in another), is the runtime going to stay in the same runtimes folder ? Or is it going to be removed, then regenerated in the .runtimes folder associated with the new location for A ?

Looking back at what I posted earlier, I realize it wasn't clear:

Quote

In 2.16 we even added support for the case where you move an asset file with its `.meta` file to another mount point and then start the Editor. We will double-check this feature.

What I meant was this: if you move file A to another mount point and then start the Editor, it will remove its runtime B and start regenerating it; we call this the reimport stage.

If you move file A to a folder outside any mount point, the Editor will only process it in the Cleaner tool - it either removes the runtime, if nothing references it, or reports it as a lost runtime in the project.

Quote

When does the editor decides a runtime is to be destroyed/replaced ? Based on a source asset (hash, change in options) yes, but can it be based on a runtime's meta file ?

The Editor relies on the information from the source asset `.meta` file and on the hash value from the runtime's `.meta`.

Quote

Like the runtime doesn't point to an existing asset ?

I think I covered this above, in the part about the Cleaner tool.

Quote

Sorry Victor, I may have a hundred questions on this subject

Please don't stop - keep them coming. I hope this thread will help more people understand the Unigine FileSystem and how the Editor manages it.

  • Thanks 1
  • 1 month later...
Posted

What a dense lecture, but really needed.

I will re-read this thread several times to asimilate all the info posted.

Our team has a lot of problems becuase de-synched guid references throught the nodes and we solve it by the radical way: Someone of us delete all the runtimes and the gui.db. Open the editor to regenerate them and commit all the changes so the rest could update a clean and functional version of the project.

I think it's not the most clean way of do things but as we do not fully understand how to work with the runtimes this Salomonic solution is the more fast way we founded to clean missing/clashed references.

Another "issue" we face sometimes is that if we don't take care in the naming of assets and import one with an existing name in the FileSystem, one of those assets is not shown in the editor becuase duplicated guid. An improvement to this could be include the folder where the asset is placed in the GUI generation to avoid this kind os conflicts.

Posted

Hi Guillermo,

Removing guids.db and regenerating .runtimes dir is actually very useful in some cases.

 

Quote

 one of those assets is not shown in the editor becuase duplicated guid. 

That is a much more difficult case to handle, but we do plan to improve this behavior in the Editor in the future.

Thank you!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Posted

I've some other questions about runtimes:
 

  1. I tried adding a script to delete all .runtimes folders and reopen the editor, and all my runtime nodes (runtimes of FBXs I suppose) are identified as "modified" due to the ids of the nodes changing (no the GUID, just the id attribute in the node tag). Why would that happen ? I mean, it's not a big problem but it's annoying to have svn notify us of differences between files which have no interest to us.
  2. We often have the problem with assets moving around in the hierarchy and people not cleaning up their local runtimes, and apparently when they open the editor after an update, it's messed up. Is it why you push to version all runtimes ? Can we instruct the Unigine build tool to clean the .runtimes folders before a build ?
Posted

Hi Kevin,

Quote

We often have the problem with assets moving around in the hierarchy and people not cleaning up their local runtimes, and apparently when they open the editor after an update, it's messed up. Is it why you push to version all runtimes ?

You mean you move assets with Editor being shut down? In that case that's expected behavior, editor can't see the file operations you did while it's been closed and can't properly fix all the issues. We push to version all runtimes for faster Editor start mostly, otherwise you would need to wait for half an hour before you can even start working with the project.

 

Quote

Can we instruct the Unigine build tool to clean the .runtimes folders before a build ?

If you have something like build.bat in your CI for building the final project you can do it manually in that script. Just locate the .runtimes dir and delete with RD before you start assemble the final version:

// build.bat
set foldername=<Path\to\.runtimes>
for /D %%i in ("%foldername%\*") do RD /S /Q "%%i"

and then do a normal build. Maybe you will need to generate runtimes first, for that we have build-in RuntimesGenerator tool.
 

Quote

I tried adding a script to delete all .runtimes folders and reopen the editor, and all my runtime nodes (runtimes of FBXs I suppose) are identified as "modified" due to the ids of the nodes changing (no the GUID, just the id attribute in the node tag). Why would that happen ? I mean, it's not a big problem but it's annoying to have svn notify us of differences between files which have no interest to us.

For nodes inside .runtimes (FBX files), the ID is generated during import and is essentially random. In this case, the node itself is the only source of the node ID.

NodeReference IDs are dynamic by design and may change even when you simply open the NodeReference in the Editor.

For .node files in the data directory that are referenced from a .world file, their IDs are read when the world is loaded. The engine then tries to preserve those node IDs when the world is saved.

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

×
×
  • Create New...