Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2003 VMware, Inc.
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice (including the
  15.  * next paragraph) shall be included in all copies or substantial portions
  16.  * of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21.  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  22.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  **************************************************************************/
  27.  
  28.  /*
  29.   * Authors:
  30.   *   Keith Whitwell <keithw@vmware.com>
  31.   */
  32.    
  33.  
  34. #ifndef ST_PROGRAM_H
  35. #define ST_PROGRAM_H
  36.  
  37. #include "main/mtypes.h"
  38. #include "program/program.h"
  39. #include "pipe/p_state.h"
  40. #include "st_context.h"
  41. #include "st_glsl_to_tgsi.h"
  42.  
  43.  
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47.  
  48. #define ST_DOUBLE_ATTRIB_PLACEHOLDER 0xffffffff
  49.  
  50. /** Fragment program variant key */
  51. struct st_fp_variant_key
  52. {
  53.    struct st_context *st;         /**< variants are per-context */
  54.  
  55.    /** for glBitmap */
  56.    GLuint bitmap:1;               /**< glBitmap variant? */
  57.  
  58.    /** for glDrawPixels */
  59.    GLuint drawpixels:1;           /**< glDrawPixels variant */
  60.    GLuint scaleAndBias:1;         /**< glDrawPixels w/ scale and/or bias? */
  61.    GLuint pixelMaps:1;            /**< glDrawPixels w/ pixel lookup map? */
  62.    GLuint drawpixels_z:1;         /**< glDrawPixels(GL_DEPTH) */
  63.    GLuint drawpixels_stencil:1;   /**< glDrawPixels(GL_STENCIL) */
  64.  
  65.    /** for ARB_color_buffer_float */
  66.    GLuint clamp_color:1;
  67.  
  68.    /** for ARB_sample_shading */
  69.    GLuint persample_shading:1;
  70. };
  71.  
  72.  
  73. /**
  74.  * Variant of a fragment program.
  75.  */
  76. struct st_fp_variant
  77. {
  78.    /** Parameters which generated this version of fragment program */
  79.    struct st_fp_variant_key key;
  80.  
  81.    struct pipe_shader_state tgsi;
  82.  
  83.    /** Driver's compiled shader */
  84.    void *driver_shader;
  85.  
  86.    /** For glBitmap variants */
  87.    struct gl_program_parameter_list *parameters;
  88.    uint bitmap_sampler;
  89.  
  90.    /** next in linked list */
  91.    struct st_fp_variant *next;
  92. };
  93.  
  94.  
  95. /**
  96.  * Derived from Mesa gl_fragment_program:
  97.  */
  98. struct st_fragment_program
  99. {
  100.    struct gl_fragment_program Base;
  101.    struct glsl_to_tgsi_visitor* glsl_to_tgsi;
  102.  
  103.    struct st_fp_variant *variants;
  104. };
  105.  
  106.  
  107.  
  108. /** Vertex program variant key */
  109. struct st_vp_variant_key
  110. {
  111.    struct st_context *st;          /**< variants are per-context */
  112.    boolean passthrough_edgeflags;
  113.  
  114.    /** for ARB_color_buffer_float */
  115.    boolean clamp_color;
  116. };
  117.  
  118.  
  119. /**
  120.  * This represents a vertex program, especially translated to match
  121.  * the inputs of a particular fragment shader.
  122.  */
  123. struct st_vp_variant
  124. {
  125.    /* Parameters which generated this translated version of a vertex
  126.     * shader:
  127.     */
  128.    struct st_vp_variant_key key;
  129.  
  130.    /**
  131.     * TGSI tokens (to later generate a 'draw' module shader for
  132.     * selection/feedback/rasterpos)
  133.     */
  134.    struct pipe_shader_state tgsi;
  135.  
  136.    /** Driver's compiled shader */
  137.    void *driver_shader;
  138.  
  139.    /** For using our private draw module (glRasterPos) */
  140.    struct draw_vertex_shader *draw_shader;
  141.  
  142.    /** Next in linked list */
  143.    struct st_vp_variant *next;  
  144.  
  145.    /** similar to that in st_vertex_program, but with edgeflags info too */
  146.    GLuint num_inputs;
  147. };
  148.  
  149.  
  150. /**
  151.  * Derived from Mesa gl_fragment_program:
  152.  */
  153. struct st_vertex_program
  154. {
  155.    struct gl_vertex_program Base;  /**< The Mesa vertex program */
  156.    struct glsl_to_tgsi_visitor* glsl_to_tgsi;
  157.  
  158.    /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
  159.    GLuint input_to_index[VERT_ATTRIB_MAX];
  160.    /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
  161.    GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
  162.    GLuint num_inputs;
  163.  
  164.    /** Maps VARYING_SLOT_x to slot */
  165.    GLuint result_to_output[VARYING_SLOT_MAX];
  166.    ubyte output_semantic_name[VARYING_SLOT_MAX];
  167.    ubyte output_semantic_index[VARYING_SLOT_MAX];
  168.    GLuint num_outputs;
  169.  
  170.    /** List of translated variants of this vertex program.
  171.     */
  172.    struct st_vp_variant *variants;
  173. };
  174.  
  175.  
  176.  
  177. /** Geometry program variant key */
  178. struct st_gp_variant_key
  179. {
  180.    struct st_context *st;          /**< variants are per-context */
  181.    /* no other fields yet */
  182. };
  183.  
  184.  
  185. /**
  186.  * Geometry program variant.
  187.  */
  188. struct st_gp_variant
  189. {
  190.    /* Parameters which generated this translated version of a vertex */
  191.    struct st_gp_variant_key key;
  192.  
  193.    void *driver_shader;
  194.  
  195.    struct st_gp_variant *next;
  196. };
  197.  
  198.  
  199. /**
  200.  * Derived from Mesa gl_geometry_program:
  201.  */
  202. struct st_geometry_program
  203. {
  204.    struct gl_geometry_program Base;  /**< The Mesa geometry program */
  205.    struct glsl_to_tgsi_visitor* glsl_to_tgsi;
  206.  
  207.    struct st_gp_variant *variants;
  208. };
  209.  
  210.  
  211.  
  212. static inline struct st_fragment_program *
  213. st_fragment_program( struct gl_fragment_program *fp )
  214. {
  215.    return (struct st_fragment_program *)fp;
  216. }
  217.  
  218.  
  219. static inline struct st_vertex_program *
  220. st_vertex_program( struct gl_vertex_program *vp )
  221. {
  222.    return (struct st_vertex_program *)vp;
  223. }
  224.  
  225. static inline struct st_geometry_program *
  226. st_geometry_program( struct gl_geometry_program *gp )
  227. {
  228.    return (struct st_geometry_program *)gp;
  229. }
  230.  
  231. static inline void
  232. st_reference_vertprog(struct st_context *st,
  233.                       struct st_vertex_program **ptr,
  234.                       struct st_vertex_program *prog)
  235. {
  236.    _mesa_reference_program(st->ctx,
  237.                            (struct gl_program **) ptr,
  238.                            (struct gl_program *) prog);
  239. }
  240.  
  241. static inline void
  242. st_reference_geomprog(struct st_context *st,
  243.                       struct st_geometry_program **ptr,
  244.                       struct st_geometry_program *prog)
  245. {
  246.    _mesa_reference_program(st->ctx,
  247.                            (struct gl_program **) ptr,
  248.                            (struct gl_program *) prog);
  249. }
  250.  
  251. static inline void
  252. st_reference_fragprog(struct st_context *st,
  253.                       struct st_fragment_program **ptr,
  254.                       struct st_fragment_program *prog)
  255. {
  256.    _mesa_reference_program(st->ctx,
  257.                            (struct gl_program **) ptr,
  258.                            (struct gl_program *) prog);
  259. }
  260.  
  261. /**
  262.  * This defines mapping from Mesa VARYING_SLOTs to TGSI GENERIC slots.
  263.  */
  264. static inline unsigned
  265. st_get_generic_varying_index(struct st_context *st, GLuint attr)
  266. {
  267.    if (attr >= VARYING_SLOT_VAR0) {
  268.       if (st->needs_texcoord_semantic)
  269.          return attr - VARYING_SLOT_VAR0;
  270.       else
  271.          return 9 + (attr - VARYING_SLOT_VAR0);
  272.    }
  273.    if (attr == VARYING_SLOT_PNTC) {
  274.       assert(!st->needs_texcoord_semantic);
  275.       return 8;
  276.    }
  277.    if (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7) {
  278.       assert(!st->needs_texcoord_semantic);
  279.       return attr - VARYING_SLOT_TEX0;
  280.    }
  281.  
  282.    assert(0);
  283.    return 0;
  284. }
  285.  
  286.  
  287. extern struct st_vp_variant *
  288. st_get_vp_variant(struct st_context *st,
  289.                   struct st_vertex_program *stvp,
  290.                   const struct st_vp_variant_key *key);
  291.  
  292.  
  293. extern struct st_fp_variant *
  294. st_get_fp_variant(struct st_context *st,
  295.                   struct st_fragment_program *stfp,
  296.                   const struct st_fp_variant_key *key);
  297.  
  298.  
  299. extern struct st_gp_variant *
  300. st_get_gp_variant(struct st_context *st,
  301.                   struct st_geometry_program *stgp,
  302.                   const struct st_gp_variant_key *key);
  303.  
  304.  
  305. extern void
  306. st_prepare_vertex_program(struct gl_context *ctx,
  307.                           struct st_vertex_program *stvp);
  308.  
  309. extern GLboolean
  310. st_prepare_fragment_program(struct gl_context *ctx,
  311.                             struct st_fragment_program *stfp);
  312.  
  313.  
  314. extern void
  315. st_release_vp_variants( struct st_context *st,
  316.                         struct st_vertex_program *stvp );
  317.  
  318. extern void
  319. st_release_fp_variants( struct st_context *st,
  320.                         struct st_fragment_program *stfp );
  321.  
  322. extern void
  323. st_release_gp_variants(struct st_context *st,
  324.                        struct st_geometry_program *stgp);
  325.  
  326. extern void
  327. st_destroy_program_variants(struct st_context *st);
  328.  
  329.  
  330. extern void
  331. st_print_current_vertex_program(void);
  332.  
  333. extern void
  334. st_precompile_shader_variant(struct st_context *st,
  335.                              struct gl_program *prog);
  336.  
  337. #ifdef __cplusplus
  338. }
  339. #endif
  340.  
  341. #endif
  342.