101e04c3fSmrg/* -*- c++ -*- */ 201e04c3fSmrg/* 301e04c3fSmrg * Copyright © 2010 Intel Corporation 401e04c3fSmrg * 501e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 601e04c3fSmrg * copy of this software and associated documentation files (the "Software"), 701e04c3fSmrg * to deal in the Software without restriction, including without limitation 801e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 901e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the 1001e04c3fSmrg * Software is furnished to do so, subject to the following conditions: 1101e04c3fSmrg * 1201e04c3fSmrg * The above copyright notice and this permission notice (including the next 1301e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the 1401e04c3fSmrg * Software. 1501e04c3fSmrg * 1601e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1701e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1801e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1901e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2001e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2101e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 2201e04c3fSmrg * DEALINGS IN THE SOFTWARE. 2301e04c3fSmrg */ 2401e04c3fSmrg 2501e04c3fSmrg#ifndef GLSL_LINKER_H 2601e04c3fSmrg#define GLSL_LINKER_H 2701e04c3fSmrg 2801e04c3fSmrg#include "linker_util.h" 2901e04c3fSmrg 3001e04c3fSmrgstruct gl_shader_program; 3101e04c3fSmrgstruct gl_shader; 3201e04c3fSmrgstruct gl_linked_shader; 3301e04c3fSmrg 3401e04c3fSmrgextern bool 3501e04c3fSmrglink_function_calls(gl_shader_program *prog, gl_linked_shader *main, 3601e04c3fSmrg gl_shader **shader_list, unsigned num_shaders); 3701e04c3fSmrg 3801e04c3fSmrgextern void 3901e04c3fSmrglink_invalidate_variable_locations(exec_list *ir); 4001e04c3fSmrg 4101e04c3fSmrgextern void 4201e04c3fSmrglink_assign_uniform_locations(struct gl_shader_program *prog, 4301e04c3fSmrg struct gl_context *ctx); 4401e04c3fSmrg 4501e04c3fSmrgextern void 4601e04c3fSmrglink_set_uniform_initializers(struct gl_shader_program *prog, 4701e04c3fSmrg unsigned int boolean_true); 4801e04c3fSmrg 4901e04c3fSmrgextern int 5001e04c3fSmrglink_cross_validate_uniform_block(void *mem_ctx, 5101e04c3fSmrg struct gl_uniform_block **linked_blocks, 5201e04c3fSmrg unsigned int *num_linked_blocks, 5301e04c3fSmrg struct gl_uniform_block *new_block); 5401e04c3fSmrg 5501e04c3fSmrgextern void 5601e04c3fSmrglink_uniform_blocks(void *mem_ctx, 5701e04c3fSmrg struct gl_context *ctx, 5801e04c3fSmrg struct gl_shader_program *prog, 5901e04c3fSmrg struct gl_linked_shader *shader, 6001e04c3fSmrg struct gl_uniform_block **ubo_blocks, 6101e04c3fSmrg unsigned *num_ubo_blocks, 6201e04c3fSmrg struct gl_uniform_block **ssbo_blocks, 6301e04c3fSmrg unsigned *num_ssbo_blocks); 6401e04c3fSmrg 6501e04c3fSmrgbool 6601e04c3fSmrgvalidate_intrastage_arrays(struct gl_shader_program *prog, 6701e04c3fSmrg ir_variable *const var, 687ec681f3Smrg ir_variable *const existing, 697ec681f3Smrg bool match_precision = true); 7001e04c3fSmrg 7101e04c3fSmrgvoid 7201e04c3fSmrgvalidate_intrastage_interface_blocks(struct gl_shader_program *prog, 7301e04c3fSmrg const gl_shader **shader_list, 7401e04c3fSmrg unsigned num_shaders); 7501e04c3fSmrg 7601e04c3fSmrgvoid 7701e04c3fSmrgvalidate_interstage_inout_blocks(struct gl_shader_program *prog, 7801e04c3fSmrg const gl_linked_shader *producer, 7901e04c3fSmrg const gl_linked_shader *consumer); 8001e04c3fSmrg 8101e04c3fSmrgvoid 8201e04c3fSmrgvalidate_interstage_uniform_blocks(struct gl_shader_program *prog, 8301e04c3fSmrg gl_linked_shader **stages); 8401e04c3fSmrg 8501e04c3fSmrgextern void 8601e04c3fSmrglink_assign_atomic_counter_resources(struct gl_context *ctx, 8701e04c3fSmrg struct gl_shader_program *prog); 8801e04c3fSmrg 8901e04c3fSmrgextern void 9001e04c3fSmrglink_check_atomic_counter_resources(struct gl_context *ctx, 9101e04c3fSmrg struct gl_shader_program *prog); 9201e04c3fSmrg 9301e04c3fSmrg 9401e04c3fSmrgextern struct gl_linked_shader * 9501e04c3fSmrglink_intrastage_shaders(void *mem_ctx, 9601e04c3fSmrg struct gl_context *ctx, 9701e04c3fSmrg struct gl_shader_program *prog, 9801e04c3fSmrg struct gl_shader **shader_list, 9901e04c3fSmrg unsigned num_shaders, 10001e04c3fSmrg bool allow_missing_main); 10101e04c3fSmrg 10201e04c3fSmrgextern unsigned 10301e04c3fSmrglink_calculate_matrix_stride(const glsl_type *matrix, bool row_major, 10401e04c3fSmrg enum glsl_interface_packing packing); 10501e04c3fSmrg 10601e04c3fSmrg/** 10701e04c3fSmrg * Class for processing all of the leaf fields of a variable that corresponds 10801e04c3fSmrg * to a program resource. 10901e04c3fSmrg * 11001e04c3fSmrg * The leaf fields are all the parts of the variable that the application 11101e04c3fSmrg * could query using \c glGetProgramResourceIndex (or that could be returned 11201e04c3fSmrg * by \c glGetProgramResourceName). 11301e04c3fSmrg * 11401e04c3fSmrg * Classes my derive from this class to implement specific functionality. 11501e04c3fSmrg * This class only provides the mechanism to iterate over the leaves. Derived 11601e04c3fSmrg * classes must implement \c ::visit_field and may override \c ::process. 11701e04c3fSmrg */ 11801e04c3fSmrgclass program_resource_visitor { 11901e04c3fSmrgpublic: 12001e04c3fSmrg /** 12101e04c3fSmrg * Begin processing a variable 12201e04c3fSmrg * 12301e04c3fSmrg * Classes that overload this function should call \c ::process from the 12401e04c3fSmrg * base class to start the recursive processing of the variable. 12501e04c3fSmrg * 12601e04c3fSmrg * \param var The variable that is to be processed 12701e04c3fSmrg * 12801e04c3fSmrg * Calls \c ::visit_field for each leaf of the variable. 12901e04c3fSmrg * 13001e04c3fSmrg * \warning 13101e04c3fSmrg * When processing a uniform block, this entry should only be used in cases 13201e04c3fSmrg * where the row / column ordering of matrices in the block does not 13301e04c3fSmrg * matter. For example, enumerating the names of members of the block, but 13401e04c3fSmrg * not for determining the offsets of members. 13501e04c3fSmrg */ 13601e04c3fSmrg void process(ir_variable *var, bool use_std430_as_default); 13701e04c3fSmrg 138993e1d59Smrg /** 139993e1d59Smrg * Begin processing a variable 140993e1d59Smrg * 141993e1d59Smrg * Classes that overload this function should call \c ::process from the 142993e1d59Smrg * base class to start the recursive processing of the variable. 143993e1d59Smrg * 144993e1d59Smrg * \param var The variable that is to be processed 145993e1d59Smrg * \param var_type The glsl_type reference of the variable 146993e1d59Smrg * 147993e1d59Smrg * Calls \c ::visit_field for each leaf of the variable. 148993e1d59Smrg * 149993e1d59Smrg * \warning 150993e1d59Smrg * When processing a uniform block, this entry should only be used in cases 151993e1d59Smrg * where the row / column ordering of matrices in the block does not 152993e1d59Smrg * matter. For example, enumerating the names of members of the block, but 153993e1d59Smrg * not for determining the offsets of members. 154993e1d59Smrg */ 155993e1d59Smrg void process(ir_variable *var, const glsl_type *var_type, 156993e1d59Smrg bool use_std430_as_default); 157993e1d59Smrg 15801e04c3fSmrg /** 15901e04c3fSmrg * Begin processing a variable of a structured type. 16001e04c3fSmrg * 16101e04c3fSmrg * This flavor of \c process should be used to handle structured types 16201e04c3fSmrg * (i.e., structures, interfaces, or arrays there of) that need special 16301e04c3fSmrg * name handling. A common usage is to handle cases where the block name 16401e04c3fSmrg * (instead of the instance name) is used for an interface block. 16501e04c3fSmrg * 16601e04c3fSmrg * \param type Type that is to be processed, associated with \c name 16701e04c3fSmrg * \param name Base name of the structured variable being processed 16801e04c3fSmrg * 16901e04c3fSmrg * \note 17001e04c3fSmrg * \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array 17101e04c3fSmrg * there of. 17201e04c3fSmrg */ 17301e04c3fSmrg void process(const glsl_type *type, const char *name, 17401e04c3fSmrg bool use_std430_as_default); 17501e04c3fSmrg 17601e04c3fSmrgprotected: 17701e04c3fSmrg /** 17801e04c3fSmrg * Method invoked for each leaf of the variable 17901e04c3fSmrg * 18001e04c3fSmrg * \param type Type of the field. 18101e04c3fSmrg * \param name Fully qualified name of the field. 18201e04c3fSmrg * \param row_major For a matrix type, is it stored row-major. 18301e04c3fSmrg * \param record_type Type of the record containing the field. 18401e04c3fSmrg * \param last_field Set if \c name is the last field of the structure 18501e04c3fSmrg * containing it. This will always be false for items 18601e04c3fSmrg * not contained in a structure or interface block. 18701e04c3fSmrg */ 18801e04c3fSmrg virtual void visit_field(const glsl_type *type, const char *name, 18901e04c3fSmrg bool row_major, const glsl_type *record_type, 19001e04c3fSmrg const enum glsl_interface_packing packing, 19101e04c3fSmrg bool last_field) = 0; 19201e04c3fSmrg 19301e04c3fSmrg virtual void enter_record(const glsl_type *type, const char *name, 19401e04c3fSmrg bool row_major, const enum glsl_interface_packing packing); 19501e04c3fSmrg 19601e04c3fSmrg virtual void leave_record(const glsl_type *type, const char *name, 19701e04c3fSmrg bool row_major, const enum glsl_interface_packing packing); 19801e04c3fSmrg 19901e04c3fSmrg virtual void set_buffer_offset(unsigned offset); 20001e04c3fSmrg 20101e04c3fSmrg virtual void set_record_array_count(unsigned record_array_count); 20201e04c3fSmrg 20301e04c3fSmrgprivate: 20401e04c3fSmrg /** 20501e04c3fSmrg * \param name_length Length of the current name \b not including the 20601e04c3fSmrg * terminating \c NUL character. 20701e04c3fSmrg * \param last_field Set if \c name is the last field of the structure 20801e04c3fSmrg * containing it. This will always be false for items 20901e04c3fSmrg * not contained in a structure or interface block. 21001e04c3fSmrg */ 21101e04c3fSmrg void recursion(const glsl_type *t, char **name, size_t name_length, 21201e04c3fSmrg bool row_major, const glsl_type *record_type, 21301e04c3fSmrg const enum glsl_interface_packing packing, 21401e04c3fSmrg bool last_field, unsigned record_array_count, 21501e04c3fSmrg const glsl_struct_field *named_ifc_member); 21601e04c3fSmrg}; 21701e04c3fSmrg 21801e04c3fSmrg#endif /* GLSL_LINKER_H */ 219