Module: Mesa
Branch: main
Commit: 7d0d4a494e16e7026bde293f80351cbe58829641
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=7d0d4a494e16e7026bde293f80351cbe58829641

Author: Caio Oliveira <[email protected]>
Date:   Thu Dec 14 22:16:15 2023 -0800

mesa: Use glsl_type C helpers

Reviewed-by: Jesse Natalie <[email protected]>
Acked-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26707>

---

 src/mesa/main/shader_query.cpp            | 12 ++++----
 src/mesa/main/uniform_query.cpp           | 50 +++++++++++++++----------------
 src/mesa/state_tracker/st_glsl_to_nir.cpp |  6 ++--
 3 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index 88de7139825..92442682dd2 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -1122,7 +1122,7 @@ program_resource_location(struct gl_program_resource 
*res, unsigned array_index)
          return -1;
       }
       return var->location +
-            (array_index * var->type->without_array()->matrix_columns);
+            (array_index * glsl_without_array(var->type)->matrix_columns);
    }
    case GL_PROGRAM_OUTPUT:
       if (RESOURCE_VAR(res)->location == -1)
@@ -1144,7 +1144,7 @@ program_resource_location(struct gl_program_resource 
*res, unsigned array_index)
       *     "A valid name cannot be a structure, an array of structures, or any
       *     portion of a single vector or a matrix."
       */
-      if (RESOURCE_UNI(res)->type->without_array()->is_struct())
+      if (glsl_type_is_struct(glsl_without_array(RESOURCE_UNI(res)->type)))
          return -1;
 
       /* From the GL_ARB_uniform_buffer_object spec:
@@ -2013,10 +2013,10 @@ validate_io(struct gl_program *producer, struct 
gl_program *consumer)
       if (consumer_is_array_stage) {
          if (consumer_interface_type) {
             /* the interface is the array; the underlying types should match */
-            if (consumer_interface_type->is_array() && !consumer_var->patch)
+            if (glsl_type_is_array(consumer_interface_type) && 
!consumer_var->patch)
                consumer_interface_type = consumer_interface_type->fields.array;
          } else {
-            if (consumer_type->is_array() && !consumer_var->patch)
+            if (glsl_type_is_array(consumer_type) && !consumer_var->patch)
                consumer_type = consumer_type->fields.array;
          }
       }
@@ -2024,10 +2024,10 @@ validate_io(struct gl_program *producer, struct 
gl_program *consumer)
       if (producer_is_array_stage) {
          if (producer_interface_type) {
             /* the interface is the array; the underlying types should match */
-            if (producer_interface_type->is_array() && !producer_var->patch)
+            if (glsl_type_is_array(producer_interface_type) && 
!producer_var->patch)
                producer_interface_type = producer_interface_type->fields.array;
          } else {
-            if (producer_type->is_array() && !producer_var->patch)
+            if (glsl_type_is_array(producer_type) && !producer_var->patch)
                producer_type = producer_type->fields.array;
          }
       }
diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index d1863697e72..193833bdf2a 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -345,13 +345,13 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, 
GLint location,
    }
 
    {
-      unsigned elements = uni->type->components();
+      unsigned elements = glsl_get_components(uni->type);
       unsigned components = uni->type->vector_elements;
 
       const int rmul = glsl_base_type_is_64bit(returnType) ? 2 : 1;
-      int dmul = (uni->type->is_64bit()) ? 2 : 1;
+      int dmul = (glsl_type_is_64bit(uni->type)) ? 2 : 1;
 
-      if ((uni->type->is_sampler() || uni->type->is_image()) &&
+      if ((glsl_type_is_sampler(uni->type) || glsl_type_is_image(uni->type)) &&
           !uni->is_bindless) {
          /* Non-bindless samplers/images are represented using unsigned integer
           * 32-bit, while bindless handles are 64-bit.
@@ -364,7 +364,7 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, 
GLint location,
        */
       const union gl_constant_value *src;
       if (ctx->Const.PackedDriverUniformStorage &&
-          (uni->is_bindless || !uni->type->contains_opaque())) {
+          (uni->is_bindless || !glsl_contains_opaque(uni->type))) {
          unsigned dword_elements = elements;
 
          /* 16-bit uniforms are packed. */
@@ -398,7 +398,7 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, 
GLint location,
        */
       if (returnType == uni->type->base_type ||
           ((returnType == GLSL_TYPE_INT || returnType == GLSL_TYPE_UINT) &&
-           (uni->type->is_sampler() || uni->type->is_image())) ||
+           (glsl_type_is_sampler(uni->type) || glsl_type_is_image(uni->type))) 
||
           (returnType == GLSL_TYPE_UINT64 && uni->is_bindless)) {
          memcpy(paramsOut, src, bytes);
       } else {
@@ -836,7 +836,7 @@ _mesa_propagate_uniforms_to_driver_storage(struct 
gl_uniform_storage *uni,
 
    const unsigned components = uni->type->vector_elements;
    const unsigned vectors = uni->type->matrix_columns;
-   const int dmul = uni->type->is_64bit() ? 2 : 1;
+   const int dmul = glsl_type_is_64bit(uni->type) ? 2 : 1;
 
    /* Store the data in the driver's requested type in the driver's storage
     * areas.
@@ -1033,11 +1033,11 @@ associate_uniform_storage(struct gl_context *ctx,
             for (unsigned j = 0; j < array_elements; ++j) {
                unsigned unit = storage->opaque[shader_type].index + j;
 
-               if (storage->type->without_array()->is_sampler()) {
+               if (glsl_type_is_sampler(glsl_without_array(storage->type))) {
                   assert(unit >= 0 && unit < prog->sh.NumBindlessSamplers);
                   prog->sh.BindlessSamplers[unit].data =
                      &params->ParameterValues[pvo] + 4 * j;
-               } else if (storage->type->without_array()->is_image()) {
+               } else if 
(glsl_type_is_image(glsl_without_array(storage->type))) {
                   assert(unit >= 0 && unit < prog->sh.NumBindlessImages);
                   prog->sh.BindlessImages[unit].data =
                      &params->ParameterValues[pvo] + 4 * j;
@@ -1051,8 +1051,8 @@ associate_uniform_storage(struct gl_context *ctx,
           */
          unsigned array_elements = MAX2(1, storage->array_elements);
          if (ctx->Const.PackedDriverUniformStorage && 
!prog->info.use_legacy_math_rules &&
-             (storage->is_bindless || !storage->type->contains_opaque())) {
-            const int dmul = storage->type->is_64bit() ? 2 : 1;
+             (storage->is_bindless || !glsl_contains_opaque(storage->type))) {
+            const int dmul = glsl_type_is_64bit(storage->type) ? 2 : 1;
             const unsigned components =
                storage->type->vector_elements *
                storage->type->matrix_columns;
@@ -1149,7 +1149,7 @@ validate_uniform(GLint location, GLsizei count, const 
GLvoid *values,
    if (uni == NULL)
       return NULL;
 
-   if (uni->type->is_matrix()) {
+   if (glsl_type_is_matrix(uni->type)) {
       /* Can't set matrix uniforms (like mat4) with glUniform */
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "glUniform%u(uniform \"%s\"@%d is matrix)",
@@ -1219,7 +1219,7 @@ validate_uniform(GLint location, GLsizei count, const 
GLvoid *values,
     * Based on that, when an invalid sampler is specified, we generate a
     * GL_INVALID_VALUE error and ignore the command.
     */
-   if (uni->type->is_sampler()) {
+   if (glsl_type_is_sampler(uni->type)) {
       for (int i = 0; i < count; i++) {
          const unsigned texUnit = ((unsigned *) values)[i];
 
@@ -1237,7 +1237,7 @@ validate_uniform(GLint location, GLsizei count, const 
GLvoid *values,
       ctx->_Shader->Validated = ctx->_Shader->UserValidated = GL_FALSE;
    }
 
-   if (uni->type->is_image()) {
+   if (glsl_type_is_image(uni->type)) {
       for (int i = 0; i < count; i++) {
          const int unit = ((GLint *) values)[i];
 
@@ -1259,9 +1259,9 @@ _mesa_flush_vertices_for_uniforms(struct gl_context *ctx,
                                   const struct gl_uniform_storage *uni)
 {
    /* Opaque uniforms have no storage unless they are bindless */
-   if (!uni->is_bindless && uni->type->contains_opaque()) {
+   if (!uni->is_bindless && glsl_contains_opaque(uni->type)) {
       /* Samplers flush on demand and ignore redundant updates. */
-      if (!uni->type->is_sampler())
+      if (!glsl_type_is_sampler(uni->type))
          FLUSH_VERTICES(ctx, 0, 0);
       return;
    }
@@ -1290,10 +1290,10 @@ copy_uniforms_to_storage(gl_constant_value *storage,
 {
    const gl_constant_value *src = (const gl_constant_value*)values;
    bool copy_as_uint64 = uni->is_bindless &&
-                         (uni->type->is_sampler() || uni->type->is_image());
+                         (glsl_type_is_sampler(uni->type) || 
glsl_type_is_image(uni->type));
    bool copy_to_float16 = uni->type->base_type == GLSL_TYPE_FLOAT16;
 
-   if (!uni->type->is_boolean() && !copy_as_uint64 && !copy_to_float16) {
+   if (!glsl_type_is_boolean(uni->type) && !copy_as_uint64 && 
!copy_to_float16) {
       unsigned size = sizeof(storage[0]) * components * count * size_mul;
 
       if (!memcmp(storage, values, size))
@@ -1489,7 +1489,7 @@ _mesa_uniform(GLint location, GLsizei count, const GLvoid 
*values,
    bool ctx_flushed = false;
    gl_constant_value *storage;
    if (ctx->Const.PackedDriverUniformStorage &&
-       (uni->is_bindless || !uni->type->contains_opaque())) {
+       (uni->is_bindless || !glsl_contains_opaque(uni->type))) {
       for (unsigned s = 0; s < uni->num_driver_storage; s++) {
          unsigned dword_components = components;
 
@@ -1515,13 +1515,13 @@ _mesa_uniform(GLint location, GLsizei count, const 
GLvoid *values,
    /* Return early if possible. Bindless samplers need to be processed
     * because of the !sampler->bound codepath below.
     */
-   if (!ctx_flushed && !(uni->type->is_sampler() && uni->is_bindless))
+   if (!ctx_flushed && !(glsl_type_is_sampler(uni->type) && uni->is_bindless))
       return; /* no change in uniform values */
 
    /* If the uniform is a sampler, do the extra magic necessary to propagate
     * the changes through.
     */
-   if (uni->type->is_sampler()) {
+   if (glsl_type_is_sampler(uni->type)) {
       /* Note that samplers are the only uniforms that don't call
        * FLUSH_VERTICES above.
        */
@@ -1587,7 +1587,7 @@ _mesa_uniform(GLint location, GLsizei count, const GLvoid 
*values,
    /* If the uniform is an image, update the mapping from image
     * uniforms to image units present in the shader data structure.
     */
-   if (uni->type->is_image()) {
+   if (glsl_type_is_image(uni->type)) {
       for (int i = 0; i < MESA_SHADER_STAGES; i++) {
          struct gl_linked_shader *sh = shProg->_LinkedShaders[i];
 
@@ -1861,7 +1861,7 @@ _mesa_uniform_matrix(GLint location, GLsizei count,
       }
    }
 
-   if (!uni->type->is_matrix()) {
+   if (!glsl_type_is_matrix(uni->type)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                  "glUniformMatrix(non-matrix uniform)");
       return;
@@ -1870,7 +1870,7 @@ _mesa_uniform_matrix(GLint location, GLsizei count,
    assert(basicType == GLSL_TYPE_FLOAT || basicType == GLSL_TYPE_DOUBLE);
    const unsigned size_mul = basicType == GLSL_TYPE_DOUBLE ? 2 : 1;
 
-   assert(!uni->type->is_sampler());
+   assert(!glsl_type_is_sampler(uni->type));
    const unsigned vectors = uni->type->matrix_columns;
    const unsigned components = uni->type->vector_elements;
 
@@ -2109,7 +2109,7 @@ _mesa_uniform_handle(GLint location, GLsizei count, const 
GLvoid *values,
       _mesa_propagate_uniforms_to_driver_storage(uni, offset, count);
    }
 
-   if (uni->type->is_sampler()) {
+   if (glsl_type_is_sampler(uni->type)) {
       /* Mark this bindless sampler as not bound to a texture unit because
        * it refers to a texture handle.
        */
@@ -2132,7 +2132,7 @@ _mesa_uniform_handle(GLint location, GLsizei count, const 
GLvoid *values,
       }
    }
 
-   if (uni->type->is_image()) {
+   if (glsl_type_is_image(uni->type)) {
       /* Mark this bindless image as not bound to an image unit because it
        * refers to a texture handle.
        */
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp 
b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index bba2e0a7f9e..736a999cbb4 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -58,7 +58,7 @@
 static int
 type_size(const struct glsl_type *type)
 {
-   return type->count_attribute_slots(false);
+   return glsl_count_attribute_slots(type, false);
 }
 
 /* Depending on PIPE_CAP_TGSI_TEXCOORD (st->needs_texcoord_semantic) we
@@ -189,8 +189,8 @@ st_nir_assign_uniform_locations(struct gl_context *ctx,
       int loc;
 
       const struct glsl_type *type = glsl_without_array(uniform->type);
-      if (!uniform->data.bindless && (type->is_sampler() || type->is_image())) 
{
-         if (type->is_sampler()) {
+      if (!uniform->data.bindless && (glsl_type_is_sampler(type) || 
glsl_type_is_image(type))) {
+         if (glsl_type_is_sampler(type)) {
             loc = shaderidx;
             shaderidx += type_size(uniform->type);
          } else {

Reply via email to