2 * vertex shaders declaration implementation
4 * Copyright 2002 Raphael Junqueira
5 * Copyright 2004 Jason Edmeades
6 * Copyright 2004 Christian Costa
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "wine/debug.h"
34 #include "d3d8_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader
);
39 * DirectX9 SDK download
40 * http://msdn.microsoft.com/library/default.asp?url=/downloads/list/directx.asp
43 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx07162002.asp
45 * Using Vertex Shaders
46 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx02192001.asp
49 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/whatsnew.asp
52 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader2_0/VertexShader2_0.asp
53 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader2_0/Instructions/Instructions.asp
54 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/GettingStarted/VertexDeclaration/VertexDeclaration.asp
55 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader3_0/VertexShader3_0.asp
58 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/advancedtopics/VertexPipe/matrixstack/matrixstack.asp
61 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/GettingStarted/VertexFormats/vformats.asp
63 * NVIDIA: DX8 Vertex Shader to NV Vertex Program
64 * http://developer.nvidia.com/view.asp?IO=vstovp
66 * NVIDIA: Memory Management with VAR
67 * http://developer.nvidia.com/view.asp?IO=var_memory_management
70 /** Vertex Shader Declaration data types tokens */
71 #define MAX_VSHADER_DECL_TYPES 8
72 static CONST
char* VertexShaderDeclDataTypes
[] = {
84 static CONST
char* VertexShaderDeclRegister
[] = {
86 "D3DVSDE_BLENDWEIGHT",
87 "D3DVSDE_BLENDINDICES",
105 /** todo check decl validity */
106 /*inline static*/ DWORD
Direct3DVextexShaderDeclarationImpl_ParseToken(const DWORD
* pToken
) {
107 const DWORD token
= *pToken
;
110 switch ((token
& D3DVSD_TOKENTYPEMASK
) >> D3DVSD_TOKENTYPESHIFT
) { /* maybe a macro to inverse ... */
111 case D3DVSD_TOKEN_NOP
:
112 TRACE(" 0x%08lx NOP()\n", token
);
114 case D3DVSD_TOKEN_STREAM
:
115 if (token
& D3DVSD_STREAMTESSMASK
) {
116 TRACE(" 0x%08lx STREAM_TESS()\n", token
);
118 TRACE(" 0x%08lx STREAM(%lu)\n", token
, ((token
& D3DVSD_STREAMNUMBERMASK
) >> D3DVSD_STREAMNUMBERSHIFT
));
121 case D3DVSD_TOKEN_STREAMDATA
:
122 if (token
& 0x10000000) {
123 TRACE(" 0x%08lx SKIP(%lu)\n", token
, ((token
& D3DVSD_SKIPCOUNTMASK
) >> D3DVSD_SKIPCOUNTSHIFT
));
125 DWORD type
= ((token
& D3DVSD_DATATYPEMASK
) >> D3DVSD_DATATYPESHIFT
);
126 DWORD reg
= ((token
& D3DVSD_VERTEXREGMASK
) >> D3DVSD_VERTEXREGSHIFT
);
127 TRACE(" 0x%08lx REG(%s, %s)\n", token
, VertexShaderDeclRegister
[reg
], VertexShaderDeclDataTypes
[type
]);
130 case D3DVSD_TOKEN_TESSELLATOR
:
131 if (token
& 0x10000000) {
132 DWORD type
= ((token
& D3DVSD_DATATYPEMASK
) >> D3DVSD_DATATYPESHIFT
);
133 DWORD reg
= ((token
& D3DVSD_VERTEXREGMASK
) >> D3DVSD_VERTEXREGSHIFT
);
134 TRACE(" 0x%08lx TESSUV(%s) as %s\n", token
, VertexShaderDeclRegister
[reg
], VertexShaderDeclDataTypes
[type
]);
136 DWORD type
= ((token
& D3DVSD_DATATYPEMASK
) >> D3DVSD_DATATYPESHIFT
);
137 DWORD regout
= ((token
& D3DVSD_VERTEXREGMASK
) >> D3DVSD_VERTEXREGSHIFT
);
138 DWORD regin
= ((token
& D3DVSD_VERTEXREGINMASK
) >> D3DVSD_VERTEXREGINSHIFT
);
139 TRACE(" 0x%08lx TESSNORMAL(%s, %s) as %s\n", token
, VertexShaderDeclRegister
[regin
], VertexShaderDeclRegister
[regout
], VertexShaderDeclDataTypes
[type
]);
142 case D3DVSD_TOKEN_CONSTMEM
:
145 DWORD count
= ((token
& D3DVSD_CONSTCOUNTMASK
) >> D3DVSD_CONSTCOUNTSHIFT
);
146 DWORD constaddress
= ((token
& D3DVSD_CONSTADDRESSMASK
) >> D3DVSD_CONSTADDRESSSHIFT
);
147 TRACE(" 0x%08lx CONST(%lu, %lu)\n", token
, constaddress
, count
);
149 for (i
= 0; i
< count
; ++i
) {
151 TRACE(" c[%lu] = (0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx)\n",
158 TRACE(" c[%lu] = (%8f, %8f, %8f, %8f)\n",
160 *(const float*) pToken
,
161 *(const float*) (pToken
+ 1),
162 *(const float*) (pToken
+ 2),
163 *(const float*) (pToken
+ 3));
167 tokenlen
= (4 * count
) + 1;
170 case D3DVSD_TOKEN_EXT
:
172 DWORD count
= ((token
& D3DVSD_CONSTCOUNTMASK
) >> D3DVSD_CONSTCOUNTSHIFT
);
173 DWORD extinfo
= ((token
& D3DVSD_EXTINFOMASK
) >> D3DVSD_EXTINFOSHIFT
);
174 TRACE(" 0x%08lx EXT(%lu, %lu)\n", token
, count
, extinfo
);
175 /* todo ... print extension */
176 tokenlen
= count
+ 1;
179 case D3DVSD_TOKEN_END
:
180 TRACE(" 0x%08lx END()\n", token
);
183 TRACE(" 0x%08lx UNKNOWN\n", token
);
189 HRESULT WINAPI
IDirect3DDeviceImpl_CreateVertexShaderDeclaration8(IDirect3DDevice8Impl
* This
, CONST DWORD
* pDeclaration8
, IDirect3DVertexShaderDeclarationImpl
** ppVertexShaderDecl
) {
191 const DWORD
* pToken
= pDeclaration8
;
198 DWORD tex
= D3DFVF_TEX0
;
199 /** TRUE if declaration can be matched by a fvf */
200 IDirect3DVertexShaderDeclarationImpl
* object
;
201 BOOL invalid_fvf
= FALSE
;
203 TRACE("(%p) : pDeclaration8(%p)\n", This
, pDeclaration8
);
205 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DVertexShaderDeclarationImpl
));
207 /*object->lpVtbl = &Direct3DVextexShaderDeclaration8_Vtbl;*/
208 object
->device
= This
; /* FIXME: AddRef(This) */
212 while (D3DVSD_END() != *pToken
) {
214 tokenlen
= Direct3DVextexShaderDeclarationImpl_ParseToken(pToken
);
215 tokentype
= ((token
& D3DVSD_TOKENTYPEMASK
) >> D3DVSD_TOKENTYPESHIFT
);
217 /** FVF generation block */
218 if (D3DVSD_TOKEN_STREAM
== tokentype
&& 0 == (D3DVSD_STREAMTESSMASK
& token
)) {
220 * how really works streams,
221 * in DolphinVS dx8 dsk sample they seems to decal reg numbers !!!
223 DWORD oldStream
= stream
;
224 stream
= ((token
& D3DVSD_STREAMNUMBERMASK
) >> D3DVSD_STREAMNUMBERSHIFT
);
226 /* copy fvf if valid */
227 if (FALSE
== invalid_fvf
) {
228 fvf
|= tex
<< D3DFVF_TEXCOUNT_SHIFT
;
230 object
->fvf
[oldStream
] = fvf
;
231 object
->allFVF
|= fvf
;
233 object
->fvf
[oldStream
] = 0;
237 /* reset valid/invalid fvf */
241 } else if (D3DVSD_TOKEN_STREAMDATA
== tokentype
&& 0 == (0x10000000 & tokentype
)) {
242 DWORD type
= ((token
& D3DVSD_DATATYPEMASK
) >> D3DVSD_DATATYPESHIFT
);
243 DWORD reg
= ((token
& D3DVSD_VERTEXREGMASK
) >> D3DVSD_VERTEXREGSHIFT
);
246 case D3DVSDE_POSITION
:
248 case D3DVSDT_FLOAT3
: fvf
|= D3DFVF_XYZ
; break;
249 case D3DVSDT_FLOAT4
: fvf
|= D3DFVF_XYZRHW
; break;
251 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
253 if (type
>= MAX_VSHADER_DECL_TYPES
) {
254 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_POSITION register: unsupported and unrecognized type %08lx\n", type
);
256 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_POSITION register: unsupported type %s\n", VertexShaderDeclDataTypes
[type
]);
261 case D3DVSDE_BLENDWEIGHT
:
263 case D3DVSDT_FLOAT1
: fvf
|= D3DFVF_XYZB1
; break;
264 case D3DVSDT_FLOAT2
: fvf
|= D3DFVF_XYZB2
; break;
265 case D3DVSDT_FLOAT3
: fvf
|= D3DFVF_XYZB3
; break;
266 case D3DVSDT_FLOAT4
: fvf
|= D3DFVF_XYZB4
; break;
268 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
270 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_BLENDWEIGHT register: unsupported type %s\n", VertexShaderDeclDataTypes
[type
]);
274 case D3DVSDE_BLENDINDICES
: /* seem to be B5 as said in MSDN Dx9SDK ?? */
276 case D3DVSDT_UBYTE4
: fvf
|= D3DFVF_LASTBETA_UBYTE4
; break;
278 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
280 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_BLENDINDINCES register: unsupported type %s\n", VertexShaderDeclDataTypes
[type
]);
284 case D3DVSDE_NORMAL
: /* TODO: only FLOAT3 supported ... another choice possible ? */
286 case D3DVSDT_FLOAT3
: fvf
|= D3DFVF_NORMAL
; break;
288 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
290 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_NORMAL register: unsupported type %s\n", VertexShaderDeclDataTypes
[type
]);
294 case D3DVSDE_PSIZE
: /* TODO: only FLOAT1 supported ... another choice possible ? */
296 case D3DVSDT_FLOAT1
: fvf
|= D3DFVF_PSIZE
; break;
298 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
300 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_PSIZE register: unsupported type %s\n", VertexShaderDeclDataTypes
[type
]);
304 case D3DVSDE_DIFFUSE
: /* TODO: only D3DCOLOR supported */
306 case D3DVSDT_D3DCOLOR
: fvf
|= D3DFVF_DIFFUSE
; break;
308 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
310 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_DIFFUSE register: unsupported type %s\n", VertexShaderDeclDataTypes
[type
]);
314 case D3DVSDE_SPECULAR
: /* TODO: only D3DCOLOR supported */
316 case D3DVSDT_D3DCOLOR
: fvf
|= D3DFVF_SPECULAR
; break;
318 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
320 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_SPECULAR register: unsupported type %s\n", VertexShaderDeclDataTypes
[type
]);
324 case D3DVSDE_TEXCOORD0
:
325 case D3DVSDE_TEXCOORD1
:
326 case D3DVSDE_TEXCOORD2
:
327 case D3DVSDE_TEXCOORD3
:
328 case D3DVSDE_TEXCOORD4
:
329 case D3DVSDE_TEXCOORD5
:
330 case D3DVSDE_TEXCOORD6
:
331 case D3DVSDE_TEXCOORD7
:
332 /* Fixme? - assume all tex coords in same stream */
334 int texNo
= 1 + (reg
- D3DVSDE_TEXCOORD0
);
335 tex
= max(tex
, texNo
);
337 case D3DVSDT_FLOAT1
: fvf
|= D3DFVF_TEXCOORDSIZE1(texNo
); break;
338 case D3DVSDT_FLOAT2
: fvf
|= D3DFVF_TEXCOORDSIZE2(texNo
); break;
339 case D3DVSDT_FLOAT3
: fvf
|= D3DFVF_TEXCOORDSIZE3(texNo
); break;
340 case D3DVSDT_FLOAT4
: fvf
|= D3DFVF_TEXCOORDSIZE4(texNo
); break;
342 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
344 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_TEXCOORD? register: unsupported type %s\n", VertexShaderDeclDataTypes
[type
]);
349 case D3DVSDE_POSITION2
: /* maybe D3DFVF_XYZRHW instead D3DFVF_XYZ (of D3DVDE_POSITION) ... to see */
350 case D3DVSDE_NORMAL2
: /* FIXME i don't know what to do here ;( */
351 FIXME("[%lu] registers in VertexShader declaration not supported yet (token:0x%08lx)\n", reg
, token
);
354 TRACE("VertexShader declaration define %lx as current FVF\n", fvf
);
359 /* here D3DVSD_END() */
360 len
+= Direct3DVextexShaderDeclarationImpl_ParseToken(pToken
);
362 /* copy fvf if valid */
363 if (FALSE
== invalid_fvf
) {
364 fvf
|= tex
<< D3DFVF_TEXCOUNT_SHIFT
;
365 object
->fvf
[stream
] = fvf
;
366 object
->allFVF
|= fvf
;
368 object
->fvf
[stream
] = 0;
370 TRACE("Completed, allFVF = %lx\n", object
->allFVF
);
373 object
->declaration8Length
= len
* sizeof(DWORD
);
374 /* copy the declaration */
375 object
->pDeclaration8
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, object
->declaration8Length
);
376 memcpy(object
->pDeclaration8
, pDeclaration8
, object
->declaration8Length
);
378 *ppVertexShaderDecl
= object
;
382 HRESULT WINAPI
IDirect3DDeviceImpl_FillVertexShaderInputSW(IDirect3DDevice8Impl
* This
,
383 IDirect3DVertexShaderImpl
* vshader
,
384 DWORD SkipnStrides
) {
386 const DWORD
* pToken
= This
->UpdateStateBlock
->vertexShaderDecl
->pDeclaration8
;
391 /** for input readers */
392 const BYTE
* curPos
= NULL
;
397 TRACE("(%p) - This:%p, skipstrides=%lu\n", vshader
, This
, SkipnStrides
);
399 while (D3DVSD_END() != *pToken
) {
401 tokentype
= ((token
& D3DVSD_TOKENTYPEMASK
) >> D3DVSD_TOKENTYPESHIFT
);
403 /** FVF generation block */
404 if (D3DVSD_TOKEN_STREAM
== tokentype
&& 0 == (D3DVSD_STREAMTESSMASK
& token
)) {
405 IDirect3DVertexBuffer8
* pVB
;
410 * how really works streams,
411 * in DolphinVS dx8 dsk sample use it !!!
413 stream
= ((token
& D3DVSD_STREAMNUMBERMASK
) >> D3DVSD_STREAMNUMBERSHIFT
);
414 skip
= This
->StateBlock
->stream_stride
[stream
];
415 pVB
= This
->StateBlock
->stream_source
[stream
];
418 ERR("using unitialised stream[%lu]\n", stream
);
419 return D3DERR_INVALIDCALL
;
421 if (This
->StateBlock
->streamIsUP
) {
422 curPos
= (BYTE
*)pVB
+ (SkipnStrides
* skip
); /* Not really a VB */
424 curPos
= ((IDirect3DVertexBuffer8Impl
*) pVB
)->allocatedMemory
+ (SkipnStrides
* skip
);
427 TRACE(" using stream[%lu] with %p (%p + (Stride %d * skip %ld))\n", stream
, curPos
,
428 ((IDirect3DVertexBuffer8Impl
*) pVB
)->allocatedMemory
, skip
, SkipnStrides
);
430 } else if (D3DVSD_TOKEN_CONSTMEM
== tokentype
) {
433 DWORD count
= ((token
& D3DVSD_CONSTCOUNTMASK
) >> D3DVSD_CONSTCOUNTSHIFT
);
434 DWORD constaddress
= ((token
& D3DVSD_CONSTADDRESSMASK
) >> D3DVSD_CONSTADDRESSSHIFT
);
436 for (i
= 0; i
< count
; ++i
) {
437 vshader
->data
->C
[constaddress
+ i
].x
= *(const float*)pToken
;
438 vshader
->data
->C
[constaddress
+ i
].y
= *(const float*)(pToken
+ 1);
439 vshader
->data
->C
[constaddress
+ i
].z
= *(const float*)(pToken
+ 2);
440 vshader
->data
->C
[constaddress
+ i
].w
= *(const float*)(pToken
+ 3);
444 } else if (D3DVSD_TOKEN_STREAMDATA
== tokentype
&& 0 != (0x10000000 & tokentype
)) {
446 DWORD skipCount
= ((token
& D3DVSD_SKIPCOUNTMASK
) >> D3DVSD_SKIPCOUNTSHIFT
);
447 TRACE(" skipping %ld dwords\n", skipCount
);
448 curPos
= curPos
+ skipCount
* sizeof(DWORD
);
451 } else if (D3DVSD_TOKEN_STREAMDATA
== tokentype
&& 0 == (0x10000000 & tokentype
)) {
452 DWORD type
= ((token
& D3DVSD_DATATYPEMASK
) >> D3DVSD_DATATYPESHIFT
);
453 DWORD reg
= ((token
& D3DVSD_VERTEXREGMASK
) >> D3DVSD_VERTEXREGSHIFT
);
456 TRACE(" type : %ld, reg = %ld\n", type
, reg
);
459 x
= *(const float*) curPos
;
460 curPos
= curPos
+ sizeof(float);
462 vshader
->input
.V
[reg
].x
= x
;
463 vshader
->input
.V
[reg
].y
= 0.0f
;
464 vshader
->input
.V
[reg
].z
= 0.0f
;
465 vshader
->input
.V
[reg
].w
= 1.0f
;
469 x
= *(const float*) curPos
;
470 curPos
= curPos
+ sizeof(float);
471 y
= *(const float*) curPos
;
472 curPos
= curPos
+ sizeof(float);
474 vshader
->input
.V
[reg
].x
= x
;
475 vshader
->input
.V
[reg
].y
= y
;
476 vshader
->input
.V
[reg
].z
= 0.0f
;
477 vshader
->input
.V
[reg
].w
= 1.0f
;
481 x
= *(const float*) curPos
;
482 curPos
= curPos
+ sizeof(float);
483 y
= *(const float*) curPos
;
484 curPos
= curPos
+ sizeof(float);
485 z
= *(const float*) curPos
;
486 curPos
= curPos
+ sizeof(float);
488 vshader
->input
.V
[reg
].x
= x
;
489 vshader
->input
.V
[reg
].y
= y
;
490 vshader
->input
.V
[reg
].z
= z
;
491 vshader
->input
.V
[reg
].w
= 1.0f
;
495 x
= *(const float*) curPos
;
496 curPos
= curPos
+ sizeof(float);
497 y
= *(const float*) curPos
;
498 curPos
= curPos
+ sizeof(float);
499 z
= *(const float*) curPos
;
500 curPos
= curPos
+ sizeof(float);
501 w
= *(const float*) curPos
;
502 curPos
= curPos
+ sizeof(float);
504 vshader
->input
.V
[reg
].x
= x
;
505 vshader
->input
.V
[reg
].y
= y
;
506 vshader
->input
.V
[reg
].z
= z
;
507 vshader
->input
.V
[reg
].w
= w
;
510 case D3DVSDT_D3DCOLOR
:
511 dw
= *(const DWORD
*) curPos
;
512 curPos
= curPos
+ sizeof(DWORD
);
514 vshader
->input
.V
[reg
].x
= D3DCOLOR_R(dw
);
515 vshader
->input
.V
[reg
].y
= D3DCOLOR_G(dw
);
516 vshader
->input
.V
[reg
].z
= D3DCOLOR_B(dw
);
517 vshader
->input
.V
[reg
].w
= D3DCOLOR_A(dw
);
521 u
= *(const SHORT
*) curPos
;
522 curPos
= curPos
+ sizeof(SHORT
);
523 v
= *(const SHORT
*) curPos
;
524 curPos
= curPos
+ sizeof(SHORT
);
526 vshader
->input
.V
[reg
].x
= (float) u
;
527 vshader
->input
.V
[reg
].y
= (float) v
;
528 vshader
->input
.V
[reg
].z
= 0.0f
;
529 vshader
->input
.V
[reg
].w
= 1.0f
;
533 u
= *(const SHORT
*) curPos
;
534 curPos
= curPos
+ sizeof(SHORT
);
535 v
= *(const SHORT
*) curPos
;
536 curPos
= curPos
+ sizeof(SHORT
);
537 r
= *(const SHORT
*) curPos
;
538 curPos
= curPos
+ sizeof(SHORT
);
539 t
= *(const SHORT
*) curPos
;
540 curPos
= curPos
+ sizeof(SHORT
);
542 vshader
->input
.V
[reg
].x
= (float) u
;
543 vshader
->input
.V
[reg
].y
= (float) v
;
544 vshader
->input
.V
[reg
].z
= (float) r
;
545 vshader
->input
.V
[reg
].w
= (float) t
;
549 dw
= *(const DWORD
*) curPos
;
550 curPos
= curPos
+ sizeof(DWORD
);
552 vshader
->input
.V
[reg
].x
= (float) ((dw
& 0x000000FF) >> 0);
553 vshader
->input
.V
[reg
].y
= (float) ((dw
& 0x0000FF00) >> 8);
554 vshader
->input
.V
[reg
].z
= (float) ((dw
& 0x00FF0000) >> 16);
555 vshader
->input
.V
[reg
].w
= (float) ((dw
& 0xFF000000) >> 24);
558 default: /** errooooorr what to do ? */
559 ERR("Error in VertexShader declaration of %s register: unsupported type %s\n", VertexShaderDeclRegister
[reg
], VertexShaderDeclDataTypes
[type
]);
564 /* here D3DVSD_END() */
568 HRESULT WINAPI
IDirect3DDeviceImpl_FillVertexShaderInputArbHW(IDirect3DDevice8Impl
* This
,
569 IDirect3DVertexShaderImpl
* vshader
,
570 DWORD SkipnStrides
) {
572 const DWORD
* pToken
= This
->UpdateStateBlock
->vertexShaderDecl
->pDeclaration8
;
577 /** for input readers */
578 const BYTE
* curPos
= NULL
;
581 TRACE("(%p) - This:%p, skipstrides=%lu\n", vshader
, This
, SkipnStrides
);
583 while (D3DVSD_END() != *pToken
) {
585 tokentype
= ((token
& D3DVSD_TOKENTYPEMASK
) >> D3DVSD_TOKENTYPESHIFT
);
587 /** FVF generation block */
588 if (D3DVSD_TOKEN_STREAM
== tokentype
&& 0 == (D3DVSD_STREAMTESSMASK
& token
)) {
589 IDirect3DVertexBuffer8
* pVB
;
593 * how really works streams,
594 * in DolphinVS dx8 dsk sample use it !!!
596 stream
= ((token
& D3DVSD_STREAMNUMBERMASK
) >> D3DVSD_STREAMNUMBERSHIFT
);
597 skip
= This
->StateBlock
->stream_stride
[stream
];
598 pVB
= This
->StateBlock
->stream_source
[stream
];
601 ERR("using unitialised stream[%lu]\n", stream
);
602 return D3DERR_INVALIDCALL
;
604 if (This
->StateBlock
->streamIsUP
) {
605 curPos
= ((BYTE
*) pVB
) + (SkipnStrides
* skip
); /* Not really a VB */
607 curPos
= ((IDirect3DVertexBuffer8Impl
*) pVB
)->allocatedMemory
+ (SkipnStrides
* skip
);
610 TRACE(" using stream[%lu] with %p (%p + (Stride %d * skip %ld))\n", stream
, curPos
,
611 ((IDirect3DVertexBuffer8Impl
*) pVB
)->allocatedMemory
, skip
, SkipnStrides
);
613 } else if (D3DVSD_TOKEN_CONSTMEM
== tokentype
) {
616 DWORD count
= ((token
& D3DVSD_CONSTCOUNTMASK
) >> D3DVSD_CONSTCOUNTSHIFT
);
617 DWORD constaddress
= ((token
& D3DVSD_CONSTADDRESSMASK
) >> D3DVSD_CONSTADDRESSSHIFT
);
620 for (i
= 0; i
< count
; ++i
) {
621 FIXME("Confirm this is correct handling of consts inside the hw vertex shader\n");
622 GL_EXTCALL(glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB
, constaddress
+i
, (GLfloat
*)pToken
));
623 vshader
->data
->C
[constaddress
+ i
].x
= *(const float*)pToken
;
624 vshader
->data
->C
[constaddress
+ i
].y
= *(const float*)(pToken
+ 1);
625 vshader
->data
->C
[constaddress
+ i
].z
= *(const float*)(pToken
+ 2);
626 vshader
->data
->C
[constaddress
+ i
].w
= *(const float*)(pToken
+ 3);
630 } else if (D3DVSD_TOKEN_STREAMDATA
== tokentype
&& 0 != (0x10000000 & tokentype
)) {
632 DWORD skipCount
= ((token
& D3DVSD_SKIPCOUNTMASK
) >> D3DVSD_SKIPCOUNTSHIFT
);
633 TRACE(" skipping %ld dwords\n", skipCount
);
634 curPos
= curPos
+ skipCount
* sizeof(DWORD
);
637 } else if (D3DVSD_TOKEN_STREAMDATA
== tokentype
&& 0 == (0x10000000 & tokentype
)) {
638 DWORD type
= ((token
& D3DVSD_DATATYPEMASK
) >> D3DVSD_DATATYPESHIFT
);
639 DWORD reg
= ((token
& D3DVSD_VERTEXREGMASK
) >> D3DVSD_VERTEXREGSHIFT
);
642 TRACE(" type : %ld, reg = %ld\n", type
, reg
);
645 TRACE("HW VS glVertexAttribPointerARB(reg=%ld,num=%d,skip=%d,ptr=%p)\n", reg
, 1, skip
, curPos
);
646 GL_EXTCALL(glVertexAttribPointerARB(reg
, 1, GL_FLOAT
, GL_FALSE
, skip
, curPos
));
647 GL_EXTCALL(glEnableVertexAttribArrayARB(reg
));
648 curPos
= curPos
+ sizeof(float);
652 TRACE("HW VS glVertexAttribPointerARB(reg=%ld,num=%d,skip=%d,ptr=%p)\n", reg
, 2, skip
, curPos
);
653 GL_EXTCALL(glVertexAttribPointerARB(reg
, 2, GL_FLOAT
, GL_FALSE
, skip
, curPos
));
654 GL_EXTCALL(glEnableVertexAttribArrayARB(reg
));
655 curPos
= curPos
+ 2*sizeof(float);
659 TRACE("HW VS glVertexAttribPointerARB(reg=%ld,num=%d,skip=%d,ptr=%p)\n", reg
, 3, skip
, curPos
);
660 GL_EXTCALL(glVertexAttribPointerARB(reg
, 3, GL_FLOAT
, GL_FALSE
, skip
, curPos
));
661 GL_EXTCALL(glEnableVertexAttribArrayARB(reg
));
662 curPos
= curPos
+ 3*sizeof(float);
666 TRACE("HW VS glVertexAttribPointerARB(reg=%ld,num=%d,skip=%d,ptr=%p)\n", reg
, 4, skip
, curPos
);
667 GL_EXTCALL(glVertexAttribPointerARB(reg
, 4, GL_FLOAT
, GL_FALSE
, skip
, curPos
));
668 GL_EXTCALL(glEnableVertexAttribArrayARB(reg
));
669 curPos
= curPos
+ 4*sizeof(float);
672 case D3DVSDT_D3DCOLOR
:
673 TRACE("HW VS glVertexAttribPointerARB(reg=%ld,num=%d,skip=%d,ptr=%p)\n", reg
, 4, skip
, curPos
);
674 FIXME("D3DVSDT_D3DCOLOR in hw shader - To confirm\n");
675 GL_EXTCALL(glVertexAttribPointerARB(reg
, 4, GL_UNSIGNED_BYTE
, GL_TRUE
, skip
, curPos
));
676 GL_EXTCALL(glEnableVertexAttribArrayARB(reg
));
677 curPos
= curPos
+ 4*sizeof(BYTE
);
681 TRACE("HW VS glVertexAttribPointerARB(reg=%ld,num=%d,skip=%d,ptr=%p)\n", reg
, 2, skip
, curPos
);
682 GL_EXTCALL(glVertexAttribPointerARB(reg
, 2, GL_UNSIGNED_SHORT
, GL_FALSE
, skip
, curPos
));
683 GL_EXTCALL(glEnableVertexAttribArrayARB(reg
));
684 curPos
= curPos
+ 2*sizeof(short int);
688 TRACE("HW VS glVertexAttribPointerARB(reg=%ld,num=%d,skip=%d,ptr=%p)\n", reg
, 1, skip
, curPos
);
689 GL_EXTCALL(glVertexAttribPointerARB(reg
, 4, GL_UNSIGNED_SHORT
, GL_FALSE
, skip
, curPos
));
690 GL_EXTCALL(glEnableVertexAttribArrayARB(reg
));
691 curPos
= curPos
+ 4*sizeof(short int);
695 FIXME("D3DVSDT_UBYTE4 in hw shader - To confirm\n");
696 GL_EXTCALL(glVertexAttribPointerARB(reg
, 4, GL_UNSIGNED_BYTE
, GL_TRUE
, skip
, curPos
));
697 GL_EXTCALL(glEnableVertexAttribArrayARB(reg
));
698 curPos
= curPos
+ 4*sizeof(BYTE
);
701 default: /** errooooorr what to do ? */
702 ERR("Error in VertexShader declaration of %s register: unsupported type %s\n", VertexShaderDeclRegister
[reg
], VertexShaderDeclDataTypes
[type
]);
707 /* here D3DVSD_END() */
711 HRESULT WINAPI
IDirect3DVertexShaderDeclarationImpl_GetDeclaration8(IDirect3DVertexShaderDeclarationImpl
* This
, DWORD
* pData
, UINT
* pSizeOfData
) {
713 *pSizeOfData
= This
->declaration8Length
;
716 if (*pSizeOfData
< This
->declaration8Length
) {
717 *pSizeOfData
= This
->declaration8Length
;
718 return D3DERR_MOREDATA
;
720 TRACE("(%p) : GetVertexShaderDeclaration copying to %p\n", This
, pData
);
721 memcpy(pData
, This
->pDeclaration8
, This
->declaration8Length
);