handmade.network » Forums » Minimal D3D11
d7samurai
72 posts

innovation through innovation™

#17156 Minimal D3D11
2 months, 2 weeks ago Edited by d7samurai on Jan. 7, 2019, 4:32 p.m. Reason: Initial post

New version of my minimal D3D11 reference implementation; an uncluttered Direct3D 11 setup and rendering primer for newcomers to the API:

https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052

No modern C++ / OOP / obscuring cruft. The source code is a complete, runnable C+ application contained in a single function (WinMain), laid out in a step-by-step fashion that should be easy to follow from the code alone (about 250 LOC). Win7 compatible. Produces this output:


software development should be a creative exercise, not a technical ordeal
mmozeiko
Mārtiņš Možeiko
1903 posts / 1 project
#17158 Minimal D3D11
2 months, 2 weeks ago Edited by Mārtiņš Možeiko on Jan. 7, 2019, 6:02 p.m.

Some time back I wrote similar thing: https://git.handmade.network/snippets/19
Yours is a bit complete, mine is only rendering one triangle, but it has extra features:
* Plain C, no C++
* Does not require DirectD3 11.1, uses 11.0
* Optionally does not link to D3DCompiler_XXX.dll file
* Handles window resizing
* Handles GPU driver reset on present call

d7samurai
72 posts

innovation through innovation™

#17159 Minimal D3D11
2 months, 2 weeks ago Edited by d7samurai on Jan. 10, 2019, 1:03 a.m.

sure. i also have other, older examples that do those things - window resizing, device reset, d3d11.0, doesn't use d3dcompiler etc. e.g.

https://gist.github.com/d7samurai/c93e8aac22ef3ec77fea03be0ce86f51
https://pastebin.com/KfGBrEx7

however, the main purpose of this particular implementation was to optimize for pedagogical simplicity; that's why i emphasize the fact that it's all a single function, for example. so the omittance of those aspects was quite deliberate. here, i wanted to streamline the conceptual flow from setup to actual 3d rendering in order to provide a straightforward overview of the d3d11 way - primarily for people already familiar with gpu programming, but new to d3d conventions and nomenclature. the tactical choices i made were informed by this guiding intent.

i did initially consider adding window resizing and device reset, but in the end decided against it as i see them as secondary concepts, not to mention that "device lost" ~never happens unpredictably in d3d11, and that it would only serve to add complexity and distract. in fact, in these reference examples there's no error handling whatsoever, for the same reasons.

d3d11.1 (assuming that was meant to mean d3d11_1.h, as opposed to FEATURE_LEVEL_11_1, since my example only requests FEATURE_LEVEL_11_0) is what i consider the minimum version of the d3d api worth bothering with. there's little, if anything, to be gained by using d3d11.0, even in terms of compatibility, as most 11.1 features are available in win7 with platform update anyway. i also specifically wanted to include the routine for "casting" to newer versions of Device and DeviceContext because that's going to be required for all recent api interfaces and something most people will need to do.

as for c vs c++.. i am not a plain c guy myself, as i see that as an unnecessary pain in the ass, but i do code in a very barebone "c+", aka "c with benefits", which i think is a better, more relevant target for a reference codebase like this. especially since it's d3d centric.

that said, i think it's great that you have a plain c alternative out there

software development should be a creative exercise, not a technical ordeal