Open ysh329 opened 3 years ago
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>
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:
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:
<normalized coords>
Specifies whether the x, y 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>
.
ref: https://www.khronos.org/registry/OpenCL/sdk/1.0/docs/man/xhtml/sampler_t.html
类似stackoverflow问题:https://stackoverflow.com/questions/23417927/opencl-read-image-returns-a-blank-pixel
Depending on what values you are passing for WRATIO and HRATIO, the problem is very like that you're using CLK_NORMALIZED_COORDS_TRUE and should likely be using CLK_NORMALIZED_COORDS_FALSE. The latter lets you use pixel coordinates instead of 0.0 to 1.0 "normalized" coordinates.
Also, while you're at it, be aware that with CLK_FILTER_LINEAR and float2 coordinates, integral coordinates will give filtered results. Add (float2)(0.5f, 0.5f) to get unfiltered values. In other words, for the pixel at (2,6) read (2.5, 6.5). This will matter when your ratio is near 1.0 so you don't get a fuzzy image.
改为