Apple owns the US premium retail PC market

hardware, OS X, Tech 18 Comments

apple_logoThis was pretty interesting; CNet reports that according to NPD stats, Apple has 91% of the retail PC sales in the US above $1,000.

Now, let’s add the caveats here:

  • That’s retail PCs. Of course, loads of people build their (desktop) PCs from OEM parts rather than buying a prebuilt machine, so it’s safe to say that these sales are almost all going to be laptops, where Apple particularly shines.
  • Also, these are primarily going to be consumer purchases, because businesses tend to buy in bulk and not at retail (excluding the smaller businesses) – again Apple is far more popular in the consumer space than in business (barring the iPhone).
  • The above $1,000 range is a minority of all sales; a majority of people buy cheap rubbish ;)
  • This is only the US, where Apple seems more popular

So, the headline isn’t quite as accurate in its crushing assessment as the wholesome reality, but even so it’s pretty impressive. When it comes to laptops, I always buy quality because I’ve been disappointed many times by machines that looked good on paper but turned out to be poorly constructed, poorly designed, and had all kinds of heat / battery life / general robustness issues, which led me to always buy from the ‘premium’ range in the last 6 years or so. At first that was the likes of the top-end Sonys, but after being convinced to try a MacBook Pro, I’ve been so pleased with the overall construction / design and the ability to use OS X as well as Windows that I’m very unlikely to buy anything else next time (my next hardware revision will be 2010, I generally switch every 3 years, which is reasonable if you buy something decent to begin with).

The talk now is about whether Apple will start making a netbook, to compete at the cheaper end of the market. Personally I don’t care – I quit buying cheap laptops ages ago, I don’t think it really ends up being cheaper in the long run. Powerful and cheap machines tend to be poorly built – I’ve burned through (literally in a couple of cases!) far too many laptops that couldn’t handle their power actually being used regularly, or which developed problems because the build quality was naff. Cheap machines with decent construction but lower spec (e.g. netbooks) just need upgrading faster if you have my sort of needs, or are just a supplement to a ‘real’ machine, either of which costs more in aggregate, and the resale value when you do upgrade is usually not even worth considering. In the round, buying a premium laptop relatively infrequently works far better for me, and as such Apple already provide what I want. YMMV :)

WWDC 09 – Apple gets aggressive, in a fairly relaxed way

OS X, Tech 6 Comments

In the grand scheme of things, nothing really very surprising was announced at the WWDC 09 keynote; sure, we got a few hardware revisions and some more specific details on the next version of OS X, but there wasn’t anything singularly shattering about it. And yet, when taken as a whole, I think it was one of the most important WWDC’s yet.

iPhone 3GS

A speed increase, more memory, better battery life, better camera, addition of a compass so it can know which direction you’re facing as well as where you are. All fairly minor but no doubt welcome changes. But, in my view perhaps the more important fact is that following the release, the previous standard 3G revisions are being sold off for $99; I think that’s going to make a big difference in the number of people taking up the iPhone. I didn’t pick one up because of the price (especially because we get screwed on it over here, since we have no O2 to subsidise it), but had it been a $99 base price – well, that’s a lot easier. Being able to offer an iPhone to a wider range of buyers is certain to give more steam to the iPhone popularity train.

MacBook Pro

More speed & RAM, FireWire 800 is back (no use to me, but some people missed it), SD card slots are in, and perhaps more importantly, Lithium-polymer battery tech is in, for up to 7 hours on the go. Sweet. Interestingly, the entry-level MacBook is now replaced by the 13-inch MacBook Pro, with the same overall design but just lower specs. This allowed Apple to claim that the MacBook Pros now start cheaper, but really they don’t – the 15 inch (the one you’d really want to start at as a power user) is exactly the same price as before. [edit]Actually, it has dropped in price, but back to the same price as the 15″ MBP was in 2007, when I last bought one. 2008′s unibody design came with a price increase, so this decrease puts it back to how it was, hence my confusion.[/edit] But still, a faster chip, double the memory and bigger HD are welcome for the same price; I’m glad I didn’t buy a unibody yet, but I’ll definitely be tempted by the new ones.

The MacBook Air however did get a set of serious price cuts; they’re impractical for me still, despite being sexy as hell, but I’m sure people that don’t need so much local power and who desire sleek looks will be very happy.

OS X

We already knew that Snow Leopard would be basically a leaner, meaner version of Leopard with go-faster stripes and a few feature tweaks. The big announcement was that Apple would be releasing the upgrade for a mere $29 (or $49 for the multi-machine family pack), which was very well received. That basically makes it a no-brainer for all users, I know I’ll be upgrading soon after launch.

Most importantly, it’s a big contrast to the price that Microsoft want to charge for the Windows 7 upgrade, which contains roughly the same degree of change over Vista as Snow Leopard has over Leopard (although Leopard is a more efficient base than Vista is – does that make W7 worth more as an upgrade?). It’s rumoured that a Home Premium upgrade for W7 will be around $50, and a Professional upgrade about $100. Of course, OS X has no ‘graduations’ like Windows has, where you don’t get everything in the OS unless you buy an expensive ‘Ultimate’ version – OS X is just OS X (personally, that lack of fannying about with variable feature sets is attractive to me as a customer).  This is an obvious attempt to undermine Microsoft’s claim to be the ‘value’ player in the OS market, and frankly, it’s a good argument. Of course, you still can’t buy cheap-and-cheerful hardware to run OS X on like you can with Windows, but when I shell out $100 per machine for my Windows 7 Pro upgrade but only $29, or $49 for up to 5 Snow Leopard upgrades, hell yeah I’m going to notice the difference.

So, I think despite the lack of shattering announcements, this was an important WWDC for Apple, a consolidation move which in many ways is more important. Despite the often fiercely held opinions of people who haven’t even used them, Apple products are generally pretty damn good, and earn brand loyalty for a reason. Making them more accessible can only lead to more people trying them, and perhaps coming to conclusions for themselves, rather than just writing them off based on what they’ve heard from other people who haven’t used them either.  ;)

Homeless Frank & Laptop Hunters

OS X, Personal, Tech, Windows 10 Comments

It’s always fun to watch Apple and Microsoft slug it out in the advertising space – here in the UK we mostly have to do this via YouTube, since apart from a short stint of amusing Mitchell and Webb Apple ads and those pretty bland “I’m A PC” ripostes, we don’t really see the front-line assaults which take place on US TV screens.

So I hear that MS have a new set of ads out, where “regular” people go and look for a laptop, whereby they look at the Mac and say “whoah, far too expensive!” and then go and buy a Dell instead. Fair enough, the 3rd party PC market certainly gives you a wider choice of blending specifications than Apple does – in practice, Macs aren’t actually much different in price to a similarly specced PC, it’s just that all the components are generally of similar ‘grade’ – so you can’t cut corners to save money like buying something with a big screen but a crappy GPU, or a large HD with a slow motherboard, or a fast CPU but crappy battery life.  Of course, many people don’t realise they’re making these sacrifices and just look at the price – but if you do know what you’re doing, you can tailor a machine closer to your needs. Anyway, I enjoyed the “Homeless Frank” spoof of these new ads:

A couple of years ago I would have made the same arguments against the Mac that MS makes with it’s Laptop Hunter series; and indeed I did, when a Mac-owning friend tried to convince me to buy one, despite being a .Net guru (who now works for Microsoft!). However, now that I’ve owned a Mac for almost 2 years, I feel completely different – in a laptop at least, I’m very willing to sacrifice a little configuration flexibility in favour of having a device that is of uniformly good quality, and is nice to use. After all, laptops are always compromised in terms of upgradability once you’ve bought them, so it’s generally better to buy something decent from the outset anyway.

I know that buying a Mac laptop is going to encourage me to spend a little more money than I otherwise might get away with. But, what I get for that is a really nice device, that has the added bonus of being able to run OS X as well as Windows. I still use Windows every day, almost exclusively because of Visual Studio these days (and some games) since everything else I use runs on the Mac too anyway, but running both Windows and OS X on the same machine merely serves to make me love OS X more, despite still being a newbie with it in many ways. Windows is fine to use and all, but there’s something about the way OS X just gets out of the way, doesn’t pester me with stupid warnings all the time, doesn’t need a virus scanner to slow it down, allows me to unmount my USB drives without hunting down every Explorer window that is using it first, and countless other little things that have slowly endeared me to it despite being a total skeptic to begin with. I’m a technical guy by nature, but even I can appreciate technology that doesn’t waste my time with trivial stuff I don’t want to care about – and at the end of the day Windows (and Linux) still feels like it’s designed for “PC users”, whilst OS X feels like it’s designed for people, specifically people with stuff to do other than worrying about keeping the computer happy. The day that XCode equals Visual Studio in functionality (it’s not far off, but it’s not there yet), and I can run Steam on OS X, is the day I might seriously consider not using Windows on a daily basis anymore. But, we’ll see whether Windows 7 changes that view.

Milestones

Business, OS X, Personal, Travel 7 Comments

I’m the kind of person who likes to keep busy; not in a ‘mad about DIY / the garden’ kind of way that tends to be the most socially acceptable form of being a ‘project oriented person’, but I always have a bunch of things on the go and never seem to have enough time to do them all. I’m always ‘working’ evenings & weekends, but a lot of the time I really don’t think of it as work, because a large portion of the time I’m doing exactly what I want to do.

If you’re anything like me you’ve had difficulty explaining to your wife / significant other that in our kind of world, there’s really no discrete black-and-white transition between ‘work’ and ‘not work’ that starts at 9am and ends at 5pm every day like clockwork. In fact there are a multitude of subtle levels ranging from ‘definitely work’ (e.g. something I don’t particularly want to do but someone has paid me to do it), to ‘not really work at all’ (e.g. having fun with technology that as a spin-off might help make a living now or later). Unfortunately these subtle graduations are invisible to the casual observer, often leading to discussions which begin with ‘You’re working again!’, ‘Not really…’, and from then on get complicated.

In the end, it’s probably not a solvable problem, but one thing that does help is taking the odd break, where you at least pretend not to think about what others would deem ‘work’ for a while. Holidays are obvious candidates, but also a good trigger for maybe taking a weekend off or something is recognising a milestone, or a cluster of milestones.

OgreSpeedTree and OgreSpeedGrass emerged from beta this morning, with official 1.0 versions being released. I’m pretty damn pleased with the result, and that’s a fairly unusual situation; I normally have a list of things as long as my arm that I consider ‘unfinished’, but in this case I’m very content with stamping a 1.0 badge on them. My attention can now switch to finalising Ogre 1.6, which is currently at the Release Candidate stage.

It’s also 2 years since I made the decision to give up having a regular day job and try my luck as a free agent / start-up. My initial measure of success was not to go broke (either personally or bankrupting the company) in the first 2 years, and I’m pleased to say that hasn’t happened. It’s certainly had ups and downs, and probably given my prior senior tech position I’ve undoubtedly earned less personally as a result, but the company has still grown, I’m still paying myself a wage that isn’t too insulting, and the benefits have easily compensated for that. Besides the flexibility and the satisfaction of knowing I’ve found and earned every penny I’ve made (which somehow makes the money feel more valuable than a guaranteed monthly paycheck), it’s been good for my personal development to mix it up a bit. And most importantly, I’m not bored :)

It’s also almost 8 years ago that I wrote this fateful message in my (very old, very manual) blog:

18th October 2000: Exam done! Work on OGRE will restart soon. First, web site revamp to be done.”

Inauspicious, but that was the seed – the time when OGRE as we know it swung into full development and started this whole crazy sequence of events off; if I’d known the significance of it at the time, I wonder whether it would have affected how I did things?

Laozi was right when he said “A journey of a thousand miles begins with a single step.”. Those words motivate me to this day – that no matter how big or challenging something looks, the most important thing is to start. My experience certainly tells me that genius and raw talent / ability is often not the most important factor when it comes to achieving things, it’s usually more about taking that first step, and having the tenacity or pure bloody-mindedness to keep going for as long as it takes. That’s particularly good for me since even if I might not be as smart as some, I’m probably more stubborn. :) And that in turn feeds back into what I was talking about at the start of this post.

But, stopping occasionally to admire the view is good too :) Maybe I’ll do that this weekend.

Parallel-split Shadow Maps are cool

Development, OGRE, OS X, Uncategorized 3 Comments

OgreSpeedTree with PSSMWe’re on the final home straight for Ogre 1.6 (aka Shoggoth), which should hit RC1 next week. One of the final features I wanted to squeeze in was support for Parallel-split Shadow Maps (PSSM), which uses multiple shadow maps per light in a hierarchical fashion to improve the quality while keeping the size down, particularly in outdoor scenes using global directional light. If you’ve played Assassin’s Creed, you will have seen this technique in action already.

For example, the screenshot on the right there is using 3 shadow maps for the single directional light, the closest one being 1024×1024, and the other two being 512×512 – together they are 38% of the size of a single 2048×2048 shadow map and yet provide greater detail. The 3 shadow textures are displayed for debug purposes on the right – notice that all 3 are using LiSPSM projection to bias the texture precision toward the camera which also helps. If you look really closely on the full resolution shot, you can see the transition from the highest resolution shadow map to the second shadow map about halfway up the screen, it changes near the top of the closest tree shadow. It’s quite hard to see though, which is kinda the point :)

One of the challenges with supporting PSSM is that Ogre had previously assumed that there is a 1:1 mapping between lights and shadow maps, which clearly had to be overcome – this limitation also prevented easy use of dual parabaloid and full cubic shadow maps for point lights of course. It was one of those things that had been languishing on my TODO for a while, begging me to find some time for it, and that’s where it still was until Pang Lih-Hern (aka lf3thn4d) from Malaysia came along and did it for me :) What a star! His initial patch allowed multiple shadow textures per light in a very sensible way, and he then implemented a PSSM facility on top of that, via our pluggable ShadowCameraSetup system (which he also extended in the patch to be aware of shadow map iteration). I adapted the PSSM code from his demo to be a little more flexible (it now handles any number of splits, and a more flexible split configuration) , so that setting it up goes something like this (simple projected shadows here, depth shadowmaps are also possible of course but let’s not overcomplicate it):


float shadowFarDistance = 3000;
mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
mSceneMgr->setShadowTextureCountPerLightType(Light::LT_DIRECTIONAL, 3);
mSceneMgr->setShadowTextureCount(3);
mSceneMgr->setShadowTextureConfig(0, 1024, 1024, PF_X8R8G8B8);
mSceneMgr->setShadowTextureConfig(1, 512, 512, PF_X8R8G8B8);
mSceneMgr->setShadowTextureConfig(2, 512, 512, PF_X8R8G8B8);
PSSMShadowCameraSetup* pssm = new PSSMShadowCameraSetup();
pssm->calculateSplitPoints(3, mCamera->getNearClipDistance(), shadowFarDistance);
pssm->setSplitPadding(mCamera->getNearClipDistance());
pssm->setOptimalAdjustFactor(0, 2);
pssm->setOptimalAdjustFactor(1, 1);
pssm->setOptimalAdjustFactor(2, 0.5);
mSceneMgr->setShadowCameraSetup(ShadowCameraSetupPtr(pssm));
mSceneMgr->setShadowFarDistance(shadowFarDistance);

Notice that I used Integrated Shadows, this is a requirement of PSSM since only shaders with integrated shadow support can decide on the fly which shadowmap to sample from.

My sincere thanks to lf3thn4d for helping us get this feature in to Ogre 1.6 (and to all those who send us patches in fact). If you want to see it and OgreSpeedTree in motion, there is a video available; that’s the low-quality streamed version but you can also download the higher resolution version if you want.

Leaping Lately to Leopard

OS X, Tech 14 Comments

For a geek, I can exhibit luddite tendencies sometimes. I don’t run Vista yet on anything other than secondary test machines, because I really don’t like it very much  – I feel it’s burning additional machine resources in a way that adds little or no value to my productivity or user experience compared to XP, and I’ve had several usability / stability hassles with the test machines I’ve had. I also remain very skeptical about the relative importance of Dx10 given that the vast majority of users either don’t have Vista, or don’t have a card worthy of being called Dx10 compliant, even in gamer circles. In short, I love reading about and playing with new tech, but when it comes to spending my money and resources (particularly time), practicality and not hype tends to rule my mind.

Another example is that I only just upgraded my MacBook Pro to OS X Leopard, even though it’s been out for 9 months already. When it first came out I was reticent to upgade immediately, wary of early problems and also that I was only just getting used to OS X anyway. Since then, I’ve always seemed to have an excuse not to do it – some impending trip / presentation / deadline which meant it wasn’t convenient, and really just lack of time.

Nevertheless, I finally made some time to do it last night, mostly because a couple of people in my family are getting or likely to be getting Macs soon, and of course those will come with Leopard, so I’d like to be in sync. Also Snow Leopard isn’t going to be out for another year by the sounds of it, so it’s still worth me upgrading and not waiting for the next one.

My early impressions have been good – it’s very much an evolution rather than revolution, but then if it ain’t broke, don’t fix it. I like how once again the things that are good for flashy demos are actually very useful in practical terms too, in particular ‘Quick Look‘ is really very handy. Basically you can just press the Spacebar whenever you’re selecting an item in Finder or whatever, and it pops up a window allowing you to browse the content of the file, whether it’s a PDF, Powerpoint presentation, document, image, archive, whatever – and it does this without starting any applications, so it’s super-duper-fast. Incredibly handy for skimming through a bunch of documents when you’re not sure exactly which one you want just from the filename, without the overhead of firing up apps and loading everything fully.

Other things are handy too, Spaces are handy but nothing new if you’ve used multiple desktops on other systems before, and the fold-out stacks make shortcuts to common folders more convenient than before. I doubt I’ll use many of the other features – all my important stuff is backed up on a server so I don’t need Time Machine (although I will definitely be recommending that one to my parents), and I’m too attached to Firefox and Thunderbird to get excited about the Safari and Mail enhancements. Oh, I could see myself using the presentation features of iChat though, that’s something I normally have to use GoToMeeting or similar for.

As an upgrade I think Leopard is a bit expensive at £70 for what it is (another reason I put it off), but nevertheless it’s a nice increment to what has become my favourite desktop OS over the last 12 months. I really can’t see that changing in the near future either – with Snow Leopard, Apple seems to be taking the opposite approach of those in Redmond by concentrating on optimizing & further streamlining what they have rather than stuffing in more and more features, which sounds good to me. OS X already does everything I want, and is no slouch in the performance dept already, certainly compared to the hulking, sweating mass that is Vista, but if they can make it even faster, and smaller, then all the better.

Hmm, I’m definitely becoming an Apple cheerleader. A bit scary, but hey, they make stuff I really like to use. Sure you have to pay a little extra, but I’d rather choose to pay for something I can take pleasure in using, than be coerced into paying for something that at best leaves me apathetic, and at worst annoys the hell out of me.

Spreading the word

OS X, Personal, Tech 15 Comments

I feel like I’m becoming something of an advocate for Apple machines these days, which is not something I ever saw coming. I hadn’t even used one until almost 12 months ago, and like many long-time PC users am guilty of having poked fun at them in the past (hur hur, one mouse button, hur hur, poor game support) but now that I’ve had one for a while, I’ve changed my tune. I’m finding that I can heartily recommend them for quite a wide cross-section of users, particularly when it comes to a portable machine.

My parent’s XP-based Dell laptop keeled over and died recently and while they’ve managed without a PC for a little while (!), they’re missing it. They’re faced with being forced (in practice) to switch to Vista if they buy a new Windows laptop, and they’d heard bad things about it (and not just from me I might add, their friends bought a Vista machine recently and have complained to them a lot about it) so were wondering what to do. My parents aren’t particularly technical but know their way around a computer, so long as nothing goes wrong, and aren’t looking for a gaming or power machine, just something that does email & internet, office tasks etc. Someone else in the family ‘knows someone at Microsoft’ (join the club ;) ) and suggested to them that if they were reticent about Vista, the sequel would be out next year so they could always look forward to that, but of course that got me chuckling. I explained that not only was Vista several years late, so predictions about the release of a sequel are somewhat premature, at this point we have no idea of what it will be like.

They even asked me what I thought about desktop Linux, since they’d seen it as an option in one or other shop they went into – something that surprised me actually. However with no on-site support from me (since they’re now 3+ hours flight & train time away) I considered that to be a recipe for disaster, given my experiences even with the latest Ubuntu. Great if you’ve got a tech you can call when things go wrong, not so good otherwise, so I ruled that out.

So, my advice? Although they’d probably be ok with Vista, particularly since SP1, given they would have to re-adjust to Vista’s changes anyway, and given the kinds of things they want to do with it, I really think a MacBook would be a better fit for them as very casual, relatively non-technical people. I didn’t recommend this lightly, because they’re not made of money (being retired) and they will have to save up a little more than they would have to buy a budget Vista laptop, but I honestly think it will be better in the long run for them. There are no drivers to worry about, OS X is definitely easier for regular people to use even counting the adjustment from Windows, and in general everything usually just works with considerably less faffing about. The software to do most of what they want is already there as standard, and works in a consistent fashion. I also think face-to-face support is more readily available if they can find a Premium Apple Reseller; they had been shocked at the outrageous prices they were quoted just to *look* at their slowly dying Dell to see if it was economically fixable. Small Apple specialists seem to be better at providing that kind of more personal service if our local premium reseller is anything to go by, certainly more so than unit-shovellers like PC World / Currys.

Simply put, I honestly think people like my parents will have a better experience with a Mac longer term. I’ve advised them to find a decent reseller first and play with one to make sure they’re happy with the idea of making the transition, and that they’ll have some local hardware support to make them feel comfortable given I can’t be there to organise it, but I think if they get over that bump it’ll be plainer sailing for them.

Hex Colour Picker for OS X

OS X No Comments

If, like me, you were wondering why the excellent Pixelmator got out of the door without an easy way to see the colours you’ve picked in HTML-friendly hexidecimal form, the way you can in Photoshop – well, it’s actually that OS X has an altogether more elegant way of handling this kind of thing.

I didn’t know this, but the colour picker widget shown in PixelMator is a standard OS X one, and you can plug in new widgets for it. One such plugin is the Hex Colour Picker. Once installed, PixelMator picks it up as a new toolbar button on the colour picker widget (as will every other app using this widget) and you can copy the HTML-friendly colour from there. Simple, but very effective.

By-value static member variables & XCode debug builds

C++, Development, OGRE, OS X 2 Comments

Well, this had me baffled for a while. I’ve been beavering away on allowing custom, user-supplied memory allocators in Ogre, hopefully for inclusion in the upcoming 1.6, and I came across a very weird problem in OS X. The wrapper for customising regular allocations (ie new/delete as opposed to STL allocations, those are in a different std::allocator compatible class), looks like this:

template <class Alloc>
class AllocatedObject
{
protected:
    static Alloc smAllocPolicy;

Pretty obvious stuff, we clearly redirect new/delete operators via that allocator policy. We then go on to define some default allocators (which can be replaced), something like this:

typedef AllocatedObject<StdAllocPolicy> DefaultAllocatedObject;
typedef DefaultAllocatedObject SomeObjectAlloc;

.. and then in our first-party class definition:

class SomeObject : public SomeObjectAlloc
{

All fairly straight forward – all that typedefing is just a compact way of allowing per-class user configurable allocators while still keeping the type duplication to a minimum. I can also place those typedefs in such a way that they can be easily replaced just by user headers or preprocessor blocks. Now, obviously I need to instantiate that smAllocPolicy member, otherwise I’m in trouble. So, here’s what I initially tried to do, in a cpp:

template <> DefaultAllocationPolicy DefaultAllocatedObject::smAllocPolicy;

Seems ok, right? Again I’ve used the typedefs here so that the instantiation will work even if I changed the basis for the types. This worked fine on Visual C++ 2005, Ubuntu 7.1 and in release mode on OS X. But, in debug mode on OS X, I got this:

ld: Undefined symbols:
__ZN4Ogre15AllocatedObjectINS_14StdAllocPolicyEE13smAllocPolicyE
/Users/steve/projects/Shoggoth/ogre/Mac/Ogre/../build/Ogre.build/Debug/Ogre.build/Objects-normal/ppc/OgreEntity.o reference to undefined __ZN4Ogre15AllocatedObjectINS_14StdAllocPolicyEE13smAllocPolicyE
/usr/bin/libtool: internal link edit command failed

WTF? I double-checked that the .cpp was included in the target, that the .LinkFileList file included the right object file, that ZeroLink was disabled (not that that would have any effect but to delay any link errors until runtime anyway). I tried getting rid of the typedefs and making it explicit, no dice. It had me scratching my head for some time, I was convinced I was instantiating this static and the object file was getting linked, so why the problem? In the end, the solution was to to change the instantiation to this:

template <> DefaultAllocationPolicy DefaultAllocatedObject::smAllocPolicy = DefaultAllocationPolicy();

I’m really not sure why in debug mode I was forced to include an explicit construction & assignment of this policy class rather than it being constructed by value in place, as seems to have happened with the other compilers and indeed in release mode under OS X. I usually don’t hold complex types statically by value, so usually I’d have an explicit initialisation in code like this to init pointers to 0 or numerics to something reasonable, so I wouldn’t have tried this particular thing on OS X before, but I did not expect to have to construct a complex type manually (and copy-construct effectively, although that’s likely to be optimised out). The fact that it worked in release mode and on other compilers makes me wonder how idiosyncratic that behaviour is. Maybe I’m just too tired and need to read Stroustrup again. If anyone has a rational explanation, I’d be glad to hear it.

Working around GLSL attribute aliasing problems on OS X

OGRE, OS X 8 Comments

As much as I love using OS X, one of the double-edged swords is that the graphics driver updates are controlled by Apple. On the one hand, that’s a bonus because you have a better idea of what you’re dealing with out in the wild, and people get prompted to update their drivers (as part of the regular OS X auto-update). On the other hand, it’s a pain in the ass because the drivers tend to lag behind those from the GPU manufacturers and therefore have bugs the mainstream ones don’t.

I just recently committed a patch from ‘hellcatv’, one of the more prolific Mac users in our community to deal with a few driver bugs in some of the older Powerbooks, and also some quirks of the recent Intel GMA-based iMacs – stuff like choking on glCompressedTexSubImage2DARB for no good reason (ie, forget uploading part of a DXT-compressed texture, it’s all or nothing). I’m indebted to him for testing on a huge range of Macs that I’d never have access to, without spending a load of cash and filling up my home office with yet more surplus hardware (my wife would not entirely approve of either methinks). One of the remaining problems we’ve had is that the OS X GLSL drivers on the recent NVIDIA-based MacBook Pros suffered from vertex attribute aliasing-associated performance problems that other platforms did not.

Now, NVIDIA has always had a fixed set of vertex attribute assignments for the built-ins – gl_Vertex is 0, gl_Normal is 2, etc. If you used gl_Normal in a shader, but also bound a custom attribute (say, skeletal blend weights) to index 2 too, you’d get a performance drop because of the aliasing. That’s fine – so instead, when we used custom attributes, we didn’t fix the indexes we used, we let the linker decide, taking into account what was actually used in the shader. We’d include the attributes in the shader, and then after glLinkProgramARB, we’d ask the program object what indexes it had chosen for the custom attributes, then wire them up that way. The well-behaved drivers (Windows, Linux) on NVIDIA would avoid clashing with any built-in attributes that had been referenced in the shader and we’d have a nice tight list of unique indexes, but on OS X, the driver would stupidly often assign custom attributes to built-in indexes that were in fact being used in the shader. Tsk, bad driver, no treats for you today.

It’s been reported to Apple as a bug, but so far, no dice on the fix front, so I decided it was time to try to work around it. The first thing I tried was simply telling the driver at the pre-link stage that I wanted any occurrences of the custom vertex attributes we supported to be placed out of the way of any possible built-ins that might be used. So for example, I did this:

glBindAttribLocationARB(mGLHandle, 6, "blendWeights");
glBindAttribLocationARB(mGLHandle, 7, "blendIndices");

That seemed to take effect, and calling glGetAttribLocationARB after the link reflected that I was indeed getting indexes 6/7 bound, rather than the 1/2 that the driver kept picking before (bad, because I used gl_Normal in this shader which is index 2). However, despite the indexes being out of the way of anything else, the shader still performed really poorly. I tried a few other indexes, like 14 and 15 which overlap with the top 2 UVs but which are rarely used (you can’t exceed 15, at least on NVIDIA), but the result was the same.

Cue head-scratching. There should be no aliasing problems anymore, yet still the shader performs like an asthmatic ant carrying some heavy shopping. So, the last thing I tried was going the whole hog, and implementing support for custom attribute replacements for all of the built-ins, all at known, fixed indexes matching currently known hardware defaults & limitations, ie:

Index Built-in Custom Name
0  gl_Vertex vertex
1 n/a blendWeights
2 gl_Normal normal
3 gl_Color colour
4 gl_SecondaryColor secondary_colour
5 gl_FogCoord n/a
7 n/a blendIndices
8 gl_MultiTexCoord0 uv0
9 gl_MultiTexCoord1 uv1
10 gl_MultiTexCoord2 uv2
11 gl_MultiTexCoord3 uv3
12 gl_MultiTexCoord4 uv4
13 gl_MultiTexCoord5 uv5
14 gl_MultiTexCoord6 uv6, tangent
15 gl_MultiTexCoord7 uv7, binormal

And what do you know, that works. The skinning shader runs considerably better like that – still not great, I think the Apple GLSL implementation is not that good, but at least 2-3 times faster than it did before. It kinda sucks to have had to do it that way, I really liked being able to leave it up to the driver to organise the attribute bindings and only using the ones I needed because that’s more in the spirit of the GLSL way, but clearly being more rigid is the more reliable way. I know that I could have packed the tangent in attribute 6 instead to save a UV entry, but the use of 6 seemed to have some performance issues still so I’ve gone with the fixed bindings I would have used with ARB programs. It’s incredibly rare to need more than 5 UVs going into a vertex program anyway in my experience.

So, the advice appears to be that if you need a custom binding in GLSL and you want it to run well on a Mac, using all custom attribute bindings in the vertex shader and fixing the indexes seems to be the way to go.