[Mesa-dev] [PATCH 7/9] nir/types: Add helpers for working with sampler and image types

Jason Ekstrand jason at jlekstrand.net
Fri Feb 12 06:16:25 UTC 2016


---
 src/compiler/nir_types.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++
 src/compiler/nir_types.h   | 14 +++++++++++
 2 files changed, 75 insertions(+)

diff --git a/src/compiler/nir_types.cpp b/src/compiler/nir_types.cpp
index 17950cc..89f1be5 100644
--- a/src/compiler/nir_types.cpp
+++ b/src/compiler/nir_types.cpp
@@ -130,6 +130,20 @@ glsl_get_struct_elem_name(const struct glsl_type *type, unsigned index)
    return type->fields.structure[index].name;
 }
 
+glsl_sampler_dim
+glsl_get_sampler_dim(const struct glsl_type *type)
+{
+   assert(glsl_type_is_sampler(type) || glsl_type_is_image(type));
+   return (glsl_sampler_dim)type->sampler_dimensionality;
+}
+
+glsl_base_type
+glsl_get_sampler_result_type(const struct glsl_type *type)
+{
+   assert(glsl_type_is_sampler(type) || glsl_type_is_image(type));
+   return (glsl_base_type)type->sampled_type;
+}
+
 unsigned
 glsl_get_record_location_offset(const struct glsl_type *type,
                                 unsigned length)
@@ -167,6 +181,32 @@ glsl_type_is_matrix(const struct glsl_type *type)
    return type->is_matrix();
 }
 
+bool
+glsl_type_is_sampler(const struct glsl_type *type)
+{
+   return type->is_sampler();
+}
+
+bool
+glsl_type_is_image(const struct glsl_type *type)
+{
+   return type->is_image();
+}
+
+bool
+glsl_sampler_type_is_shadow(const struct glsl_type *type)
+{
+   assert(glsl_type_is_sampler(type));
+   return type->sampler_shadow;
+}
+
+bool
+glsl_sampler_type_is_array(const struct glsl_type *type)
+{
+   assert(glsl_type_is_sampler(type) || glsl_type_is_image(type));
+   return type->sampler_array;
+}
+
 const glsl_type *
 glsl_void_type(void)
 {
@@ -204,6 +244,27 @@ glsl_array_type(const glsl_type *base, unsigned elements)
 }
 
 const glsl_type *
+const struct glsl_type *
+glsl_sampler_type(enum glsl_sampler_dim dim, bool is_shadow, bool is_array,
+                  enum glsl_base_type base_type)
+{
+   return glsl_type::get_sampler_instance(dim, is_shadow, is_array, base_type);
+}
+
+const struct glsl_type *
+glsl_bare_sampler_type()
+{
+   return glsl_type::sampler_type;
+}
+
+const struct glsl_type *
+glsl_image_type(enum glsl_sampler_dim dim, bool is_array,
+                enum glsl_base_type base_type)
+{
+   return glsl_type::get_image_instance(dim, is_array, base_type);
+}
+
+const glsl_type *
 glsl_function_type(const glsl_type *return_type,
                    const glsl_function_param *params, unsigned num_params)
 {
diff --git a/src/compiler/nir_types.h b/src/compiler/nir_types.h
index 98228a0..e16dc4b 100644
--- a/src/compiler/nir_types.h
+++ b/src/compiler/nir_types.h
@@ -71,6 +71,9 @@ unsigned glsl_get_aoa_size(const struct glsl_type *type);
 const char *glsl_get_struct_elem_name(const struct glsl_type *type,
                                       unsigned index);
 
+enum glsl_sampler_dim glsl_get_sampler_dim(const struct glsl_type *type);
+enum glsl_base_type glsl_get_sampler_result_type(const struct glsl_type *type);
+
 unsigned glsl_get_record_location_offset(const struct glsl_type *type,
                                          unsigned length);
 
@@ -79,6 +82,10 @@ bool glsl_type_is_vector(const struct glsl_type *type);
 bool glsl_type_is_scalar(const struct glsl_type *type);
 bool glsl_type_is_vector_or_scalar(const struct glsl_type *type);
 bool glsl_type_is_matrix(const struct glsl_type *type);
+bool glsl_type_is_sampler(const struct glsl_type *type);
+bool glsl_type_is_image(const struct glsl_type *type);
+bool glsl_sampler_type_is_shadow(const struct glsl_type *type);
+bool glsl_sampler_type_is_array(const struct glsl_type *type);
 
 const struct glsl_type *glsl_void_type(void);
 const struct glsl_type *glsl_float_type(void);
@@ -87,6 +94,13 @@ const struct glsl_type *glsl_vec4_type(void);
 const struct glsl_type *glsl_uint_type(void);
 const struct glsl_type *glsl_array_type(const struct glsl_type *base,
                                         unsigned elements);
+const struct glsl_type *glsl_sampler_type(enum glsl_sampler_dim dim,
+                                          bool is_shadow, bool is_array,
+                                          enum glsl_base_type base_type);
+const struct glsl_type *glsl_bare_sampler_type();
+const struct glsl_type *glsl_image_type(enum glsl_sampler_dim dim,
+                                        bool is_array,
+                                        enum glsl_base_type base_type);
 const struct glsl_type * glsl_function_type(const struct glsl_type *return_type,
                                             const struct glsl_function_param *params,
                                             unsigned num_params);
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list