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.  * State validation for vertex/fragment shaders.
  30.  * Note that we have to delay most vertex/fragment shader translation
  31.  * until rendering time since the linkage between the vertex outputs and
  32.  * fragment inputs can vary depending on the pairing of shaders.
  33.  *
  34.  * Authors:
  35.  *   Brian Paul
  36.  */
  37.  
  38. #include "main/imports.h"
  39. #include "main/mtypes.h"
  40. #include "program/program.h"
  41.  
  42. #include "pipe/p_context.h"
  43. #include "pipe/p_shader_tokens.h"
  44. #include "util/u_simple_shaders.h"
  45. #include "cso_cache/cso_context.h"
  46.  
  47. #include "st_context.h"
  48. #include "st_atom.h"
  49. #include "st_program.h"
  50.  
  51.  
  52. /**
  53.  * Return pointer to a pass-through fragment shader.
  54.  * This shader is used when a texture is missing/incomplete.
  55.  */
  56. static void *
  57. get_passthrough_fs(struct st_context *st)
  58. {
  59.    if (!st->passthrough_fs) {
  60.       st->passthrough_fs =
  61.          util_make_fragment_passthrough_shader(st->pipe, TGSI_SEMANTIC_COLOR,
  62.                                                TGSI_INTERPOLATE_PERSPECTIVE,
  63.                                                TRUE);
  64.    }
  65.  
  66.    return st->passthrough_fs;
  67. }
  68.  
  69.  
  70. /**
  71.  * Update fragment program state/atom.  This involves translating the
  72.  * Mesa fragment program into a gallium fragment program and binding it.
  73.  */
  74. static void
  75. update_fp( struct st_context *st )
  76. {
  77.    struct st_fragment_program *stfp;
  78.    struct st_fp_variant_key key;
  79.  
  80.    assert(st->ctx->FragmentProgram._Current);
  81.    stfp = st_fragment_program(st->ctx->FragmentProgram._Current);
  82.    assert(stfp->Base.Base.Target == GL_FRAGMENT_PROGRAM_ARB);
  83.  
  84.    memset(&key, 0, sizeof(key));
  85.    key.st = st;
  86.  
  87.    /* _NEW_FRAG_CLAMP */
  88.    key.clamp_color = st->clamp_frag_color_in_shader &&
  89.                      st->ctx->Color._ClampFragmentColor;
  90.  
  91.    /* Ignore sample qualifier while computing this flag. */
  92.    key.persample_shading =
  93.       _mesa_get_min_invocations_per_fragment(st->ctx, &stfp->Base, true) > 1;
  94.  
  95.    st->fp_variant = st_get_fp_variant(st, stfp, &key);
  96.  
  97.    st_reference_fragprog(st, &st->fp, stfp);
  98.  
  99.    if (st->missing_textures) {
  100.       /* use a pass-through frag shader that uses no textures */
  101.       void *fs = get_passthrough_fs(st);
  102.       cso_set_fragment_shader_handle(st->cso_context, fs);
  103.    }
  104.    else {
  105.       cso_set_fragment_shader_handle(st->cso_context,
  106.                                      st->fp_variant->driver_shader);
  107.    }
  108. }
  109.  
  110.  
  111. const struct st_tracked_state st_update_fp = {
  112.    "st_update_fp",                                      /* name */
  113.    {                                                    /* dirty */
  114.       _NEW_BUFFERS | _NEW_MULTISAMPLE,                  /* mesa */
  115.       ST_NEW_FRAGMENT_PROGRAM                           /* st */
  116.    },
  117.    update_fp                                    /* update */
  118. };
  119.  
  120.  
  121.  
  122. /**
  123.  * Update vertex program state/atom.  This involves translating the
  124.  * Mesa vertex program into a gallium fragment program and binding it.
  125.  */
  126. static void
  127. update_vp( struct st_context *st )
  128. {
  129.    struct st_vertex_program *stvp;
  130.    struct st_vp_variant_key key;
  131.  
  132.    /* find active shader and params -- Should be covered by
  133.     * ST_NEW_VERTEX_PROGRAM
  134.     */
  135.    assert(st->ctx->VertexProgram._Current);
  136.    stvp = st_vertex_program(st->ctx->VertexProgram._Current);
  137.    assert(stvp->Base.Base.Target == GL_VERTEX_PROGRAM_ARB);
  138.  
  139.    memset(&key, 0, sizeof key);
  140.    key.st = st;  /* variants are per-context */
  141.  
  142.    /* When this is true, we will add an extra input to the vertex
  143.     * shader translation (for edgeflags), an extra output with
  144.     * edgeflag semantics, and extend the vertex shader to pass through
  145.     * the input to the output.  We'll need to use similar logic to set
  146.     * up the extra vertex_element input for edgeflags.
  147.     */
  148.    key.passthrough_edgeflags = st->vertdata_edgeflags;
  149.  
  150.    key.clamp_color = st->clamp_vert_color_in_shader &&
  151.                      st->ctx->Light._ClampVertexColor &&
  152.                      (stvp->Base.Base.OutputsWritten &
  153.                       (VARYING_SLOT_COL0 |
  154.                        VARYING_SLOT_COL1 |
  155.                        VARYING_SLOT_BFC0 |
  156.                        VARYING_SLOT_BFC1));
  157.  
  158.    st->vp_variant = st_get_vp_variant(st, stvp, &key);
  159.  
  160.    st_reference_vertprog(st, &st->vp, stvp);
  161.  
  162.    cso_set_vertex_shader_handle(st->cso_context,
  163.                                 st->vp_variant->driver_shader);
  164.  
  165.    st->vertex_result_to_slot = stvp->result_to_output;
  166. }
  167.  
  168.  
  169. const struct st_tracked_state st_update_vp = {
  170.    "st_update_vp",                                      /* name */
  171.    {                                                    /* dirty */
  172.       0,                                                /* mesa */
  173.       ST_NEW_VERTEX_PROGRAM                             /* st */
  174.    },
  175.    update_vp                                            /* update */
  176. };
  177.  
  178.  
  179.  
  180. static void
  181. update_gp( struct st_context *st )
  182. {
  183.    struct st_geometry_program *stgp;
  184.    struct st_gp_variant_key key;
  185.  
  186.    if (!st->ctx->GeometryProgram._Current) {
  187.       cso_set_geometry_shader_handle(st->cso_context, NULL);
  188.       return;
  189.    }
  190.  
  191.    stgp = st_geometry_program(st->ctx->GeometryProgram._Current);
  192.    assert(stgp->Base.Base.Target == MESA_GEOMETRY_PROGRAM);
  193.  
  194.    memset(&key, 0, sizeof(key));
  195.    key.st = st;
  196.  
  197.    st->gp_variant = st_get_gp_variant(st, stgp, &key);
  198.  
  199.    st_reference_geomprog(st, &st->gp, stgp);
  200.  
  201.    cso_set_geometry_shader_handle(st->cso_context,
  202.                                   st->gp_variant->driver_shader);
  203. }
  204.  
  205. const struct st_tracked_state st_update_gp = {
  206.    "st_update_gp",                      /* name */
  207.    {                                    /* dirty */
  208.       0,                                /* mesa */
  209.       ST_NEW_GEOMETRY_PROGRAM           /* st */
  210.    },
  211.    update_gp                            /* update */
  212. };
  213.