1a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell/**************************************************************************
2a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell *
3a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * All Rights Reserved.
5a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell *
6a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
7a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * copy of this software and associated documentation files (the
8a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * "Software"), to deal in the Software without restriction, including
9a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
10a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
11a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * permit persons to whom the Software is furnished to do so, subject to
12a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * the following conditions:
13a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell *
14a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * The above copyright notice and this permission notice (including the
15a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * next paragraph) shall be included in all copies or substantial portions
16a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * of the Software.
17a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell *
18a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell *
26a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell **************************************************************************/
27a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
28a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell#include "lp_context.h"
29a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell#include "lp_state.h"
30a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell#include "lp_texture.h"
31a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
32a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell#include "pipe/p_defines.h"
33a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell#include "util/u_memory.h"
34a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell#include "util/u_inlines.h"
35a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell#include "draw/draw_context.h"
36a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell#include "tgsi/tgsi_dump.h"
37a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell#include "tgsi/tgsi_scan.h"
38a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell#include "tgsi/tgsi_parse.h"
39a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
40a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
41a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwellstatic void *
42a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwellllvmpipe_create_gs_state(struct pipe_context *pipe,
43a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell                         const struct pipe_shader_state *templ)
44a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell{
45a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
46a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   struct lp_geometry_shader *state;
47a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
48a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   state = CALLOC_STRUCT(lp_geometry_shader);
49a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   if (state == NULL )
50a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell      goto fail;
51a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
52a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   /* debug */
53a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   if (0)
54a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell      tgsi_dump(templ->tokens, 0);
55a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
56a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   /* copy shader tokens, the ones passed in will go away.
57a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell    */
58a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   state->shader.tokens = tgsi_dup_tokens(templ->tokens);
59a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   if (state->shader.tokens == NULL)
60a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell      goto fail;
61a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
62a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   state->draw_data = draw_create_geometry_shader(llvmpipe->draw, templ);
63a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   if (state->draw_data == NULL)
64a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell      goto fail;
65a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
66a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   return state;
67a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
68a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwellfail:
69a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   if (state) {
70a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell      FREE( (void *)state->shader.tokens );
71a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell      FREE( state->draw_data );
72a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell      FREE( state );
73a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   }
74a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   return NULL;
75a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell}
76a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
77a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
78a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwellstatic void
79a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwellllvmpipe_bind_gs_state(struct pipe_context *pipe, void *gs)
80a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell{
81a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
82a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
83a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   llvmpipe->gs = (struct lp_geometry_shader *)gs;
84a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
85a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   draw_bind_geometry_shader(llvmpipe->draw,
86a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell                             (llvmpipe->gs ? llvmpipe->gs->draw_data : NULL));
87a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
88a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   llvmpipe->dirty |= LP_NEW_GS;
89a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell}
90a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
91a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
92a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwellstatic void
93a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwellllvmpipe_delete_gs_state(struct pipe_context *pipe, void *gs)
94a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell{
95a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
96a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
97a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   struct lp_geometry_shader *state =
98a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell      (struct lp_geometry_shader *)gs;
99a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
100a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   draw_delete_geometry_shader(llvmpipe->draw,
101a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell                               (state) ? state->draw_data : 0);
102a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   FREE(state);
103a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell}
104a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
105a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell
106a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwellvoid
107a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwellllvmpipe_init_gs_funcs(struct llvmpipe_context *llvmpipe)
108a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell{
109a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   llvmpipe->pipe.create_gs_state = llvmpipe_create_gs_state;
110a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   llvmpipe->pipe.bind_gs_state   = llvmpipe_bind_gs_state;
111a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell   llvmpipe->pipe.delete_gs_state = llvmpipe_delete_gs_state;
112a6d9d18faecef9963be3e4b64a21b89889b4670dKeith Whitwell}
113