1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 "pipe/p_util.h"
30 #include "draw/draw_context.h"
31 #include "draw/draw_vertex.h"
32 #include "i915_context.h"
33 #include "i915_state.h"
36 #include "pipe/p_shader_tokens.h"
40 * Determine which post-transform / pre-rasterization vertex attributes
42 * Derived from: fs, setup states.
44 static void calculate_vertex_layout( struct i915_context
*i915
)
46 const struct pipe_shader_state
*fs
= i915
->fs
;
47 const enum interp_mode colorInterp
= i915
->rasterizer
->color_interp
;
48 struct vertex_info vinfo
;
49 uint front0
= 0, back0
= 0, front1
= 0, back1
= 0;
55 memset(texCoords
, 0, sizeof(texCoords
));
56 memset(&vinfo
, 0, sizeof(vinfo
));
59 draw_emit_vertex_attr(&vinfo
, EMIT_3F
, INTERP_LINEAR
, src
++);
60 /* Note: we'll set the S4_VFMT_XYZ[W] bits below */
62 for (i
= 0; i
< fs
->num_inputs
; i
++) {
63 switch (fs
->input_semantic_name
[i
]) {
64 case TGSI_SEMANTIC_POSITION
:
66 case TGSI_SEMANTIC_COLOR
:
67 if (fs
->input_semantic_index
[i
] == 0) {
68 front0
= draw_emit_vertex_attr(&vinfo
, EMIT_4UB
, colorInterp
, src
++);
69 vinfo
.hwfmt
[0] |= S4_VFMT_COLOR
;
72 assert(fs
->input_semantic_index
[i
] == 1);
73 front1
= draw_emit_vertex_attr(&vinfo
, EMIT_4UB
, colorInterp
, src
++);
74 vinfo
.hwfmt
[0] |= S4_VFMT_SPEC_FOG
;
77 case TGSI_SEMANTIC_GENERIC
:
78 /* usually a texcoord */
80 const uint unit
= fs
->input_semantic_index
[i
];
82 texCoords
[unit
] = TRUE
;
83 draw_emit_vertex_attr(&vinfo
, EMIT_4F
, INTERP_PERSPECTIVE
, src
++);
84 hwtc
= TEXCOORDFMT_4D
;
86 vinfo
.hwfmt
[1] |= hwtc
<< (unit
* 4);
89 case TGSI_SEMANTIC_FOG
:
90 debug_printf("i915 fogcoord not implemented yet\n");
91 draw_emit_vertex_attr(&vinfo
, EMIT_1F
, INTERP_PERSPECTIVE
, src
++);
99 /* finish up texcoord fields */
100 for (i
= 0; i
< 8; i
++) {
102 const uint hwtc
= TEXCOORDFMT_NOT_PRESENT
;
103 vinfo
.hwfmt
[1] |= hwtc
<< (i
* 4);
107 /* go back and fill in the vertex position info now that we have needW */
109 vinfo
.hwfmt
[0] |= S4_VFMT_XYZW
;
110 vinfo
.emit
[0] = EMIT_4F
;
113 vinfo
.hwfmt
[0] |= S4_VFMT_XYZ
;
114 vinfo
.emit
[0] = EMIT_3F
;
117 /* Additional attributes required for setup: Just twosided
118 * lighting. Edgeflag is dealt with specially by setting bits in
121 if (i915
->rasterizer
->light_twoside
) {
123 back0
= draw_emit_vertex_attr(&vinfo
, EMIT_OMIT
, colorInterp
, src
++);
126 back1
= draw_emit_vertex_attr(&vinfo
, EMIT_OMIT
, colorInterp
, src
++);
130 draw_compute_vertex_size(&vinfo
);
132 if (memcmp(&i915
->current
.vertex_info
, &vinfo
, sizeof(vinfo
))) {
133 /* Need to set this flag so that the LIS2/4 registers get set.
134 * It also means the i915_update_immediate() function must be called
135 * after this one, in i915_update_derived().
137 i915
->dirty
|= I915_NEW_VERTEX_FORMAT
;
139 memcpy(&i915
->current
.vertex_info
, &vinfo
, sizeof(vinfo
));
146 /* Hopefully this will remain quite simple, otherwise need to pull in
147 * something like the state tracker mechanism.
149 void i915_update_derived( struct i915_context
*i915
)
151 if (i915
->dirty
& (I915_NEW_RASTERIZER
| I915_NEW_FS
))
152 calculate_vertex_layout( i915
);
154 if (i915
->dirty
& (I915_NEW_SAMPLER
| I915_NEW_TEXTURE
))
155 i915_update_samplers(i915
);
157 if (i915
->dirty
& I915_NEW_TEXTURE
)
158 i915_update_textures(i915
);
161 i915_update_immediate( i915
);
164 i915_update_dynamic( i915
);
166 if (i915
->dirty
& I915_NEW_FS
) {
167 i915_translate_fragment_program(i915
);
168 i915
->hardware_dirty
|= I915_HW_PROGRAM
; /* XXX right? */
171 /* HW emit currently references framebuffer state directly:
173 if (i915
->dirty
& I915_NEW_FRAMEBUFFER
)
174 i915
->hardware_dirty
|= I915_HW_STATIC
;