clCreateFromD3D11BufferNV returns CL_INVALID_D3D11_RESOURCE_NV for buffer with D3D11_RESOURCE_MISC_D...

Hi All,

I try to use OpenCL for updating indirect ID3D11buffer, but during calling clCreateFromD3D11BufferNV, i got error CL_INVALID_D3D11_RESOURCE_NV.

The Direct3D11 Debug Runtime will output:

D3D11 ERROR: ID3D11Device::CreateBuffer: Buffers for DrawIndirect can not be created with D3D11_RESOURCE_MISC_SHARED or D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX. [ STATE_CREATION ERROR #68: CREATEBUFFER_INVALIDMISCFLAGS]
Exception thrown at 0x73C7DDC2 in SimpleDX11.exe: Microsoft C++ exception: _com_error at memory location 0x001EEA8C.
D3D11 ERROR: ID3D11Device::CreateBuffer: CreateBuffer returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #69: CREATEBUFFER_INVALIDARG_RETURN]

simple code:

D3D11_BUFFER_DESC bufDesc;
bufDesc.ByteWidth = sizeof(D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS); // 20 bytes
bufDesc.Usage = D3D11_USAGE_DEFAULT;
bufDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
bufDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_SHADER_RESOURCE;
bufDesc.MiscFlags = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS; // Indirect Buffer
bufDesc.StructureByteStride = 0;
ID3D11Buffer* pVertexBufPtr = NULL;
HRESULT hr = hrStatus = pD3D11Device->CreateBuffer(&bufDesc, NULL, &pVertexBufPtr); // pVertexBufPtr - OK
cl_int ret = 0;
// CL_INVALID_D3D11_RESOURCE_NV
cl_mem clBuffer = clCreateFromD3D11BufferNV(context, CL_MEM_WRITE_ONLY, pVertexBufPtr, &ret);

It working fine on any AMD/Intel GPU with OpenCL 1.2 and Direct3D11 with D3D_FEATURE_LEVEL_11_X.

i attached simpe project with executable file.
https://www.dropbox.com/s/eamsw95u9sieg4j/SimpleD3D11.7z?dl=0

It happens for example on nVidia GTX 760, nVidia 610

What do i do wrong ?

I can’t submit bug report
The page https://developer.nvidia.com/nvidia_bug/2291495 not found

That’s not the correct link to submit a new bug report.

See here:

https://devtalk.nvidia.com/default/topic/1037479/serious-bug-in-latest-version-of-cublas-v9-2-cublaszdotc_v2-crashes-on-windows-10-only/?offset=4#5270942

Hi txbob, Thanks you for your responce,
I can see bug in my profile:
https://ibb.co/fREyjT(Bug ID 2291495), but i can’t load this page

I’m not sure what the problem is regarding the external portal. I can see the bug in our internal system, it was logged at 9AM this morning.

Ok, then I will be waiting of fixing OpenCL problem on nVidia hardware :)

Any Update ?
I have additional Information from Direct3D11 Debug Runtime, after calling clCreateFromD3D11BufferNV:

D3D11 ERROR: ID3D11Device::CreateBuffer: Buffers for DrawIndirect can not be created with D3D11_RESOURCE_MISC_SHARED or D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX. [ STATE_CREATION ERROR #68: CREATEBUFFER_INVALIDMISCFLAGS]
Exception thrown at 0x73C7DDC2 in SimpleDX11.exe: Microsoft C++ exception: _com_error at memory location 0x001EEA8C.
D3D11 ERROR: ID3D11Device::CreateBuffer: CreateBuffer returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #69: CREATEBUFFER_INVALIDARG_RETURN]

The application is trying to access cl_khr_d3d11_sharing platform which is not supported.So it is failing.

Hi Robert_Crovella

  1. clCreateFromD3D11BufferNV is not correct for only ID3D11buffer with D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS flag.

  2. if cl_khr_d3d11_sharing doesn’t support, we can use cl_nv_d3d11_sharing, in this case clCreateFromD3D11BufferNV is equal clCreateFromD3D11BufferKHR.

https://www.khronos.org/registry/OpenCL/extensions/nv/cl_nv_d3d11_sharing.txt
https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/clCreateFromD3D11BufferKHR.html

There is example code from attached project:

bool khr_d3d11 = strstr(pbuf, "cl_khr_d3d11_sharing") != NULL;
	bool nv_d3d11 = strstr(pbuf, "cl_nv_d3d11_sharing") != NULL;

	/******************************************************************************
	* Init extension function pointers
	******************************************************************************/ 
	if (khr_d3d11) {
		INIT_CL_EXT_FCN_PTR(clCreateFromD3D11BufferKHR);
		INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D11ObjectsKHR);
		INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D11ObjectsKHR);
		INIT_CL_EXT_FCN_PTR(clGetDeviceIDsFromD3D11KHR);
	}
	else {
		pfn_clCreateFromD3D11BufferKHR = reinterpret_cast<PFN_clCreateFromD3D11BufferKHR>(clGetExtensionFunctionAddress("clCreateFromD3D11BufferNV"));
		pfn_clEnqueueAcquireD3D11ObjectsKHR = reinterpret_cast<PFN_clEnqueueAcquireD3D11ObjectsKHR>(clGetExtensionFunctionAddress("clEnqueueAcquireD3D11ObjectsNV"));
		pfn_clEnqueueReleaseD3D11ObjectsKHR = reinterpret_cast<PFN_clEnqueueReleaseD3D11ObjectsKHR>(clGetExtensionFunctionAddress("clEnqueueReleaseD3D11ObjectsNV"));
		pfn_clGetDeviceIDsFromD3D11KHR = reinterpret_cast<PFN_clGetDeviceIDsFromD3D11KHR>(clGetExtensionFunctionAddress("clGetDeviceIDsFromD3D11NV"));
	}

Note:

So i have correct code. what do you think about it ?

I’m not sure I understand what it is you are asking.

But NVIDIA does recommend that you use cl_nv_d3d11_sharing in place of cl_khr_d3d11_sharing at this time.

Ok, I’m trying to explain you again:
I can share VertexBuffer between Direct3D11/OpenCL, but I can’t share Indirect Buffer between Direct3D11/OpenCL Why ? Is it nVidia BUG ? I think this is true.

Yes, I agree with you, because I have no any variants to share Direct3D11/OpenCL on nVidia for OpenCL 1.1.