sampler 用法 OpenCL

本文详细介绍了OpenCL中Sampler_t类型的作用与使用方法。Sampler_t用于控制如何读取2D或3D图像对象的元素,并可通过clSetKernelArg传递给内核。文章解释了地址模式、过滤模式和归一化坐标等属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

sampler_t

A type used to control how elements of a 2D or 3D image object are read by read_image{f|i|ui}.

const sampler_t <sampler name> = <value>

Description

The image read functions take a sampler argument. The sampler can be passed as an argument to the kernel using clSetKernelArg, or it can be a constant variable of type sampler_t declared in the program source.

Sampler variables in a program are declared to be of type sampler_t. The sampler_t type is a 32-bit unsigned int constant and is interpreted as a bit-field that specifies the following properties:

  • Addressing Mode

  • Filter Mode

  • Normalized Coordinates

These properties control how elements of a 2D or 3D image object are read by read_image{f|i|ui}.

Samplers can also be declared as global constants in the program source using the syntax shown at the top of this page.

The sampler fields are described in the table below:

Sampler State Description

<normalized coords>

Specifies whether the xy and z coordinates are passed in as normalized or unnormalized values. This must be one of the following predefined enums:

CLK_NORMALIZED_COORDS_TRUE or
CLK_NORMALIZED_COORDS_FALSE.

In OpenCL 1.0, the samplers specified with an image in multiple read_image{f|i|ui} calls declared in a kernel must use the same value for <normalized coords>.

<address mode>

Specifies the image addressing-mode i.e. how out-of-range image coordinates are handled. This must be a literal value and can be one of the following predefined enums:

CLK_ADDRESS_REPEAT - out-of-range image coordinates are wrapped to the valid range. This address mode can only be used with normalized coordinates. If normalized coordinates are not used, this addressing mode may generate image coordinates that are undefined.

CLK_ADDRESS_CLAMP_TO_EDGE - out-of-range image coordinates are clamped to the extent.

CLK_ADDRESS_CLAMP32 - out-of-range image coordinates will return a border color. The border color is (0.0f0.0f0.0f0.0f) if image channel order is CL_A, CL_INTENSITY, CL_RA, CL_ARGB, CL_BGRA or CL_RGBA and is (0.0f0.0f0.0f1.0f) if image channel order is CL_R, CL_RG, CL_RGB or CL_LUMINANCE.

CLK_ADDRESS_NONE - for this address mode the programmer guarantees that the image coordinates used to sample elements of the image refer to a location inside the image; otherwise the results are undefined.

<filter mode>

Specifies the filtering mode to use. This must be a literal value and can be one of the following predefined enums: CLK_FILTER_NEAREST or CLK_FILTER_LINEAR.

Refer to section on Image Addressing and Filtering in the OpenCL specification for a description of these filtering modes.

Samplers cannot be declared as arrays, pointers, or be used as the type for local variables inside a function or as the return value of a function defined in a program. Samplers cannot be passed as arguments to functions called by a __kernel function. A sampler argument to a __kernel function cannot be modified.

Notes

The maximum number of samplers that can be declared in a kernel can be queried using the CL_DEVICE_MAX_SAMPLERS token in the table of OpenCL Device Queries for clGetDeviceInfo.

Example

const sampler_t samplerA = CLK_NORMALIZED_COORDS_TRUE | CLK_ADDRESS_REPEAT | CLK_FILTER_NEAREST;

samplerA specifies a sampler that uses normalized coordinates, the repeat addressing mode and a nearest filter.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值