1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 #include "util/u_memory.h"
30 #include "pipe/p_shader_tokens.h"
31 #include "draw/draw_context.h"
32 #include "draw/draw_vertex.h"
33 #include "i915_context.h"
34 #include "i915_state.h"
35 #include "i915_debug.h"
39 static uint
find_mapping(const struct i915_fragment_shader
* fs
, int unit
)
42 for (i
= 0; i
< I915_TEX_UNITS
; i
++)
44 if (fs
->generic_mapping
[i
] == unit
)
47 debug_printf("Mapping not found\n");
53 /***********************************************************************
54 * Determine the hardware vertex layout.
55 * Depends on vertex/fragment shader state.
57 static void calculate_vertex_layout(struct i915_context
*i915
)
59 const struct i915_fragment_shader
*fs
= i915
->fs
;
60 const enum interp_mode colorInterp
= i915
->rasterizer
->color_interp
;
61 struct vertex_info vinfo
;
62 boolean texCoords
[I915_TEX_UNITS
], colors
[2], fog
, needW
, face
;
66 memset(texCoords
, 0, sizeof(texCoords
));
67 colors
[0] = colors
[1] = fog
= needW
= face
= FALSE
;
68 memset(&vinfo
, 0, sizeof(vinfo
));
70 /* Determine which fragment program inputs are needed. Setup HW vertex
71 * layout below, in the HW-specific attribute order.
73 for (i
= 0; i
< fs
->info
.num_inputs
; i
++) {
74 switch (fs
->info
.input_semantic_name
[i
]) {
75 case TGSI_SEMANTIC_POSITION
:
77 uint unit
= I915_SEMANTIC_POS
;
78 texCoords
[find_mapping(fs
, unit
)] = TRUE
;
81 case TGSI_SEMANTIC_COLOR
:
82 assert(fs
->info
.input_semantic_index
[i
] < 2);
83 colors
[fs
->info
.input_semantic_index
[i
]] = TRUE
;
85 case TGSI_SEMANTIC_GENERIC
:
87 /* texcoords/varyings/other generic */
88 uint unit
= fs
->info
.input_semantic_index
[i
];
90 texCoords
[find_mapping(fs
, unit
)] = TRUE
;
94 case TGSI_SEMANTIC_FOG
:
97 case TGSI_SEMANTIC_FACE
:
101 debug_printf("Unknown input type %d\n", fs
->info
.input_semantic_name
[i
]);
108 src
= draw_find_shader_output(i915
->draw
, TGSI_SEMANTIC_POSITION
, 0);
110 draw_emit_vertex_attr(&vinfo
, EMIT_4F
, INTERP_LINEAR
, src
);
111 vinfo
.hwfmt
[0] |= S4_VFMT_XYZW
;
112 vinfo
.attrib
[0].emit
= EMIT_4F
;
115 draw_emit_vertex_attr(&vinfo
, EMIT_3F
, INTERP_LINEAR
, src
);
116 vinfo
.hwfmt
[0] |= S4_VFMT_XYZ
;
117 vinfo
.attrib
[0].emit
= EMIT_3F
;
120 /* hardware point size */
125 src
= draw_find_shader_output(i915
->draw
, TGSI_SEMANTIC_COLOR
, 0);
126 draw_emit_vertex_attr(&vinfo
, EMIT_4UB_BGRA
, colorInterp
, src
);
127 vinfo
.hwfmt
[0] |= S4_VFMT_COLOR
;
130 /* secondary color */
132 src
= draw_find_shader_output(i915
->draw
, TGSI_SEMANTIC_COLOR
, 1);
133 draw_emit_vertex_attr(&vinfo
, EMIT_4UB_BGRA
, colorInterp
, src
);
134 vinfo
.hwfmt
[0] |= S4_VFMT_SPEC_FOG
;
137 /* fog coord, not fog blend factor */
139 src
= draw_find_shader_output(i915
->draw
, TGSI_SEMANTIC_FOG
, 0);
140 draw_emit_vertex_attr(&vinfo
, EMIT_1F
, INTERP_PERSPECTIVE
, src
);
141 vinfo
.hwfmt
[0] |= S4_VFMT_FOG_PARAM
;
144 /* texcoords/varyings */
145 for (i
= 0; i
< I915_TEX_UNITS
; i
++) {
148 hwtc
= TEXCOORDFMT_4D
;
149 src
= draw_find_shader_output(i915
->draw
, TGSI_SEMANTIC_GENERIC
, fs
->generic_mapping
[i
]);
150 draw_emit_vertex_attr(&vinfo
, EMIT_4F
, INTERP_PERSPECTIVE
, src
);
153 hwtc
= TEXCOORDFMT_NOT_PRESENT
;
155 vinfo
.hwfmt
[1] |= hwtc
<< (i
* 4);
158 /* front/back face */
160 uint slot
= find_mapping(fs
, I915_SEMANTIC_FACE
);
161 debug_printf("Front/back face is broken\n");
162 /* XXX Because of limitations in the draw module, currently src will be 0
163 * for SEMANTIC_FACE, so this aliases to POS. We need to fix in the draw
164 * module by adding an extra shader output.
166 src
= draw_find_shader_output(i915
->draw
, TGSI_SEMANTIC_FACE
, 0);
167 draw_emit_vertex_attr(&vinfo
, EMIT_1F
, INTERP_CONSTANT
, src
);
168 vinfo
.hwfmt
[1] &= ~(TEXCOORDFMT_NOT_PRESENT
<< (slot
* 4));
169 vinfo
.hwfmt
[1] |= TEXCOORDFMT_1D
<< (slot
* 4);
172 draw_compute_vertex_size(&vinfo
);
174 if (memcmp(&i915
->current
.vertex_info
, &vinfo
, sizeof(vinfo
))) {
175 /* Need to set this flag so that the LIS2/4 registers get set.
176 * It also means the i915_update_immediate() function must be called
177 * after this one, in i915_update_derived().
179 i915
->dirty
|= I915_NEW_VERTEX_FORMAT
;
181 memcpy(&i915
->current
.vertex_info
, &vinfo
, sizeof(vinfo
));
185 struct i915_tracked_state i915_update_vertex_layout
= {
187 calculate_vertex_layout
,
188 I915_NEW_RASTERIZER
| I915_NEW_FS
| I915_NEW_VS
193 /***********************************************************************
195 static struct i915_tracked_state
*atoms
[] = {
196 &i915_update_vertex_layout
,
198 &i915_hw_sampler_views
,
202 &i915_hw_framebuffer
,
203 &i915_hw_dst_buf_vars
,
208 void i915_update_derived(struct i915_context
*i915
)
212 if (I915_DBG_ON(DBG_ATOMS
))
213 i915_dump_dirty(i915
, __FUNCTION__
);
215 for (i
= 0; atoms
[i
]; i
++)
216 if (atoms
[i
]->dirty
& i915
->dirty
)
217 atoms
[i
]->update(i915
);