CLCREATEFROMD3D11TEX(3clc)
β¨ NAME β¨
clCreateFromD3D11Texture3DKHR β bestie, this one creates an OpenCL 3D image object from a subresource of a Direct3D 11 3D texture. Yes, we're bridging the Direct3D and OpenCL worlds, and yes, it's giving main character energy. π¦
This page lives in the OpenCL Manual, section 3clc, and it's a whole journey, so buckle up. π
πΈ SYNOPSIS πΈ
cl_mem clCreateFromD3D11Texture3DKHR(cl_context context,
cl_mem_flags flags,
ID3D11Texture3D *resource,
UINT subresource,
cl_int *errcode_ret);
π PARAMETERS π
contextβ a valid OpenCL context, and no cap, it has to be one created from a Direct3D 11 device. That's the whole vibe. If it's not, this isn't gonna slay. πflagsβ a bit-field that specifies usage information. It can beCL_MEM_READ_ONLY,CL_MEM_WRITE_ONLY, orCL_MEM_READ_WRITE. That's the whole menu, three options, pick your fighter. π
If you want the full lore on what these flags actually do, go peek at the table over in clCreateBuffer(3clc). It's right there, iykyk.
resourceβ a pointer to the Direct3D 11 texture you're sharing. Hand it over, bestie. π€subresourceβ the subresource ofresourcethat you're sharing. Yes, specifically that one. Not the whole thing. π―errcode_retβ an appropriate error code lives here when the call comes back. But heads up: iferrcode_retisNULL, then no error code gets returned. Nothing. Silence. π So if you want to know what went wrong, pass a real pointer, okay?
π NOTES π
Okay so here's the cute part. π§ The width, height and depth of the returned OpenCL 3D image object? They're determined by the width, height and depth of subresource subresource of resource. Like, it literally mirrors it. β¨
And the channel type and order of the returned OpenCL 3D image object are determined by the format of resource, as shown in the table below. π
Lowkey important: both of those things come straight from the source texture β you don't get to pick them, the texture picks for you. Periodt.
...and bestie, that's only the beginning, there's more of this page coming π
So like, this call increments the internal Direct3D reference count on resource π. And then β plot twist β that same internal Direct3D reference count on resource gets decremented when the OpenCL reference count on the returned OpenCL memory object drops alllll the way down to zero. Bestie, it's giving "we're linked now, ride or die" π«Ά.
π The Format Glow-Up Chart (DXGI β‘οΈ CL image format) π
Okay so here's the β¨mappingβ¨, and you're gonna want to screenshot this. Every DXGI format on the left pairs up with a CL image format on the right, listed as (channel order, channel data type) π:
DXGI_FORMAT_R32G32B32A32_FLOATβCL_RGBA,CL_FLOATDXGI_FORMAT_R32G32B32A32_UINTβCL_RGBA,CL_UNSIGNED_INT32DXGI_FORMAT_R32G32B32A32_SINTβCL_RGBA,CL_SIGNED_INT32DXGI_FORMAT_R16G16B16A16_FLOATβCL_RGBA,CL_HALF_FLOATDXGI_FORMAT_R16G16B16A16_UNORMβCL_RGBA,CL_UNORM_INT16DXGI_FORMAT_R16G16B16A16_UINTβCL_RGBA,CL_UNSIGNED_INT16DXGI_FORMAT_R16G16B16A16_SNORMβCL_RGBA,CL_SNORM_INT16DXGI_FORMAT_R16G16B16A16_SINTβCL_RGBA,CL_SIGNED_INT16DXGI_FORMAT_R8G8B8A8_UNORMβCL_RGBA,CL_UNORM_INT8DXGI_FORMAT_R8G8B8A8_UINTβCL_RGBA,CL_UNSIGNED_INT8DXGI_FORMAT_R8G8B8A8_SNORMβCL_RGBA,CL_SNORM_INT8DXGI_FORMAT_R8G8B8A8_SINTβCL_RGBA,CL_SIGNED_INT8DXGI_FORMAT_R32G32_FLOATβCL_RG,CL_FLOATDXGI_FORMAT_R32G32_UINTβCL_RG,CL_UNSIGNED_INT32DXGI_FORMAT_R32G32_SINTβCL_RG,CL_SIGNED_INT32DXGI_FORMAT_R16G16_FLOATβCL_RG,CL_HALF_FLOATDXGI_FORMAT_R16G16_UNORMβCL_RG,CL_UNORM_INT16DXGI_FORMAT_R16G16_UINTβCL_RG,CL_UNSIGNED_INT16DXGI_FORMAT_R16G16_SNORMβCL_RG,CL_SNORM_INT16DXGI_FORMAT_R16G16_SINTβCL_RG,CL_SIGNED_INT16DXGI_FORMAT_R8G8_UNORMβCL_RG,CL_UNORM_INT8DXGI_FORMAT_R8G8_UINTβCL_RG,CL_UNSIGNED_INT8DXGI_FORMAT_R8G8_SNORMβCL_RG,CL_SNORM_INT8DXGI_FORMAT_R8G8_SINTβCL_RG,CL_SIGNED_INT8DXGI_FORMAT_R32_FLOATβCL_R,CL_FLOATDXGI_FORMAT_R32_UINTβCL_R,CL_UNSIGNED_INT32DXGI_FORMAT_R32_SINTβCL_R,CL_SIGNED_INT32DXGI_FORMAT_R16_FLOATβCL_R,CL_HALF_FLOATDXGI_FORMAT_R16_UNORMβCL_R,CL_UNORM_INT16DXGI_FORMAT_R16_UINTβCL_R,CL_UNSIGNED_INT16DXGI_FORMAT_R16_SNORMβCL_R,CL_SNORM_INT16DXGI_FORMAT_R16_SINTβCL_R,CL_SIGNED_INT16DXGI_FORMAT_R8_UNORMβCL_R,CL_UNORM_INT8DXGI_FORMAT_R8_UINTβCL_R,CL_UNSIGNED_INT8DXGI_FORMAT_R8_SNORMβCL_R,CL_SNORM_INT8DXGI_FORMAT_R8_SINTβCL_R,CL_SIGNED_INT8
π¦ The Tea On Sharing Memory Objects With Direct3D 11 π¦
So, general info about sharing memory objects with Direct3D 11? Coming right up, bestie π .
The goal of this whole extension is to provide interoperability between OpenCL and Direct3D 11 π₯. And the vibe? It's designed to function analogously to the OpenGL interoperability β same energy, different API, iykyk πΈ.
If your implementation supports this extension, then the string cl_khr_d3d11_sharing(3clc) will be present in the CL_PLATFORM_EXTENSIONS or CL_DEVICE_EXTENSIONS string described in the table of allowed values for param_name for clGetDeviceInfo(3clc) β¨. So like, go check those extension strings, that's your vibe check π.
As currently proposed, the interfaces for this extension would be provided in cl_d3d11.h π.
okay so picture this: your app is out here living its Direct3D 11 life, and you want OpenCL to come join the party too. That's literally what this whole little family of functions is for β letting applications use Direct3D 11 resources as OpenCL memory objects. Sharing is caring, and this is efficient sharing of data between OpenCL and Direct3D 11, fr fr.
You can use the OpenCL API to execute kernels that read and/or write memory objects that are <em>also</em> Direct3D 11 resources. An OpenCL image object may be created from a Direct3D 11 texture resource. An OpenCL buffer object may be created from a Direct3D 11 buffer resource. And here's the catch, bestie, and it's a big one: OpenCL memory objects may be created from Direct3D 11 objects if and only if the OpenCL context has been created from a Direct3D 11 device. Periodt. No exceptions, no loopholes.
An OpenCL memory object created from a Direct3D 11 resource stays valid as long as the corresponding Direct3D 11 resource has not been deleted. But if the Direct3D 11 resource is deleted through the Direct3D 11 API, then any subsequent use of the OpenCL memory object will result in undefined behavior, "including but not limited to possible OpenCL errors, data corruption, and program termination." π That is not a vibe check you want to fail.
tl;dr β don't delete the D3D11 resource out from under the OpenCL memory object. Just don't. π
The successful creation of a cl_context against a Direct3D 11 device specified via the context create parameter CL_CONTEXT_D3D11_DEVICE_KHR will increment the internal Direct3D reference count on the specified Direct3D 11 device. And the internal Direct3D reference count on that Direct3D 11 device will be decremented when the OpenCL reference count on the returned OpenCL context drops to zero. So like, they're holding hands the whole time. π«Ά
The OpenCL context and corresponding command-queues are dependent on the existence of the Direct3D 11 device from which the OpenCL context was created. If the Direct3D 11 device is deleted through the Direct3D 11 API, subsequent use of the OpenCL context will result in undefined behavior, including but not limited to possible OpenCL errors, data corruption, and program termination. Same energy as before. Same consequences. π
Properties of Direct3D 11 objects may be queried using clGetMemObjectInfo(3clc) and clGetImageInfo(3clc) with param_name CL_MEM_D3D11_RESOURCE_KHR and CL_IMAGE_D3D11_SUBRESOURCE_KHR as described for clGetImageInfo(3clc) and in the information below about accessing mapped regions of a memory object.
Accessing mapped regions of a memory object πΊοΈ
This section describes the behavior of OpenCL commands that access mapped regions of a memory object. Buckle up. β¨
The contents of the region of a memory object and associated memory objects (sub-buffer objects or 1D image buffer objects that overlap this region) mapped for writing β i.e. CL_MAP_WRITE or CL_MAP_WRITE_INVALIDATE_REGION is set in the map_flags argument to clEnqueueMapBuffer(3clc) or clEnqueueMapImage(3clc) β are considered to be undefined until this region is unmapped. So like, don't peek at it. It's giving "he's not answering for a reason." π
Multiple commands in command-queues can map a region or overlapping regions of a memory object and associated memory objects (sub-buffer objects or 1D image buffer objects that overlap this region) for reading β i.e. map_flags = CL_MAP_READ. And the contents of the regions of a memory object mapped for reading can <em>also</em> be read by kernels and other OpenCL commands (such as clEnqueueCopyBuffer(3clc)) executing on a device(s). Everyone can read, it's a whole group chat. π
But mapping (and unmapping) overlapped regions in a memory object and/or associated memory objects (sub-buffer objects or 1D image buffer objects that overlap this region) for writing is an error and will result in a CL_INVALID_OPERATION error returned by clEnqueueMapBuffer(3clc) or clEnqueueMapImage(3clc). That's a hard no. π«
If a memory object is currently mapped for writing, the application must ensure that the memory object is unmapped before any enqueued kernels or commands that read from or write to this memory object or any of its associated memory objects (sub-buffer or 1D image buffer objects) or its parent object (if the memory object is a sub-buffer or 1D image buffer object) begin execution; otherwise the behavior is undefined. Unmap first. That's the whole rule. π
If a memory object is currently mapped for reading, the application must ensure that the memory object is unmapped before any enqueued kernels or commands that write to this memory object or any of its associated memory objects (sub-buffer or 1D image buffer objects) or its parent object (if the memory object is a sub-buffer or 1D image buffer object) begin execution; otherwise the behavior is undefined. Yes, even for reads. Yes, it matters. π€
Accessing the contents of the memory region referred to by the mapped pointer that has been unmapped is undefined. The pointer is expired, bestie, it's a ghost, let it go. π»
The mapped pointer returned by clEnqueueMapBuffer(3clc) or clEnqueueMapImage(3clc) can be used as the ptr argument value to clEnqueueReadBuffer(3clc), clEnqueueWriteBuffer(3clc), clEnqueueReadBufferRect(3clc), clEnqueueWriteBufferRect(3clc), clEnqueueReadImage(3clc), and clEnqueueWriteImage(3clc), provided the rules described above are adhered to. So you <em>can</em> pass it around β just respect the rules, okay? π€
β¨ ERRORS β¨
Returns CL_SUCCESS returns a valid non-zero OpenCL image object and errcode_ret is set to CL_SUCCESS if the image object is created successfully. Otherwise, it returns a NULL value with one of the following error values returned in errcode_ret:
CL_INVALID_CONTEXTβ ifcontextis not a valid context. Bestie, that's not a context. πCL_INVALID_VALUEβ if the values specified inflagsare not valid, or ifsubresourceis not a valid subresource index forresource.CL_INVALID_D3D11_RESOURCE_KHRβ ifresourceis not a Direct3D 11 texture resource, ifresourcewas created with theD3D11_USAGEflagD3D11_USAGE_IMMUTABLE, if aresourceis a multisampled texture, ifcl_memfromsubresourcesubresourceofresourcehas already been created usingclCreateFromD3D11Texture3DKHR, or ifcontextwas not created against the same Direct3D 11 device from whichresourcewas created. That's a lot of ways to fail, but okay. π«CL_INVALID_D3D11_RESOURCE_KHRβ ifresourceis not a Direct3D 11 texture object.CL_INVALID_IMAGE_FORMAT_DESCRIPTORβ if the Direct3D 11 texture format ofresourceis not a value listed in the table above of Direct3D 11 and corresponding OpenCL image formats forclCreateFromD3D11Texture3DKHR(3clc), or if the Direct3D 11 texture format ofresourcedoes not map to a supported OpenCL image format.CL_OUT_OF_HOST_MEMORYβ if there is a failure to allocate resources required by the OpenCL implementation on the host. The host said "I'm full." π½οΈ
π SPECIFICATION
OpenCL Specification[1]
π SEE ALSO
cl_khr_d3d11_sharing(3clc)clGetDeviceIDsFromD3D11KHR(3clc)clCreateFromD3D11BufferKHR(3clc)clCreateFromD3D11Texture3DKHR(3clc)clEnqueueAcquireD3D11ObjectsKHR(3clc)clEnqueueReleaseD3D11ObjectsKHR(3clc)
π«Ά AUTHORS
The Khronos Group
Β© COPYRIGHT
Copyright Β© 2007-2011 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.
π NOTES
- OpenCL Specification page 106, section 9.11.7.4 - Sharing Direct3D 11 Texture and Resources....
and that's the whole page, bestie!! π This icon of a document was brought to you by The Khronos Group, dated 01/14/2021, and it lives in the manpage as CLCREATEFROMD3D11TEX(3clc). Go forth and share your D3D11 resources responsibly. πβ¨π
π¦ where this page comes from
- ubuntu jammy: opencl-1.2-man-doc 1.0~svn33624-5 Β· other
- ubuntu noble: opencl-1.2-man-doc 1.0~svn33624-5 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms