state->ARB_shader_image_load_store_enable);
}
+static bool
+shader_image_size(const _mesa_glsl_parse_state *state)
+{
+ return state->is_version(430, 310) ||
+ state->ARB_shader_image_size_enable;
+}
+
static bool
gs_streams(const _mesa_glsl_parse_state *state)
{
/** Create a new function and add the given signatures. */
void add_function(const char *name, ...);
+ typedef ir_function_signature *(builtin_builder::*image_prototype_ctr)(const glsl_type *image_type,
+ const char *intrinsic_name,
+ unsigned num_arguments,
+ unsigned flags);
+
enum image_function_flags {
IMAGE_FUNCTION_EMIT_STUB = (1 << 0),
IMAGE_FUNCTION_RETURNS_VOID = (1 << 1),
*/
void add_image_function(const char *name,
const char *intrinsic_name,
+ image_prototype_ctr prototype,
unsigned num_arguments,
unsigned flags);
const char *intrinsic_name,
unsigned num_arguments,
unsigned flags);
- ir_function_signature *_image(const glsl_type *image_type,
+ ir_function_signature *_image_size_prototype(const glsl_type *image_type,
+ const char *intrinsic_name,
+ unsigned num_arguments,
+ unsigned flags);
+ ir_function_signature *_image(image_prototype_ctr prototype,
+ const glsl_type *image_type,
const char *intrinsic_name,
unsigned num_arguments,
unsigned flags);
void
builtin_builder::add_image_function(const char *name,
const char *intrinsic_name,
+ image_prototype_ctr prototype,
unsigned num_arguments,
unsigned flags)
{
glsl_type::uimage2DMS_type,
glsl_type::uimage2DMSArray_type
};
+
ir_function *f = new(mem_ctx) ir_function(name);
for (unsigned i = 0; i < ARRAY_SIZE(types); ++i) {
if (types[i]->sampler_type != GLSL_TYPE_FLOAT ||
(flags & IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE))
- f->add_signature(_image(types[i], intrinsic_name,
+ f->add_signature(_image(prototype, types[i], intrinsic_name,
num_arguments, flags));
}
const unsigned flags = (glsl ? IMAGE_FUNCTION_EMIT_STUB : 0);
add_image_function(glsl ? "imageLoad" : "__intrinsic_image_load",
- "__intrinsic_image_load", 0,
- (flags | IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE |
+ "__intrinsic_image_load",
+ &builtin_builder::_image_prototype, 0,
+ (flags | IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE |
IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE |
IMAGE_FUNCTION_READ_ONLY));
add_image_function(glsl ? "imageStore" : "__intrinsic_image_store",
- "__intrinsic_image_store", 1,
+ "__intrinsic_image_store",
+ &builtin_builder::_image_prototype, 1,
(flags | IMAGE_FUNCTION_RETURNS_VOID |
IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE |
IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE |
const unsigned atom_flags = flags | IMAGE_FUNCTION_AVAIL_ATOMIC;
add_image_function(glsl ? "imageAtomicAdd" : "__intrinsic_image_atomic_add",
- "__intrinsic_image_atomic_add", 1, atom_flags);
+ "__intrinsic_image_atomic_add",
+ &builtin_builder::_image_prototype, 1, atom_flags);
add_image_function(glsl ? "imageAtomicMin" : "__intrinsic_image_atomic_min",
- "__intrinsic_image_atomic_min", 1, atom_flags);
+ "__intrinsic_image_atomic_min",
+ &builtin_builder::_image_prototype, 1, atom_flags);
add_image_function(glsl ? "imageAtomicMax" : "__intrinsic_image_atomic_max",
- "__intrinsic_image_atomic_max", 1, atom_flags);
+ "__intrinsic_image_atomic_max",
+ &builtin_builder::_image_prototype, 1, atom_flags);
add_image_function(glsl ? "imageAtomicAnd" : "__intrinsic_image_atomic_and",
- "__intrinsic_image_atomic_and", 1, atom_flags);
+ "__intrinsic_image_atomic_and",
+ &builtin_builder::_image_prototype, 1, atom_flags);
add_image_function(glsl ? "imageAtomicOr" : "__intrinsic_image_atomic_or",
- "__intrinsic_image_atomic_or", 1, atom_flags);
+ "__intrinsic_image_atomic_or",
+ &builtin_builder::_image_prototype, 1, atom_flags);
add_image_function(glsl ? "imageAtomicXor" : "__intrinsic_image_atomic_xor",
- "__intrinsic_image_atomic_xor", 1, atom_flags);
+ "__intrinsic_image_atomic_xor",
+ &builtin_builder::_image_prototype, 1, atom_flags);
add_image_function((glsl ? "imageAtomicExchange" :
"__intrinsic_image_atomic_exchange"),
- "__intrinsic_image_atomic_exchange", 1, atom_flags);
+ "__intrinsic_image_atomic_exchange",
+ &builtin_builder::_image_prototype, 1, atom_flags);
add_image_function((glsl ? "imageAtomicCompSwap" :
"__intrinsic_image_atomic_comp_swap"),
- "__intrinsic_image_atomic_comp_swap", 2, atom_flags);
+ "__intrinsic_image_atomic_comp_swap",
+ &builtin_builder::_image_prototype, 2, atom_flags);
+
+ add_image_function(glsl ? "imageSize" : "__intrinsic_image_size",
+ "__intrinsic_image_size",
+ &builtin_builder::_image_size_prototype, 1, atom_flags);
}
ir_variable *
}
ir_function_signature *
-builtin_builder::_image(const glsl_type *image_type,
+builtin_builder::_image_size_prototype(const glsl_type *image_type,
+ const char *intrinsic_name,
+ unsigned num_arguments,
+ unsigned flags)
+{
+ const glsl_type *ret_type;
+ unsigned num_components = image_type->coordinate_components();
+
+ /* From the ARB_shader_image_size extension:
+ * "Cube images return the dimensions of one face."
+ */
+ if (image_type->sampler_dimensionality == GLSL_SAMPLER_DIM_CUBE &&
+ !image_type->sampler_array) {
+ num_components = 2;
+ }
+
+ /* FIXME: Add the highp precision qualifier for GLES 3.10 when it is
+ * supported by mesa.
+ */
+ ret_type = glsl_type::get_instance(GLSL_TYPE_INT, num_components, 1);
+
+ ir_variable *image = in_var(image_type, "image");
+ ir_function_signature *sig = new_sig(ret_type, shader_image_size, 1, image);
+
+ /* 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 = true;
+ image->data.image_write_only = true;
+ image->data.image_coherent = true;
+ image->data.image_volatile = true;
+ image->data.image_restrict = true;
+
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_image(image_prototype_ctr prototype,
+ 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);
+ ir_function_signature *sig = (this->*prototype)(image_type, intrinsic_name,
+ num_arguments, flags);
if (flags & IMAGE_FUNCTION_EMIT_STUB) {
ir_factory body(&sig->body, mem_ctx);