dx12 open 4x msaa failed - directx-12

I am just learning "introduction to 3D game programming with DirectX 12".Running the example code in initialize d3d(chapter 4),when I wanna use 4xmsaa,something wrong was happened,like the follow figure,please help me.
wrong figure

In keeping with the DirectX 12 design philosophy of "no magic runtime behavior", you aren't allowed to create a backbuffer as MSAA. This is because the video output hardware can't actually present MSAA backbuffers, so they have to be resolved to a single pixel each at some point in the pipeline. In DirectX 11, this was done 'behind the scenes' when you created an MSAA backbuffer. In DirectX 12, you are responsible for creating the MSAA render target texture yourself, and then perform the resolve to the backbuffer -or- run some other postprocess that does the resolve. The set up is exactly the same, just more verbose and explicit and under application control instead of being 'magic'.
See the SimpleMSAA12 sample.
With DirectX 12 you also aren't allowed to create sRGB format backbuffers. You can create sRGB render target views that will perform the gamma while writing to the backbuffer. There were some bugs in the older debug layers and Windows 10 runtime when doing direct resolves of sRGB MSAA render targets to non-sRGB backbuffers. These are also noted in the sample above.
Note that UWP apps have exactly the same behavior as DirectX 12 for Win32 desktop apps. This is because both UWP apps and DirectX 12 are required to use the DXGI_SWAP_EFFECT_FLIP_* swap effects instead of the legacy DXGI_SWAP_EFFECT_* swap modes.
BTW, if you had enabled DXGI debugging, you'd have gotten some specific debug diagnostic output when you tried to create the 4x MSAA backbuffer:
DXGI ERROR: IDXGIFactory::CreateSwapChain: Flip model swapchains (
DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL
and DXGI_SWAP_EFFECT_FLIP_DISCARD) do not support multisampling.
[ MISCELLANEOUS ERROR #102: ]
Take a look at this blog post for details on enabling DXGI debugging in your project, or take a look at the implementation of DeviceResources.

Related

what is multisample per pixel in directx11 DXGI_SAMPLE_DECS

I was reading documentation about DXGI_SWAP_CHAIN_DESC and i came across with DXGI_SAMPLE_DESC
Count
Type: UINT
The number of multisamples per pixel.
now what exactly is multisamples per pixel?
DXGI_SAMPLE_DESC as you surmised is for specifying Multi-Sample Anti-Aliasing (MSAA).
That said, you should be aware that the SwapChain support for MSAA is not something you should use anymore. As such, just always set DXGI_SWAP_CHAIN_DESC.SampleDesc.Count = 1; and DXGI_SWAP_CHAIN_DESC.SampleDesc.Quality = 0;.
Instead, to use MSAA you should explicitly create your own MSAA render target and explicitly resolve the result yourself as part of your presentation of the results to the single-sample SwapChain. For details on why and how, see this blog post series.
Note that you can use MSAA SwapChains for DirectX 11 with the older DXGI_SWAP_EFFECT_DISCARD and DXGI_SWAP_EFFECT_SEQUENTIAL flip-effects, and the DirectX 11 runtime will do the resolve automatically. Per the blog post, this is NOT supported for DirectX 12 or the use of modern DXGI_SWAP_EFFECT_FLIP_DISCARD or DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL swap effects. This is really a 'toy' setup as any production rendering will do additional processing after the resolve from multi-sample to single-sample before putting it into the swapchain for display.
As you are likely new to DirectX 11, you may want to look at DirectX Tool Kit. I have a tutorial that covers MSAA.
ok it is anti-aliasing (my bad i didn't know that)
Anti-aliasing is a technique used by users to get rid of jaggies that form on the screen. Since pixels are rectangular, they form small jagged edges when used to display round edges. Anti-aliasing tries to smooth out the shape and produce perfect round edges.

How Can I implement MSAA on DX12?

I Searched many other questions and samples, but I still can't understand what I must do.
What I know about this process is
Create a Render Target for msaa. - Different from SwapChain's Backbuffer.
Draw everything (like meshes) on msaa render target.
Copy the contents of the msaa Render Target to the current BackBuffer using the ResolveSubresource function.
Is this the right process? Or is there a part that I left out?
These samples demonstrate using MSAA with DirectX12:
https://github.com/microsoft/Xbox-ATG-Samples/tree/master/PCSamples/IntroGraphics/SimpleMSAA_PC12
https://github.com/microsoft/Xbox-ATG-Samples/tree/master/UWPSamples/IntroGraphics/SimpleMSAA_UWP12
I also cover this (among other topics) in this blog series.
Per the comments, you can also find MSAA covered in the DirectX Tool Kit for DX12 tutorials.

Combining DirectX 9 and DirectX 11 rendering in one application

I'm currently developing a renderer in C++ for a games company I work for and I'm restricted to using DirectX 9 libraries. This is because the target hardware our games run on on requires our games to create and use a Dx9 device that they can hook in to via a dll in order to do some custom drawing of overlays over our games.
The frustrating thing is the hardware is capable of running DirectX 11 (which we've tried and tested) but because our hardware provider won't update the dll that draws the overlays we're stuck with using a Dx9 device, which we can't even upgrade to an extended device, and this limits the things we can do with respect to shaders and other improvements that Dx11 brings.
I was wondering if it would be possible to have a Dx11 and Dx9 device running side by side in the same application with the Dx11 device doing all the behind the scenes work whilst using the Dx9 device to present the render target of the Dx11 pipeline. That way we could implement Dx11 shaders but still have a Dx9 device doing the "drawing" to screen that the third party dll could still hook in to and draw overlays over? I was thinking something like setting a Dx9 device texture as a render target to the Dx11 pipeline but I'm not sure thats even possible?
Any feedback, comments or advice on whether these ideas would be possible or if there are any alternatives that I'm not thinking of would be welcome.
Thanks in advance.

Creating a texture from a image in DX 12 VC++

I just want know Directx 12 API to create texture from image.
For DX11 it is D3DX11CreateShaderResourceViewFromFile and for DX9 it is D3DXCreateTextureFromFileEx and for DX12 ?
Things are a little bit better by now. Microsoft rewrote their DDSTextureLoader for DX12 and released it as part of their MiniEngine on GitHub
https://github.com/Microsoft/DirectX-Graphics-Samples/blob/master/MiniEngine/Core/DDSTextureLoader.cpp
You also may want to take a look at my derivative work that is intended to make use of the DDSTextureLoader a bit easier outside of MiniEngine.
https://github.com/ClemensX/ShadedPath12/blob/master/ShadedPath12/ShadedPath12/DDSTextureLoader.cpp
I use this loader for all my texture files. It parses DDS (DirectDrawSurface) file format pretty well, including mipmaps.
There isn't one.
Direct3D 12 is a low-level API. A very low-level API. It doesn't have convenience functions that create textures out of whole cloth from just a filename. If you want to create a texture, you have to work for it. You have to load the file, figure out what format you want it in, allocate memory for it by asking the system how much memory it would take, then go through a complex series of steps to transfer your loaded image into that memory.
The official 'utility header' for Direct3D 12 is d3dx12.h. It's an inline header and has no DLL or static library, so the functionality provided is limited to true helpers. It has no equivalent to D3DX11CreateShaderResourceViewFromFile. It is not included as part of the Windows SDK, but instead is provided under the MIT license and you are expected to just copy it into your project--it's included in the various DirectX 12 Visual Studio templates including my Direct3D Game templates.
You can use the DDSTextureLoader and WICTextureLoader modules provided in the DirectX Tool Kit for DirectX 12 for some ready-to-use texture loader for Direct3D 12. See this tutorial lesson.
It's worth noting that D3DX9, D3DX10, and D3DX11 are all deprecated and only available as part of the legacy DirectX SDK per MSDN. In other words, you shouldn't be using D3DX11CreateShaderResourceViewFromFile for your Direct3D 11 code. See this blog post for a full list of D3DX9/10/11 replacements. TL;DR: use DDSTextureLoader and WICTextureLoader in DirectX Tool Kit for DirectX 11.
Google keeps referring to this topic for questions around DX-12 and textures, so let's update.
1. Managed
If you insist on "managed" check out the samples with the last version of SharpDX (2019)
https://github.com/discosultan/dx12-game-programming
It provides a C# interface to DX-12 native and it works, there are a lot of very nice samples, including texturing,
09-Crate loads a single DDS texture and shows it on a cube
09-TexColumns shows basic UV-coordinate actions on various shapes
.. but IMHO it's not really advisable, to keep depending on the good old SharpDX library, because that library is not maintained anymore. I can't advise good alternatives for C# atm, I'm not an expert on Unity and Vulkan.
2. Unmanaged
As mentioned earlier in this topic, DX-12 things improve. They still do. Check out Chuck Walbourn's current samples here,
https://github.com/microsoft/Xbox-ATG-Samples
For straight PC/x64, you'll find this,
https://github.com/microsoft/Xbox-ATG-Samples/tree/master/PCSamples
For PC/UWP, you'll find this,
https://github.com/microsoft/Xbox-ATG-Samples/tree/master/UWPSamples
These are very nice x64 unmanaged C++ 14.0 examples, using DirectXtk for DirectX-12. Last update in the Master was 3 months ago. Examples involving textures, also straight bitmap textures are
SimpleTexturePC12 loads a single .jpg texture and shows it in front view
DirectXTKSimpleSample12 loads several textures
Graphics\VideoTexturePC12 shows a dynamic texture read from an .mp4 video
These projects are configured for VS2017, but they convert out of the box when loading them in VS2019 and they compile and run ok.
Other sources
A known switchboard on DX-12 is vinjn on github, his page is
http://www.vinjn.com/awesome-d3d12/
Navigate from there to study articles and find various other samples.
There is a 3dgep.com tutorial on the subject of DX12 textures, that is
https://www.3dgep.com/learning-directx-12-4/
.. accompanied by
https://github.com/jpvanoosten/LearningDirectX12

DirectX11 Non-Solid wireframe

I'm attempting to draw a 100x100 grid in DirectX11 using C++, but the following issue happens:
The image above shows a grid I am drawing in wireframe, using a rasterizer with its fillmode set to 'D3D11_FILL_WIREFRAME' and a 'D3D11_PRIMITIVE_TOPOLOGY_LINELIST' topology. The lines of the wireframe appear staggered rather than straight, with some parts of the wireframe missing.
As I'm not sure what this issue is referred to as, I'm not entirely sure what I should be looking for and as such, any help is appreciated.
This is a classic problem of 'aliasing'.
With Direct3D 11, you can use either MSAA which is a general anti-aliasing option, or use a specific line algorithm if you are not using MSAA. See D3D11_RASTERIZER_DESC AntialiasedLineEnable and MultisampleEnable.
See Aliasing and Multisample anti-aliasing
UPDATE: I've added MSAA and the AA mode to the DirectX Tool Kit tutorial.
I stumbled across the solution to this and it wasn't what I expected at all. Since the window I created had outline bars, the windows client area was being misrepresented. So when I was creating my graphics device, I was initializing it with the windows size, rather than the windows client size. Somehow, this caused the issue above.
I fixed this by implementing a 'GetClientSize' method for the window, using 'GetWindowRect'.