Category: Development

Keyboard Mapping – seemed like a good idea at the time

X-Plane 860 introduces a fundamental change in the way the keyboard is handled in X-Plane.

Before X-Plane 860, keyboard keys are matched to their commands by looking at the character that is prodcued by typing.

For example, spot view is produced by the ‘@’ symbol. On a US keyboard that means shift-2. On an Italian keyboard, the @ symbol is shift + the ò key (ò on its own key, cool!).

But in X-Plane 860, the matching is done on the key itself, not the symbol you get when typing. In other words, the 2 key is the 2 key no matter what. So in X-plane 860, spot view is mapped to shift-2 and shift-2 will induce spot mode whether this gives you @ or ” when typing (on Italian keyboards, shift-2 gives the double-qoute).

One advantage of this method is that the keys stay in roughly the same place…the point of those strange punctuation keys for autopilot modes is that on a US keyboard they’re all top-of-the-keyboard functions. Now that the keyboard bindings are based on the number keys plus the shift key, this will be true on international keyboards too.

One disadvantage of the new system is that if there is no “primary” key for a symbol, international keyboards can’t use it. For example, ; is a key on a US keyboard, but is made by shifiting the , key on an Italian keyboard. So right now in beta 2 Italians can’t invoke free-view (ctrl-;) at all…if they type ctrl-shift-, they get, well, ctrl-shift-,. (Of coures, mapping free view to ctrl-shift-, in the keys file does work.)

For now please just keep in mind that 860 is a beta and is still a work in progress. In the long term once we get the quirks worked out, the new keyboard system offers a lot more mapping combinations, because everything can be mapped with any combination of modifier keys. No more running out of keyboard combinations!

Also for hackers, try X-Plane –cmnds=all to see a list of all possible command bindings in the sim.

Posted in Development by | 4 Comments

Using GLSL does not mean changing the system requirements!

X-Plane 860 uses GLSL pixel shaders. But this doesn’t mean you need any new hardware. It does mean you might need to update your drivers. Let’s break this down a little bit.

X-Plane never talks directly to your video card. It always talks to the video driver, a piece of software that acts as a translator between X-Plane and your video card. (That’s a gross simplification – video drivers do a lot of amazing things these days.)

Your video card has certain capabilities – different cards can do different tricks. The video driver tells X-Plane what tricks the video card can do.

So there are really four possibilities for any given trick:

  1. Your video card cannot do that trick. The video driver will tell X-Plane “I can’t do it.”
  2. Your video card can do that trick. The video driver will tell X-plane “I can do it”.
  3. Your video card can do the trick, but the driver is old and will tell X-Plane “I can’t do it” because the driver doesn’t realize what the card can do. (This can happen because the video driver you use might come with your operating system, before you bought the new video card.)
  4. Your video card cando the trick, but the driver has a bug. The driver will tell X-Plane “I can do it”, but when X-Plane says “go and do it”, the video driver will crash your whole computer. This happens when drivers are buggy and can usually be fixed by getting newer drivers.

Something to note about this last case – we only crash if X-Plane actually says “go and do it”. So when we release a new version of X-Plane that utilizes new video driver tricks…

  • Some users have cards that can’t do it and will see no change.
  • Some users have cards that can do it, so they see the new feature.
  • Some users have cards that can do it but old drivers and see no change.
  • Some users have buggy drivers and see a crash for the first time.

GLSL shaders is a certain way to use the pixel shaders built into some cards. (GLSL is an interface and language to talk to those shaders.)

GLSL shaders are definitely not required for X-Plane 860. If you don’t have them, X-Plane will run the way it always did.

But if your drivers are buggy and crash when GLSL shaders are used, you will need a software update to get good drivers. (There is a way out of this…if you really can’t get a driver fix, there are command-line options that will tell X-Plane “don’t use this feature even if the card has it”.)

Posted in Development by | 6 Comments

Virtual Memory – a precious resource?

Traditionally it always has been real memory – system RAM or VRAM – that’s been most important to the flying equation. But recently virtual memory has been a scarce resource. What happened?

To understand this situation, consider X-Plane 6 vs 8. Back in the X-Plane 6 days, a typical system might have 256 MB of system RAM, 16 MB of VRAM, and 2 GB of virtual memory* for X-Plane. That’s a ratio of 8:1 virtual to real RAM and 128:1 virtual to VRAM.

These ratios are actually pretty useful. At any given time only part of the loaded scenery is visible, so only part of it needs to be in real RAM/VRAM. So having that extra virtual memory lets us load a big chunk of scenery at a time, rather than having a lot of complex details to load tiny bits of scenery.

Today’s computers are a bit different. 2 GB of RAM is not uncommon…that’d be a ratio of 1:1! And most gamers cards have 256 MB of VRAM now for an 8:1 ratio with VRAM. 512 MB cards are coming out and nVidia’s monstrous 8800GTX comes with (gasp) 768 MB of VRAM! Insanity!

The problem is: RAM and VRAM are getting larger, but virtual memory is not! This means the ability to have the part of the scenery you don’t see in virtual memory is getting more and more difficult.

Why can’t we get more virtual memory? Well, the problem is to get more virtual memory we need 64-bit CPUs, 64-bit operating systems, 64-bit drivers, and 64-bit applications. That’s a lot of parts that all need to be 64 bit and means a full computer upgrade and motherboard upgrade. Of the 5 machines Apple sells right now, only one is 64-bit, so even some of today’s fastest machines aren’t 64 bit. That’s slow adoption.

So in the meantime we’re adjusting X-Plane’s strategy to deal with increasingly limited virtual memory. Back in X-Plane 6 it was acceptable to leave all objects their textures cached in virtual memory for later use (which sped up reloading of scenery).

X-Plane 860 (coming soon to a beta near you) will change this – unused textures and objects will be fully purged, which will hopefully address the problem of running out of virtual memory during long flights over lots of different custom scenery.

* 2 GB? Well, technically an application can have 4 GB of virtual memory, but the OS keeps some for itself. Some OSes take 2 and leave 2, some take 1 and leave 3, but even if we had all 4 GB of virtual memory for application use (and we don’t – the graphics driver steals some too) we’ll have 4 GB machines soon, so virtual memory is disappearing.

Posted in Development by | 6 Comments

DSF Object Order is Not Draw Order

The order objects are listed in a DSF file (either the OBJ definitions or the actual OBJ instances) is not the same as the order X-Plane will draw them! X-Plane will change the order to maximize frame-rate, and the way it organizes them has changed in 850 (and will change again in futur versions).

Until X-Plane 850 there was no way to control the order of objects (although some packages do rely on X-Plane 840’s behavior and now look funny in 850). But with 850 there is a clean way to control draw order that will work well into the future.

Starting with X-Plane 850, there is a new command ATTR_layer_group…it let’s you override what part of the rendering process your object is drawn in, which is useful in a number of cases. Here’s how it works:

X-Plane draws the scenery in a series of steps or “layer groups”. Because of the way OpenGL transparency and polygon-offset affect Z buffering, X-Plane must draw the terrain first, all decals over the terrain second, 3-d buildings third, and anything translucent (clouds, smoke puffs, etc.) last. Layer groups organize all of the scenery into these catagories.

Objects are normally drawn in the “objects” layer group, which is intended for 3-d buildings, static airplanes, jetways, and anything else you might model with an OBJ. However ATTR_layer_group will let you specify that some objects be drawn earlier or later than others.

The command’s syntax is:

ATTR_layer_group objects 1

Where the name (“objects”, but others are allowed – see the OBJ spec) specifies a group, and the number makes the object be drawn after (positive numbers) or before (negative numbers). Objects with the same group and number are drawn together (in an unspecified order), but X-Plane goes by the numbers.

So for example if you want to ensure that a transparent hanger is drawn after a static plane, use ATTR_layer_group objects 1 on the hanger to draw it after all other objects. To draw some apron lines before the terminal, use ATTR_layer_group objects -1 to draw before buildings.

A few other tips:

  • Try to use as few offsets as possible – e.g. try to put all “draw last” objects into the group objects/1 – rather than using a different number for each.
  • Avoid using layer groups when they are not needed – they inhibit X-Plane from optimizing framerate.
  • If you do not use a layer group, but do use polygon offset, X-Plane sets the layer group to objects with a negative number. This is inhibited when you specify the layer group yourself, so be sure to use a negative offset layer group for polygon offset!
  • Try to organize your textures so that one texture is not used in multiple layer groups. For example, if you have translucent buildings that must be drawn later, group them in their own texture.
  • Related – try to keep polygon-offset geometry (pavement markings) in their own texture and objects. Share one texture for all markings, but don’t put the markings and object together.
Posted in Development, Scenery by | Comments Off on DSF Object Order is Not Draw Order

Pixel Shaders and Scenery

X-Plane 850 was the first version of X-Plane to start employing pixel shaders — they make the new hardware-accelerated lights possible. Our next step will be to start converting existing OpenGL code over to pixel shaders.

DISCLAIMER: these are my predictions for the future of X-Plane, not promises or guarantees. Do not base your purchasing decisions on what I say, and do not come back quoting this blog saying “you promised X”. This is a statement of our intentions, but we cannot predict what limitations we could hit in the future, such as graphics problems we did not anticipate!

Right now X-Plane works based on individual selection of features – that is, each separate part of X-Plane examines our summary of a driver’s capabilities and does what it can based on those capabilities. The result is good for users in that X-Plane’s visual features turn off one-by-one as a card becomes less capable, leaving as much eye candy as possible.

What’s bad about this technique is that there are huge combinations of possible configurations, more than we can test individually, so we sometimes have bugs that show up only with a peculiar combination. Since most of the code that uses this driver spec has been relatively stable we haven’t seen a lot of bugs due to this in 830-850, but I definitely fixed a lot of configuration-related OpenGL bugs in the early v8 run when the rendering engine was new.

Pixel shaders (we use GLSL for the OpenGL nerds out there) will change that; the OpenGL shader spec is powerful enough that if we have it, we can do everything we want. So the new world of shaders will make X-Plane’s visuals be either “you have it” or “you don’t”. This definitely helps us for testing – we can test the shader version, the legacy version, and that’s it.

Remember the dark old days of X-Plane 6 when GeForce 4 MX’s had two pixel shaders, but GeForce 4 Ti’s had 4, and ATI cards had 2,3,4 or 6? Fortunately we’re past that. The last three generations of video cards have pixel shaders and every card with shaders has 16 texture units, which is more tha enough for us.

Here are the cards that will support shaders, at leaset I think from the specs posted on the web (all suffixes have equal pixel shader capabilities – the suffix usually is about the speed of the card):

  • ATI Radeon 9500-9800.
  • ATI Radeon X300-x850.
  • ATI Radeon X1000-X1900.
  • nVidia GeForce 5200-7900.
  • Any card that hasn’t been released yet will surely support shaders.

Here are the cards that X-Plane will run on but don’t support shaders:

  • ATI Radeon 7000-8500.
  • GeForce 2,3, and 4.
  • Intel GMA950 (and probably a few other Intel chipsets I don’t know abot).

I don’t know about the old Rage 128 or original GeForce 256 – technically they probably meet minimum requirement, but they’re so underpowered you wouldn’t want to run X-Plane 8 on them. Also I don’t think they ever came in 16 MB variants. I don’t know about Matrox’s compatibility.

To use pixel shaders you will also need reasonably new and modern drivers. Both ATI and nVidia ship modern drivers that support shaders fully, but very often what you get on your machine or with Windows XP does not. So if you have a card that supports shaders but don’t see them, it might be time to check the vendor website.

For Mac users Apple shipped full pixel shader support in 10.4. So: if you have a card with pixel shaders and you use 10.3.9 you should upgrade to either 10.4 now or 10.5 when it comes out! Otherwise x-Plane will not have the right driver to utilize your hardware! An X850 or 7300 on OS 9 is definitely a waste of potential. (X-Plane 8.50 already has features that are only available to pixel-shader users on 10.4!)

I am excited about pixel shaders because we’ll be able to finally fix some of the bugs we just couldn’t fix before. For example, when you turn on the landing light, X-Plane’s ambient lighting levels drop to pitch black. With pixel shaders we will finally have the capability to fix this!

Posted in Development by | 2 Comments

High Altitude Object Placement

Jonathan Harris sent me a test package showing how that 850 betas misplace objects at high altitude. The pyramid is 1000 meters up, and the object should be right on top of it. (Mind you DSF has a little bit of rounding error; the amount depends on the smartness of the DSF writer. DSF2Text isn’t that smart, so I can’t promise it’s better than half a meter anyway.)

The problem is that X-Plane figures out how high the ground is based on a cartesian coordinate system, not based on true round world math. This is not a problem as long as the ground and the point you are looking at the ground from are not that far apart vertically. (This is why this does not represent a physics bug; as the plane gets closer to the ground, the error in terrain height, which is also a function of slope and is thus probably zero on a good runway, gets smaller and smaller until we are dead-on at the instant the wheels touch down.)

The problem is that DSF objects do not have elevation specified in the DSF file; they are “dropped” onto the terrain. In order to drop them and know their elevation, we must have their location in cartesian coordinates, and that requires knowing their elevation. Doh! A paradox.

X-Plane 850 used to simply pick an elevation of 0 to start out the process. This leads to a lot of error at high elevation areas away from the center of mapped scenery. X-Plane 850RC4 “solves” this problem (temporarily until I can come up with something better) by dropping the object twice. The second drop is done using the height of the first drop to redo the conversion from lat-lon to cartesian coordinates. Since the first drop is only off by a little bit (a few meters usually) the error introduced in the second drop is very little.

Here’s a comparison of placement in 850RC3 and RC4 (coming to a web page near you soon I hope). The object is 5 meters tall and 1 meter across. While RC4 is still not perfect, the error should be small enough that you won’t have to hack your scenery package to get good object placement.

Posted in Development by | Comments Off on High Altitude Object Placement

That was so fun – let’s do it again!

One of the less fun aspects of X-Plane 8.50 was dealing with driver bugs. The basic problem is that PC hardware vendors have a relatively slow cycle for updating the software they bundle with their machines; while the companies that write drivers (ATI and nVidia) have a pretty high latency from when they first ship a card to when the driver support is to the level that X-Plane needs.

The clearest case of this I saw during 8.50 was in the case of PC users with “1.5”*-type ATI drivers. These drivers will cause the terrain textures to swim when hardware-accelerated runway lights are used. Upgrading to “2.0”-type ATI drivers fix the bug. A lot of users were just fine with the 1.5 drivers that came with their machines until X-Plane 8.50 came out, and have only now updated.

8.50 started using pixel shaders; hence the need for newer drivers with bug-free pixel-shader support. But in the future we’re going to move from “DSP”-type shaders (that is, shaders written in a very low level language) to shaders writen in a GLSL, a high level abstract way to write shaders.

My fear is that this will induce a second round of “update your driver” for PC and Linux users. (Apple ships new drivers with system update, so users of the current Mac OS can usually just run the updater if it isn’t set to update automatically.) But I think it’s probably for the best that people use the latest drivers, as ATI and nVidia put software changes in the drivers that increase the throughput of the graphics card, through smarter use of the hardware.

The one group that is really stuck is Macintosh 10.3 users; Apple doesn’t provide driver updates to older operating systems. So for example users with 10.3.9 and an ATI card with pixel shaders can’t get hardware-accelerated texture lights without buying OS X 10.4. I would go as far as saying that in the future if you have a pixel-shader card it might be worth buying an OS upgrade to unlock the driver support needed to use these features.

Why move to GLSL (and require more driver updates)? In the long term it will provide superior framerate. The current shaders we have now are written in a very low level language, that roughly matches the technology of the first generation pixel-shader cards (Radeon 9700 and GeForce “FX” series). As cards gain new capabilities, Austin and I can’t take advantage of the new capabilities using this old language.

GLSL however is a higher level language; when we write a shader in GLSL, the graphics driver translates our shader into code specific to the video card at hand when X-Plane starts. This means that if the video card has some new magic trick it can do, the driver can take advantage of that trick as it translates our shader, resulting in higher framerate. And everyone loves higher framerate. 🙂

EDIT: who will be able to use GLSL? Basically any card that has hardware-based pixel shaders** from ATI or nVidia will support GLSL-based shaders if you have a modern enough driver. So if you are seeing hardware-accelerated runway lights in 850 then the GLSL changeover shouldn’t cause any more fuss than a driver upgrade if you haven’t done one rcently.

Also I should say that if I sound like I am dumping on ATI and nVidia for driver bugs, I shouldn’t be; video cards are amazingly powerful, the drivers are very complex, and the technology jumps by huge amounts in a very short time period. I believe the level of driver bugginess we see is a function of fast technology rollout and not the competence of the driver teams, who I am sure are working as hard as they can.

So we, the developers who write programs that use these cards, and you, the users who enjoy these cards, have to ask whether we’d rather have faster framerate and more eye candy or less chaos from our drivers.

*ATI drivers are numbered by ATI to match ATI’s internal versioning scheme. But X-Plane can’t really see what the ATI driver version number is (e.g. the catalyst version number). So when I say 1.5 or 2.0 I am really talking about the OpenGL specification number that the driver implements. ATI implements newer specs in newer drivers, so we can tell that an ATI driver that supports the 2.0 spec is newer than an ATI driver that supports teh 1.5 spec.

So while I have no idea of either which versions of the ATI drivers had this bug or which version it was fixed in, but we can tell from an X-Plane Log.txt file whether the drivers are going to have this bug.

**Hardware-accelerated shaders? Well, previously I’ve described a graphics card as either having shaders or not, but this isn’t totally accurate. Technically a shader can include a non-programmable shader. Furthermore the driver can present software emulation of a shader. For example, the Intel GMA950 has programmable pixel shaders in hardware. On a Mac the driver reports that it has vertex shaders, but the vertex shadings is actually done by the CPU. (This isn’t unreasonable — all vertex processing is done by the CPU on the GMA950.)

So really when we talk about “cards with shaders” we mean: any nVidia card with a number of 5000 or higher (plus some Quadros, sorry I don’t know the numbres on those), and any ATI card with a number of 9500 or higher, and any ATI card with an “X” in it, e.g. X850. At this point we’ve had shaders in cards for 3 generations, so if you buy a new computer and it has an ATI or nVidia graphics card, it should have fully programmable hardware shaders.

Of course now not all shaders are equal; the newest cards have even more powerful shaders. But this isn’t likely to matter a whole lot to X-Plane for a while. But generally I’d recommend buying the mid-range latest generation cards over high-end obsolete cards at this point.

Posted in Development by | Comments Off on That was so fun – let’s do it again!

GIF is Dead!

(This one’s gonna be a little bit political I fear. More scenery-related stuff in a few days!)

The last software patent on GIF expired October 1st 2006. It’s very rare that I agree with Richard Stallman on much, but I think he presents some strong arguments against software patents in this speech.

X-Plane never used GIF; we’ve used PNG as our main graphics format for a while now…here‘s a history of PNG’s development, relating to the problem with GIF being patented.

A few comments of my own:

  • One problem with software patents is the “landmine” effect. There’s no way to know as a programmer when we’ve violated a software patent. (Try searching the patent database for an hour or so and I think you will agree with me on this.)
  • The bar for non-obvious patents is completely miscalibrated. Software engineering is all about building black boxes out of past work and rearranging them to do new things. Allowing the arrangement of past technologies to be patentable is like allowing a mason to patent a particular stacking of bricks; to most masons it should be obvious how to stack bricks for a certain job, and any good programmer should know how to generalize past ideas to solve new problems. This isn’t invention, it’s implementation!
  • Patents aren’t based on natural law and human rights, they’re based on fostering creativity. To this end patents are the exact wrong solution for software, where having basic interoperable technologies be free and cheap is good for common infrastructure. Software patents are like someone being able to charge a toll for driving at exactly 55 miles an hour. We want everyone driving the same speed because it’s good for the traffic system; similarly we want people to all use the same file formats because it makes all programs more useful.

There are two cases of software patents I can imagine: short-lived ideas that will be obsolete by the time the patent is ever defended; these patents at best serve to help one company beat another over the head with lawyers; I think this is comparable to a SLAPP lawsuit.

The other case is when the idea is truly useful for its entire lifetime (see GIF, which became the only way to put transparent graphics on the web for a while). In this case the result is a stifling of interoperability and innovation and the patent is to the detriment of the industry and all of its users.

To this end I see libpng as a perfect success: a well-designed file format that’s free of patents implemented in an easy-to-use high performance library that’s free (X11/MIT license). This encourages and makes it easy for everyone to use PNGs which makes all programs work better. Would we be better off if Austin and I had to invent a proprietary image format (with our own inferior compression) because the major formats were patented?

(Would it be feasable to license such a format? I don’t think so – see Stallman’s comments on the number of components in a software program vs the cost of licensing.)

Posted in Development by | Comments Off on GIF is Dead!

Stupid Laptop Tricks

First a disclaimer: DO NOT SHAKE YOUR LAPTOP!!! If you shake or thrash your laptop and kill yor hard drive, do not blame me. Laptops are delicate complex electronic devices and should not be jostled, beaten, dropped, abused, or tossed around.

Okay with that out of the way, a stupid plugin trick. This is only for Mac users with a MacBook, MacBook Pro, or possibly some of the newer G4 laptops (although I haven’t tested on these).

First, download “SMSHack.xpl“. Unzip it and drag the .xpl file into your plugins folder.

Start X-Plane. In an external view, rotate your laptop about 45 degrees to the left and right and 45 degrees up and back. this calibrates “SMSHack” to know the orientation of your computer. You must do this calibration every time you use SMSHack.

Then: fly using your laptop like a yoke. Roll your laptop to roll the plane, and pitch the laptop to climb and descend. Disable the plugin to get normal joystick control back.

How it works: I use a library called Unimotion. (Hrm..it’s LGPL…well, source is here then.) Unimotion reads the SMS (sudden motion sensors) on modern Mac laptops. These are three accelerometers that the Macintosh can use to detect it has been dropped; the operating system will try to park the hard drive heads to prevent a disk failure on impact.

Because gravity is a constant acceleration on the laptop, the accelerometers can be used to detemrine the roll and pitch of the laptop. This plugin simply shovels the relative accelerations into the joystick deflections.

Posted in Development by | 6 Comments

A Tale of Three Operating Systems

In a vain and foolish attempt to prove that I am the uber-nerd, I have configured my MacBook Pro to boot Mac OS X 10.4, Windows XP Home SP2, and Ubuntu Linux 6.06. It took a while to get everything set up, but all three now run X-Plane with hardware acceleration.

This provides a unique chance to compare the performance of the sim varying old operating-system factors (the OS, the drivers, and the compiler). The machine is a 2.16 ghz DuCore MacBook Pro with 2 GB of RAM and a 256 MB ATI X1600 card.

So without further delay, here are the numbers. Speed is in fps for frame-rate tests 1-3 (1 is lowest settings, 3 is very very aggressive). Each set of fps is for panel view, forward-no-HUD view, and the same view paused. Load times are in seconds for the KSBD demo DSF. The second load time is to reload the same scenery – the times are much faster on all 3 OSes because of the disk cache.

Drivers are not tweaked; this is simply the ATI binary drivers for Linux, whatever Apple ships in BootCamp (some 2.0 series ATI drivers) for Windows, and the 10.4.8 drivers for Mac, none tweaked in any way at the OS/control panel level. For Linux I disabled VBOs because they cause graphic corruption in some cases and slow frame-rate. This is probably a Linux/ATI driver bug.

PLATFORM      Mac         WIN        LINUX
Load/Reload 2.77/1.31 5.02/1.33 3.05/1.04
FPS Test 1 65/71/80 64/69/88 56/62/62
FPS Test 2 49/55/54 50/56/56 34/37/37
FPS Test 3 15/15/15 16/16/16 4/4/4

Analysis:

  • The Mac has the fastest disk performance; both Mac and Linux are significantly faster than Windows in raw loading. For reloading a file all operating systems are about the same, but it’s the load-without-cache case that counts.
  • Windows has the highest frame-rates; slightly faster than Mac but quite a bit more than Linux. The lack of safe VBOs on Linux could account for this.
  • In the case where the fps didn’t rise when the sim was paused, the limitation is with the video card – not surprising for tests 2 and 3 where there’s a lot of antialiasing, anisotropic filtering, and objects.

Tomorrow I’ll blog about how the fps test itself can be used.

Posted in Development by | 6 Comments