mesa: pass gl_program to _mesa_associate_uniform_storage()
[mesa.git] / src / mesa / program / ir_to_mesa.cpp
index b0fecde11ca82733ee794c8728618c748909920d..f6608af2240cb4f045fda73d2abe13dbf4de317b 100644 (file)
@@ -1389,12 +1389,6 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
    case ir_unop_dFdy_fine:
    case ir_unop_subroutine_to_int:
    case ir_unop_get_buffer_size:
-   case ir_unop_ballot:
-   case ir_binop_read_invocation:
-   case ir_unop_read_first_invocation:
-   case ir_unop_vote_any:
-   case ir_unop_vote_all:
-   case ir_unop_vote_eq:
    case ir_unop_bitcast_u642d:
    case ir_unop_bitcast_i642d:
    case ir_unop_bitcast_d2u64:
@@ -1423,6 +1417,10 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
    case ir_unop_unpack_int_2x32:
    case ir_unop_pack_uint_2x32:
    case ir_unop_unpack_uint_2x32:
+   case ir_unop_pack_sampler_2x32:
+   case ir_unop_unpack_sampler_2x32:
+   case ir_unop_pack_image_2x32:
+   case ir_unop_unpack_image_2x32:
       assert(!"not supported");
       break;
 
@@ -2422,6 +2420,7 @@ public:
    void process(ir_variable *var)
    {
       this->idx = -1;
+      this->var = var;
       this->program_resource_visitor::process(var);
       var->data.param_index = this->idx;
    }
@@ -2435,6 +2434,7 @@ private:
    struct gl_shader_program *shader_program;
    struct gl_program_parameter_list *params;
    int idx;
+   ir_variable *var;
    gl_shader_stage shader_type;
 };
 
@@ -2447,22 +2447,12 @@ add_uniform_to_shader::visit_field(const glsl_type *type, const char *name,
                                    const enum glsl_interface_packing,
                                    bool /* last_field */)
 {
-   unsigned int size;
-
    /* atomics don't get real storage */
    if (type->contains_atomic())
       return;
 
-   if (type->is_vector() || type->is_scalar()) {
-      size = type->vector_elements;
-      if (type->is_64bit())
-         size *= 2;
-   } else {
-      size = type_size(type) * 4;
-   }
-
    gl_register_file file;
-   if (type->without_array()->is_sampler()) {
+   if (type->without_array()->is_sampler() && !var->data.bindless) {
       file = PROGRAM_SAMPLER;
    } else {
       file = PROGRAM_UNIFORM;
@@ -2470,6 +2460,8 @@ add_uniform_to_shader::visit_field(const glsl_type *type, const char *name,
 
    int index = _mesa_lookup_parameter_index(params, name);
    if (index < 0) {
+      unsigned size = type_size(type) * 4;
+
       index = _mesa_add_parameter(params, file, name, size, type->gl_type,
                                  NULL, NULL);
 
@@ -2536,10 +2528,12 @@ _mesa_generate_parameters_list_for_uniforms(struct gl_shader_program
 
 void
 _mesa_associate_uniform_storage(struct gl_context *ctx,
-                               struct gl_shader_program *shader_program,
-                                struct gl_program_parameter_list *params,
+                                struct gl_shader_program *shader_program,
+                                struct gl_program *prog,
                                 bool propagate_to_storage)
 {
+   struct gl_program_parameter_list *params = prog->Parameters;
+
    /* After adding each uniform to the parameter list, connect the storage for
     * the parameter with the tracking structure used by the API for the
     * uniform.
@@ -2547,15 +2541,15 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
    unsigned last_location = unsigned(~0);
    for (unsigned i = 0; i < params->NumParameters; i++) {
       if (params->Parameters[i].Type != PROGRAM_UNIFORM)
-        continue;
+         continue;
 
       unsigned location;
       const bool found =
-        shader_program->UniformHash->get(location, params->Parameters[i].Name);
+         shader_program->UniformHash->get(location, params->Parameters[i].Name);
       assert(found);
 
       if (!found)
-        continue;
+         continue;
 
       struct gl_uniform_storage *storage =
          &shader_program->data->UniformStorage[location];
@@ -2565,48 +2559,47 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
          continue;
 
       if (location != last_location) {
-        enum gl_uniform_driver_format format = uniform_native;
+         enum gl_uniform_driver_format format = uniform_native;
+         unsigned columns = 0;
+         int dmul = 4 * sizeof(float);
 
-        unsigned columns = 0;
-        int dmul = 4 * sizeof(float);
-        switch (storage->type->base_type) {
+         switch (storage->type->base_type) {
          case GLSL_TYPE_UINT64:
-           if (storage->type->vector_elements > 2)
+            if (storage->type->vector_elements > 2)
                dmul *= 2;
-           /* fallthrough */
-        case GLSL_TYPE_UINT:
-           assert(ctx->Const.NativeIntegers);
-           format = uniform_native;
-           columns = 1;
-           break;
+            /* fallthrough */
+         case GLSL_TYPE_UINT:
+            assert(ctx->Const.NativeIntegers);
+            format = uniform_native;
+            columns = 1;
+            break;
          case GLSL_TYPE_INT64:
-           if (storage->type->vector_elements > 2)
+            if (storage->type->vector_elements > 2)
                dmul *= 2;
-           /* fallthrough */
-        case GLSL_TYPE_INT:
-           format =
-              (ctx->Const.NativeIntegers) ? uniform_native : uniform_int_float;
-           columns = 1;
-           break;
-
-        case GLSL_TYPE_DOUBLE:
-           if (storage->type->vector_elements > 2)
+            /* fallthrough */
+         case GLSL_TYPE_INT:
+            format =
+               (ctx->Const.NativeIntegers) ? uniform_native : uniform_int_float;
+            columns = 1;
+            break;
+         case GLSL_TYPE_DOUBLE:
+            if (storage->type->vector_elements > 2)
                dmul *= 2;
-           /* fallthrough */
-        case GLSL_TYPE_FLOAT:
-           format = uniform_native;
-           columns = storage->type->matrix_columns;
-           break;
-        case GLSL_TYPE_BOOL:
-           format = uniform_native;
-           columns = 1;
-           break;
-        case GLSL_TYPE_SAMPLER:
-        case GLSL_TYPE_IMAGE:
+            /* fallthrough */
+         case GLSL_TYPE_FLOAT:
+            format = uniform_native;
+            columns = storage->type->matrix_columns;
+            break;
+         case GLSL_TYPE_BOOL:
+            format = uniform_native;
+            columns = 1;
+            break;
+         case GLSL_TYPE_SAMPLER:
+         case GLSL_TYPE_IMAGE:
          case GLSL_TYPE_SUBROUTINE:
-           format = uniform_native;
-           columns = 1;
-           break;
+            format = uniform_native;
+            columns = 1;
+            break;
          case GLSL_TYPE_ATOMIC_UINT:
          case GLSL_TYPE_ARRAY:
          case GLSL_TYPE_VOID:
@@ -2614,27 +2607,25 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
          case GLSL_TYPE_ERROR:
          case GLSL_TYPE_INTERFACE:
          case GLSL_TYPE_FUNCTION:
-           assert(!"Should not get here.");
-           break;
-        }
+            assert(!"Should not get here.");
+            break;
+         }
 
-        _mesa_uniform_attach_driver_storage(storage,
-                                            dmul * columns,
-                                            dmul,
-                                            format,
-                                            &params->ParameterValues[i]);
+         _mesa_uniform_attach_driver_storage(storage, dmul * columns, dmul,
+                                             format,
+                                             &params->ParameterValues[i]);
 
-        /* After attaching the driver's storage to the uniform, propagate any
-         * data from the linker's backing store.  This will cause values from
-         * initializers in the source code to be copied over.
-         */
+         /* After attaching the driver's storage to the uniform, propagate any
+          * data from the linker's backing store.  This will cause values from
+          * initializers in the source code to be copied over.
+          */
          if (propagate_to_storage) {
             unsigned array_elements = MAX2(1, storage->array_elements);
             _mesa_propagate_uniforms_to_driver_storage(storage, 0,
                                                        array_elements);
          }
 
-        last_location = location;
+             last_location = location;
       }
    }
 }
@@ -2990,8 +2981,7 @@ get_mesa_program(struct gl_context *ctx,
     * prog->ParameterValues to get reallocated (e.g., anything that adds a
     * program constant) has to happen before creating this linkage.
     */
-   _mesa_associate_uniform_storage(ctx, shader_program, prog->Parameters,
-                                   true);
+   _mesa_associate_uniform_storage(ctx, shader_program, prog, true);
    if (!shader_program->data->LinkStatus) {
       goto fail_exit;
    }
@@ -3117,6 +3107,11 @@ _mesa_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
    }
 
    if (prog->data->LinkStatus) {
+      /* Reset sampler validated to true, validation happens via the
+       * LinkShader call below.
+       */
+      prog->SamplersValidated = GL_TRUE;
+
       if (!ctx->Driver.LinkShader(ctx, prog)) {
          prog->data->LinkStatus = linking_failure;
       }