Category: Aircraft & Modeling

Third Party Cars Should Really Be Instanced

I’m going to keep going with “random stuff I looked at today” and see if there’s something for authors mixed in.

I spent part of today measuring shader and texture changes in our engine under heavy load – my goal was to get a sense of how much data we’d be pushing through a next-gen API (e.g. Vulkan, Metal, DX12) if we just did a straight port of the engine.  This was just a fact finding mission.

The only problem was: the numbers were just absolutely awful. Terrible. Unusable!

Then I noticed the other thing: the entire area of KSEA was littered with thousands of Fed-Ex trucks.  Just tons and tons of them!  Only Fed-Ex trucks on the road, and only Fed-Ex trucks parked on the street.


Leftovers For Lunch

The Fed-Ex trucks were a left-over. I do this to myself all the time: I create a dumb custom scenery pack to test some part of the sim and then forget to remove it from my working X-Plane folder.

Before X-Plane 1040 there was a bug where cars and trucks on the road could crash the sim if you viewed them across a DSF tile boundary and the 3-d models were not instanced. This last point is why the bug went unfixed for so long; the car set we ship with is entirely instanced for performance.

So I built a library with a Fed-Ex truck that was intentionally not instanced to reproduce the bug and forgot about it. The custom scenery pack was why my traffic looked silly, and the non-instanced traffic was why my stats showed the rendering engine doing 4x more on the CPU work than it was supposed to.

(Since X-Plane was in debug mode, the framerate was expected to be terrible due to unoptimized code and debug checks running on an old laptop with the scenery cranked to the max.)

So there’s a take-away here and it is:

OBJs in a Custom Vehicle Pack Should Be Instancing-Friendly

There are a few custom vehicle packs for X-Plane floating around the web, and the quality of the objects with regards to performance is mixed and overall not very good – probably some of these packs pre-date X-Plane 10.

Instancing is the ability for X-Plane to draw more than one OBJ in a single instruction to the GPU. We implement instancing by observing your OBJ as we load it and noting whether the OBJ contains anything complicated (dataref usage, animation, lots of material changes) or if it is more or less just a big pile of triangles.

If we have the latter case, then we mark the object as instancing friendly, and when it is drawn, all objects of that type are collected and drawn at once. The instancing code path in X-Plane is thus separate and much faster for both X-Plane itself and the driver.

Since you can have a lot of the same car on the roads, even with a varied collection, it’s worth it to be instanced!

How to Tell If Your Object Is Instance-Friendly

To see if your object is instancing friendly:

  1. Make a custom scenery pack and place ten of the objects very close to each other (e.g. at an airport).
  2. Load the airport in X-Plane and in DRE set the art control “terrain/kill_clusters” to 1.

When you do this, all of the instanced objects that come from DSFs will disappear, and all of the non-instanced ones will remain.

Your object will be instance-friendly if:

  • It uses no animations
  • It uses no ATTRibutes mid-object – use the new GLOBAL properties instead
  • For cars, LOD is okay (but non-additive LOD will make the WED test fail). For cars you should only use one LOD anyway.
  • Only some named lights are instancing friendly; fortunately the headlight/taillight ones are.

Draped geometry is instancing-friendly, but don’t use it for vehicles.

In the new Blender 2.7 exporter (and our branch of the Blender 2.49 exporter) instancing is made quite easy: you mark an object as “instanced” and one of two things will happen:

  • Blender will write only stuff that is instancing friendly or
  • The export will fail with an error telling you what you did wrong.

Thus when you -need- something to be instanced (scenery objects, etc.) you just tell the exporter to enforce it.

Here are some things where instancing really matters:

  • Repeated buildings in autogen.
  • Static aircraft that repeat a lot.
  • “Clutter” on the ramp (baggage trucks, etc.).
  • 3-d modeled vegetation that gets repeated.
  • Cars (both parked and moving)

Here are some cases where it does not matter:

  • Aircraft-attached objects. Since aircraft attached objects aren’t usually repeated and almost always have a lot of complicated stuff, instancing doesn’t matter or work here. Instancing is really for scenery.
  • Single extremely complicated objects like the Nimitz.

Right now objects drawn with the XPLMDrawObjects API call do not benefit from instancing, but this is probably something that will change in the future, as long as every “instance” is fed through a single XPLMDrawObjects call.

Posted in Development, Modeling, Scenery by | 12 Comments

Don’t Ship Payware Using Beta Plane-Maker

In my previous post I mentioned that re-saving your aircraft in Plane-Maker from X-Plane 10.45 would opt you in to the new fixed torque model.

I’ve talked about this before, but it might bear repeating now:

Please do not ship an aircraft saved with a beta version of Plane-Maker.  Instead wait for X-plane to go final or use the previous non-beta version of X-Plane.

The problem is that file formats change during beta and if they do we do not provide compatibility; the file format is only “for real” when beta is over.

So if you need the torque bug fix, plan to ship your aircraft in a week or two when 10.45 beta is over.  If you need to ship now, use Plane-Maker 10.42.  Test against the beta, but don’t save using it.

Posted in Aircraft, Aircraft & Modeling by | 2 Comments

How to Apply the Torque Fix to Your Aircraft

X-Plane 10.45 beta 1 fixes a bug in X-Plane’s flight model where props applied too much torque to the aircraft. The effect is most noticeable on single engine aircraft where the prop torque is applied along the center of the fuselage.

Authors: in order to have the new correct torque applied to your aircraft, you must resave your aircraft in Plane-Maker 10.45. When X-Plane finds an aircraft authored with an old Plane-Maker, which includes all existing aircraft already shipped, we preserve the old torque behavior.

We put in this compatibility because some aircraft have plugins and other work-arounds that try to get correct flight dynamics assuming X-Plane will apply too much torque.  If we were to apply the fix to these planes, they’d then have too little torque (because we’d apply less torque and the work-around would already be in place). So this is an opt-in fix.

Authors: if you use Plane-Maker 10.45 to work on your aircraft, you will be opted in to the fix!  There is no way to work on a new aircraft and preserve the old torque. Our thinking is: the old torque calculating is physically wrong, so we’re not letting anyone preserve this mistake when working on a new aircraft.

So when you bring your aircraft in for its next feature update, note that you will be getting the torque fix and you should make sure the results are useful.

Posted in Aircraft, Aircraft & Modeling by | 6 Comments

Making 3-d Modeling Less Weird

I mentioned in a previous post that we are working with Ondrej on a next-generation Blender 2.7 OBJ exporter. I am excited for this work because I believe it will greatly improve the artist interface to X-Plane. Let’s use instancing as an example to explain the idea.

X-Plane 10 will sometimes draw scenery objects using hardware instancing. When an object is drawn with instancing, performance is a lot better than without it; the huge numbers of objects you can see in the autogen scenery are due to instancing. But the conditions for instancing are, to put it mildly, complicated.

  • The object has to be attached to a DSF. Well, that’s not crazy.
  • There’s a giant pile of things you’re not allowed to do in an instanced object – animation, material attributes, smoke puffs, bla bla bla. (The object has to be simple so that the GPU can draw a big pile of objects without the CPU intervening to handle things like smoke generation on a per-object basis.)
  • Buuuuut…not every ATTRibute is a problem. You can use ATTR_hard in an instanced object, no problem! But don’t use ATTR_shiny_rat – that’ll kill instancing.
  • But wait, there are these weirdo new attributes like GLOBAL_specular that seem to replace ATTR_shiny_rat that do work with instancing.

If you model, and this seems confusing, it’s because it is. You were never supposed to see this!

File Formats for Machines and Applications For Humans

My view is this: the file formats of X-Plane are meant to be seen by programmers, not artists. When was the last time you had to hand-edit an .acf? You just use Plane-Maker. You don’t hand-edit a PNG file or worry about its internal compression – you use PhotoShop.

OBJ should be the same way – you should export from a 3-d tool and never have to look inside the OBJ itself. This means the OBJ8 format can serve two purposes:

  • Help X-Plane load models quickly and draw good looking content and
  • Maintain compatibility so older scenery continues to load.

Note that “be really easy to understand in Notepad” is not on the list!

Blender the Transformer

Now here’s the trick: the rules for OBJ that a 3-d modeler can present can be different from the rules that the OBJ8 format itself has. And that is exactly what we are trying to do in the new Blender exporter.

Rather than expose global attributes and non-global attributes and all of the crazy complexity of OBJ8, our strategy with the new exporter is this:

  • When you export a scenery object, you specify if you want the object to be instanced or not.
  • If the object is not instanced, Blender creates the best OBJ it can for this case.
  • If the object is instanced, Blender tries to create the best OBJ it can for this case.
  • If the object is supposed to be instanced but you’ve done something that is not instancing-friendly, the exporter tells you, in terms you can understand.

So for example, if you make an animated radar dish that spins and attempt to export with instancing, the exporter can say “you cannot have animation in an instanced object.” Now you, the scenery designer, can make a decision: is it more important to have the radar dish draw really really fast, or is it more important that it spins?

This is the strategy we used for our modifications of Marginal’s 2.49 exporter* – the artist specifies instancing and gets a check that instancing requirements have met. This means instance-tagged objects will be fast. (It is possible to check instancing within the sim with DataRefEditor but it’s not easy, especially for large projects.)

Don’t Expose the Weird

This idea that Blender can transform your work, and thus hide weird X-Plane rules, is not specific to OBJ, not new to X-Plane, and not even specific to X-Plane. When you look at major 3-d game engines (e.g. for combat games and racing games) a ton of code goes into the “art asset pipeline”, transforming the artist’s original work into something already digested for the 3-d engine.

Another example of this is WED. DSFs have an annoying rule that polygons can’t cross DSF boundaries. There are also some even weirder exceptions for a few special cases, introduced in X-Plane 10.20.

WED knows all of these rules; you draw polygons wherever you want and set the export target for the version of X-Plane you want to fly in, and WED figures out the best way to export your work, chopping up polygons as needed.

Shedding Light on Things

Our current work on the Blender exporter focuses on WYSIWYG animation and the material model (which includes instancing support). There is one more area that I think will make a huge difference to authors that we haven’t started working on yet: lighting.

The lighting values for commands like LIGHT_PARAM are, to put it mildly, completely goofy. If you’ve ever tried to read this, you know that even when things are explained, they make no sense.

No author should ever have to write a LIGHT_PARAM. This is a classic case where the exporter should do the transformation for us. What I would like to get into Blender 2.7 is the ability to place a cone light in Blender and have the exporter write the spill light automatically, e.g. filling in the parameters from the position and shape of the light. You light your scene and you see the same thing in X-Plane.

For years we’ve been behind the curve on user experience when it comes to 3-d modeling. I think we’re starting to fix some of those problems in a major way, which should help make the power of X-Plane 10’s rendering engine quite a bit more accessible.


*As a side note, I have no idea what the current 2.49 script status is. We view the 2.7 scripts as the long term way forward, due to Blender 2.49’s not being maintained, so our effort on a truly user-friendly tool is going into 2.7. But we also maintain updates to 2.49 to support our internal team. X-Plane 10.50 will feature a few new OBJ commands, so I will try to post our branch of the 2.49 scripts (which do have this new support) for anyone whose aircraft is in 2.49.

In the long term the 2.7 scripts will feature a migration tool, but I expect we will have a useful 2.7 release (for 2.7 authors) without migration first, and then migration will come later.

Posted in Development, Modeling, Tools by | 30 Comments

Scenery Tools Update

Update: the comments form is fixed – sorry about that!

I’ve been working a bit on scenery tools this week. Here’s a road map of some of what’s coming up.

WED and the X-Plane Scenery Gateway

We are working on a release of the latest scenery gateway airports for X-Plane 10.45. Like all releases, we’ve found problems with airports that WED does not detect. So I will try to release a new version of WED with stricter validation soon.

Airport Parking Spots

Austin is working on new code to place static aircraft at unused ramp parking spots. I’l describe this in more detail in another post, but here are some key points:

  • As an airport author, you simply place ramp starts, not static aircraft.
  • X-Plane will feature some new static aircraft in the update.
  • Third parties can further add to the static aircraft and have them be used via the library system.
  • There will be a revision to the apt.dat format that stores more data per ramp spot and a WED update to support this new data.
  • Since there may be scenery now with static aircraft on top of ramp starts*, we will auto-remove static aircraft from ramp starts in the gateway export as a temporary measure until authors can resolve the situation and post the fixes to the gateway.
  • We are not removing the old static aircraft from the library, but we will be hiding them from WED’s library so that authors use ramp starts instead of placing them by hand.

Static aircraft in parking spots will ship next year, not this year, but is planned as a v10 update.

Scenery Tools on OS X

I made significant progress this week porting WED for OS X to 64-bit and modern Mac APIs. This effort basically meant rewriting the OS-level UI code in WED to be new AppKit based calls instead of the old Carbon API.

What this means is that developers will be able to build all of the scenery tools on a modern Mac running Yosemite or El Capitan with X-Code 7. Since Chris has already updated the projects to compiled WED in MSVC, a developer can build all of the common scenery tools from the most widely used open source IDEs.

It also brings us closer to a 64-bit WED on Mac, which is desperately needed since OS X provides the least amount of usable address space to 32-bit apps. I am not sure of the 64-bit status of the Windows WED build; it may need more work on the libraries.

Will It Blend

This might be the most significant scenery tools development: we’ve been working with Ondrej (der-On on Git-Hub) on new features for the Blender 2.7 exporter. This will include:

  • Much better animation support. Complete WYSIWYG animation of data blocks and bones, with no work-arounds needed. Bone animations match Blender 2.49 so you can move your projects forward.
  • Modernized material support including instancing for a really clean work-flow that takes advantage of X-Plane 10’s features.
  • Updates for the latest OBJ features.
  • Our plan is to create a migration script to bring 2.49 projects into 2.7, converting the special tags used for an X-Plane 2.49 export into 2.7.

Many of our artists still use 2.49, but there’s no question that 2.49’s days are numbered. It’s a question of when it stops working on OS X, not if. With the migration step, we can move our projects forward without artists having to redo work.

Like the previous 2.7 exporter, this one is open source and will be free, and should be able to export existing 2.7-type projects with no modifications – we are trying to maintain full backward compatibility.


* This situation is slightly silly – if the user picks the ramp start to fly, the user will be on top of a static aircraft.

Posted in Modeling, Scenery, Tools by | 22 Comments

SASL Crash Fixed – You’ll Need a New SASL

Since El Capitan came out, SASL has been crashing on quit when used in aircraft with customized sound. While I work on neither SASL nor El Capitan, both are (at least partly) open source, so I spent a few hours yesterday and located the bugs.

The good news is: this bug is fixed in SASL version 2.4. The bad news is: you’ll need to make sure the aircraft you are flying is using SASL 2.4 – and this applies to every aircraft that you have that uses SASL.

If you develop an aircraft using SASL, you can get the latest free version of SASL here. Note that this new version is apparently 64-bit only.

If you are using a freeware aircraft that is no longer supported, I think you could theoretically drop in the new SASL and see if it fixes things. If the aircraft is payware, the aircraft author might not be thrilled to have to support a “modified” aircraft and might prefer to do the upgrade in-house.

If you are a developer of SASL or you use OpenAL, you can read the gory technical details here.

Posted in Aircraft, Development, News by | 9 Comments

Performance Analysis by Subtraction

In a previous post I discussed a new facility in X-Plane 10.25r1 (coming real soon) to disable aircraft-attached objects for performance optimization.  There is a second use for this feature: performance analysis.

This post is targeted at aircraft authors, particularly authors who create complex aircraft with Lua scripts or plugins.

The basic idea here is to remove work from X-Plane and measure the improvement in performance.  I strongly recommend you look at X-Plane’s framerate in milliseconds.  An improvement of 1 frame per second is a big improvement at 15 fps and almost nothing at 60 fps.  But saving 5 ms is always a good thing, no matter what framerate.

The GPU Is Confusing

Your graphics card is basically a second computer, with its own memory, its own bus, and its own CPU (in this case called a GPU).  Ideally the CPU on your computer and GPU on your graphics card are both working at the same time, in parallel, to present each frame of X-Plane.

OpenGL drivers accomplish this by building a “todo” list for the GPU, which the GPU then does on its own time.  Ideally the CPU is off computing flight models and running plugins while the GPU is still filling in mountain pixel shaders on screen.

For any given frame, however, one of the CPU or GPU will have more work than the other, and the other will be idle some of the time.

  • If you have a lot of GPU work (e.g. 4x SSAA HDR with clouds on a huge screen) and not much CPU work (e.g. no autogen) then the CPU will have to wait.  It will give all of its instructions to the GPU for a frame, then the next one, then the next one and eventually the GPU will go “stop!  I’m not done with the frames you gave me” and the CPU will wait.
  • If you have a lot of CPU work (e.g. lots of objects and shadows and plugins) but not much GPU work (e.g. a small screen without HDR on a powerful graphics card) the GPU will wait; it will finish its entire todo list and then go “uh, now what?”.  Until the CPU can get more instructions ready, the GPU is idle.

Here’s the key point: your framerate is determined by the processor that is not idle.  If your GPU is idle and your CPU is not, you are “CPU bound”; if your CPU is idle and your GPU is not, you are GPU bound.  Optimizing the use of the processor that is idle will not improve framerate at all.

Viewing Specific Processor Load in X-Plane

X-Plane’s “frame rate” data output gives you two useful numbers for figuring out where X-Plane is spending its time:

  • “frame time” gives you the total time to draw one frame, in milliseconds.
  • CPU load give you the fraction of that frame time that the CPU was busy.

For example, my copy of X-Plane is showing 9 ms frame time and .78 CPU load.  That means that the GPU needs 9 ms to draw the frame, but the CPU needs 7 ms to draw the frame – I am GPU bound. (I am also in the middle of the ocean, hence the low numbers.)

Unfortunately if you are CPU bound (CPU load > 0.95 or so) there is no current display for the GPU’s utilization; we are working on that for X-Plane 10.30.

Analyze Performance By Subtraction

Putting it all together:

  • You can calculate the actual CPU time spent in your add-on from the CPU load and frame time data outputs.
  • You can disable your add-on to see how much CPU time is now used; the difference is the CPU time your add-on is consuming.
  • You can change settings to be GPU bound (and confirm that by seeing CPU load < 0.95).  Once you are GPU bound, improvements in framerate when you turn off your add-on show the amount of time you used the GPU for.

Armed with this knowledge, you can find the real cost in milliseconds of GPU and CPU time of the various parts of your add-on.  You can find out what costs a lot (the panel? The 3-d? The systems modeling) and then focus your optimizations in places where they will matter.

Support Performance Analysis in Your Add-Ons

In order to tell what part of you add-on is consuming CPU and GPU time, you need to be able to separate your add-on into its sub-components and disable each one.

If your add-on makes heavy use of plugin code or scripts, I recommend putting in datarefs that turn off entire sub-sections of processing.  Good choices might be:

  • Bypassing custom drawing of glass displays in an aircraft.
  • Bypassing per-frame systems calculations.
  • Bypassing per-frame audio code, or shutting off the entire audio subsystem.
  • Turning off any 2-d overlay UI.

You use DataRefEditor to turn off each part of your system and see how much framerate comes back.  If you get 5 ms of CPU time back from turning off your 2-d UI you can then say “wow, the UI should not be so CPU expensive” and you can then investigate.

X-Plane Supports Performance Analysis

The technic of shutting a system off and measuring the increase in performance is exactly how we perform performance analysis on X-Plane itself, and as a result X-Plane ships with a pile of “art controls” that disable various pieces of the simulator.

This article provides a big list of art controls you can use to disable parts of your aircraft and measure the performance improvement.

Here’s where object-kill datarefs come in: the “cost” of drawing an object is mostly inside X-Plane (in driver and OpenGL code) but also in the time spent calling dataref handlers that drive animation.  With an object-kill dataref, you can turn off your objects one at at time and see which ones consume a lot of CPU and GPU time.  If an object is found to be expensive, it might be worth an optimization pass in a 3-d editor, or some time spent to improve the scripts that control its datarefs.


Posted in Aircraft & Modeling, Development by | 4 Comments

Kill Your Objects

X-Plane 10.25r1 will go final soon (this week I think) and will be almost the same as 10.25b3.  There is one new feature that I am ‘squeezing’ into the RC at the last minute. Squeezing features into an RC at the last minute is not very good project management discipline, but in this case the feature is simple in its implementation and will allow custom airplane authors to improve framerate a bit.

The feature is “object-kill” – that is, the ability to completely disable (via a dataref) attached objects from being drawn.  Even when objects are hidden, they have CPU overhead; this features lets authors determine (in their plugins) which parts of the plane are not needed and completely remove them.  That big link explains how to use it and what it does.

How the Killers Kill Objects

X-Plane is, for the most part, not like a first-person shooter or racing game; those games have incredibly detail-rich environments, but they also have players that (mostly) stay on the ground, and environments with a lot of near objects blocking far views.  By comparison, with X-Plane, once you take off and climb to about 300 feet AGL, you can see nearly everything around you.

For this reason, X-Plane takes a fairly different strategy than shooters when it comes to figuring out which objects to draw, and which not to draw.

  • X-Plane only eliminates objects that are off-screen (behind you, off to the side), too far away, or too small due to distance.
  • First person shooting games try to eliminate objects that are occluded by nearby scenery.  (They also eliminate the off-screen and too-small objects.)  Here are two Wikipedia articles on the basic techniques.*

We don’t try to eliminate occluded objects because the cost of searching for them would hurt fps at all times; since a lot of the time almost no objects will be occluded, we skip the step, saving overhead.

First person shooters often pre-compute “hint” information to determine which objects can be hidden.  This is not possible for X-Plane because the loaded scenery may be a mix of several scenery packs; while we could pre-compute occlusion information for the global scenery, custom scenery might eliminate the occluders (using exclusion zones), rendering our pre-computed information wrong.

But there is one environment where X-Plane looks a lot more like a first person shooter: inside the virtual cockpit.  The VC is an environment where there is a ton of detail at high density and a lot of occlusion.

Here’s the problem: first person shooters often set up culling data ahead of time in their modeling environments; the engine only evaluates the precomputed hints.  But airplane scan be modeled in any number of programs: Blender 2.49, Blender 2.6, 3DS, ac3d, or any program that can create 3-d.

Therefore the intention of object-kill is to let authors do their own culling and simply tell X-Plane (via datarefs) the result.  These techniques could be portal-style occlusion techniques, computed automatically, or simple rules coded in a script.

Inside/Outside Views

The X-Plane 3-d cockpit camera is a completely free camera – you can walk out of the cockpit, through the cabin, out the door, and go look under your wings.  I think that this kind of ‘freedom to roam’ adds a nice element of ‘playability’ to X-Plane, but it also comes at a performance cost.  We do not provide separate “interior/exterior” objects – every object is drawn in both the interior and exterior views, because the views are fluid.  You can always look in the window from an exterior view, and you can always walk outside from an interior view.

If you need distinct inside/outside views to improve performance, you can use object-kill to implement this feature.  Simply write datarefs to determine when the view is ‘inside’ or ‘outside’ and wire up each object with a dataref to kill it.  Kill your interior views in exterior views and vice versa.

(See below for more subtle ways to optimize objects.)

How Would I Use This Feature?

I am not an aircraft author, so that’s a highly theoretical question, but here is how I would use this feature:

  1. I would wire each object up to its own custom dataref and turn each one off in DataRefEditor.  For each object, I would note the change in CPU and GPU usage.  From this I can determine which objects are actually expensive.
  2. For each object that is expensive, I would look at my model, and develop simple rules for when I can avoid drawing them.
  3. I would code some ‘predicates’ – that is, functions that tell me about the state of my objects.  The idea of predicates is to summarize a set of conditions in question form.
  4. I would then code these rules into simple plugin-based datarefs to hide the objects at the right times.

Here are some of the predicates I would look at:

  • Is the camera in the cockpit?  (This requires looking at the XYZ of the pilot’s head position and comparing it to a box I determine from my model, as well as the current view mode.)
  • Can the pilot see backward?  (This requires looking at the pilot’s head horizontal rotation.)
  • Is the cabin of the airplane visible?  (E.g. for planes with a cockpit door, is that door closed?)

Then I can easily write rules like:

  • “if the camera is in cockpit and (the pilot cannot see backward or the cabin is not visible) kill interior cabin.”
  • “if the pilot is in the cockpit and the pilot cannot see backward, kill the entire external model.”
  • “if the pilot is in the cockpit, kill any details underneath the aircraft (gear, gear door, baggage doors, etc.).”

Two last thoughts on performance tuning by removing objects:

  1. It make sense to spend more time tuning performance on the views that matter most.  Note that the above rules are all for the virtual cockpit.  The virtual cockpit is where users will spend most of their time in the plane, including hand-flying it, so performance matters.
  2. You need the most fps gains on the views that are slowest.  So if the virtual cockpit is slower than external views (which it almost always is) it makes sense to do more work to optimize the virtual cockpit.

* I wrote some very simple anti-portal culling code for X-Plane in an attempt to measure what kind of performance gains we might get.  The conclusion: not much.

The problem is that X-Plane heavily groups objects into large clusters so that it can submit them via hardware instancing.  When a lot of objects are visible, this optimization makes a big difference in performance – it can be a 10x improvement in speed.  But the large groups also mean that, at any given time, at least some part of a cluster is on screen, even when portals are used.

When I turned off the grouping, portal culling cut the object load in half (after some hacking the engine).  That’s a big win, but the grouping gives us 10x the object budget, so we hurt object performance by 10x, and then improved it by 2x – not a win in the end.

Posted in Aircraft & Modeling by | 8 Comments

X-Plane 10.22: LuaJIT Memory for Windows and Linux

There are a number of changes to how X-Plane 10.22 beta 1 handles memory for LuaJIT plugins.

Windows and Linux 64-bit: X-Plane Manages Memory

Previously, 64-bit Windows and Linux LuaJIT plugins had to allocate their own memory, and often they did not succeed.  64-bit LuaJIT can only use certain special areas* of memory; if, by the time a LuaJIT-based plugin loads, some other code has used all of that memory, then the LuaJIT plugin cannot operate.

With 10.22 beta 1, X-Plane pre-allocates as much low memory as it can and then provides it to LuaJIT plugins on demand.

This change should fix problems where LuaJIT-based plugins run out of memory, fail to load, etc. on Windows with lots of scenery packs and rendering settings cranked up.

If you ship a plugin that uses LuaJIT, make sure your plugin can use the memory provided by X-Plane.  The process for doing this was defined during the X-Plane 10.20 beta and has not changed, so plugins that are coded correctly will just work.

OS X 64-bit: Crash Fix

Previously for OS X, when a LuaJIT used up all available low memory that X-Plane had reserved, X-Plane would crash.  This was a bug in our code; X-Plane now correctly simply tells the plugin “sorry, we’re out of memory for you.”

I have said this before in forum posts and I will say it again: your plugin should not exhaust Lua memory! There is typically over 1 GB of LuaJIT memory available; if your plugin exhausts it all, your plugin is doing something wrong.

So it’s good that this won’t crash, but if there were plugins that were causing this crash, those plugins probably need to be carefully examined – their memory use was way too high!

New Stats to Monitor Memory Use

There are two new “stats” in DataRefEditor (pick the “show stats” sub-menu option) for Lua memory use: lua/total_bytes_alloc and lua/total_bytes_alloc_maximum.  The first one tells you how many bytes of memory all Lua plugins are using, the second shows the highest memory allocation ever recorded.  A few notes:

  • This only measures memory use provided by X-Plane.  So 32-bit plugins will show “0” for both, because in 32-bit plugins, X-Plane does not provide memory to Lua.
  • Lua is garbage-collected, meaning it allocates memory for a while, then periodically throws out unused stuff.  So it is normal to see this value slowly rise over time, then periodically drop down by quite a bit.  It is not normal to see these values increase indefinitely without ever dropping down.
  • If your 64-bit Windows plugin uses LuaJIT but registers “0” for lua/total_bytes_alloc, your plugin is not getting memory from X-Plane and is not working correctly; fix your plugin ASAP!
  • This memory includes allocations by Lua scripts.  It does not include memory for textures, sounds, and other “native” resources provided by SASL or Gizmo.  So you should not see a 4 MB allocation just because you made a 1024 x 1024 texture, for example.

* The lowest 2 GB of virtual memory, to be specific.  Most other code running in X-Plane (the sim itself, the OpenGL driver, OpenAL, the operating system, other plugins) can use any memory, but they tend to consume some of this “LuaJIT-friendly” memory during normal operations.  Thus X-Plane’s strategy is to pre-allocate the LuaJIT-friendly memory and reserve it only for LuaJIT use.

Posted in Aircraft, Development by | 11 Comments

X-Plane 10.22 Beta 1: Memory for Lua and Landing Gear

X-Plane 10.22 Beta 1 is available now (release notes, bug reports).  To get this beta you’ll need to check “Get New Betas” in the X-Plane 10 Installer’s update screen.

This is a very small bug fix patch; there will not be an art asset update, and we’re only including three fixes that we think are critical enough to release ASAP, as well as support for the latest Xavion iPad app.

I will comment on Lua memory allocation in a separate post.

Landing Gear Problems

Plane-Maker 10.21 has a bug: when you save your airplane, the weight distribution coefficients for landing gear are calculated incorrectly, causing the plane to tilt or lean on the runway.  Astute users noticed that resaving the plane in Plane-Maker 10.20 fixed the problem.

This bug is fixed in Plane-Maker 10.22; if your plane has “the leans”, just re-save it in Plane-Maker 10.22 and the problem should resolve itself.

This bug was always a bug in Plane-Maker, not in X-Plane itself; airplanes whose data was not saved incorrectly would fly correctly in 10.21, which is why it took a while for the bug report to get to us.

Copy Protection

First: let’s agree to disagree re: copy protection.  No one likes copy protection, and we can all agree that copy protection is always imperfect.  (That is, it never avoids annoying users completely and it never stops piracy completely.)  Users who buy products and the companies that sell them often disagree about where to draw the line between deterrence and annoyance.

So please: no rants about how awful DVDs are in the comments section.  The goal of this part of the post is to explain what we fixed so that users who have seen a known bug can have better situational awareness.

X-Plane 10 “remembers” that you have inserted X-Plane DVD 1 recently, so that you do not need to have the DVD constantly in the drive to fly.  Right now X-Plane needs to see DVD 1 (for each product you purchased) every seven days or so.

Every now and then we get a bug report from a user where the process of saving the DVD information fails; due to a bug in X-Plane 10.21 and earlier, when this process fails, the DVD would not enable scenery loading at all and the user interface would tell a global scenery user that a regional DVD was found.  This was very confusing and also annoying (since it stops paying customers from using the product).

The bug in X-Plane is fixed in 10.22; furthermore if the preference-saving process fails we now put up a message for the user to contact tech support; previously it was a small item in Log.txt.  If this preference-saving process fails, we want to know about it and fix it.  (So far the only cases we’ve seen are Hackintoshes with hardware configuration issues and one case of a borked network preferences file.)

Water, Water Eveywhere

There is a separate bug in the copy protection system that I couldn’t fix for 10.22; we’ll revisit this issue for 10.30.  The issue is this:

  • When X-Plane needs to see your DVD to get out of demo mode, it tells you after you have started your flight.
  • By that time you are on a runway that is all water.
  • When you insert the DVD, does not reload scenery; you have to go to another airport and then come back to your original airport to “force” a scenery reload.

This behavior is confusing – X-Plane says “now you can fly anywhere in the world” but where’s your scenery?  We get a fair number of tech support calls about this.  The problem is that if we reload scenery when the DVD is inserted and your airplane is on the runway (in water-world) then once scenery is reloaded your aircraft is underground and your aircraft is destroyed.  So a fair number of things need to change (e.g. when we check for the DVD, what we do when we find it) to fix this use case.  That’s too much change for 10.22 and will have to wait for 10.30.

Posted in Aircraft, News by | 10 Comments