2 * Copyright 2008 Luis Busquets
3 * Copyright 2009 Matteo Bruni
4 * Copyright 2011 Travis Athougies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "d3dx9_36_private.h"
22 #include "d3dcompiler.h"
25 /* This function is not declared in the SDK headers yet. */
26 HRESULT WINAPI
D3DAssemble(const void *data
, SIZE_T datasize
, const char *filename
,
27 const D3D_SHADER_MACRO
*defines
, ID3DInclude
*include
, UINT flags
,
28 ID3DBlob
**shader
, ID3DBlob
**error_messages
);
30 static inline BOOL
is_valid_bytecode(DWORD token
)
32 return (token
& 0xfffe0000) == 0xfffe0000;
35 const char * WINAPI
D3DXGetPixelShaderProfile(struct IDirect3DDevice9
*device
)
39 TRACE("device %p\n", device
);
41 if (!device
) return NULL
;
43 IDirect3DDevice9_GetDeviceCaps(device
,&caps
);
45 switch (caps
.PixelShaderVersion
)
47 case D3DPS_VERSION(1, 1):
50 case D3DPS_VERSION(1, 2):
53 case D3DPS_VERSION(1, 3):
56 case D3DPS_VERSION(1, 4):
59 case D3DPS_VERSION(2, 0):
60 if ((caps
.PS20Caps
.NumTemps
>=22) &&
61 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_ARBITRARYSWIZZLE
) &&
62 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_GRADIENTINSTRUCTIONS
) &&
63 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_PREDICATION
) &&
64 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_NODEPENDENTREADLIMIT
) &&
65 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT
))
69 if ((caps
.PS20Caps
.NumTemps
>=32) &&
70 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT
))
76 case D3DPS_VERSION(3, 0):
83 UINT WINAPI
D3DXGetShaderSize(const DWORD
*byte_code
)
85 const DWORD
*ptr
= byte_code
;
87 TRACE("byte_code %p\n", byte_code
);
91 /* Look for the END token, skipping the VERSION token */
92 while (*++ptr
!= D3DSIO_END
)
95 if ((*ptr
& D3DSI_OPCODE_MASK
) == D3DSIO_COMMENT
)
97 ptr
+= ((*ptr
& D3DSI_COMMENTSIZE_MASK
) >> D3DSI_COMMENTSIZE_SHIFT
);
102 /* Return the shader size in bytes */
103 return (ptr
- byte_code
) * sizeof(*ptr
);
106 DWORD WINAPI
D3DXGetShaderVersion(const DWORD
*byte_code
)
108 TRACE("byte_code %p\n", byte_code
);
110 return byte_code
? *byte_code
: 0;
113 const char * WINAPI
D3DXGetVertexShaderProfile(struct IDirect3DDevice9
*device
)
117 TRACE("device %p\n", device
);
119 if (!device
) return NULL
;
121 IDirect3DDevice9_GetDeviceCaps(device
,&caps
);
123 switch (caps
.VertexShaderVersion
)
125 case D3DVS_VERSION(1, 1):
127 case D3DVS_VERSION(2, 0):
128 if ((caps
.VS20Caps
.NumTemps
>=13) &&
129 (caps
.VS20Caps
.DynamicFlowControlDepth
==24) &&
130 (caps
.VS20Caps
.Caps
&D3DPS20CAPS_PREDICATION
))
135 case D3DVS_VERSION(3, 0):
142 HRESULT WINAPI
D3DXFindShaderComment(const DWORD
*byte_code
, DWORD fourcc
, const void **data
, UINT
*size
)
144 const DWORD
*ptr
= byte_code
;
147 TRACE("byte_code %p, fourcc %x, data %p, size %p\n", byte_code
, fourcc
, data
, size
);
149 if (data
) *data
= NULL
;
152 if (!byte_code
) return D3DERR_INVALIDCALL
;
154 version
= *ptr
>> 16;
155 if (version
!= 0x4658 /* FX */
156 && version
!= 0x5458 /* TX */
159 && version
!= 0xfffe /* VS */
160 && version
!= 0xffff) /* PS */
162 WARN("Invalid data supplied\n");
163 return D3DXERR_INVALIDDATA
;
166 while (*++ptr
!= D3DSIO_END
)
168 /* Check if it is a comment */
169 if ((*ptr
& D3DSI_OPCODE_MASK
) == D3DSIO_COMMENT
)
171 DWORD comment_size
= (*ptr
& D3DSI_COMMENTSIZE_MASK
) >> D3DSI_COMMENTSIZE_SHIFT
;
173 /* Check if this is the comment we are looking for */
174 if (*(ptr
+ 1) == fourcc
)
176 UINT ctab_size
= (comment_size
- 1) * sizeof(DWORD
);
177 const void *ctab_data
= ptr
+ 2;
182 TRACE("Returning comment data at %p with size %d\n", ctab_data
, ctab_size
);
192 HRESULT WINAPI
D3DXAssembleShader(const char *data
, UINT data_len
, const D3DXMACRO
*defines
,
193 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
197 TRACE("data %p, data_len %u, defines %p, include %p, flags %#x, shader %p, error_messages %p\n",
198 data
, data_len
, defines
, include
, flags
, shader
, error_messages
);
200 /* Forward to d3dcompiler: the parameter types aren't really different,
201 the actual data types are equivalent */
202 hr
= D3DAssemble(data
, data_len
, NULL
, (D3D_SHADER_MACRO
*)defines
,
203 (ID3DInclude
*)include
, flags
, (ID3DBlob
**)shader
,
204 (ID3DBlob
**)error_messages
);
206 if(hr
== E_FAIL
) hr
= D3DXERR_INVALIDDATA
;
210 /* D3DXInclude private implementation, used to implement
211 * D3DXAssembleShaderFromFile() from D3DXAssembleShader(). */
212 /* To be able to correctly resolve include search paths we have to store the
213 * pathname of each include file. We store the pathname pointer right before
215 static HRESULT WINAPI
d3dincludefromfile_open(ID3DXInclude
*iface
, D3DXINCLUDE_TYPE include_type
,
216 const char *filename
, const void *parent_data
, const void **data
, UINT
*bytes
)
218 const char *p
, *parent_name
= "";
219 char *pathname
= NULL
;
220 char **buffer
= NULL
;
224 if(parent_data
!= NULL
)
225 parent_name
= *((const char **)parent_data
- 1);
227 TRACE("Looking up for include file %s, parent %s\n", debugstr_a(filename
), debugstr_a(parent_name
));
229 if ((p
= strrchr(parent_name
, '\\')) || (p
= strrchr(parent_name
, '/'))) p
++;
230 else p
= parent_name
;
231 pathname
= HeapAlloc(GetProcessHeap(), 0, (p
- parent_name
) + strlen(filename
) + 1);
233 return HRESULT_FROM_WIN32(GetLastError());
235 memcpy(pathname
, parent_name
, p
- parent_name
);
236 strcpy(pathname
+ (p
- parent_name
), filename
);
238 file
= CreateFileA(pathname
, GENERIC_READ
, FILE_SHARE_READ
, 0, OPEN_EXISTING
, 0, 0);
239 if(file
== INVALID_HANDLE_VALUE
)
242 TRACE("Include file found at pathname = %s\n", debugstr_a(pathname
));
244 size
= GetFileSize(file
, NULL
);
245 if(size
== INVALID_FILE_SIZE
)
248 buffer
= HeapAlloc(GetProcessHeap(), 0, size
+ sizeof(char *));
252 if(!ReadFile(file
, buffer
+ 1, size
, bytes
, NULL
))
262 HeapFree(GetProcessHeap(), 0, pathname
);
263 HeapFree(GetProcessHeap(), 0, buffer
);
264 return HRESULT_FROM_WIN32(GetLastError());
267 static HRESULT WINAPI
d3dincludefromfile_close(ID3DXInclude
*iface
, const void *data
)
269 HeapFree(GetProcessHeap(), 0, *((char **)data
- 1));
270 HeapFree(GetProcessHeap(), 0, (char **)data
- 1);
274 static const struct ID3DXIncludeVtbl D3DXInclude_Vtbl
= {
275 d3dincludefromfile_open
,
276 d3dincludefromfile_close
279 struct D3DXIncludeImpl
{
280 ID3DXInclude ID3DXInclude_iface
;
283 HRESULT WINAPI
D3DXAssembleShaderFromFileA(const char *filename
, const D3DXMACRO
*defines
,
284 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
290 TRACE("filename %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
291 debugstr_a(filename
), defines
, include
, flags
, shader
, error_messages
);
293 if (!filename
) return D3DXERR_INVALIDDATA
;
295 len
= MultiByteToWideChar(CP_ACP
, 0, filename
, -1, NULL
, 0);
296 filename_w
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
297 if (!filename_w
) return E_OUTOFMEMORY
;
298 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filename_w
, len
);
300 ret
= D3DXAssembleShaderFromFileW(filename_w
, defines
, include
, flags
, shader
, error_messages
);
302 HeapFree(GetProcessHeap(), 0, filename_w
);
306 HRESULT WINAPI
D3DXAssembleShaderFromFileW(const WCHAR
*filename
, const D3DXMACRO
*defines
,
307 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
312 struct D3DXIncludeImpl includefromfile
;
315 TRACE("filename %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
316 debugstr_w(filename
), defines
, include
, flags
, shader
, error_messages
);
320 includefromfile
.ID3DXInclude_iface
.lpVtbl
= &D3DXInclude_Vtbl
;
321 include
= &includefromfile
.ID3DXInclude_iface
;
324 len
= WideCharToMultiByte(CP_ACP
, 0, filename
, -1, NULL
, 0, NULL
, NULL
);
325 filename_a
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(char));
327 return E_OUTOFMEMORY
;
328 WideCharToMultiByte(CP_ACP
, 0, filename
, -1, filename_a
, len
, NULL
, NULL
);
330 hr
= ID3DXInclude_Open(include
, D3D_INCLUDE_LOCAL
, filename_a
, NULL
, &buffer
, &len
);
333 HeapFree(GetProcessHeap(), 0, filename_a
);
334 return D3DXERR_INVALIDDATA
;
337 hr
= D3DXAssembleShader(buffer
, len
, defines
, include
, flags
, shader
, error_messages
);
339 ID3DXInclude_Close(include
, buffer
);
340 HeapFree(GetProcessHeap(), 0, filename_a
);
344 HRESULT WINAPI
D3DXAssembleShaderFromResourceA(HMODULE module
, const char *resource
, const D3DXMACRO
*defines
,
345 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
351 TRACE("module %p, resource %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
352 module
, debugstr_a(resource
), defines
, include
, flags
, shader
, error_messages
);
354 if (!(res
= FindResourceA(module
, resource
, (const char *)RT_RCDATA
)))
355 return D3DXERR_INVALIDDATA
;
356 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
357 return D3DXERR_INVALIDDATA
;
358 return D3DXAssembleShader(buffer
, len
, defines
, include
, flags
,
359 shader
, error_messages
);
362 HRESULT WINAPI
D3DXAssembleShaderFromResourceW(HMODULE module
, const WCHAR
*resource
, const D3DXMACRO
*defines
,
363 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
369 TRACE("module %p, resource %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
370 module
, debugstr_w(resource
), defines
, include
, flags
, shader
, error_messages
);
372 if (!(res
= FindResourceW(module
, resource
, (const WCHAR
*)RT_RCDATA
)))
373 return D3DXERR_INVALIDDATA
;
374 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
375 return D3DXERR_INVALIDDATA
;
376 return D3DXAssembleShader(buffer
, len
, defines
, include
, flags
,
377 shader
, error_messages
);
380 HRESULT WINAPI
D3DXCompileShader(const char *data
, UINT length
, const D3DXMACRO
*defines
,
381 ID3DXInclude
*include
, const char *function
, const char *profile
, DWORD flags
,
382 ID3DXBuffer
**shader
, ID3DXBuffer
**error_msgs
, ID3DXConstantTable
**constant_table
)
386 TRACE("data %s, length %u, defines %p, include %p, function %s, profile %s, "
387 "flags %#x, shader %p, error_msgs %p, constant_table %p.\n",
388 debugstr_a(data
), length
, defines
, include
, debugstr_a(function
), debugstr_a(profile
),
389 flags
, shader
, error_msgs
, constant_table
);
391 hr
= D3DCompile(data
, length
, NULL
, (D3D_SHADER_MACRO
*)defines
, (ID3DInclude
*)include
,
392 function
, profile
, flags
, 0, (ID3DBlob
**)shader
, (ID3DBlob
**)error_msgs
);
394 if (SUCCEEDED(hr
) && constant_table
)
396 hr
= D3DXGetShaderConstantTable(ID3DXBuffer_GetBufferPointer(*shader
), constant_table
);
399 ID3DXBuffer_Release(*shader
);
407 HRESULT WINAPI
D3DXCompileShaderFromFileA(const char *filename
, const D3DXMACRO
*defines
,
408 ID3DXInclude
*include
, const char *entrypoint
, const char *profile
, DWORD flags
,
409 ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
, ID3DXConstantTable
**constant_table
)
415 TRACE("filename %s, defines %p, include %p, entrypoint %s, profile %s, "
416 "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
417 debugstr_a(filename
), defines
, include
, debugstr_a(entrypoint
),
418 debugstr_a(profile
), flags
, shader
, error_messages
, constant_table
);
420 if (!filename
) return D3DXERR_INVALIDDATA
;
422 len
= MultiByteToWideChar(CP_ACP
, 0, filename
, -1, NULL
, 0);
423 filename_w
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
424 if (!filename_w
) return E_OUTOFMEMORY
;
425 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filename_w
, len
);
427 ret
= D3DXCompileShaderFromFileW(filename_w
, defines
, include
,
428 entrypoint
, profile
, flags
,
429 shader
, error_messages
, constant_table
);
431 HeapFree(GetProcessHeap(), 0, filename_w
);
435 HRESULT WINAPI
D3DXCompileShaderFromFileW(const WCHAR
*filename
, const D3DXMACRO
*defines
,
436 ID3DXInclude
*include
, const char *entrypoint
, const char *profile
, DWORD flags
,
437 ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
, ID3DXConstantTable
**constant_table
)
440 DWORD len
, filename_len
;
442 struct D3DXIncludeImpl includefromfile
;
445 TRACE("filename %s, defines %p, include %p, entrypoint %s, profile %s, "
446 "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
447 debugstr_w(filename
), defines
, include
, debugstr_a(entrypoint
), debugstr_a(profile
),
448 flags
, shader
, error_messages
, constant_table
);
452 includefromfile
.ID3DXInclude_iface
.lpVtbl
= &D3DXInclude_Vtbl
;
453 include
= &includefromfile
.ID3DXInclude_iface
;
456 filename_len
= WideCharToMultiByte(CP_ACP
, 0, filename
, -1, NULL
, 0, NULL
, NULL
);
457 filename_a
= HeapAlloc(GetProcessHeap(), 0, filename_len
* sizeof(char));
459 return E_OUTOFMEMORY
;
460 WideCharToMultiByte(CP_ACP
, 0, filename
, -1, filename_a
, filename_len
, NULL
, NULL
);
462 hr
= ID3DXInclude_Open(include
, D3D_INCLUDE_LOCAL
, filename_a
, NULL
, &buffer
, &len
);
465 HeapFree(GetProcessHeap(), 0, filename_a
);
466 return D3DXERR_INVALIDDATA
;
469 hr
= D3DCompile(buffer
, len
, filename_a
, (const D3D_SHADER_MACRO
*)defines
,
470 (ID3DInclude
*)include
, entrypoint
, profile
, flags
, 0,
471 (ID3DBlob
**)shader
, (ID3DBlob
**)error_messages
);
473 if (SUCCEEDED(hr
) && constant_table
)
474 hr
= D3DXGetShaderConstantTable(ID3DXBuffer_GetBufferPointer(*shader
),
477 ID3DXInclude_Close(include
, buffer
);
478 HeapFree(GetProcessHeap(), 0, filename_a
);
482 HRESULT WINAPI
D3DXCompileShaderFromResourceA(HMODULE module
, const char *resource
, const D3DXMACRO
*defines
,
483 ID3DXInclude
*include
, const char *entrypoint
, const char *profile
, DWORD flags
,
484 ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
, ID3DXConstantTable
**constant_table
)
490 TRACE("module %p, resource %s, defines %p, include %p, entrypoint %s, profile %s, "
491 "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
492 module
, debugstr_a(resource
), defines
, include
, debugstr_a(entrypoint
), debugstr_a(profile
),
493 flags
, shader
, error_messages
, constant_table
);
495 if (!(res
= FindResourceA(module
, resource
, (const char *)RT_RCDATA
)))
496 return D3DXERR_INVALIDDATA
;
497 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
498 return D3DXERR_INVALIDDATA
;
499 return D3DXCompileShader(buffer
, len
, defines
, include
, entrypoint
, profile
,
500 flags
, shader
, error_messages
, constant_table
);
503 HRESULT WINAPI
D3DXCompileShaderFromResourceW(HMODULE module
, const WCHAR
*resource
, const D3DXMACRO
*defines
,
504 ID3DXInclude
*include
, const char *entrypoint
, const char *profile
, DWORD flags
,
505 ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
, ID3DXConstantTable
**constant_table
)
511 TRACE("module %p, resource %s, defines %p, include %p, entrypoint %s, profile %s, "
512 "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
513 module
, debugstr_w(resource
), defines
, include
, debugstr_a(entrypoint
), debugstr_a(profile
),
514 flags
, shader
, error_messages
, constant_table
);
516 if (!(res
= FindResourceW(module
, resource
, (const WCHAR
*)RT_RCDATA
)))
517 return D3DXERR_INVALIDDATA
;
518 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
519 return D3DXERR_INVALIDDATA
;
520 return D3DXCompileShader(buffer
, len
, defines
, include
, entrypoint
, profile
,
521 flags
, shader
, error_messages
, constant_table
);
524 HRESULT WINAPI
D3DXPreprocessShader(const char *data
, UINT data_len
, const D3DXMACRO
*defines
,
525 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
527 TRACE("data %s, data_len %u, defines %p, include %p, shader %p, error_messages %p.\n",
528 debugstr_a(data
), data_len
, defines
, include
, shader
, error_messages
);
530 return D3DPreprocess(data
, data_len
, NULL
,
531 (const D3D_SHADER_MACRO
*)defines
, (ID3DInclude
*)include
,
532 (ID3DBlob
**)shader
, (ID3DBlob
**)error_messages
);
535 HRESULT WINAPI
D3DXPreprocessShaderFromFileA(const char *filename
, const D3DXMACRO
*defines
,
536 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
538 WCHAR
*filename_w
= NULL
;
542 TRACE("filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
543 debugstr_a(filename
), defines
, include
, shader
, error_messages
);
545 if (!filename
) return D3DXERR_INVALIDDATA
;
547 len
= MultiByteToWideChar(CP_ACP
, 0, filename
, -1, NULL
, 0);
548 filename_w
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
549 if (!filename_w
) return E_OUTOFMEMORY
;
550 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filename_w
, len
);
552 ret
= D3DXPreprocessShaderFromFileW(filename_w
, defines
, include
, shader
, error_messages
);
554 HeapFree(GetProcessHeap(), 0, filename_w
);
558 HRESULT WINAPI
D3DXPreprocessShaderFromFileW(const WCHAR
*filename
, const D3DXMACRO
*defines
,
559 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
564 struct D3DXIncludeImpl includefromfile
;
567 TRACE("filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
568 debugstr_w(filename
), defines
, include
, shader
, error_messages
);
572 includefromfile
.ID3DXInclude_iface
.lpVtbl
= &D3DXInclude_Vtbl
;
573 include
= &includefromfile
.ID3DXInclude_iface
;
576 len
= WideCharToMultiByte(CP_ACP
, 0, filename
, -1, NULL
, 0, NULL
, NULL
);
577 filename_a
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(char));
579 return E_OUTOFMEMORY
;
580 WideCharToMultiByte(CP_ACP
, 0, filename
, -1, filename_a
, len
, NULL
, NULL
);
582 hr
= ID3DXInclude_Open(include
, D3D_INCLUDE_LOCAL
, filename_a
, NULL
, &buffer
, &len
);
585 HeapFree(GetProcessHeap(), 0, filename_a
);
586 return D3DXERR_INVALIDDATA
;
589 hr
= D3DPreprocess(buffer
, len
, NULL
,
590 (const D3D_SHADER_MACRO
*)defines
,
591 (ID3DInclude
*) include
,
592 (ID3DBlob
**)shader
, (ID3DBlob
**)error_messages
);
594 ID3DXInclude_Close(include
, buffer
);
595 HeapFree(GetProcessHeap(), 0, filename_a
);
599 HRESULT WINAPI
D3DXPreprocessShaderFromResourceA(HMODULE module
, const char *resource
, const D3DXMACRO
*defines
,
600 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
606 TRACE("module %p, resource %s, defines %p, include %p, shader %p, error_messages %p.\n",
607 module
, debugstr_a(resource
), defines
, include
, shader
, error_messages
);
609 if (!(res
= FindResourceA(module
, resource
, (const char *)RT_RCDATA
)))
610 return D3DXERR_INVALIDDATA
;
611 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
612 return D3DXERR_INVALIDDATA
;
613 return D3DXPreprocessShader(buffer
, len
, defines
, include
,
614 shader
, error_messages
);
617 HRESULT WINAPI
D3DXPreprocessShaderFromResourceW(HMODULE module
, const WCHAR
*resource
, const D3DXMACRO
*defines
,
618 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
624 TRACE("module %p, resource %s, defines %p, include %p, shader %p, error_messages %p.\n",
625 module
, debugstr_w(resource
), defines
, include
, shader
, error_messages
);
627 if (!(res
= FindResourceW(module
, resource
, (const WCHAR
*)RT_RCDATA
)))
628 return D3DXERR_INVALIDDATA
;
629 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
630 return D3DXERR_INVALIDDATA
;
631 return D3DXPreprocessShader(buffer
, len
, defines
, include
,
632 shader
, error_messages
);
636 struct ctab_constant
{
637 D3DXCONSTANT_DESC desc
;
638 struct ctab_constant
*constants
;
641 struct ID3DXConstantTableImpl
{
642 ID3DXConstantTable ID3DXConstantTable_iface
;
646 D3DXCONSTANTTABLE_DESC desc
;
647 struct ctab_constant
*constants
;
650 static void free_constant(struct ctab_constant
*constant
)
652 if (constant
->constants
)
654 UINT i
, count
= constant
->desc
.Elements
> 1 ? constant
->desc
.Elements
: constant
->desc
.StructMembers
;
656 for (i
= 0; i
< count
; ++i
)
658 free_constant(&constant
->constants
[i
]);
660 HeapFree(GetProcessHeap(), 0, constant
->constants
);
664 static void free_constant_table(struct ID3DXConstantTableImpl
*table
)
666 if (table
->constants
)
670 for (i
= 0; i
< table
->desc
.Constants
; ++i
)
672 free_constant(&table
->constants
[i
]);
674 HeapFree(GetProcessHeap(), 0, table
->constants
);
676 HeapFree(GetProcessHeap(), 0, table
->ctab
);
679 static inline struct ID3DXConstantTableImpl
*impl_from_ID3DXConstantTable(ID3DXConstantTable
*iface
)
681 return CONTAINING_RECORD(iface
, struct ID3DXConstantTableImpl
, ID3DXConstantTable_iface
);
684 static inline BOOL
is_vertex_shader(DWORD version
)
686 return (version
& 0xffff0000) == 0xfffe0000;
689 static inline D3DXHANDLE
handle_from_constant(struct ctab_constant
*constant
)
691 return (D3DXHANDLE
)constant
;
694 static struct ctab_constant
*get_constant_by_name(struct ID3DXConstantTableImpl
*table
,
695 struct ctab_constant
*constant
, const char *name
);
697 static struct ctab_constant
*get_constant_element_by_name(struct ctab_constant
*constant
, const char *name
)
702 TRACE("constant %p, name %s\n", constant
, debugstr_a(name
));
704 if (!name
|| !*name
) return NULL
;
706 element
= atoi(name
);
707 part
= strchr(name
, ']') + 1;
709 if (constant
->desc
.Elements
> element
)
711 struct ctab_constant
*c
= constant
->constants
? &constant
->constants
[element
] : constant
;
716 return get_constant_by_name(NULL
, c
, part
);
719 return get_constant_element_by_name(c
, part
);
722 TRACE("Returning parameter %p\n", c
);
726 FIXME("Unhandled case \"%c\"\n", *--part
);
731 TRACE("Constant not found\n");
735 static struct ctab_constant
*get_constant_by_name(struct ID3DXConstantTableImpl
*table
,
736 struct ctab_constant
*constant
, const char *name
)
738 UINT i
, count
, length
;
739 struct ctab_constant
*handles
;
742 TRACE("table %p, constant %p, name %s\n", table
, constant
, debugstr_a(name
));
744 if (!name
|| !*name
) return NULL
;
748 count
= table
->desc
.Constants
;
749 handles
= table
->constants
;
753 count
= constant
->desc
.StructMembers
;
754 handles
= constant
->constants
;
757 length
= strcspn(name
, "[.");
758 part
= name
+ length
;
760 for (i
= 0; i
< count
; i
++)
762 if (strlen(handles
[i
].desc
.Name
) == length
&& !strncmp(handles
[i
].desc
.Name
, name
, length
))
767 return get_constant_by_name(NULL
, &handles
[i
], part
);
770 return get_constant_element_by_name(&handles
[i
], part
);
773 TRACE("Returning parameter %p\n", &handles
[i
]);
779 TRACE("Constant not found\n");
783 static struct ctab_constant
*is_valid_sub_constant(struct ctab_constant
*parent
, D3DXHANDLE handle
)
785 struct ctab_constant
*c
;
788 /* all variable have at least elements = 1, but not always elements */
789 if (!parent
->constants
) return NULL
;
791 count
= parent
->desc
.Elements
> 1 ? parent
->desc
.Elements
: parent
->desc
.StructMembers
;
792 for (i
= 0; i
< count
; ++i
)
794 if (handle_from_constant(&parent
->constants
[i
]) == handle
)
795 return &parent
->constants
[i
];
797 c
= is_valid_sub_constant(&parent
->constants
[i
], handle
);
804 static inline struct ctab_constant
*get_valid_constant(struct ID3DXConstantTableImpl
*table
, D3DXHANDLE handle
)
806 struct ctab_constant
*c
;
809 if (!handle
) return NULL
;
811 for (i
= 0; i
< table
->desc
.Constants
; ++i
)
813 if (handle_from_constant(&table
->constants
[i
]) == handle
)
814 return &table
->constants
[i
];
816 c
= is_valid_sub_constant(&table
->constants
[i
], handle
);
820 return get_constant_by_name(table
, NULL
, handle
);
823 /*** IUnknown methods ***/
824 static HRESULT WINAPI
ID3DXConstantTableImpl_QueryInterface(ID3DXConstantTable
*iface
, REFIID riid
, void **out
)
826 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
828 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
829 IsEqualGUID(riid
, &IID_ID3DXBuffer
) ||
830 IsEqualGUID(riid
, &IID_ID3DXConstantTable
))
832 ID3DXConstantTable_AddRef(iface
);
837 WARN("Interface %s not found.\n", debugstr_guid(riid
));
839 return E_NOINTERFACE
;
842 static ULONG WINAPI
ID3DXConstantTableImpl_AddRef(ID3DXConstantTable
*iface
)
844 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
846 TRACE("(%p)->(): AddRef from %d\n", This
, This
->ref
);
848 return InterlockedIncrement(&This
->ref
);
851 static ULONG WINAPI
ID3DXConstantTableImpl_Release(ID3DXConstantTable
*iface
)
853 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
854 ULONG ref
= InterlockedDecrement(&This
->ref
);
856 TRACE("(%p)->(): Release from %d\n", This
, ref
+ 1);
860 free_constant_table(This
);
861 HeapFree(GetProcessHeap(), 0, This
);
867 /*** ID3DXBuffer methods ***/
868 static void * WINAPI
ID3DXConstantTableImpl_GetBufferPointer(ID3DXConstantTable
*iface
)
870 struct ID3DXConstantTableImpl
*table
= impl_from_ID3DXConstantTable(iface
);
872 TRACE("iface %p.\n", iface
);
877 static DWORD WINAPI
ID3DXConstantTableImpl_GetBufferSize(ID3DXConstantTable
*iface
)
879 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
881 TRACE("(%p)->()\n", This
);
886 /*** ID3DXConstantTable methods ***/
887 static HRESULT WINAPI
ID3DXConstantTableImpl_GetDesc(ID3DXConstantTable
*iface
, D3DXCONSTANTTABLE_DESC
*desc
)
889 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
891 TRACE("(%p)->(%p)\n", This
, desc
);
894 return D3DERR_INVALIDCALL
;
901 static HRESULT WINAPI
ID3DXConstantTableImpl_GetConstantDesc(ID3DXConstantTable
*iface
, D3DXHANDLE constant
,
902 D3DXCONSTANT_DESC
*desc
, UINT
*count
)
904 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
905 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
907 TRACE("(%p)->(%p, %p, %p)\n", This
, constant
, desc
, count
);
911 WARN("Invalid argument specified\n");
912 return D3DERR_INVALIDCALL
;
915 if (desc
) *desc
= c
->desc
;
916 if (count
) *count
= 1;
921 static UINT WINAPI
ID3DXConstantTableImpl_GetSamplerIndex(ID3DXConstantTable
*iface
, D3DXHANDLE constant
)
923 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
924 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
926 TRACE("(%p)->(%p)\n", This
, constant
);
928 if (!c
|| c
->desc
.RegisterSet
!= D3DXRS_SAMPLER
)
930 WARN("Invalid argument specified\n");
934 TRACE("Returning RegisterIndex %u\n", c
->desc
.RegisterIndex
);
935 return c
->desc
.RegisterIndex
;
938 static D3DXHANDLE WINAPI
ID3DXConstantTableImpl_GetConstant(ID3DXConstantTable
*iface
, D3DXHANDLE constant
, UINT index
)
940 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
941 struct ctab_constant
*c
;
943 TRACE("(%p)->(%p, %d)\n", This
, constant
, index
);
947 c
= get_valid_constant(This
, constant
);
948 if (c
&& index
< c
->desc
.StructMembers
)
950 c
= &c
->constants
[index
];
951 TRACE("Returning constant %p\n", c
);
952 return handle_from_constant(c
);
957 if (index
< This
->desc
.Constants
)
959 c
= &This
->constants
[index
];
960 TRACE("Returning constant %p\n", c
);
961 return handle_from_constant(c
);
965 WARN("Index out of range\n");
969 static D3DXHANDLE WINAPI
ID3DXConstantTableImpl_GetConstantByName(ID3DXConstantTable
*iface
,
970 D3DXHANDLE constant
, const char *name
)
972 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
973 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
975 TRACE("iface %p, constant %p, name %s.\n", iface
, constant
, debugstr_a(name
));
977 c
= get_constant_by_name(This
, c
, name
);
978 TRACE("Returning constant %p\n", c
);
980 return handle_from_constant(c
);
983 static D3DXHANDLE WINAPI
ID3DXConstantTableImpl_GetConstantElement(ID3DXConstantTable
*iface
, D3DXHANDLE constant
, UINT index
)
985 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
986 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
988 TRACE("(%p)->(%p, %d)\n", This
, constant
, index
);
990 if (c
&& index
< c
->desc
.Elements
)
992 if (c
->desc
.Elements
> 1) c
= &c
->constants
[index
];
993 TRACE("Returning constant %p\n", c
);
994 return handle_from_constant(c
);
997 WARN("Invalid argument specified\n");
1001 static inline DWORD
get_index(const void **indata
, UINT index
, BOOL is_pointer
)
1007 return ((DWORD
**)indata
)[index
/ 16][index
% 16];
1009 return (*((DWORD
**)indata
))[index
];
1012 static UINT
set(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, struct ctab_constant
*constant
,
1013 const void **indata
, D3DXPARAMETER_TYPE intype
, UINT
*size
, UINT incol
, D3DXPARAMETER_CLASS inclass
, UINT index
,
1016 D3DXCONSTANT_DESC
*desc
= &constant
->desc
;
1017 UINT l
, i
, regcount
= 1, regsize
= 1, cin
= 1, rin
= 1, ret
, last
= 0;
1020 /* size too small to set anything */
1021 if (*size
< desc
->Rows
* desc
->Columns
)
1027 /* D3DXPC_STRUCT is somewhat special */
1028 if (desc
->Class
== D3DXPC_STRUCT
)
1031 * Struct array sets the last complete input to the first struct element, all other
1032 * elements are not set.
1033 * E.g.: struct {int i;} s1[2];
1034 * SetValue(device, "s1", [1, 2], 8) => s1 = {2, x};
1036 * struct {int i; int n} s2[2];
1037 * SetValue(device, "s2", [1, 2, 3, 4, 5], 20) => s1 = {{3, 4}, {x, x}};
1039 if (desc
->Elements
> 1)
1041 UINT offset
= *size
/ (desc
->Rows
* desc
->Columns
) - 1;
1043 offset
= min(desc
->Elements
- 1, offset
);
1044 last
= offset
* desc
->Rows
* desc
->Columns
;
1046 if ((is_pointer
|| (!is_pointer
&& inclass
== D3DXPC_MATRIX_ROWS
)) && desc
->RegisterSet
!= D3DXRS_BOOL
)
1048 set(table
, device
, &constant
->constants
[0], NULL
, intype
, size
, incol
, inclass
, 0, is_pointer
);
1052 last
+= set(table
, device
, &constant
->constants
[0], indata
, intype
, size
, incol
, inclass
,
1053 index
+ last
, is_pointer
);
1059 * D3DXRS_BOOL is always set. As there are only 16 bools and there are
1060 * exactly 16 input values, use matrix transpose.
1062 if (inclass
== D3DXPC_MATRIX_ROWS
&& desc
->RegisterSet
== D3DXRS_BOOL
)
1064 D3DXMATRIX mat
, *m
, min
;
1065 D3DXMatrixTranspose(&mat
, &min
);
1068 min
= *(D3DXMATRIX
*)(indata
[index
/ 16]);
1070 min
= **(D3DXMATRIX
**)indata
;
1072 D3DXMatrixTranspose(&mat
, &min
);
1074 for (i
= 0; i
< desc
->StructMembers
; ++i
)
1076 last
+= set(table
, device
, &constant
->constants
[i
], (const void **)&m
, intype
, size
, incol
,
1077 D3DXPC_SCALAR
, index
+ last
, is_pointer
);
1081 * For pointers or for matrix rows, only the first member is set.
1082 * All other members are set to 0. This is not true for D3DXRS_BOOL.
1083 * E.g.: struct {int i; int n} s;
1084 * SetValue(device, "s", [1, 2], 8) => s = {1, 0};
1086 else if ((is_pointer
|| (!is_pointer
&& inclass
== D3DXPC_MATRIX_ROWS
)) && desc
->RegisterSet
!= D3DXRS_BOOL
)
1088 last
= set(table
, device
, &constant
->constants
[0], indata
, intype
, size
, incol
, inclass
,
1089 index
+ last
, is_pointer
);
1091 for (i
= 1; i
< desc
->StructMembers
; ++i
)
1093 set(table
, device
, &constant
->constants
[i
], NULL
, intype
, size
, incol
, inclass
, 0, is_pointer
);
1098 for (i
= 0; i
< desc
->StructMembers
; ++i
)
1100 last
+= set(table
, device
, &constant
->constants
[i
], indata
, intype
, size
, incol
, D3DXPC_SCALAR
,
1101 index
+ last
, is_pointer
);
1110 if (desc
->Elements
> 1)
1112 for (i
= 0; i
< desc
->Elements
&& *size
> 0; ++i
)
1114 last
+= set(table
, device
, &constant
->constants
[i
], indata
, intype
, size
, incol
, inclass
,
1115 index
+ last
, is_pointer
);
1117 /* adjust the vector size for matrix rows */
1118 if (inclass
== D3DXPC_MATRIX_ROWS
&& desc
->Class
== D3DXPC_VECTOR
&& (i
% 4) == 3)
1121 *size
= *size
< 12 ? 0 : *size
- 12;
1128 switch (desc
->Class
)
1132 case D3DXPC_MATRIX_ROWS
:
1133 regcount
= min(desc
->RegisterCount
, desc
->Rows
);
1134 if (inclass
== D3DXPC_MATRIX_ROWS
) cin
= incol
;
1136 regsize
= desc
->Columns
;
1139 case D3DXPC_MATRIX_COLUMNS
:
1140 regcount
= min(desc
->RegisterCount
, desc
->Columns
);
1141 if (inclass
== D3DXPC_MATRIX_ROWS
) rin
= incol
;
1143 regsize
= desc
->Rows
;
1147 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1151 /* specific stuff for different in types */
1155 ret
= desc
->Columns
* desc
->Rows
;
1156 *size
-= desc
->Columns
* desc
->Rows
;
1160 switch (desc
->Class
)
1162 case D3DXPC_MATRIX_ROWS
:
1163 if (*size
< regcount
* 4)
1169 *size
-= 4 * regcount
;
1172 case D3DXPC_MATRIX_COLUMNS
:
1174 *size
-= 4 * regcount
;
1188 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1193 case D3DXPC_MATRIX_ROWS
:
1194 switch (desc
->Class
)
1196 case D3DXPC_MATRIX_ROWS
:
1197 case D3DXPC_MATRIX_COLUMNS
:
1215 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1221 case D3DXPC_MATRIX_COLUMNS
:
1222 switch (desc
->Class
)
1224 case D3DXPC_MATRIX_ROWS
:
1225 case D3DXPC_MATRIX_COLUMNS
:
1243 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1250 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(inclass
));
1254 /* set the registers */
1255 switch (desc
->RegisterSet
)
1258 regcount
= min(desc
->RegisterCount
, desc
->Columns
* desc
->Rows
);
1260 for (i
= 0; i
< regcount
; ++i
)
1263 DWORD t
= get_index(indata
, index
+ i
/ regsize
* rin
+ l
* cin
, is_pointer
);
1265 set_number(&tmp
, desc
->Type
, &t
, intype
);
1266 set_number(&out
, D3DXPT_BOOL
, &tmp
, desc
->Type
);
1267 if (is_vertex_shader(table
->desc
.Version
))
1268 IDirect3DDevice9_SetVertexShaderConstantB(device
, desc
->RegisterIndex
+ i
, &out
, 1);
1270 IDirect3DDevice9_SetPixelShaderConstantB(device
, desc
->RegisterIndex
+ i
, &out
, 1);
1272 if (++l
>= regsize
) l
= 0;
1277 for (i
= 0; i
< regcount
; ++i
)
1279 INT vec
[4] = {0, 0, 1, 0};
1281 for (l
= 0; l
< regsize
; ++l
)
1283 DWORD t
= get_index(indata
, index
+ i
* rin
+ l
* cin
, is_pointer
);
1285 set_number(&tmp
, desc
->Type
, &t
, intype
);
1286 set_number(&vec
[l
], D3DXPT_INT
, &tmp
, desc
->Type
);
1288 if (is_vertex_shader(table
->desc
.Version
))
1289 IDirect3DDevice9_SetVertexShaderConstantI(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1291 IDirect3DDevice9_SetPixelShaderConstantI(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1296 for (i
= 0; i
< regcount
; ++i
)
1300 for (l
= 0; l
< regsize
; ++l
)
1302 DWORD t
= get_index(indata
, index
+ i
* rin
+ l
* cin
, is_pointer
);
1304 set_number(&tmp
, desc
->Type
, &t
, intype
);
1305 set_number(&vec
[l
], D3DXPT_FLOAT
, &tmp
, desc
->Type
);
1307 if (is_vertex_shader(table
->desc
.Version
))
1308 IDirect3DDevice9_SetVertexShaderConstantF(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1310 IDirect3DDevice9_SetPixelShaderConstantF(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1315 FIXME("Unhandled register set %s\n", debug_d3dxparameter_registerset(desc
->RegisterSet
));
1320 static HRESULT
set_scalar(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1321 const void *indata
, D3DXPARAMETER_TYPE intype
)
1323 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1328 WARN("Invalid argument specified\n");
1329 return D3DERR_INVALIDCALL
;
1332 switch (c
->desc
.Class
)
1335 set(table
, device
, c
, &indata
, intype
, &count
, c
->desc
.Columns
, D3DXPC_SCALAR
, 0, FALSE
);
1339 case D3DXPC_MATRIX_ROWS
:
1340 case D3DXPC_MATRIX_COLUMNS
:
1345 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1346 return D3DERR_INVALIDCALL
;
1350 static HRESULT
set_scalar_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1351 const void *indata
, UINT count
, D3DXPARAMETER_TYPE intype
)
1353 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1357 WARN("Invalid argument specified\n");
1358 return D3DERR_INVALIDCALL
;
1361 switch (c
->desc
.Class
)
1365 case D3DXPC_MATRIX_ROWS
:
1366 case D3DXPC_MATRIX_COLUMNS
:
1368 set(table
, device
, c
, &indata
, intype
, &count
, c
->desc
.Columns
, D3DXPC_SCALAR
, 0, FALSE
);
1372 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1373 return D3DERR_INVALIDCALL
;
1377 static HRESULT
set_vector(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1378 const void *indata
, D3DXPARAMETER_TYPE intype
)
1380 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1385 WARN("Invalid argument specified\n");
1386 return D3DERR_INVALIDCALL
;
1389 switch (c
->desc
.Class
)
1394 set(table
, device
, c
, &indata
, intype
, &count
, 4, D3DXPC_VECTOR
, 0, FALSE
);
1397 case D3DXPC_MATRIX_ROWS
:
1398 case D3DXPC_MATRIX_COLUMNS
:
1402 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1403 return D3DERR_INVALIDCALL
;
1407 static HRESULT
set_vector_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1408 const void *indata
, UINT count
, D3DXPARAMETER_TYPE intype
)
1410 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1414 WARN("Invalid argument specified\n");
1415 return D3DERR_INVALIDCALL
;
1418 switch (c
->desc
.Class
)
1422 case D3DXPC_MATRIX_ROWS
:
1423 case D3DXPC_MATRIX_COLUMNS
:
1426 set(table
, device
, c
, &indata
, intype
, &count
, 4, D3DXPC_VECTOR
, 0, FALSE
);
1430 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1431 return D3DERR_INVALIDCALL
;
1435 static HRESULT
set_matrix_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1436 const void *indata
, UINT count
, BOOL transpose
)
1438 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1442 WARN("Invalid argument specified\n");
1443 return D3DERR_INVALIDCALL
;
1446 switch (c
->desc
.Class
)
1450 case D3DXPC_MATRIX_ROWS
:
1451 case D3DXPC_MATRIX_COLUMNS
:
1454 set(table
, device
, c
, &indata
, D3DXPT_FLOAT
, &count
, 4,
1455 transpose
? D3DXPC_MATRIX_ROWS
: D3DXPC_MATRIX_COLUMNS
, 0, FALSE
);
1459 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1460 return D3DERR_INVALIDCALL
;
1464 static HRESULT
set_matrix_pointer_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
,
1465 D3DXHANDLE constant
, const void **indata
, UINT count
, BOOL transpose
)
1467 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1471 WARN("Invalid argument specified\n");
1472 return D3DERR_INVALIDCALL
;
1475 switch (c
->desc
.Class
)
1479 case D3DXPC_MATRIX_ROWS
:
1480 case D3DXPC_MATRIX_COLUMNS
:
1483 set(table
, device
, c
, indata
, D3DXPT_FLOAT
, &count
, 4,
1484 transpose
? D3DXPC_MATRIX_ROWS
: D3DXPC_MATRIX_COLUMNS
, 0, TRUE
);
1488 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1489 return D3DERR_INVALIDCALL
;
1493 static HRESULT WINAPI
ID3DXConstantTableImpl_SetDefaults(struct ID3DXConstantTable
*iface
,
1494 struct IDirect3DDevice9
*device
)
1496 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1499 TRACE("iface %p, device %p\n", iface
, device
);
1503 WARN("Invalid argument specified\n");
1504 return D3DERR_INVALIDCALL
;
1507 for (i
= 0; i
< This
->desc
.Constants
; i
++)
1509 D3DXCONSTANT_DESC
*desc
= &This
->constants
[i
].desc
;
1512 if (!desc
->DefaultValue
)
1515 switch (desc
->RegisterSet
)
1518 if (is_vertex_shader(This
->desc
.Version
))
1519 hr
= IDirect3DDevice9_SetVertexShaderConstantB(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1520 desc
->RegisterCount
);
1522 hr
= IDirect3DDevice9_SetPixelShaderConstantB(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1523 desc
->RegisterCount
);
1527 if (is_vertex_shader(This
->desc
.Version
))
1528 hr
= IDirect3DDevice9_SetVertexShaderConstantI(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1529 desc
->RegisterCount
);
1531 hr
= IDirect3DDevice9_SetPixelShaderConstantI(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1532 desc
->RegisterCount
);
1536 if (is_vertex_shader(This
->desc
.Version
))
1537 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1538 desc
->RegisterCount
);
1540 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1541 desc
->RegisterCount
);
1545 FIXME("Unhandled register set %s\n", debug_d3dxparameter_registerset(desc
->RegisterSet
));
1557 static HRESULT WINAPI
ID3DXConstantTableImpl_SetValue(struct ID3DXConstantTable
*iface
,
1558 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const void *data
, unsigned int bytes
)
1560 struct ID3DXConstantTableImpl
*table
= impl_from_ID3DXConstantTable(iface
);
1561 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1562 D3DXCONSTANT_DESC
*desc
;
1564 TRACE("iface %p, device %p, constant %p, data %p, bytes %u\n", iface
, device
, constant
, data
, bytes
);
1566 if (!device
|| !c
|| !data
)
1568 WARN("Invalid argument specified\n");
1569 return D3DERR_INVALIDCALL
;
1574 switch (desc
->Class
)
1578 case D3DXPC_MATRIX_ROWS
:
1579 case D3DXPC_MATRIX_COLUMNS
:
1582 set(table
, device
, c
, &data
, desc
->Type
, &bytes
, desc
->Columns
, D3DXPC_SCALAR
, 0, FALSE
);
1586 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(desc
->Class
));
1587 return D3DERR_INVALIDCALL
;
1591 static HRESULT WINAPI
ID3DXConstantTableImpl_SetBool(struct ID3DXConstantTable
*iface
,
1592 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, BOOL b
)
1594 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1596 TRACE("iface %p, device %p, constant %p, b %d\n", iface
, device
, constant
, b
);
1598 return set_scalar(This
, device
, constant
, &b
, D3DXPT_BOOL
);
1601 static HRESULT WINAPI
ID3DXConstantTableImpl_SetBoolArray(struct ID3DXConstantTable
*iface
,
1602 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const BOOL
*b
, UINT count
)
1604 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1606 TRACE("iface %p, device %p, constant %p, b %p, count %d\n", iface
, device
, constant
, b
, count
);
1608 return set_scalar_array(This
, device
, constant
, b
, count
, D3DXPT_BOOL
);
1611 static HRESULT WINAPI
ID3DXConstantTableImpl_SetInt(struct ID3DXConstantTable
*iface
,
1612 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, INT n
)
1614 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1616 TRACE("iface %p, device %p, constant %p, n %d\n", iface
, device
, constant
, n
);
1618 return set_scalar(This
, device
, constant
, &n
, D3DXPT_INT
);
1621 static HRESULT WINAPI
ID3DXConstantTableImpl_SetIntArray(struct ID3DXConstantTable
*iface
,
1622 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const INT
*n
, UINT count
)
1624 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1626 TRACE("iface %p, device %p, constant %p, n %p, count %d\n", iface
, device
, constant
, n
, count
);
1628 return set_scalar_array(This
, device
, constant
, n
, count
, D3DXPT_INT
);
1631 static HRESULT WINAPI
ID3DXConstantTableImpl_SetFloat(struct ID3DXConstantTable
*iface
,
1632 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, float f
)
1634 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1636 TRACE("iface %p, device %p, constant %p, f %f\n", iface
, device
, constant
, f
);
1638 return set_scalar(This
, device
, constant
, &f
, D3DXPT_FLOAT
);
1641 static HRESULT WINAPI
ID3DXConstantTableImpl_SetFloatArray(struct ID3DXConstantTable
*iface
,
1642 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const float *f
, UINT count
)
1644 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1646 TRACE("iface %p, device %p, constant %p, f %p, count %d\n", iface
, device
, constant
, f
, count
);
1648 return set_scalar_array(This
, device
, constant
, f
, count
, D3DXPT_FLOAT
);
1651 static HRESULT WINAPI
ID3DXConstantTableImpl_SetVector(struct ID3DXConstantTable
*iface
,
1652 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXVECTOR4
*vector
)
1654 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1656 TRACE("iface %p, device %p, constant %p, vector %p\n", iface
, device
, constant
, vector
);
1658 return set_vector(This
, device
, constant
, vector
, D3DXPT_FLOAT
);
1661 static HRESULT WINAPI
ID3DXConstantTableImpl_SetVectorArray(struct ID3DXConstantTable
*iface
,
1662 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXVECTOR4
*vector
, UINT count
)
1664 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1666 TRACE("iface %p, device %p, constant %p, vector %p, count %u\n", iface
, device
, constant
, vector
, count
);
1668 return set_vector_array(This
, device
, constant
, vector
, count
, D3DXPT_FLOAT
);
1671 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrix(struct ID3DXConstantTable
*iface
,
1672 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
)
1674 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1676 TRACE("iface %p, device %p, constant %p, matrix %p\n", iface
, device
, constant
, matrix
);
1678 return set_matrix_array(This
, device
, constant
, matrix
, 1, FALSE
);
1681 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixArray(struct ID3DXConstantTable
*iface
,
1682 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
, UINT count
)
1684 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1686 TRACE("iface %p, device %p, constant %p, matrix %p, count %u\n", iface
, device
, constant
, matrix
, count
);
1688 return set_matrix_array(This
, device
, constant
, matrix
, count
, FALSE
);
1691 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixPointerArray(struct ID3DXConstantTable
*iface
,
1692 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
**matrix
, UINT count
)
1694 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1696 TRACE("iface %p, device %p, constant %p, matrix %p, count %u)\n", iface
, device
, constant
, matrix
, count
);
1698 return set_matrix_pointer_array(This
, device
, constant
, (const void **)matrix
, count
, FALSE
);
1701 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixTranspose(struct ID3DXConstantTable
*iface
,
1702 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
)
1704 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1706 TRACE("iface %p, device %p, constant %p, matrix %p\n", iface
, device
, constant
, matrix
);
1708 return set_matrix_array(This
, device
, constant
, matrix
, 1, TRUE
);
1711 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixTransposeArray(struct ID3DXConstantTable
*iface
,
1712 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
, UINT count
)
1714 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1716 TRACE("iface %p, device %p, constant %p, matrix %p, count %u\n", iface
, device
, constant
, matrix
, count
);
1718 return set_matrix_array(This
, device
, constant
, matrix
, count
, TRUE
);
1721 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixTransposePointerArray(struct ID3DXConstantTable
*iface
,
1722 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
**matrix
, UINT count
)
1724 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1726 TRACE("iface %p, device %p, constant %p, matrix %p, count %u)\n", iface
, device
, constant
, matrix
, count
);
1728 return set_matrix_pointer_array(This
, device
, constant
, (const void **)matrix
, count
, TRUE
);
1731 static const struct ID3DXConstantTableVtbl ID3DXConstantTable_Vtbl
=
1733 /*** IUnknown methods ***/
1734 ID3DXConstantTableImpl_QueryInterface
,
1735 ID3DXConstantTableImpl_AddRef
,
1736 ID3DXConstantTableImpl_Release
,
1737 /*** ID3DXBuffer methods ***/
1738 ID3DXConstantTableImpl_GetBufferPointer
,
1739 ID3DXConstantTableImpl_GetBufferSize
,
1740 /*** ID3DXConstantTable methods ***/
1741 ID3DXConstantTableImpl_GetDesc
,
1742 ID3DXConstantTableImpl_GetConstantDesc
,
1743 ID3DXConstantTableImpl_GetSamplerIndex
,
1744 ID3DXConstantTableImpl_GetConstant
,
1745 ID3DXConstantTableImpl_GetConstantByName
,
1746 ID3DXConstantTableImpl_GetConstantElement
,
1747 ID3DXConstantTableImpl_SetDefaults
,
1748 ID3DXConstantTableImpl_SetValue
,
1749 ID3DXConstantTableImpl_SetBool
,
1750 ID3DXConstantTableImpl_SetBoolArray
,
1751 ID3DXConstantTableImpl_SetInt
,
1752 ID3DXConstantTableImpl_SetIntArray
,
1753 ID3DXConstantTableImpl_SetFloat
,
1754 ID3DXConstantTableImpl_SetFloatArray
,
1755 ID3DXConstantTableImpl_SetVector
,
1756 ID3DXConstantTableImpl_SetVectorArray
,
1757 ID3DXConstantTableImpl_SetMatrix
,
1758 ID3DXConstantTableImpl_SetMatrixArray
,
1759 ID3DXConstantTableImpl_SetMatrixPointerArray
,
1760 ID3DXConstantTableImpl_SetMatrixTranspose
,
1761 ID3DXConstantTableImpl_SetMatrixTransposeArray
,
1762 ID3DXConstantTableImpl_SetMatrixTransposePointerArray
1765 static HRESULT
parse_ctab_constant_type(const char *ctab
, DWORD typeoffset
, struct ctab_constant
*constant
,
1766 BOOL is_element
, WORD index
, WORD max_index
, DWORD
*offset
, DWORD nameoffset
, UINT regset
)
1768 const D3DXSHADER_TYPEINFO
*type
= (LPD3DXSHADER_TYPEINFO
)(ctab
+ typeoffset
);
1769 const D3DXSHADER_STRUCTMEMBERINFO
*memberinfo
= NULL
;
1770 HRESULT hr
= D3D_OK
;
1774 constant
->desc
.DefaultValue
= offset
? ctab
+ *offset
: NULL
;
1775 constant
->desc
.Class
= type
->Class
;
1776 constant
->desc
.Type
= type
->Type
;
1777 constant
->desc
.Rows
= type
->Rows
;
1778 constant
->desc
.Columns
= type
->Columns
;
1779 constant
->desc
.Elements
= is_element
? 1 : type
->Elements
;
1780 constant
->desc
.StructMembers
= type
->StructMembers
;
1781 constant
->desc
.Name
= ctab
+ nameoffset
;
1782 constant
->desc
.RegisterSet
= regset
;
1783 constant
->desc
.RegisterIndex
= index
;
1785 TRACE("name %s, elements %u, index %u, defaultvalue %p, regset %s\n", constant
->desc
.Name
,
1786 constant
->desc
.Elements
, index
, constant
->desc
.DefaultValue
,
1787 debug_d3dxparameter_registerset(regset
));
1788 TRACE("class %s, type %s, rows %d, columns %d, elements %d, struct_members %d\n",
1789 debug_d3dxparameter_class(type
->Class
), debug_d3dxparameter_type(type
->Type
),
1790 type
->Rows
, type
->Columns
, type
->Elements
, type
->StructMembers
);
1792 if (type
->Elements
> 1 && !is_element
)
1794 count
= type
->Elements
;
1796 else if ((type
->Class
== D3DXPC_STRUCT
) && type
->StructMembers
)
1798 memberinfo
= (D3DXSHADER_STRUCTMEMBERINFO
*)(ctab
+ type
->StructMemberInfo
);
1799 count
= type
->StructMembers
;
1804 constant
->constants
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*constant
->constants
) * count
);
1805 if (!constant
->constants
)
1807 ERR("Out of memory\n");
1812 for (i
= 0; i
< count
; ++i
)
1814 hr
= parse_ctab_constant_type(ctab
, memberinfo
? memberinfo
[i
].TypeInfo
: typeoffset
,
1815 &constant
->constants
[i
], memberinfo
== NULL
, index
+ size
, max_index
, offset
,
1816 memberinfo
? memberinfo
[i
].Name
: nameoffset
, regset
);
1820 size
+= constant
->constants
[i
].desc
.RegisterCount
;
1825 WORD offsetdiff
= type
->Columns
* type
->Rows
;
1828 size
= type
->Columns
* type
->Rows
;
1833 fail
= type
->Class
!= D3DXPC_SCALAR
&& type
->Class
!= D3DXPC_VECTOR
1834 && type
->Class
!= D3DXPC_MATRIX_ROWS
&& type
->Class
!= D3DXPC_MATRIX_COLUMNS
;
1839 switch (type
->Class
)
1845 offsetdiff
= type
->Rows
* 4;
1848 case D3DXPC_MATRIX_ROWS
:
1849 offsetdiff
= type
->Rows
* 4;
1853 case D3DXPC_MATRIX_COLUMNS
:
1854 offsetdiff
= type
->Columns
* 4;
1855 size
= type
->Columns
;
1864 case D3DXRS_SAMPLER
:
1866 fail
= type
->Class
!= D3DXPC_OBJECT
;
1876 FIXME("Unhandled register set %s, type class %s\n", debug_d3dxparameter_registerset(regset
),
1877 debug_d3dxparameter_class(type
->Class
));
1880 /* offset in bytes => offsetdiff * sizeof(DWORD) */
1881 if (offset
) *offset
+= offsetdiff
* 4;
1884 constant
->desc
.RegisterCount
= max(0, min(max_index
- index
, size
));
1885 constant
->desc
.Bytes
= 4 * constant
->desc
.Elements
* type
->Rows
* type
->Columns
;
1890 if (constant
->constants
)
1892 for (i
= 0; i
< count
; ++i
)
1894 free_constant(&constant
->constants
[i
]);
1896 HeapFree(GetProcessHeap(), 0, constant
->constants
);
1897 constant
->constants
= NULL
;
1903 HRESULT WINAPI
D3DXGetShaderConstantTableEx(const DWORD
*byte_code
, DWORD flags
, ID3DXConstantTable
**constant_table
)
1905 struct ID3DXConstantTableImpl
*object
= NULL
;
1909 const D3DXSHADER_CONSTANTTABLE
*ctab_header
;
1910 const D3DXSHADER_CONSTANTINFO
*constant_info
;
1913 TRACE("byte_code %p, flags %x, constant_table %p\n", byte_code
, flags
, constant_table
);
1915 if (constant_table
) *constant_table
= NULL
;
1917 if (!byte_code
|| !constant_table
)
1919 WARN("Invalid argument specified.\n");
1920 return D3DERR_INVALIDCALL
;
1923 if (!is_valid_bytecode(*byte_code
))
1925 WARN("Invalid byte_code specified.\n");
1929 if (flags
) FIXME("Flags (%#x) are not handled, yet!\n", flags
);
1931 hr
= D3DXFindShaderComment(byte_code
, MAKEFOURCC('C','T','A','B'), &data
, &size
);
1934 WARN("CTAB not found.\n");
1935 return D3DXERR_INVALIDDATA
;
1938 if (size
< sizeof(*ctab_header
))
1940 WARN("Invalid CTAB size.\n");
1941 return D3DXERR_INVALIDDATA
;
1944 ctab_header
= (const D3DXSHADER_CONSTANTTABLE
*)data
;
1945 if (ctab_header
->Size
!= sizeof(*ctab_header
))
1947 WARN("Invalid D3DXSHADER_CONSTANTTABLE size.\n");
1948 return D3DXERR_INVALIDDATA
;
1951 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1953 return E_OUTOFMEMORY
;
1955 object
->ID3DXConstantTable_iface
.lpVtbl
= &ID3DXConstantTable_Vtbl
;
1958 object
->ctab
= HeapAlloc(GetProcessHeap(), 0, size
);
1961 ERR("Out of memory\n");
1962 HeapFree(GetProcessHeap(), 0, object
);
1963 return E_OUTOFMEMORY
;
1965 object
->size
= size
;
1966 memcpy(object
->ctab
, data
, object
->size
);
1968 object
->desc
.Creator
= ctab_header
->Creator
? object
->ctab
+ ctab_header
->Creator
: NULL
;
1969 object
->desc
.Version
= ctab_header
->Version
;
1970 object
->desc
.Constants
= ctab_header
->Constants
;
1971 TRACE("Creator %s, Version %x, Constants %u, Target %s\n",
1972 debugstr_a(object
->desc
.Creator
), object
->desc
.Version
, object
->desc
.Constants
,
1973 debugstr_a(ctab_header
->Target
? object
->ctab
+ ctab_header
->Target
: NULL
));
1975 object
->constants
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1976 sizeof(*object
->constants
) * object
->desc
.Constants
);
1977 if (!object
->constants
)
1979 ERR("Out of memory\n");
1984 constant_info
= (const D3DXSHADER_CONSTANTINFO
*)(object
->ctab
+ ctab_header
->ConstantInfo
);
1985 for (i
= 0; i
< ctab_header
->Constants
; i
++)
1987 DWORD offset
= constant_info
[i
].DefaultValue
;
1989 hr
= parse_ctab_constant_type(object
->ctab
, constant_info
[i
].TypeInfo
,
1990 &object
->constants
[i
], FALSE
, constant_info
[i
].RegisterIndex
,
1991 constant_info
[i
].RegisterIndex
+ constant_info
[i
].RegisterCount
,
1992 offset
? &offset
: NULL
, constant_info
[i
].Name
, constant_info
[i
].RegisterSet
);
1997 * Set the register count, it may differ for D3DXRS_INT4, because somehow
1998 * it makes the assumption that the register size is 1 instead of 4, so the
1999 * count is 4 times bigger. This holds true only for toplevel shader
2000 * constants. The count of elements and members is always based on a
2001 * register size of 4.
2003 if (object
->constants
[i
].desc
.RegisterSet
== D3DXRS_INT4
)
2005 object
->constants
[i
].desc
.RegisterCount
= constant_info
[i
].RegisterCount
;
2009 *constant_table
= &object
->ID3DXConstantTable_iface
;
2014 free_constant_table(object
);
2015 HeapFree(GetProcessHeap(), 0, object
);
2020 HRESULT WINAPI
D3DXGetShaderConstantTable(const DWORD
*byte_code
, ID3DXConstantTable
**constant_table
)
2022 TRACE("(%p, %p): Forwarded to D3DXGetShaderConstantTableEx\n", byte_code
, constant_table
);
2024 return D3DXGetShaderConstantTableEx(byte_code
, 0, constant_table
);
2027 HRESULT WINAPI
D3DXGetShaderSamplers(const DWORD
*byte_code
, const char **samplers
, UINT
*count
)
2029 UINT i
, sampler_count
= 0;
2032 const D3DXSHADER_CONSTANTTABLE
*ctab_header
;
2033 const D3DXSHADER_CONSTANTINFO
*constant_info
;
2035 TRACE("byte_code %p, samplers %p, count %p\n", byte_code
, samplers
, count
);
2037 if (count
) *count
= 0;
2039 if (D3DXFindShaderComment(byte_code
, MAKEFOURCC('C','T','A','B'), (const void **)&data
, &size
) != D3D_OK
)
2042 if (size
< sizeof(*ctab_header
)) return D3D_OK
;
2044 ctab_header
= (const D3DXSHADER_CONSTANTTABLE
*)data
;
2045 if (ctab_header
->Size
!= sizeof(*ctab_header
)) return D3D_OK
;
2047 constant_info
= (const D3DXSHADER_CONSTANTINFO
*)(data
+ ctab_header
->ConstantInfo
);
2048 for (i
= 0; i
< ctab_header
->Constants
; i
++)
2050 const D3DXSHADER_TYPEINFO
*type
;
2052 TRACE("name = %s\n", data
+ constant_info
[i
].Name
);
2054 type
= (const D3DXSHADER_TYPEINFO
*)(data
+ constant_info
[i
].TypeInfo
);
2056 if (type
->Type
== D3DXPT_SAMPLER
2057 || type
->Type
== D3DXPT_SAMPLER1D
2058 || type
->Type
== D3DXPT_SAMPLER2D
2059 || type
->Type
== D3DXPT_SAMPLER3D
2060 || type
->Type
== D3DXPT_SAMPLERCUBE
)
2062 if (samplers
) samplers
[sampler_count
] = data
+ constant_info
[i
].Name
;
2068 TRACE("Found %u samplers\n", sampler_count
);
2070 if (count
) *count
= sampler_count
;