linker.h revision 7ec681f3
11.2Sjdc/* -*- c++ -*- */ 21.1Sleo/* 31.1Sleo * Copyright © 2010 Intel Corporation 41.1Sleo * 51.1Sleo * Permission is hereby granted, free of charge, to any person obtaining a 61.1Sleo * copy of this software and associated documentation files (the "Software"), 71.1Sleo * to deal in the Software without restriction, including without limitation 81.1Sleo * the rights to use, copy, modify, merge, publish, distribute, sublicense, 91.1Sleo * and/or sell copies of the Software, and to permit persons to whom the 101.1Sleo * Software is furnished to do so, subject to the following conditions: 111.1Sleo * 121.1Sleo * The above copyright notice and this permission notice (including the next 131.1Sleo * paragraph) shall be included in all copies or substantial portions of the 141.1Sleo * Software. 151.1Sleo * 161.1Sleo * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 171.1Sleo * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 181.1Sleo * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 191.1Sleo * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 201.1Sleo * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 211.1Sleo * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 221.1Sleo * DEALINGS IN THE SOFTWARE. 231.1Sleo */ 241.1Sleo 251.1Sleo#ifndef GLSL_LINKER_H 261.1Sleo#define GLSL_LINKER_H 271.1Sleo 281.1Sleo#include "linker_util.h" 291.1Sleo 301.1Sleostruct gl_shader_program; 311.1Sleostruct gl_shader; 321.1Sleostruct gl_linked_shader; 331.1Sleo 341.1Sleoextern bool 351.1Sleolink_function_calls(gl_shader_program *prog, gl_linked_shader *main, 361.1Sleo gl_shader **shader_list, unsigned num_shaders); 371.1Sleo 381.1Sleoextern void 391.1Sleolink_invalidate_variable_locations(exec_list *ir); 401.1Sleo 411.1Sleoextern void 421.1Sleolink_assign_uniform_locations(struct gl_shader_program *prog, 431.1Sleo struct gl_context *ctx); 441.1Sleo 451.1Sleoextern void 461.1Sleolink_set_uniform_initializers(struct gl_shader_program *prog, 471.1Sleo unsigned int boolean_true); 481.1Sleo 491.1Sleoextern int 501.1Sleolink_cross_validate_uniform_block(void *mem_ctx, 511.1Sleo struct gl_uniform_block **linked_blocks, 521.1Sleo unsigned int *num_linked_blocks, 531.1Sleo struct gl_uniform_block *new_block); 541.1Sleo 551.1Sleoextern void 561.1Sleolink_uniform_blocks(void *mem_ctx, 571.1Sleo struct gl_context *ctx, 581.1Sleo struct gl_shader_program *prog, 591.1Sleo struct gl_linked_shader *shader, 601.1Sleo struct gl_uniform_block **ubo_blocks, 611.1Sleo unsigned *num_ubo_blocks, 621.1Sleo struct gl_uniform_block **ssbo_blocks, 631.1Sleo unsigned *num_ssbo_blocks); 641.1Sleo 651.1Sleobool 661.1Sleovalidate_intrastage_arrays(struct gl_shader_program *prog, 671.1Sleo ir_variable *const var, 681.1Sleo ir_variable *const existing, 691.1Sleo bool match_precision = true); 701.1Sleo 711.1Sleovoid 721.1Sleovalidate_intrastage_interface_blocks(struct gl_shader_program *prog, 731.1Sleo const gl_shader **shader_list, 741.2Sjdc unsigned num_shaders); 751.1Sleo 761.1Sleovoid 771.1Sleovalidate_interstage_inout_blocks(struct gl_shader_program *prog, 781.1Sleo const gl_linked_shader *producer, 791.1Sleo const gl_linked_shader *consumer); 801.1Sleo 811.1Sleovoid 821.1Sleovalidate_interstage_uniform_blocks(struct gl_shader_program *prog, 831.1Sleo gl_linked_shader **stages); 841.1Sleo 851.1Sleoextern void 861.1Sleolink_assign_atomic_counter_resources(struct gl_context *ctx, 871.1Sleo struct gl_shader_program *prog); 881.1Sleo 891.1Sleoextern void 901.1Sleolink_check_atomic_counter_resources(struct gl_context *ctx, 911.1Sleo struct gl_shader_program *prog); 921.1Sleo 931.1Sleo 941.1Sleoextern struct gl_linked_shader * 951.1Sleolink_intrastage_shaders(void *mem_ctx, 961.1Sleo struct gl_context *ctx, 971.1Sleo struct gl_shader_program *prog, 981.1Sleo struct gl_shader **shader_list, 991.1Sleo unsigned num_shaders, 1001.1Sleo bool allow_missing_main); 1011.1Sleo 1021.1Sleoextern unsigned 1031.2Sjdclink_calculate_matrix_stride(const glsl_type *matrix, bool row_major, 1041.1Sleo enum glsl_interface_packing packing); 1051.1Sleo 1061.1Sleo/** 1071.1Sleo * Class for processing all of the leaf fields of a variable that corresponds 1081.1Sleo * to a program resource. 1091.1Sleo * 1101.1Sleo * The leaf fields are all the parts of the variable that the application 1111.1Sleo * could query using \c glGetProgramResourceIndex (or that could be returned 1121.1Sleo * by \c glGetProgramResourceName). 1131.1Sleo * 1141.1Sleo * Classes my derive from this class to implement specific functionality. 1151.1Sleo * This class only provides the mechanism to iterate over the leaves. Derived 1161.1Sleo * classes must implement \c ::visit_field and may override \c ::process. 1171.1Sleo */ 1181.1Sleoclass program_resource_visitor { 1191.1Sleopublic: 1201.1Sleo /** 1211.1Sleo * Begin processing a variable 1221.1Sleo * 1231.1Sleo * Classes that overload this function should call \c ::process from the 1241.1Sleo * base class to start the recursive processing of the variable. 1251.1Sleo * 1261.1Sleo * \param var The variable that is to be processed 1271.1Sleo * 1281.1Sleo * Calls \c ::visit_field for each leaf of the variable. 1291.1Sleo * 1301.1Sleo * \warning 1311.1Sleo * When processing a uniform block, this entry should only be used in cases 1321.1Sleo * where the row / column ordering of matrices in the block does not 1331.1Sleo * matter. For example, enumerating the names of members of the block, but 1341.1Sleo * not for determining the offsets of members. 1351.1Sleo */ 1361.1Sleo void process(ir_variable *var, bool use_std430_as_default); 1371.1Sleo 1381.1Sleo /** 1391.1Sleo * Begin processing a variable 1401.1Sleo * 1411.1Sleo * Classes that overload this function should call \c ::process from the 1421.1Sleo * base class to start the recursive processing of the variable. 1431.1Sleo * 1441.1Sleo * \param var The variable that is to be processed 1451.1Sleo * \param var_type The glsl_type reference of the variable 1461.1Sleo * 1471.1Sleo * Calls \c ::visit_field for each leaf of the variable. 1481.1Sleo * 1491.1Sleo * \warning 1501.1Sleo * When processing a uniform block, this entry should only be used in cases 1511.1Sleo * where the row / column ordering of matrices in the block does not 1521.1Sleo * matter. For example, enumerating the names of members of the block, but 1531.1Sleo * not for determining the offsets of members. 1541.1Sleo */ 1551.1Sleo void process(ir_variable *var, const glsl_type *var_type, 1561.1Sleo bool use_std430_as_default); 1571.1Sleo 1581.1Sleo /** 1591.1Sleo * Begin processing a variable of a structured type. 1601.1Sleo * 1611.1Sleo * This flavor of \c process should be used to handle structured types 1621.1Sleo * (i.e., structures, interfaces, or arrays there of) that need special 1631.1Sleo * name handling. A common usage is to handle cases where the block name 1641.1Sleo * (instead of the instance name) is used for an interface block. 1651.1Sleo * 1661.1Sleo * \param type Type that is to be processed, associated with \c name 1671.1Sleo * \param name Base name of the structured variable being processed 1681.1Sleo * 1691.1Sleo * \note 1701.1Sleo * \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array 1711.1Sleo * there of. 1721.1Sleo */ 1731.1Sleo void process(const glsl_type *type, const char *name, 1741.1Sleo bool use_std430_as_default); 1751.1Sleo 1761.1Sleoprotected: 1771.1Sleo /** 1781.1Sleo * Method invoked for each leaf of the variable 1791.1Sleo * 1801.1Sleo * \param type Type of the field. 1811.1Sleo * \param name Fully qualified name of the field. 1821.1Sleo * \param row_major For a matrix type, is it stored row-major. 1831.1Sleo * \param record_type Type of the record containing the field. 1841.1Sleo * \param last_field Set if \c name is the last field of the structure 1851.1Sleo * containing it. This will always be false for items 1861.1Sleo * not contained in a structure or interface block. 1871.1Sleo */ 1881.1Sleo virtual void visit_field(const glsl_type *type, const char *name, 1891.1Sleo bool row_major, const glsl_type *record_type, 1901.1Sleo const enum glsl_interface_packing packing, 1911.1Sleo bool last_field) = 0; 1921.1Sleo 1931.1Sleo virtual void enter_record(const glsl_type *type, const char *name, 1941.1Sleo bool row_major, const enum glsl_interface_packing packing); 1951.1Sleo 1961.1Sleo virtual void leave_record(const glsl_type *type, const char *name, 1971.1Sleo bool row_major, const enum glsl_interface_packing packing); 1981.1Sleo 1991.1Sleo virtual void set_buffer_offset(unsigned offset); 2001.1Sleo 2011.1Sleo virtual void set_record_array_count(unsigned record_array_count); 2021.1Sleo 2031.1Sleoprivate: 2041.1Sleo /** 2051.1Sleo * \param name_length Length of the current name \b not including the 2061.1Sleo * terminating \c NUL character. 2071.1Sleo * \param last_field Set if \c name is the last field of the structure 2081.1Sleo * containing it. This will always be false for items 2091.1Sleo * not contained in a structure or interface block. 2101.1Sleo */ 2111.1Sleo void recursion(const glsl_type *t, char **name, size_t name_length, 2121.1Sleo bool row_major, const glsl_type *record_type, 2131.1Sleo const enum glsl_interface_packing packing, 2141.1Sleo bool last_field, unsigned record_array_count, 2151.1Sleo const glsl_struct_field *named_ifc_member); 2161.1Sleo}; 2171.1Sleo 2181.1Sleo#endif /* GLSL_LINKER_H */ 2191.1Sleo