My DirectX 11 Renderer

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • My DirectX 11 Renderer

      Hi!
      I'd like to present the library I have been working on roughly last two month. It is DirectX 11 forward renderer. The library is written in C++11 using VS2013 Express and Windows SDK 8.1. The library is targeting DX11 hardware with SM 5.0 and higher. No deprecated stuff from DXSDK is used.

      What the library has and what it can do:
      • Classes for shaders, materials, material properties, meshes, shader resources, samplers
      • Control over almost all pipeline functionality (rasterizer, depthstencil, blend, sampler states)
      • Cameras, ability to render into separate render target
      • Simple lighting manager (dir and point lights; amount of lights is configurable and associated with shaders)
      • Ability to set flags for object-camera, object-light relationship (e.g. you can render certain objects with certain cameras and lit certain objects with certain lights)
      • Automatic sorting of submitted items (camera -> opaque/transparent queues ->rendering order -> materials -> material properties); this allows to minimize state changes thus gain more performance
      • Material properties allow you to interface with shaders. You can specify constants for material constant buffer, set shader resources and samplers (Effects framework is not used); setting shader data is done using strings names (shader reflection is used for that)
      • Support for vertex, pixel and geometry shaders
      • Dynamic hlsl shader linking which allows you to make your shaders to behave like uber-shader without having to recompile the hlsl code
      • Flexible mesh class which contains mesh buffer classes for vertices, indices and instances (i.e. support for HW instancing); you can choose usage for your mesh buffers (default, immutable, dynamic, but no staging), update them at runtime, change usage as required, control all aspects of DirectX Draw*** commands (start, count parameter for all buffers etc); mesh buffers can also keep copy of the data in the system memory (e.g. for calculating bounding box)
      • Flexible vertex layout creation (you can cache the layouts); materials control and set appropriate input layout for IA pipeline stage
      • You can specify MSAA for the swap chain
      • Texture loading is done via DirectXTex library
      • DirectXMath simd library is used under the hood
      • Public interfaces does not contain any dx specific types
      • For convenience pod vector types are added similar to hlsl types (e.g. bool2, float3), although they are mostly for passing data rather than for calculations
      • And many other little details


      What it can't do (yet)
      • No support for tesselation and compute shaders as those are huge topic on itself
      • Still no animation support (very high on the priority list)
      • Not able to load meshes from the file, but I'm thinking about that
      • No post-effects
      • No multipass materials
      • No runtime shader compilation, you must compile shaders beforehand into *.cso objects load those cso files at runtime
      • Several raster state bits describing depth options are not presented
      • And many many more features which I'd like to add but unfortunately have no time to read about and implement; one of them is making the code to work with GCC engine and what's even more difficult - with the editor (this thing will bite me sooner or later I'm sure)


      Using the library I've written several demos. Each of the demo presents group of the concepts from the library. Currently there are 3 projects.

      Controls common to all projects:
      Two camera modes, default one is orbital, press F2 to select first person camera, press F1 to select orbital camera. In orbital mode press left button and move the mouse to rotate, use wheel for zooming. In first person mode, use WASD to walk/strafe, Q and E to fly up/down, hold right mouse button and move to change look direction. Press F to go fullscreen, press G to go into window mode. Press Esc to exit the program.

      Basics
      [IMG:http://s7.postimg.org/ze30x2ilz/Basics.jpg]
      Concepts shown: opaque/transparent sorting, raster/blend states, render to render target, dynamic meshes, multiple lights, texture transform, mesh transform, computing AABB on the fly, object/camera, object/light flags.
      Specific controls for Basics scene: arrows to move the ball, z/x/c - change render target resolution, v - kill render target. 1/2/3/4 - change sample filtering to point/bilinear/trilinear/anisotropic filtering accordingly, 5/6/7/8 change anisotropy to 1/2/4/8 samples accordingly (only works if anisotropic filtering mode is on). 'I' - make rotating wireframe sphere immutable (will no longer animate)

      Geometry Shader
      [IMG:http://s7.postimg.org/sqb0o7ohj/Geometry_Shader.jpg]
      Concepts shown: geometry shaders (trees are points, actual quads are constructed on the gpu), billboarding, dynamic hlsl linking (outer ring of trees use oriented billboards, inner ring - screen aligned billboards, but there is only one compiled shader), alpha cutouts (trees are rendered in opaque queue), alpha-to-coverage (to smooth trees), texture arrays (actual dds file is constructed using DirectXTex lib).

      Instancing
      [IMG:http://s7.postimg.org/6pq2tugfr/Instancing.jpg]
      Concepts shown: mostly hardware instancing (there are roughly 10000 spheres), working with various parameters of the mesh class (start/offset/count for vertices/indices/instances), number of instances is animated as well as each sphere indices (you can see that if you zoom in close), overall it renders several million triangles via single draw call.

      That's it folks! I have never thought that it would be so hard to write rendering library, there are tons of little details which you can't even predict. Additionally I haven't used DirectX11 before, so this is my first experience using this API which adds more efforts for learning.
      I will develop the library further as my free time allows me. Ideally in the end this would be the module for the GCC engine, however there is lot of work to be done yet!
      Share your thoughts and comments, if you want to see some certain functionality in the library also let me know. Thanks for reading this!

      P.S. You can download demo binaries by the following link dropbox.com/s/nv0zbxwql65bsr6/bin.zip. Archive contains several textures, 3 executable, compiled shaders and dll for shader reflection.
      Looking for a job!
      My LinkedIn Profile
    • For those who don't know (before you ask), you will need to get the visual c++ 2013 runtime to use this.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • I don't plan to start using 2013 for the foreseeable feature, it is only in preview (as far as I know), and when I used 2012 in preview I had alot of issues, and wasn't able to fully appreciate it until well into its life cycle.

      What are your thoughts on 2013 so far, any cool features to point out? Anything you don't like?
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • I'm using it about a month and got no issues so far (well maybe one, and I'm not sure whether it's actually problem of 2013). Purpose was to use latest windows sdk 8.1 and thus using latest DirectX functionality. It has more C++11 features (although I must admit I haven't used variadic templates and other 'kewl' stuff yet). The library in the first post if written in vs2013 (switched from 2012).
      Looking for a job!
      My LinkedIn Profile
    • I have used variadic templates only once for my thread pool jobs, however it was some crazy compiler magic that I found in a book on C++11 concurrency. Of C++11 I really enjoy a lot of the little things that make things easier ie. auto, the new for each, nullptr. I really like the fact that they have standardized threading, and so far it is a really good library.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • RE: My DirectX 11 Renderer

      Hey brother, great job with this. I haven't used VS 2013 yet, but I'm thinking about buying Pro edition if it's not too expensive when it comes out.

      PS. I don't know if you were aware of it, but I can see all of your shader code. If you were not, then all you have to do it's turn that option off on the fxc compiler.
      Intel i7 3930k
      8GB Mushkin LP @ 2133 mhz
      GTX 680
      Asus Rampage IV Extreme
      Corsair 650w
    • Have you ever bought a copy of visual studio? If yes forget I said anything, if no, take a look at a price chart it is quite expensive.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • RE: My DirectX 11 Renderer

      Originally posted by hondero
      Hey brother, great job with this. I haven't used VS 2013 yet, but I'm thinking about buying Pro edition if it's not too expensive when it comes out.

      PS. I don't know if you were aware of it, but I can see all of your shader code. If you were not, then all you have to do it's turn that option off on the fxc compiler.


      Well there is nothing to hide there :) I'll open sources when they will be ready anyway! But thanks for the info about fxc.
      Looking for a job!
      My LinkedIn Profile
    • Ok, I see Devast. I thought it was a mistake.

      It is pretty expensive Matt but the benefits are pretty damn good. No I have never bought one(I have used the professional edition thought with MSDN), but I'm only buying the Professional version, can't afford anything past that. I will to see what will be the prices for VS2013 Pro and also what will be the benefits over the Express Edition and I will go from there.

      My main thing right now is the hlsl debugger that it's usually not available on the Express Editions. Also I love the msdn access so I can test my apps on other versions of windows and windows server.

      PS. It is only about $ 1100 USD.
      Intel i7 3930k
      8GB Mushkin LP @ 2133 mhz
      GTX 680
      Asus Rampage IV Extreme
      Corsair 650w
    • In my opinion 1100$ is alot to dish out for software, it would be different if you worked at or owned a studio which already had a steady income to pay for that, but for a personal cost that is too much. I know alot of windows users don't like non-windows development, but I personally find linux development (I use CodeLite as an IDE, as well ask custom make files) more intuitive.

      Visual Studio is the best IDE to use on windows which is why I still use it when I am under windows, however as MinGW has caught up and now maintains speed with the official gcc compiler, it becomes more and more appealing to use MinGW, which is completely free.

      My only issue with gcc when I first started on linux in early-mid 2000's, was that the debugging was not as good as visual c++, however I can say now that gdb produces even better debugging information than vc++ (which may be an opinion) as of g++ 4.8.1. The error messages are now very precise and descriptive, and will show you up to the character in a line where your error is, as well as the debugging info used for the watch window is flawless.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • I see Matt, I've used both and in my opinion no other IDE compares to visual studio. This including xcode as well. But then again I guess that's just my opinion. Also does GCC provide a way to debug your shader code?
      Intel i7 3930k
      8GB Mushkin LP @ 2133 mhz
      GTX 680
      Asus Rampage IV Extreme
      Corsair 650w
    • I'm not sure that even vc++ debugs your shader code, maybe a hook from visual studio that does it?

      In the past I have seen PIX used for debugging HLSL shader code and I have always used gDEBugger for graphical debugging (OpenGL).

      Edit: One other thing that visual studio seems to lack is refactoring capabilities, I was under the impression that 2012 was going to be implementing a refactoring tool set, however it seemed to have got dropped maybe?
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz

      The post was edited 1 time, last by mholley519 ().

    • Yeah vs natively debugs your shader code(DirectX that is). I haven't used code re-factoring yet, but I would love to see something like that implemented in visual studio.
      Intel i7 3930k
      8GB Mushkin LP @ 2133 mhz
      GTX 680
      Asus Rampage IV Extreme
      Corsair 650w