1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/*
Copyright (C) Intel Corp. 2006. All Rights Reserved.
Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
develop this 3D driver.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**********************************************************************/
/*
* Authors:
* Keith Whitwell <keith@tungstengraphics.com>
*/
#include "util/u_memory.h"
#include "tgsi/tgsi_parse.h"
#include "tgsi/tgsi_scan.h"
#include "brw_context.h"
#include "brw_util.h"
#include "brw_wm.h"
/**
* Determine if the given shader uses complex features such as flow
* conditionals, loops, subroutines.
*/
static GLboolean has_flow_control(const struct tgsi_shader_info *info)
{
return (info->opcode_count[TGSI_OPCODE_ARL] > 0 ||
info->opcode_count[TGSI_OPCODE_IF] > 0 ||
info->opcode_count[TGSI_OPCODE_ENDIF] > 0 || /* redundant - IF */
info->opcode_count[TGSI_OPCODE_CAL] > 0 ||
info->opcode_count[TGSI_OPCODE_BRK] > 0 || /* redundant - BGNLOOP */
info->opcode_count[TGSI_OPCODE_RET] > 0 || /* redundant - CAL */
info->opcode_count[TGSI_OPCODE_BGNLOOP] > 0);
}
static void brw_bind_fs_state( struct pipe_context *pipe, void *prog )
{
struct brw_context *brw = brw_context(pipe);
brw->curr.fragment_shader = (struct brw_fragment_shader *)prog;
brw->state.dirty.mesa |= PIPE_NEW_FRAGMENT_SHADER;
}
static void brw_bind_vs_state( struct pipe_context *pipe, void *prog )
{
struct brw_context *brw = brw_context(pipe);
brw->curr.vertex_shader = (struct brw_vertex_shader *)prog;
brw->state.dirty.mesa |= PIPE_NEW_VERTEX_SHADER;
}
static void *brw_create_fs_state( struct pipe_context *pipe,
const struct pipe_shader_state *shader )
{
struct brw_context *brw = brw_context(pipe);
struct brw_fragment_shader *fs;
int i;
fs = CALLOC_STRUCT(brw_fragment_shader);
if (fs == NULL)
return NULL;
/* Duplicate tokens, scan shader
*/
fs->id = brw->program_id++;
fs->has_flow_control = has_flow_control(&fs->info);
fs->tokens = tgsi_dup_tokens(shader->tokens);
if (fs->tokens == NULL)
goto fail;
tgsi_scan_shader(fs->tokens, &fs->info);
fs->signature.nr_inputs = fs->info.num_inputs;
for (i = 0; i < fs->info.num_inputs; i++) {
fs->signature.input[i].semantic = fs->info.input_semantic_name[i];
fs->signature.input[i].semantic_index = fs->info.input_semantic_index[i];
}
for (i = 0; i < fs->info.num_inputs; i++)
if (fs->info.input_semantic_name[i] == TGSI_SEMANTIC_POSITION)
fs->uses_depth = 1;
if (fs->info.uses_kill)
fs->iz_lookup |= IZ_PS_KILL_ALPHATEST_BIT;
if (fs->info.writes_z)
fs->iz_lookup |= IZ_PS_COMPUTES_DEPTH_BIT;
return (void *)fs;
fail:
FREE(fs);
return NULL;
}
static void *brw_create_vs_state( struct pipe_context *pipe,
const struct pipe_shader_state *shader )
{
struct brw_context *brw = brw_context(pipe);
struct brw_vertex_shader *vs = CALLOC_STRUCT(brw_vertex_shader);
if (vs == NULL)
return NULL;
/* Duplicate tokens, scan shader
*/
vs->id = brw->program_id++;
vs->has_flow_control = has_flow_control(&vs->info);
vs->tokens = tgsi_dup_tokens(shader->tokens);
if (vs->tokens == NULL)
goto fail;
tgsi_scan_shader(vs->tokens, &vs->info);
/* Done:
*/
return (void *)vs;
fail:
FREE(vs);
return NULL;
}
static void brw_delete_fs_state( struct pipe_context *pipe, void *prog )
{
struct brw_fragment_shader *fs = (struct brw_fragment_shader *)prog;
bo_reference(&fs->const_buffer, NULL);
FREE( (void *)fs->tokens );
FREE( fs );
}
static void brw_delete_vs_state( struct pipe_context *pipe, void *prog )
{
struct brw_fragment_shader *vs = (struct brw_fragment_shader *)prog;
/* Delete draw shader
*/
FREE( (void *)vs->tokens );
FREE( vs );
}
static void brw_set_constant_buffer(struct pipe_context *pipe,
uint shader, uint index,
const struct pipe_constant_buffer *buf)
{
struct brw_context *brw = brw_context(pipe);
assert(index == 0);
if (shader == PIPE_SHADER_FRAGMENT) {
pipe_buffer_reference( &brw->curr.fragment_constants,
buf->buffer );
brw->state.dirty.mesa |= PIPE_NEW_FRAGMENT_CONSTANTS;
}
else {
pipe_buffer_reference( &brw->curr.vertex_constants,
buf->buffer );
brw->state.dirty.mesa |= PIPE_NEW_VERTEX_CONSTANTS;
}
}
void brw_pipe_shader_init( struct brw_context *brw )
{
brw->base.set_constant_buffer = brw_set_constant_buffer;
brw->base.create_vs_state = brw_create_vs_state;
brw->base.bind_vs_state = brw_bind_vs_state;
brw->base.delete_vs_state = brw_delete_vs_state;
brw->base.create_fs_state = brw_create_fs_state;
brw->base.bind_fs_state = brw_bind_fs_state;
brw->base.delete_fs_state = brw_delete_fs_state;
}
void brw_pipe_shader_cleanup( struct brw_context *brw )
{
pipe_buffer_reference( &brw->curr.fragment_constants, NULL );
pipe_buffer_reference( &brw->curr.vertex_constants, NULL );
}
|