CLGETDEVICEIDSFROMDX(3clc)
π CLGETDEVICEIDSFROMDX π
okay bestie, we're diving into clGetDeviceIDsFromDX9MediaAdapterKHR from the OpenCL Manual (3clc), and honestly? it's giving "let me find the OpenCL devices that vibe with your media adapter." stay with me, this one's a two-parter π«Ά
β¨ NAME β¨
clGetDeviceIDsFromDX9MediaAdapterKHR β Query a media adapter for any associated OpenCL devices.
cl_int clGetDeviceIDsFromDX9MediaAdapterKHR(cl_platform_id platform,
cl_uint num_media_adapters,
cl_dx9_media_adapter_type_khr *media_adapters_type,
void *media_adapters,
cl_dx9_media_adapter_set_khr media_adapter_set,
cl_uint num_entries,
cl_device_id *devices,
cl_int *num_devices);
like look at that signature. eight arguments. she's got range π
πΈ PARAMETERS πΈ
platformβ the platform ID you got back fromclGetPlatformIDs(3clc). yes, that one. go get it if you don't have it already.num_media_adaptersβ literally just how many media adapters we're talking about.media_adapters_typeβ an array withnum_media_adaptersentries in it. every single entry says what type of media adapter it is, and it must be one of these values, no exceptions:CL_ADAPTER_D3D9_KHRβIDirect3DDevice9 *CL_ADAPTER_D3D9EX_KHRβIDirect3DDevice9Ex *CL_ADAPTER_DXVA_KHRβIDXVAHD_Device *
so the column on the left is the cl_dx9_media_adapter_type_khr value and the column on the right is the type of media adapter it maps to. match them up correctly or it's over for you π
media_adaptersβ also an array ofnum_media_adaptersentries. but this one holds the actual adapter, the real one, whose type is specified bymedia_adapter_type. andmedia_adaptersmust be one of the types described in that table right above. same table, same energy.media_adapter_setβ tells us which set of adapters we're returning, and it must be one of these two:CL_PREFERRED_DEVICES_FOR_MEDIA_ADAPTER_KHRβ the preferred OpenCL devices associated with the media adapter. the favourites, the inner circle πCL_ALL_DEVICES_FOR_MEDIA_ADAPTER_KHRβ all OpenCL devices that may interoperate with the media adapter. everybody's invited to this one.
num_entriesβ the number ofcl_device_identries that can be added todevices. heads up: ifdevicesis notNULL, thennum_entriesmust be greater than zero. no cap.devicesβ returns a list of the OpenCL devices we found that support the list of media adapters specified. thecl_device_idvalues that come back indevicescan be used to identify a specific OpenCL device. if thedevicesargument isNULL, this argument is ignored. and the number of OpenCL devices returned is the minimum of the value specified bynum_entriesor the number of OpenCL devices whose type matchesdevice_type.num_devicesβ returns the number of OpenCL devices. ifnum_devicesisNULL, this argument is ignored. she's optional, she knows it β¨
π¦ DESCRIPTION π¦
Queries a media adapter for any associated OpenCL devices. and why do we care? because adapters that do have associated OpenCL devices can enable media surface sharing between the two. it's a whole collaboration era π€
π NOTES π
The goal of this extension is to allow applications to use media surfaces as OpenCL memory objects. that means efficient sharing of data between OpenCL and selected adapter APIs (only DX9 for now, bestie, patience). if this extension is supported, an OpenCL image object can be created from a media surface, and the OpenCL API can be used to execute kernels that read and/or write memory objects that are media surfaces. note that OpenCL memory objects may be created from the adapter media surface if and only if the OpenCL context has been created from that adapter. that "if and only if" is doing heavy lifting, don't ignore her π
If this extension is supported by an implementation, the string "cl_khr_media_sharing" 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). that's your vibe check β go look for it.
As currently proposed, the interfaces for this extension would be provided in cl_dx9_media_sharing.h.
This section includes the D3D surface formats that are supported when the adapter type is one of the Direct 3D lineage. Using a D3D surface format not listed here is an error. To extend the use of this extension to support media adapters beyond DirectX9, tables similar to the ones in this section will need to be defined for the surface formats supported by the new media adapter. All implementations that support this extension are required to support the NV12 surface format β the other surface formats supported are the same surface formats that the adapter you are sharing with supports, as long as they are listed in the two tables below.
FOURCC('N', 'V', '1', '2'), Plane 0βCL_R, CL_UNORM_INT8FOURCC('N', 'V', '1', '2'), Plane 1βCL_RG, CL_UNORM_INT8FOURCC('Y', 'V', '1', '2'), Plane 0βCL_R, CL_UNORM_INT8FOURCC('Y', 'V', '1', '2'), Plane 1βCL_R, CL_UNORM_INT8FOURCC('Y', 'V', '1', '2'), Plane 2βCL_R, CL_UNORM_INT8
left column is the FOUR CC code, right column is the CL image format β that's channel order, channel data type. both matter. don't mix them up π
Okay so in that table up there, NV12 Plane 0 is the luminance (Y) channel and Plane 1 is the UV channels. For YV12, Plane 0 is the Y channel, Plane 1 is the U channel, and Plane 2 is the V channel. And bestie, note that the YUV formats map to CL_R and CL_RG but they do not do any YUV to RGB conversion, and vice-versa. No sneaky conversion. None. π
And here's the glow-up map from D3D formats to CL image formats (channel order, channel data type):
D3DFMT_R32FβCL_R,CL_FLOATD3DFMT_R16FβCL_R,CL_HALF_FLOATD3DFMT_L16βCL_R,CL_UNORM_INT16D3DFMT_A8βCL_A,CL_UNORM_INT8D3DFMT_L8βCL_R,CL_UNORM_INT8D3DFMT_G32R32FβCL_RG,CL_FLOATD3DFMT_G16R16FβCL_RG,CL_HALF_FLOATD3DFMT_G16R16βCL_RG,CL_UNORM_INT16D3DFMT_A8L8βCL_RG,CL_UNORM_INT8D3DFMT_A32B32G32R32FβCL_RGBA,CL_FLOATD3DFMT_A16B16G16R16FβCL_RGBA,CL_HALF_FLOATD3DFMT_A16B16G16R16βCL_RGBA,CL_UNORM_INT16D3DFMT_A8B8G8R8βCL_RGBA,CL_UNORM_INT8D3DFMT_X8B8G8R8βCL_RGBA,CL_UNORM_INT8D3DFMT_A8R8G8B8βCL_BGRA,CL_UNORM_INT8D3DFMT_X8R8G8B8βCL_BGRA,CL_UNORM_INT8
Okay and listen β the D3D9 format names look like they're implying the order of the color channels is switched compared to OpenCL, but it is not the case. Not even a little. For example, the layout of channels for each pixel for D3DFMT_A32FB32FG32FR32F is the same as CL_RGBA, CL_FLOAT. Same same. β¨
Properties of media surface objects can be queried using clGetMemObjectInfo(3clc) and clGetImageInfo(3clc) with param_name CL_MEM_MEDIA_ADAPTER_TYPE_KHR, CL_MEM_MEDIA_SURFACE_INFO_KHR and CL_IMAGE_MEDIA_SURFACE_PLANE_KHR, as described for clGetImageInfo(3clc) and in the info 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. Like, undefined undefined. Don't look at it. π
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. The contents of the regions of a memory object mapped for reading can also be read by kernels and other OpenCL commands (such as clEnqueueCopyBuffer(3clc)) executing on a device(s). Read party, everyone's invited. π
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 CL_INVALID_OPERATION error returned by clEnqueueMapBuffer(3clc) or clEnqueueMapImage(3clc).
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. π
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.
Accessing the contents of the memory region referred to by the mapped pointer that has been unmapped is undefined. It's gone. Ghosted. π
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. Rules first, vibes second. π«Ά
π ERRORS π
Returns CL_SUCCESS if the function is executed successfully. Otherwise, it returns one of the following errors:
CL_INVALID_PLATFORMifplatformis not a valid platform.CL_INVALID_VALUEifnum_media_adaptersis zero or ifmedia_adapters_typeisNULLor ifmedia_adaptersisNULL.CL_INVALID_VALUEif any of the entries inmedia_adapters_typeormedia_adaptersis not a valid value.CL_INVALID_VALUEifmedia_adapter_setis not a valid value.CL_INVALID_VALUEifnum_entriesis equal to zero anddevicesis notNULLor if bothnum_devicesanddevicesareNULL.CL_DEVICE_NOT_FOUNDif no OpenCL devices that correspond to adapters specified inmedia_adaptersandmedia_adapters_typewere found.CL_OUT_OF_RESOURCESif there is a failure to allocate resources required by the OpenCL implementation on the device.CL_OUT_OF_HOST_MEMORYif there is a failure to allocate resources required by the OpenCL implementation on the host.
π SPECIFICATION π
OpenCL Specification[1]
π SEE ALSO π
cl_khr_dx9_media_sharing(3clc)clGetDeviceIDsFromDX9MediaAdapterKHR(3clc)clCreateFromDX9MediaSurfaceKHR(3clc)clEnqueueAcquireDX9MediaSurfacesKHR(3clc)clEnqueueReleaseDX9MediaSurfacesKHR(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 88, section 9.10.7.1 β Querying OpenCL Devices corresponding....
And that's a wrap bestie π this one came from The Khronos Group, dated 01/14/2021, and it's the CLGETDEVICEIDSFROMDX(3clc) page β go forth and query those devices, you absolute icon πβ¨
π¦ 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