Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © 2013 Intel Corporation
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the "Software"),
  6.  * to deal in the Software without restriction, including without limitation
  7.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.  * and/or sell copies of the Software, and to permit persons to whom the
  9.  * Software is furnished to do so, subject to the following conditions:
  10.  *
  11.  * The above copyright notice and this permission notice (including the next
  12.  * paragraph) shall be included in all copies or substantial portions of the
  13.  * Software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  18.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21.  * DEALINGS IN THE SOFTWARE.
  22.  */
  23.  
  24. /**
  25.  * \file link_interface_blocks.cpp
  26.  * Linker support for GLSL's interface blocks.
  27.  */
  28.  
  29. #include "ir.h"
  30. #include "glsl_symbol_table.h"
  31. #include "linker.h"
  32. #include "main/macros.h"
  33.  
  34. bool
  35. validate_intrastage_interface_blocks(const gl_shader **shader_list,
  36.                                      unsigned num_shaders)
  37. {
  38.    glsl_symbol_table interfaces;
  39.  
  40.    for (unsigned int i = 0; i < num_shaders; i++) {
  41.       if (shader_list[i] == NULL)
  42.          continue;
  43.  
  44.       foreach_list(node, shader_list[i]->ir) {
  45.          ir_variable *var = ((ir_instruction *) node)->as_variable();
  46.          if (!var)
  47.             continue;
  48.  
  49.          const glsl_type *iface_type = var->interface_type;
  50.  
  51.          if (iface_type == NULL)
  52.             continue;
  53.  
  54.          const glsl_type *old_iface_type =
  55.             interfaces.get_interface(iface_type->name,
  56.                                      (enum ir_variable_mode) var->mode);
  57.  
  58.          if (old_iface_type == NULL) {
  59.             /* This is the first time we've seen the interface, so save
  60.              * it into our symbol table.
  61.              */
  62.             interfaces.add_interface(iface_type->name, iface_type,
  63.                                      (enum ir_variable_mode) var->mode);
  64.          } else if (old_iface_type != iface_type) {
  65.             return false;
  66.          }
  67.       }
  68.    }
  69.  
  70.    return true;
  71. }
  72.  
  73. bool
  74. validate_interstage_interface_blocks(const gl_shader *producer,
  75.                                      const gl_shader *consumer)
  76. {
  77.    glsl_symbol_table interfaces;
  78.  
  79.    /* Add non-output interfaces from the consumer to the symbol table. */
  80.    foreach_list(node, consumer->ir) {
  81.       ir_variable *var = ((ir_instruction *) node)->as_variable();
  82.       if (!var || !var->interface_type || var->mode == ir_var_shader_out)
  83.          continue;
  84.  
  85.       interfaces.add_interface(var->interface_type->name,
  86.                                var->interface_type,
  87.                                (enum ir_variable_mode) var->mode);
  88.    }
  89.  
  90.    /* Verify that the producer's interfaces match. */
  91.    foreach_list(node, producer->ir) {
  92.       ir_variable *var = ((ir_instruction *) node)->as_variable();
  93.       if (!var || !var->interface_type || var->mode == ir_var_shader_in)
  94.          continue;
  95.  
  96.       enum ir_variable_mode consumer_mode =
  97.          var->mode == ir_var_uniform ? ir_var_uniform : ir_var_shader_in;
  98.       const glsl_type *expected_type =
  99.          interfaces.get_interface(var->interface_type->name, consumer_mode);
  100.  
  101.       /* The consumer doesn't use this output block.  Ignore it. */
  102.       if (expected_type == NULL)
  103.          continue;
  104.  
  105.       if (var->interface_type != expected_type)
  106.          return false;
  107.    }
  108.  
  109.    return true;
  110. }
  111.