VirtualBox

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

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

LGPL disclaimer by filemuncher

  • Property svn:eol-style set to native
File size: 47.4 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 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26/*
27 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
28 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
29 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
30 * a choice of LGPL license versions is made available with the language indicating
31 * that LGPLv2 or any later version may be used, or where a choice of which version
32 * of the LGPL is applied is otherwise unspecified.
33 */
34
35#include "config.h"
36#include <string.h>
37#include <stdio.h>
38#include "wined3d_private.h"
39
40WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
41WINE_DECLARE_DEBUG_CHANNEL(d3d);
42
43#define GLNAME_REQUIRE_GLSL ((const char *)1)
44
45static void shader_dump_param(const DWORD param, const DWORD addr_token, int input, DWORD shader_version);
46
47static inline BOOL shader_is_version_token(DWORD token) {
48 return shader_is_pshader_version(token) ||
49 shader_is_vshader_version(token);
50}
51
52int shader_addline(
53 SHADER_BUFFER* buffer,
54 const char *format, ...) {
55
56 char* base = buffer->buffer + buffer->bsize;
57 int rc;
58
59 va_list args;
60 va_start(args, format);
61 rc = _vsnprintf(base, SHADER_PGMSIZE - 1 - buffer->bsize, format, args);
62 va_end(args);
63
64 if (rc < 0 || /* C89 */
65 rc > SHADER_PGMSIZE - 1 - buffer->bsize) { /* C99 */
66
67 ERR("The buffer allocated for the shader program string "
68 "is too small at %d bytes.\n", SHADER_PGMSIZE);
69 buffer->bsize = SHADER_PGMSIZE - 1;
70 return -1;
71 }
72
73 if (buffer->newline) {
74 TRACE("GL HW (%u, %u) : %s", buffer->lineNo + 1, buffer->bsize, base);
75 buffer->newline = FALSE;
76 } else {
77 TRACE("%s", base);
78 }
79
80 buffer->bsize += rc;
81 if (buffer->buffer[buffer->bsize-1] == '\n') {
82 buffer->lineNo++;
83 buffer->newline = TRUE;
84 }
85 return 0;
86}
87
88const SHADER_OPCODE *shader_get_opcode(const SHADER_OPCODE *opcode_table, DWORD shader_version, DWORD code)
89{
90 DWORD i = 0;
91
92 /** TODO: use dichotomic search */
93 while (opcode_table[i].name)
94 {
95 if ((code & WINED3DSI_OPCODE_MASK) == opcode_table[i].opcode
96 && shader_version >= opcode_table[i].min_version
97 && (!opcode_table[i].max_version || shader_version <= opcode_table[i].max_version))
98 {
99 return &opcode_table[i];
100 }
101 ++i;
102 }
103
104 FIXME("Unsupported opcode %#x(%d) masked %#x, shader version %#x\n",
105 code, code, code & WINED3DSI_OPCODE_MASK, shader_version);
106
107 return NULL;
108}
109
110/* Read a parameter opcode from the input stream,
111 * and possibly a relative addressing token.
112 * Return the number of tokens read */
113static int shader_get_param(IWineD3DBaseShader *iface, const DWORD *pToken, DWORD *param, DWORD *addr_token)
114{
115 /* PS >= 3.0 have relative addressing (with token)
116 * VS >= 2.0 have relative addressing (with token)
117 * VS >= 1.0 < 2.0 have relative addressing (without token)
118 * The version check below should work in general */
119
120 IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
121 char rel_token = WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 2 &&
122 ((*pToken & WINED3DSHADER_ADDRESSMODE_MASK) == WINED3DSHADER_ADDRMODE_RELATIVE);
123
124 *param = *pToken;
125 *addr_token = rel_token? *(pToken + 1): 0;
126 return rel_token? 2:1;
127}
128
129/* Return the number of parameters to skip for an opcode */
130static inline int shader_skip_opcode(
131 IWineD3DBaseShaderImpl* This,
132 const SHADER_OPCODE* curOpcode,
133 DWORD opcode_token) {
134
135 /* Shaders >= 2.0 may contain address tokens, but fortunately they
136 * have a useful length mask - use it here. Shaders 1.0 contain no such tokens */
137
138 return (WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 2)?
139 ((opcode_token & WINED3DSI_INSTLENGTH_MASK) >> WINED3DSI_INSTLENGTH_SHIFT):
140 curOpcode->num_params;
141}
142
143/* Read the parameters of an unrecognized opcode from the input stream
144 * Return the number of tokens read.
145 *
146 * Note: This function assumes source or destination token format.
147 * It will not work with specially-formatted tokens like DEF or DCL,
148 * but hopefully those would be recognized */
149static int shader_skip_unrecognized(IWineD3DBaseShader *iface, const DWORD *pToken)
150{
151 DWORD shader_version = ((IWineD3DBaseShaderImpl *)iface)->baseShader.hex_version;
152 int tokens_read = 0;
153 int i = 0;
154
155 /* TODO: Think of a good name for 0x80000000 and replace it with a constant */
156 while (*pToken & 0x80000000) {
157
158 DWORD param, addr_token;
159 tokens_read += shader_get_param(iface, pToken, &param, &addr_token);
160 pToken += tokens_read;
161
162 FIXME("Unrecognized opcode param: token=0x%08x "
163 "addr_token=0x%08x name=", param, addr_token);
164 shader_dump_param(param, addr_token, i, shader_version);
165 FIXME("\n");
166 ++i;
167 }
168 return tokens_read;
169}
170
171/* Convert floating point offset relative
172 * to a register file to an absolute offset for float constants */
173static unsigned int shader_get_float_offset(const DWORD reg)
174{
175 unsigned int regnum = reg & WINED3DSP_REGNUM_MASK;
176 int regtype = shader_get_regtype(reg);
177
178 switch (regtype) {
179 case WINED3DSPR_CONST: return regnum;
180 case WINED3DSPR_CONST2: return 2048 + regnum;
181 case WINED3DSPR_CONST3: return 4096 + regnum;
182 case WINED3DSPR_CONST4: return 6144 + regnum;
183 default:
184 FIXME("Unsupported register type: %d\n", regtype);
185 return regnum;
186 }
187}
188
189static void shader_delete_constant_list(struct list* clist) {
190
191 struct list *ptr;
192 struct local_constant* constant;
193
194 ptr = list_head(clist);
195 while (ptr) {
196 constant = LIST_ENTRY(ptr, struct local_constant, entry);
197 ptr = list_next(clist, ptr);
198 HeapFree(GetProcessHeap(), 0, constant);
199 }
200 list_init(clist);
201}
202
203/* Note that this does not count the loop register
204 * as an address register. */
205
206HRESULT shader_get_registers_used(
207 IWineD3DBaseShader *iface,
208 shader_reg_maps* reg_maps,
209 semantic* semantics_in,
210 semantic* semantics_out,
211 CONST DWORD* pToken,
212 IWineD3DStateBlockImpl *stateBlock) {
213
214 IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
215 const SHADER_OPCODE *shader_ins = This->baseShader.shader_ins;
216 DWORD shader_version = This->baseShader.hex_version;
217 unsigned int cur_loop_depth = 0, max_loop_depth = 0;
218
219 /* There are some minor differences between pixel and vertex shaders */
220 char pshader = shader_is_pshader_version(This->baseShader.hex_version);
221
222 memset(reg_maps->bumpmat, 0, sizeof(reg_maps->bumpmat));
223 memset(reg_maps->luminanceparams, 0, sizeof(reg_maps->luminanceparams));
224
225 if (pToken == NULL)
226 return WINED3D_OK;
227
228 /* get_registers_used is called on every compile on some 1.x shaders, which can result
229 * in stacking up a collection of local constants. Delete the old constants if existing
230 */
231 shader_delete_constant_list(&This->baseShader.constantsF);
232 shader_delete_constant_list(&This->baseShader.constantsB);
233 shader_delete_constant_list(&This->baseShader.constantsI);
234
235 while (WINED3DVS_END() != *pToken) {
236 CONST SHADER_OPCODE* curOpcode;
237 DWORD opcode_token;
238
239 /* Skip version */
240 if (shader_is_version_token(*pToken)) {
241 ++pToken;
242 continue;
243
244 /* Skip comments */
245 } else if (shader_is_comment(*pToken)) {
246 DWORD comment_len = (*pToken & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
247 ++pToken;
248 pToken += comment_len;
249 continue;
250 }
251
252 /* Fetch opcode */
253 opcode_token = *pToken++;
254 curOpcode = shader_get_opcode(shader_ins, shader_version, opcode_token);
255
256 /* Unhandled opcode, and its parameters */
257 if (NULL == curOpcode) {
258 while (*pToken & 0x80000000)
259 ++pToken;
260
261 /* Handle declarations */
262 } else if (WINED3DSIO_DCL == curOpcode->opcode) {
263
264 DWORD usage = *pToken++;
265 DWORD param = *pToken++;
266 DWORD regtype = shader_get_regtype(param);
267 unsigned int regnum = param & WINED3DSP_REGNUM_MASK;
268
269 /* Vshader: mark attributes used
270 Pshader: mark 3.0 input registers used, save token */
271 if (WINED3DSPR_INPUT == regtype) {
272
273 if (!pshader)
274 reg_maps->attributes[regnum] = 1;
275 else
276 reg_maps->packed_input[regnum] = 1;
277
278 semantics_in[regnum].usage = usage;
279 semantics_in[regnum].reg = param;
280
281 /* Vshader: mark 3.0 output registers used, save token */
282 } else if (WINED3DSPR_OUTPUT == regtype) {
283 reg_maps->packed_output[regnum] = 1;
284 semantics_out[regnum].usage = usage;
285 semantics_out[regnum].reg = param;
286 if (usage & (WINED3DDECLUSAGE_FOG << WINED3DSP_DCL_USAGE_SHIFT))
287 reg_maps->fog = 1;
288
289 /* Save sampler usage token */
290 } else if (WINED3DSPR_SAMPLER == regtype)
291 reg_maps->samplers[regnum] = usage;
292
293 } else if (WINED3DSIO_DEF == curOpcode->opcode) {
294
295 local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
296 if (!lconst) return E_OUTOFMEMORY;
297 lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
298 memcpy(lconst->value, pToken + 1, 4 * sizeof(DWORD));
299
300 /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
301 if(WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) == 1 && pshader) {
302 float *value = (float *) lconst->value;
303 if(value[0] < -1.0) value[0] = -1.0;
304 else if(value[0] > 1.0) value[0] = 1.0;
305 if(value[1] < -1.0) value[1] = -1.0;
306 else if(value[1] > 1.0) value[1] = 1.0;
307 if(value[2] < -1.0) value[2] = -1.0;
308 else if(value[2] > 1.0) value[2] = 1.0;
309 if(value[3] < -1.0) value[3] = -1.0;
310 else if(value[3] > 1.0) value[3] = 1.0;
311 }
312
313 list_add_head(&This->baseShader.constantsF, &lconst->entry);
314 pToken += curOpcode->num_params;
315
316 } else if (WINED3DSIO_DEFI == curOpcode->opcode) {
317
318 local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
319 if (!lconst) return E_OUTOFMEMORY;
320 lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
321 memcpy(lconst->value, pToken + 1, 4 * sizeof(DWORD));
322 list_add_head(&This->baseShader.constantsI, &lconst->entry);
323 pToken += curOpcode->num_params;
324
325 } else if (WINED3DSIO_DEFB == curOpcode->opcode) {
326
327 local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
328 if (!lconst) return E_OUTOFMEMORY;
329 lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
330 memcpy(lconst->value, pToken + 1, 1 * sizeof(DWORD));
331 list_add_head(&This->baseShader.constantsB, &lconst->entry);
332 pToken += curOpcode->num_params;
333
334 /* If there's a loop in the shader */
335 } else if (WINED3DSIO_LOOP == curOpcode->opcode ||
336 WINED3DSIO_REP == curOpcode->opcode) {
337 cur_loop_depth++;
338 if(cur_loop_depth > max_loop_depth)
339 max_loop_depth = cur_loop_depth;
340 pToken += curOpcode->num_params;
341
342 } else if (WINED3DSIO_ENDLOOP == curOpcode->opcode ||
343 WINED3DSIO_ENDREP == curOpcode->opcode) {
344 cur_loop_depth--;
345
346 /* For subroutine prototypes */
347 } else if (WINED3DSIO_LABEL == curOpcode->opcode) {
348
349 DWORD snum = *pToken & WINED3DSP_REGNUM_MASK;
350 reg_maps->labels[snum] = 1;
351 pToken += curOpcode->num_params;
352
353 /* Set texture, address, temporary registers */
354 } else {
355 int i, limit;
356
357 /* Declare 1.X samplers implicitly, based on the destination reg. number */
358 if (WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) == 1 &&
359 pshader /* Filter different instructions with the same enum values in VS */ &&
360 (WINED3DSIO_TEX == curOpcode->opcode ||
361 WINED3DSIO_TEXBEM == curOpcode->opcode ||
362 WINED3DSIO_TEXBEML == curOpcode->opcode ||
363 WINED3DSIO_TEXDP3TEX == curOpcode->opcode ||
364 WINED3DSIO_TEXM3x2TEX == curOpcode->opcode ||
365 WINED3DSIO_TEXM3x3SPEC == curOpcode->opcode ||
366 WINED3DSIO_TEXM3x3TEX == curOpcode->opcode ||
367 WINED3DSIO_TEXM3x3VSPEC == curOpcode->opcode ||
368 WINED3DSIO_TEXREG2AR == curOpcode->opcode ||
369 WINED3DSIO_TEXREG2GB == curOpcode->opcode ||
370 WINED3DSIO_TEXREG2RGB == curOpcode->opcode)) {
371
372 /* Fake sampler usage, only set reserved bit and ttype */
373 DWORD sampler_code = *pToken & WINED3DSP_REGNUM_MASK;
374
375 if(!stateBlock->textures[sampler_code]) {
376 ERR("No texture bound to sampler %d\n", sampler_code);
377 reg_maps->samplers[sampler_code] = (0x1 << 31) | WINED3DSTT_2D;
378 } else {
379 int texType = IWineD3DBaseTexture_GetTextureDimensions(stateBlock->textures[sampler_code]);
380 switch(texType) {
381 /* We have to select between texture rectangles and 2D textures later because 2.0 and
382 * 3.0 shaders only have WINED3DSTT_2D as well
383 */
384 case GL_TEXTURE_RECTANGLE_ARB:
385 case GL_TEXTURE_2D:
386 reg_maps->samplers[sampler_code] = (0x1 << 31) | WINED3DSTT_2D;
387 break;
388
389 case GL_TEXTURE_3D:
390 reg_maps->samplers[sampler_code] = (0x1 << 31) | WINED3DSTT_VOLUME;
391 break;
392
393 case GL_TEXTURE_CUBE_MAP_ARB:
394 reg_maps->samplers[sampler_code] = (0x1 << 31) | WINED3DSTT_CUBE;
395 break;
396
397 default:
398 ERR("Unexpected gl texture type found: %d\n", texType);
399 reg_maps->samplers[sampler_code] = (0x1 << 31) | WINED3DSTT_2D;
400 }
401 }
402
403 /* texbem is only valid with < 1.4 pixel shaders */
404 if(WINED3DSIO_TEXBEM == curOpcode->opcode ||
405 WINED3DSIO_TEXBEML == curOpcode->opcode) {
406 reg_maps->bumpmat[sampler_code] = TRUE;
407 if(WINED3DSIO_TEXBEML == curOpcode->opcode) {
408 reg_maps->luminanceparams[sampler_code] = TRUE;
409 }
410 }
411 }
412 if(WINED3DSIO_NRM == curOpcode->opcode) {
413 reg_maps->usesnrm = 1;
414 } else if(WINED3DSIO_BEM == curOpcode->opcode && pshader) {
415 DWORD regnum = *pToken & WINED3DSP_REGNUM_MASK;
416 reg_maps->bumpmat[regnum] = TRUE;
417 } else if(WINED3DSIO_DSY == curOpcode->opcode) {
418 reg_maps->usesdsy = 1;
419 }
420
421 /* This will loop over all the registers and try to
422 * make a bitmask of the ones we're interested in.
423 *
424 * Relative addressing tokens are ignored, but that's
425 * okay, since we'll catch any address registers when
426 * they are initialized (required by spec) */
427
428 limit = (opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED)?
429 curOpcode->num_params + 1: curOpcode->num_params;
430
431 for (i = 0; i < limit; ++i) {
432
433 DWORD param, addr_token, reg, regtype;
434 pToken += shader_get_param(iface, pToken, &param, &addr_token);
435
436 regtype = shader_get_regtype(param);
437 reg = param & WINED3DSP_REGNUM_MASK;
438
439 if (WINED3DSPR_TEXTURE == regtype) { /* vs: WINED3DSPR_ADDR */
440
441 if (pshader)
442 reg_maps->texcoord[reg] = 1;
443 else
444 reg_maps->address[reg] = 1;
445 }
446
447 else if (WINED3DSPR_TEMP == regtype)
448 reg_maps->temporary[reg] = 1;
449
450 else if (WINED3DSPR_INPUT == regtype) {
451 if( !pshader)
452 reg_maps->attributes[reg] = 1;
453 else {
454 if(param & WINED3DSHADER_ADDRMODE_RELATIVE) {
455 /* If relative addressing is used, we must assume that all registers
456 * are used. Even if it is a construct like v3[aL], we can't assume
457 * that v0, v1 and v2 aren't read because aL can be negative
458 */
459 unsigned int i;
460 for(i = 0; i < MAX_REG_INPUT; i++) {
461 ((IWineD3DPixelShaderImpl *) This)->input_reg_used[i] = TRUE;
462 }
463 } else {
464 ((IWineD3DPixelShaderImpl *) This)->input_reg_used[reg] = TRUE;
465 }
466 }
467 }
468
469 else if (WINED3DSPR_RASTOUT == regtype && reg == 1)
470 reg_maps->fog = 1;
471
472 else if (WINED3DSPR_MISCTYPE == regtype && reg == 0 && pshader)
473 reg_maps->vpos = 1;
474
475 else if(WINED3DSPR_CONST == regtype) {
476 if(param & WINED3DSHADER_ADDRMODE_RELATIVE) {
477 if(!pshader) {
478 if(reg <= ((IWineD3DVertexShaderImpl *) This)->min_rel_offset) {
479 ((IWineD3DVertexShaderImpl *) This)->min_rel_offset = reg;
480 } else if(reg >= ((IWineD3DVertexShaderImpl *) This)->max_rel_offset) {
481 ((IWineD3DVertexShaderImpl *) This)->max_rel_offset = reg;
482 }
483 }
484 reg_maps->usesrelconstF = TRUE;
485 }
486 }
487
488 /* WINED3DSPR_TEXCRDOUT is the same as WINED3DSPR_OUTPUT. _OUTPUT can be > MAX_REG_TEXCRD and is used
489 * in >= 3.0 shaders. Filter 3.0 shaders to prevent overflows, and also filter pixel shaders because TECRDOUT
490 * isn't used in them, but future register types might cause issues
491 */
492 else if(WINED3DSPR_TEXCRDOUT == regtype && i == 0 /* Only look at writes */ &&
493 !pshader && WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) < 3) {
494 reg_maps->texcoord_mask[reg] |= shader_get_writemask(param);
495 }
496 }
497 }
498 }
499 reg_maps->loop_depth = max_loop_depth;
500
501 return WINED3D_OK;
502}
503
504static void shader_dump_decl_usage(DWORD decl, DWORD param, DWORD shader_version)
505{
506 DWORD regtype = shader_get_regtype(param);
507
508 TRACE("dcl");
509
510 if (regtype == WINED3DSPR_SAMPLER) {
511 DWORD ttype = decl & WINED3DSP_TEXTURETYPE_MASK;
512
513 switch (ttype) {
514 case WINED3DSTT_2D: TRACE("_2d"); break;
515 case WINED3DSTT_CUBE: TRACE("_cube"); break;
516 case WINED3DSTT_VOLUME: TRACE("_volume"); break;
517 default: TRACE("_unknown_ttype(0x%08x)", ttype);
518 }
519
520 } else {
521
522 DWORD usage = decl & WINED3DSP_DCL_USAGE_MASK;
523 DWORD idx = (decl & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
524
525 /* Pixel shaders 3.0 don't have usage semantics */
526 if (shader_is_pshader_version(shader_version) && shader_version < WINED3DPS_VERSION(3,0))
527 return;
528 else
529 TRACE("_");
530
531 switch(usage) {
532 case WINED3DDECLUSAGE_POSITION:
533 TRACE("position%d", idx);
534 break;
535 case WINED3DDECLUSAGE_BLENDINDICES:
536 TRACE("blend");
537 break;
538 case WINED3DDECLUSAGE_BLENDWEIGHT:
539 TRACE("weight");
540 break;
541 case WINED3DDECLUSAGE_NORMAL:
542 TRACE("normal%d", idx);
543 break;
544 case WINED3DDECLUSAGE_PSIZE:
545 TRACE("psize");
546 break;
547 case WINED3DDECLUSAGE_COLOR:
548 if(idx == 0) {
549 TRACE("color");
550 } else {
551 TRACE("specular%d", (idx - 1));
552 }
553 break;
554 case WINED3DDECLUSAGE_TEXCOORD:
555 TRACE("texture%d", idx);
556 break;
557 case WINED3DDECLUSAGE_TANGENT:
558 TRACE("tangent");
559 break;
560 case WINED3DDECLUSAGE_BINORMAL:
561 TRACE("binormal");
562 break;
563 case WINED3DDECLUSAGE_TESSFACTOR:
564 TRACE("tessfactor");
565 break;
566 case WINED3DDECLUSAGE_POSITIONT:
567 TRACE("positionT%d", idx);
568 break;
569 case WINED3DDECLUSAGE_FOG:
570 TRACE("fog");
571 break;
572 case WINED3DDECLUSAGE_DEPTH:
573 TRACE("depth");
574 break;
575 case WINED3DDECLUSAGE_SAMPLE:
576 TRACE("sample");
577 break;
578 default:
579 FIXME("unknown_semantics(0x%08x)", usage);
580 }
581 }
582}
583
584static void shader_dump_arr_entry(const DWORD param, const DWORD addr_token,
585 unsigned int reg, int input, DWORD shader_version)
586{
587 char relative =
588 ((param & WINED3DSHADER_ADDRESSMODE_MASK) == WINED3DSHADER_ADDRMODE_RELATIVE);
589
590 if (relative) {
591 TRACE("[");
592 if (addr_token)
593 shader_dump_param(addr_token, 0, input, shader_version);
594 else
595 TRACE("a0.x");
596 TRACE(" + ");
597 }
598 TRACE("%u", reg);
599 if (relative)
600 TRACE("]");
601}
602
603static void shader_dump_param(const DWORD param, const DWORD addr_token, int input, DWORD shader_version)
604{
605 static const char * const rastout_reg_names[] = { "oPos", "oFog", "oPts" };
606 static const char * const misctype_reg_names[] = { "vPos", "vFace"};
607 char swizzle_reg_chars[4];
608
609 DWORD reg = param & WINED3DSP_REGNUM_MASK;
610 DWORD regtype = shader_get_regtype(param);
611 DWORD modifier = param & WINED3DSP_SRCMOD_MASK;
612
613 /* There are some minor differences between pixel and vertex shaders */
614 char pshader = shader_is_pshader_version(shader_version);
615
616 /* For one, we'd prefer color components to be shown for pshaders.
617 * FIXME: use the swizzle function for this */
618
619 swizzle_reg_chars[0] = pshader? 'r': 'x';
620 swizzle_reg_chars[1] = pshader? 'g': 'y';
621 swizzle_reg_chars[2] = pshader? 'b': 'z';
622 swizzle_reg_chars[3] = pshader? 'a': 'w';
623
624 if (input) {
625 if ( (modifier == WINED3DSPSM_NEG) ||
626 (modifier == WINED3DSPSM_BIASNEG) ||
627 (modifier == WINED3DSPSM_SIGNNEG) ||
628 (modifier == WINED3DSPSM_X2NEG) ||
629 (modifier == WINED3DSPSM_ABSNEG) )
630 TRACE("-");
631 else if (modifier == WINED3DSPSM_COMP)
632 TRACE("1-");
633 else if (modifier == WINED3DSPSM_NOT)
634 TRACE("!");
635
636 if (modifier == WINED3DSPSM_ABS || modifier == WINED3DSPSM_ABSNEG)
637 TRACE("abs(");
638 }
639
640 switch (regtype) {
641 case WINED3DSPR_TEMP:
642 TRACE("r%u", reg);
643 break;
644 case WINED3DSPR_INPUT:
645 TRACE("v");
646 shader_dump_arr_entry(param, addr_token, reg, input, shader_version);
647 break;
648 case WINED3DSPR_CONST:
649 case WINED3DSPR_CONST2:
650 case WINED3DSPR_CONST3:
651 case WINED3DSPR_CONST4:
652 TRACE("c");
653 shader_dump_arr_entry(param, addr_token, shader_get_float_offset(param), input, shader_version);
654 break;
655 case WINED3DSPR_TEXTURE: /* vs: case D3DSPR_ADDR */
656 TRACE("%c%u", (pshader? 't':'a'), reg);
657 break;
658 case WINED3DSPR_RASTOUT:
659 TRACE("%s", rastout_reg_names[reg]);
660 break;
661 case WINED3DSPR_COLOROUT:
662 TRACE("oC%u", reg);
663 break;
664 case WINED3DSPR_DEPTHOUT:
665 TRACE("oDepth");
666 break;
667 case WINED3DSPR_ATTROUT:
668 TRACE("oD%u", reg);
669 break;
670 case WINED3DSPR_TEXCRDOUT:
671
672 /* Vertex shaders >= 3.0 use general purpose output registers
673 * (WINED3DSPR_OUTPUT), which can include an address token */
674
675 if (WINED3DSHADER_VERSION_MAJOR(shader_version) >= 3) {
676 TRACE("o");
677 shader_dump_arr_entry(param, addr_token, reg, input, shader_version);
678 }
679 else
680 TRACE("oT%u", reg);
681 break;
682 case WINED3DSPR_CONSTINT:
683 TRACE("i");
684 shader_dump_arr_entry(param, addr_token, reg, input, shader_version);
685 break;
686 case WINED3DSPR_CONSTBOOL:
687 TRACE("b");
688 shader_dump_arr_entry(param, addr_token, reg, input, shader_version);
689 break;
690 case WINED3DSPR_LABEL:
691 TRACE("l%u", reg);
692 break;
693 case WINED3DSPR_LOOP:
694 TRACE("aL");
695 break;
696 case WINED3DSPR_SAMPLER:
697 TRACE("s%u", reg);
698 break;
699 case WINED3DSPR_MISCTYPE:
700 if (reg > 1) {
701 FIXME("Unhandled misctype register %d\n", reg);
702 } else {
703 TRACE("%s", misctype_reg_names[reg]);
704 }
705 break;
706 case WINED3DSPR_PREDICATE:
707 TRACE("p%u", reg);
708 break;
709 default:
710 TRACE("unhandled_rtype(%#x)", regtype);
711 break;
712 }
713
714 if (!input) {
715 /* operand output (for modifiers and shift, see dump_ins_modifiers) */
716
717 if ((param & WINED3DSP_WRITEMASK_ALL) != WINED3DSP_WRITEMASK_ALL) {
718 TRACE(".");
719 if (param & WINED3DSP_WRITEMASK_0) TRACE("%c", swizzle_reg_chars[0]);
720 if (param & WINED3DSP_WRITEMASK_1) TRACE("%c", swizzle_reg_chars[1]);
721 if (param & WINED3DSP_WRITEMASK_2) TRACE("%c", swizzle_reg_chars[2]);
722 if (param & WINED3DSP_WRITEMASK_3) TRACE("%c", swizzle_reg_chars[3]);
723 }
724
725 } else {
726 /** operand input */
727 DWORD swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
728 DWORD swizzle_r = swizzle & 0x03;
729 DWORD swizzle_g = (swizzle >> 2) & 0x03;
730 DWORD swizzle_b = (swizzle >> 4) & 0x03;
731 DWORD swizzle_a = (swizzle >> 6) & 0x03;
732
733 if (0 != modifier) {
734 switch (modifier) {
735 case WINED3DSPSM_NONE: break;
736 case WINED3DSPSM_NEG: break;
737 case WINED3DSPSM_NOT: break;
738 case WINED3DSPSM_BIAS: TRACE("_bias"); break;
739 case WINED3DSPSM_BIASNEG: TRACE("_bias"); break;
740 case WINED3DSPSM_SIGN: TRACE("_bx2"); break;
741 case WINED3DSPSM_SIGNNEG: TRACE("_bx2"); break;
742 case WINED3DSPSM_COMP: break;
743 case WINED3DSPSM_X2: TRACE("_x2"); break;
744 case WINED3DSPSM_X2NEG: TRACE("_x2"); break;
745 case WINED3DSPSM_DZ: TRACE("_dz"); break;
746 case WINED3DSPSM_DW: TRACE("_dw"); break;
747 case WINED3DSPSM_ABSNEG: TRACE(")"); break;
748 case WINED3DSPSM_ABS: TRACE(")"); break;
749 default:
750 TRACE("_unknown_modifier(%#x)", modifier >> WINED3DSP_SRCMOD_SHIFT);
751 }
752 }
753
754 /**
755 * swizzle bits fields:
756 * RRGGBBAA
757 */
758 if ((WINED3DVS_NOSWIZZLE >> WINED3DVS_SWIZZLE_SHIFT) != swizzle) {
759 if (swizzle_r == swizzle_g &&
760 swizzle_r == swizzle_b &&
761 swizzle_r == swizzle_a) {
762 TRACE(".%c", swizzle_reg_chars[swizzle_r]);
763 } else {
764 TRACE(".%c%c%c%c",
765 swizzle_reg_chars[swizzle_r],
766 swizzle_reg_chars[swizzle_g],
767 swizzle_reg_chars[swizzle_b],
768 swizzle_reg_chars[swizzle_a]);
769 }
770 }
771 }
772}
773
774static void shader_color_correction(IWineD3DBaseShaderImpl *shader,
775 IWineD3DDeviceImpl *device, const struct SHADER_OPCODE_ARG *arg)
776{
777 DWORD hex_version = shader->baseShader.hex_version;
778 IWineD3DBaseTextureImpl *texture;
779 struct color_fixup_desc fixup;
780 BOOL recorded = FALSE;
781 DWORD sampler_idx;
782 UINT i;
783
784 switch(arg->opcode->opcode)
785 {
786 case WINED3DSIO_TEX:
787 if (hex_version < WINED3DPS_VERSION(2,0)) sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
788 else sampler_idx = arg->src[1] & WINED3DSP_REGNUM_MASK;
789 break;
790
791 case WINED3DSIO_TEXLDL:
792 FIXME("Add color fixup for vertex texture WINED3DSIO_TEXLDL\n");
793 return;
794
795 case WINED3DSIO_TEXDP3TEX:
796 case WINED3DSIO_TEXM3x3TEX:
797 case WINED3DSIO_TEXM3x3SPEC:
798 case WINED3DSIO_TEXM3x3VSPEC:
799 case WINED3DSIO_TEXBEM:
800 case WINED3DSIO_TEXREG2AR:
801 case WINED3DSIO_TEXREG2GB:
802 case WINED3DSIO_TEXREG2RGB:
803 sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
804 break;
805
806 default:
807 /* Not a texture sampling instruction, nothing to do */
808 return;
809 };
810
811 texture = (IWineD3DBaseTextureImpl *)device->stateBlock->textures[sampler_idx];
812 if (texture) fixup = texture->baseTexture.shader_color_fixup;
813 else fixup = COLOR_FIXUP_IDENTITY;
814
815 /* before doing anything, record the sampler with the format in the format conversion list,
816 * but check if it's not there already */
817 for (i = 0; i < shader->baseShader.num_sampled_samplers; ++i)
818 {
819 if (shader->baseShader.sampled_samplers[i] == sampler_idx)
820 {
821 recorded = TRUE;
822 break;
823 }
824 }
825
826 if (!recorded)
827 {
828 shader->baseShader.sampled_samplers[shader->baseShader.num_sampled_samplers] = sampler_idx;
829 ++shader->baseShader.num_sampled_samplers;
830 }
831
832 device->shader_backend->shader_color_correction(arg, fixup);
833}
834
835/** Shared code in order to generate the bulk of the shader string.
836 Use the shader_header_fct & shader_footer_fct to add strings
837 that are specific to pixel or vertex functions
838 NOTE: A description of how to parse tokens can be found on msdn */
839void shader_generate_main(IWineD3DBaseShader *iface, SHADER_BUFFER* buffer,
840 const shader_reg_maps* reg_maps, CONST DWORD* pFunction)
841{
842 IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
843 IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device; /* To access shader backend callbacks */
844 const SHADER_OPCODE *opcode_table = This->baseShader.shader_ins;
845 const SHADER_HANDLER *handler_table = device->shader_backend->shader_instruction_handler_table;
846 DWORD shader_version = This->baseShader.hex_version;
847 const DWORD *pToken = pFunction;
848 const SHADER_OPCODE *curOpcode = NULL;
849 SHADER_HANDLER hw_fct = NULL;
850 DWORD i;
851 SHADER_OPCODE_ARG hw_arg;
852
853 /* Initialize current parsing state */
854 hw_arg.shader = iface;
855 hw_arg.buffer = buffer;
856 hw_arg.reg_maps = reg_maps;
857 This->baseShader.parse_state.current_row = 0;
858
859 /* Second pass, process opcodes */
860 if (NULL != pToken) {
861 while (WINED3DPS_END() != *pToken) {
862
863 /* Skip version token */
864 if (shader_is_version_token(*pToken)) {
865 ++pToken;
866 continue;
867 }
868
869 /* Skip comment tokens */
870 if (shader_is_comment(*pToken)) {
871 DWORD comment_len = (*pToken & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
872 ++pToken;
873 TRACE("#%s\n", (const char*)pToken);
874 pToken += comment_len;
875 continue;
876 }
877
878 /* Read opcode */
879 hw_arg.opcode_token = *pToken++;
880 curOpcode = shader_get_opcode(opcode_table, shader_version, hw_arg.opcode_token);
881
882 /* Select handler */
883 if (curOpcode == NULL)
884 hw_fct = NULL;
885 else
886 hw_fct = handler_table[curOpcode->handler_idx];
887
888 /* Unknown opcode and its parameters */
889 if (NULL == curOpcode) {
890 FIXME("Unrecognized opcode: token=0x%08x\n", hw_arg.opcode_token);
891 pToken += shader_skip_unrecognized(iface, pToken);
892
893 /* Nothing to do */
894 } else if (WINED3DSIO_DCL == curOpcode->opcode ||
895 WINED3DSIO_NOP == curOpcode->opcode ||
896 WINED3DSIO_DEF == curOpcode->opcode ||
897 WINED3DSIO_DEFI == curOpcode->opcode ||
898 WINED3DSIO_DEFB == curOpcode->opcode ||
899 WINED3DSIO_PHASE == curOpcode->opcode ||
900 WINED3DSIO_RET == curOpcode->opcode) {
901
902 pToken += shader_skip_opcode(This, curOpcode, hw_arg.opcode_token);
903
904 /* If a generator function is set for current shader target, use it */
905 } else if (hw_fct != NULL) {
906
907 hw_arg.opcode = curOpcode;
908
909 /* Destination token */
910 if (curOpcode->dst_token) {
911
912 DWORD param, addr_token = 0;
913 pToken += shader_get_param(iface, pToken, &param, &addr_token);
914 hw_arg.dst = param;
915 hw_arg.dst_addr = addr_token;
916 }
917
918 /* Predication token */
919 if (hw_arg.opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED)
920 hw_arg.predicate = *pToken++;
921
922 /* Other source tokens */
923 for (i = 0; i < (curOpcode->num_params - curOpcode->dst_token); i++) {
924
925 DWORD param, addr_token = 0;
926 pToken += shader_get_param(iface, pToken, &param, &addr_token);
927 hw_arg.src[i] = param;
928 hw_arg.src_addr[i] = addr_token;
929 }
930
931 /* Call appropriate function for output target */
932 hw_fct(&hw_arg);
933
934 /* Add color correction if needed */
935 shader_color_correction(This, device, &hw_arg);
936
937 /* Process instruction modifiers for GLSL apps ( _sat, etc. ) */
938 /* FIXME: This should be internal to the shader backend.
939 * Also, right now this is the only reason "shader_mode" exists. */
940 if (This->baseShader.shader_mode == SHADER_GLSL)
941 shader_glsl_add_instruction_modifiers(&hw_arg);
942
943 /* Unhandled opcode */
944 } else {
945
946 FIXME("Can't handle opcode %s in hwShader\n", curOpcode->name);
947 pToken += shader_skip_opcode(This, curOpcode, hw_arg.opcode_token);
948 }
949 }
950 /* TODO: What about result.depth? */
951
952 }
953}
954
955static void shader_dump_ins_modifiers(const DWORD output)
956{
957 DWORD shift = (output & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT;
958 DWORD mmask = output & WINED3DSP_DSTMOD_MASK;
959
960 switch (shift) {
961 case 0: break;
962 case 13: TRACE("_d8"); break;
963 case 14: TRACE("_d4"); break;
964 case 15: TRACE("_d2"); break;
965 case 1: TRACE("_x2"); break;
966 case 2: TRACE("_x4"); break;
967 case 3: TRACE("_x8"); break;
968 default: TRACE("_unhandled_shift(%d)", shift); break;
969 }
970
971 if (mmask & WINED3DSPDM_SATURATE) TRACE("_sat");
972 if (mmask & WINED3DSPDM_PARTIALPRECISION) TRACE("_pp");
973 if (mmask & WINED3DSPDM_MSAMPCENTROID) TRACE("_centroid");
974
975 mmask &= ~(WINED3DSPDM_SATURATE | WINED3DSPDM_PARTIALPRECISION | WINED3DSPDM_MSAMPCENTROID);
976 if (mmask)
977 FIXME("_unrecognized_modifier(%#x)", mmask >> WINED3DSP_DSTMOD_SHIFT);
978}
979
980/* First pass: trace shader, initialize length and version */
981void shader_trace_init(
982 IWineD3DBaseShader *iface,
983 const DWORD* pFunction) {
984
985 IWineD3DBaseShaderImpl *This =(IWineD3DBaseShaderImpl *)iface;
986
987 const DWORD* pToken = pFunction;
988 const SHADER_OPCODE* curOpcode = NULL;
989 DWORD opcode_token;
990 unsigned int len = 0;
991 DWORD i;
992
993 TRACE("(%p) : Parsing program\n", This);
994
995 if (NULL != pToken) {
996 while (WINED3DVS_END() != *pToken) {
997 if (shader_is_version_token(*pToken)) { /** version */
998 This->baseShader.hex_version = *pToken;
999 TRACE("%s_%u_%u\n", shader_is_pshader_version(This->baseShader.hex_version)? "ps": "vs",
1000 WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version),
1001 WINED3DSHADER_VERSION_MINOR(This->baseShader.hex_version));
1002 ++pToken;
1003 ++len;
1004 continue;
1005 }
1006 if (shader_is_comment(*pToken)) { /** comment */
1007 DWORD comment_len = (*pToken & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
1008 ++pToken;
1009 TRACE("//%s\n", (const char*)pToken);
1010 pToken += comment_len;
1011 len += comment_len + 1;
1012 continue;
1013 }
1014 opcode_token = *pToken++;
1015 curOpcode = shader_get_opcode(This->baseShader.shader_ins, This->baseShader.hex_version, opcode_token);
1016 len++;
1017
1018 if (NULL == curOpcode) {
1019 int tokens_read;
1020 FIXME("Unrecognized opcode: token=0x%08x\n", opcode_token);
1021 tokens_read = shader_skip_unrecognized(iface, pToken);
1022 pToken += tokens_read;
1023 len += tokens_read;
1024
1025 } else {
1026 if (curOpcode->opcode == WINED3DSIO_DCL) {
1027
1028 DWORD usage = *pToken;
1029 DWORD param = *(pToken + 1);
1030
1031 shader_dump_decl_usage(usage, param, This->baseShader.hex_version);
1032 shader_dump_ins_modifiers(param);
1033 TRACE(" ");
1034 shader_dump_param(param, 0, 0, This->baseShader.hex_version);
1035 pToken += 2;
1036 len += 2;
1037
1038 } else if (curOpcode->opcode == WINED3DSIO_DEF) {
1039
1040 unsigned int offset = shader_get_float_offset(*pToken);
1041
1042 TRACE("def c%u = %f, %f, %f, %f", offset,
1043 *(const float *)(pToken + 1),
1044 *(const float *)(pToken + 2),
1045 *(const float *)(pToken + 3),
1046 *(const float *)(pToken + 4));
1047
1048 pToken += 5;
1049 len += 5;
1050 } else if (curOpcode->opcode == WINED3DSIO_DEFI) {
1051
1052 TRACE("defi i%u = %d, %d, %d, %d", *pToken & WINED3DSP_REGNUM_MASK,
1053 *(pToken + 1),
1054 *(pToken + 2),
1055 *(pToken + 3),
1056 *(pToken + 4));
1057
1058 pToken += 5;
1059 len += 5;
1060
1061 } else if (curOpcode->opcode == WINED3DSIO_DEFB) {
1062
1063 TRACE("defb b%u = %s", *pToken & WINED3DSP_REGNUM_MASK,
1064 *(pToken + 1)? "true": "false");
1065
1066 pToken += 2;
1067 len += 2;
1068
1069 } else {
1070
1071 DWORD param, addr_token;
1072 int tokens_read;
1073
1074 /* Print out predication source token first - it follows
1075 * the destination token. */
1076 if (opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED) {
1077 TRACE("(");
1078 shader_dump_param(*(pToken + 2), 0, 1, This->baseShader.hex_version);
1079 TRACE(") ");
1080 }
1081 if (opcode_token & WINED3DSI_COISSUE) {
1082 /* PixWin marks instructions with the coissue flag with a '+' */
1083 TRACE("+");
1084 }
1085
1086 TRACE("%s", curOpcode->name);
1087
1088 if (curOpcode->opcode == WINED3DSIO_IFC ||
1089 curOpcode->opcode == WINED3DSIO_BREAKC) {
1090
1091 DWORD op = (opcode_token & INST_CONTROLS_MASK) >> INST_CONTROLS_SHIFT;
1092 switch (op) {
1093 case COMPARISON_GT: TRACE("_gt"); break;
1094 case COMPARISON_EQ: TRACE("_eq"); break;
1095 case COMPARISON_GE: TRACE("_ge"); break;
1096 case COMPARISON_LT: TRACE("_lt"); break;
1097 case COMPARISON_NE: TRACE("_ne"); break;
1098 case COMPARISON_LE: TRACE("_le"); break;
1099 default:
1100 TRACE("_(%u)", op);
1101 }
1102 } else if (curOpcode->opcode == WINED3DSIO_TEX &&
1103 This->baseShader.hex_version >= WINED3DPS_VERSION(2,0)) {
1104 if(opcode_token & WINED3DSI_TEXLD_PROJECT) TRACE("p");
1105 }
1106
1107 /* Destination token */
1108 if (curOpcode->dst_token) {
1109
1110 /* Destination token */
1111 tokens_read = shader_get_param(iface, pToken, &param, &addr_token);
1112 pToken += tokens_read;
1113 len += tokens_read;
1114
1115 shader_dump_ins_modifiers(param);
1116 TRACE(" ");
1117 shader_dump_param(param, addr_token, 0, This->baseShader.hex_version);
1118 }
1119
1120 /* Predication token - already printed out, just skip it */
1121 if (opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED) {
1122 pToken++;
1123 len++;
1124 }
1125
1126 /* Other source tokens */
1127 for (i = curOpcode->dst_token; i < curOpcode->num_params; ++i) {
1128
1129 tokens_read = shader_get_param(iface, pToken, &param, &addr_token);
1130 pToken += tokens_read;
1131 len += tokens_read;
1132
1133 TRACE((i == 0)? " " : ", ");
1134 shader_dump_param(param, addr_token, 1, This->baseShader.hex_version);
1135 }
1136 }
1137 TRACE("\n");
1138 }
1139 }
1140 This->baseShader.functionLength = (len + 1) * sizeof(DWORD);
1141 } else {
1142 This->baseShader.functionLength = 1; /* no Function defined use fixed function vertex processing */
1143 }
1144}
1145
1146static const SHADER_HANDLER shader_none_instruction_handler_table[WINED3DSIH_TABLE_SIZE] = {0};
1147static void shader_none_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {}
1148static void shader_none_select_depth_blt(IWineD3DDevice *iface, enum tex_types tex_type) {}
1149static void shader_none_deselect_depth_blt(IWineD3DDevice *iface) {}
1150static void shader_none_load_constants(IWineD3DDevice *iface, char usePS, char useVS) {}
1151static void shader_none_cleanup(IWineD3DDevice *iface) {}
1152static void shader_none_color_correction(const struct SHADER_OPCODE_ARG *arg, struct color_fixup_desc fixup) {}
1153static void shader_none_destroy(IWineD3DBaseShader *iface) {}
1154static HRESULT shader_none_alloc(IWineD3DDevice *iface) {return WINED3D_OK;}
1155static void shader_none_free(IWineD3DDevice *iface) {}
1156static BOOL shader_none_dirty_const(IWineD3DDevice *iface) {return FALSE;}
1157static GLuint shader_none_generate_pshader(IWineD3DPixelShader *iface, SHADER_BUFFER *buffer) {
1158 FIXME("NONE shader backend asked to generate a pixel shader\n");
1159 return 0;
1160}
1161static void shader_none_generate_vshader(IWineD3DVertexShader *iface, SHADER_BUFFER *buffer) {
1162 FIXME("NONE shader backend asked to generate a vertex shader\n");
1163}
1164
1165#define GLINFO_LOCATION (*gl_info)
1166static void shader_none_get_caps(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct shader_caps *pCaps)
1167{
1168 /* Set the shader caps to 0 for the none shader backend */
1169 pCaps->VertexShaderVersion = 0;
1170 pCaps->PixelShaderVersion = 0;
1171 pCaps->PixelShader1xMaxValue = 0.0;
1172}
1173#undef GLINFO_LOCATION
1174static BOOL shader_none_color_fixup_supported(struct color_fixup_desc fixup)
1175{
1176 if (TRACE_ON(d3d_shader) && TRACE_ON(d3d))
1177 {
1178 TRACE("Checking support for fixup:\n");
1179 dump_color_fixup_desc(fixup);
1180 }
1181
1182 /* Faked to make some apps happy. */
1183 if (!is_yuv_fixup(fixup))
1184 {
1185 TRACE("[OK]\n");
1186 return TRUE;
1187 }
1188
1189 TRACE("[FAILED]\n");
1190 return FALSE;
1191}
1192
1193const shader_backend_t none_shader_backend = {
1194 shader_none_instruction_handler_table,
1195 shader_none_select,
1196 shader_none_select_depth_blt,
1197 shader_none_deselect_depth_blt,
1198 shader_none_load_constants,
1199 shader_none_cleanup,
1200 shader_none_color_correction,
1201 shader_none_destroy,
1202 shader_none_alloc,
1203 shader_none_free,
1204 shader_none_dirty_const,
1205 shader_none_generate_pshader,
1206 shader_none_generate_vshader,
1207 shader_none_get_caps,
1208 shader_none_color_fixup_supported,
1209};
1210
1211/* *******************************************
1212 IWineD3DPixelShader IUnknown parts follow
1213 ******************************************* */
1214HRESULT WINAPI IWineD3DBaseShaderImpl_QueryInterface(IWineD3DBaseShader *iface, REFIID riid, LPVOID *ppobj)
1215{
1216 IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)iface;
1217 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
1218 if (IsEqualGUID(riid, &IID_IUnknown)
1219 || IsEqualGUID(riid, &IID_IWineD3DBase)
1220 || IsEqualGUID(riid, &IID_IWineD3DBaseShader)
1221 || IsEqualGUID(riid, &IID_IWineD3DPixelShader)) {
1222 IUnknown_AddRef(iface);
1223 *ppobj = This;
1224 return S_OK;
1225 }
1226 *ppobj = NULL;
1227 return E_NOINTERFACE;
1228}
1229
1230ULONG WINAPI IWineD3DBaseShaderImpl_AddRef(IWineD3DBaseShader *iface) {
1231 IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
1232 TRACE("(%p) : AddRef increasing from %d\n", This, This->baseShader.ref);
1233 return InterlockedIncrement(&This->baseShader.ref);
1234}
1235
1236ULONG WINAPI IWineD3DBaseShaderImpl_Release(IWineD3DBaseShader *iface) {
1237 IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)iface;
1238 IWineD3DDeviceImpl *deviceImpl = (IWineD3DDeviceImpl *) This->baseShader.device;
1239 ULONG ref;
1240 TRACE("(%p) : Releasing from %d\n", This, This->baseShader.ref);
1241 ref = InterlockedDecrement(&This->baseShader.ref);
1242 if (ref == 0) {
1243 deviceImpl->shader_backend->shader_destroy(iface);
1244 HeapFree(GetProcessHeap(), 0, This->baseShader.function);
1245 shader_delete_constant_list(&This->baseShader.constantsF);
1246 shader_delete_constant_list(&This->baseShader.constantsB);
1247 shader_delete_constant_list(&This->baseShader.constantsI);
1248 list_remove(&This->baseShader.shader_list_entry);
1249 HeapFree(GetProcessHeap(), 0, This);
1250 }
1251 return ref;
1252}
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