Esempio n. 1
0
func (s *Sampler) GetReferenceCount() (int, error) {
	if s.clSampler != nil {
		var outCount C.cl_uint
		err := C.clGetSamplerInfo(s.clSampler, C.CL_SAMPLER_REFERENCE_COUNT, C.size_t(unsafe.Sizeof(outCount)), unsafe.Pointer(&outCount), nil)
		return int(outCount), toError(err)
	}
	return 0, toError(C.CL_INVALID_SAMPLER)
}
Esempio n. 2
0
func (s *Sampler) GetContext() (*Context, error) {
	if s.clSampler != nil {
		var outContext C.cl_context
		err := C.clGetSamplerInfo(s.clSampler, C.CL_SAMPLER_CONTEXT, C.size_t(unsafe.Sizeof(outContext)), unsafe.Pointer(&outContext), nil)
		return &Context{clContext: outContext, devices: nil}, toError(err)
	}
	return nil, toError(C.CL_INVALID_SAMPLER)
}
Esempio n. 3
0
func (s *Sampler) Info(param SamplerInfo) (uint32, error) {
	var ret uint32
	var c_size_ret C.size_t
	if err := C.clGetSamplerInfo(s.id, C.cl_sampler_info(param), C.size_t(4), unsafe.Pointer(&ret), &c_size_ret); err != C.CL_SUCCESS {
		return 0, Cl_error(err)
	}
	return ret, nil
}
Esempio n. 4
0
func (s *Sampler) Property(prop SamplerProperty) interface{} {
	if value, ok := s.properties[prop]; ok {
		return value
	}

	var data interface{}
	var length C.size_t
	var ret C.cl_int

	switch prop {
	case SAMPLER_REFERENCE_COUNT:
		var val C.cl_uint
		ret = C.clGetSamplerInfo(s.id, C.cl_sampler_info(prop), C.size_t(unsafe.Sizeof(val)), unsafe.Pointer(&val), &length)
		data = val
	case SAMPLER_NORMALIZED_COORDS:
		var val C.cl_bool
		ret = C.clGetSamplerInfo(s.id, C.cl_sampler_info(prop), C.size_t(unsafe.Sizeof(val)), unsafe.Pointer(&val), &length)
		data = val == C.CL_TRUE
	case SAMPLER_ADDRESSING_MODE:
		var val C.cl_addressing_mode
		ret = C.clGetSamplerInfo(s.id, C.cl_sampler_info(prop), C.size_t(unsafe.Sizeof(val)), unsafe.Pointer(&val), &length)
		data = AddressingMode(ret)
	case SAMPLER_FILTER_MODE:
		var val C.cl_filter_mode
		ret = C.clGetSamplerInfo(s.id, C.cl_sampler_info(prop), C.size_t(unsafe.Sizeof(val)), unsafe.Pointer(&val), &length)
		data = FilterMode(ret)
	default:
		return nil
	}

	if ret != C.CL_SUCCESS {
		return nil
	}
	s.properties[prop] = data
	return s.properties[prop]
}
Esempio n. 5
0
func (s *Sampler) GetNormalizedCoords() (bool, error) {
	if s.clSampler != nil {
		var outRes C.cl_bool
		err := C.clGetSamplerInfo(s.clSampler, C.CL_SAMPLER_NORMALIZED_COORDS, C.size_t(unsafe.Sizeof(outRes)), unsafe.Pointer(&outRes), nil)
		if toError(err) != nil {
			return false, toError(err)
		}
		switch {
		case outRes == C.CL_TRUE:
			return true, nil
		default:
			return false, nil
		}
	}
	return false, toError(C.CL_INVALID_SAMPLER)
}
Esempio n. 6
0
func (s *Sampler) GetFilterMode() (SamplerFilterMode, error) {
	if s.clSampler != nil {
		var outRes C.cl_filter_mode
		err := C.clGetSamplerInfo(s.clSampler, C.CL_SAMPLER_FILTER_MODE, C.size_t(unsafe.Sizeof(outRes)), unsafe.Pointer(&outRes), nil)
		if toError(err) != nil {
			return -1, toError(err)
		}
		switch {
		case outRes == C.CL_FILTER_LINEAR:
			return SamplerFilterLinear, nil
		case outRes == C.CL_FILTER_NEAREST:
			return SamplerFilterNearest, nil
		default:
			return -1, toError(C.CL_INVALID_SAMPLER)
		}
	}
	return -1, toError(C.CL_INVALID_SAMPLER)
}
Esempio n. 7
0
func (s *Sampler) GetAddressingMode() (SamplerAddressingMode, error) {
	if s.clSampler != nil {
		var outRes C.cl_addressing_mode
		err := C.clGetSamplerInfo(s.clSampler, C.CL_SAMPLER_ADDRESSING_MODE, C.size_t(unsafe.Sizeof(outRes)), unsafe.Pointer(&outRes), nil)
		if toError(err) != nil {
			return -1, toError(err)
		}
		switch {
		case outRes == C.CL_ADDRESS_REPEAT:
			return SamplerAddressRepeat, nil
		case outRes == C.CL_ADDRESS_CLAMP_TO_EDGE:
			return SamplerAddressClampToEdge, nil
		case outRes == C.CL_ADDRESS_CLAMP:
			return SamplerAddressClamp, nil
		case outRes == C.CL_ADDRESS_NONE:
			return SamplerAddressNone, nil
		default:
			return -1, toError(C.CL_INVALID_SAMPLER)
		}
	}
	return -1, toError(C.CL_INVALID_SAMPLER)
}
Esempio n. 8
0
File: package.go Progetto: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetSamplerInfo.html
func GetSamplerInfo(sampler Sampler, paramName SamplerInfo, paramValueSize uint64, paramValue unsafe.Pointer, paramValueSizeRet *uint64) ErrorCode {
	return ErrorCode(C.clGetSamplerInfo(sampler, C.cl_sampler_info(paramName), C.size_t(paramValueSize), paramValue, (*C.size_t)(paramValueSizeRet)))
}
Esempio n. 9
0
func CLGetSamplerInfo(sampler CL_sampler,
	param_name CL_sampler_info,
	param_value_size CL_size_t,
	param_value *interface{},
	param_value_size_ret *CL_size_t) CL_int {

	if (param_value_size == 0 || param_value == nil) && param_value_size_ret == nil {
		return CL_INVALID_VALUE
	} else {
		var c_param_value_size_ret C.size_t
		var c_errcode_ret C.cl_int

		if param_value_size == 0 || param_value == nil {
			c_errcode_ret = C.clGetSamplerInfo(sampler.cl_sampler,
				C.cl_sampler_info(param_name),
				C.size_t(param_value_size),
				nil,
				&c_param_value_size_ret)
		} else {
			switch param_name {
			case CL_SAMPLER_REFERENCE_COUNT:

				var value C.cl_uint
				c_errcode_ret = C.clGetSamplerInfo(sampler.cl_sampler,
					C.cl_sampler_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

				*param_value = CL_uint(value)
			case CL_SAMPLER_CONTEXT:

				var value C.cl_context
				c_errcode_ret = C.clGetSamplerInfo(sampler.cl_sampler,
					C.cl_sampler_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

				*param_value = CL_context{value}
			case CL_SAMPLER_FILTER_MODE:

				var value C.cl_filter_mode
				c_errcode_ret = C.clGetSamplerInfo(sampler.cl_sampler,
					C.cl_sampler_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

				*param_value = CL_filter_mode(value)
			case CL_SAMPLER_ADDRESSING_MODE:

				var value C.cl_addressing_mode
				c_errcode_ret = C.clGetSamplerInfo(sampler.cl_sampler,
					C.cl_sampler_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

				*param_value = CL_addressing_mode(value)
			case CL_SAMPLER_NORMALIZED_COORDS:

				var value C.cl_bool
				c_errcode_ret = C.clGetSamplerInfo(sampler.cl_sampler,
					C.cl_sampler_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

				*param_value = CL_bool(value)

			//TODO in CL.h, but not in spec? Why?
			//case CL_SAMPLER_MIP_FILTER_MODE,
			// CL_SAMPLER_LOD_MIN,
			// CL_SAMPLER_LOD_MAX:

			default:
				return CL_INVALID_VALUE
			}
		}

		if param_value_size_ret != nil {
			*param_value_size_ret = CL_size_t(c_param_value_size_ret)
		}

		return CL_int(c_errcode_ret)
	}
}