+
+ir_function_signature *
+builtin_builder::_interpolateAtCentroid(const glsl_type *type)
+{
+ ir_variable *interpolant = in_var(type, "interpolant");
+ interpolant->data.must_be_shader_input = 1;
+ MAKE_SIG(type, fs_gpu_shader5, 1, interpolant);
+
+ body.emit(ret(interpolate_at_centroid(interpolant)));
+
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_interpolateAtOffset(const glsl_type *type)
+{
+ ir_variable *interpolant = in_var(type, "interpolant");
+ interpolant->data.must_be_shader_input = 1;
+ ir_variable *offset = in_var(glsl_type::vec2_type, "offset");
+ MAKE_SIG(type, fs_gpu_shader5, 2, interpolant, offset);
+
+ body.emit(ret(interpolate_at_offset(interpolant, offset)));
+
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_interpolateAtSample(const glsl_type *type)
+{
+ ir_variable *interpolant = in_var(type, "interpolant");
+ interpolant->data.must_be_shader_input = 1;
+ ir_variable *sample_num = in_var(glsl_type::int_type, "sample_num");
+ MAKE_SIG(type, fs_gpu_shader5, 2, interpolant, sample_num);
+
+ body.emit(ret(interpolate_at_sample(interpolant, sample_num)));
+
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_atomic_intrinsic(builtin_available_predicate avail)
+{
+ ir_variable *counter = in_var(glsl_type::atomic_uint_type, "counter");
+ MAKE_INTRINSIC(glsl_type::uint_type, avail, 1, counter);
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_atomic_op(const char *intrinsic,
+ builtin_available_predicate avail)
+{
+ ir_variable *counter = in_var(glsl_type::atomic_uint_type, "atomic_counter");
+ MAKE_SIG(glsl_type::uint_type, avail, 1, counter);
+
+ ir_variable *retval = body.make_temp(glsl_type::uint_type, "atomic_retval");
+ body.emit(call(shader->symbols->get_function(intrinsic), retval,
+ sig->parameters));
+ body.emit(ret(retval));
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_min3(const glsl_type *type)
+{
+ ir_variable *x = in_var(type, "x");
+ ir_variable *y = in_var(type, "y");
+ ir_variable *z = in_var(type, "z");
+ MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
+
+ ir_expression *min3 = min2(x, min2(y,z));
+ body.emit(ret(min3));
+
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_max3(const glsl_type *type)
+{
+ ir_variable *x = in_var(type, "x");
+ ir_variable *y = in_var(type, "y");
+ ir_variable *z = in_var(type, "z");
+ MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
+
+ ir_expression *max3 = max2(x, max2(y,z));
+ body.emit(ret(max3));
+
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_mid3(const glsl_type *type)
+{
+ ir_variable *x = in_var(type, "x");
+ ir_variable *y = in_var(type, "y");
+ ir_variable *z = in_var(type, "z");
+ MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
+
+ ir_expression *mid3 = max2(min2(x, y), max2(min2(x, z), min2(y, z)));
+ body.emit(ret(mid3));
+
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_image_prototype(const glsl_type *image_type,
+ const char *intrinsic_name,
+ unsigned num_arguments,
+ unsigned flags)
+{
+ const glsl_type *data_type = glsl_type::get_instance(
+ image_type->sampler_type,
+ (flags & IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE ? 4 : 1),
+ 1);
+ const glsl_type *ret_type = (flags & IMAGE_FUNCTION_RETURNS_VOID ?
+ glsl_type::void_type : data_type);
+
+ /* Addressing arguments that are always present. */
+ ir_variable *image = in_var(image_type, "image");
+ ir_variable *coord = in_var(
+ glsl_type::ivec(image_type->coordinate_components()), "coord");
+
+ ir_function_signature *sig = new_sig(
+ ret_type, shader_image_load_store, 2, image, coord);
+
+ /* Sample index for multisample images. */
+ if (image_type->sampler_dimensionality == GLSL_SAMPLER_DIM_MS)
+ sig->parameters.push_tail(in_var(glsl_type::int_type, "sample"));
+
+ /* Data arguments. */
+ for (unsigned i = 0; i < num_arguments; ++i) {
+ char *arg_name = ralloc_asprintf(NULL, "arg%d", i);
+ sig->parameters.push_tail(in_var(data_type, arg_name));
+ ralloc_free(arg_name);
+ }
+
+ /* Set the maximal set of qualifiers allowed for this image
+ * built-in. Function calls with arguments having fewer
+ * qualifiers than present in the prototype are allowed by the
+ * spec, but not with more, i.e. this will make the compiler
+ * accept everything that needs to be accepted, and reject cases
+ * like loads from write-only or stores to read-only images.
+ */
+ image->data.image_read_only = (flags & IMAGE_FUNCTION_READ_ONLY) != 0;
+ image->data.image_write_only = (flags & IMAGE_FUNCTION_WRITE_ONLY) != 0;
+ image->data.image_coherent = true;
+ image->data.image_volatile = true;
+ image->data.image_restrict = true;
+
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_image(const glsl_type *image_type,
+ const char *intrinsic_name,
+ unsigned num_arguments,
+ unsigned flags)
+{
+ ir_function_signature *sig = _image_prototype(image_type, intrinsic_name,
+ num_arguments, flags);
+
+ if (flags & IMAGE_FUNCTION_EMIT_STUB) {
+ ir_factory body(&sig->body, mem_ctx);
+ ir_function *f = shader->symbols->get_function(intrinsic_name);
+
+ if (flags & IMAGE_FUNCTION_RETURNS_VOID) {
+ body.emit(call(f, NULL, sig->parameters));
+ } else {
+ ir_variable *ret_val =
+ body.make_temp(sig->return_type, "_ret_val");
+ body.emit(call(f, ret_val, sig->parameters));
+ body.emit(ret(ret_val));
+ }
+
+ sig->is_defined = true;
+
+ } else {
+ sig->is_intrinsic = true;
+ }
+
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_memory_barrier_intrinsic(builtin_available_predicate avail)
+{
+ MAKE_INTRINSIC(glsl_type::void_type, avail, 0);
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_memory_barrier(builtin_available_predicate avail)
+{
+ MAKE_SIG(glsl_type::void_type, avail, 0);
+ body.emit(call(shader->symbols->get_function("__intrinsic_memory_barrier"),
+ NULL, sig->parameters));
+ return sig;
+}
+