Several things you must know about d3d11 (2)

Source: Internet
Author: User
Reprinted please indicate the source for the klayge game engine, this article address for http://www.klayge.org/2011/08/12/%e5%85%b3%e4%ba%8ed3d11%ef%bc%8c%e4%bd%a0%e5%bf%85%e9%a1%bb%e4%ba%86%e8%a7%a3%e7%9a%84%e5%87%a0%e4%bb%b6%e4%ba%8b%e6%83%85%ef%bc%88%e4%ba%8c%ef%bc%89/

The Feature Level and option features are the two most misunderstood d3d11 features. This article mainly discusses the other two important features: Compute shader and multi-threaded. They can also be used on d3d10 hardware, but there are many details to note.

Compute shader

Compute shader (also called directcompute) is one of the main new functions of d3d11. On the d3d11 GPU, compute shader is the complete version 5.0, while on the d3d10. x GPU, compute shader has a simplified version 4. x. For specific differences between the two, see compute shaders on downlevel hardware.

One of the important disadvantages of CS 4.x is that it does not support rwtexture, so shader cannot write texture and can only write buffer. (This is caused by NV. AMD's hardware has been able to write rwtexture for a long time, but because CS 4.x requires compatibility with NV and AMD at the same time, it gives up writing rwtexture. I believe that my friends who have used Cuda 2.0 know about this issue) the result is that CS 4.x cannot be used for post process operations. A solution is to write the results of compute shader to the buffer. To use the graphic assembly line, call a pixel shader to convert the buffer to texture. CS 4. X can use texture and buffer as input and buffer as output, while PS 4 in d3d11. X can use texture and buffer as input and texture as output, so the two can be combined to implement the pipeline from texture to texture.

However, when switching from CS to the graphics pipeline, a significant delay of several milliseconds may occur on the Nv card, regardless of CS 4.x or 5.0. Therefore, the number of switching times for each frame should be minimized. There is no such problem in amd cards.

CS 4.x also has an important disadvantage. Although each thread can read shared memory of any address, it can only write its own shared memory unit, so it cannot use the stride layout commonly used in Cuda. (This is AMD's implementation limitation. Or because of compatibility requirements, even if NV can do it) A common practice is to declare a struct with all the shared variables you need. With such a struct to declare shared memory, you can write multiple values.

Multi-threaded

D3d11 is added with explicit multi-threaded support. It divides the d3d10 interface into two parts. The functions responsible for Resource Creation belong to id3d11device, and the rest are divided into id3d11devicecontext. Id3d11device is thread-safe. If the driver does not support parallel Resource Creation, the runtime will be locked to ensure thread security (unless it is forcibly disabled by using d3d11_create_device_singlethreaded ). Id3d11devicecontext is NOT thread-safe and must be implemented by the upper layer.CodeHandle it by yourself.

The device context of d3d11 is divided into immediate context and deferred context. All commands of immediate context are executed immediately. Deferred context stores the commands in the list and starts execution only when the command is submitted. Because the CPU needs to do some extra work when calling draw, it will improve performance if the draw call is distributed to multiple cores for execution.

High-performance use of this multithreading requires driver support. Currently, GPUs generally have multiple command units, but the driver often does not enable multi-threaded functions. Currently, both d3d11 and d3d10 do not support multi-threaded. All deferred context is implemented by software, so the performance is not improved or decreased. One day, we hope the driver can be improved to support it, so that developers can use the efficient deferred context.

So far, the next article will talk about tessellation and the new texture compression format.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.