Support of 3-Component Textures

In Visual Studio 2012, C++ AMP introduced concurrency::graphics::texture data container and the support for three component texture formats was not provided in that release. In Visual Studio 2013, the support for the three component texture formats is included. Let’s dive deep down into those details.


Direct3D offers various data source formats for texel element. Few of those formats help to store data in the form of three components. For example, DXGI_FORMAT_R32G32B32_FLOAT indicates that it is a 96-bit floating-point format that supports 32 bits per color channel data. C++ AMP texture objects can now be constructed using these formats. The construction is similar to construction of other multi component textures. The valid combinations of data types and bits_per_scalar_element, which was summarized in our earlier blog posts, can be extended to include the following combinations:


Texture data type

#bits per scalar_element






The three component texture objects save 25% of memory when compared to the texture objects created with four component texels. Despite the advantage of saving the memory, the three component textures are not widely used and they have limited functionalities like below:

  • The regular three component texture format families like R32G32B32 can be used only as input read only buffers. The data in these texture objects cannot be modified.
  • The only three component format that allows both read and writes operations is DXGI_FORMAT_R11G11B10_FLOAT. This is an irregular texture format and texture object for this format needs to be adopted using the texture interop apis. The precision of the data stored in this format is very low as the maximum number of bits used for storing each component is value is 11 bits only in this format. 

Now let’s look at how to use the three component textures in C++ AMP.


As a Readonly Buffer:

 extent<2> imgDim(640,480);
 texture<int3,2> inputImg(imgDim); // Creation of 3 component texture. The underlying D3DTexture object is created using ‘DXGI_FORMAT_R32G32B32_INT’ format
 copy(,rawImg.size() * sizeof(int3),inputImg); // rawImg is a std::vector that contains RGB information of each pixel
 texture_view<const int3,2> tx_view(inputImg); // Creation of read only texture_view
 parallel_for_each(imgDim,[tx_view](index<2> idx) restrict(amp) {
     auto grayedOutvalue = (tx_view[idx].r + tx_view[idx].g + tx_view[idx].b)/3;


Please note that trying to write data to ‘inputImg’ like in the below code snippet, will throw runtime_exception with message : Failed to create read-write texture view .

 texture_view<int3,2> wr_view(inputImg);
 parallel_for_each(imgDim,[wr_view](index<2> idx) restrict(amp) {

So, 3 Component textures objects with regular texture formats, can be used only as input buffer.

As an output Buffer:  

We already stated in the above sections that, to use 3 component texture object for write operations, we have to first create the D3DTexture object with format DXGI_FORMAT_R11G11B10_FLOAT and then adopt it in C++ AMP, like in the below code snippet

 extent<2> datapointsGridSize(640,480);
 array_view<const float3,2> inputpoints(datapointsGridSize,datapoints3D); // points3Ddata is a std::vector of x,y,z co-ordinates of each point
 ID3D11Texture2D* normalised_coordinates = create_d3d_texture(datapointsGridSize,DXGI_FORMAT_R11G11B10_FLOAT); // Creating D3DTexture object in the given format to use for writing normalised data
 texture<float3,2> normalisedDatapoints = make_texture<float3,2>(av,normalised_coordinates); // Adopting the texture object.
 texture_view<float3,2> normalised_data_view(normalisedDatapoints); // Creating a view to write data into the texture oject
 parallel_for_each(datapointsGridSize,[inputpoints,normalised_data_view](index<2> idx) restrict(amp) {
     normalised_data_view.set(idx, foo_normlise(input_tx_view[idx].x,input_tx_view[idx].y,input_tx_view[idx].z)); // 'foo_normalise' is any function that returns float3


In Closing

In this post we learnt that C++ AMP textures can now support 3-Component texture data formats. Stay tuned to know what C++ AMP offers you in Visual Studio 2013. As usual, I would love to read your comments below or in our MSDN forum.