2 /* FF is big and ugly so feel free to write lines as long as you like.
5 * Let me make that clearer:
6 * Aieeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee ! !! !!!
10 #include "basetexture9.h"
11 #include "vertexdeclaration9.h"
12 #include "vertexshader9.h"
13 #include "pixelshader9.h"
15 #include "nine_defines.h"
16 #include "nine_helpers.h"
17 #include "nine_pipe.h"
18 #include "nine_dump.h"
20 #include "pipe/p_context.h"
21 #include "tgsi/tgsi_ureg.h"
22 #include "tgsi/tgsi_dump.h"
23 #include "util/u_box.h"
24 #include "util/u_hash_table.h"
25 #include "util/u_upload_mgr.h"
27 #define NINE_TGSI_LAZY_DEVS 1
29 #define DBG_CHANNEL DBG_FF
31 #define NINE_FF_NUM_VS_CONST 256
32 #define NINE_FF_NUM_PS_CONST 24
43 uint32_t position_t
: 1;
44 uint32_t lighting
: 1;
45 uint32_t darkness
: 1; /* lighting enabled but no active lights */
46 uint32_t localviewer
: 1;
47 uint32_t vertexpointsize
: 1;
48 uint32_t pointscale
: 1;
49 uint32_t vertexblend
: 3;
50 uint32_t vertexblend_indexed
: 1;
51 uint32_t vertextween
: 1;
52 uint32_t mtl_diffuse
: 2; /* 0 = material, 1 = color1, 2 = color2 */
53 uint32_t mtl_ambient
: 2;
54 uint32_t mtl_specular
: 2;
55 uint32_t mtl_emissive
: 2;
56 uint32_t fog_mode
: 2;
57 uint32_t fog_range
: 1;
58 uint32_t color0in_one
: 1;
59 uint32_t color1in_one
: 1;
61 uint32_t specular_enable
: 1;
63 uint32_t tc_dim_input
: 16; /* 8 * 2 bits */
65 uint32_t tc_dim_output
: 24; /* 8 * 3 bits */
67 uint32_t tc_gen
: 24; /* 8 * 3 bits */
73 uint64_t value64
[3]; /* don't forget to resize VertexShader9.ff_key */
78 /* Texture stage state:
80 * COLOROP D3DTOP 5 bit
81 * ALPHAOP D3DTOP 5 bit
82 * COLORARG0 D3DTA 3 bit
83 * COLORARG1 D3DTA 3 bit
84 * COLORARG2 D3DTA 3 bit
85 * ALPHAARG0 D3DTA 3 bit
86 * ALPHAARG1 D3DTA 3 bit
87 * ALPHAARG2 D3DTA 3 bit
88 * RESULTARG D3DTA 1 bit (CURRENT:0 or TEMP:1)
89 * TEXCOORDINDEX 0 - 7 3 bit
90 * ===========================
100 uint32_t colorarg0
: 3;
101 uint32_t colorarg1
: 3;
102 uint32_t colorarg2
: 3;
103 uint32_t alphaarg0
: 3;
104 uint32_t alphaarg1
: 3;
105 uint32_t alphaarg2
: 3;
106 uint32_t resultarg
: 1; /* CURRENT:0 or TEMP:1 */
107 uint32_t textarget
: 2; /* 1D/2D/3D/CUBE */
109 /* that's 32 bit exactly */
111 uint32_t projected
: 16;
112 uint32_t fog
: 1; /* for vFog coming from VS */
113 uint32_t fog_mode
: 2;
114 uint32_t specular
: 1;
115 uint32_t pad1
: 12; /* 9 32-bit words with this */
116 uint8_t colorarg_b4
[3];
117 uint8_t colorarg_b5
[3];
118 uint8_t alphaarg_b4
[3]; /* 11 32-bit words plus a byte */
121 uint64_t value64
[6]; /* don't forget to resize PixelShader9.ff_key */
122 uint32_t value32
[12];
126 static unsigned nine_ff_vs_key_hash(void *key
)
128 struct nine_ff_vs_key
*vs
= key
;
130 uint32_t hash
= vs
->value32
[0];
131 for (i
= 1; i
< Elements(vs
->value32
); ++i
)
132 hash
^= vs
->value32
[i
];
135 static int nine_ff_vs_key_comp(void *key1
, void *key2
)
137 struct nine_ff_vs_key
*a
= (struct nine_ff_vs_key
*)key1
;
138 struct nine_ff_vs_key
*b
= (struct nine_ff_vs_key
*)key2
;
140 return memcmp(a
->value64
, b
->value64
, sizeof(a
->value64
));
142 static unsigned nine_ff_ps_key_hash(void *key
)
144 struct nine_ff_ps_key
*ps
= key
;
146 uint32_t hash
= ps
->value32
[0];
147 for (i
= 1; i
< Elements(ps
->value32
); ++i
)
148 hash
^= ps
->value32
[i
];
151 static int nine_ff_ps_key_comp(void *key1
, void *key2
)
153 struct nine_ff_ps_key
*a
= (struct nine_ff_ps_key
*)key1
;
154 struct nine_ff_ps_key
*b
= (struct nine_ff_ps_key
*)key2
;
156 return memcmp(a
->value64
, b
->value64
, sizeof(a
->value64
));
158 static unsigned nine_ff_fvf_key_hash(void *key
)
160 return *(DWORD
*)key
;
162 static int nine_ff_fvf_key_comp(void *key1
, void *key2
)
164 return *(DWORD
*)key1
!= *(DWORD
*)key2
;
167 static void nine_ff_prune_vs(struct NineDevice9
*);
168 static void nine_ff_prune_ps(struct NineDevice9
*);
170 static void nine_ureg_tgsi_dump(struct ureg_program
*ureg
, boolean override
)
172 if (debug_get_bool_option("NINE_FF_DUMP", FALSE
) || override
) {
174 const struct tgsi_token
*toks
= ureg_get_tokens(ureg
, &count
);
176 ureg_free_tokens(toks
);
180 #define _X(r) ureg_scalar(ureg_src(r), TGSI_SWIZZLE_X)
181 #define _Y(r) ureg_scalar(ureg_src(r), TGSI_SWIZZLE_Y)
182 #define _Z(r) ureg_scalar(ureg_src(r), TGSI_SWIZZLE_Z)
183 #define _W(r) ureg_scalar(ureg_src(r), TGSI_SWIZZLE_W)
185 #define _XXXX(r) ureg_scalar(r, TGSI_SWIZZLE_X)
186 #define _YYYY(r) ureg_scalar(r, TGSI_SWIZZLE_Y)
187 #define _ZZZZ(r) ureg_scalar(r, TGSI_SWIZZLE_Z)
188 #define _WWWW(r) ureg_scalar(r, TGSI_SWIZZLE_W)
192 /* AL should contain base address of lights table. */
193 #define LIGHT_CONST(i) \
194 ureg_src_indirect(ureg_DECL_constant(ureg, i), _X(AL))
196 #define MATERIAL_CONST(i) \
197 ureg_DECL_constant(ureg, 19 + (i))
199 #define _CONST(n) ureg_DECL_constant(ureg, n)
201 /* VS FF constants layout:
203 * CONST[ 0.. 3] D3DTS_WORLD * D3DTS_VIEW * D3DTS_PROJECTION
204 * CONST[ 4.. 7] D3DTS_WORLD * D3DTS_VIEW
205 * CONST[ 8..11] D3DTS_VIEW * D3DTS_PROJECTION
206 * CONST[12..15] D3DTS_VIEW
207 * CONST[16..18] Normal matrix
209 * CONST[19] MATERIAL.Emissive + Material.Ambient * RS.Ambient
210 * CONST[20] MATERIAL.Diffuse
211 * CONST[21] MATERIAL.Ambient
212 * CONST[22] MATERIAL.Specular
213 * CONST[23].x___ MATERIAL.Power
214 * CONST[24] MATERIAL.Emissive
215 * CONST[25] RS.Ambient
217 * CONST[26].x___ RS.PointSizeMin
218 * CONST[26]._y__ RS.PointSizeMax
219 * CONST[26].__z_ RS.PointSize
220 * CONST[26].___w RS.PointScaleA
221 * CONST[27].x___ RS.PointScaleB
222 * CONST[27]._y__ RS.PointScaleC
224 * CONST[28].x___ RS.FogEnd
225 * CONST[28]._y__ 1.0f / (RS.FogEnd - RS.FogStart)
226 * CONST[28].__z_ RS.FogDensity
228 * CONST[30].x___ TWEENFACTOR
230 * CONST[32].x___ LIGHT[0].Type
231 * CONST[32]._yzw LIGHT[0].Attenuation0,1,2
232 * CONST[33] LIGHT[0].Diffuse
233 * CONST[34] LIGHT[0].Specular
234 * CONST[35] LIGHT[0].Ambient
235 * CONST[36].xyz_ LIGHT[0].Position
236 * CONST[36].___w LIGHT[0].Range
237 * CONST[37].xyz_ LIGHT[0].Direction
238 * CONST[37].___w LIGHT[0].Falloff
239 * CONST[38].x___ cos(LIGHT[0].Theta / 2)
240 * CONST[38]._y__ cos(LIGHT[0].Phi / 2)
241 * CONST[38].__z_ 1.0f / (cos(LIGHT[0].Theta / 2) - cos(Light[0].Phi / 2))
242 * CONST[39].xyz_ LIGHT[0].HalfVector (for directional lights)
243 * CONST[39].___w 1 if this is the last active light, 0 if not
251 * NOTE: no lighting code is generated if there are no active lights
253 * CONST[100].x___ Viewport 2/width
254 * CONST[100]._y__ Viewport 2/height
255 * CONST[100].__z_ Viewport 1/(zmax - zmin)
256 * CONST[101].x___ Viewport x0
257 * CONST[101]._y__ Viewport y0
258 * CONST[101].__z_ Viewport z0
260 * CONST[128..131] D3DTS_TEXTURE0
261 * CONST[132..135] D3DTS_TEXTURE1
262 * CONST[136..139] D3DTS_TEXTURE2
263 * CONST[140..143] D3DTS_TEXTURE3
264 * CONST[144..147] D3DTS_TEXTURE4
265 * CONST[148..151] D3DTS_TEXTURE5
266 * CONST[152..155] D3DTS_TEXTURE6
267 * CONST[156..159] D3DTS_TEXTURE7
269 * CONST[224] D3DTS_WORLDMATRIX[0]
270 * CONST[228] D3DTS_WORLDMATRIX[1]
272 * CONST[252] D3DTS_WORLDMATRIX[7]
276 struct ureg_program
*ureg
;
277 const struct nine_ff_vs_key
*key
;
279 uint16_t input
[PIPE_MAX_ATTRIBS
];
282 struct ureg_src aVtx
;
283 struct ureg_src aNrm
;
284 struct ureg_src aCol
[2];
285 struct ureg_src aTex
[8];
286 struct ureg_src aPsz
;
287 struct ureg_src aInd
;
288 struct ureg_src aWgt
;
290 struct ureg_src aVtx1
; /* tweening */
291 struct ureg_src aNrm1
;
293 struct ureg_src mtlA
;
294 struct ureg_src mtlD
;
295 struct ureg_src mtlS
;
296 struct ureg_src mtlE
;
299 static inline unsigned
300 get_texcoord_sn(struct pipe_screen
*screen
)
302 if (screen
->get_param(screen
, PIPE_CAP_TGSI_TEXCOORD
))
303 return TGSI_SEMANTIC_TEXCOORD
;
304 return TGSI_SEMANTIC_GENERIC
;
307 static inline struct ureg_src
308 build_vs_add_input(struct vs_build_ctx
*vs
, uint16_t ndecl
)
310 const unsigned i
= vs
->num_inputs
++;
311 assert(i
< PIPE_MAX_ATTRIBS
);
312 vs
->input
[i
] = ndecl
;
313 return ureg_DECL_vs_input(vs
->ureg
, i
);
316 /* NOTE: dst may alias src */
318 ureg_normalize3(struct ureg_program
*ureg
,
319 struct ureg_dst dst
, struct ureg_src src
,
322 #ifdef NINE_TGSI_LAZY_DEVS
323 struct ureg_dst tmp_x
= ureg_writemask(tmp
, TGSI_WRITEMASK_X
);
325 ureg_DP3(ureg
, tmp_x
, src
, src
);
326 ureg_RSQ(ureg
, tmp_x
, _X(tmp
));
327 ureg_MUL(ureg
, dst
, src
, _X(tmp
));
329 ureg_NRM(ureg
, dst
, src
);
334 nine_ff_build_vs(struct NineDevice9
*device
, struct vs_build_ctx
*vs
)
336 const struct nine_ff_vs_key
*key
= vs
->key
;
337 struct ureg_program
*ureg
= ureg_create(TGSI_PROCESSOR_VERTEX
);
338 struct ureg_dst oPos
, oCol
[2], oPsz
, oFog
;
339 struct ureg_dst rVtx
, rNrm
;
340 struct ureg_dst r
[8];
342 struct ureg_dst tmp
, tmp_x
, tmp_y
, tmp_z
;
344 unsigned label
[32], l
= 0;
346 boolean need_rNrm
= key
->lighting
|| key
->pointscale
|| key
->passthrough
& (1 << NINE_DECLUSAGE_NORMAL
);
347 boolean need_rVtx
= key
->lighting
|| key
->fog_mode
;
348 const unsigned texcoord_sn
= get_texcoord_sn(device
->screen
);
352 /* Check which inputs we should transform. */
353 for (i
= 0; i
< 8 * 3; i
+= 3) {
354 switch ((key
->tc_gen
>> i
) & 0x3) {
355 case NINED3DTSS_TCI_CAMERASPACENORMAL
:
358 case NINED3DTSS_TCI_CAMERASPACEPOSITION
:
361 case NINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR
:
362 need_rVtx
= need_rNrm
= TRUE
;
369 /* Declare and record used inputs (needed for linkage with vertex format):
370 * (texture coordinates handled later)
372 vs
->aVtx
= build_vs_add_input(vs
,
373 key
->position_t
? NINE_DECLUSAGE_POSITIONT
: NINE_DECLUSAGE_POSITION
);
376 vs
->aNrm
= build_vs_add_input(vs
, NINE_DECLUSAGE_NORMAL
);
378 vs
->aCol
[0] = ureg_imm1f(ureg
, 1.0f
);
379 vs
->aCol
[1] = ureg_imm1f(ureg
, 1.0f
);
381 if (key
->lighting
|| key
->darkness
) {
382 const unsigned mask
= key
->mtl_diffuse
| key
->mtl_specular
|
383 key
->mtl_ambient
| key
->mtl_emissive
;
384 if ((mask
& 0x1) && !key
->color0in_one
)
385 vs
->aCol
[0] = build_vs_add_input(vs
, NINE_DECLUSAGE_i(COLOR
, 0));
386 if ((mask
& 0x2) && !key
->color1in_one
)
387 vs
->aCol
[1] = build_vs_add_input(vs
, NINE_DECLUSAGE_i(COLOR
, 1));
389 vs
->mtlD
= MATERIAL_CONST(1);
390 vs
->mtlA
= MATERIAL_CONST(2);
391 vs
->mtlS
= MATERIAL_CONST(3);
392 vs
->mtlE
= MATERIAL_CONST(5);
393 if (key
->mtl_diffuse
== 1) vs
->mtlD
= vs
->aCol
[0]; else
394 if (key
->mtl_diffuse
== 2) vs
->mtlD
= vs
->aCol
[1];
395 if (key
->mtl_ambient
== 1) vs
->mtlA
= vs
->aCol
[0]; else
396 if (key
->mtl_ambient
== 2) vs
->mtlA
= vs
->aCol
[1];
397 if (key
->mtl_specular
== 1) vs
->mtlS
= vs
->aCol
[0]; else
398 if (key
->mtl_specular
== 2) vs
->mtlS
= vs
->aCol
[1];
399 if (key
->mtl_emissive
== 1) vs
->mtlE
= vs
->aCol
[0]; else
400 if (key
->mtl_emissive
== 2) vs
->mtlE
= vs
->aCol
[1];
402 if (!key
->color0in_one
) vs
->aCol
[0] = build_vs_add_input(vs
, NINE_DECLUSAGE_i(COLOR
, 0));
403 if (!key
->color1in_one
) vs
->aCol
[1] = build_vs_add_input(vs
, NINE_DECLUSAGE_i(COLOR
, 1));
406 if (key
->vertexpointsize
)
407 vs
->aPsz
= build_vs_add_input(vs
, NINE_DECLUSAGE_PSIZE
);
409 if (key
->vertexblend_indexed
|| key
->passthrough
& (1 << NINE_DECLUSAGE_BLENDINDICES
))
410 vs
->aInd
= build_vs_add_input(vs
, NINE_DECLUSAGE_BLENDINDICES
);
411 if (key
->vertexblend
|| key
->passthrough
& (1 << NINE_DECLUSAGE_BLENDWEIGHT
))
412 vs
->aWgt
= build_vs_add_input(vs
, NINE_DECLUSAGE_BLENDWEIGHT
);
413 if (key
->vertextween
) {
414 vs
->aVtx1
= build_vs_add_input(vs
, NINE_DECLUSAGE_i(POSITION
,1));
415 vs
->aNrm1
= build_vs_add_input(vs
, NINE_DECLUSAGE_i(NORMAL
,1));
420 oPos
= ureg_DECL_output(ureg
, TGSI_SEMANTIC_POSITION
, 0); /* HPOS */
421 oCol
[0] = ureg_saturate(ureg_DECL_output(ureg
, TGSI_SEMANTIC_COLOR
, 0));
422 oCol
[1] = ureg_saturate(ureg_DECL_output(ureg
, TGSI_SEMANTIC_COLOR
, 1));
423 if (key
->fog
|| key
->passthrough
& (1 << NINE_DECLUSAGE_FOG
)) {
424 oFog
= ureg_DECL_output(ureg
, TGSI_SEMANTIC_FOG
, 0);
425 oFog
= ureg_writemask(oFog
, TGSI_WRITEMASK_X
);
428 if (key
->vertexpointsize
|| key
->pointscale
) {
429 oPsz
= ureg_DECL_output_masked(ureg
, TGSI_SEMANTIC_PSIZE
, 0,
430 TGSI_WRITEMASK_X
, 0, 1);
431 oPsz
= ureg_writemask(oPsz
, TGSI_WRITEMASK_X
);
436 for (i
= 0; i
< num_r
; ++i
)
437 r
[i
] = ureg_DECL_local_temporary(ureg
);
439 tmp_x
= ureg_writemask(tmp
, TGSI_WRITEMASK_X
);
440 tmp_y
= ureg_writemask(tmp
, TGSI_WRITEMASK_Y
);
441 tmp_z
= ureg_writemask(tmp
, TGSI_WRITEMASK_Z
);
442 if (key
->lighting
|| key
->vertexblend
)
443 AR
= ureg_DECL_address(ureg
);
445 rVtx
= ureg_writemask(r
[1], TGSI_WRITEMASK_XYZ
);
446 rNrm
= ureg_writemask(r
[2], TGSI_WRITEMASK_XYZ
);
448 /* === Vertex transformation / vertex blending:
450 if (key
->vertextween
) {
451 assert(!key
->vertexblend
);
452 ureg_LRP(ureg
, r
[2], _XXXX(_CONST(30)), vs
->aVtx
, vs
->aVtx1
);
454 ureg_LRP(ureg
, r
[3], _XXXX(_CONST(30)), vs
->aNrm
, vs
->aNrm1
);
455 vs
->aVtx
= ureg_src(r
[2]);
456 vs
->aNrm
= ureg_src(r
[3]);
459 if (key
->vertexblend
) {
460 struct ureg_src cWM
[4];
462 for (i
= 224; i
<= 255; ++i
)
463 ureg_DECL_constant(ureg
, i
);
465 /* translate world matrix index to constant file index */
466 if (key
->vertexblend_indexed
) {
467 ureg_MAD(ureg
, tmp
, vs
->aInd
, ureg_imm1f(ureg
, 4.0f
), ureg_imm1f(ureg
, 224.0f
));
468 ureg_ARL(ureg
, AR
, ureg_src(tmp
));
470 for (i
= 0; i
< key
->vertexblend
; ++i
) {
471 for (c
= 0; c
< 4; ++c
) {
472 cWM
[c
] = ureg_src_register(TGSI_FILE_CONSTANT
, (224 + i
* 4) * !key
->vertexblend_indexed
+ c
);
473 if (key
->vertexblend_indexed
)
474 cWM
[c
] = ureg_src_indirect(cWM
[c
], ureg_scalar(ureg_src(AR
), i
));
476 /* multiply by WORLD(index) */
477 ureg_MUL(ureg
, tmp
, _XXXX(vs
->aVtx
), cWM
[0]);
478 ureg_MAD(ureg
, tmp
, _YYYY(vs
->aVtx
), cWM
[1], ureg_src(tmp
));
479 ureg_MAD(ureg
, tmp
, _ZZZZ(vs
->aVtx
), cWM
[2], ureg_src(tmp
));
480 ureg_MAD(ureg
, tmp
, _WWWW(vs
->aVtx
), cWM
[3], ureg_src(tmp
));
482 /* accumulate weighted position value */
484 ureg_MAD(ureg
, r
[2], ureg_src(tmp
), ureg_scalar(vs
->aWgt
, i
), ureg_src(r
[2]));
486 ureg_MUL(ureg
, r
[2], ureg_src(tmp
), ureg_scalar(vs
->aWgt
, 0));
488 /* multiply by VIEW_PROJ */
489 ureg_MUL(ureg
, tmp
, _X(r
[2]), _CONST(8));
490 ureg_MAD(ureg
, tmp
, _Y(r
[2]), _CONST(9), ureg_src(tmp
));
491 ureg_MAD(ureg
, tmp
, _Z(r
[2]), _CONST(10), ureg_src(tmp
));
492 ureg_MAD(ureg
, oPos
, _W(r
[2]), _CONST(11), ureg_src(tmp
));
495 vs
->aVtx
= ureg_src(r
[2]);
497 if (key
->position_t
&& device
->driver_caps
.window_space_position_support
) {
498 ureg_MOV(ureg
, oPos
, vs
->aVtx
);
499 } else if (key
->position_t
) {
500 /* vs->aVtx contains the coordinates buffer wise.
501 * later in the pipeline, clipping, viewport and division
502 * by w (rhw = 1/w) are going to be applied, so do the reverse
503 * of these transformations (except clipping) to have the good
504 * position at the end.*/
505 ureg_MOV(ureg
, tmp
, vs
->aVtx
);
506 /* X from [X_min, X_min + width] to [-1, 1], same for Y. Z to [0, 1] */
507 ureg_SUB(ureg
, ureg_writemask(tmp
, TGSI_WRITEMASK_XYZ
), ureg_src(tmp
), _CONST(101));
508 ureg_MUL(ureg
, ureg_writemask(tmp
, TGSI_WRITEMASK_XYZ
), ureg_src(tmp
), _CONST(100));
509 ureg_SUB(ureg
, ureg_writemask(tmp
, TGSI_WRITEMASK_XY
), ureg_src(tmp
), ureg_imm1f(ureg
, 1.0f
));
510 /* Y needs to be reversed */
511 ureg_MOV(ureg
, ureg_writemask(tmp
, TGSI_WRITEMASK_Y
), ureg_negate(ureg_src(tmp
)));
513 ureg_RCP(ureg
, ureg_writemask(tmp
, TGSI_WRITEMASK_W
), _W(tmp
));
514 /* multiply X, Y, Z by w */
515 ureg_MUL(ureg
, ureg_writemask(tmp
, TGSI_WRITEMASK_XYZ
), ureg_src(tmp
), _W(tmp
));
516 ureg_MOV(ureg
, oPos
, ureg_src(tmp
));
518 /* position = vertex * WORLD_VIEW_PROJ */
519 ureg_MUL(ureg
, tmp
, _XXXX(vs
->aVtx
), _CONST(0));
520 ureg_MAD(ureg
, tmp
, _YYYY(vs
->aVtx
), _CONST(1), ureg_src(tmp
));
521 ureg_MAD(ureg
, tmp
, _ZZZZ(vs
->aVtx
), _CONST(2), ureg_src(tmp
));
522 ureg_MAD(ureg
, oPos
, _WWWW(vs
->aVtx
), _CONST(3), ureg_src(tmp
));
526 ureg_MUL(ureg
, rVtx
, _XXXX(vs
->aVtx
), _CONST(4));
527 ureg_MAD(ureg
, rVtx
, _YYYY(vs
->aVtx
), _CONST(5), ureg_src(rVtx
));
528 ureg_MAD(ureg
, rVtx
, _ZZZZ(vs
->aVtx
), _CONST(6), ureg_src(rVtx
));
529 ureg_MAD(ureg
, rVtx
, _WWWW(vs
->aVtx
), _CONST(7), ureg_src(rVtx
));
532 ureg_MUL(ureg
, rNrm
, _XXXX(vs
->aNrm
), _CONST(16));
533 ureg_MAD(ureg
, rNrm
, _YYYY(vs
->aNrm
), _CONST(17), ureg_src(rNrm
));
534 ureg_MAD(ureg
, rNrm
, _ZZZZ(vs
->aNrm
), _CONST(18), ureg_src(rNrm
));
535 ureg_normalize3(ureg
, rNrm
, ureg_src(rNrm
), tmp
);
537 /* NOTE: don't use vs->aVtx, vs->aNrm after this line */
539 /* === Process point size:
541 if (key
->vertexpointsize
) {
542 struct ureg_src cPsz1
= ureg_DECL_constant(ureg
, 26);
543 #ifdef NINE_TGSI_LAZY_DEVS
544 struct ureg_dst tmp_clamp
= ureg_DECL_temporary(ureg
);
546 ureg_MAX(ureg
, tmp_clamp
, vs
->aPsz
, _XXXX(cPsz1
));
547 ureg_MIN(ureg
, oPsz
, ureg_src(tmp_clamp
), _YYYY(cPsz1
));
548 ureg_release_temporary(ureg
, tmp_clamp
);
550 ureg_CLAMP(ureg
, oPsz
, vs
->aPsz
, _XXXX(cPsz1
), _YYYY(cPsz1
));
552 } else if (key
->pointscale
) {
553 struct ureg_src cPsz1
= ureg_DECL_constant(ureg
, 26);
554 struct ureg_src cPsz2
= ureg_DECL_constant(ureg
, 27);
556 ureg_DP3(ureg
, tmp_x
, ureg_src(r
[1]), ureg_src(r
[1]));
557 ureg_SQRT(ureg
, tmp_y
, _X(tmp
));
558 ureg_MAD(ureg
, tmp_x
, _Y(tmp
), _YYYY(cPsz2
), _XXXX(cPsz2
));
559 ureg_MAD(ureg
, tmp_x
, _Y(tmp
), _X(tmp
), _WWWW(cPsz1
));
560 ureg_RCP(ureg
, tmp_x
, ureg_src(tmp
));
561 ureg_MUL(ureg
, tmp_x
, ureg_src(tmp
), _ZZZZ(cPsz1
));
562 #ifdef NINE_TGSI_LAZY_DEVS
563 struct ureg_dst tmp_clamp
= ureg_DECL_temporary(ureg
);
565 ureg_MAX(ureg
, tmp_clamp
, _X(tmp
), _XXXX(cPsz1
));
566 ureg_MIN(ureg
, oPsz
, ureg_src(tmp_clamp
), _YYYY(cPsz1
));
567 ureg_release_temporary(ureg
, tmp_clamp
);
569 ureg_CLAMP(ureg
, oPsz
, _X(tmp
), _XXXX(cPsz1
), _YYYY(cPsz1
));
573 for (i
= 0; i
< 8; ++i
) {
574 struct ureg_dst oTex
, input_coord
, transformed
, t
;
575 unsigned c
, writemask
;
576 const unsigned tci
= (key
->tc_gen
>> (i
* 3)) & 0x7;
577 const unsigned idx
= (key
->tc_idx
>> (i
* 3)) & 0x7;
578 unsigned dim_input
= 1 + ((key
->tc_dim_input
>> (i
* 2)) & 0x3);
579 const unsigned dim_output
= (key
->tc_dim_output
>> (i
* 3)) & 0x7;
581 /* No texture output of index s */
582 if (tci
== NINED3DTSS_TCI_DISABLE
)
584 oTex
= ureg_DECL_output(ureg
, texcoord_sn
, i
);
588 /* Get the coordinate */
590 case NINED3DTSS_TCI_PASSTHRU
:
591 /* NINED3DTSS_TCI_PASSTHRU => Use texcoord coming from index idx *
592 * Else the idx is used only to determine wrapping mode. */
593 vs
->aTex
[idx
] = build_vs_add_input(vs
, NINE_DECLUSAGE_i(TEXCOORD
,idx
));
594 ureg_MOV(ureg
, input_coord
, vs
->aTex
[idx
]);
596 case NINED3DTSS_TCI_CAMERASPACENORMAL
:
597 ureg_MOV(ureg
, ureg_writemask(input_coord
, TGSI_WRITEMASK_XYZ
), ureg_src(rNrm
));
598 ureg_MOV(ureg
, ureg_writemask(input_coord
, TGSI_WRITEMASK_W
), ureg_imm1f(ureg
, 1.0f
));
601 case NINED3DTSS_TCI_CAMERASPACEPOSITION
:
602 ureg_MOV(ureg
, ureg_writemask(input_coord
, TGSI_WRITEMASK_XYZ
), ureg_src(rVtx
));
603 ureg_MOV(ureg
, ureg_writemask(input_coord
, TGSI_WRITEMASK_W
), ureg_imm1f(ureg
, 1.0f
));
606 case NINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR
:
607 tmp
.WriteMask
= TGSI_WRITEMASK_XYZ
;
608 ureg_DP3(ureg
, tmp_x
, ureg_src(rVtx
), ureg_src(rNrm
));
609 ureg_MUL(ureg
, tmp
, ureg_src(rNrm
), _X(tmp
));
610 ureg_ADD(ureg
, tmp
, ureg_src(tmp
), ureg_src(tmp
));
611 ureg_SUB(ureg
, ureg_writemask(input_coord
, TGSI_WRITEMASK_XYZ
), ureg_src(rVtx
), ureg_src(tmp
));
612 ureg_MOV(ureg
, ureg_writemask(input_coord
, TGSI_WRITEMASK_W
), ureg_imm1f(ureg
, 1.0f
));
614 tmp
.WriteMask
= TGSI_WRITEMASK_XYZW
;
616 case NINED3DTSS_TCI_SPHEREMAP
:
624 /* Apply the transformation */
625 /* dim_output == 0 => do not transform the components.
626 * XYZRHW also disables transformation */
627 if (!dim_output
|| key
->position_t
) {
628 transformed
= input_coord
;
629 writemask
= TGSI_WRITEMASK_XYZW
;
631 for (c
= 0; c
< dim_output
; c
++) {
632 t
= ureg_writemask(transformed
, 1 << c
);
634 /* dim_input = 1 2 3: -> we add trailing 1 to input*/
635 case 1: ureg_MAD(ureg
, t
, _X(input_coord
), _XXXX(_CONST(128 + i
* 4 + c
)), _YYYY(_CONST(128 + i
* 4 + c
)));
637 case 2: ureg_DP2(ureg
, t
, ureg_src(input_coord
), _CONST(128 + i
* 4 + c
));
638 ureg_ADD(ureg
, t
, ureg_src(transformed
), _ZZZZ(_CONST(128 + i
* 4 + c
)));
640 case 3: ureg_DP3(ureg
, t
, ureg_src(input_coord
), _CONST(128 + i
* 4 + c
));
641 ureg_ADD(ureg
, t
, ureg_src(transformed
), _WWWW(_CONST(128 + i
* 4 + c
)));
643 case 4: ureg_DP4(ureg
, t
, ureg_src(input_coord
), _CONST(128 + i
* 4 + c
)); break;
648 writemask
= (1 << dim_output
) - 1;
651 ureg_MOV(ureg
, ureg_writemask(oTex
, writemask
), ureg_src(transformed
));
656 * DIRECTIONAL: Light at infinite distance, parallel rays, no attenuation.
657 * POINT: Finite distance to scene, divergent rays, isotropic, attenuation.
658 * SPOT: Finite distance, divergent rays, angular dependence, attenuation.
660 * vec3 normal = normalize(in.Normal * NormalMatrix);
661 * vec3 hitDir = light.direction;
664 * if (light.type != DIRECTIONAL)
666 * vec3 hitVec = light.position - eyeVertex;
667 * float d = length(hitVec);
668 * hitDir = hitVec / d;
669 * atten = 1 / ((light.atten2 * d + light.atten1) * d + light.atten0);
672 * if (light.type == SPOTLIGHT)
674 * float rho = dp3(-hitVec, light.direction);
675 * if (rho < cos(light.phi / 2))
677 * if (rho < cos(light.theta / 2))
678 * atten *= pow(some_func(rho), light.falloff);
681 * float nDotHit = dp3_sat(normal, hitVec);
682 * float powFact = 0.0;
686 * vec3 midVec = normalize(hitDir + eye);
687 * float nDotMid = dp3_sat(normal, midVec);
688 * pFact = pow(nDotMid, material.power);
691 * ambient += light.ambient * atten;
692 * diffuse += light.diffuse * atten * nDotHit;
693 * specular += light.specular * atten * powFact;
696 struct ureg_dst rAtt
= ureg_writemask(r
[1], TGSI_WRITEMASK_W
);
697 struct ureg_dst rHit
= ureg_writemask(r
[3], TGSI_WRITEMASK_XYZ
);
698 struct ureg_dst rMid
= ureg_writemask(r
[4], TGSI_WRITEMASK_XYZ
);
700 struct ureg_dst rCtr
= ureg_writemask(r
[2], TGSI_WRITEMASK_W
);
702 struct ureg_dst AL
= ureg_writemask(AR
, TGSI_WRITEMASK_X
);
704 /* Light.*.Alpha is not used. */
705 struct ureg_dst rD
= ureg_writemask(r
[5], TGSI_WRITEMASK_XYZ
);
706 struct ureg_dst rA
= ureg_writemask(r
[6], TGSI_WRITEMASK_XYZ
);
707 struct ureg_dst rS
= ureg_writemask(r
[7], TGSI_WRITEMASK_XYZ
);
709 struct ureg_src mtlP
= _XXXX(MATERIAL_CONST(4));
711 struct ureg_src cLKind
= _XXXX(LIGHT_CONST(0));
712 struct ureg_src cLAtt0
= _YYYY(LIGHT_CONST(0));
713 struct ureg_src cLAtt1
= _ZZZZ(LIGHT_CONST(0));
714 struct ureg_src cLAtt2
= _WWWW(LIGHT_CONST(0));
715 struct ureg_src cLColD
= _XYZW(LIGHT_CONST(1));
716 struct ureg_src cLColS
= _XYZW(LIGHT_CONST(2));
717 struct ureg_src cLColA
= _XYZW(LIGHT_CONST(3));
718 struct ureg_src cLPos
= _XYZW(LIGHT_CONST(4));
719 struct ureg_src cLRng
= _WWWW(LIGHT_CONST(4));
720 struct ureg_src cLDir
= _XYZW(LIGHT_CONST(5));
721 struct ureg_src cLFOff
= _WWWW(LIGHT_CONST(5));
722 struct ureg_src cLTht
= _XXXX(LIGHT_CONST(6));
723 struct ureg_src cLPhi
= _YYYY(LIGHT_CONST(6));
724 struct ureg_src cLSDiv
= _ZZZZ(LIGHT_CONST(6));
725 struct ureg_src cLLast
= _WWWW(LIGHT_CONST(7));
727 const unsigned loop_label
= l
++;
729 ureg_MOV(ureg
, rCtr
, ureg_imm1f(ureg
, 32.0f
)); /* &lightconst(0) */
730 ureg_MOV(ureg
, rD
, ureg_imm1f(ureg
, 0.0f
));
731 ureg_MOV(ureg
, rA
, ureg_imm1f(ureg
, 0.0f
));
732 ureg_MOV(ureg
, rS
, ureg_imm1f(ureg
, 0.0f
));
733 rD
= ureg_saturate(rD
);
734 rA
= ureg_saturate(rA
);
735 rS
= ureg_saturate(rS
);
738 /* loop management */
739 ureg_BGNLOOP(ureg
, &label
[loop_label
]);
740 ureg_ARL(ureg
, AL
, _W(rCtr
));
742 /* if (not DIRECTIONAL light): */
743 ureg_SNE(ureg
, tmp_x
, cLKind
, ureg_imm1f(ureg
, D3DLIGHT_DIRECTIONAL
));
744 ureg_MOV(ureg
, rHit
, ureg_negate(cLDir
));
745 ureg_MOV(ureg
, rAtt
, ureg_imm1f(ureg
, 1.0f
));
746 ureg_IF(ureg
, _X(tmp
), &label
[l
++]);
748 /* hitDir = light.position - eyeVtx
752 ureg_SUB(ureg
, rHit
, cLPos
, ureg_src(rVtx
));
753 ureg_DP3(ureg
, tmp_x
, ureg_src(rHit
), ureg_src(rHit
));
754 ureg_RSQ(ureg
, tmp_y
, _X(tmp
));
755 ureg_MUL(ureg
, rHit
, ureg_src(rHit
), _Y(tmp
)); /* normalize */
756 ureg_MUL(ureg
, tmp_x
, _X(tmp
), _Y(tmp
)); /* length */
758 /* att = 1.0 / (light.att0 + (light.att1 + light.att2 * d) * d) */
759 ureg_MAD(ureg
, rAtt
, _X(tmp
), cLAtt2
, cLAtt1
);
760 ureg_MAD(ureg
, rAtt
, _X(tmp
), _W(rAtt
), cLAtt0
);
761 ureg_RCP(ureg
, rAtt
, _W(rAtt
));
762 /* cut-off if distance exceeds Light.Range */
763 ureg_SLT(ureg
, tmp_x
, _X(tmp
), cLRng
);
764 ureg_MUL(ureg
, rAtt
, _W(rAtt
), _X(tmp
));
766 ureg_fixup_label(ureg
, label
[l
-1], ureg_get_instruction_number(ureg
));
769 /* if (SPOT light) */
770 ureg_SEQ(ureg
, tmp_x
, cLKind
, ureg_imm1f(ureg
, D3DLIGHT_SPOT
));
771 ureg_IF(ureg
, _X(tmp
), &label
[l
++]);
773 /* rho = dp3(-hitDir, light.spotDir)
775 * if (rho > light.ctht2) NOTE: 0 <= phi <= pi, 0 <= theta <= phi
778 * if (rho <= light.cphi2)
781 * spotAtt = (rho - light.cphi2) / (light.ctht2 - light.cphi2) ^ light.falloff
783 ureg_DP3(ureg
, tmp_y
, ureg_negate(ureg_src(rHit
)), cLDir
); /* rho */
784 ureg_SUB(ureg
, tmp_x
, _Y(tmp
), cLPhi
);
785 ureg_MUL(ureg
, tmp_x
, _X(tmp
), cLSDiv
);
786 ureg_POW(ureg
, tmp_x
, _X(tmp
), cLFOff
); /* spotAtten */
787 ureg_SGE(ureg
, tmp_z
, _Y(tmp
), cLTht
); /* if inside theta && phi */
788 ureg_SGE(ureg
, tmp_y
, _Y(tmp
), cLPhi
); /* if inside phi */
789 ureg_MAD(ureg
, ureg_saturate(tmp_x
), _X(tmp
), _Y(tmp
), _Z(tmp
));
790 ureg_MUL(ureg
, rAtt
, _W(rAtt
), _X(tmp
));
792 ureg_fixup_label(ureg
, label
[l
-1], ureg_get_instruction_number(ureg
));
795 /* directional factors, let's not use LIT because of clarity */
796 ureg_DP3(ureg
, ureg_saturate(tmp_x
), ureg_src(rNrm
), ureg_src(rHit
));
797 ureg_MOV(ureg
, tmp_y
, ureg_imm1f(ureg
, 0.0f
));
798 ureg_IF(ureg
, _X(tmp
), &label
[l
++]);
800 /* midVec = normalize(hitDir + eyeDir) */
801 if (key
->localviewer
) {
802 ureg_normalize3(ureg
, rMid
, ureg_src(rVtx
), tmp
);
803 ureg_SUB(ureg
, rMid
, ureg_src(rHit
), ureg_src(rMid
));
805 ureg_SUB(ureg
, rMid
, ureg_src(rHit
), ureg_imm3f(ureg
, 0.0f
, 0.0f
, 1.0f
));
807 ureg_normalize3(ureg
, rMid
, ureg_src(rMid
), tmp
);
808 ureg_DP3(ureg
, ureg_saturate(tmp_y
), ureg_src(rNrm
), ureg_src(rMid
));
809 ureg_POW(ureg
, tmp_y
, _Y(tmp
), mtlP
);
811 ureg_MUL(ureg
, tmp_x
, _W(rAtt
), _X(tmp
)); /* dp3(normal,hitDir) * att */
812 ureg_MUL(ureg
, tmp_y
, _W(rAtt
), _Y(tmp
)); /* power factor * att */
813 ureg_MAD(ureg
, rD
, cLColD
, _X(tmp
), ureg_src(rD
)); /* accumulate diffuse */
814 ureg_MAD(ureg
, rS
, cLColS
, _Y(tmp
), ureg_src(rS
)); /* accumulate specular */
816 ureg_fixup_label(ureg
, label
[l
-1], ureg_get_instruction_number(ureg
));
819 ureg_MAD(ureg
, rA
, cLColA
, _W(rAtt
), ureg_src(rA
)); /* accumulate ambient */
821 /* break if this was the last light */
822 ureg_IF(ureg
, cLLast
, &label
[l
++]);
825 ureg_fixup_label(ureg
, label
[l
-1], ureg_get_instruction_number(ureg
));
827 ureg_ADD(ureg
, rCtr
, _W(rCtr
), ureg_imm1f(ureg
, 8.0f
));
828 ureg_fixup_label(ureg
, label
[loop_label
], ureg_get_instruction_number(ureg
));
829 ureg_ENDLOOP(ureg
, &label
[loop_label
]);
831 /* Set alpha factors of illumination to 1.0 for the multiplications. */
832 rD
.WriteMask
= TGSI_WRITEMASK_W
; rD
.Saturate
= 0;
833 rS
.WriteMask
= TGSI_WRITEMASK_W
; rS
.Saturate
= 0;
834 rA
.WriteMask
= TGSI_WRITEMASK_W
; rA
.Saturate
= 0;
835 ureg_MOV(ureg
, rD
, ureg_imm1f(ureg
, 1.0f
));
836 ureg_MOV(ureg
, rS
, ureg_imm1f(ureg
, 1.0f
));
838 /* Apply to material:
840 * oCol[0] = (material.emissive + material.ambient * rs.ambient) +
841 * material.ambient * ambient +
842 * material.diffuse * diffuse +
843 * oCol[1] = material.specular * specular;
845 if (key
->mtl_emissive
== 0 && key
->mtl_ambient
== 0) {
846 ureg_MOV(ureg
, rA
, ureg_imm1f(ureg
, 1.0f
));
847 ureg_MAD(ureg
, tmp
, ureg_src(rA
), vs
->mtlA
, _CONST(19));
849 ureg_ADD(ureg
, ureg_writemask(tmp
, TGSI_WRITEMASK_XYZ
), ureg_src(rA
), _CONST(25));
850 ureg_MAD(ureg
, ureg_writemask(tmp
, TGSI_WRITEMASK_XYZ
), vs
->mtlA
, ureg_src(tmp
), vs
->mtlE
);
851 ureg_ADD(ureg
, ureg_writemask(tmp
, TGSI_WRITEMASK_W
), vs
->mtlA
, vs
->mtlE
);
854 if (key
->specular_enable
) {
855 /* add oCol[1] to oCol[0] */
856 ureg_MAD(ureg
, tmp
, ureg_src(rD
), vs
->mtlD
, ureg_src(tmp
));
857 ureg_MAD(ureg
, oCol
[0], ureg_src(rS
), vs
->mtlS
, ureg_src(tmp
));
859 ureg_MAD(ureg
, oCol
[0], ureg_src(rD
), vs
->mtlD
, ureg_src(tmp
));
861 ureg_MUL(ureg
, oCol
[1], ureg_src(rS
), vs
->mtlS
);
865 if (key
->mtl_emissive
== 0 && key
->mtl_ambient
== 0) {
866 ureg_MAD(ureg
, oCol
[0], vs
->mtlD
, ureg_imm4f(ureg
, 0.0f
, 0.0f
, 0.0f
, 1.0f
), _CONST(19));
868 ureg_MAD(ureg
, ureg_writemask(oCol
[0], TGSI_WRITEMASK_XYZ
), vs
->mtlA
, _CONST(25), vs
->mtlE
);
869 ureg_ADD(ureg
, ureg_writemask(tmp
, TGSI_WRITEMASK_W
), vs
->mtlA
, vs
->mtlE
);
870 ureg_ADD(ureg
, ureg_writemask(oCol
[0], TGSI_WRITEMASK_W
), vs
->mtlD
, _W(tmp
));
872 ureg_MUL(ureg
, oCol
[1], ureg_imm4f(ureg
, 0.0f
, 0.0f
, 0.0f
, 1.0f
), vs
->mtlS
);
874 ureg_MOV(ureg
, oCol
[0], vs
->aCol
[0]);
875 ureg_MOV(ureg
, oCol
[1], vs
->aCol
[1]);
880 * exp(x) = ex2(log2(e) * x)
883 if (key
->position_t
) {
884 ureg_MOV(ureg
, ureg_saturate(tmp_x
), ureg_scalar(vs
->aCol
[1], TGSI_SWIZZLE_W
));
886 if (key
->fog_range
) {
887 ureg_DP3(ureg
, tmp_x
, ureg_src(rVtx
), ureg_src(rVtx
));
888 ureg_RSQ(ureg
, tmp_z
, _X(tmp
));
889 ureg_MUL(ureg
, tmp_z
, _Z(tmp
), _X(tmp
));
891 ureg_MOV(ureg
, tmp_z
, ureg_abs(_Z(rVtx
)));
894 if (key
->fog_mode
== D3DFOG_EXP
) {
895 ureg_MUL(ureg
, tmp_x
, _Z(tmp
), _ZZZZ(_CONST(28)));
896 ureg_MUL(ureg
, tmp_x
, _X(tmp
), ureg_imm1f(ureg
, -1.442695f
));
897 ureg_EX2(ureg
, tmp_x
, _X(tmp
));
899 if (key
->fog_mode
== D3DFOG_EXP2
) {
900 ureg_MUL(ureg
, tmp_x
, _Z(tmp
), _ZZZZ(_CONST(28)));
901 ureg_MUL(ureg
, tmp_x
, _X(tmp
), _X(tmp
));
902 ureg_MUL(ureg
, tmp_x
, _X(tmp
), ureg_imm1f(ureg
, -1.442695f
));
903 ureg_EX2(ureg
, tmp_x
, _X(tmp
));
905 if (key
->fog_mode
== D3DFOG_LINEAR
&& !key
->position_t
) {
906 ureg_SUB(ureg
, tmp_x
, _XXXX(_CONST(28)), _Z(tmp
));
907 ureg_MUL(ureg
, ureg_saturate(tmp_x
), _X(tmp
), _YYYY(_CONST(28)));
909 ureg_MOV(ureg
, oFog
, _X(tmp
));
910 } else if (key
->fog
&& !(key
->passthrough
& (1 << NINE_DECLUSAGE_FOG
))) {
911 ureg_MOV(ureg
, oFog
, ureg_scalar(vs
->aCol
[1], TGSI_SWIZZLE_W
));
914 if (key
->passthrough
& (1 << NINE_DECLUSAGE_BLENDWEIGHT
)) {
915 struct ureg_src input
;
916 struct ureg_dst output
;
918 output
= ureg_DECL_output(ureg
, TGSI_SEMANTIC_GENERIC
, 18);
919 ureg_MOV(ureg
, output
, input
);
921 if (key
->passthrough
& (1 << NINE_DECLUSAGE_BLENDINDICES
)) {
922 struct ureg_src input
;
923 struct ureg_dst output
;
925 output
= ureg_DECL_output(ureg
, TGSI_SEMANTIC_GENERIC
, 19);
926 ureg_MOV(ureg
, output
, input
);
928 if (key
->passthrough
& (1 << NINE_DECLUSAGE_NORMAL
)) {
929 struct ureg_src input
;
930 struct ureg_dst output
;
932 output
= ureg_DECL_output(ureg
, TGSI_SEMANTIC_GENERIC
, 20);
933 ureg_MOV(ureg
, output
, input
);
935 if (key
->passthrough
& (1 << NINE_DECLUSAGE_TANGENT
)) {
936 struct ureg_src input
;
937 struct ureg_dst output
;
938 input
= build_vs_add_input(vs
, NINE_DECLUSAGE_TANGENT
);
939 output
= ureg_DECL_output(ureg
, TGSI_SEMANTIC_GENERIC
, 21);
940 ureg_MOV(ureg
, output
, input
);
942 if (key
->passthrough
& (1 << NINE_DECLUSAGE_BINORMAL
)) {
943 struct ureg_src input
;
944 struct ureg_dst output
;
945 input
= build_vs_add_input(vs
, NINE_DECLUSAGE_BINORMAL
);
946 output
= ureg_DECL_output(ureg
, TGSI_SEMANTIC_GENERIC
, 22);
947 ureg_MOV(ureg
, output
, input
);
949 if (key
->passthrough
& (1 << NINE_DECLUSAGE_FOG
)) {
950 struct ureg_src input
;
951 struct ureg_dst output
;
952 input
= build_vs_add_input(vs
, NINE_DECLUSAGE_FOG
);
953 input
= ureg_scalar(input
, TGSI_SWIZZLE_X
);
955 ureg_MOV(ureg
, output
, input
);
957 if (key
->passthrough
& (1 << NINE_DECLUSAGE_DEPTH
)) {
958 (void) 0; /* TODO: replace z of position output ? */
962 if (key
->position_t
&& device
->driver_caps
.window_space_position_support
)
963 ureg_property(ureg
, TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
, TRUE
);
966 nine_ureg_tgsi_dump(ureg
, FALSE
);
967 return ureg_create_shader_and_destroy(ureg
, device
->pipe
);
970 /* PS FF constants layout:
972 * CONST[ 0.. 7] stage[i].D3DTSS_CONSTANT
973 * CONST[ 8..15].x___ stage[i].D3DTSS_BUMPENVMAT00
974 * CONST[ 8..15]._y__ stage[i].D3DTSS_BUMPENVMAT01
975 * CONST[ 8..15].__z_ stage[i].D3DTSS_BUMPENVMAT10
976 * CONST[ 8..15].___w stage[i].D3DTSS_BUMPENVMAT11
977 * CONST[16..19].x_z_ stage[i].D3DTSS_BUMPENVLSCALE
978 * CONST[17..19]._y_w stage[i].D3DTSS_BUMPENVLOFFSET
980 * CONST[20] D3DRS_TEXTUREFACTOR
981 * CONST[21] D3DRS_FOGCOLOR
982 * CONST[22].x___ RS.FogEnd
983 * CONST[22]._y__ 1.0f / (RS.FogEnd - RS.FogStart)
984 * CONST[22].__z_ RS.FogDensity
988 struct ureg_program
*ureg
;
990 struct ureg_src vC
[2]; /* DIFFUSE, SPECULAR */
991 struct ureg_src vT
[8]; /* TEXCOORD[i] */
992 struct ureg_dst r
[6]; /* TEMPs */
993 struct ureg_dst rCur
; /* D3DTA_CURRENT */
994 struct ureg_dst rMod
;
995 struct ureg_src rCurSrc
;
996 struct ureg_dst rTmp
; /* D3DTA_TEMP */
997 struct ureg_src rTmpSrc
;
998 struct ureg_dst rTex
;
999 struct ureg_src rTexSrc
;
1000 struct ureg_src cBEM
[8];
1001 struct ureg_src s
[8];
1005 unsigned index_pre_mod
;
1010 static struct ureg_src
1011 ps_get_ts_arg(struct ps_build_ctx
*ps
, unsigned ta
)
1013 struct ureg_src reg
;
1015 switch (ta
& D3DTA_SELECTMASK
) {
1016 case D3DTA_CONSTANT
:
1017 reg
= ureg_DECL_constant(ps
->ureg
, ps
->stage
.index
);
1020 reg
= (ps
->stage
.index
== ps
->stage
.index_pre_mod
) ? ureg_src(ps
->rMod
) : ps
->rCurSrc
;
1023 reg
= ureg_DECL_fs_input(ps
->ureg
, TGSI_SEMANTIC_COLOR
, 0, TGSI_INTERPOLATE_PERSPECTIVE
);
1025 case D3DTA_SPECULAR
:
1026 reg
= ureg_DECL_fs_input(ps
->ureg
, TGSI_SEMANTIC_COLOR
, 1, TGSI_INTERPOLATE_PERSPECTIVE
);
1035 reg
= ureg_DECL_constant(ps
->ureg
, 20);
1039 reg
= ureg_src_undef();
1042 if (ta
& D3DTA_COMPLEMENT
) {
1043 struct ureg_dst dst
= ps
->r
[ps
->stage
.num_regs
++];
1044 ureg_SUB(ps
->ureg
, dst
, ureg_imm1f(ps
->ureg
, 1.0f
), reg
);
1045 reg
= ureg_src(dst
);
1047 if (ta
& D3DTA_ALPHAREPLICATE
)
1052 static struct ureg_dst
1053 ps_get_ts_dst(struct ps_build_ctx
*ps
, unsigned ta
)
1055 assert(!(ta
& (D3DTA_COMPLEMENT
| D3DTA_ALPHAREPLICATE
)));
1057 switch (ta
& D3DTA_SELECTMASK
) {
1064 return ureg_dst_undef();
1068 static uint8_t ps_d3dtop_args_mask(D3DTEXTUREOP top
)
1071 case D3DTOP_DISABLE
:
1073 case D3DTOP_SELECTARG1
:
1074 case D3DTOP_PREMODULATE
:
1076 case D3DTOP_SELECTARG2
:
1078 case D3DTOP_MULTIPLYADD
:
1086 static inline boolean
1087 is_MOV_no_op(struct ureg_dst dst
, struct ureg_src src
)
1089 return !dst
.WriteMask
||
1090 (dst
.File
== src
.File
&&
1091 dst
.Index
== src
.Index
&&
1097 (!(dst
.WriteMask
& TGSI_WRITEMASK_X
) || (src
.SwizzleX
== TGSI_SWIZZLE_X
)) &&
1098 (!(dst
.WriteMask
& TGSI_WRITEMASK_Y
) || (src
.SwizzleY
== TGSI_SWIZZLE_Y
)) &&
1099 (!(dst
.WriteMask
& TGSI_WRITEMASK_Z
) || (src
.SwizzleZ
== TGSI_SWIZZLE_Z
)) &&
1100 (!(dst
.WriteMask
& TGSI_WRITEMASK_W
) || (src
.SwizzleW
== TGSI_SWIZZLE_W
)));
1105 ps_do_ts_op(struct ps_build_ctx
*ps
, unsigned top
, struct ureg_dst dst
, struct ureg_src
*arg
)
1107 struct ureg_program
*ureg
= ps
->ureg
;
1108 struct ureg_dst tmp
= ps
->r
[ps
->stage
.num_regs
];
1109 struct ureg_dst tmp2
= ps
->r
[ps
->stage
.num_regs
+1];
1110 struct ureg_dst tmp_x
= ureg_writemask(tmp
, TGSI_WRITEMASK_X
);
1112 tmp
.WriteMask
= dst
.WriteMask
;
1114 if (top
!= D3DTOP_SELECTARG1
&& top
!= D3DTOP_SELECTARG2
&&
1115 top
!= D3DTOP_MODULATE
&& top
!= D3DTOP_PREMODULATE
&&
1116 top
!= D3DTOP_BLENDDIFFUSEALPHA
&& top
!= D3DTOP_BLENDTEXTUREALPHA
&&
1117 top
!= D3DTOP_BLENDFACTORALPHA
&& top
!= D3DTOP_BLENDCURRENTALPHA
&&
1118 top
!= D3DTOP_BUMPENVMAP
&& top
!= D3DTOP_BUMPENVMAPLUMINANCE
&&
1120 dst
= ureg_saturate(dst
);
1123 case D3DTOP_SELECTARG1
:
1124 if (!is_MOV_no_op(dst
, arg
[1]))
1125 ureg_MOV(ureg
, dst
, arg
[1]);
1127 case D3DTOP_SELECTARG2
:
1128 if (!is_MOV_no_op(dst
, arg
[2]))
1129 ureg_MOV(ureg
, dst
, arg
[2]);
1131 case D3DTOP_MODULATE
:
1132 ureg_MUL(ureg
, dst
, arg
[1], arg
[2]);
1134 case D3DTOP_MODULATE2X
:
1135 ureg_MUL(ureg
, tmp
, arg
[1], arg
[2]);
1136 ureg_ADD(ureg
, dst
, ureg_src(tmp
), ureg_src(tmp
));
1138 case D3DTOP_MODULATE4X
:
1139 ureg_MUL(ureg
, tmp
, arg
[1], arg
[2]);
1140 ureg_MUL(ureg
, dst
, ureg_src(tmp
), ureg_imm1f(ureg
, 4.0f
));
1143 ureg_ADD(ureg
, dst
, arg
[1], arg
[2]);
1145 case D3DTOP_ADDSIGNED
:
1146 ureg_ADD(ureg
, tmp
, arg
[1], arg
[2]);
1147 ureg_SUB(ureg
, dst
, ureg_src(tmp
), ureg_imm1f(ureg
, 0.5f
));
1149 case D3DTOP_ADDSIGNED2X
:
1150 ureg_ADD(ureg
, tmp
, arg
[1], arg
[2]);
1151 ureg_MAD(ureg
, dst
, ureg_src(tmp
), ureg_imm1f(ureg
, 2.0f
), ureg_imm1f(ureg
, -1.0f
));
1153 case D3DTOP_SUBTRACT
:
1154 ureg_SUB(ureg
, dst
, arg
[1], arg
[2]);
1156 case D3DTOP_ADDSMOOTH
:
1157 ureg_SUB(ureg
, tmp
, ureg_imm1f(ureg
, 1.0f
), arg
[1]);
1158 ureg_MAD(ureg
, dst
, ureg_src(tmp
), arg
[2], arg
[1]);
1160 case D3DTOP_BLENDDIFFUSEALPHA
:
1161 ureg_LRP(ureg
, dst
, _WWWW(ps
->vC
[0]), arg
[1], arg
[2]);
1163 case D3DTOP_BLENDTEXTUREALPHA
:
1164 /* XXX: alpha taken from previous stage, texture or result ? */
1165 ureg_LRP(ureg
, dst
, _W(ps
->rTex
), arg
[1], arg
[2]);
1167 case D3DTOP_BLENDFACTORALPHA
:
1168 ureg_LRP(ureg
, dst
, _WWWW(_CONST(20)), arg
[1], arg
[2]);
1170 case D3DTOP_BLENDTEXTUREALPHAPM
:
1171 ureg_SUB(ureg
, tmp_x
, ureg_imm1f(ureg
, 1.0f
), _W(ps
->rTex
));
1172 ureg_MAD(ureg
, dst
, arg
[2], _X(tmp
), arg
[1]);
1174 case D3DTOP_BLENDCURRENTALPHA
:
1175 ureg_LRP(ureg
, dst
, _WWWW(ps
->rCurSrc
), arg
[1], arg
[2]);
1177 case D3DTOP_PREMODULATE
:
1178 ureg_MOV(ureg
, dst
, arg
[1]);
1179 ps
->stage
.index_pre_mod
= ps
->stage
.index
+ 1;
1181 case D3DTOP_MODULATEALPHA_ADDCOLOR
:
1182 ureg_MAD(ureg
, dst
, _WWWW(arg
[1]), arg
[2], arg
[1]);
1184 case D3DTOP_MODULATECOLOR_ADDALPHA
:
1185 ureg_MAD(ureg
, dst
, arg
[1], arg
[2], _WWWW(arg
[1]));
1187 case D3DTOP_MODULATEINVALPHA_ADDCOLOR
:
1188 ureg_SUB(ureg
, tmp_x
, ureg_imm1f(ureg
, 1.0f
), _WWWW(arg
[1]));
1189 ureg_MAD(ureg
, dst
, _X(tmp
), arg
[2], arg
[1]);
1191 case D3DTOP_MODULATEINVCOLOR_ADDALPHA
:
1192 ureg_SUB(ureg
, tmp
, ureg_imm1f(ureg
, 1.0f
), arg
[1]);
1193 ureg_MAD(ureg
, dst
, ureg_src(tmp
), arg
[2], _WWWW(arg
[1]));
1195 case D3DTOP_BUMPENVMAP
:
1197 case D3DTOP_BUMPENVMAPLUMINANCE
:
1199 case D3DTOP_DOTPRODUCT3
:
1200 ureg_SUB(ureg
, tmp
, arg
[1], ureg_imm4f(ureg
,0.5,0.5,0.5,0.5));
1201 ureg_SUB(ureg
, tmp2
, arg
[2] , ureg_imm4f(ureg
,0.5,0.5,0.5,0.5));
1202 ureg_DP3(ureg
, tmp
, ureg_src(tmp
), ureg_src(tmp2
));
1203 ureg_MUL(ureg
, ureg_saturate(dst
), ureg_src(tmp
), ureg_imm4f(ureg
,4.0,4.0,4.0,4.0));
1205 case D3DTOP_MULTIPLYADD
:
1206 ureg_MAD(ureg
, dst
, arg
[1], arg
[2], arg
[0]);
1209 ureg_LRP(ureg
, dst
, arg
[0], arg
[1], arg
[2]);
1211 case D3DTOP_DISABLE
:
1215 assert(!"invalid D3DTOP");
1221 nine_ff_build_ps(struct NineDevice9
*device
, struct nine_ff_ps_key
*key
)
1223 struct ps_build_ctx ps
;
1224 struct ureg_program
*ureg
= ureg_create(TGSI_PROCESSOR_FRAGMENT
);
1225 struct ureg_dst oCol
;
1227 const unsigned texcoord_sn
= get_texcoord_sn(device
->screen
);
1229 memset(&ps
, 0, sizeof(ps
));
1231 ps
.stage
.index_pre_mod
= -1;
1233 ps
.vC
[0] = ureg_DECL_fs_input(ureg
, TGSI_SEMANTIC_COLOR
, 0, TGSI_INTERPOLATE_PERSPECTIVE
);
1235 /* Declare all TEMPs we might need, serious drivers have a register allocator. */
1236 for (i
= 0; i
< Elements(ps
.r
); ++i
)
1237 ps
.r
[i
] = ureg_DECL_local_temporary(ureg
);
1241 ps
.rCurSrc
= ureg_src(ps
.rCur
);
1242 ps
.rTmpSrc
= ureg_src(ps
.rTmp
);
1243 ps
.rTexSrc
= ureg_src(ps
.rTex
);
1245 for (s
= 0; s
< 8; ++s
) {
1246 ps
.s
[s
] = ureg_src_undef();
1248 if (key
->ts
[s
].colorop
!= D3DTOP_DISABLE
) {
1249 if (key
->ts
[s
].colorarg0
== D3DTA_SPECULAR
||
1250 key
->ts
[s
].colorarg1
== D3DTA_SPECULAR
||
1251 key
->ts
[s
].colorarg2
== D3DTA_SPECULAR
)
1252 ps
.vC
[1] = ureg_DECL_fs_input(ureg
, TGSI_SEMANTIC_COLOR
, 1, TGSI_INTERPOLATE_PERSPECTIVE
);
1254 if (key
->ts
[s
].colorarg0
== D3DTA_TEXTURE
||
1255 key
->ts
[s
].colorarg1
== D3DTA_TEXTURE
||
1256 key
->ts
[s
].colorarg2
== D3DTA_TEXTURE
) {
1257 ps
.s
[s
] = ureg_DECL_sampler(ureg
, s
);
1258 ps
.vT
[s
] = ureg_DECL_fs_input(ureg
, texcoord_sn
, s
, TGSI_INTERPOLATE_PERSPECTIVE
);
1260 if (s
&& (key
->ts
[s
- 1].colorop
== D3DTOP_PREMODULATE
||
1261 key
->ts
[s
- 1].alphaop
== D3DTOP_PREMODULATE
))
1262 ps
.s
[s
] = ureg_DECL_sampler(ureg
, s
);
1265 if (key
->ts
[s
].alphaop
!= D3DTOP_DISABLE
) {
1266 if (key
->ts
[s
].alphaarg0
== D3DTA_SPECULAR
||
1267 key
->ts
[s
].alphaarg1
== D3DTA_SPECULAR
||
1268 key
->ts
[s
].alphaarg2
== D3DTA_SPECULAR
)
1269 ps
.vC
[1] = ureg_DECL_fs_input(ureg
, TGSI_SEMANTIC_COLOR
, 1, TGSI_INTERPOLATE_PERSPECTIVE
);
1271 if (key
->ts
[s
].alphaarg0
== D3DTA_TEXTURE
||
1272 key
->ts
[s
].alphaarg1
== D3DTA_TEXTURE
||
1273 key
->ts
[s
].alphaarg2
== D3DTA_TEXTURE
) {
1274 ps
.s
[s
] = ureg_DECL_sampler(ureg
, s
);
1275 ps
.vT
[s
] = ureg_DECL_fs_input(ureg
, texcoord_sn
, s
, TGSI_INTERPOLATE_PERSPECTIVE
);
1280 ps
.vC
[1] = ureg_DECL_fs_input(ureg
, TGSI_SEMANTIC_COLOR
, 1, TGSI_INTERPOLATE_PERSPECTIVE
);
1282 oCol
= ureg_DECL_output(ureg
, TGSI_SEMANTIC_COLOR
, 0);
1284 if (key
->ts
[0].colorop
== D3DTOP_DISABLE
&&
1285 key
->ts
[0].alphaop
== D3DTOP_DISABLE
)
1286 ureg_MOV(ureg
, ps
.rCur
, ps
.vC
[0]);
1287 /* Or is it undefined then ? */
1291 for (s
= 0; s
< 8; ++s
) {
1292 unsigned colorarg
[3];
1293 unsigned alphaarg
[3];
1294 const uint8_t used_c
= ps_d3dtop_args_mask(key
->ts
[s
].colorop
);
1295 const uint8_t used_a
= ps_d3dtop_args_mask(key
->ts
[s
].alphaop
);
1296 struct ureg_dst dst
;
1297 struct ureg_src arg
[3];
1299 if (key
->ts
[s
].colorop
== D3DTOP_DISABLE
&&
1300 key
->ts
[s
].alphaop
== D3DTOP_DISABLE
)
1303 ps
.stage
.num_regs
= 3;
1305 DBG("STAGE[%u]: colorop=%s alphaop=%s\n", s
,
1306 nine_D3DTOP_to_str(key
->ts
[s
].colorop
),
1307 nine_D3DTOP_to_str(key
->ts
[s
].alphaop
));
1309 if (!ureg_src_is_undef(ps
.s
[s
])) {
1311 switch (key
->ts
[s
].textarget
) {
1312 case 0: target
= TGSI_TEXTURE_1D
; break;
1313 case 1: target
= TGSI_TEXTURE_2D
; break;
1314 case 2: target
= TGSI_TEXTURE_3D
; break;
1315 case 3: target
= TGSI_TEXTURE_CUBE
; break;
1316 /* this is a 2 bit bitfield, do I really need a default case ? */
1319 /* sample the texture */
1320 if (key
->ts
[s
].colorop
== D3DTOP_BUMPENVMAP
||
1321 key
->ts
[s
].colorop
== D3DTOP_BUMPENVMAPLUMINANCE
) {
1323 if (key
->projected
& (3 << (s
*2))) {
1324 unsigned dim
= 1 + ((key
->projected
>> (2 * s
)) & 3);
1326 ureg_TXP(ureg
, ps
.rTex
, target
, ps
.vT
[s
], ps
.s
[s
]);
1328 ureg_RCP(ureg
, ureg_writemask(ps
.rTmp
, TGSI_WRITEMASK_X
), ureg_scalar(ps
.vT
[s
], dim
-1));
1329 ureg_MUL(ureg
, ps
.rTmp
, _XXXX(ps
.rTmpSrc
), ps
.vT
[s
]);
1330 ureg_TEX(ureg
, ps
.rTex
, target
, ps
.rTmpSrc
, ps
.s
[s
]);
1333 ureg_TEX(ureg
, ps
.rTex
, target
, ps
.vT
[s
], ps
.s
[s
]);
1338 (key
->ts
[0].resultarg
!= 0 /* not current */ ||
1339 key
->ts
[0].colorop
== D3DTOP_DISABLE
||
1340 key
->ts
[0].alphaop
== D3DTOP_DISABLE
||
1341 key
->ts
[0].colorop
== D3DTOP_BLENDCURRENTALPHA
||
1342 key
->ts
[0].alphaop
== D3DTOP_BLENDCURRENTALPHA
||
1343 key
->ts
[0].colorarg0
== D3DTA_CURRENT
||
1344 key
->ts
[0].colorarg1
== D3DTA_CURRENT
||
1345 key
->ts
[0].colorarg2
== D3DTA_CURRENT
||
1346 key
->ts
[0].alphaarg0
== D3DTA_CURRENT
||
1347 key
->ts
[0].alphaarg1
== D3DTA_CURRENT
||
1348 key
->ts
[0].alphaarg2
== D3DTA_CURRENT
)
1350 /* Initialize D3DTA_CURRENT.
1351 * (Yes we can do this before the loop but not until
1352 * NVE4 has an instruction scheduling pass.)
1354 ureg_MOV(ureg
, ps
.rCur
, ps
.vC
[0]);
1357 dst
= ps_get_ts_dst(&ps
, key
->ts
[s
].resultarg
? D3DTA_TEMP
: D3DTA_CURRENT
);
1359 if (ps
.stage
.index_pre_mod
== ps
.stage
.index
) {
1360 ps
.rMod
= ps
.r
[ps
.stage
.num_regs
++];
1361 ureg_MUL(ureg
, ps
.rMod
, ps
.rCurSrc
, ps
.rTexSrc
);
1364 colorarg
[0] = (key
->ts
[s
].colorarg0
| ((key
->colorarg_b4
[0] >> s
) << 4) | ((key
->colorarg_b5
[0] >> s
) << 5)) & 0x3f;
1365 colorarg
[1] = (key
->ts
[s
].colorarg1
| ((key
->colorarg_b4
[1] >> s
) << 4) | ((key
->colorarg_b5
[1] >> s
) << 5)) & 0x3f;
1366 colorarg
[2] = (key
->ts
[s
].colorarg2
| ((key
->colorarg_b4
[2] >> s
) << 4) | ((key
->colorarg_b5
[2] >> s
) << 5)) & 0x3f;
1367 alphaarg
[0] = (key
->ts
[s
].alphaarg0
| ((key
->alphaarg_b4
[0] >> s
) << 4)) & 0x1f;
1368 alphaarg
[1] = (key
->ts
[s
].alphaarg1
| ((key
->alphaarg_b4
[1] >> s
) << 4)) & 0x1f;
1369 alphaarg
[2] = (key
->ts
[s
].alphaarg2
| ((key
->alphaarg_b4
[2] >> s
) << 4)) & 0x1f;
1371 if (key
->ts
[s
].colorop
!= key
->ts
[s
].alphaop
||
1372 colorarg
[0] != alphaarg
[0] ||
1373 colorarg
[1] != alphaarg
[1] ||
1374 colorarg
[2] != alphaarg
[2])
1375 dst
.WriteMask
= TGSI_WRITEMASK_XYZ
;
1377 /* Special DOTPRODUCT behaviour (see wine tests) */
1378 if (key
->ts
[s
].colorop
== D3DTOP_DOTPRODUCT3
)
1379 dst
.WriteMask
= TGSI_WRITEMASK_XYZW
;
1381 if (used_c
& 0x1) arg
[0] = ps_get_ts_arg(&ps
, colorarg
[0]);
1382 if (used_c
& 0x2) arg
[1] = ps_get_ts_arg(&ps
, colorarg
[1]);
1383 if (used_c
& 0x4) arg
[2] = ps_get_ts_arg(&ps
, colorarg
[2]);
1384 ps_do_ts_op(&ps
, key
->ts
[s
].colorop
, dst
, arg
);
1386 if (dst
.WriteMask
!= TGSI_WRITEMASK_XYZW
) {
1387 dst
.WriteMask
= TGSI_WRITEMASK_W
;
1389 if (used_a
& 0x1) arg
[0] = ps_get_ts_arg(&ps
, alphaarg
[0]);
1390 if (used_a
& 0x2) arg
[1] = ps_get_ts_arg(&ps
, alphaarg
[1]);
1391 if (used_a
& 0x4) arg
[2] = ps_get_ts_arg(&ps
, alphaarg
[2]);
1392 ps_do_ts_op(&ps
, key
->ts
[s
].alphaop
, dst
, arg
);
1397 ureg_ADD(ureg
, ps
.rCur
, ps
.rCurSrc
, ps
.vC
[1]);
1401 if (key
->fog_mode
) {
1402 struct ureg_src vPos
;
1403 if (device
->screen
->get_param(device
->screen
,
1404 PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL
)) {
1405 vPos
= ureg_DECL_system_value(ureg
, TGSI_SEMANTIC_POSITION
, 0);
1407 vPos
= ureg_DECL_fs_input(ureg
, TGSI_SEMANTIC_POSITION
, 0,
1408 TGSI_INTERPOLATE_LINEAR
);
1411 struct ureg_dst rFog
= ureg_writemask(ps
.rTmp
, TGSI_WRITEMASK_X
);
1412 if (key
->fog_mode
== D3DFOG_EXP
) {
1413 ureg_MUL(ureg
, rFog
, _ZZZZ(vPos
), _ZZZZ(_CONST(22)));
1414 ureg_MUL(ureg
, rFog
, _X(rFog
), ureg_imm1f(ureg
, -1.442695f
));
1415 ureg_EX2(ureg
, rFog
, _X(rFog
));
1417 if (key
->fog_mode
== D3DFOG_EXP2
) {
1418 ureg_MUL(ureg
, rFog
, _ZZZZ(vPos
), _ZZZZ(_CONST(22)));
1419 ureg_MUL(ureg
, rFog
, _X(rFog
), _X(rFog
));
1420 ureg_MUL(ureg
, rFog
, _X(rFog
), ureg_imm1f(ureg
, -1.442695f
));
1421 ureg_EX2(ureg
, rFog
, _X(rFog
));
1423 if (key
->fog_mode
== D3DFOG_LINEAR
) {
1424 ureg_SUB(ureg
, rFog
, _XXXX(_CONST(22)), _ZZZZ(vPos
));
1425 ureg_MUL(ureg
, ureg_saturate(rFog
), _X(rFog
), _YYYY(_CONST(22)));
1427 ureg_LRP(ureg
, ureg_writemask(oCol
, TGSI_WRITEMASK_XYZ
), _X(rFog
), ps
.rCurSrc
, _CONST(21));
1428 ureg_MOV(ureg
, ureg_writemask(oCol
, TGSI_WRITEMASK_W
), ps
.rCurSrc
);
1431 struct ureg_src vFog
= ureg_DECL_fs_input(ureg
, TGSI_SEMANTIC_FOG
, 0, TGSI_INTERPOLATE_PERSPECTIVE
);
1432 ureg_LRP(ureg
, ureg_writemask(oCol
, TGSI_WRITEMASK_XYZ
), _XXXX(vFog
), ps
.rCurSrc
, _CONST(21));
1433 ureg_MOV(ureg
, ureg_writemask(oCol
, TGSI_WRITEMASK_W
), ps
.rCurSrc
);
1435 ureg_MOV(ureg
, oCol
, ps
.rCurSrc
);
1439 nine_ureg_tgsi_dump(ureg
, FALSE
);
1440 return ureg_create_shader_and_destroy(ureg
, device
->pipe
);
1443 static struct NineVertexShader9
*
1444 nine_ff_get_vs(struct NineDevice9
*device
)
1446 const struct nine_state
*state
= &device
->state
;
1447 struct NineVertexShader9
*vs
;
1448 enum pipe_error err
;
1449 struct vs_build_ctx bld
;
1450 struct nine_ff_vs_key key
;
1452 char input_texture_coord
[8];
1454 assert(sizeof(key
) <= sizeof(key
.value32
));
1456 memset(&key
, 0, sizeof(key
));
1457 memset(&bld
, 0, sizeof(bld
));
1458 memset(&input_texture_coord
, 0, sizeof(input_texture_coord
));
1462 /* FIXME: this shouldn't be NULL, but it is on init */
1464 key
.color0in_one
= 1;
1465 key
.color1in_one
= 1;
1466 for (i
= 0; i
< state
->vdecl
->nelems
; i
++) {
1467 uint16_t usage
= state
->vdecl
->usage_map
[i
];
1468 if (usage
== NINE_DECLUSAGE_POSITIONT
)
1470 else if (usage
== NINE_DECLUSAGE_i(COLOR
, 0))
1471 key
.color0in_one
= 0;
1472 else if (usage
== NINE_DECLUSAGE_i(COLOR
, 1))
1473 key
.color1in_one
= 0;
1474 else if (usage
== NINE_DECLUSAGE_PSIZE
)
1475 key
.vertexpointsize
= 1;
1476 else if (usage
% NINE_DECLUSAGE_COUNT
== NINE_DECLUSAGE_TEXCOORD
) {
1477 s
= usage
/ NINE_DECLUSAGE_COUNT
;
1479 input_texture_coord
[s
] = nine_decltype_get_dim(state
->vdecl
->decls
[i
].Type
);
1481 DBG("FF given texture coordinate >= 8. Ignoring\n");
1482 } else if (usage
< NINE_DECLUSAGE_NONE
)
1483 key
.passthrough
|= 1 << usage
;
1486 /* ff vs + ps 3.0: some elements are passed to the ps (wine test).
1487 * We do restrict to indices 0 */
1488 key
.passthrough
&= ~((1 << NINE_DECLUSAGE_POSITION
) | (1 << NINE_DECLUSAGE_PSIZE
) |
1489 (1 << NINE_DECLUSAGE_TEXCOORD
) | (1 << NINE_DECLUSAGE_POSITIONT
) |
1490 (1 << NINE_DECLUSAGE_TESSFACTOR
) | (1 << NINE_DECLUSAGE_SAMPLE
));
1491 if (!key
.vertexpointsize
)
1492 key
.pointscale
= !!state
->rs
[D3DRS_POINTSCALEENABLE
];
1494 key
.lighting
= !!state
->rs
[D3DRS_LIGHTING
] && state
->ff
.num_lights_active
;
1495 key
.darkness
= !!state
->rs
[D3DRS_LIGHTING
] && !state
->ff
.num_lights_active
;
1496 if (key
.position_t
) {
1497 key
.darkness
= 0; /* |= key.lighting; */ /* XXX ? */
1500 if ((key
.lighting
| key
.darkness
) && state
->rs
[D3DRS_COLORVERTEX
]) {
1501 key
.mtl_diffuse
= state
->rs
[D3DRS_DIFFUSEMATERIALSOURCE
];
1502 key
.mtl_ambient
= state
->rs
[D3DRS_AMBIENTMATERIALSOURCE
];
1503 key
.mtl_specular
= state
->rs
[D3DRS_SPECULARMATERIALSOURCE
];
1504 key
.mtl_emissive
= state
->rs
[D3DRS_EMISSIVEMATERIALSOURCE
];
1506 key
.fog
= !!state
->rs
[D3DRS_FOGENABLE
];
1507 key
.fog_mode
= state
->rs
[D3DRS_FOGENABLE
] ? state
->rs
[D3DRS_FOGVERTEXMODE
] : 0;
1509 key
.fog_range
= !key
.position_t
&& state
->rs
[D3DRS_RANGEFOGENABLE
];
1511 key
.localviewer
= !!state
->rs
[D3DRS_LOCALVIEWER
];
1512 key
.specular_enable
= !!state
->rs
[D3DRS_SPECULARENABLE
];
1514 if (state
->rs
[D3DRS_VERTEXBLEND
] != D3DVBF_DISABLE
) {
1515 key
.vertexblend_indexed
= !!state
->rs
[D3DRS_INDEXEDVERTEXBLENDENABLE
];
1517 switch (state
->rs
[D3DRS_VERTEXBLEND
]) {
1518 case D3DVBF_0WEIGHTS
: key
.vertexblend
= key
.vertexblend_indexed
; break;
1519 case D3DVBF_1WEIGHTS
: key
.vertexblend
= 2; break;
1520 case D3DVBF_2WEIGHTS
: key
.vertexblend
= 3; break;
1521 case D3DVBF_3WEIGHTS
: key
.vertexblend
= 4; break;
1522 case D3DVBF_TWEENING
: key
.vertextween
= 1; break;
1524 assert(!"invalid D3DVBF");
1529 for (s
= 0; s
< 8; ++s
) {
1530 unsigned gen
= (state
->ff
.tex_stage
[s
][D3DTSS_TEXCOORDINDEX
] >> 16) + 1;
1533 if (key
.position_t
&& gen
> NINED3DTSS_TCI_PASSTHRU
)
1534 gen
= NINED3DTSS_TCI_PASSTHRU
;
1536 if (!input_texture_coord
[s
] && gen
== NINED3DTSS_TCI_PASSTHRU
)
1537 gen
= NINED3DTSS_TCI_DISABLE
;
1539 key
.tc_gen
|= gen
<< (s
* 3);
1540 key
.tc_idx
|= (state
->ff
.tex_stage
[s
][D3DTSS_TEXCOORDINDEX
] & 7) << (s
* 3);
1541 key
.tc_dim_input
|= ((input_texture_coord
[s
]-1) & 0x3) << (s
* 2);
1543 dim
= state
->ff
.tex_stage
[s
][D3DTSS_TEXTURETRANSFORMFLAGS
] & 0x7;
1545 dim
= input_texture_coord
[s
];
1546 if (dim
== 1) /* NV behaviour */
1548 key
.tc_dim_output
|= dim
<< (s
* 3);
1551 vs
= util_hash_table_get(device
->ff
.ht_vs
, &key
);
1554 NineVertexShader9_new(device
, &vs
, NULL
, nine_ff_build_vs(device
, &bld
));
1556 nine_ff_prune_vs(device
);
1560 memcpy(&vs
->ff_key
, &key
, sizeof(vs
->ff_key
));
1562 err
= util_hash_table_set(device
->ff
.ht_vs
, &vs
->ff_key
, vs
);
1564 assert(err
== PIPE_OK
);
1565 device
->ff
.num_vs
++;
1566 NineUnknown_ConvertRefToBind(NineUnknown(vs
));
1568 vs
->num_inputs
= bld
.num_inputs
;
1569 for (n
= 0; n
< bld
.num_inputs
; ++n
)
1570 vs
->input_map
[n
].ndecl
= bld
.input
[n
];
1572 vs
->position_t
= key
.position_t
;
1573 vs
->point_size
= key
.vertexpointsize
| key
.pointscale
;
1578 static struct NinePixelShader9
*
1579 nine_ff_get_ps(struct NineDevice9
*device
)
1581 struct nine_state
*state
= &device
->state
;
1582 struct NinePixelShader9
*ps
;
1583 enum pipe_error err
;
1584 struct nine_ff_ps_key key
;
1586 uint8_t sampler_mask
= 0;
1588 assert(sizeof(key
) <= sizeof(key
.value32
));
1590 memset(&key
, 0, sizeof(key
));
1591 for (s
= 0; s
< 8; ++s
) {
1592 key
.ts
[s
].colorop
= state
->ff
.tex_stage
[s
][D3DTSS_COLOROP
];
1593 key
.ts
[s
].alphaop
= state
->ff
.tex_stage
[s
][D3DTSS_ALPHAOP
];
1594 /* MSDN says D3DTOP_DISABLE disables this and all subsequent stages. */
1595 /* ALPHAOP cannot be disabled if COLOROP is enabled. */
1596 if (key
.ts
[s
].colorop
== D3DTOP_DISABLE
) {
1597 key
.ts
[s
].alphaop
= D3DTOP_DISABLE
; /* DISABLE == 1, avoid degenerate keys */
1601 if (!state
->texture
[s
] &&
1602 state
->ff
.tex_stage
[s
][D3DTSS_COLORARG1
] == D3DTA_TEXTURE
) {
1603 /* This should also disable the stage. */
1604 key
.ts
[s
].colorop
= key
.ts
[s
].alphaop
= D3DTOP_DISABLE
;
1608 if (state
->ff
.tex_stage
[s
][D3DTSS_COLORARG1
] == D3DTA_TEXTURE
)
1609 sampler_mask
|= (1 << s
);
1611 if (key
.ts
[s
].colorop
!= D3DTOP_DISABLE
) {
1612 uint8_t used_c
= ps_d3dtop_args_mask(key
.ts
[s
].colorop
);
1613 if (used_c
& 0x1) key
.ts
[s
].colorarg0
= state
->ff
.tex_stage
[s
][D3DTSS_COLORARG0
];
1614 if (used_c
& 0x2) key
.ts
[s
].colorarg1
= state
->ff
.tex_stage
[s
][D3DTSS_COLORARG1
];
1615 if (used_c
& 0x4) key
.ts
[s
].colorarg2
= state
->ff
.tex_stage
[s
][D3DTSS_COLORARG2
];
1616 if (used_c
& 0x1) key
.colorarg_b4
[0] |= (state
->ff
.tex_stage
[s
][D3DTSS_COLORARG0
] >> 4) << s
;
1617 if (used_c
& 0x1) key
.colorarg_b5
[0] |= (state
->ff
.tex_stage
[s
][D3DTSS_COLORARG0
] >> 5) << s
;
1618 if (used_c
& 0x2) key
.colorarg_b4
[1] |= (state
->ff
.tex_stage
[s
][D3DTSS_COLORARG1
] >> 4) << s
;
1619 if (used_c
& 0x2) key
.colorarg_b5
[1] |= (state
->ff
.tex_stage
[s
][D3DTSS_COLORARG1
] >> 5) << s
;
1620 if (used_c
& 0x4) key
.colorarg_b4
[2] |= (state
->ff
.tex_stage
[s
][D3DTSS_COLORARG2
] >> 4) << s
;
1621 if (used_c
& 0x4) key
.colorarg_b5
[2] |= (state
->ff
.tex_stage
[s
][D3DTSS_COLORARG2
] >> 5) << s
;
1623 if (key
.ts
[s
].alphaop
!= D3DTOP_DISABLE
) {
1624 uint8_t used_a
= ps_d3dtop_args_mask(key
.ts
[s
].alphaop
);
1625 if (used_a
& 0x1) key
.ts
[s
].alphaarg0
= state
->ff
.tex_stage
[s
][D3DTSS_ALPHAARG0
];
1626 if (used_a
& 0x2) key
.ts
[s
].alphaarg1
= state
->ff
.tex_stage
[s
][D3DTSS_ALPHAARG1
];
1627 if (used_a
& 0x4) key
.ts
[s
].alphaarg2
= state
->ff
.tex_stage
[s
][D3DTSS_ALPHAARG2
];
1628 if (used_a
& 0x1) key
.alphaarg_b4
[0] |= (state
->ff
.tex_stage
[s
][D3DTSS_ALPHAARG0
] >> 4) << s
;
1629 if (used_a
& 0x2) key
.alphaarg_b4
[1] |= (state
->ff
.tex_stage
[s
][D3DTSS_ALPHAARG1
] >> 4) << s
;
1630 if (used_a
& 0x4) key
.alphaarg_b4
[2] |= (state
->ff
.tex_stage
[s
][D3DTSS_ALPHAARG2
] >> 4) << s
;
1632 key
.ts
[s
].resultarg
= state
->ff
.tex_stage
[s
][D3DTSS_RESULTARG
] == D3DTA_TEMP
;
1634 if (state
->texture
[s
]) {
1635 switch (state
->texture
[s
]->base
.type
) {
1636 case D3DRTYPE_TEXTURE
: key
.ts
[s
].textarget
= 1; break;
1637 case D3DRTYPE_VOLUMETEXTURE
: key
.ts
[s
].textarget
= 2; break;
1638 case D3DRTYPE_CUBETEXTURE
: key
.ts
[s
].textarget
= 3; break;
1640 assert(!"unexpected texture type");
1644 key
.ts
[s
].textarget
= 1;
1648 key
.projected
= nine_ff_get_projected_key(state
);
1651 key
.ts
[s
].colorop
= key
.ts
[s
].alphaop
= D3DTOP_DISABLE
;
1652 if (state
->rs
[D3DRS_FOGENABLE
])
1653 key
.fog_mode
= state
->rs
[D3DRS_FOGTABLEMODE
];
1654 key
.fog
= !!state
->rs
[D3DRS_FOGENABLE
];
1656 ps
= util_hash_table_get(device
->ff
.ht_ps
, &key
);
1659 NinePixelShader9_new(device
, &ps
, NULL
, nine_ff_build_ps(device
, &key
));
1661 nine_ff_prune_ps(device
);
1663 memcpy(&ps
->ff_key
, &key
, sizeof(ps
->ff_key
));
1665 err
= util_hash_table_set(device
->ff
.ht_ps
, &ps
->ff_key
, ps
);
1667 assert(err
== PIPE_OK
);
1668 device
->ff
.num_ps
++;
1669 NineUnknown_ConvertRefToBind(NineUnknown(ps
));
1672 ps
->sampler_mask
= sampler_mask
;
1677 #define GET_D3DTS(n) nine_state_access_transform(state, D3DTS_##n, FALSE)
1678 #define IS_D3DTS_DIRTY(s,n) ((s)->ff.changed.transform[(D3DTS_##n) / 32] & (1 << ((D3DTS_##n) % 32)))
1680 nine_ff_load_vs_transforms(struct NineDevice9
*device
)
1682 struct nine_state
*state
= &device
->state
;
1684 D3DMATRIX
*M
= (D3DMATRIX
*)device
->ff
.vs_const
;
1687 /* TODO: make this nicer, and only upload the ones we need */
1688 /* TODO: use ff.vs_const as storage of W, V, P matrices */
1690 if (IS_D3DTS_DIRTY(state
, WORLD
) ||
1691 IS_D3DTS_DIRTY(state
, VIEW
) ||
1692 IS_D3DTS_DIRTY(state
, PROJECTION
)) {
1693 /* WVP, WV matrices */
1694 nine_d3d_matrix_matrix_mul(&M
[1], GET_D3DTS(WORLD
), GET_D3DTS(VIEW
));
1695 nine_d3d_matrix_matrix_mul(&M
[0], &M
[1], GET_D3DTS(PROJECTION
));
1697 /* normal matrix == transpose(inverse(WV)) */
1698 nine_d3d_matrix_inverse_3x3(&T
, &M
[1]);
1699 nine_d3d_matrix_transpose(&M
[4], &T
);
1702 nine_d3d_matrix_matrix_mul(&M
[2], GET_D3DTS(VIEW
), GET_D3DTS(PROJECTION
));
1704 /* V and W matrix */
1705 M
[3] = *GET_D3DTS(VIEW
);
1706 M
[56] = *GET_D3DTS(WORLD
);
1709 if (state
->rs
[D3DRS_VERTEXBLEND
] != D3DVBF_DISABLE
) {
1710 /* load other world matrices */
1711 for (i
= 1; i
<= 7; ++i
)
1712 M
[56 + i
] = *GET_D3DTS(WORLDMATRIX(i
));
1715 device
->ff
.vs_const
[30 * 4] = asfloat(state
->rs
[D3DRS_TWEENFACTOR
]);
1719 nine_ff_load_lights(struct NineDevice9
*device
)
1721 struct nine_state
*state
= &device
->state
;
1722 struct fvec4
*dst
= (struct fvec4
*)device
->ff
.vs_const
;
1725 if (state
->changed
.group
& NINE_STATE_FF_MATERIAL
) {
1726 const D3DMATERIAL9
*mtl
= &state
->ff
.material
;
1728 memcpy(&dst
[20], &mtl
->Diffuse
, 4 * sizeof(float));
1729 memcpy(&dst
[21], &mtl
->Ambient
, 4 * sizeof(float));
1730 memcpy(&dst
[22], &mtl
->Specular
, 4 * sizeof(float));
1731 dst
[23].x
= mtl
->Power
;
1732 memcpy(&dst
[24], &mtl
->Emissive
, 4 * sizeof(float));
1733 d3dcolor_to_rgba(&dst
[25].x
, state
->rs
[D3DRS_AMBIENT
]);
1734 dst
[19].x
= dst
[25].x
* mtl
->Ambient
.r
+ mtl
->Emissive
.r
;
1735 dst
[19].y
= dst
[25].y
* mtl
->Ambient
.g
+ mtl
->Emissive
.g
;
1736 dst
[19].z
= dst
[25].z
* mtl
->Ambient
.b
+ mtl
->Emissive
.b
;
1737 dst
[19].w
= mtl
->Ambient
.a
+ mtl
->Emissive
.a
;
1740 if (!(state
->changed
.group
& NINE_STATE_FF_LIGHTING
))
1743 for (l
= 0; l
< state
->ff
.num_lights_active
; ++l
) {
1744 const D3DLIGHT9
*light
= &state
->ff
.light
[state
->ff
.active_light
[l
]];
1746 dst
[32 + l
* 8].x
= light
->Type
;
1747 dst
[32 + l
* 8].y
= light
->Attenuation0
;
1748 dst
[32 + l
* 8].z
= light
->Attenuation1
;
1749 dst
[32 + l
* 8].w
= light
->Attenuation2
;
1750 memcpy(&dst
[33 + l
* 8].x
, &light
->Diffuse
, sizeof(light
->Diffuse
));
1751 memcpy(&dst
[34 + l
* 8].x
, &light
->Specular
, sizeof(light
->Specular
));
1752 memcpy(&dst
[35 + l
* 8].x
, &light
->Ambient
, sizeof(light
->Ambient
));
1753 nine_d3d_vector4_matrix_mul((D3DVECTOR
*)&dst
[36 + l
* 8].x
, &light
->Position
, GET_D3DTS(VIEW
));
1754 nine_d3d_vector3_matrix_mul((D3DVECTOR
*)&dst
[37 + l
* 8].x
, &light
->Direction
, GET_D3DTS(VIEW
));
1755 dst
[36 + l
* 8].w
= light
->Type
== D3DLIGHT_DIRECTIONAL
? 1e9f
: light
->Range
;
1756 dst
[37 + l
* 8].w
= light
->Falloff
;
1757 dst
[38 + l
* 8].x
= cosf(light
->Theta
* 0.5f
);
1758 dst
[38 + l
* 8].y
= cosf(light
->Phi
* 0.5f
);
1759 dst
[38 + l
* 8].z
= 1.0f
/ (dst
[38 + l
* 8].x
- dst
[38 + l
* 8].y
);
1760 dst
[39 + l
* 8].w
= (l
+ 1) == state
->ff
.num_lights_active
;
1765 nine_ff_load_point_and_fog_params(struct NineDevice9
*device
)
1767 const struct nine_state
*state
= &device
->state
;
1768 struct fvec4
*dst
= (struct fvec4
*)device
->ff
.vs_const
;
1770 if (!(state
->changed
.group
& NINE_STATE_FF_OTHER
))
1772 dst
[26].x
= asfloat(state
->rs
[D3DRS_POINTSIZE_MIN
]);
1773 dst
[26].y
= asfloat(state
->rs
[D3DRS_POINTSIZE_MAX
]);
1774 dst
[26].z
= asfloat(state
->rs
[D3DRS_POINTSIZE
]);
1775 dst
[26].w
= asfloat(state
->rs
[D3DRS_POINTSCALE_A
]);
1776 dst
[27].x
= asfloat(state
->rs
[D3DRS_POINTSCALE_B
]);
1777 dst
[27].y
= asfloat(state
->rs
[D3DRS_POINTSCALE_C
]);
1778 dst
[28].x
= asfloat(state
->rs
[D3DRS_FOGEND
]);
1779 dst
[28].y
= 1.0f
/ (asfloat(state
->rs
[D3DRS_FOGEND
]) - asfloat(state
->rs
[D3DRS_FOGSTART
]));
1780 if (isinf(dst
[28].y
))
1782 dst
[28].z
= asfloat(state
->rs
[D3DRS_FOGDENSITY
]);
1786 nine_ff_load_tex_matrices(struct NineDevice9
*device
)
1788 struct nine_state
*state
= &device
->state
;
1789 D3DMATRIX
*M
= (D3DMATRIX
*)device
->ff
.vs_const
;
1792 if (!(state
->ff
.changed
.transform
[0] & 0xff0000))
1794 for (s
= 0; s
< 8; ++s
) {
1795 if (IS_D3DTS_DIRTY(state
, TEXTURE0
+ s
))
1796 nine_d3d_matrix_transpose(&M
[32 + s
], nine_state_access_transform(state
, D3DTS_TEXTURE0
+ s
, FALSE
));
1801 nine_ff_load_ps_params(struct NineDevice9
*device
)
1803 const struct nine_state
*state
= &device
->state
;
1804 struct fvec4
*dst
= (struct fvec4
*)device
->ff
.ps_const
;
1807 if (!(state
->changed
.group
& (NINE_STATE_FF_PSSTAGES
| NINE_STATE_FF_OTHER
)))
1810 for (s
= 0; s
< 8; ++s
)
1811 d3dcolor_to_rgba(&dst
[s
].x
, state
->ff
.tex_stage
[s
][D3DTSS_CONSTANT
]);
1813 for (s
= 0; s
< 8; ++s
) {
1814 dst
[8 + s
].x
= asfloat(state
->ff
.tex_stage
[s
][D3DTSS_BUMPENVMAT00
]);
1815 dst
[8 + s
].y
= asfloat(state
->ff
.tex_stage
[s
][D3DTSS_BUMPENVMAT01
]);
1816 dst
[8 + s
].z
= asfloat(state
->ff
.tex_stage
[s
][D3DTSS_BUMPENVMAT10
]);
1817 dst
[8 + s
].w
= asfloat(state
->ff
.tex_stage
[s
][D3DTSS_BUMPENVMAT11
]);
1819 dst
[8 + s
/ 2].z
= asfloat(state
->ff
.tex_stage
[s
][D3DTSS_BUMPENVLSCALE
]);
1820 dst
[8 + s
/ 2].w
= asfloat(state
->ff
.tex_stage
[s
][D3DTSS_BUMPENVLOFFSET
]);
1822 dst
[8 + s
/ 2].x
= asfloat(state
->ff
.tex_stage
[s
][D3DTSS_BUMPENVLSCALE
]);
1823 dst
[8 + s
/ 2].y
= asfloat(state
->ff
.tex_stage
[s
][D3DTSS_BUMPENVLOFFSET
]);
1827 d3dcolor_to_rgba(&dst
[20].x
, state
->rs
[D3DRS_TEXTUREFACTOR
]);
1828 d3dcolor_to_rgba(&dst
[21].x
, state
->rs
[D3DRS_FOGCOLOR
]);
1829 dst
[22].x
= asfloat(state
->rs
[D3DRS_FOGEND
]);
1830 dst
[22].y
= 1.0f
/ (asfloat(state
->rs
[D3DRS_FOGEND
]) - asfloat(state
->rs
[D3DRS_FOGSTART
]));
1831 dst
[22].z
= asfloat(state
->rs
[D3DRS_FOGDENSITY
]);
1835 nine_ff_load_viewport_info(struct NineDevice9
*device
)
1837 D3DVIEWPORT9
*viewport
= &device
->state
.viewport
;
1838 struct fvec4
*dst
= (struct fvec4
*)device
->ff
.vs_const
;
1839 float diffZ
= viewport
->MaxZ
- viewport
->MinZ
;
1841 /* Note: the other functions avoids to fill the const again if nothing changed.
1842 * But we don't have much to fill, and adding code to allow that may be complex
1843 * so just fill it always */
1844 dst
[100].x
= 2.0f
/ (float)(viewport
->Width
);
1845 dst
[100].y
= 2.0f
/ (float)(viewport
->Height
);
1846 dst
[100].z
= (diffZ
== 0.0f
) ? 0.0f
: (1.0f
/ diffZ
);
1847 dst
[101].x
= (float)(viewport
->X
);
1848 dst
[101].y
= (float)(viewport
->Y
);
1849 dst
[101].z
= (float)(viewport
->MinZ
);
1853 nine_ff_update(struct NineDevice9
*device
)
1855 struct nine_state
*state
= &device
->state
;
1856 struct pipe_constant_buffer cb
;
1858 DBG("vs=%p ps=%p\n", device
->state
.vs
, device
->state
.ps
);
1860 /* NOTE: the only reference belongs to the hash table */
1861 if (!device
->state
.vs
) {
1862 device
->ff
.vs
= nine_ff_get_vs(device
);
1863 device
->state
.changed
.group
|= NINE_STATE_VS
;
1865 if (!device
->state
.ps
) {
1866 device
->ff
.ps
= nine_ff_get_ps(device
);
1867 device
->state
.changed
.group
|= NINE_STATE_PS
;
1870 if (!device
->state
.vs
) {
1871 nine_ff_load_vs_transforms(device
);
1872 nine_ff_load_tex_matrices(device
);
1873 nine_ff_load_lights(device
);
1874 nine_ff_load_point_and_fog_params(device
);
1875 nine_ff_load_viewport_info(device
);
1877 memset(state
->ff
.changed
.transform
, 0, sizeof(state
->ff
.changed
.transform
));
1879 cb
.buffer_offset
= 0;
1881 cb
.user_buffer
= device
->ff
.vs_const
;
1882 cb
.buffer_size
= NINE_FF_NUM_VS_CONST
* 4 * sizeof(float);
1884 if (!device
->driver_caps
.user_cbufs
) {
1885 u_upload_data(device
->constbuf_uploader
,
1888 device
->constbuf_alignment
,
1892 u_upload_unmap(device
->constbuf_uploader
);
1893 cb
.user_buffer
= NULL
;
1895 state
->pipe
.cb_vs_ff
= cb
;
1896 state
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
1899 if (!device
->state
.ps
) {
1900 nine_ff_load_ps_params(device
);
1902 cb
.buffer_offset
= 0;
1904 cb
.user_buffer
= device
->ff
.ps_const
;
1905 cb
.buffer_size
= NINE_FF_NUM_PS_CONST
* 4 * sizeof(float);
1907 if (!device
->driver_caps
.user_cbufs
) {
1908 u_upload_data(device
->constbuf_uploader
,
1911 device
->constbuf_alignment
,
1915 u_upload_unmap(device
->constbuf_uploader
);
1916 cb
.user_buffer
= NULL
;
1918 state
->pipe
.cb_ps_ff
= cb
;
1919 state
->commit
|= NINE_STATE_COMMIT_CONST_PS
;
1922 device
->state
.changed
.group
&= ~NINE_STATE_FF
;
1927 nine_ff_init(struct NineDevice9
*device
)
1929 device
->ff
.ht_vs
= util_hash_table_create(nine_ff_vs_key_hash
,
1930 nine_ff_vs_key_comp
);
1931 device
->ff
.ht_ps
= util_hash_table_create(nine_ff_ps_key_hash
,
1932 nine_ff_ps_key_comp
);
1934 device
->ff
.ht_fvf
= util_hash_table_create(nine_ff_fvf_key_hash
,
1935 nine_ff_fvf_key_comp
);
1937 device
->ff
.vs_const
= CALLOC(NINE_FF_NUM_VS_CONST
, 4 * sizeof(float));
1938 device
->ff
.ps_const
= CALLOC(NINE_FF_NUM_PS_CONST
, 4 * sizeof(float));
1940 return device
->ff
.ht_vs
&& device
->ff
.ht_ps
&&
1941 device
->ff
.ht_fvf
&&
1942 device
->ff
.vs_const
&& device
->ff
.ps_const
;
1945 static enum pipe_error
nine_ff_ht_delete_cb(void *key
, void *value
, void *data
)
1947 NineUnknown_Unbind(NineUnknown(value
));
1952 nine_ff_fini(struct NineDevice9
*device
)
1954 if (device
->ff
.ht_vs
) {
1955 util_hash_table_foreach(device
->ff
.ht_vs
, nine_ff_ht_delete_cb
, NULL
);
1956 util_hash_table_destroy(device
->ff
.ht_vs
);
1958 if (device
->ff
.ht_ps
) {
1959 util_hash_table_foreach(device
->ff
.ht_ps
, nine_ff_ht_delete_cb
, NULL
);
1960 util_hash_table_destroy(device
->ff
.ht_ps
);
1962 if (device
->ff
.ht_fvf
) {
1963 util_hash_table_foreach(device
->ff
.ht_fvf
, nine_ff_ht_delete_cb
, NULL
);
1964 util_hash_table_destroy(device
->ff
.ht_fvf
);
1966 device
->ff
.vs
= NULL
; /* destroyed by unbinding from hash table */
1967 device
->ff
.ps
= NULL
;
1969 FREE(device
->ff
.vs_const
);
1970 FREE(device
->ff
.ps_const
);
1974 nine_ff_prune_vs(struct NineDevice9
*device
)
1976 if (device
->ff
.num_vs
> 100) {
1977 /* could destroy the bound one here, so unbind */
1978 device
->pipe
->bind_vs_state(device
->pipe
, NULL
);
1979 util_hash_table_foreach(device
->ff
.ht_vs
, nine_ff_ht_delete_cb
, NULL
);
1980 util_hash_table_clear(device
->ff
.ht_vs
);
1981 device
->ff
.num_vs
= 0;
1982 device
->state
.changed
.group
|= NINE_STATE_VS
;
1986 nine_ff_prune_ps(struct NineDevice9
*device
)
1988 if (device
->ff
.num_ps
> 100) {
1989 /* could destroy the bound one here, so unbind */
1990 device
->pipe
->bind_fs_state(device
->pipe
, NULL
);
1991 util_hash_table_foreach(device
->ff
.ht_ps
, nine_ff_ht_delete_cb
, NULL
);
1992 util_hash_table_clear(device
->ff
.ht_ps
);
1993 device
->ff
.num_ps
= 0;
1994 device
->state
.changed
.group
|= NINE_STATE_PS
;
1998 /* ========================================================================== */
2000 /* Matrix multiplication:
2002 * in memory: 0 1 2 3 (row major)
2008 * r0 = (r0 * cA) (r0 * cB) . .
2009 * r1 = (r1 * cA) (r1 * cB)
2013 * r: (11) (12) (13) (14)
2014 * (21) (22) (23) (24)
2015 * (31) (32) (33) (34)
2016 * (41) (42) (43) (44)
2024 * t.xyzw = MUL(v.xxxx, r[0]);
2025 * t.xyzw = MAD(v.yyyy, r[1], t.xyzw);
2026 * t.xyzw = MAD(v.zzzz, r[2], t.xyzw);
2027 * v.xyzw = MAD(v.wwww, r[3], t.xyzw);
2029 * v.x = DP4(v, c[0]);
2030 * v.y = DP4(v, c[1]);
2031 * v.z = DP4(v, c[2]);
2032 * v.w = DP4(v, c[3]) = 1
2037 nine_D3DMATRIX_print(const D3DMATRIX *M)
2039 DBG("\n(%f %f %f %f)\n"
2043 M->m[0][0], M->m[0][1], M->m[0][2], M->m[0][3],
2044 M->m[1][0], M->m[1][1], M->m[1][2], M->m[1][3],
2045 M->m[2][0], M->m[2][1], M->m[2][2], M->m[2][3],
2046 M->m[3][0], M->m[3][1], M->m[3][2], M->m[3][3]);
2051 nine_DP4_row_col(const D3DMATRIX
*A
, int r
, const D3DMATRIX
*B
, int c
)
2053 return A
->m
[r
][0] * B
->m
[0][c
] +
2054 A
->m
[r
][1] * B
->m
[1][c
] +
2055 A
->m
[r
][2] * B
->m
[2][c
] +
2056 A
->m
[r
][3] * B
->m
[3][c
];
2060 nine_DP4_vec_col(const D3DVECTOR
*v
, const D3DMATRIX
*M
, int c
)
2062 return v
->x
* M
->m
[0][c
] +
2069 nine_DP3_vec_col(const D3DVECTOR
*v
, const D3DMATRIX
*M
, int c
)
2071 return v
->x
* M
->m
[0][c
] +
2077 nine_d3d_matrix_matrix_mul(D3DMATRIX
*D
, const D3DMATRIX
*L
, const D3DMATRIX
*R
)
2079 D
->_11
= nine_DP4_row_col(L
, 0, R
, 0);
2080 D
->_12
= nine_DP4_row_col(L
, 0, R
, 1);
2081 D
->_13
= nine_DP4_row_col(L
, 0, R
, 2);
2082 D
->_14
= nine_DP4_row_col(L
, 0, R
, 3);
2084 D
->_21
= nine_DP4_row_col(L
, 1, R
, 0);
2085 D
->_22
= nine_DP4_row_col(L
, 1, R
, 1);
2086 D
->_23
= nine_DP4_row_col(L
, 1, R
, 2);
2087 D
->_24
= nine_DP4_row_col(L
, 1, R
, 3);
2089 D
->_31
= nine_DP4_row_col(L
, 2, R
, 0);
2090 D
->_32
= nine_DP4_row_col(L
, 2, R
, 1);
2091 D
->_33
= nine_DP4_row_col(L
, 2, R
, 2);
2092 D
->_34
= nine_DP4_row_col(L
, 2, R
, 3);
2094 D
->_41
= nine_DP4_row_col(L
, 3, R
, 0);
2095 D
->_42
= nine_DP4_row_col(L
, 3, R
, 1);
2096 D
->_43
= nine_DP4_row_col(L
, 3, R
, 2);
2097 D
->_44
= nine_DP4_row_col(L
, 3, R
, 3);
2101 nine_d3d_vector4_matrix_mul(D3DVECTOR
*d
, const D3DVECTOR
*v
, const D3DMATRIX
*M
)
2103 d
->x
= nine_DP4_vec_col(v
, M
, 0);
2104 d
->y
= nine_DP4_vec_col(v
, M
, 1);
2105 d
->z
= nine_DP4_vec_col(v
, M
, 2);
2109 nine_d3d_vector3_matrix_mul(D3DVECTOR
*d
, const D3DVECTOR
*v
, const D3DMATRIX
*M
)
2111 d
->x
= nine_DP3_vec_col(v
, M
, 0);
2112 d
->y
= nine_DP3_vec_col(v
, M
, 1);
2113 d
->z
= nine_DP3_vec_col(v
, M
, 2);
2117 nine_d3d_matrix_transpose(D3DMATRIX
*D
, const D3DMATRIX
*M
)
2120 for (i
= 0; i
< 4; ++i
)
2121 for (j
= 0; j
< 4; ++j
)
2122 D
->m
[i
][j
] = M
->m
[j
][i
];
2125 #define _M_ADD_PROD_1i_2j_3k_4l(i,j,k,l) do { \
2126 float t = M->_1##i * M->_2##j * M->_3##k * M->_4##l; \
2127 if (t > 0.0f) pos += t; else neg += t; } while(0)
2129 #define _M_SUB_PROD_1i_2j_3k_4l(i,j,k,l) do { \
2130 float t = M->_1##i * M->_2##j * M->_3##k * M->_4##l; \
2131 if (t > 0.0f) neg -= t; else pos -= t; } while(0)
2133 nine_d3d_matrix_det(const D3DMATRIX
*M
)
2138 _M_ADD_PROD_1i_2j_3k_4l(1, 2, 3, 4);
2139 _M_ADD_PROD_1i_2j_3k_4l(1, 3, 4, 2);
2140 _M_ADD_PROD_1i_2j_3k_4l(1, 4, 2, 3);
2142 _M_ADD_PROD_1i_2j_3k_4l(2, 1, 4, 3);
2143 _M_ADD_PROD_1i_2j_3k_4l(2, 3, 1, 4);
2144 _M_ADD_PROD_1i_2j_3k_4l(2, 4, 3, 1);
2146 _M_ADD_PROD_1i_2j_3k_4l(3, 1, 2, 4);
2147 _M_ADD_PROD_1i_2j_3k_4l(3, 2, 4, 1);
2148 _M_ADD_PROD_1i_2j_3k_4l(3, 4, 1, 2);
2150 _M_ADD_PROD_1i_2j_3k_4l(4, 1, 3, 2);
2151 _M_ADD_PROD_1i_2j_3k_4l(4, 2, 1, 3);
2152 _M_ADD_PROD_1i_2j_3k_4l(4, 3, 2, 1);
2154 _M_SUB_PROD_1i_2j_3k_4l(1, 2, 4, 3);
2155 _M_SUB_PROD_1i_2j_3k_4l(1, 3, 2, 4);
2156 _M_SUB_PROD_1i_2j_3k_4l(1, 4, 3, 2);
2158 _M_SUB_PROD_1i_2j_3k_4l(2, 1, 3, 4);
2159 _M_SUB_PROD_1i_2j_3k_4l(2, 3, 4, 1);
2160 _M_SUB_PROD_1i_2j_3k_4l(2, 4, 1, 3);
2162 _M_SUB_PROD_1i_2j_3k_4l(3, 1, 4, 2);
2163 _M_SUB_PROD_1i_2j_3k_4l(3, 2, 1, 4);
2164 _M_SUB_PROD_1i_2j_3k_4l(3, 4, 2, 1);
2166 _M_SUB_PROD_1i_2j_3k_4l(4, 1, 2, 3);
2167 _M_SUB_PROD_1i_2j_3k_4l(4, 2, 3, 1);
2168 _M_SUB_PROD_1i_2j_3k_4l(4, 3, 1, 2);
2173 /* XXX: Probably better to just use src/mesa/math/m_matrix.c because
2174 * I have no idea where this code came from.
2177 nine_d3d_matrix_inverse(D3DMATRIX
*D
, const D3DMATRIX
*M
)
2183 M
->m
[1][1] * M
->m
[2][2] * M
->m
[3][3] -
2184 M
->m
[1][1] * M
->m
[3][2] * M
->m
[2][3] -
2185 M
->m
[1][2] * M
->m
[2][1] * M
->m
[3][3] +
2186 M
->m
[1][2] * M
->m
[3][1] * M
->m
[2][3] +
2187 M
->m
[1][3] * M
->m
[2][1] * M
->m
[3][2] -
2188 M
->m
[1][3] * M
->m
[3][1] * M
->m
[2][2];
2191 -M
->m
[0][1] * M
->m
[2][2] * M
->m
[3][3] +
2192 M
->m
[0][1] * M
->m
[3][2] * M
->m
[2][3] +
2193 M
->m
[0][2] * M
->m
[2][1] * M
->m
[3][3] -
2194 M
->m
[0][2] * M
->m
[3][1] * M
->m
[2][3] -
2195 M
->m
[0][3] * M
->m
[2][1] * M
->m
[3][2] +
2196 M
->m
[0][3] * M
->m
[3][1] * M
->m
[2][2];
2199 M
->m
[0][1] * M
->m
[1][2] * M
->m
[3][3] -
2200 M
->m
[0][1] * M
->m
[3][2] * M
->m
[1][3] -
2201 M
->m
[0][2] * M
->m
[1][1] * M
->m
[3][3] +
2202 M
->m
[0][2] * M
->m
[3][1] * M
->m
[1][3] +
2203 M
->m
[0][3] * M
->m
[1][1] * M
->m
[3][2] -
2204 M
->m
[0][3] * M
->m
[3][1] * M
->m
[1][2];
2207 -M
->m
[0][1] * M
->m
[1][2] * M
->m
[2][3] +
2208 M
->m
[0][1] * M
->m
[2][2] * M
->m
[1][3] +
2209 M
->m
[0][2] * M
->m
[1][1] * M
->m
[2][3] -
2210 M
->m
[0][2] * M
->m
[2][1] * M
->m
[1][3] -
2211 M
->m
[0][3] * M
->m
[1][1] * M
->m
[2][2] +
2212 M
->m
[0][3] * M
->m
[2][1] * M
->m
[1][2];
2215 -M
->m
[1][0] * M
->m
[2][2] * M
->m
[3][3] +
2216 M
->m
[1][0] * M
->m
[3][2] * M
->m
[2][3] +
2217 M
->m
[1][2] * M
->m
[2][0] * M
->m
[3][3] -
2218 M
->m
[1][2] * M
->m
[3][0] * M
->m
[2][3] -
2219 M
->m
[1][3] * M
->m
[2][0] * M
->m
[3][2] +
2220 M
->m
[1][3] * M
->m
[3][0] * M
->m
[2][2];
2223 M
->m
[0][0] * M
->m
[2][2] * M
->m
[3][3] -
2224 M
->m
[0][0] * M
->m
[3][2] * M
->m
[2][3] -
2225 M
->m
[0][2] * M
->m
[2][0] * M
->m
[3][3] +
2226 M
->m
[0][2] * M
->m
[3][0] * M
->m
[2][3] +
2227 M
->m
[0][3] * M
->m
[2][0] * M
->m
[3][2] -
2228 M
->m
[0][3] * M
->m
[3][0] * M
->m
[2][2];
2231 -M
->m
[0][0] * M
->m
[1][2] * M
->m
[3][3] +
2232 M
->m
[0][0] * M
->m
[3][2] * M
->m
[1][3] +
2233 M
->m
[0][2] * M
->m
[1][0] * M
->m
[3][3] -
2234 M
->m
[0][2] * M
->m
[3][0] * M
->m
[1][3] -
2235 M
->m
[0][3] * M
->m
[1][0] * M
->m
[3][2] +
2236 M
->m
[0][3] * M
->m
[3][0] * M
->m
[1][2];
2239 M
->m
[0][0] * M
->m
[1][2] * M
->m
[2][3] -
2240 M
->m
[0][0] * M
->m
[2][2] * M
->m
[1][3] -
2241 M
->m
[0][2] * M
->m
[1][0] * M
->m
[2][3] +
2242 M
->m
[0][2] * M
->m
[2][0] * M
->m
[1][3] +
2243 M
->m
[0][3] * M
->m
[1][0] * M
->m
[2][2] -
2244 M
->m
[0][3] * M
->m
[2][0] * M
->m
[1][2];
2247 M
->m
[1][0] * M
->m
[2][1] * M
->m
[3][3] -
2248 M
->m
[1][0] * M
->m
[3][1] * M
->m
[2][3] -
2249 M
->m
[1][1] * M
->m
[2][0] * M
->m
[3][3] +
2250 M
->m
[1][1] * M
->m
[3][0] * M
->m
[2][3] +
2251 M
->m
[1][3] * M
->m
[2][0] * M
->m
[3][1] -
2252 M
->m
[1][3] * M
->m
[3][0] * M
->m
[2][1];
2255 -M
->m
[0][0] * M
->m
[2][1] * M
->m
[3][3] +
2256 M
->m
[0][0] * M
->m
[3][1] * M
->m
[2][3] +
2257 M
->m
[0][1] * M
->m
[2][0] * M
->m
[3][3] -
2258 M
->m
[0][1] * M
->m
[3][0] * M
->m
[2][3] -
2259 M
->m
[0][3] * M
->m
[2][0] * M
->m
[3][1] +
2260 M
->m
[0][3] * M
->m
[3][0] * M
->m
[2][1];
2263 M
->m
[0][0] * M
->m
[1][1] * M
->m
[3][3] -
2264 M
->m
[0][0] * M
->m
[3][1] * M
->m
[1][3] -
2265 M
->m
[0][1] * M
->m
[1][0] * M
->m
[3][3] +
2266 M
->m
[0][1] * M
->m
[3][0] * M
->m
[1][3] +
2267 M
->m
[0][3] * M
->m
[1][0] * M
->m
[3][1] -
2268 M
->m
[0][3] * M
->m
[3][0] * M
->m
[1][1];
2271 -M
->m
[0][0] * M
->m
[1][1] * M
->m
[2][3] +
2272 M
->m
[0][0] * M
->m
[2][1] * M
->m
[1][3] +
2273 M
->m
[0][1] * M
->m
[1][0] * M
->m
[2][3] -
2274 M
->m
[0][1] * M
->m
[2][0] * M
->m
[1][3] -
2275 M
->m
[0][3] * M
->m
[1][0] * M
->m
[2][1] +
2276 M
->m
[0][3] * M
->m
[2][0] * M
->m
[1][1];
2279 -M
->m
[1][0] * M
->m
[2][1] * M
->m
[3][2] +
2280 M
->m
[1][0] * M
->m
[3][1] * M
->m
[2][2] +
2281 M
->m
[1][1] * M
->m
[2][0] * M
->m
[3][2] -
2282 M
->m
[1][1] * M
->m
[3][0] * M
->m
[2][2] -
2283 M
->m
[1][2] * M
->m
[2][0] * M
->m
[3][1] +
2284 M
->m
[1][2] * M
->m
[3][0] * M
->m
[2][1];
2287 M
->m
[0][0] * M
->m
[2][1] * M
->m
[3][2] -
2288 M
->m
[0][0] * M
->m
[3][1] * M
->m
[2][2] -
2289 M
->m
[0][1] * M
->m
[2][0] * M
->m
[3][2] +
2290 M
->m
[0][1] * M
->m
[3][0] * M
->m
[2][2] +
2291 M
->m
[0][2] * M
->m
[2][0] * M
->m
[3][1] -
2292 M
->m
[0][2] * M
->m
[3][0] * M
->m
[2][1];
2295 -M
->m
[0][0] * M
->m
[1][1] * M
->m
[3][2] +
2296 M
->m
[0][0] * M
->m
[3][1] * M
->m
[1][2] +
2297 M
->m
[0][1] * M
->m
[1][0] * M
->m
[3][2] -
2298 M
->m
[0][1] * M
->m
[3][0] * M
->m
[1][2] -
2299 M
->m
[0][2] * M
->m
[1][0] * M
->m
[3][1] +
2300 M
->m
[0][2] * M
->m
[3][0] * M
->m
[1][1];
2303 M
->m
[0][0] * M
->m
[1][1] * M
->m
[2][2] -
2304 M
->m
[0][0] * M
->m
[2][1] * M
->m
[1][2] -
2305 M
->m
[0][1] * M
->m
[1][0] * M
->m
[2][2] +
2306 M
->m
[0][1] * M
->m
[2][0] * M
->m
[1][2] +
2307 M
->m
[0][2] * M
->m
[1][0] * M
->m
[2][1] -
2308 M
->m
[0][2] * M
->m
[2][0] * M
->m
[1][1];
2311 M
->m
[0][0] * D
->m
[0][0] +
2312 M
->m
[1][0] * D
->m
[0][1] +
2313 M
->m
[2][0] * D
->m
[0][2] +
2314 M
->m
[3][0] * D
->m
[0][3];
2318 for (i
= 0; i
< 4; i
++)
2319 for (k
= 0; k
< 4; k
++)
2326 nine_d3d_matrix_matrix_mul(&I
, D
, M
);
2328 for (i
= 0; i
< 4; ++i
)
2329 for (k
= 0; k
< 4; ++k
)
2330 if (fabsf(I
.m
[i
][k
] - (float)(i
== k
)) > 1e-3)
2331 DBG("Matrix inversion check FAILED !\n");
2336 /* TODO: don't use 4x4 inverse, unless this gets all nicely inlined ? */
2338 nine_d3d_matrix_inverse_3x3(D3DMATRIX
*D
, const D3DMATRIX
*M
)
2343 for (i
= 0; i
< 3; ++i
)
2344 for (j
= 0; j
< 3; ++j
)
2345 T
.m
[i
][j
] = M
->m
[i
][j
];
2346 for (i
= 0; i
< 3; ++i
) {
2352 nine_d3d_matrix_inverse(D
, &T
);