direct3d namespace and HLSL intrinsics in C++ AMP

As you know by now, as a rule most functionality in C++ AMP is in the concurrency namespace. The exception to that is the C++ AMP math library which introduces two sub namespaces (precise_math and fast_math), and the textures and short vector types which introduce one sub namespace (graphics).

The other sub namespace is direct3d.

direct3d namespace

You’ve already seen in the concurrency::direct3d namespace four DirectX Interop APIs. In concurrency::graphics::direct3d there are two more for interop with textures, plus some aliased functions for short vector types.

In the concurrency::direct3d namespace there are also 20 functions that you can find in <amp.h>. These intrinsics are offered when you do HLSL programming and, we decided to offer them through C++ AMP too. You can only call them from restrict(amp) functions. The list below is for your reference and it includes links to the HLSL documentation (I also encourage you to open the header file and look at our xml comments in there for each function).

  1. int abs(int _X)
  2. float clamp(float _X, float _Min, float _Max)
  3. int clamp(int _X, int _Min, int _Max)
  4. unsigned int countbits(unsigned int _X)
  5. int firstbithigh(int _X)
  6. int firstbitlow(int _X)
  7. int imax(int _X, int _Y)
  8. int imin(int _X, int _Y)
  9. float mad(float _X, float _Y, float _Z)
  10. double mad(double _X, double _Y, double _Z)
  11. int mad(int _X, int _Y, int _Z)
  12. unsigned int mad(unsigned int _X, unsigned int _Y, unsigned int _Z)
  13. float noise(float _X)
  14. float radians(float _X)
  15. float rcp(float _X)
  16. unsigned int reversebits(unsigned int _X)
  17. float saturate(float _X)
  18. int sign(int _X)
  19. float smoothstep(float _Min, float _Max, float _X)
  20. float step(float _Y, float _X)

And that is all you will find in the direct3d namespace.

HLSL intrinsics

Beyond the aforementioned 20 functions, you may be wondering about other HLSL intrinsics and access to them through C++ AMP. Well, if we haven’t wrapped them for you, then you cannot use them. However we have done exactly that for many of them in our fast_math namespace, debug functions, memory fences & barriers, and our atomic operations. If there are other intrinsics that we left out, please ask us about them (e.g. in our MSDN Forum) so we can potentially suggest a workaround or so we can consider them for a future release…

Comments (3)

  1. Brandon Furtwangler says:

    Why exactly is direct3d called out for anything other than interop?  If Apple wanted to implement your open standard on top of opengl would you expect them to duplicate these functions in an opengl namespace? It seems to me that any common graphics api should be in a common namespace.

  2. I was thinking the same thing, @Brandon.

  3. DanielMoth says:

    Brandon, thanks for the questions.

    For your first question: the direct3d namespace has 6 DirectX interop APIs, some aliased functions for SVTs, plus these 20 little functions – that is all, as per the post above. If that was not clear, let me know how I could have made it clearer, or elaborate/rephrase your question if I misunderstood it.

    For your second question, the direct3d namespace is optional in the open spec, so other implementers could implement it if they wanted, but don’t have to if they are not willing or able. Implementers that want to implement interop to other graphics stacks, can add their own interop extensions. In fact, even the entire graphics namespace is optional, since C++ AMP can be implemented for non-graphics hardware. For more on what is optional in the spec and what not, please download it from here:…/c-amp-open-spec-published.aspx

Skip to main content