Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /**********************************************************
  2.  * Copyright 2008-2009 VMware, Inc.  All rights reserved.
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person
  5.  * obtaining a copy of this software and associated documentation
  6.  * files (the "Software"), to deal in the Software without
  7.  * restriction, including without limitation the rights to use, copy,
  8.  * modify, merge, publish, distribute, sublicense, and/or sell copies
  9.  * of the Software, and to permit persons to whom the Software is
  10.  * furnished to do so, subject to the following conditions:
  11.  *
  12.  * The above copyright notice and this permission notice shall be
  13.  * included in all copies or substantial portions of the Software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16.  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18.  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19.  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20.  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22.  * SOFTWARE.
  23.  *
  24.  **********************************************************/
  25.  
  26. #include "draw/draw_context.h"
  27. #include "util/u_inlines.h"
  28. #include "util/u_math.h"
  29. #include "util/u_memory.h"
  30. #include "util/u_bitmask.h"
  31. #include "tgsi/tgsi_parse.h"
  32. #include "tgsi/tgsi_text.h"
  33.  
  34. #include "svga_context.h"
  35. #include "svga_tgsi.h"
  36. #include "svga_hw_reg.h"
  37. #include "svga_cmd.h"
  38. #include "svga_debug.h"
  39.  
  40.  
  41. /**
  42.  * Substitute a debug shader.
  43.  */
  44. static const struct tgsi_token *
  45. substitute_vs(unsigned shader_id, const struct tgsi_token *old_tokens)
  46. {
  47. #if 0
  48.    if (shader_id == 12) {
  49.    static struct tgsi_token tokens[300];
  50.  
  51.    const char *text =
  52.       "VERT\n"
  53.       "DCL IN[0]\n"
  54.       "DCL IN[1]\n"
  55.       "DCL IN[2]\n"
  56.       "DCL OUT[0], POSITION\n"
  57.       "DCL TEMP[0..4]\n"
  58.       "IMM FLT32 {     1.0000,     1.0000,     1.0000,     1.0000 }\n"
  59.       "IMM FLT32 {     0.45,     1.0000,     1.0000,     1.0000 }\n"
  60.       "IMM FLT32 { 1.297863, 0.039245, 0.035993, 0.035976}\n"
  61.       "IMM FLT32 { -0.019398, 1.696131, -0.202151, -0.202050  }\n"
  62.       "IMM FLT32 { 0.051711, -0.348713, -0.979204, -0.978714  }\n"
  63.       "IMM FLT32 { 0.000000, 0.000003, 139.491577, 141.421356 }\n"
  64.       "DCL CONST[0..7]\n"
  65.       "DCL CONST[9..16]\n"
  66.       "  MOV TEMP[2], IMM[0]\n"
  67.  
  68.       "  MOV TEMP[2].xyz, IN[2]\n"
  69.       "  MOV TEMP[2].xyz, IN[0]\n"
  70.       "  MOV TEMP[2].xyz, IN[1]\n"
  71.  
  72.       "  MUL TEMP[1], IMM[3], TEMP[2].yyyy\n"
  73.       "  MAD TEMP[3], IMM[2],  TEMP[2].xxxx, TEMP[1]\n"
  74.       "  MAD TEMP[1], IMM[4], TEMP[2].zzzz, TEMP[3]\n"
  75.       "  MAD TEMP[4], IMM[5], TEMP[2].wwww, TEMP[1]\n"
  76.  
  77.       "  MOV OUT[0], TEMP[4]\n"
  78.       "  END\n";
  79.  
  80.    if (!tgsi_text_translate(text,
  81.                              tokens,
  82.                              Elements(tokens)))
  83.    {
  84.       assert(0);
  85.       return NULL;
  86.    }
  87.  
  88.    return tokens;
  89.    }
  90. #endif
  91.  
  92.    return old_tokens;
  93. }
  94.  
  95.  
  96. static void *
  97. svga_create_vs_state(struct pipe_context *pipe,
  98.                      const struct pipe_shader_state *templ)
  99. {
  100.    struct svga_context *svga = svga_context(pipe);
  101.    struct svga_vertex_shader *vs = CALLOC_STRUCT(svga_vertex_shader);
  102.    if (!vs)
  103.       return NULL;
  104.  
  105.    /* substitute a debug shader?
  106.     */
  107.    vs->base.tokens = tgsi_dup_tokens(substitute_vs(svga->debug.shader_id,
  108.                                                    templ->tokens));
  109.  
  110.    /* Collect basic info that we'll need later:
  111.     */
  112.    tgsi_scan_shader(vs->base.tokens, &vs->base.info);
  113.  
  114.    {
  115.       /* Need to do construct a new template in case we substitued a
  116.        * debug shader.
  117.        */
  118.       struct pipe_shader_state tmp2 = *templ;
  119.       tmp2.tokens = vs->base.tokens;
  120.       vs->draw_shader = draw_create_vertex_shader(svga->swtnl.draw, &tmp2);
  121.    }
  122.  
  123.    vs->base.id = svga->debug.shader_id++;
  124.  
  125.    if (SVGA_DEBUG & DEBUG_TGSI || 0) {
  126.       debug_printf("%s id: %u, inputs: %u, outputs: %u\n",
  127.                    __FUNCTION__, vs->base.id,
  128.                    vs->base.info.num_inputs, vs->base.info.num_outputs);
  129.    }
  130.  
  131.    return vs;
  132. }
  133.  
  134.  
  135. static void
  136. svga_bind_vs_state(struct pipe_context *pipe, void *shader)
  137. {
  138.    struct svga_vertex_shader *vs = (struct svga_vertex_shader *)shader;
  139.    struct svga_context *svga = svga_context(pipe);
  140.  
  141.    svga->curr.vs = vs;
  142.    svga->dirty |= SVGA_NEW_VS;
  143. }
  144.  
  145.  
  146. static void
  147. svga_delete_vs_state(struct pipe_context *pipe, void *shader)
  148. {
  149.    struct svga_context *svga = svga_context(pipe);
  150.    struct svga_vertex_shader *vs = (struct svga_vertex_shader *)shader;
  151.    struct svga_shader_result *result, *tmp;
  152.    enum pipe_error ret;
  153.  
  154.    svga_hwtnl_flush_retry(svga);
  155.  
  156.    draw_delete_vertex_shader(svga->swtnl.draw, vs->draw_shader);
  157.  
  158.    for (result = vs->base.results; result; result = tmp) {
  159.       tmp = result->next;
  160.  
  161.       ret = SVGA3D_DestroyShader(svga->swc, result->id, SVGA3D_SHADERTYPE_VS);
  162.       if (ret != PIPE_OK) {
  163.          svga_context_flush(svga, NULL);
  164.          ret = SVGA3D_DestroyShader(svga->swc, result->id,
  165.                                     SVGA3D_SHADERTYPE_VS);
  166.          assert(ret == PIPE_OK);
  167.       }
  168.  
  169.       util_bitmask_clear(svga->vs_bm, result->id);
  170.  
  171.       svga_destroy_shader_result(result);
  172.  
  173.       /*
  174.        * Remove stale references to this result to ensure a new result on the
  175.        * same address will be detected as a change.
  176.        */
  177.       if (result == svga->state.hw_draw.vs)
  178.          svga->state.hw_draw.vs = NULL;
  179.    }
  180.  
  181.    FREE((void *)vs->base.tokens);
  182.    FREE(vs);
  183. }
  184.  
  185.  
  186. void
  187. svga_init_vs_functions(struct svga_context *svga)
  188. {
  189.    svga->pipe.create_vs_state = svga_create_vs_state;
  190.    svga->pipe.bind_vs_state = svga_bind_vs_state;
  191.    svga->pipe.delete_vs_state = svga_delete_vs_state;
  192. }
  193.  
  194.