# DX11 If targetting DX9, should I use the DX11 SDK and methods?

## Recommended Posts

I really have no -need- for the new features of DX11, but given its the current and cleaned-up interface, I'm tempted to use it.  However, I will need my game to run on machines that do not have DX11 hardware.  I don't need to target XP (Win7 is fine).

What I'm (obviously) completely unclear about is:  if I write to the DX11 apis and link to the DX11 dlls, but do not use any DX11-specific functionality, will the game run on a machine that only has DX9 hardware but that -does- have the DX11 redistributable?

Since (according to Steam's stats) DX11 penetration is still only about 60%, and I don't require anything new from DX11, it seems like a no-brainer to use DX9.  But if I can write to DX11 and it'll run on DX9 hardware, all the better.

Can someone clarify this for me?

As a tangential question, I've also been playing with the DXUT framework which seems to be able to target both, but if I call D3DX11CompileFromFile to compile a shader (vs_2_0), is there any way that's going to work on DX9 hardware?

Thanks for humoring the DX noob!

Cheers,

Dave

#### Share this post

##### Share on other sites

If I'm not mistaken, you can target the DX11 API if you don't need to support XP, and its a good idea for the reasons you cite. Be aware that Win7 (and Vista?) only got a partial update to D3D11 so some features aren't available, but its not an issue if you're targetting feature-level 9_x anyhow. Your game will run fine on DX9 hardware.

If you want to run on Windows RT tablets like Microsoft Surface to reach the widest possible market, target feature-level 9_1 -- which is what all but one of the current ARM-based platforms support, including Surface RT. As an added note, be aware that the current arm-based platforms are typically fill-rate limited (as is the case with SurfaceRT's Tegra3), so be careful to reduce overdraw.

As for shaders, you need to select the shader profiles that are appropriate for feature-level 9_1, and you might have to simplify your shader too. Down-level shader profiles support fewer instruction slots than newer profiles, and may not have enough room to run larger shaders that you might prefer with more-capable hardware.

Edited by Ravyne

#### Share this post

##### Share on other sites

Starting DirectX 11, they introduced the notion of "feature levels".

When you initialize D3D with a specific feature level, the API will fail if you try to do something that is only available on higher levels even if your HW is fully D3D 11 compliant.

However it's always advisable of course, to test that your game still works on real older hardware (mostly because of driver issues).

Note that your users will still need Windows 7 to play it (or Windows Vista with DX11 installed)

#### Share this post

##### Share on other sites

As Matias mentions, check out the different feature levels.

Feature level 11 gives you access to SM5 hardware (aka DX11 era hardware).
Feature level 10 gives you access to SM4 hardware (aka DX10 era hardware).
Feature level 9 gives you access to SM2 hardware (aka early DX9 era hardware).

You only need to use D3D9 if you require XP support, or you specifically want to target SM3 hardware (aka late DX9 / PS3 / 360 era hardware), because it was left out of the feature levels for some reason (simplicity?)...

As a tangential question, I've also been playing with the DXUT framework which seems to be able to target both, but if I call D3DX11CompileFromFile to compile a shader (vs_2_0), is there any way that's going to work on DX9 hardware?

Yes. The important detail is the target profile (shader model) that you specify. The vs_2_0 profile will produce a SM2 compatible shader, which will work on DX9+ era hardware.

Edited by Hodgman

#### Share this post

##### Share on other sites

I'd like to keep my options open for a 360 port, which I assume is a lot easier from a DX9 codebase.  Otherwise it sounds like the DX11 api would be the way to go, but I'm thinking it's a lot of work to port DX11 -> DX9 since the 360 probably lacks the whole "Deal with DX11 apis but map them to DX9_3 features".

#### Share this post

##### Share on other sites

I'd like to keep my options open for a 360 port, which I assume is a lot easier from a DX9 codebase.

Keep in mind though that the general public isn't allowed to make DX9/360 games.
The general public can make 360 games using C# and XNA.
Professional companies that have gone through the trouble (and cost) of becoming a licensed 360 developer can make 360 games using C++ and DX9. If you're not a professional company that can afford to spend many tens of thousands on licensing and hardware, then making this kind of 360 game is out of the question :/

#### Share this post

I think that the XDK for the xbox one will be released for the public and we will be able to make indie C++ written indie games without paying tons $$. But these thoughts are currently only dreams... #### Share this post ##### Link to post ##### Share on other sites I think that the XDK for the xbox one will be released for the public and we will be able to make indie C++ written indie games without paying tons$$$. But these thoughts are currently only dreams... I sure hope that'll be the case. Current info on the Xbox one indie/self-publishing is scant right now but i think we're supposed to get more info about that next month from Microsoft. #### Share this post ##### Link to post ##### Share on other sites I think that the XDK for the xbox one will be released for the public and we will be able to make indie C++ written indie games without paying tons$.
But these thoughts are currently only dreams...

I sure hope that'll be the case. Current info on the Xbox one indie/self-publishing is scant right now but i think we're supposed to get more info about that next month from Microsoft.

Keep in mind that "indie self publishing" doesn't mean that anyone can publish games on their system.
Sony have been making big noises about how they're now allowing "indie self publishing", but this just means that licensed developers can release a game without requiring them to be signed with a publisher. You still need to be a licensed developer, buy expensive dev-kits, and pay ten grand for a formal submission review prior to publishing...

#### Share this post

##### Share on other sites

I doubt if its going to be as accessible as XNA was -- if for the technology alone. XNA was much simplified compared to using DX natively, and the content pipeline was huge. That said, given that you had to manage memory anyways if you wanted to do anything worth a darn, and that C# is a curly-brace language, that C++/CX closes many of the remaining gaps where it applies most (the UI layer), and that DX11 has a smaller conceptual footprint than DX9 ever did, I don't think it'll be so traumatic a transition, once you get over fear of the unknown.

Here's what they've said publicly:

• Every Xbox one can run unsigned code.
• No need for a publisher (I believe by default, Microsoft is considered the publisher, but they don't take ownership of IP, etc)
• psuedo-quote: "If you wanted to prepare for that future today, developing a Windows Store app would be a good place to start."
• More info at the end of August, at GamesCon.

Putting that all together, I'm wagering on a frills-light SDK based on native C++, C++/CX possibly, that has a similar app-model to Windows Store apps. What I'm kind of curious about, is whether they'll allow access to the game hardware partition on hypervisor. If not, your app will share the OS with some smallish percent of the overall resources -- sources say between 10-20% -- which is still probably about on par with Xbox 360 and very capable. But things would be really interesting if you could use the game partition with 80-90% of the hardware dedicated to your game.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now

• ### Forum Statistics

• Total Topics
627704
• Total Posts
2978715
• ### Similar Content

• By Baemz
Hello,
I've been working on some culling-techniques for a project. We've built our own engine so pretty much everything is built from scratch. I've set up a frustum with the following code, assuming that the FOV is 90 degrees.
float angle = CU::ToRadians(45.f); Plane<float> nearPlane(Vector3<float>(0, 0, aNear), Vector3<float>(0, 0, -1)); Plane<float> farPlane(Vector3<float>(0, 0, aFar), Vector3<float>(0, 0, 1)); Plane<float> right(Vector3<float>(0, 0, 0), Vector3<float>(angle, 0, -angle)); Plane<float> left(Vector3<float>(0, 0, 0), Vector3<float>(-angle, 0, -angle)); Plane<float> up(Vector3<float>(0, 0, 0), Vector3<float>(0, angle, -angle)); Plane<float> down(Vector3<float>(0, 0, 0), Vector3<float>(0, -angle, -angle)); myVolume.AddPlane(nearPlane); myVolume.AddPlane(farPlane); myVolume.AddPlane(right); myVolume.AddPlane(left); myVolume.AddPlane(up); myVolume.AddPlane(down); When checking the intersections I am using a BoundingSphere of my models, which is calculated by taking the average position of all vertices and then choosing the furthest distance to a vertex for radius. The actual intersection test looks like this, where the "myFrustum90" is the actual frustum described above.
The orientationInverse is the viewMatrix in this case.
bool CFrustum::Intersects(const SFrustumCollider& aCollider) { CU::Vector4<float> position = CU::Vector4<float>(aCollider.myCenter.x, aCollider.myCenter.y, aCollider.myCenter.z, 1.f) * myOrientationInverse; return myFrustum90.Inside({ position.x, position.y, position.z }, aCollider.myRadius); } The Inside() function looks like this.
template <typename T> bool PlaneVolume<T>::Inside(Vector3<T> aPosition, T aRadius) const { for (unsigned short i = 0; i < myPlaneList.size(); ++i) { if (myPlaneList[i].ClassifySpherePlane(aPosition, aRadius) > 0) { return false; } } return true; } And this is the ClassifySpherePlane() function. (The plane is defined as a Vector4 called myABCD, where ABC is the normal)
template <typename T> inline int Plane<T>::ClassifySpherePlane(Vector3<T> aSpherePosition, float aSphereRadius) const { float distance = (aSpherePosition.Dot(myNormal)) - myABCD.w; // completely on the front side if (distance >= aSphereRadius) { return 1; } // completely on the backside (aka "inside") if (distance <= -aSphereRadius) { return -1; } //sphere intersects the plane return 0; }
Please bare in mind that this code is not optimized nor well-written by any means. I am just looking to get it working.
The result of this culling is that the models seem to be culled a bit "too early", so that the culling is visible and the models pops away.
How do I get the culling to work properly?
I have tried different techniques but haven't gotten any of them to work.
If you need more code or explanations feel free to ask for it.

Thanks.

• hi,
i have read very much about the binding of a constantbuffer to a shader but something is still unclear to me.
e.g. when performing :   vertexshader.setConstantbuffer ( buffer,  slot )
is the buffer bound
a.  to the VertexShaderStage
or
b. to the VertexShader that is currently set as the active VertexShader
Is it possible to bind a constantBuffer to a VertexShader e.g. VS_A and keep this binding even after the active VertexShader has changed ?
I mean i want to bind constantbuffer_A  to VS_A, an Constantbuffer_B to VS_B  and  only use updateSubresource without using setConstantBuffer command every time.

Look at this example:
SetVertexShader ( VS_A )
updateSubresource(buffer_A)
vertexshader.setConstantbuffer ( buffer_A,  slot_A )
perform drawcall       ( buffer_A is used )

SetVertexShader ( VS_B )
updateSubresource(buffer_B)
vertexshader.setConstantbuffer ( buffer_B,  slot_A )
perform drawcall   ( buffer_B is used )
SetVertexShader ( VS_A )
perform drawcall   (now which buffer is used ??? )

I ask this question because i have made a custom render engine an want to optimize to
the minimum  updateSubresource, and setConstantbuffer  calls

• I got a quick question about buffers when it comes to DirectX 11. If I bind a buffer using a command like:
IASetVertexBuffers IASetIndexBuffer VSSetConstantBuffers PSSetConstantBuffers  and then later on I update that bound buffer's data using commands like Map/Unmap or any of the other update commands.
Do I need to rebind the buffer again in order for my update to take effect? If I dont rebind is that really bad as in I get a performance hit? My thought process behind this is that if the buffer is already bound why do I need to rebind it? I'm using that same buffer it is just different data

• I am really stuck with something that should be very simple in DirectX 11.
1. I can draw lines using a PC (position, colored) vertices and a simple shader just fine.
2. I can draw 3D triangles using PCN (position, colored, normal) vertices just fine (even transparency and SpecularBlinnPhong shaders).

However, if I'm using my 3D shader, and I want to draw my PC lines in the same scene how can I do that?

If I change my lines to PCN and pass them to the 3D shader with my triangles, then the lighting screws them all up.  I only want the lighting for the 3D triangles, but no SpecularBlinnPhong/Lighting for the lines (just PC).
I am sure this is because if I change the lines to PNC there is not really a correct "normal" for the lines.
I assume I somehow need to draw the 3D triangles using one shader, and then "switch" to another shader and draw the lines?  But I have no clue how to use two different shaders in the same scene.  And then are the lines just drawn on top of the triangles, or vice versa (maybe draw order dependent)?
I must be missing something really basic, so if anyone can just point me in the right direction (or link to an example showing the implementation of multiple shaders) that would be REALLY appreciated.

I'm also more than happy to post my simple test code if that helps as well!

THANKS SO MUCH IN ADVANCE!!!
• By Reitano
Hi,
I am writing a linear allocator of per-frame constants using the DirectX 11.1 API. My plan is to replace the traditional constant allocation strategy, where most of the work is done by the driver behind my back, with a manual one inspired by the DirectX 12 and Vulkan APIs.
In brief, the allocator maintains a list of 64K pages, each page owns a constant buffer managed as a ring buffer. Each page has a history of the N previous frames. At the beginning of a new frame, the allocator retires the frames that have been processed by the GPU and frees up the corresponding space in each page. I use DirectX 11 queries for detecting when a frame is complete and the ID3D11DeviceContext1::VS/PSSetConstantBuffers1 methods for binding constant buffers with an offset.
The new allocator appears to be working but I am not 100% confident it is actually correct. In particular:
1) it relies on queries which I am not too familiar with. Are they 100% reliable ?
2) it maps/unmaps the constant buffer of each page at the beginning of a new frame and then writes the mapped memory as the frame is built. In pseudo code:
BeginFrame:
page.data = device.Map(page.buffer)
device.Unmap(page.buffer)
RenderFrame
Alloc(size, initData)
...
memcpy(page.data + page.start, initData, size)
Alloc(size, initData)
...
memcpy(page.data + page.start, initData, size)
(Note: calling Unmap at the end of a frame prevents binding the mapped constant buffers and triggers an error in the debug layer)
Is this valid ?
3) I don't fully understand how many frames I should keep in the history. My intuition says it should be equal to the maximum latency reported by IDXGIDevice1::GetMaximumFrameLatency, which is 3 on my machine. But, this value works fine in an unit test while on a more complex demo I need to manually set it to 5, otherwise the allocator starts overwriting previous frames that have not completed yet. Shouldn't the swap chain Present method block the CPU in this case ?
4) Should I expect this approach to be more efficient than the one managed by the driver ? I don't have meaningful profile data yet.
Is anybody familiar with the approach described above and can answer my questions and discuss the pros and cons of this technique based on his experience ?
For reference, I've uploaded the (WIP) allocator code at https://paste.ofcode.org/Bq98ujP6zaAuKyjv4X7HSv.  Feel free to adapt it in your engine and please let me know if you spot any mistakes
Thanks
Stefano Lanza

• 21
• 14
• 12
• 10
• 12