/** * Tests creation (using "full" constructor), getting info from and * destruction of sampler wrapper objects. * */ static void create_full_info_destroy_test() { /* Test variables. */ CCLContext* ctx = NULL; CCLSampler* s = NULL; const cl_sampler_properties sampler_properties[] = { CL_SAMPLER_NORMALIZED_COORDS, CL_FALSE, CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_CLAMP_TO_EDGE, CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST, 0}; GError* err = NULL; /* Get the test context with the pre-defined device. */ ctx = ccl_test_context_new(&err); g_assert_no_error(err); /* Create sampler using "full" constructor. */ s = ccl_sampler_new_full(ctx, sampler_properties, &err); g_assert_no_error(err); /* Get some info and check if the return value is as expected. */ cl_addressing_mode am; am = ccl_sampler_get_info_scalar( s, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode, &err); g_assert_no_error(err); g_assert_cmpuint(am, ==, CL_ADDRESS_CLAMP_TO_EDGE); cl_filter_mode fm; fm = ccl_sampler_get_info_scalar( s, CL_SAMPLER_FILTER_MODE, cl_filter_mode, &err); g_assert_no_error(err); g_assert_cmpuint(fm, ==, CL_FILTER_NEAREST); cl_bool nc; nc = ccl_sampler_get_info_scalar( s, CL_SAMPLER_NORMALIZED_COORDS, cl_bool, &err); g_assert_no_error(err); g_assert_cmpuint(nc, ==, CL_FALSE); cl_context context; context = ccl_sampler_get_info_scalar( s, CL_SAMPLER_CONTEXT, cl_context, &err); g_assert_no_error(err); g_assert_cmphex(GPOINTER_TO_UINT(context), ==, GPOINTER_TO_UINT(ccl_context_unwrap(ctx))); /* Destroy sampler. */ ccl_sampler_destroy(s); ccl_context_destroy(ctx); /* Confirm that memory allocated by wrappers has been properly * freed. */ g_assert(ccl_wrapper_memcheck()); }
/** * Create a new sampler wrapper object by specifying a basic set of * sampler properties. * * @public @memberof ccl_sampler * * This function mimicks the style of the classic sampler constructor, * clCreateSampler(), but can be used with any version of OpenCL. This * function calls the ccl_sampler_new_full() function for actual * sampler creation. * * @param[in] ctx A context wrapper object. * @param[in] normalized_coords Are the image coordinates normalized? * @param[in] addressing_mode How to handle out-of-range coordinates. * @param[in] filter_mode Filter to apply when reading an image. * @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(CCLContext* ctx, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode, CCLErr** err) { const cl_sampler_properties sp[] = { CL_SAMPLER_NORMALIZED_COORDS, normalized_coords, CL_SAMPLER_ADDRESSING_MODE, addressing_mode, CL_SAMPLER_FILTER_MODE, filter_mode, 0 }; return ccl_sampler_new_full(ctx, sp, err); }
/** * Tests creation (using "simple" constructor), getting info from and * destruction of sampler wrapper objects. * */ static void create_info_destroy_test() { /* Test variables. */ CCLContext* ctx = NULL; CCLSampler* s = NULL; cl_sampler sampler = NULL; GError* err = NULL; cl_int ocl_status; const cl_sampler_properties sampler_properties[] = { CL_SAMPLER_NORMALIZED_COORDS, CL_TRUE, CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_NONE, CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST, 0}; /* Get the test context with the pre-defined device. */ ctx = ccl_test_context_new(&err); g_assert_no_error(err); /* Test three ways to create a sampler. */ for (cl_uint i = 0; i < 3; ++i) { /* Create sampler wrapper. */ switch (i) { case 0: /* Create sampler using "simple" constructor. */ s = ccl_sampler_new(ctx, CL_TRUE, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &err); g_assert_no_error(err); break; case 1: /* Using the "full" constructor. */ s = ccl_sampler_new_full(ctx, sampler_properties, &err); g_assert_no_error(err); break; case 2: /* Using the "wrap" constructor. */ CCL_BEGIN_IGNORE_DEPRECATIONS sampler = clCreateSampler(ccl_context_unwrap(ctx), CL_TRUE, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &ocl_status); g_assert_cmpint(ocl_status, ==, CL_SUCCESS); CCL_END_IGNORE_DEPRECATIONS s = ccl_sampler_new_wrap(sampler); g_assert_cmphex(GPOINTER_TO_UINT(sampler), ==, GPOINTER_TO_UINT(ccl_sampler_unwrap(s))); break; } /* Get some info and check if the return value is as expected. */ cl_addressing_mode am; am = ccl_sampler_get_info_scalar( s, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode, &err); g_assert_no_error(err); g_assert_cmpuint(am, ==, CL_ADDRESS_NONE); cl_filter_mode fm; fm = ccl_sampler_get_info_scalar( s, CL_SAMPLER_FILTER_MODE, cl_filter_mode, &err); g_assert_no_error(err); g_assert_cmpuint(fm, ==, CL_FILTER_NEAREST); cl_bool nc; nc = ccl_sampler_get_info_scalar( s, CL_SAMPLER_NORMALIZED_COORDS, cl_bool, &err); g_assert_no_error(err); g_assert_cmpuint(nc, ==, CL_TRUE); cl_context context; context = ccl_sampler_get_info_scalar( s, CL_SAMPLER_CONTEXT, cl_context, &err); g_assert_no_error(err); g_assert_cmphex(GPOINTER_TO_UINT(context), ==, GPOINTER_TO_UINT(ccl_context_unwrap(ctx))); /* Destroy sampler. */ ccl_sampler_destroy(s); } /* Destroy context. */ ccl_context_destroy(ctx); /* Confirm that memory allocated by wrappers has been properly * freed. */ g_assert(ccl_wrapper_memcheck()); }