Ejemplo n.º 1
1
/**
 * \brief Creates the OpenCL Sampler with its Context.
 *
 * \param amode AdressingMode specifies how out-of-range image coordinates are handled when reading from an image.
 * \param fmode FilterMode specifies the type of filter that must be applied when reading an image.
 * \param normalized determines if the image coordinates specified are normalized.
 */
void ocl::Sampler::create(AdressingMode amode, FilterMode fmode, bool normalized)
{
	if(this->_context == nullptr) throw std::runtime_error("context not valid. cannot create a sampler");

    cl_bool coords = normalized ? CL_TRUE : CL_FALSE;
    cl_addressing_mode cl_amode = amode;
    cl_filter_mode cl_fmode = fmode;
    cl_int status;
    
// #ifdef CL_VERSION_2_0
#ifdef OPENCL_V2_0
    cl_sampler_properties props[] = {
      CL_SAMPLER_NORMALIZED_COORDS, coords,
      CL_SAMPLER_ADDRESSING_MODE, cl_amode,
      CL_SAMPLER_FILTER_MODE, cl_fmode,
      0
    };
    
    this->_id = clCreateSamplerWithProperties( this->_context->id(), props, &status );
#else
    this->_id = clCreateSampler(this->_context->id(), coords, cl_amode, cl_fmode, &status);
#endif

    OPENCL_SAFE_CALL(status);
	if(this->_id == nullptr) throw std::runtime_error("Could not create Sampler.");
}
JNIEXPORT jlong JNICALL Java_org_lwjgl_opencl_CL20_nclCreateSamplerWithProperties(JNIEnv *__env, jclass clazz, jlong contextAddress, jlong sampler_propertiesAddress, jlong errcode_retAddress, jlong __functionAddress) {
	cl_context context = (cl_context)(intptr_t)contextAddress;
	const cl_sampler_properties *sampler_properties = (const cl_sampler_properties *)(intptr_t)sampler_propertiesAddress;
	cl_int *errcode_ret = (cl_int *)(intptr_t)errcode_retAddress;
	clCreateSamplerWithPropertiesPROC clCreateSamplerWithProperties = (clCreateSamplerWithPropertiesPROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	return (jlong)(intptr_t)clCreateSamplerWithProperties(context, sampler_properties, errcode_ret);
}
Ejemplo n.º 3
0
/**
 * Create a new sampler wrapper object using a list of properties.
 *
 * If a supported property is not specified, a default value is used.
 * Some valid properties are `CL_SAMPLER_NORMALIZED_COORDS` (default
 * value is `CL_TRUE`), `CL_SAMPLER_ADDRESSING_MODE` (default value is
 * `CL_ADDRESS_CLAMP`) and `CL_SAMPLER_FILTER_MODE` (default value is
 * `CL_FILTER_NEAREST`).
 *
 * This function mimicks the style of the OpenCL 2.0 sampler
 * constructor, clCreateSamplerWithProperties(), but can be used with
 * any version of OpenCL. Thus, The underlying OpenCL sampler object is
 * created using:
 *
 * * clCreateSampler() - for platforms with OpenCL version <= 1.2
 * * clCreateSamplerWithProperties() - for platforms with OpenCL version
 * >= 2.0.
 *
 * @public @memberof ccl_sampler
 *
 * @param[in] ctx A context wrapper object.
 * @param[in] sampler_properties A list of sampler property names and
 * their corresponding values. Each sampler property name is immediately
 * followed by the corresponding desired value. The list is terminated
 * with 0. If a supported property is not specified, its default value
 * will be used. If `NULL`, default values for supported sampler
 * properties will be used.
 * @param[out] err Return location for a ::CCLErr object, or `NULL` if error
 * reporting is to be ignored.
 * @return A new sampler wrapper object or `NULL` if an error occurs.
 * */
CCL_EXPORT
CCLSampler* ccl_sampler_new_full(CCLContext* ctx,
	const cl_sampler_properties *sampler_properties, CCLErr** err) {

	/* Make sure err is NULL or it is not set. */
	g_return_val_if_fail((err) == NULL || *(err) == NULL, NULL);
	/* Make sure ctx is not NULL. */
	g_return_val_if_fail(ctx != NULL, NULL);

	/* New sampler wrapper object to create. */
	CCLSampler* smplr = NULL;
	/* OpenCL sampler object to create and wrap. */
	cl_sampler sampler;
	/* OpenCL function status. */
	cl_int ocl_status;

#ifdef CL_VERSION_2_0

	/* OpenCL platform version. */
	double ocl_ver;
	/* Internal error handling object. */
	CCLErr* err_internal = NULL;

	/* Get context platform version. */
	ocl_ver = ccl_context_get_opencl_version(ctx, &err_internal);
	ccl_if_err_propagate_goto(err, err_internal, error_handler);

	/* Create the OpenCL sampler object. */
	if (ocl_ver >= 200) {
		/* Platform is OpenCL >= 2.0, use "new" API. */
		sampler = clCreateSamplerWithProperties(
			ccl_context_unwrap(ctx), sampler_properties, &ocl_status);
	} else {
		/* Platform is OpenCL <= 1.2, use "old" API. */
		struct ccl_sampler_basic_properties sbp =
			ccl_sampler_get_basic_properties(sampler_properties);
		CCL_BEGIN_IGNORE_DEPRECATIONS
		sampler = clCreateSampler(ccl_context_unwrap(ctx),
			sbp.normalized_coords, sbp.addressing_mode, sbp.filter_mode,
			&ocl_status);
		CCL_END_IGNORE_DEPRECATIONS
	}

#else

	/* Create OpenCL sampler object. */
	struct ccl_sampler_basic_properties sbp =
		ccl_sampler_get_basic_properties(sampler_properties);
	sampler = clCreateSampler(ccl_context_unwrap(ctx),
		sbp.normalized_coords, sbp.addressing_mode, sbp.filter_mode,
		&ocl_status);

#endif

	/* Check for errors. */
	ccl_if_err_create_goto(*err, CCL_OCL_ERROR,
		CL_SUCCESS != ocl_status, ocl_status, error_handler,
		"%s: unable to create sampler (OpenCL error %d: %s).",
		CCL_STRD, ocl_status, ccl_err(ocl_status));

	/* Create sampler wrapper. */
	smplr = ccl_sampler_new_wrap(sampler);

	/* If we got here, everything is OK. */
	g_assert(err == NULL || *err == NULL);
	goto finish;

error_handler:

	/* If we got here there was an error, verify that it is so. */
	g_assert(err == NULL || *err != NULL);

finish:

	/* Return sampler wrapper. */
	return smplr;


}