I am wondering if excessive use of the D3DXIntersect function will put a lot of strain on the CPU. I plan to use this or something like it in a project where in each frame I use this for each pixel. Since calling D3DXIntersect several million times per frame per mesh might not be such a smart thing to do, are there any other ways to implement this, like in HLSL?
This is not exactly ray tracing an image as the topic may suggest, but rather using "ray tracing" ontop of rasterizing to achieve effects ingame.
If I remember correctly, D3DXIntersect is quite slow. Certainly not fast enough to be called many times per frame.
When I used a similar functionality of the havok physics engine, I got almost uncomparably better speed.
If you want to do it on the GPU you could use MRT to output an identifier saying which model you're rendering to a second render target. The depth buffer will ensure each pixel holds the correct result after rendering. You can than use that render target as input to another shader to process the results.
Depending on exactly what you want to do you may find that you'll need to use DirectX 10/11 functionality to achieve it. However even on DX9 simply reading back that extra render target on the CPU (which isn't very efficient) will still be much quicker than doing all those D3DXIntersect calls.
What your talking about is out of my depth so I can't directly help you, but doesn't DX11 have a way to identify primitives at least in some parts of the pipeline. If you have the primitive values stored for an object (stored into some textures for instance) you might be able to index into those to get your triangle vertices. That would involve duplication of your model data, but depending upon what you need it could work.
You could read up on the Geometry Shader which operates on complete primitives, including adjacent primitives. But again, I can hardly help you or explain it further, I've never used the Geometry Shader.