前面说过可以通过map函数来用cpu来读写gpu的计算数据。这几天又看了些文章后,感觉自己前面的理解有点肤浅。再来补充总结下。
首先如果想更新GPU中的resource,1是可以通过map()函数来让CPU读写GPU的数据;2还可以通过ID3D11DeviceContext::CopyResource(),ID3D11DeviceContext::UpdateSubresource()等来直接让GPU写更新它自己的resource。
对于上面几个方法的异同呢,可以参考SDK如下: Each usage dictates a tradeoff between functionality and performance. In general, resource accessing is accomplished with the following APIs. CPU access is done with ID3D11DeviceContext::Map. GPU access is done with ID3D11DeviceContext::CopySubresourceRegion, ID3D11DeviceContext::CopyResource, or ID3D11DeviceContext::UpdateSubresource.
从上简单看出采用Map(),通过CPU能access resource,剩下的方法是直接让GPU来access resource。 为了将让我们理解的数据(int,float之类)输出到屏幕控制台之类的(gpu没有传统的i/o功能),我们还是要通过cpu来读写gpu中的数据。当然如果只是GPU内部的计算,就让GPU来读写就可以了。
至于在创建哪种GPU读写或者CPU读写的buffer的时候,要非常注意。其中我们都会先创建一个D3D11_BUFFER_DESC来描述我们的buffer。在D3D11_BUFFER_DESC里面,有个D3D11_USAGE Usage,它