VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/baseshader.c@ 19678

Last change on this file since 19678 was 19678, checked in by vboxsync, 16 years ago

opengl: update wine to 1.1.21, add d3d9.dll to build list

  • Property svn:eol-style set to native
File size: 46.0 KB
Line 
1/*
2 * shaders implementation
3 *
4 * Copyright 2002-2003 Jason Edmeades
5 * Copyright 2002-2003 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2006 Ivan Gyurdiev
9 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
10 * Copyright 2009 Henri Verbeet for CodeWeavers
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27/*
28 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
29 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
30 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
31 * a choice of LGPL license versions is made available with the language indicating
32 * that LGPLv2 or any later version may be used, or where a choice of which version
33 * of the LGPL is applied is otherwise unspecified.
34 */
35
36#include "config.h"
37#include <string.h>
38#include <stdio.h>
39#include "wined3d_private.h"
40
41WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
42WINE_DECLARE_DEBUG_CHANNEL(d3d);
43
44static const char *shader_opcode_names[] =
45{
46 /* WINED3DSIH_ABS */ "abs",
47 /* WINED3DSIH_ADD */ "add",
48 /* WINED3DSIH_BEM */ "bem",
49 /* WINED3DSIH_BREAK */ "break",
50 /* WINED3DSIH_BREAKC */ "breakc",
51 /* WINED3DSIH_BREAKP */ "breakp",
52 /* WINED3DSIH_CALL */ "call",
53 /* WINED3DSIH_CALLNZ */ "callnz",
54 /* WINED3DSIH_CMP */ "cmp",
55 /* WINED3DSIH_CND */ "cnd",
56 /* WINED3DSIH_CRS */ "crs",
57 /* WINED3DSIH_DCL */ "dcl",
58 /* WINED3DSIH_DEF */ "def",
59 /* WINED3DSIH_DEFB */ "defb",
60 /* WINED3DSIH_DEFI */ "defi",
61 /* WINED3DSIH_DP2ADD */ "dp2add",
62 /* WINED3DSIH_DP3 */ "dp3",
63 /* WINED3DSIH_DP4 */ "dp4",
64 /* WINED3DSIH_DST */ "dst",
65 /* WINED3DSIH_DSX */ "dsx",
66 /* WINED3DSIH_DSY */ "dsy",
67 /* WINED3DSIH_ELSE */ "else",
68 /* WINED3DSIH_ENDIF */ "endif",
69 /* WINED3DSIH_ENDLOOP */ "endloop",
70 /* WINED3DSIH_ENDREP */ "endrep",
71 /* WINED3DSIH_EXP */ "exp",
72 /* WINED3DSIH_EXPP */ "expp",
73 /* WINED3DSIH_FRC */ "frc",
74 /* WINED3DSIH_IF */ "if",
75 /* WINED3DSIH_IFC */ "ifc",
76 /* WINED3DSIH_LABEL */ "label",
77 /* WINED3DSIH_LIT */ "lit",
78 /* WINED3DSIH_LOG */ "log",
79 /* WINED3DSIH_LOGP */ "logp",
80 /* WINED3DSIH_LOOP */ "loop",
81 /* WINED3DSIH_LRP */ "lrp",
82 /* WINED3DSIH_M3x2 */ "m3x2",
83 /* WINED3DSIH_M3x3 */ "m3x3",
84 /* WINED3DSIH_M3x4 */ "m3x4",
85 /* WINED3DSIH_M4x3 */ "m4x3",
86 /* WINED3DSIH_M4x4 */ "m4x4",
87 /* WINED3DSIH_MAD */ "mad",
88 /* WINED3DSIH_MAX */ "max",
89 /* WINED3DSIH_MIN */ "min",
90 /* WINED3DSIH_MOV */ "mov",
91 /* WINED3DSIH_MOVA */ "mova",
92 /* WINED3DSIH_MUL */ "mul",
93 /* WINED3DSIH_NOP */ "nop",
94 /* WINED3DSIH_NRM */ "nrm",
95 /* WINED3DSIH_PHASE */ "phase",
96 /* WINED3DSIH_POW */ "pow",
97 /* WINED3DSIH_RCP */ "rcp",
98 /* WINED3DSIH_REP */ "rep",
99 /* WINED3DSIH_RET */ "ret",
100 /* WINED3DSIH_RSQ */ "rsq",
101 /* WINED3DSIH_SETP */ "setp",
102 /* WINED3DSIH_SGE */ "sge",
103 /* WINED3DSIH_SGN */ "sgn",
104 /* WINED3DSIH_SINCOS */ "sincos",
105 /* WINED3DSIH_SLT */ "slt",
106 /* WINED3DSIH_SUB */ "sub",
107 /* WINED3DSIH_TEX */ "texld",
108 /* WINED3DSIH_TEXBEM */ "texbem",
109 /* WINED3DSIH_TEXBEML */ "texbeml",
110 /* WINED3DSIH_TEXCOORD */ "texcrd",
111 /* WINED3DSIH_TEXDEPTH */ "texdepth",
112 /* WINED3DSIH_TEXDP3 */ "texdp3",
113 /* WINED3DSIH_TEXDP3TEX */ "texdp3tex",
114 /* WINED3DSIH_TEXKILL */ "texkill",
115 /* WINED3DSIH_TEXLDD */ "texldd",
116 /* WINED3DSIH_TEXLDL */ "texldl",
117 /* WINED3DSIH_TEXM3x2DEPTH */ "texm3x2depth",
118 /* WINED3DSIH_TEXM3x2PAD */ "texm3x2pad",
119 /* WINED3DSIH_TEXM3x2TEX */ "texm3x2tex",
120 /* WINED3DSIH_TEXM3x3 */ "texm3x3",
121 /* WINED3DSIH_TEXM3x3DIFF */ "texm3x3diff",
122 /* WINED3DSIH_TEXM3x3PAD */ "texm3x3pad",
123 /* WINED3DSIH_TEXM3x3SPEC */ "texm3x3spec",
124 /* WINED3DSIH_TEXM3x3TEX */ "texm3x3tex",
125 /* WINED3DSIH_TEXM3x3VSPEC */ "texm3x3vspec",
126 /* WINED3DSIH_TEXREG2AR */ "texreg2ar",
127 /* WINED3DSIH_TEXREG2GB */ "texreg2gb",
128 /* WINED3DSIH_TEXREG2RGB */ "texreg2rgb",
129};
130
131const struct wined3d_shader_frontend *shader_select_frontend(DWORD version_token)
132{
133 switch (version_token >> 16)
134 {
135 case WINED3D_SM1_VS:
136 case WINED3D_SM1_PS:
137 return &sm1_shader_frontend;
138
139 case WINED3D_SM4_PS:
140 case WINED3D_SM4_VS:
141 case WINED3D_SM4_GS:
142 return &sm4_shader_frontend;
143
144 default:
145 FIXME("Unrecognised version token %#x\n", version_token);
146 return NULL;
147 }
148}
149
150static inline BOOL shader_is_version_token(DWORD token) {
151 return shader_is_pshader_version(token) ||
152 shader_is_vshader_version(token);
153}
154
155void shader_buffer_init(struct SHADER_BUFFER *buffer)
156{
157 buffer->buffer = HeapAlloc(GetProcessHeap(), 0, SHADER_PGMSIZE);
158 buffer->buffer[0] = '\0';
159 buffer->bsize = 0;
160 buffer->lineNo = 0;
161 buffer->newline = TRUE;
162}
163
164void shader_buffer_free(struct SHADER_BUFFER *buffer)
165{
166 HeapFree(GetProcessHeap(), 0, buffer->buffer);
167}
168
169int shader_vaddline(SHADER_BUFFER* buffer, const char *format, va_list args)
170{
171 char* base = buffer->buffer + buffer->bsize;
172 int rc;
173
174 rc = _vsnprintf(base, SHADER_PGMSIZE - 1 - buffer->bsize, format, args);
175
176 if (rc < 0 || /* C89 */
177 rc > SHADER_PGMSIZE - 1 - buffer->bsize) { /* C99 */
178
179 ERR("The buffer allocated for the shader program string "
180 "is too small at %d bytes.\n", SHADER_PGMSIZE);
181 buffer->bsize = SHADER_PGMSIZE - 1;
182 return -1;
183 }
184
185 if (buffer->newline) {
186 TRACE("GL HW (%u, %u) : %s", buffer->lineNo + 1, buffer->bsize, base);
187 buffer->newline = FALSE;
188 } else {
189 TRACE("%s", base);
190 }
191
192 buffer->bsize += rc;
193 if (buffer->buffer[buffer->bsize-1] == '\n') {
194 buffer->lineNo++;
195 buffer->newline = TRUE;
196 }
197 return 0;
198}
199
200int shader_addline(SHADER_BUFFER* buffer, const char *format, ...)
201{
202 int ret;
203 va_list args;
204
205 va_start(args, format);
206 ret = shader_vaddline(buffer, format, args);
207 va_end(args);
208
209 return ret;
210}
211
212void shader_init(struct IWineD3DBaseShaderClass *shader, IWineD3DDevice *device)
213{
214 shader->ref = 1;
215 shader->device = device;
216 list_init(&shader->linked_programs);
217}
218
219/* Convert floating point offset relative
220 * to a register file to an absolute offset for float constants */
221static unsigned int shader_get_float_offset(WINED3DSHADER_PARAM_REGISTER_TYPE register_type, UINT register_idx)
222{
223 switch (register_type)
224 {
225 case WINED3DSPR_CONST: return register_idx;
226 case WINED3DSPR_CONST2: return 2048 + register_idx;
227 case WINED3DSPR_CONST3: return 4096 + register_idx;
228 case WINED3DSPR_CONST4: return 6144 + register_idx;
229 default:
230 FIXME("Unsupported register type: %d\n", register_type);
231 return register_idx;
232 }
233}
234
235static void shader_delete_constant_list(struct list* clist) {
236
237 struct list *ptr;
238 struct local_constant* constant;
239
240 ptr = list_head(clist);
241 while (ptr) {
242 constant = LIST_ENTRY(ptr, struct local_constant, entry);
243 ptr = list_next(clist, ptr);
244 HeapFree(GetProcessHeap(), 0, constant);
245 }
246 list_init(clist);
247}
248
249static inline void set_bitmap_bit(DWORD *bitmap, DWORD bit)
250{
251 DWORD idx, shift;
252 idx = bit >> 5;
253 shift = bit & 0x1f;
254 bitmap[idx] |= (1 << shift);
255}
256
257static void shader_record_register_usage(IWineD3DBaseShaderImpl *This, struct shader_reg_maps *reg_maps,
258 DWORD register_type, UINT register_idx, BOOL has_rel_addr, BOOL pshader)
259{
260 switch (register_type)
261 {
262 case WINED3DSPR_TEXTURE: /* WINED3DSPR_ADDR */
263 if (pshader) reg_maps->texcoord[register_idx] = 1;
264 else reg_maps->address[register_idx] = 1;
265 break;
266
267 case WINED3DSPR_TEMP:
268 reg_maps->temporary[register_idx] = 1;
269 break;
270
271 case WINED3DSPR_INPUT:
272 if (!pshader) reg_maps->attributes[register_idx] = 1;
273 else
274 {
275 if (has_rel_addr)
276 {
277 /* If relative addressing is used, we must assume that all registers
278 * are used. Even if it is a construct like v3[aL], we can't assume
279 * that v0, v1 and v2 aren't read because aL can be negative */
280 unsigned int i;
281 for (i = 0; i < MAX_REG_INPUT; ++i)
282 {
283 ((IWineD3DPixelShaderImpl *)This)->input_reg_used[i] = TRUE;
284 }
285 }
286 else
287 {
288 ((IWineD3DPixelShaderImpl *)This)->input_reg_used[register_idx] = TRUE;
289 }
290 }
291 break;
292
293 case WINED3DSPR_RASTOUT:
294 if (register_idx == 1) reg_maps->fog = 1;
295 break;
296
297 case WINED3DSPR_MISCTYPE:
298 if (pshader && register_idx == 0) reg_maps->vpos = 1;
299 break;
300
301 case WINED3DSPR_CONST:
302 if (has_rel_addr)
303 {
304 if (!pshader)
305 {
306 if (register_idx <= ((IWineD3DVertexShaderImpl *)This)->min_rel_offset)
307 ((IWineD3DVertexShaderImpl *)This)->min_rel_offset = register_idx;
308 else if (register_idx >= ((IWineD3DVertexShaderImpl *)This)->max_rel_offset)
309 ((IWineD3DVertexShaderImpl *)This)->max_rel_offset = register_idx;
310 }
311 reg_maps->usesrelconstF = TRUE;
312 }
313 else
314 {
315 set_bitmap_bit(reg_maps->constf, register_idx);
316 }
317 break;
318
319 case WINED3DSPR_CONSTINT:
320 reg_maps->integer_constants |= (1 << register_idx);
321 break;
322
323 case WINED3DSPR_CONSTBOOL:
324 reg_maps->boolean_constants |= (1 << register_idx);
325 break;
326
327 default:
328 TRACE("Not recording register of type %#x and idx %u\n", register_type, register_idx);
329 break;
330 }
331}
332
333static unsigned char get_instr_regcount(enum WINED3D_SHADER_INSTRUCTION_HANDLER instr, int param)
334{
335 switch(instr)
336 {
337 case WINED3DSIH_M4x4:
338 case WINED3DSIH_M3x4:
339 return param == 1 ? 4 : 1;
340
341 case WINED3DSIH_M4x3:
342 case WINED3DSIH_M3x3:
343 return param == 1 ? 3 : 1;
344
345 case WINED3DSIH_M3x2:
346 return param == 1 ? 2 : 1;
347
348 default:
349 return 1;
350 }
351}
352
353/* Note that this does not count the loop register
354 * as an address register. */
355
356HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, const struct wined3d_shader_frontend *fe,
357 struct shader_reg_maps *reg_maps, struct wined3d_shader_semantic *semantics_in,
358 struct wined3d_shader_semantic *semantics_out, const DWORD *byte_code, DWORD constf_size)
359{
360 IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
361 void *fe_data = This->baseShader.frontend_data;
362 struct wined3d_shader_version shader_version;
363 unsigned int cur_loop_depth = 0, max_loop_depth = 0;
364 const DWORD* pToken = byte_code;
365 char pshader;
366
367 /* There are some minor differences between pixel and vertex shaders */
368
369 memset(reg_maps, 0, sizeof(*reg_maps));
370
371 /* get_registers_used is called on every compile on some 1.x shaders, which can result
372 * in stacking up a collection of local constants. Delete the old constants if existing
373 */
374 shader_delete_constant_list(&This->baseShader.constantsF);
375 shader_delete_constant_list(&This->baseShader.constantsB);
376 shader_delete_constant_list(&This->baseShader.constantsI);
377
378 fe->shader_read_header(fe_data, &pToken, &shader_version);
379 reg_maps->shader_version = shader_version;
380 pshader = shader_is_pshader_version(shader_version.type);
381
382 reg_maps->constf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
383 sizeof(*reg_maps->constf) * ((constf_size + 31) / 32));
384 if(!reg_maps->constf) {
385 ERR("Out of memory\n");
386 return E_OUTOFMEMORY;
387 }
388
389 while (!fe->shader_is_end(fe_data, &pToken))
390 {
391 struct wined3d_shader_instruction ins;
392 const char *comment;
393 UINT param_size;
394
395 /* Skip comments */
396 fe->shader_read_comment(&pToken, &comment);
397 if (comment) continue;
398
399 /* Fetch opcode */
400 fe->shader_read_opcode(fe_data, &pToken, &ins, &param_size);
401
402 /* Unhandled opcode, and its parameters */
403 if (ins.handler_idx == WINED3DSIH_TABLE_SIZE)
404 {
405 TRACE("Skipping unrecognized instruction.\n");
406 pToken += param_size;
407 continue;
408 }
409
410 /* Handle declarations */
411 if (ins.handler_idx == WINED3DSIH_DCL)
412 {
413 struct wined3d_shader_semantic semantic;
414
415 fe->shader_read_semantic(&pToken, &semantic);
416
417 switch (semantic.reg.reg.type)
418 {
419 /* Vshader: mark attributes used
420 * Pshader: mark 3.0 input registers used, save token */
421 case WINED3DSPR_INPUT:
422 if (!pshader) reg_maps->attributes[semantic.reg.reg.idx] = 1;
423 else reg_maps->packed_input[semantic.reg.reg.idx] = 1;
424 semantics_in[semantic.reg.reg.idx] = semantic;
425 break;
426
427 /* Vshader: mark 3.0 output registers used, save token */
428 case WINED3DSPR_OUTPUT:
429 reg_maps->packed_output[semantic.reg.reg.idx] = 1;
430 semantics_out[semantic.reg.reg.idx] = semantic;
431 if (semantic.usage == WINED3DDECLUSAGE_FOG) reg_maps->fog = 1;
432 break;
433
434 /* Save sampler usage token */
435 case WINED3DSPR_SAMPLER:
436 reg_maps->sampler_type[semantic.reg.reg.idx] = semantic.sampler_type;
437 break;
438
439 default:
440 TRACE("Not recording DCL register type %#x.\n", semantic.reg.reg.type);
441 break;
442 }
443 }
444 else if (ins.handler_idx == WINED3DSIH_DEF)
445 {
446 struct wined3d_shader_dst_param dst;
447 struct wined3d_shader_src_param rel_addr;
448
449 local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
450 if (!lconst) return E_OUTOFMEMORY;
451
452 fe->shader_read_dst_param(fe_data, &pToken, &dst, &rel_addr);
453 lconst->idx = dst.reg.idx;
454
455 memcpy(lconst->value, pToken, 4 * sizeof(DWORD));
456 pToken += 4;
457
458 /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
459 if (shader_version.major == 1 && pshader)
460 {
461 float *value = (float *) lconst->value;
462 if(value[0] < -1.0) value[0] = -1.0;
463 else if(value[0] > 1.0) value[0] = 1.0;
464 if(value[1] < -1.0) value[1] = -1.0;
465 else if(value[1] > 1.0) value[1] = 1.0;
466 if(value[2] < -1.0) value[2] = -1.0;
467 else if(value[2] > 1.0) value[2] = 1.0;
468 if(value[3] < -1.0) value[3] = -1.0;
469 else if(value[3] > 1.0) value[3] = 1.0;
470 }
471
472 list_add_head(&This->baseShader.constantsF, &lconst->entry);
473 }
474 else if (ins.handler_idx == WINED3DSIH_DEFI)
475 {
476 struct wined3d_shader_dst_param dst;
477 struct wined3d_shader_src_param rel_addr;
478
479 local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
480 if (!lconst) return E_OUTOFMEMORY;
481
482 fe->shader_read_dst_param(fe_data, &pToken, &dst, &rel_addr);
483 lconst->idx = dst.reg.idx;
484
485 memcpy(lconst->value, pToken, 4 * sizeof(DWORD));
486 pToken += 4;
487
488 list_add_head(&This->baseShader.constantsI, &lconst->entry);
489 }
490 else if (ins.handler_idx == WINED3DSIH_DEFB)
491 {
492 struct wined3d_shader_dst_param dst;
493 struct wined3d_shader_src_param rel_addr;
494
495 local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
496 if (!lconst) return E_OUTOFMEMORY;
497
498 fe->shader_read_dst_param(fe_data, &pToken, &dst, &rel_addr);
499 lconst->idx = dst.reg.idx;
500
501 memcpy(lconst->value, pToken, sizeof(DWORD));
502 ++pToken;
503
504 list_add_head(&This->baseShader.constantsB, &lconst->entry);
505 }
506 /* If there's a loop in the shader */
507 else if (ins.handler_idx == WINED3DSIH_LOOP
508 || ins.handler_idx == WINED3DSIH_REP)
509 {
510 struct wined3d_shader_src_param src, rel_addr;
511
512 fe->shader_read_src_param(fe_data, &pToken, &src, &rel_addr);
513
514 /* Rep and Loop always use an integer constant for the control parameters */
515 if (ins.handler_idx == WINED3DSIH_REP)
516 {
517 reg_maps->integer_constants |= 1 << src.reg.idx;
518 }
519 else
520 {
521 fe->shader_read_src_param(fe_data, &pToken, &src, &rel_addr);
522 reg_maps->integer_constants |= 1 << src.reg.idx;
523 }
524
525 cur_loop_depth++;
526 if(cur_loop_depth > max_loop_depth)
527 max_loop_depth = cur_loop_depth;
528 }
529 else if (ins.handler_idx == WINED3DSIH_ENDLOOP
530 || ins.handler_idx == WINED3DSIH_ENDREP)
531 {
532 cur_loop_depth--;
533 }
534 /* For subroutine prototypes */
535 else if (ins.handler_idx == WINED3DSIH_LABEL)
536 {
537 struct wined3d_shader_src_param src, rel_addr;
538
539 fe->shader_read_src_param(fe_data, &pToken, &src, &rel_addr);
540 reg_maps->labels[src.reg.idx] = 1;
541 }
542 /* Set texture, address, temporary registers */
543 else
544 {
545 int i, limit;
546
547 /* This will loop over all the registers and try to
548 * make a bitmask of the ones we're interested in.
549 *
550 * Relative addressing tokens are ignored, but that's
551 * okay, since we'll catch any address registers when
552 * they are initialized (required by spec) */
553
554 if (ins.dst_count)
555 {
556 struct wined3d_shader_dst_param dst_param;
557 struct wined3d_shader_src_param dst_rel_addr;
558
559 fe->shader_read_dst_param(fe_data, &pToken, &dst_param, &dst_rel_addr);
560
561 /* WINED3DSPR_TEXCRDOUT is the same as WINED3DSPR_OUTPUT. _OUTPUT can be > MAX_REG_TEXCRD and
562 * is used in >= 3.0 shaders. Filter 3.0 shaders to prevent overflows, and also filter pixel
563 * shaders because TECRDOUT isn't used in them, but future register types might cause issues */
564 if (!pshader && shader_version.major < 3 && dst_param.reg.type == WINED3DSPR_TEXCRDOUT)
565 {
566 reg_maps->texcoord_mask[dst_param.reg.type] |= dst_param.write_mask;
567 }
568 else
569 {
570 shader_record_register_usage(This, reg_maps, dst_param.reg.type,
571 dst_param.reg.idx, !!dst_param.reg.rel_addr, pshader);
572 }
573
574 /* Declare 1.X samplers implicitly, based on the destination reg. number */
575 if (shader_version.major == 1
576 && pshader /* Filter different instructions with the same enum values in VS */
577 && (ins.handler_idx == WINED3DSIH_TEX
578 || ins.handler_idx == WINED3DSIH_TEXBEM
579 || ins.handler_idx == WINED3DSIH_TEXBEML
580 || ins.handler_idx == WINED3DSIH_TEXDP3TEX
581 || ins.handler_idx == WINED3DSIH_TEXM3x2TEX
582 || ins.handler_idx == WINED3DSIH_TEXM3x3SPEC
583 || ins.handler_idx == WINED3DSIH_TEXM3x3TEX
584 || ins.handler_idx == WINED3DSIH_TEXM3x3VSPEC
585 || ins.handler_idx == WINED3DSIH_TEXREG2AR
586 || ins.handler_idx == WINED3DSIH_TEXREG2GB
587 || ins.handler_idx == WINED3DSIH_TEXREG2RGB))
588 {
589 /* Fake sampler usage, only set reserved bit and ttype */
590 DWORD sampler_code = dst_param.reg.idx;
591
592 TRACE("Setting fake 2D sampler for 1.x pixelshader\n");
593 reg_maps->sampler_type[sampler_code] = WINED3DSTT_2D;
594
595 /* texbem is only valid with < 1.4 pixel shaders */
596 if (ins.handler_idx == WINED3DSIH_TEXBEM
597 || ins.handler_idx == WINED3DSIH_TEXBEML)
598 {
599 reg_maps->bumpmat[sampler_code] = TRUE;
600 if (ins.handler_idx == WINED3DSIH_TEXBEML)
601 {
602 reg_maps->luminanceparams[sampler_code] = TRUE;
603 }
604 }
605 }
606 else if (pshader && ins.handler_idx == WINED3DSIH_BEM)
607 {
608 reg_maps->bumpmat[dst_param.reg.idx] = TRUE;
609 }
610 }
611
612 if (ins.handler_idx == WINED3DSIH_NRM)
613 {
614 reg_maps->usesnrm = 1;
615 }
616 else if (ins.handler_idx == WINED3DSIH_DSY)
617 {
618 reg_maps->usesdsy = 1;
619 }
620 else if(ins.handler_idx == WINED3DSIH_TEXLDD)
621 {
622 reg_maps->usestexldd = 1;
623 }
624
625 limit = ins.src_count + (ins.predicate ? 1 : 0);
626 for (i = 0; i < limit; ++i)
627 {
628 struct wined3d_shader_src_param src_param, src_rel_addr;
629
630 fe->shader_read_src_param(fe_data, &pToken, &src_param, &src_rel_addr);
631 switch(get_instr_regcount(ins.handler_idx, i))
632 {
633 case 4:
634 shader_record_register_usage(This, reg_maps, src_param.reg.type,
635 src_param.reg.idx + 3, !!src_param.reg.rel_addr, pshader);
636 /* drop through */
637 case 3:
638 shader_record_register_usage(This, reg_maps, src_param.reg.type,
639 src_param.reg.idx + 2, !!src_param.reg.rel_addr, pshader);
640 /* drop through */
641 case 2:
642 shader_record_register_usage(This, reg_maps, src_param.reg.type,
643 src_param.reg.idx + 1, !!src_param.reg.rel_addr, pshader);
644 /* drop through */
645 case 1:
646 shader_record_register_usage(This, reg_maps, src_param.reg.type,
647 src_param.reg.idx, !!src_param.reg.rel_addr, pshader);
648 }
649 }
650 }
651 }
652 reg_maps->loop_depth = max_loop_depth;
653
654 This->baseShader.functionLength = ((char *)pToken - (char *)byte_code);
655
656 return WINED3D_OK;
657}
658
659static void shader_dump_decl_usage(const struct wined3d_shader_semantic *semantic,
660 const struct wined3d_shader_version *shader_version)
661{
662 TRACE("dcl");
663
664 if (semantic->reg.reg.type == WINED3DSPR_SAMPLER)
665 {
666 switch (semantic->sampler_type)
667 {
668 case WINED3DSTT_2D: TRACE("_2d"); break;
669 case WINED3DSTT_CUBE: TRACE("_cube"); break;
670 case WINED3DSTT_VOLUME: TRACE("_volume"); break;
671 default: TRACE("_unknown_ttype(0x%08x)", semantic->sampler_type);
672 }
673 }
674 else
675 {
676 /* Pixel shaders 3.0 don't have usage semantics */
677 if (shader_is_pshader_version(shader_version->type) && shader_version->major < 3)
678 return;
679 else
680 TRACE("_");
681
682 switch (semantic->usage)
683 {
684 case WINED3DDECLUSAGE_POSITION:
685 TRACE("position%d", semantic->usage_idx);
686 break;
687 case WINED3DDECLUSAGE_BLENDINDICES:
688 TRACE("blend");
689 break;
690 case WINED3DDECLUSAGE_BLENDWEIGHT:
691 TRACE("weight");
692 break;
693 case WINED3DDECLUSAGE_NORMAL:
694 TRACE("normal%d", semantic->usage_idx);
695 break;
696 case WINED3DDECLUSAGE_PSIZE:
697 TRACE("psize");
698 break;
699 case WINED3DDECLUSAGE_COLOR:
700 if (semantic->usage_idx == 0) TRACE("color");
701 else TRACE("specular%d", (semantic->usage_idx - 1));
702 break;
703 case WINED3DDECLUSAGE_TEXCOORD:
704 TRACE("texture%d", semantic->usage_idx);
705 break;
706 case WINED3DDECLUSAGE_TANGENT:
707 TRACE("tangent");
708 break;
709 case WINED3DDECLUSAGE_BINORMAL:
710 TRACE("binormal");
711 break;
712 case WINED3DDECLUSAGE_TESSFACTOR:
713 TRACE("tessfactor");
714 break;
715 case WINED3DDECLUSAGE_POSITIONT:
716 TRACE("positionT%d", semantic->usage_idx);
717 break;
718 case WINED3DDECLUSAGE_FOG:
719 TRACE("fog");
720 break;
721 case WINED3DDECLUSAGE_DEPTH:
722 TRACE("depth");
723 break;
724 case WINED3DDECLUSAGE_SAMPLE:
725 TRACE("sample");
726 break;
727 default:
728 FIXME("unknown_semantics(0x%08x)", semantic->usage);
729 }
730 }
731}
732
733static void shader_dump_register(WINED3DSHADER_PARAM_REGISTER_TYPE register_type, UINT register_idx,
734 enum wined3d_immconst_type immconst_type, const DWORD *immconst_data,
735 const struct wined3d_shader_src_param *rel_addr, const struct wined3d_shader_version *shader_version)
736{
737 static const char * const rastout_reg_names[] = {"oPos", "oFog", "oPts"};
738 static const char * const misctype_reg_names[] = {"vPos", "vFace"};
739 UINT offset = register_idx;
740
741 switch (register_type)
742 {
743 case WINED3DSPR_TEMP:
744 TRACE("r");
745 break;
746
747 case WINED3DSPR_INPUT:
748 TRACE("v");
749 break;
750
751 case WINED3DSPR_CONST:
752 case WINED3DSPR_CONST2:
753 case WINED3DSPR_CONST3:
754 case WINED3DSPR_CONST4:
755 TRACE("c");
756 offset = shader_get_float_offset(register_type, register_idx);
757 break;
758
759 case WINED3DSPR_TEXTURE: /* vs: case WINED3DSPR_ADDR */
760 TRACE("%c", shader_is_pshader_version(shader_version->type) ? 't' : 'a');
761 break;
762
763 case WINED3DSPR_RASTOUT:
764 TRACE("%s", rastout_reg_names[register_idx]);
765 break;
766
767 case WINED3DSPR_COLOROUT:
768 TRACE("oC");
769 break;
770
771 case WINED3DSPR_DEPTHOUT:
772 TRACE("oDepth");
773 break;
774
775 case WINED3DSPR_ATTROUT:
776 TRACE("oD");
777 break;
778
779 case WINED3DSPR_TEXCRDOUT:
780 /* Vertex shaders >= 3.0 use general purpose output registers
781 * (WINED3DSPR_OUTPUT), which can include an address token */
782 if (shader_version->major >= 3) TRACE("o");
783 else TRACE("oT");
784 break;
785
786 case WINED3DSPR_CONSTINT:
787 TRACE("i");
788 break;
789
790 case WINED3DSPR_CONSTBOOL:
791 TRACE("b");
792 break;
793
794 case WINED3DSPR_LABEL:
795 TRACE("l");
796 break;
797
798 case WINED3DSPR_LOOP:
799 TRACE("aL");
800 break;
801
802 case WINED3DSPR_SAMPLER:
803 TRACE("s");
804 break;
805
806 case WINED3DSPR_MISCTYPE:
807 if (register_idx > 1) FIXME("Unhandled misctype register %d\n", register_idx);
808 else TRACE("%s", misctype_reg_names[register_idx]);
809 break;
810
811 case WINED3DSPR_PREDICATE:
812 TRACE("p");
813 break;
814
815 case WINED3DSPR_IMMCONST:
816 TRACE("l");
817 break;
818
819 default:
820 TRACE("unhandled_rtype(%#x)", register_type);
821 break;
822 }
823
824 if (register_type == WINED3DSPR_IMMCONST)
825 {
826 TRACE("(");
827 switch (immconst_type)
828 {
829 case WINED3D_IMMCONST_FLOAT:
830 TRACE("%.8e", *(float *)immconst_data);
831 break;
832
833 case WINED3D_IMMCONST_FLOAT4:
834 TRACE("%.8e, %.8e, %.8e, %.8e",
835 *(float *)&immconst_data[0], *(float *)&immconst_data[1],
836 *(float *)&immconst_data[2], *(float *)&immconst_data[3]);
837 break;
838
839 default:
840 TRACE("<unhandled immconst_type %#x>", immconst_type);
841 break;
842 }
843 TRACE(")");
844 }
845 else if (register_type != WINED3DSPR_RASTOUT && register_type != WINED3DSPR_MISCTYPE)
846 {
847 if (rel_addr)
848 {
849 TRACE("[");
850 shader_dump_src_param(rel_addr, shader_version);
851 TRACE(" + ");
852 }
853 TRACE("%u", offset);
854 if (rel_addr) TRACE("]");
855 }
856}
857
858void shader_dump_dst_param(const struct wined3d_shader_dst_param *param,
859 const struct wined3d_shader_version *shader_version)
860{
861 DWORD write_mask = param->write_mask;
862
863 shader_dump_register(param->reg.type, param->reg.idx, 0, NULL, param->reg.rel_addr, shader_version);
864
865 if (write_mask != WINED3DSP_WRITEMASK_ALL)
866 {
867 static const char *write_mask_chars = "xyzw";
868
869 TRACE(".");
870 if (write_mask & WINED3DSP_WRITEMASK_0) TRACE("%c", write_mask_chars[0]);
871 if (write_mask & WINED3DSP_WRITEMASK_1) TRACE("%c", write_mask_chars[1]);
872 if (write_mask & WINED3DSP_WRITEMASK_2) TRACE("%c", write_mask_chars[2]);
873 if (write_mask & WINED3DSP_WRITEMASK_3) TRACE("%c", write_mask_chars[3]);
874 }
875}
876
877void shader_dump_src_param(const struct wined3d_shader_src_param *param,
878 const struct wined3d_shader_version *shader_version)
879{
880 DWORD src_modifier = param->modifiers;
881 DWORD swizzle = param->swizzle;
882
883 if (src_modifier == WINED3DSPSM_NEG
884 || src_modifier == WINED3DSPSM_BIASNEG
885 || src_modifier == WINED3DSPSM_SIGNNEG
886 || src_modifier == WINED3DSPSM_X2NEG
887 || src_modifier == WINED3DSPSM_ABSNEG)
888 TRACE("-");
889 else if (src_modifier == WINED3DSPSM_COMP)
890 TRACE("1-");
891 else if (src_modifier == WINED3DSPSM_NOT)
892 TRACE("!");
893
894 if (src_modifier == WINED3DSPSM_ABS || src_modifier == WINED3DSPSM_ABSNEG)
895 TRACE("abs(");
896
897 shader_dump_register(param->reg.type, param->reg.idx, param->reg.immconst_type,
898 param->reg.immconst_data, param->reg.rel_addr, shader_version);
899
900 if (src_modifier)
901 {
902 switch (src_modifier)
903 {
904 case WINED3DSPSM_NONE: break;
905 case WINED3DSPSM_NEG: break;
906 case WINED3DSPSM_NOT: break;
907 case WINED3DSPSM_BIAS: TRACE("_bias"); break;
908 case WINED3DSPSM_BIASNEG: TRACE("_bias"); break;
909 case WINED3DSPSM_SIGN: TRACE("_bx2"); break;
910 case WINED3DSPSM_SIGNNEG: TRACE("_bx2"); break;
911 case WINED3DSPSM_COMP: break;
912 case WINED3DSPSM_X2: TRACE("_x2"); break;
913 case WINED3DSPSM_X2NEG: TRACE("_x2"); break;
914 case WINED3DSPSM_DZ: TRACE("_dz"); break;
915 case WINED3DSPSM_DW: TRACE("_dw"); break;
916 case WINED3DSPSM_ABSNEG: TRACE(")"); break;
917 case WINED3DSPSM_ABS: TRACE(")"); break;
918 default:
919 TRACE("_unknown_modifier(%#x)", src_modifier);
920 }
921 }
922
923 if (swizzle != WINED3DSP_NOSWIZZLE)
924 {
925 static const char *swizzle_chars = "xyzw";
926 DWORD swizzle_x = swizzle & 0x03;
927 DWORD swizzle_y = (swizzle >> 2) & 0x03;
928 DWORD swizzle_z = (swizzle >> 4) & 0x03;
929 DWORD swizzle_w = (swizzle >> 6) & 0x03;
930
931 if (swizzle_x == swizzle_y
932 && swizzle_x == swizzle_z
933 && swizzle_x == swizzle_w)
934 {
935 TRACE(".%c", swizzle_chars[swizzle_x]);
936 }
937 else
938 {
939 TRACE(".%c%c%c%c", swizzle_chars[swizzle_x], swizzle_chars[swizzle_y],
940 swizzle_chars[swizzle_z], swizzle_chars[swizzle_w]);
941 }
942 }
943}
944
945/* Shared code in order to generate the bulk of the shader string.
946 * NOTE: A description of how to parse tokens can be found on msdn */
947void shader_generate_main(IWineD3DBaseShader *iface, SHADER_BUFFER *buffer,
948 const shader_reg_maps *reg_maps, const DWORD *pFunction)
949{
950 IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
951 IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device; /* To access shader backend callbacks */
952 const SHADER_HANDLER *handler_table = device->shader_backend->shader_instruction_handler_table;
953 const struct wined3d_shader_frontend *fe = This->baseShader.frontend;
954 void *fe_data = This->baseShader.frontend_data;
955 struct wined3d_shader_src_param src_rel_addr[4];
956 struct wined3d_shader_src_param src_param[4];
957 struct wined3d_shader_version shader_version;
958 struct wined3d_shader_src_param dst_rel_addr;
959 struct wined3d_shader_dst_param dst_param;
960 struct wined3d_shader_instruction ins;
961 struct wined3d_shader_context ctx;
962 const DWORD *pToken = pFunction;
963 SHADER_HANDLER hw_fct;
964 DWORD i;
965
966 /* Initialize current parsing state */
967 ctx.shader = iface;
968 ctx.reg_maps = reg_maps;
969 ctx.buffer = buffer;
970
971 ins.ctx = &ctx;
972 ins.dst = &dst_param;
973 ins.src = src_param;
974 This->baseShader.parse_state.current_row = 0;
975
976 fe->shader_read_header(fe_data, &pToken, &shader_version);
977
978 while (!fe->shader_is_end(fe_data, &pToken))
979 {
980 const char *comment;
981 UINT param_size;
982
983 /* Skip comment tokens */
984 fe->shader_read_comment(&pToken, &comment);
985 if (comment) continue;
986
987 /* Read opcode */
988 fe->shader_read_opcode(fe_data, &pToken, &ins, &param_size);
989
990 /* Unknown opcode and its parameters */
991 if (ins.handler_idx == WINED3DSIH_TABLE_SIZE)
992 {
993 TRACE("Skipping unrecognized instruction.\n");
994 pToken += param_size;
995 continue;
996 }
997
998 /* Nothing to do */
999 if (ins.handler_idx == WINED3DSIH_DCL
1000 || ins.handler_idx == WINED3DSIH_NOP
1001 || ins.handler_idx == WINED3DSIH_DEF
1002 || ins.handler_idx == WINED3DSIH_DEFI
1003 || ins.handler_idx == WINED3DSIH_DEFB
1004 || ins.handler_idx == WINED3DSIH_PHASE
1005 || ins.handler_idx == WINED3DSIH_RET)
1006 {
1007 pToken += param_size;
1008 continue;
1009 }
1010
1011 /* Select handler */
1012 hw_fct = handler_table[ins.handler_idx];
1013
1014 /* Unhandled opcode */
1015 if (!hw_fct)
1016 {
1017 FIXME("Backend can't handle opcode %#x\n", ins.handler_idx);
1018 pToken += param_size;
1019 continue;
1020 }
1021
1022 /* Destination token */
1023 if (ins.dst_count) fe->shader_read_dst_param(fe_data, &pToken, &dst_param, &dst_rel_addr);
1024
1025 /* Predication token */
1026 if (ins.predicate) ins.predicate = *pToken++;
1027
1028 /* Other source tokens */
1029 for (i = 0; i < ins.src_count; ++i)
1030 {
1031 fe->shader_read_src_param(fe_data, &pToken, &src_param[i], &src_rel_addr[i]);
1032 }
1033
1034 /* Call appropriate function for output target */
1035 hw_fct(&ins);
1036
1037 /* Process instruction modifiers for GLSL apps ( _sat, etc. ) */
1038 device->shader_backend->shader_add_instruction_modifiers(&ins);
1039 }
1040}
1041
1042static void shader_dump_ins_modifiers(const struct wined3d_shader_dst_param *dst)
1043{
1044 DWORD mmask = dst->modifiers;
1045
1046 switch (dst->shift)
1047 {
1048 case 0: break;
1049 case 13: TRACE("_d8"); break;
1050 case 14: TRACE("_d4"); break;
1051 case 15: TRACE("_d2"); break;
1052 case 1: TRACE("_x2"); break;
1053 case 2: TRACE("_x4"); break;
1054 case 3: TRACE("_x8"); break;
1055 default: TRACE("_unhandled_shift(%d)", dst->shift); break;
1056 }
1057
1058 if (mmask & WINED3DSPDM_SATURATE) TRACE("_sat");
1059 if (mmask & WINED3DSPDM_PARTIALPRECISION) TRACE("_pp");
1060 if (mmask & WINED3DSPDM_MSAMPCENTROID) TRACE("_centroid");
1061
1062 mmask &= ~(WINED3DSPDM_SATURATE | WINED3DSPDM_PARTIALPRECISION | WINED3DSPDM_MSAMPCENTROID);
1063 if (mmask)
1064 FIXME("_unrecognized_modifier(%#x)", mmask);
1065}
1066
1067void shader_trace_init(const struct wined3d_shader_frontend *fe, void *fe_data, const DWORD *pFunction)
1068{
1069 struct wined3d_shader_version shader_version;
1070 const DWORD* pToken = pFunction;
1071 DWORD i;
1072
1073 TRACE("Parsing %p\n", pFunction);
1074
1075 fe->shader_read_header(fe_data, &pToken, &shader_version);
1076
1077 TRACE("%s_%u_%u\n", shader_is_pshader_version(shader_version.type) ? "ps": "vs",
1078 shader_version.major, shader_version.minor);
1079
1080 while (!fe->shader_is_end(fe_data, &pToken))
1081 {
1082 struct wined3d_shader_instruction ins;
1083 const char *comment;
1084 UINT param_size;
1085
1086 /* comment */
1087 fe->shader_read_comment(&pToken, &comment);
1088 if (comment)
1089 {
1090 TRACE("//%s\n", comment);
1091 continue;
1092 }
1093
1094 fe->shader_read_opcode(fe_data, &pToken, &ins, &param_size);
1095 if (ins.handler_idx == WINED3DSIH_TABLE_SIZE)
1096 {
1097 TRACE("Skipping unrecognized instruction.\n");
1098 pToken += param_size;
1099 continue;
1100 }
1101
1102 if (ins.handler_idx == WINED3DSIH_DCL)
1103 {
1104 struct wined3d_shader_semantic semantic;
1105
1106 fe->shader_read_semantic(&pToken, &semantic);
1107
1108 shader_dump_decl_usage(&semantic, &shader_version);
1109 shader_dump_ins_modifiers(&semantic.reg);
1110 TRACE(" ");
1111 shader_dump_dst_param(&semantic.reg, &shader_version);
1112 }
1113 else if (ins.handler_idx == WINED3DSIH_DEF)
1114 {
1115 struct wined3d_shader_dst_param dst;
1116 struct wined3d_shader_src_param rel_addr;
1117
1118 fe->shader_read_dst_param(fe_data, &pToken, &dst, &rel_addr);
1119
1120 TRACE("def c%u = %f, %f, %f, %f", shader_get_float_offset(dst.reg.type, dst.reg.idx),
1121 *(const float *)(pToken),
1122 *(const float *)(pToken + 1),
1123 *(const float *)(pToken + 2),
1124 *(const float *)(pToken + 3));
1125 pToken += 4;
1126 }
1127 else if (ins.handler_idx == WINED3DSIH_DEFI)
1128 {
1129 struct wined3d_shader_dst_param dst;
1130 struct wined3d_shader_src_param rel_addr;
1131
1132 fe->shader_read_dst_param(fe_data, &pToken, &dst, &rel_addr);
1133
1134 TRACE("defi i%u = %d, %d, %d, %d", dst.reg.idx,
1135 *(pToken),
1136 *(pToken + 1),
1137 *(pToken + 2),
1138 *(pToken + 3));
1139 pToken += 4;
1140 }
1141 else if (ins.handler_idx == WINED3DSIH_DEFB)
1142 {
1143 struct wined3d_shader_dst_param dst;
1144 struct wined3d_shader_src_param rel_addr;
1145
1146 fe->shader_read_dst_param(fe_data, &pToken, &dst, &rel_addr);
1147
1148 TRACE("defb b%u = %s", dst.reg.idx, *pToken ? "true" : "false");
1149 ++pToken;
1150 }
1151 else
1152 {
1153 struct wined3d_shader_src_param dst_rel_addr, src_rel_addr;
1154 struct wined3d_shader_dst_param dst_param;
1155 struct wined3d_shader_src_param src_param;
1156
1157 if (ins.dst_count)
1158 {
1159 fe->shader_read_dst_param(fe_data, &pToken, &dst_param, &dst_rel_addr);
1160 }
1161
1162 /* Print out predication source token first - it follows
1163 * the destination token. */
1164 if (ins.predicate)
1165 {
1166 fe->shader_read_src_param(fe_data, &pToken, &src_param, &src_rel_addr);
1167 TRACE("(");
1168 shader_dump_src_param(&src_param, &shader_version);
1169 TRACE(") ");
1170 }
1171
1172 /* PixWin marks instructions with the coissue flag with a '+' */
1173 if (ins.coissue) TRACE("+");
1174
1175 TRACE("%s", shader_opcode_names[ins.handler_idx]);
1176
1177 if (ins.handler_idx == WINED3DSIH_IFC
1178 || ins.handler_idx == WINED3DSIH_BREAKC)
1179 {
1180 switch (ins.flags)
1181 {
1182 case COMPARISON_GT: TRACE("_gt"); break;
1183 case COMPARISON_EQ: TRACE("_eq"); break;
1184 case COMPARISON_GE: TRACE("_ge"); break;
1185 case COMPARISON_LT: TRACE("_lt"); break;
1186 case COMPARISON_NE: TRACE("_ne"); break;
1187 case COMPARISON_LE: TRACE("_le"); break;
1188 default: TRACE("_(%u)", ins.flags);
1189 }
1190 }
1191 else if (ins.handler_idx == WINED3DSIH_TEX
1192 && shader_version.major >= 2
1193 && (ins.flags & WINED3DSI_TEXLD_PROJECT))
1194 {
1195 TRACE("p");
1196 }
1197
1198 /* We already read the destination token, print it. */
1199 if (ins.dst_count)
1200 {
1201 shader_dump_ins_modifiers(&dst_param);
1202 TRACE(" ");
1203 shader_dump_dst_param(&dst_param, &shader_version);
1204 }
1205
1206 /* Other source tokens */
1207 for (i = ins.dst_count; i < (ins.dst_count + ins.src_count); ++i)
1208 {
1209 fe->shader_read_src_param(fe_data, &pToken, &src_param, &src_rel_addr);
1210 TRACE(!i ? " " : ", ");
1211 shader_dump_src_param(&src_param, &shader_version);
1212 }
1213 }
1214 TRACE("\n");
1215 }
1216}
1217
1218void shader_cleanup(IWineD3DBaseShader *iface)
1219{
1220 IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)iface;
1221
1222 ((IWineD3DDeviceImpl *)This->baseShader.device)->shader_backend->shader_destroy(iface);
1223 HeapFree(GetProcessHeap(), 0, This->baseShader.reg_maps.constf);
1224 HeapFree(GetProcessHeap(), 0, This->baseShader.function);
1225 shader_delete_constant_list(&This->baseShader.constantsF);
1226 shader_delete_constant_list(&This->baseShader.constantsB);
1227 shader_delete_constant_list(&This->baseShader.constantsI);
1228 list_remove(&This->baseShader.shader_list_entry);
1229
1230 if (This->baseShader.frontend && This->baseShader.frontend_data)
1231 {
1232 This->baseShader.frontend->shader_free(This->baseShader.frontend_data);
1233 }
1234}
1235
1236static const SHADER_HANDLER shader_none_instruction_handler_table[WINED3DSIH_TABLE_SIZE] = {0};
1237static void shader_none_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {}
1238static void shader_none_select_depth_blt(IWineD3DDevice *iface, enum tex_types tex_type) {}
1239static void shader_none_deselect_depth_blt(IWineD3DDevice *iface) {}
1240static void shader_none_update_float_vertex_constants(IWineD3DDevice *iface, UINT start, UINT count) {}
1241static void shader_none_update_float_pixel_constants(IWineD3DDevice *iface, UINT start, UINT count) {}
1242static void shader_none_load_constants(IWineD3DDevice *iface, char usePS, char useVS) {}
1243static void shader_none_load_np2fixup_constants(IWineD3DDevice *iface, char usePS, char useVS) {}
1244static void shader_none_destroy(IWineD3DBaseShader *iface) {}
1245static HRESULT shader_none_alloc(IWineD3DDevice *iface) {return WINED3D_OK;}
1246static void shader_none_free(IWineD3DDevice *iface) {}
1247static BOOL shader_none_dirty_const(IWineD3DDevice *iface) {return FALSE;}
1248static GLuint shader_none_generate_pshader(IWineD3DPixelShader *iface,
1249 SHADER_BUFFER *buffer, const struct ps_compile_args *args)
1250{
1251 FIXME("NONE shader backend asked to generate a pixel shader\n");
1252 return 0;
1253}
1254static GLuint shader_none_generate_vshader(IWineD3DVertexShader *iface,
1255 SHADER_BUFFER *buffer, const struct vs_compile_args *args)
1256{
1257 FIXME("NONE shader backend asked to generate a vertex shader\n");
1258 return 0;
1259}
1260static void shader_none_add_instruction_modifiers(const struct wined3d_shader_instruction *ins) {}
1261
1262#define GLINFO_LOCATION (*gl_info)
1263static void shader_none_get_caps(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct shader_caps *pCaps)
1264{
1265 /* Set the shader caps to 0 for the none shader backend */
1266 pCaps->VertexShaderVersion = 0;
1267 pCaps->PixelShaderVersion = 0;
1268 pCaps->PixelShader1xMaxValue = 0.0;
1269}
1270#undef GLINFO_LOCATION
1271static BOOL shader_none_color_fixup_supported(struct color_fixup_desc fixup)
1272{
1273 if (TRACE_ON(d3d_shader) && TRACE_ON(d3d))
1274 {
1275 TRACE("Checking support for fixup:\n");
1276 dump_color_fixup_desc(fixup);
1277 }
1278
1279 /* Faked to make some apps happy. */
1280 if (!is_yuv_fixup(fixup))
1281 {
1282 TRACE("[OK]\n");
1283 return TRUE;
1284 }
1285
1286 TRACE("[FAILED]\n");
1287 return FALSE;
1288}
1289
1290const shader_backend_t none_shader_backend = {
1291 shader_none_instruction_handler_table,
1292 shader_none_select,
1293 shader_none_select_depth_blt,
1294 shader_none_deselect_depth_blt,
1295 shader_none_update_float_vertex_constants,
1296 shader_none_update_float_pixel_constants,
1297 shader_none_load_constants,
1298 shader_none_load_np2fixup_constants,
1299 shader_none_destroy,
1300 shader_none_alloc,
1301 shader_none_free,
1302 shader_none_dirty_const,
1303 shader_none_generate_pshader,
1304 shader_none_generate_vshader,
1305 shader_none_get_caps,
1306 shader_none_color_fixup_supported,
1307 shader_none_add_instruction_modifiers,
1308};
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette