Browsed by
Month: May 2011

Gotcha’s of using ID3D11ShaderReflection

Gotcha’s of using ID3D11ShaderReflection

So, I am working on something that requires I programmatically know what’s in a DX11 shader file.  One of the cool things you can use to figure out how many constant buffers, get string names from position streams, etc – is the DirectX Shader Reflection system.  It gives you the ability to query a loaded shader blob for names/types/etc.  However, it’s not quite as straightforward as one might expect to use.  The docs were pretty incomplete up until the DX11 version.  But here’s the basics of the ID3D11ShaderReflection system:

  1. Load your vertex/pixel shaders.  Get the actual shader blob – or extract it from the FX system if you used that.
  2. Bind it to a shader reflection object using D3DReflect:
    pd3dDevice->CreatePixelShader( pPixelShaderBuffer->GetBufferPointer(), pPixelShaderBuffer->GetBufferSize(), g_pPSClassLinkage, &g_pPixelShader );
    ID3D11ShaderReflection* pReflector = NULL;
    D3DReflect( pPixelShaderBuffer->GetBufferPointer(), pPixelShaderBuffer->GetBufferSize(), IID_ID3D11ShaderReflection, (void**) &pReflector);
  3. Query the reflection object for whatever constant buffer, input/output stream, or other info you want using the many methods available.  It’s a GREAT way to test your shaders at load time so you don’t get cryptic runtime errors later when you try to actually draw objects.

Now, the gotcha’s:

  1. You must add this:
    #include <D3DCompiler.h>

    Or you’ll get a compile error with D3DReflect() – despite the fact the official Microsoft docs seem to say you should (only) include:

    #include <D3DShader.h>
  2. You MUST have the DirectX SDK include directory listed before the windows include directory in the Visual Studio compiler include directory list or you’ll get compile errors in D3DShader.h. This is apparently because the windows headers that come with Visual Studio platform headers actually have a few DX definitions in them that conflict with the DX SDK header definitions.   Check Tools/Options | Project and Solutions | VC++ Directories and make sure Windows SDK include & library paths appear AFTER DirectX include & library paths.  See here for the thread.
iPhone programming – Learnings

iPhone programming – Learnings

From the wayback machine…

I found a half-completed post on when I was first learning to program on the iPhone.  I think these things are all still valid…
So, I’ve embarked on an ambitious programming project.  One that is now 1/3 of the way complete (first third was the ‘heaviest lifting’ part of the project – took about a month of outsourced grunt work).  The next 1/3 involves programming an app on the iPhone/iTouch.  I thought that would be the easy part, but as it turns out – there is a substantial learning curve that one should be aware of before starting this endeavor.  Here are some of the learnings I’ve found so far after having just got the bare bones of my own app up and running.

  1. Apple’s documentation is very robust – but frustratingly ‘useless’ at times.  They provide many very detailed and excellent vertical stacks of information.  Want to learn about pooled allocators?  They have a document that gives you all the information you could ever want.  But not in the context of how you’d actually use them – or why you hit various problems you hit.   You’ll find yourself sifting around from document to document trying to find out why your NSString object is throwing an exception when returning from a function – only to find the real reason is buried in the memory management section of the Cocoa programming guide – not anywhere near the NSString documentation or their samples
  2. You need to learn Objective C and Cocoa. – and learn them in THAT order.  It’s annoying, but try to find a good Objective C book first.  There aren’t many of them.  There are lots of bad ones though.  Learn how to write a class, add functions with multiple calling parameters, how to make calls to classes, and how allocation works.  That last one is key.  Really spend time learning why:
    [[NSString alloc] init]
    is the right way to allocate and initialize an object and then learn why:
    NSString *s = [[NSString alloc] initFromString:@”hello”];
    [s appendString:@”this string now leaks”];
    leaks memory.  And how the autoAllocator pools work/don’t work.  This is all huge and the first biggest gotcha’s your get hit with right off the bat.
  3. You’ll struggle to get even a 5 line program working at first.  Your first Objective C/Cocoa programs will be very painful.  The simplest things will feel like fighting a brick wall.  I tried to do a simple enum, and kept getting burned by an invalid class definition.  Wha?  The objective C compiler on the iPhone requires you typedef your enums and structs:
    enum newEnum { a, b, c, d }; (NOPE – will cause a compiler error in whatever line follows this definition)
    typedef enum { a, b, c, d } newEnum; (yes – works)
    Just millions of little things like that.  Again, logical if you put your old C/gcc hat on, but it’s been a bit since I last had that hat on and it had some dust on it…
  4. The GUI IDE is great – if you do things they way THEY want them and only for straight-forward designs.  The interfaces for GUI controls holds very much like Win32/X programming philosophies, albeit the syntax is very different.  X Code comes with it’s own WYSIWYG GUI editor, but I found it very limited if you’re going to come up with any kind of innovative interface.  If you just want some standard buttons/etc – you’re probably fine.  But if you want to have some interesting scrolling effects/etc – you best be ready to spend another few days learning how the UI control systems work underneath and experimenting.  The built-in GUI editor reminds me of the old VS2005 GUI editor that you could drag-n-drop controls, compile, and you’d see the results.  If you want any dynamic elements – I haven’t found a way to do that using their gui editor.  And if you want to embed controls on scrolling panels and some other more modern effects – you’ll be tossing the GUI editor altogether.  Trouble is, you spend a good bit of time learning how the built-in GUI system works, find out it won’t do the thing you need without tons of digging through forums and ‘tricking’ the thing to do what you want, then give up and have to learn a bunch of NEW stuff when you give up and decide to just dynamically/hand-generate the controls yourself.  Frustrating.

Advice from a manager

Advice from a manager

Interesting article in Fortune from someone who appears to be a good manager and author of the book “You Can’t Fire Everyone” by Hank Gilman.   I particularly liked him because he seemed like a ‘good’ manager.  i.e. he had the notion of treating his people with respect, and handling his job with class, professionalism, and style.  One of his un-stated guidelines he seems to have is that if you build a great work environment, then it will sell itself.  Keep that point in mind while reading the rest of this. Some of his points:

  1. The day your star employee decides to leave is the day you start woo-ing your player back again – it’s not a time to act like child, hold a grudge, or try to sabotage them.  New opportunities and a chance to grow/try something different come along for everyone.  It’s your job as a manager to get them to want to come back. Doing any of the aforementioned childish behaviors only sabotages your own reputation, future hiring, and long-term career.
  2. Try to keep them – if what they want is something you can give.  Know when it’s right to bend over to keep someone.  If it’s about money, get them some more. If it’s about title, do something about that (titles are only words anyway). But if they really want a new job – or need a change – let them take it.  People who think a good career move is a new title will likely be back in six months anyway.  Conversely, all the money in the world won’t keep someone who really wants or needs a change.
  3. Don’t bad-mouth their direction/new employer.  Even if you know the other company is bad or people there are cut-throat back-stabbers, don’t get involved in a petty squabble or words that might get back to the people you gab about.  Show your integrity at those moments.  If you’ve build a great work environment, then you can honestly say “Go off and have a great time. I think you have a great opportunity.  However, I’ve had enough of them and I believe you’re not going to get much better than what we offer.  You’re always welcome here.”  The grass isn’t always greener, but sometimes you just have to let them find that out on their own and welcome them back when they’re ready.
  4. Keep in touch – Make it a point to have lunch or dinner and remain friendly.  You have a scout in a new place if you want to recruit one of their colleagues. You also have a damn good reference in case you need to look for work!

He had other suggestions, but you get the idea of his style.  He shows how an other-directed focus gives your actions class and doing things with a style that makes people want to come back to him.  His advice is to not pout around like a child that didn’t get their way, burn up potential partners and bridges, and generally strangle your own career over the long haul because you’re too ego-centric.  If all managers worked in a similar way, then I think far more people would be happier in their work lives.

Windows 7 blue-screens due to stdriver64.sys

Windows 7 blue-screens due to stdriver64.sys

I recently started getting blue-screens with stdriver64.sys. In doing my blue-screen debug, very little useful information was given:

This is a very common bugcheck.  Usually the exception address pinpoints
the driver/function that caused the problem.  Always note this address
as well as the link date of the driver/image that contains this address.
Arg1: ffffffffc0000005, The exception code that was not handled
Arg2: fffff8800970bbe8, The address that the exception occurred at
Arg3: fffff8800676d7f8, Exception Record Address
Arg4: fffff8800676d050, Context Record Address

Debugging Details:

EXCEPTION_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%08lx referenced memory at 0x%08lx. The memory could not be %s.

fffff880`0970bbe8 49              dec     ecx

EXCEPTION_RECORD:  fffff8800676d7f8 -- (.exr 0xfffff8800676d7f8)
ExceptionAddress: 0000000000000000
ExceptionCode: c0000005 (Access violation)
ExceptionFlags: 00000000
NumberParameters: 158383080
Parameter[0]: fffffffffffff880
Parameter[1]: 0000000000000002
Parameter[2]: 0000000000000000
Parameter[3]: 0000000000000000
Parameter[4]: 0000000000000000
Parameter[5]: 000000000022dba8
Parameter[6]: 0000000000000000
Parameter[7]: 0000000000000000
Parameter[8]: 0000000000000000
Parameter[9]: 0000000000000018
Parameter[10]: 0000000000000000
Parameter[11]: ffffffffffffffff
Parameter[12]: 000000000000007f
Parameter[13]: 0000000000000000
Parameter[14]: 0000000000000000
Attempt to execute non-executable address 0000000000000002

CONTEXT:  fffff8800676d050 -- (.cxr 0xfffff8800676d050)
Unable to read context, NTSTATUS 0xC0000147




LAST_CONTROL_TRANSFER:  from 0000000000000000 to 0000000000000000

00000000 00000000 00000000 00000000 00000000 0x0

STACK_COMMAND:  .bugcheck ; kb

fffff880`0970bbe8 49              dec     ecx

SYMBOL_NAME:  stdriver64+1be8
FOLLOWUP_NAME:  MachineOwner
MODULE_NAME: Unknown_Module
IMAGE_NAME:  Unknown_Image


I dug around on my support forums, and exception 7E has been related to loads of different problems: bad logitech mice drivers, cardbus adapters, audio drivers, failed USB drivers when it happens on awake from hibernate, etc.  Basically, any and all services seem to be known to cause it.  Also, having the module and image names completely unknown wasn’t very hopeful either.  I considered the idea of stepping into the memory location specificed until I found this write-up.  It mentions the program SoundTap as a very common source.  I had recently got Soundtap as part of a kit including the excellent Switch sound converter.  I uninstalled Sound Tap and sure enough – bluescreens went away.  Soundtap installs an audio driver to divert playback so you can do raw rips of anything you play on your pc (think sound ripper for youtube/shoutcast streams/shockwave players/etc).

So, it’s always a good idea to keep track of what you’ve changed on your pc and suspect even the unlikely things such as a simple software install.  That and googling for others with the same problems. 🙂

Is there really a shortage of scientists, engineers, and computer scientists?

Is there really a shortage of scientists, engineers, and computer scientists?

You hear it in the news – the US has a shortage of people going into engineering, science, and high-end technical degrees.  We’re being trounced by the extrodinary graduation rates in developing contries and China/India.  Even Obama introduced his STEM education support program to encourage students into Science, Technology, Engineering, and Math (which he touted on his trip to our Intel site a few months back).

I was recently elected to Purdue’s Alumni Board for the school of Sciences.   During the last bi-annual meeting, we have a dean of one of the science schools come in.  This time it was the dean of the Geology dept.  He gave a great presentation on the interesting things they’re doing, but one of the most interesting points about his presentation was this: he gets calls all day long from companies and government agencies looking for geologists, but he has none to give them.  Currently the enrollment in geology at Purdue is around 150 students.  For ALL undergraduate levels.  Purdue has just under 30,000 total students, and only 150 are enrolled in undergrad geology.  He says he has jobs to give away, but nobody to fill them.  And they’re not all just for oil companies – government needs lots of surveyors, building ground inspections, erosion and terrain evaluation/etc.  Companies have all kinds of jobs too.

Surprised by this information, I went over afterwards to my haunt – the Computer Science department.  In talking to one of my old professor acquaintances over there,  I was surprised to find they were *just* reaching 200 undergraduates.  When I was in computer science in the last 90’s, there were 250 students and rising every year.  it turns out that enrollment plummeted right after the dot-com bust and has only recently started recovering.   Both of Dean of Geology and the CS professor independently cited 2 major reasons:  high-school curriculum focus and perception of job market.

First they both talked about the need for outreach programs.  The dean of Geology and the CS department appear to desperately want to get kids in High School interested in CS or Geology (I’d say most of the schools of sciences would also agree).  We all know that high school programs across most states have been getting chopped for years.  Their evaluation is that the constant budget chopping has seriously cut back on all their curriculum; but in science/math it’s had a particularly chilling effect.  Why?  Because schools under budget constraints tend to focus only on core-courses that are required for state accreditation, and cut everything else.  Computer programs are nice, but are expensive investments from a per-student basis.  My own high school only had a programming course because one math teacher wanted to teach it pretty much pro-bono and the machines were the ones use to teach typing/word processing classes.   Many science programs have cut back to just basic chemistry and biology.  So it’s no wonder that students that have had lack-luster, or simply no, high school experiences with sciences like geology or computer science.  Even fewer are inspired to look into or consider them as possible career choices.  In recounting my own experience of being a rural Indiana student of a high school with only 500 students; my professor friend said I was most certainly a huge exception.  Most rural students never see the insides of a Purdue science lecture hall, let alone even apply.

If anecdotal evidence isn’t enough, the Dean of Geology said that many states and oil/geology companies are becoming so desperate for geologists that they are starting to create their own high-school curricula for geology programs and giving them to high-schools for free; if only they agree to teach it.  Some of these companies have even considered also sending along someone to teach it – for free.

Secondly, there is a perception that the job market isn’t good for sciences.  For CS, there is apparently still a lot of stigma from the dot-com explosion.  During a lot of the later 2000’s there were tons of out of work programmers, and even though the tide is completely turned around, the perception is that there is still a glut of programmers and/or that it’s a difficult job market.  In Geology, there is a perception that one will have to work for an ‘evil’ oil company; not knowing there are tons of fascinating other job opportunities doing surveying, soil research, water erosion, earthquake prediction/prevention, etc, etc, etc.

These two points were big factors in their take on the situation.   So as a member of this board, what should one advise?  I did some of my own research, and will write about THAT next time. 🙂