10 Replies Latest reply on May 6, 2010 2:07 AM by genaganna

    Questions about d3d9 interop: Which is the correct way? is API stable?

    oscarbarenys1

      Hi I have coded some example trying to see how d3d interop works..

      I see up to three APIs one is

      KB91 - Additional Header File Required For Preview Feature: ATI Stream SDK v2.01 Support for OpenCL™ / Microsoft® DirectX® 9 & 10 Interoperability

      wich shows in cl_amd.hpp clEnqueueReleaseExternalObjects similar to clEnqueueReleaseGLObjects for gl interop..

      this seems to be the correct way according to KB but I can't find clEnqueueReleaseExternalObjects with clGetExtensionFunctionAddress so I also

      in cl_d3d9.h I see

      clEnqueueAcquireD3D9ObjectsKHR which is another way..

      this is found by clGetExtensionFunctionAddress

      then for buffer interop similarly we found two functions:

      clCreateFromD3D9BufferKHR

      and then below is

      "//
      // Legacy AMD CL-D3D9 interop extension
      //"
      with

      clCreateFromD3D9Buffer

      function.

      With clGetExtensionFunctionAddress I found clCreateFromD3D9BufferKHR which is the correct I think.

      also I'm asking for correct texture interop(yeah I know is image support required but I'm talking having correct/stable source code here not testing)

      I must use this clCreateFromD3D9TextureKHR?

      For testing I create context with

       cl_context_properties cps[6] =
          {
              CL_CONTEXT_PLATFORM,
              (cl_context_properties)platform,
              CL_CONTEXT_D3D9_DEVICE,
              (cl_context_properties)g_pd3dDevice,
              0
          };

      with a D3d device created and then use

       CL_API_ENTRY cl_mem (CL_API_CALL
      *myclCreateFromD3D9TextureKHR)(
          cl_context          /* context */,
          cl_mem_flags        /* flags */,
          IDirect3DTexture9 * /* texture */,
          HANDLE              /* shared_handle */,
          UINT                /* miplevel */,
          cl_int *            /* errcode_ret */);

      myclCreateFromD3D9TextureKHR=(P2)clGetExtensionFunctionAddress("clCreateFromD3D9TextureKHR")

      as clCreateFromD3D9TextureKHR is defined already in header.

      then calling

      myclCreateFromD3D9TextureKHR(context,CL_MEM_READ_WRITE,g_inputTex,g_handle,0,&status);

      where  g_inputTex is created and g_handle is the last parameter returned by CreateTexture. Is this correct?

      In this way I get runtime error after enabling images with "set GPU_IMAGES_SUPPORT=1"

      setting the Handle shader parameter to NULL

      myclCreateFromD3D9TextureKHR(context,CL_MEM_READ_WRITE,g_inputTex,NULL,0,&status);

      returns an CL_INVALID_D3D_OBJECT

      What's the correct API? Is that stable?

      Is there any sample showing interop?

      is d3d11 interop coming? as nvidia has one d3d11 extension published in khronos registry?..

        • Questions about d3d9 interop: Which is the correct way? is API stable?
          MicahVillmow
          oscar,
          I discussed with the engineer that did this work and he stated that we do not currently support Texture with D3D interop, only through buffers. Also officially d3d9 interop is not yet accepted by Khronos, so the API isn't standardized. The correct call to use should be 'clCreateFromD3D9BufferKHR'. Also, images are not officially supported yet, so we don't guarantee that it works.
            • Questions about d3d9 interop: Which is the correct way? is API stable?Mi
              oscarbarenys1

              Thanks Micah,

              for being fair I have tested Nvidia d3d10 interop (Nvidia APis seem final and are very similar)(d3d10 are the only current entry poins found) and they are reporting initialization issues so no go..

              I hope you implement d3d texture interop sooner than ogl as CAL has cal-d3d interop example with texture interop working..

               

              • Questions about d3d9 interop: Which is the correct way? is API stable?
                wb0330

                Hi Micah,

                 i do some similar work to test d3d interop use "clCreateFromD3D9BufferKHR" on my Radeon HD4850 card, and also get CL_INVALID_D3D_OBJECT error. can you give some suggestions?

                 My code sample :

                 //Create  context with D3D_Device.

                 cl_context_properties cps[3] =
                 {
                  CL_CONTEXT_D3D9_DEVICE,
                  (cl_context_properties)m_pD3DDevice,
                  0
                 };

                    cl_context_properties* cprops =  cps;

                 context = clCreateContext(
                  cprops,
                  ciDeviceCount,
                  cdDevices,
                  0,
                  0,
                  &status) ;

                //Get the Function Address:clCreateFromD3D9BufferKHR

                 typedef CL_API_ENTRY cl_mem (CL_API_CALL *Fun_clCreateFromD3D9BufferKHR)(
                  cl_context           /* context */,
                  cl_mem_flags         /* flags */,
                  IDirect3DResource9 * /* resource */,
                  HANDLE               /* shared_handle */,
                  cl_int *             /* errcode_ret */);

                 Fun_clCreateFromD3D9BufferKHR myclCreateFromD3D9BufferKHR = 0;

                 myclCreateFromD3D9BufferKHR= (Fun_clCreateFromD3D9BufferKHR)clGetExtensionFunctionAddress("clCreateFromD3D9BufferKHR");

                // Create D3Dsurface and get the handle.


                 HRESULT hr = m_pD3DDevice->CreateOffscreenPlainSurface(width,
                  height, 
                  (D3DFORMAT)MAKEFOURCC('N','V','1','2'),
                  D3DPOOL_DEFAULT,
                  &m_d3dOutputSurface,
                  &m_hD3Dhandle);

                //Map the D3DSurface to cl_mem

                 outputBuffer = myclCreateFromD3D9BufferKHR(
                  context,
                  CL_MEM_READ_WRITE,
                  m_d3dOutputSurface,
                  m_hD3Dhandle,
                  &status);

                Then get the Return error status = -60(CL_INVALID_D3D_OBJECT,CL_INVALID_GL_OBJECT)

                  • Questions about d3d9 interop: Which is the correct way? is API stable?
                    genaganna

                     

                    Originally posted by: wb0330 Hi Micah,

                     

                     i do some similar work to test d3d interop use "clCreateFromD3D9BufferKHR" on my Radeon HD4850 card, and also get CL_INVALID_D3D_OBJECT error. can you give some suggestions?

                     

                     My code sample :

                     

                     //Create  context with D3D_Device.

                     

                     cl_context_properties cps[3] =  {   CL_CONTEXT_D3D9_DEVICE,   (cl_context_properties)m_pD3DDevice,   0  };

                     

                        cl_context_properties* cprops =  cps;

                     

                     context = clCreateContext(   cprops,   ciDeviceCount,   cdDevices,   0,   0,   &status) ;

                     

                    //Get the Function Address:clCreateFromD3D9BufferKHR

                     

                     typedef CL_API_ENTRY cl_mem (CL_API_CALL *Fun_clCreateFromD3D9BufferKHR)(   cl_context           /* context */,   cl_mem_flags         /* flags */,   IDirect3DResource9 * /* resource */,   HANDLE               /* shared_handle */,   cl_int *             /* errcode_ret */);

                     

                     Fun_clCreateFromD3D9BufferKHR myclCreateFromD3D9BufferKHR = 0;

                     

                     myclCreateFromD3D9BufferKHR= (Fun_clCreateFromD3D9BufferKHR)clGetExtensionFunctionAddress("clCreateFromD3D9BufferKHR");

                     

                    // Create D3Dsurface and get the handle.

                     

                     HRESULT hr = m_pD3DDevice->CreateOffscreenPlainSurface(width,   height,    (D3DFORMAT)MAKEFOURCC('N','V','1','2'),   D3DPOOL_DEFAULT,   &m_d3dOutputSurface,   &m_hD3Dhandle);

                     

                    //Map the D3DSurface to cl_mem

                     

                     outputBuffer = myclCreateFromD3D9BufferKHR(   context,   CL_MEM_READ_WRITE,   m_d3dOutputSurface,   m_hD3Dhandle,   &status);

                     

                    Then get the Return error status = -60(CL_INVALID_D3D_OBJECT,CL_INVALID_GL_OBJECT)

                     



                    In SDK2.1,  D3D9 interop is not supported.  It is expected to support in upcoming releases.