CLGETDEVICEIDSFROMDX(3clc)

πŸ“¦
version 1.0~svn33624 Β· 3 versions
, in ubuntu jammy, ubuntu noble

πŸ’– 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 from clGetPlatformIDs(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 with num_media_adapters entries 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 of num_media_adapters entries. but this one holds the actual adapter, the real one, whose type is specified by media_adapter_type. and media_adapters must 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 of cl_device_id entries that can be added to devices. heads up: if devices is not NULL, then num_entries must be greater than zero. no cap.
  • devices β€” returns a list of the OpenCL devices we found that support the list of media adapters specified. the cl_device_id values that come back in devices can be used to identify a specific OpenCL device. if the devices argument is NULL, this argument is ignored. and the number of OpenCL devices returned is the minimum of the value specified by num_entries or the number of OpenCL devices whose type matches device_type.
  • num_devices β€” returns the number of OpenCL devices. if num_devices is NULL, 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_INT8
  • FOURCC('N', 'V', '1', '2'), Plane 1 β†’ CL_RG, CL_UNORM_INT8
  • FOURCC('Y', 'V', '1', '2'), Plane 0 β†’ CL_R, CL_UNORM_INT8
  • FOURCC('Y', 'V', '1', '2'), Plane 1 β†’ CL_R, CL_UNORM_INT8
  • FOURCC('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_FLOAT
  • D3DFMT_R16F β†’ CL_R, CL_HALF_FLOAT
  • D3DFMT_L16 β†’ CL_R, CL_UNORM_INT16
  • D3DFMT_A8 β†’ CL_A, CL_UNORM_INT8
  • D3DFMT_L8 β†’ CL_R, CL_UNORM_INT8
  • D3DFMT_G32R32F β†’ CL_RG, CL_FLOAT
  • D3DFMT_G16R16F β†’ CL_RG, CL_HALF_FLOAT
  • D3DFMT_G16R16 β†’ CL_RG, CL_UNORM_INT16
  • D3DFMT_A8L8 β†’ CL_RG, CL_UNORM_INT8
  • D3DFMT_A32B32G32R32F β†’ CL_RGBA, CL_FLOAT
  • D3DFMT_A16B16G16R16F β†’ CL_RGBA, CL_HALF_FLOAT
  • D3DFMT_A16B16G16R16 β†’ CL_RGBA, CL_UNORM_INT16
  • D3DFMT_A8B8G8R8 β†’ CL_RGBA, CL_UNORM_INT8
  • D3DFMT_X8B8G8R8 β†’ CL_RGBA, CL_UNORM_INT8
  • D3DFMT_A8R8G8B8 β†’ CL_BGRA, CL_UNORM_INT8
  • D3DFMT_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_PLATFORM if platform is not a valid platform.
  • CL_INVALID_VALUE if num_media_adapters is zero or if media_adapters_type is NULL or if media_adapters is NULL.
  • CL_INVALID_VALUE if any of the entries in media_adapters_type or media_adapters is not a valid value.
  • CL_INVALID_VALUE if media_adapter_set is not a valid value.
  • CL_INVALID_VALUE if num_entries is equal to zero and devices is not NULL or if both num_devices and devices are NULL.
  • CL_DEVICE_NOT_FOUND if no OpenCL devices that correspond to adapters specified in media_adapters and media_adapters_type were found.
  • CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL implementation on the device.
  • CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.

πŸ“œ SPECIFICATION πŸ“œ

OpenCL Specification[1]


πŸ‘€ SEE ALSO πŸ‘€


πŸ‘‘ AUTHORS πŸ‘‘

The Khronos Group


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 πŸ“

  1. 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