C++ AMP in Visual Studio 2012 had the ability to create staging array which helped in optimizing data transfer cost between the host and accelerator_view. In C++ AMP in Visual Studio 2013, we have enhanced the texture by adding the capability to create staging texture which brings in same benefits and has same semantics as that of staging array.
Creating Staging Texture
Similar to staging array, staging textures have the notion of associated accelerator_view. The associated accelerator_view is a hint to C++ AMP runtime as the intended destination for copying to/from the staging texture. For each constructor, that creates a texture on an accelerator in C++ AMP in Visual Studio 2012, we have a corresponding constructor for creating staging texture in C++ AMP in Visual Studio 2013. The only different being that constructors for staging textures (similar to staging array) take an additional parameter: associated accelerator_view.
Copy Constructing Staging Texture
A staging texture can be copy constructed either from another staging texture or from a texture on an accelerator (and vice-versa).
Accessing Staging Texture on CPU
Staging texture is primarily designed to only serve as a data storage medium that can provide optimum copy performance. It is not intended to be used for computation or data manipulation on CPU. Hence, the indexing and get/set operations on a texture are only supported on accelerator and are not available to staging texture. However, one can get pointer to underlying data of a staging texture by using the ‘data()’ member function and use it for modifying underlying data on host.
Due to memory alignment needs the underlying data of staging texture is padded and hence the size of each dimension cannot be used to navigate the raw data. Staging texture provides two properties ‘row_ pitch’ and ‘depth_pitch’ which can be used to navigate the raw data. The ‘row_ pitch’ of a 2D or 3D staging texture refers to the number of bytes needed to navigate from one row to the next row. The ‘depth_pitch’ of a 3D staging texture refers to the number of bytes needed to advance to navigate from once depth slice to next depth slice.
Interop with DirectX
Interop with staging textures has the same experience as that of interop with texture. The only requirement for adopting a DirectX staging texture into C++ AMP is that it should be a read-write staging texture.
Creating Texture View on Staging Texture
You cannot create a texture view on top of a staging texture. This is because staging texture is not intended to perform texture based computation on CPU and hence there is no CPU scenario which necessitates creation of these types.
Similar to the staging array, staging texture cannot be captured in a parallel_for_each kernel, accessing the data underlying a staging texture while a copy operation is in progress can result in undefined behavior and the pointer to the underlying data must not be cached across copy operation involving the staging texture.
I hope you now have a better understanding of staging texture that will enable you to use it efficiently in you code. As usual, I would love to read your comments below or in our MSDN forum.