1874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell/**************************************************************************
2874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell *
3877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * Copyright 2007 VMware, Inc.
4874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * All Rights Reserved.
5874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell *
6874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
7874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * copy of this software and associated documentation files (the
8874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * "Software"), to deal in the Software without restriction, including
9874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
10874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
11874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to
12874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * the following conditions:
13874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell *
14874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * The above copyright notice and this permission notice (including the
15874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * next paragraph) shall be included in all copies or substantial portions
16874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * of the Software.
17874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell *
18874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell *
26874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell **************************************************************************/
27874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell
28874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell /*
29874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell  * Authors:
30877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca  *   Keith Whitwell <keithw@vmware.com>
31874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell  *   Brian Paul
32874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell  */
33874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell
344f25420bdd834e81a3e22733304efc5261c2998aBrian Paul#include "util/u_math.h"
354f25420bdd834e81a3e22733304efc5261c2998aBrian Paul#include "util/u_memory.h"
364f25420bdd834e81a3e22733304efc5261c2998aBrian Paul
37abd5e8e41d54f7f491f91af9354f19c8d24d3572Michal Krol#include "pipe/p_shader_tokens.h"
384f25420bdd834e81a3e22733304efc5261c2998aBrian Paul
39874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell#include "draw_private.h"
40874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell#include "draw_context.h"
41b29d8d27292c2ad956d3f0a307603f00ee01af28Keith Whitwell#include "draw_vs.h"
424f25420bdd834e81a3e22733304efc5261c2998aBrian Paul
437c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell#include "translate/translate.h"
447c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell#include "translate/translate_cache.h"
45874b9265601fcc05b1e32e2be029f3ac6a966c97Keith Whitwell
46b96976cc7c74f601f60d90a23a099bb2605f2edbMichal Krol#include "tgsi/tgsi_dump.h"
47c202fe187cf7a08d60e23ce617a5820a8bc510fdKeith Whitwell#include "tgsi/tgsi_exec.h"
48c202fe187cf7a08d60e23ce617a5820a8bc510fdKeith Whitwell
490e4f0e8725cd93fc1e51e4caa09aadf340add11aBrian PaulDEBUG_GET_ONCE_BOOL_OPTION(gallium_dump_vs, "GALLIUM_DUMP_VS", FALSE)
50a1a989f0be8dc34082b52bb3b3a6eacb36d9e75eZack Rusin
51ba2cc3b8e6ad161181b67fd2575c6bc768584d23Brian Paul
52aa7f2333675f3e005f3eb6a40ac55d2fb55ea36eBrian Paulstruct draw_vertex_shader *
53a1a989f0be8dc34082b52bb3b3a6eacb36d9e75eZack Rusindraw_create_vertex_shader(struct draw_context *draw,
54a1a989f0be8dc34082b52bb3b3a6eacb36d9e75eZack Rusin                          const struct pipe_shader_state *shader)
55a1a989f0be8dc34082b52bb3b3a6eacb36d9e75eZack Rusin{
56d44c8ee568878899e4ce5d8e1d0fcf523aa62199José Fonseca   struct draw_vertex_shader *vs = NULL;
57a1a989f0be8dc34082b52bb3b3a6eacb36d9e75eZack Rusin
58f7748d72b46465d807cf4209892d73af62485738Luca Barbieri   if (draw->dump_vs) {
59f7748d72b46465d807cf4209892d73af62485738Luca Barbieri      tgsi_dump(shader->tokens, 0);
60f7748d72b46465d807cf4209892d73af62485738Luca Barbieri   }
61f7748d72b46465d807cf4209892d73af62485738Luca Barbieri
6234041968f883253de639f137a761340e84f82bb9José Fonseca#if HAVE_LLVM
634eb3225b38ce12cb34ab3d90804c9683bd7b4ed3José Fonseca   if (draw->pt.middle.llvm) {
648ebfcf31eb905b7d47e520c04420620ae21bdf4eZack Rusin      vs = draw_create_vs_llvm(draw, shader);
658ebfcf31eb905b7d47e520c04420620ae21bdf4eZack Rusin   }
668ebfcf31eb905b7d47e520c04420620ae21bdf4eZack Rusin#endif
67d44c8ee568878899e4ce5d8e1d0fcf523aa62199José Fonseca
68d44c8ee568878899e4ce5d8e1d0fcf523aa62199José Fonseca   if (!vs) {
69d44c8ee568878899e4ce5d8e1d0fcf523aa62199José Fonseca      vs = draw_create_vs_exec( draw, shader );
70cddeca51adf0d2b736a223e47b60f6ef3be85bffBrian Paul   }
71a1a989f0be8dc34082b52bb3b3a6eacb36d9e75eZack Rusin
722161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell   if (vs)
732161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell   {
742161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell      uint i;
7540c5987ed84f9f0b8bb1f707bb13c1aafc39330aDave Airlie      bool found_clipvertex = FALSE;
769e41b0badbab97c9db03d5825f91533c69e4f9f9Dave Airlie      vs->position_output = -1;
772161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell      for (i = 0; i < vs->info.num_outputs; i++) {
782161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell         if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_POSITION &&
792161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell             vs->info.output_semantic_index[i] == 0)
802161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell            vs->position_output = i;
81a0127b6ced257919180ba3a1bf534b68d9c750beRoland Scheidegger         else if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_EDGEFLAG &&
82a0127b6ced257919180ba3a1bf534b68d9c750beRoland Scheidegger             vs->info.output_semantic_index[i] == 0)
83a0127b6ced257919180ba3a1bf534b68d9c750beRoland Scheidegger            vs->edgeflag_output = i;
8440c5987ed84f9f0b8bb1f707bb13c1aafc39330aDave Airlie         else if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_CLIPVERTEX &&
8540c5987ed84f9f0b8bb1f707bb13c1aafc39330aDave Airlie                  vs->info.output_semantic_index[i] == 0) {
8640c5987ed84f9f0b8bb1f707bb13c1aafc39330aDave Airlie            found_clipvertex = TRUE;
8740c5987ed84f9f0b8bb1f707bb13c1aafc39330aDave Airlie            vs->clipvertex_output = i;
884b6d6642d2c64ce67d65ead480fb99104a7e2d3aRoland Scheidegger         } else if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_VIEWPORT_INDEX)
894b6d6642d2c64ce67d65ead480fb99104a7e2d3aRoland Scheidegger            vs->viewport_index_output = i;
904b6d6642d2c64ce67d65ead480fb99104a7e2d3aRoland Scheidegger         else if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_CLIPDIST) {
915507c11f85dda4fbcdc9b36494551c933471a070Zack Rusin            debug_assert(vs->info.output_semantic_index[i] <
925507c11f85dda4fbcdc9b36494551c933471a070Zack Rusin                         PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT);
93d17062a40e16454a15aa037a4d1d9e9562cedd46Dave Airlie            vs->ccdistance_output[vs->info.output_semantic_index[i]] = i;
9440c5987ed84f9f0b8bb1f707bb13c1aafc39330aDave Airlie         }
952161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell      }
9640c5987ed84f9f0b8bb1f707bb13c1aafc39330aDave Airlie      if (!found_clipvertex)
9740c5987ed84f9f0b8bb1f707bb13c1aafc39330aDave Airlie         vs->clipvertex_output = vs->position_output;
982161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell   }
992161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell
100280bcff1fa200b790d8712946a4ffbaa47a67433Keith Whitwell   assert(vs);
101a1a989f0be8dc34082b52bb3b3a6eacb36d9e75eZack Rusin   return vs;
102a1a989f0be8dc34082b52bb3b3a6eacb36d9e75eZack Rusin}
103a1a989f0be8dc34082b52bb3b3a6eacb36d9e75eZack Rusin
1044e62fbbfc5bcf368c3f11d4384008e64aad06ec8Brian Paul
1054e62fbbfc5bcf368c3f11d4384008e64aad06ec8Brian Paulvoid
1064e62fbbfc5bcf368c3f11d4384008e64aad06ec8Brian Pauldraw_bind_vertex_shader(struct draw_context *draw,
1074e62fbbfc5bcf368c3f11d4384008e64aad06ec8Brian Paul                        struct draw_vertex_shader *dvs)
108a1a989f0be8dc34082b52bb3b3a6eacb36d9e75eZack Rusin{
1091603a33fb276d7e78a2e872dfa05aa0093d1329aBrian Paul   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
110aff4cf19a753baf0428d2bf53614900e5afea8a3Keith Whitwell
111aff4cf19a753baf0428d2bf53614900e5afea8a3Keith Whitwell   if (dvs)
112aff4cf19a753baf0428d2bf53614900e5afea8a3Keith Whitwell   {
1132f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwell      draw->vs.vertex_shader = dvs;
1142f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwell      draw->vs.num_vs_outputs = dvs->info.num_outputs;
1152161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell      draw->vs.position_output = dvs->position_output;
116a0127b6ced257919180ba3a1bf534b68d9c750beRoland Scheidegger      draw->vs.edgeflag_output = dvs->edgeflag_output;
11740c5987ed84f9f0b8bb1f707bb13c1aafc39330aDave Airlie      draw->vs.clipvertex_output = dvs->clipvertex_output;
118d17062a40e16454a15aa037a4d1d9e9562cedd46Dave Airlie      draw->vs.ccdistance_output[0] = dvs->ccdistance_output[0];
119d17062a40e16454a15aa037a4d1d9e9562cedd46Dave Airlie      draw->vs.ccdistance_output[1] = dvs->ccdistance_output[1];
120aff4cf19a753baf0428d2bf53614900e5afea8a3Keith Whitwell      dvs->prepare( dvs, draw );
12165ef78e8611556780fce0bee1feba805347ec627Marek Olšák      draw_update_clip_flags(draw);
12265ef78e8611556780fce0bee1feba805347ec627Marek Olšák      draw_update_viewport_flags(draw);
123aff4cf19a753baf0428d2bf53614900e5afea8a3Keith Whitwell   }
124aff4cf19a753baf0428d2bf53614900e5afea8a3Keith Whitwell   else {
1252f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwell      draw->vs.vertex_shader = NULL;
1262f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwell      draw->vs.num_vs_outputs = 0;
127aff4cf19a753baf0428d2bf53614900e5afea8a3Keith Whitwell   }
128a1a989f0be8dc34082b52bb3b3a6eacb36d9e75eZack Rusin}
129a1a989f0be8dc34082b52bb3b3a6eacb36d9e75eZack Rusin
1304e62fbbfc5bcf368c3f11d4384008e64aad06ec8Brian Paul
1314e62fbbfc5bcf368c3f11d4384008e64aad06ec8Brian Paulvoid
1324e62fbbfc5bcf368c3f11d4384008e64aad06ec8Brian Pauldraw_delete_vertex_shader(struct draw_context *draw,
1334e62fbbfc5bcf368c3f11d4384008e64aad06ec8Brian Paul                          struct draw_vertex_shader *dvs)
134a1a989f0be8dc34082b52bb3b3a6eacb36d9e75eZack Rusin{
13562628c4d3d497cbca73fde869c9069fa90e6453eKeith Whitwell   unsigned i;
13662628c4d3d497cbca73fde869c9069fa90e6453eKeith Whitwell
137b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul   for (i = 0; i < dvs->nr_variants; i++)
138b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul      dvs->variant[i]->destroy( dvs->variant[i] );
13962628c4d3d497cbca73fde869c9069fa90e6453eKeith Whitwell
140b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul   dvs->nr_variants = 0;
14162628c4d3d497cbca73fde869c9069fa90e6453eKeith Whitwell
142b29d8d27292c2ad956d3f0a307603f00ee01af28Keith Whitwell   dvs->delete( dvs );
143a1a989f0be8dc34082b52bb3b3a6eacb36d9e75eZack Rusin}
1442f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwell
1452f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwell
1462f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwell
1472f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwellboolean
1482f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwelldraw_vs_init( struct draw_context *draw )
1492f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwell{
1501820d240cd0b517ca1d73f1e8e0a528ca8d5b092Jakob Bornecrantz   draw->dump_vs = debug_get_option_gallium_dump_vs();
151f7748d72b46465d807cf4209892d73af62485738Luca Barbieri
1529af68e9b1d116cdc8eb6a22bac091fe4716679e6Roland Scheidegger   if (!draw->llvm) {
153e3e6859381df15fe17a4bd2b93906f69a3657dd4Dave Airlie      draw->vs.tgsi.machine = tgsi_exec_machine_create(PIPE_SHADER_VERTEX);
1541c73e919a4b4dd79166d0633075990056f27fd28Zack Rusin      if (!draw->vs.tgsi.machine)
1551c73e919a4b4dd79166d0633075990056f27fd28Zack Rusin         return FALSE;
1561c73e919a4b4dd79166d0633075990056f27fd28Zack Rusin   }
1577c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
1587c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   draw->vs.emit_cache = translate_cache_create();
1597c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   if (!draw->vs.emit_cache)
1607c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell      return FALSE;
1617c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
1627c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   draw->vs.fetch_cache = translate_cache_create();
1637c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   if (!draw->vs.fetch_cache)
1647c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell      return FALSE;
16562628c4d3d497cbca73fde869c9069fa90e6453eKeith Whitwell
1662f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwell   return TRUE;
1672f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwell}
1682f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwell
1692f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwellvoid
1702f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwelldraw_vs_destroy( struct draw_context *draw )
1712f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwell{
1727c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   if (draw->vs.fetch_cache)
1737c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell      translate_cache_destroy(draw->vs.fetch_cache);
1747c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
1757c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   if (draw->vs.emit_cache)
1767c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell      translate_cache_destroy(draw->vs.emit_cache);
1777c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
1789af68e9b1d116cdc8eb6a22bac091fe4716679e6Roland Scheidegger   if (!draw->llvm)
1791c73e919a4b4dd79166d0633075990056f27fd28Zack Rusin      tgsi_exec_machine_destroy(draw->vs.tgsi.machine);
1802f0d1396e4c1626b3b1ac799bd29e86a9530369eKeith Whitwell}
1817c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
1827c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
183b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paulstruct draw_vs_variant *
184b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Pauldraw_vs_lookup_variant( struct draw_vertex_shader *vs,
185b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul                        const struct draw_vs_variant_key *key )
1867c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell{
187b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul   struct draw_vs_variant *variant;
1887c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   unsigned i;
1897c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
190b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul   /* Lookup existing variant:
1917c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell    */
192b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul   for (i = 0; i < vs->nr_variants; i++)
193b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul      if (draw_vs_variant_key_compare(key, &vs->variant[i]->key) == 0)
194b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul         return vs->variant[i];
1957c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
1967c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   /* Else have to create a new one:
1977c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell    */
198b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul   variant = vs->create_variant( vs, key );
199150c289f6067cb1ba4572f9124948a94ef94c839Edward O'Callaghan   if (!variant)
2007c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell      return NULL;
2017c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
20262628c4d3d497cbca73fde869c9069fa90e6453eKeith Whitwell   /* Add it to our list, could be smarter:
2037c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell    */
204489df4a71aca99b2eebc62c02215a5860def944dBrian Paul   if (vs->nr_variants < ARRAY_SIZE(vs->variant)) {
205b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul      vs->variant[vs->nr_variants++] = variant;
20662628c4d3d497cbca73fde869c9069fa90e6453eKeith Whitwell   }
20762628c4d3d497cbca73fde869c9069fa90e6453eKeith Whitwell   else {
208b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul      vs->last_variant++;
209489df4a71aca99b2eebc62c02215a5860def944dBrian Paul      vs->last_variant %= ARRAY_SIZE(vs->variant);
210b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul      vs->variant[vs->last_variant]->destroy(vs->variant[vs->last_variant]);
211b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul      vs->variant[vs->last_variant] = variant;
21262628c4d3d497cbca73fde869c9069fa90e6453eKeith Whitwell   }
2137c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
2147c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   /* Done
2157c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell    */
216b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul   return variant;
2177c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell}
2187c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
2197c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
2207c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwellstruct translate *
2217c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwelldraw_vs_get_fetch( struct draw_context *draw,
2227c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell                   struct translate_key *key )
2237c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell{
2247c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   if (!draw->vs.fetch ||
2257c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell       translate_key_compare(&draw->vs.fetch->key, key) != 0)
2267c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   {
2277c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell      translate_key_sanitize(key);
2287c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell      draw->vs.fetch = translate_cache_find(draw->vs.fetch_cache, key);
2297c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   }
2307c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
2317c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   return draw->vs.fetch;
2327c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell}
2337c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
2347c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwellstruct translate *
2357c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwelldraw_vs_get_emit( struct draw_context *draw,
2367c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell                  struct translate_key *key )
2377c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell{
2387c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   if (!draw->vs.emit ||
2397c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell       translate_key_compare(&draw->vs.emit->key, key) != 0)
2407c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   {
2417c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell      translate_key_sanitize(key);
2427c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell      draw->vs.emit = translate_cache_find(draw->vs.emit_cache, key);
2437c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   }
2447c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell
2457c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell   return draw->vs.emit;
2467c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell}
247302df7cc85b0e2ce47c40048f30bd116b0d692fcZack Rusin
248302df7cc85b0e2ce47c40048f30bd116b0d692fcZack Rusinvoid
249302df7cc85b0e2ce47c40048f30bd116b0d692fcZack Rusindraw_vs_attach_so(struct draw_vertex_shader *dvs,
250302df7cc85b0e2ce47c40048f30bd116b0d692fcZack Rusin                  const struct pipe_stream_output_info *info)
251302df7cc85b0e2ce47c40048f30bd116b0d692fcZack Rusin{
252302df7cc85b0e2ce47c40048f30bd116b0d692fcZack Rusin   dvs->state.stream_output = *info;
253302df7cc85b0e2ce47c40048f30bd116b0d692fcZack Rusin}
254302df7cc85b0e2ce47c40048f30bd116b0d692fcZack Rusin
255302df7cc85b0e2ce47c40048f30bd116b0d692fcZack Rusinvoid
256302df7cc85b0e2ce47c40048f30bd116b0d692fcZack Rusindraw_vs_reset_so(struct draw_vertex_shader *dvs)
257302df7cc85b0e2ce47c40048f30bd116b0d692fcZack Rusin{
258302df7cc85b0e2ce47c40048f30bd116b0d692fcZack Rusin   memset(&dvs->state.stream_output, 0, sizeof(dvs->state.stream_output));
259302df7cc85b0e2ce47c40048f30bd116b0d692fcZack Rusin}
260