draw: reduce the size of the llvm variant key
[mesa.git] / src / gallium / auxiliary / draw / draw_vs_llvm.c
1 /**************************************************************************
2 *
3 * Copyright 2010 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 #include "util/u_math.h"
29 #include "util/u_memory.h"
30 #include "pipe/p_shader_tokens.h"
31
32 #include "draw_private.h"
33 #include "draw_context.h"
34 #include "draw_vs.h"
35 #include "draw_llvm.h"
36
37 #include "tgsi/tgsi_parse.h"
38 #include "tgsi/tgsi_scan.h"
39
40 static void
41 vs_llvm_prepare(struct draw_vertex_shader *shader,
42 struct draw_context *draw)
43 {
44 /*struct llvm_vertex_shader *evs = llvm_vertex_shader(shader);*/
45 }
46
47 static void
48 vs_llvm_run_linear( struct draw_vertex_shader *shader,
49 const float (*input)[4],
50 float (*output)[4],
51 const void *constants[PIPE_MAX_CONSTANT_BUFFERS],
52 const unsigned constants_size[PIPE_MAX_CONSTANT_BUFFERS],
53 unsigned count,
54 unsigned input_stride,
55 unsigned output_stride )
56 {
57 /* we should never get here since the entire pipeline is
58 * generated in draw_pt_fetch_shade_pipeline_llvm.c */
59 debug_assert(0);
60 }
61
62
63 static void
64 vs_llvm_delete( struct draw_vertex_shader *dvs )
65 {
66 struct llvm_vertex_shader *shader = llvm_vertex_shader(dvs);
67 struct pipe_fence_handle *fence = NULL;
68 struct draw_llvm_variant_list_item *li;
69 struct pipe_context *pipe = dvs->draw->pipe;
70
71 /*
72 * XXX: This might be not neccessary at all.
73 */
74 pipe->flush(pipe, 0, &fence);
75 if (fence) {
76 pipe->screen->fence_finish(pipe->screen, fence, 0);
77 pipe->screen->fence_reference(pipe->screen, &fence, NULL);
78 }
79
80
81 li = first_elem(&shader->variants);
82 while(!at_end(&shader->variants, li)) {
83 struct draw_llvm_variant_list_item *next = next_elem(li);
84 draw_llvm_destroy_variant(li->base);
85 li = next;
86 }
87
88 assert(shader->variants_cached == 0);
89 FREE((void*) dvs->state.tokens);
90 FREE( dvs );
91 }
92
93
94 struct draw_vertex_shader *
95 draw_create_vs_llvm(struct draw_context *draw,
96 const struct pipe_shader_state *state)
97 {
98 struct llvm_vertex_shader *vs = CALLOC_STRUCT( llvm_vertex_shader );
99
100 if (vs == NULL)
101 return NULL;
102
103 /* we make a private copy of the tokens */
104 vs->base.state.tokens = tgsi_dup_tokens(state->tokens);
105 if (!vs->base.state.tokens) {
106 FREE(vs);
107 return NULL;
108 }
109
110 tgsi_scan_shader(state->tokens, &vs->base.info);
111
112 vs->variant_key_size =
113 draw_llvm_variant_key_size(
114 vs->base.info.file_max[TGSI_FILE_INPUT]+1,
115 vs->base.info.file_max[TGSI_FILE_SAMPLER]+1);
116
117 vs->base.draw = draw;
118 vs->base.prepare = vs_llvm_prepare;
119 vs->base.run_linear = vs_llvm_run_linear;
120 vs->base.delete = vs_llvm_delete;
121 vs->base.create_varient = draw_vs_create_varient_generic;
122
123 make_empty_list(&vs->variants);
124
125 return &vs->base;
126 }