program.h revision af69d88d
13464ebd5Sriastradh/* 23464ebd5Sriastradh * Mesa 3-D graphics library 33464ebd5Sriastradh * 43464ebd5Sriastradh * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 53464ebd5Sriastradh * 63464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a 73464ebd5Sriastradh * copy of this software and associated documentation files (the "Software"), 83464ebd5Sriastradh * to deal in the Software without restriction, including without limitation 93464ebd5Sriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense, 103464ebd5Sriastradh * and/or sell copies of the Software, and to permit persons to whom the 113464ebd5Sriastradh * Software is furnished to do so, subject to the following conditions: 123464ebd5Sriastradh * 133464ebd5Sriastradh * The above copyright notice and this permission notice shall be included 143464ebd5Sriastradh * in all copies or substantial portions of the Software. 153464ebd5Sriastradh * 163464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 173464ebd5Sriastradh * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 183464ebd5Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE. 233464ebd5Sriastradh */ 243464ebd5Sriastradh 253464ebd5Sriastradh/** 263464ebd5Sriastradh * \file program.c 273464ebd5Sriastradh * Vertex and fragment program support functions. 283464ebd5Sriastradh * \author Brian Paul 293464ebd5Sriastradh */ 303464ebd5Sriastradh 313464ebd5Sriastradh 323464ebd5Sriastradh/** 333464ebd5Sriastradh * \mainpage Mesa vertex and fragment program module 343464ebd5Sriastradh * 353464ebd5Sriastradh * This module or directory contains most of the code for vertex and 363464ebd5Sriastradh * fragment programs and shaders, including state management, parsers, 373464ebd5Sriastradh * and (some) software routines for executing programs 383464ebd5Sriastradh */ 393464ebd5Sriastradh 403464ebd5Sriastradh#ifndef PROGRAM_H 413464ebd5Sriastradh#define PROGRAM_H 423464ebd5Sriastradh 433464ebd5Sriastradh#include "main/compiler.h" 443464ebd5Sriastradh#include "main/mtypes.h" 453464ebd5Sriastradh 463464ebd5Sriastradh 47af69d88dSmrg#ifdef __cplusplus 48af69d88dSmrgextern "C" { 49af69d88dSmrg#endif 50af69d88dSmrg 513464ebd5Sriastradhextern struct gl_program _mesa_DummyProgram; 523464ebd5Sriastradh 533464ebd5Sriastradh 543464ebd5Sriastradhextern void 553464ebd5Sriastradh_mesa_init_program(struct gl_context *ctx); 563464ebd5Sriastradh 573464ebd5Sriastradhextern void 583464ebd5Sriastradh_mesa_free_program_data(struct gl_context *ctx); 593464ebd5Sriastradh 603464ebd5Sriastradhextern void 613464ebd5Sriastradh_mesa_update_default_objects_program(struct gl_context *ctx); 623464ebd5Sriastradh 633464ebd5Sriastradhextern void 643464ebd5Sriastradh_mesa_set_program_error(struct gl_context *ctx, GLint pos, const char *string); 653464ebd5Sriastradh 663464ebd5Sriastradhextern const GLubyte * 673464ebd5Sriastradh_mesa_find_line_column(const GLubyte *string, const GLubyte *pos, 683464ebd5Sriastradh GLint *line, GLint *col); 693464ebd5Sriastradh 703464ebd5Sriastradh 713464ebd5Sriastradhextern struct gl_program * 723464ebd5Sriastradh_mesa_init_vertex_program(struct gl_context *ctx, 733464ebd5Sriastradh struct gl_vertex_program *prog, 743464ebd5Sriastradh GLenum target, GLuint id); 753464ebd5Sriastradh 763464ebd5Sriastradhextern struct gl_program * 773464ebd5Sriastradh_mesa_init_fragment_program(struct gl_context *ctx, 783464ebd5Sriastradh struct gl_fragment_program *prog, 793464ebd5Sriastradh GLenum target, GLuint id); 803464ebd5Sriastradh 813464ebd5Sriastradhextern struct gl_program * 823464ebd5Sriastradh_mesa_init_geometry_program(struct gl_context *ctx, 833464ebd5Sriastradh struct gl_geometry_program *prog, 843464ebd5Sriastradh GLenum target, GLuint id); 853464ebd5Sriastradh 86af69d88dSmrgextern struct gl_program * 87af69d88dSmrg_mesa_init_compute_program(struct gl_context *ctx, 88af69d88dSmrg struct gl_compute_program *prog, 89af69d88dSmrg GLenum target, GLuint id); 90af69d88dSmrg 913464ebd5Sriastradhextern struct gl_program * 923464ebd5Sriastradh_mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id); 933464ebd5Sriastradh 943464ebd5Sriastradhextern void 953464ebd5Sriastradh_mesa_delete_program(struct gl_context *ctx, struct gl_program *prog); 963464ebd5Sriastradh 973464ebd5Sriastradhextern struct gl_program * 983464ebd5Sriastradh_mesa_lookup_program(struct gl_context *ctx, GLuint id); 993464ebd5Sriastradh 1003464ebd5Sriastradhextern void 101af69d88dSmrg_mesa_reference_program_(struct gl_context *ctx, 102af69d88dSmrg struct gl_program **ptr, 103af69d88dSmrg struct gl_program *prog); 104af69d88dSmrg 105af69d88dSmrgstatic inline void 1063464ebd5Sriastradh_mesa_reference_program(struct gl_context *ctx, 1073464ebd5Sriastradh struct gl_program **ptr, 108af69d88dSmrg struct gl_program *prog) 109af69d88dSmrg{ 110af69d88dSmrg if (*ptr != prog) 111af69d88dSmrg _mesa_reference_program_(ctx, ptr, prog); 112af69d88dSmrg} 1133464ebd5Sriastradh 114af69d88dSmrgstatic inline void 1153464ebd5Sriastradh_mesa_reference_vertprog(struct gl_context *ctx, 1163464ebd5Sriastradh struct gl_vertex_program **ptr, 1173464ebd5Sriastradh struct gl_vertex_program *prog) 1183464ebd5Sriastradh{ 1193464ebd5Sriastradh _mesa_reference_program(ctx, (struct gl_program **) ptr, 1203464ebd5Sriastradh (struct gl_program *) prog); 1213464ebd5Sriastradh} 1223464ebd5Sriastradh 123af69d88dSmrgstatic inline void 1243464ebd5Sriastradh_mesa_reference_fragprog(struct gl_context *ctx, 1253464ebd5Sriastradh struct gl_fragment_program **ptr, 1263464ebd5Sriastradh struct gl_fragment_program *prog) 1273464ebd5Sriastradh{ 1283464ebd5Sriastradh _mesa_reference_program(ctx, (struct gl_program **) ptr, 1293464ebd5Sriastradh (struct gl_program *) prog); 1303464ebd5Sriastradh} 1313464ebd5Sriastradh 132af69d88dSmrgstatic inline void 1333464ebd5Sriastradh_mesa_reference_geomprog(struct gl_context *ctx, 1343464ebd5Sriastradh struct gl_geometry_program **ptr, 1353464ebd5Sriastradh struct gl_geometry_program *prog) 1363464ebd5Sriastradh{ 1373464ebd5Sriastradh _mesa_reference_program(ctx, (struct gl_program **) ptr, 1383464ebd5Sriastradh (struct gl_program *) prog); 1393464ebd5Sriastradh} 1403464ebd5Sriastradh 1413464ebd5Sriastradhextern struct gl_program * 1423464ebd5Sriastradh_mesa_clone_program(struct gl_context *ctx, const struct gl_program *prog); 1433464ebd5Sriastradh 144af69d88dSmrgstatic inline struct gl_vertex_program * 1453464ebd5Sriastradh_mesa_clone_vertex_program(struct gl_context *ctx, 1463464ebd5Sriastradh const struct gl_vertex_program *prog) 1473464ebd5Sriastradh{ 1483464ebd5Sriastradh return (struct gl_vertex_program *) _mesa_clone_program(ctx, &prog->Base); 1493464ebd5Sriastradh} 1503464ebd5Sriastradh 151af69d88dSmrgstatic inline struct gl_geometry_program * 1523464ebd5Sriastradh_mesa_clone_geometry_program(struct gl_context *ctx, 1533464ebd5Sriastradh const struct gl_geometry_program *prog) 1543464ebd5Sriastradh{ 1553464ebd5Sriastradh return (struct gl_geometry_program *) _mesa_clone_program(ctx, &prog->Base); 1563464ebd5Sriastradh} 1573464ebd5Sriastradh 158af69d88dSmrgstatic inline struct gl_fragment_program * 1593464ebd5Sriastradh_mesa_clone_fragment_program(struct gl_context *ctx, 1603464ebd5Sriastradh const struct gl_fragment_program *prog) 1613464ebd5Sriastradh{ 1623464ebd5Sriastradh return (struct gl_fragment_program *) _mesa_clone_program(ctx, &prog->Base); 1633464ebd5Sriastradh} 1643464ebd5Sriastradh 1653464ebd5Sriastradh 1663464ebd5Sriastradhextern GLboolean 1673464ebd5Sriastradh_mesa_insert_instructions(struct gl_program *prog, GLuint start, GLuint count); 1683464ebd5Sriastradh 1693464ebd5Sriastradhextern GLboolean 1703464ebd5Sriastradh_mesa_delete_instructions(struct gl_program *prog, GLuint start, GLuint count); 1713464ebd5Sriastradh 1723464ebd5Sriastradhextern struct gl_program * 1733464ebd5Sriastradh_mesa_combine_programs(struct gl_context *ctx, 1743464ebd5Sriastradh const struct gl_program *progA, 1753464ebd5Sriastradh const struct gl_program *progB); 1763464ebd5Sriastradh 1773464ebd5Sriastradhextern void 1783464ebd5Sriastradh_mesa_find_used_registers(const struct gl_program *prog, 1793464ebd5Sriastradh gl_register_file file, 1803464ebd5Sriastradh GLboolean used[], GLuint usedSize); 1813464ebd5Sriastradh 1823464ebd5Sriastradhextern GLint 1833464ebd5Sriastradh_mesa_find_free_register(const GLboolean used[], 1843464ebd5Sriastradh GLuint maxRegs, GLuint firstReg); 1853464ebd5Sriastradh 1863464ebd5Sriastradh 1873464ebd5Sriastradhextern GLboolean 1883464ebd5Sriastradh_mesa_valid_register_index(const struct gl_context *ctx, 189af69d88dSmrg gl_shader_stage shaderType, 1903464ebd5Sriastradh gl_register_file file, GLint index); 1913464ebd5Sriastradh 1923464ebd5Sriastradhextern void 1933464ebd5Sriastradh_mesa_postprocess_program(struct gl_context *ctx, struct gl_program *prog); 1943464ebd5Sriastradh 195af69d88dSmrgextern GLint 196af69d88dSmrg_mesa_get_min_invocations_per_fragment(struct gl_context *ctx, 197af69d88dSmrg const struct gl_fragment_program *prog, 198af69d88dSmrg bool ignore_sample_qualifier); 1993464ebd5Sriastradh 200af69d88dSmrgstatic inline GLuint 201af69d88dSmrg_mesa_program_enum_to_shader_stage(GLenum v) 2023464ebd5Sriastradh{ 203af69d88dSmrg switch (v) { 2043464ebd5Sriastradh case GL_VERTEX_PROGRAM_ARB: 2053464ebd5Sriastradh return MESA_SHADER_VERTEX; 2063464ebd5Sriastradh case GL_FRAGMENT_PROGRAM_ARB: 2073464ebd5Sriastradh return MESA_SHADER_FRAGMENT; 2083464ebd5Sriastradh case GL_GEOMETRY_PROGRAM_NV: 2093464ebd5Sriastradh return MESA_SHADER_GEOMETRY; 210af69d88dSmrg case GL_COMPUTE_PROGRAM_NV: 211af69d88dSmrg return MESA_SHADER_COMPUTE; 2123464ebd5Sriastradh default: 2133464ebd5Sriastradh ASSERT(0); 2143464ebd5Sriastradh return ~0; 2153464ebd5Sriastradh } 2163464ebd5Sriastradh} 2173464ebd5Sriastradh 218af69d88dSmrg 219af69d88dSmrgstatic inline GLenum 220af69d88dSmrg_mesa_shader_stage_to_program(unsigned stage) 221af69d88dSmrg{ 222af69d88dSmrg switch (stage) { 223af69d88dSmrg case MESA_SHADER_VERTEX: 224af69d88dSmrg return GL_VERTEX_PROGRAM_ARB; 225af69d88dSmrg case MESA_SHADER_FRAGMENT: 226af69d88dSmrg return GL_FRAGMENT_PROGRAM_ARB; 227af69d88dSmrg case MESA_SHADER_GEOMETRY: 228af69d88dSmrg return GL_GEOMETRY_PROGRAM_NV; 229af69d88dSmrg case MESA_SHADER_COMPUTE: 230af69d88dSmrg return GL_COMPUTE_PROGRAM_NV; 231af69d88dSmrg } 232af69d88dSmrg 233af69d88dSmrg assert(!"Unexpected shader stage in _mesa_shader_stage_to_program"); 234af69d88dSmrg return GL_VERTEX_PROGRAM_ARB; 235af69d88dSmrg} 236af69d88dSmrg 237af69d88dSmrg 238af69d88dSmrg/* Cast wrappers from gl_program to gl_vertex/geometry/fragment_program */ 239af69d88dSmrg 240af69d88dSmrgstatic inline struct gl_fragment_program * 241af69d88dSmrggl_fragment_program(struct gl_program *prog) 242af69d88dSmrg{ 243af69d88dSmrg return (struct gl_fragment_program *) prog; 244af69d88dSmrg} 245af69d88dSmrg 246af69d88dSmrgstatic inline const struct gl_fragment_program * 247af69d88dSmrggl_fragment_program_const(const struct gl_program *prog) 248af69d88dSmrg{ 249af69d88dSmrg return (const struct gl_fragment_program *) prog; 250af69d88dSmrg} 251af69d88dSmrg 252af69d88dSmrg 253af69d88dSmrgstatic inline struct gl_vertex_program * 254af69d88dSmrggl_vertex_program(struct gl_program *prog) 2553464ebd5Sriastradh{ 256af69d88dSmrg return (struct gl_vertex_program *) prog; 2573464ebd5Sriastradh} 2583464ebd5Sriastradh 259af69d88dSmrgstatic inline const struct gl_vertex_program * 260af69d88dSmrggl_vertex_program_const(const struct gl_program *prog) 261af69d88dSmrg{ 262af69d88dSmrg return (const struct gl_vertex_program *) prog; 263af69d88dSmrg} 264af69d88dSmrg 265af69d88dSmrg 266af69d88dSmrgstatic inline struct gl_geometry_program * 267af69d88dSmrggl_geometry_program(struct gl_program *prog) 268af69d88dSmrg{ 269af69d88dSmrg return (struct gl_geometry_program *) prog; 270af69d88dSmrg} 271af69d88dSmrg 272af69d88dSmrgstatic inline const struct gl_geometry_program * 273af69d88dSmrggl_geometry_program_const(const struct gl_program *prog) 274af69d88dSmrg{ 275af69d88dSmrg return (const struct gl_geometry_program *) prog; 276af69d88dSmrg} 277af69d88dSmrg 278af69d88dSmrg 279af69d88dSmrg#ifdef __cplusplus 280af69d88dSmrg} /* extern "C" */ 281af69d88dSmrg#endif 282af69d88dSmrg 2833464ebd5Sriastradh#endif /* PROGRAM_H */ 284