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
22 #include "wine/port.h"
24 #include "d3dx9_private.h"
25 #include "d3dcommon.h"
26 #include "d3dcompiler.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3dx
);
30 /* This function is not declared in the SDK headers yet. */
31 HRESULT WINAPI
D3DAssemble(const void *data
, SIZE_T datasize
, const char *filename
,
32 const D3D_SHADER_MACRO
*defines
, ID3DInclude
*include
, UINT flags
,
33 ID3DBlob
**shader
, ID3DBlob
**error_messages
);
35 static inline BOOL
is_valid_bytecode(DWORD token
)
37 return (token
& 0xfffe0000) == 0xfffe0000;
40 const char * WINAPI
D3DXGetPixelShaderProfile(struct IDirect3DDevice9
*device
)
44 TRACE("device %p\n", device
);
46 if (!device
) return NULL
;
48 IDirect3DDevice9_GetDeviceCaps(device
,&caps
);
50 switch (caps
.PixelShaderVersion
)
52 case D3DPS_VERSION(1, 1):
55 case D3DPS_VERSION(1, 2):
58 case D3DPS_VERSION(1, 3):
61 case D3DPS_VERSION(1, 4):
64 case D3DPS_VERSION(2, 0):
65 if ((caps
.PS20Caps
.NumTemps
>=22) &&
66 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_ARBITRARYSWIZZLE
) &&
67 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_GRADIENTINSTRUCTIONS
) &&
68 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_PREDICATION
) &&
69 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_NODEPENDENTREADLIMIT
) &&
70 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT
))
74 if ((caps
.PS20Caps
.NumTemps
>=32) &&
75 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT
))
81 case D3DPS_VERSION(3, 0):
88 UINT WINAPI
D3DXGetShaderSize(const DWORD
*byte_code
)
90 const DWORD
*ptr
= byte_code
;
92 TRACE("byte_code %p\n", byte_code
);
96 /* Look for the END token, skipping the VERSION token */
97 while (*++ptr
!= D3DSIO_END
)
100 if ((*ptr
& D3DSI_OPCODE_MASK
) == D3DSIO_COMMENT
)
102 ptr
+= ((*ptr
& D3DSI_COMMENTSIZE_MASK
) >> D3DSI_COMMENTSIZE_SHIFT
);
107 /* Return the shader size in bytes */
108 return (ptr
- byte_code
) * sizeof(*ptr
);
111 DWORD WINAPI
D3DXGetShaderVersion(const DWORD
*byte_code
)
113 TRACE("byte_code %p\n", byte_code
);
115 return byte_code
? *byte_code
: 0;
118 const char * WINAPI
D3DXGetVertexShaderProfile(struct IDirect3DDevice9
*device
)
122 TRACE("device %p\n", device
);
124 if (!device
) return NULL
;
126 IDirect3DDevice9_GetDeviceCaps(device
,&caps
);
128 switch (caps
.VertexShaderVersion
)
130 case D3DVS_VERSION(1, 1):
132 case D3DVS_VERSION(2, 0):
133 if ((caps
.VS20Caps
.NumTemps
>=13) &&
134 (caps
.VS20Caps
.DynamicFlowControlDepth
==24) &&
135 (caps
.VS20Caps
.Caps
&D3DPS20CAPS_PREDICATION
))
140 case D3DVS_VERSION(3, 0):
147 HRESULT WINAPI
D3DXFindShaderComment(const DWORD
*byte_code
, DWORD fourcc
, const void **data
, UINT
*size
)
149 const DWORD
*ptr
= byte_code
;
152 TRACE("byte_code %p, fourcc %x, data %p, size %p\n", byte_code
, fourcc
, data
, size
);
154 if (data
) *data
= NULL
;
157 if (!byte_code
) return D3DERR_INVALIDCALL
;
159 version
= *ptr
>> 16;
160 if (version
!= 0x4658 /* FX */
161 && version
!= 0x5458 /* TX */
164 && version
!= 0xfffe /* VS */
165 && version
!= 0xffff) /* PS */
167 WARN("Invalid data supplied\n");
168 return D3DXERR_INVALIDDATA
;
171 while (*++ptr
!= D3DSIO_END
)
173 /* Check if it is a comment */
174 if ((*ptr
& D3DSI_OPCODE_MASK
) == D3DSIO_COMMENT
)
176 DWORD comment_size
= (*ptr
& D3DSI_COMMENTSIZE_MASK
) >> D3DSI_COMMENTSIZE_SHIFT
;
178 /* Check if this is the comment we are looking for */
179 if (*(ptr
+ 1) == fourcc
)
181 UINT ctab_size
= (comment_size
- 1) * sizeof(DWORD
);
182 const void *ctab_data
= ptr
+ 2;
187 TRACE("Returning comment data at %p with size %d\n", ctab_data
, ctab_size
);
197 HRESULT WINAPI
D3DXAssembleShader(const char *data
, UINT data_len
, const D3DXMACRO
*defines
,
198 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
202 TRACE("data %p, data_len %u, defines %p, include %p, flags %#x, shader %p, error_messages %p\n",
203 data
, data_len
, defines
, include
, flags
, shader
, error_messages
);
205 /* Forward to d3dcompiler: the parameter types aren't really different,
206 the actual data types are equivalent */
207 hr
= D3DAssemble(data
, data_len
, NULL
, (D3D_SHADER_MACRO
*)defines
,
208 (ID3DInclude
*)include
, flags
, (ID3DBlob
**)shader
,
209 (ID3DBlob
**)error_messages
);
211 if(hr
== E_FAIL
) hr
= D3DXERR_INVALIDDATA
;
215 static const void *main_file_data
;
217 static CRITICAL_SECTION from_file_mutex
;
218 static CRITICAL_SECTION_DEBUG from_file_mutex_debug
=
220 0, 0, &from_file_mutex
,
222 &from_file_mutex_debug
.ProcessLocksList
,
223 &from_file_mutex_debug
.ProcessLocksList
225 0, 0, {(DWORD_PTR
)(__FILE__
": from_file_mutex")}
227 static CRITICAL_SECTION from_file_mutex
= {&from_file_mutex_debug
, -1, 0, 0, 0, 0};
229 /* D3DXInclude private implementation, used to implement
230 * D3DXAssembleShaderFromFile() from D3DXAssembleShader(). */
231 /* To be able to correctly resolve include search paths we have to store the
232 * pathname of each include file. We store the pathname pointer right before
234 static HRESULT WINAPI
d3dincludefromfile_open(ID3DXInclude
*iface
, D3DXINCLUDE_TYPE include_type
,
235 const char *filename
, const void *parent_data
, const void **data
, UINT
*bytes
)
237 const char *p
, *parent_name
= "";
238 char *pathname
= NULL
, *ptr
;
239 char **buffer
= NULL
;
245 parent_name
= *((const char **)parent_data
- 1);
250 parent_name
= *((const char **)main_file_data
- 1);
253 TRACE("Looking up for include file %s, parent %s\n", debugstr_a(filename
), debugstr_a(parent_name
));
255 if ((p
= strrchr(parent_name
, '\\')))
259 pathname
= HeapAlloc(GetProcessHeap(), 0, (p
- parent_name
) + strlen(filename
) + 1);
261 return HRESULT_FROM_WIN32(GetLastError());
263 memcpy(pathname
, parent_name
, p
- parent_name
);
264 strcpy(pathname
+ (p
- parent_name
), filename
);
265 ptr
= pathname
+ (p
- parent_name
);
273 file
= CreateFileA(pathname
, GENERIC_READ
, FILE_SHARE_READ
, 0, OPEN_EXISTING
, 0, 0);
274 if(file
== INVALID_HANDLE_VALUE
)
277 TRACE("Include file found at pathname = %s\n", debugstr_a(pathname
));
279 size
= GetFileSize(file
, NULL
);
280 if(size
== INVALID_FILE_SIZE
)
283 buffer
= HeapAlloc(GetProcessHeap(), 0, size
+ sizeof(char *));
287 if(!ReadFile(file
, buffer
+ 1, size
, bytes
, NULL
))
292 main_file_data
= *data
;
299 HeapFree(GetProcessHeap(), 0, pathname
);
300 HeapFree(GetProcessHeap(), 0, buffer
);
301 return HRESULT_FROM_WIN32(GetLastError());
304 static HRESULT WINAPI
d3dincludefromfile_close(ID3DXInclude
*iface
, const void *data
)
306 HeapFree(GetProcessHeap(), 0, *((char **)data
- 1));
307 HeapFree(GetProcessHeap(), 0, (char **)data
- 1);
308 if (main_file_data
== data
)
309 main_file_data
= NULL
;
313 static const struct ID3DXIncludeVtbl D3DXInclude_Vtbl
= {
314 d3dincludefromfile_open
,
315 d3dincludefromfile_close
318 struct D3DXIncludeImpl
{
319 ID3DXInclude ID3DXInclude_iface
;
322 HRESULT WINAPI
D3DXAssembleShaderFromFileA(const char *filename
, const D3DXMACRO
*defines
,
323 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
329 TRACE("filename %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
330 debugstr_a(filename
), defines
, include
, flags
, shader
, error_messages
);
332 if (!filename
) return D3DXERR_INVALIDDATA
;
334 len
= MultiByteToWideChar(CP_ACP
, 0, filename
, -1, NULL
, 0);
335 filename_w
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
336 if (!filename_w
) return E_OUTOFMEMORY
;
337 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filename_w
, len
);
339 ret
= D3DXAssembleShaderFromFileW(filename_w
, defines
, include
, flags
, shader
, error_messages
);
341 HeapFree(GetProcessHeap(), 0, filename_w
);
345 HRESULT WINAPI
D3DXAssembleShaderFromFileW(const WCHAR
*filename
, const D3DXMACRO
*defines
,
346 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
351 struct D3DXIncludeImpl includefromfile
;
354 TRACE("filename %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
355 debugstr_w(filename
), defines
, include
, flags
, shader
, error_messages
);
359 includefromfile
.ID3DXInclude_iface
.lpVtbl
= &D3DXInclude_Vtbl
;
360 include
= &includefromfile
.ID3DXInclude_iface
;
363 len
= WideCharToMultiByte(CP_ACP
, 0, filename
, -1, NULL
, 0, NULL
, NULL
);
364 filename_a
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(char));
366 return E_OUTOFMEMORY
;
367 WideCharToMultiByte(CP_ACP
, 0, filename
, -1, filename_a
, len
, NULL
, NULL
);
369 EnterCriticalSection(&from_file_mutex
);
370 hr
= ID3DXInclude_Open(include
, D3DXINC_LOCAL
, filename_a
, NULL
, &buffer
, &len
);
373 LeaveCriticalSection(&from_file_mutex
);
374 HeapFree(GetProcessHeap(), 0, filename_a
);
375 return D3DXERR_INVALIDDATA
;
378 hr
= D3DXAssembleShader(buffer
, len
, defines
, include
, flags
, shader
, error_messages
);
380 ID3DXInclude_Close(include
, buffer
);
381 LeaveCriticalSection(&from_file_mutex
);
382 HeapFree(GetProcessHeap(), 0, filename_a
);
386 HRESULT WINAPI
D3DXAssembleShaderFromResourceA(HMODULE module
, const char *resource
, const D3DXMACRO
*defines
,
387 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
393 TRACE("module %p, resource %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
394 module
, debugstr_a(resource
), defines
, include
, flags
, shader
, error_messages
);
396 if (!(res
= FindResourceA(module
, resource
, (const char *)RT_RCDATA
)))
397 return D3DXERR_INVALIDDATA
;
398 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
399 return D3DXERR_INVALIDDATA
;
400 return D3DXAssembleShader(buffer
, len
, defines
, include
, flags
,
401 shader
, error_messages
);
404 HRESULT WINAPI
D3DXAssembleShaderFromResourceW(HMODULE module
, const WCHAR
*resource
, const D3DXMACRO
*defines
,
405 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
411 TRACE("module %p, resource %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
412 module
, debugstr_w(resource
), defines
, include
, flags
, shader
, error_messages
);
414 if (!(res
= FindResourceW(module
, resource
, (const WCHAR
*)RT_RCDATA
)))
415 return D3DXERR_INVALIDDATA
;
416 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
417 return D3DXERR_INVALIDDATA
;
418 return D3DXAssembleShader(buffer
, len
, defines
, include
, flags
,
419 shader
, error_messages
);
422 HRESULT WINAPI
D3DXCompileShader(const char *data
, UINT length
, const D3DXMACRO
*defines
,
423 ID3DXInclude
*include
, const char *function
, const char *profile
, DWORD flags
,
424 ID3DXBuffer
**shader
, ID3DXBuffer
**error_msgs
, ID3DXConstantTable
**constant_table
)
428 TRACE("data %s, length %u, defines %p, include %p, function %s, profile %s, "
429 "flags %#x, shader %p, error_msgs %p, constant_table %p.\n",
430 debugstr_a(data
), length
, defines
, include
, debugstr_a(function
), debugstr_a(profile
),
431 flags
, shader
, error_msgs
, constant_table
);
433 hr
= D3DCompile(data
, length
, NULL
, (D3D_SHADER_MACRO
*)defines
, (ID3DInclude
*)include
,
434 function
, profile
, flags
, 0, (ID3DBlob
**)shader
, (ID3DBlob
**)error_msgs
);
436 if (SUCCEEDED(hr
) && constant_table
)
438 hr
= D3DXGetShaderConstantTable(ID3DXBuffer_GetBufferPointer(*shader
), constant_table
);
441 ID3DXBuffer_Release(*shader
);
449 HRESULT WINAPI
D3DXCompileShaderFromFileA(const char *filename
, const D3DXMACRO
*defines
,
450 ID3DXInclude
*include
, const char *entrypoint
, const char *profile
, DWORD flags
,
451 ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
, ID3DXConstantTable
**constant_table
)
457 TRACE("filename %s, defines %p, include %p, entrypoint %s, profile %s, "
458 "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
459 debugstr_a(filename
), defines
, include
, debugstr_a(entrypoint
),
460 debugstr_a(profile
), flags
, shader
, error_messages
, constant_table
);
462 if (!filename
) return D3DXERR_INVALIDDATA
;
464 len
= MultiByteToWideChar(CP_ACP
, 0, filename
, -1, NULL
, 0);
465 filename_w
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
466 if (!filename_w
) return E_OUTOFMEMORY
;
467 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filename_w
, len
);
469 ret
= D3DXCompileShaderFromFileW(filename_w
, defines
, include
,
470 entrypoint
, profile
, flags
,
471 shader
, error_messages
, constant_table
);
473 HeapFree(GetProcessHeap(), 0, filename_w
);
477 HRESULT WINAPI
D3DXCompileShaderFromFileW(const WCHAR
*filename
, const D3DXMACRO
*defines
,
478 ID3DXInclude
*include
, const char *entrypoint
, const char *profile
, DWORD flags
,
479 ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
, ID3DXConstantTable
**constant_table
)
482 DWORD len
, filename_len
;
484 struct D3DXIncludeImpl includefromfile
;
487 TRACE("filename %s, defines %p, include %p, entrypoint %s, profile %s, "
488 "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
489 debugstr_w(filename
), defines
, include
, debugstr_a(entrypoint
), debugstr_a(profile
),
490 flags
, shader
, error_messages
, constant_table
);
494 includefromfile
.ID3DXInclude_iface
.lpVtbl
= &D3DXInclude_Vtbl
;
495 include
= &includefromfile
.ID3DXInclude_iface
;
498 filename_len
= WideCharToMultiByte(CP_ACP
, 0, filename
, -1, NULL
, 0, NULL
, NULL
);
499 filename_a
= HeapAlloc(GetProcessHeap(), 0, filename_len
* sizeof(char));
501 return E_OUTOFMEMORY
;
502 WideCharToMultiByte(CP_ACP
, 0, filename
, -1, filename_a
, filename_len
, NULL
, NULL
);
504 EnterCriticalSection(&from_file_mutex
);
505 hr
= ID3DXInclude_Open(include
, D3DXINC_LOCAL
, filename_a
, NULL
, &buffer
, &len
);
508 LeaveCriticalSection(&from_file_mutex
);
509 HeapFree(GetProcessHeap(), 0, filename_a
);
510 return D3DXERR_INVALIDDATA
;
513 hr
= D3DCompile(buffer
, len
, filename_a
, (const D3D_SHADER_MACRO
*)defines
,
514 (ID3DInclude
*)include
, entrypoint
, profile
, flags
, 0,
515 (ID3DBlob
**)shader
, (ID3DBlob
**)error_messages
);
517 if (SUCCEEDED(hr
) && constant_table
)
518 hr
= D3DXGetShaderConstantTable(ID3DXBuffer_GetBufferPointer(*shader
),
521 ID3DXInclude_Close(include
, buffer
);
522 LeaveCriticalSection(&from_file_mutex
);
523 HeapFree(GetProcessHeap(), 0, filename_a
);
527 HRESULT WINAPI
D3DXCompileShaderFromResourceA(HMODULE module
, const char *resource
, const D3DXMACRO
*defines
,
528 ID3DXInclude
*include
, const char *entrypoint
, const char *profile
, DWORD flags
,
529 ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
, ID3DXConstantTable
**constant_table
)
535 TRACE("module %p, resource %s, defines %p, include %p, entrypoint %s, profile %s, "
536 "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
537 module
, debugstr_a(resource
), defines
, include
, debugstr_a(entrypoint
), debugstr_a(profile
),
538 flags
, shader
, error_messages
, constant_table
);
540 if (!(res
= FindResourceA(module
, resource
, (const char *)RT_RCDATA
)))
541 return D3DXERR_INVALIDDATA
;
542 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
543 return D3DXERR_INVALIDDATA
;
544 return D3DXCompileShader(buffer
, len
, defines
, include
, entrypoint
, profile
,
545 flags
, shader
, error_messages
, constant_table
);
548 HRESULT WINAPI
D3DXCompileShaderFromResourceW(HMODULE module
, const WCHAR
*resource
, const D3DXMACRO
*defines
,
549 ID3DXInclude
*include
, const char *entrypoint
, const char *profile
, DWORD flags
,
550 ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
, ID3DXConstantTable
**constant_table
)
556 TRACE("module %p, resource %s, defines %p, include %p, entrypoint %s, profile %s, "
557 "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
558 module
, debugstr_w(resource
), defines
, include
, debugstr_a(entrypoint
), debugstr_a(profile
),
559 flags
, shader
, error_messages
, constant_table
);
561 if (!(res
= FindResourceW(module
, resource
, (const WCHAR
*)RT_RCDATA
)))
562 return D3DXERR_INVALIDDATA
;
563 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
564 return D3DXERR_INVALIDDATA
;
565 return D3DXCompileShader(buffer
, len
, defines
, include
, entrypoint
, profile
,
566 flags
, shader
, error_messages
, constant_table
);
569 HRESULT WINAPI
D3DXPreprocessShader(const char *data
, UINT data_len
, const D3DXMACRO
*defines
,
570 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
572 TRACE("data %s, data_len %u, defines %p, include %p, shader %p, error_messages %p.\n",
573 debugstr_a(data
), data_len
, defines
, include
, shader
, error_messages
);
575 return D3DPreprocess(data
, data_len
, NULL
,
576 (const D3D_SHADER_MACRO
*)defines
, (ID3DInclude
*)include
,
577 (ID3DBlob
**)shader
, (ID3DBlob
**)error_messages
);
580 HRESULT WINAPI
D3DXPreprocessShaderFromFileA(const char *filename
, const D3DXMACRO
*defines
,
581 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
583 WCHAR
*filename_w
= NULL
;
587 TRACE("filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
588 debugstr_a(filename
), defines
, include
, shader
, error_messages
);
590 if (!filename
) return D3DXERR_INVALIDDATA
;
592 len
= MultiByteToWideChar(CP_ACP
, 0, filename
, -1, NULL
, 0);
593 filename_w
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
594 if (!filename_w
) return E_OUTOFMEMORY
;
595 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filename_w
, len
);
597 ret
= D3DXPreprocessShaderFromFileW(filename_w
, defines
, include
, shader
, error_messages
);
599 HeapFree(GetProcessHeap(), 0, filename_w
);
603 HRESULT WINAPI
D3DXPreprocessShaderFromFileW(const WCHAR
*filename
, const D3DXMACRO
*defines
,
604 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
609 struct D3DXIncludeImpl includefromfile
;
612 TRACE("filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
613 debugstr_w(filename
), defines
, include
, shader
, error_messages
);
617 includefromfile
.ID3DXInclude_iface
.lpVtbl
= &D3DXInclude_Vtbl
;
618 include
= &includefromfile
.ID3DXInclude_iface
;
621 len
= WideCharToMultiByte(CP_ACP
, 0, filename
, -1, NULL
, 0, NULL
, NULL
);
622 filename_a
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(char));
624 return E_OUTOFMEMORY
;
625 WideCharToMultiByte(CP_ACP
, 0, filename
, -1, filename_a
, len
, NULL
, NULL
);
627 EnterCriticalSection(&from_file_mutex
);
628 hr
= ID3DXInclude_Open(include
, D3DXINC_LOCAL
, filename_a
, NULL
, &buffer
, &len
);
631 LeaveCriticalSection(&from_file_mutex
);
632 HeapFree(GetProcessHeap(), 0, filename_a
);
633 return D3DXERR_INVALIDDATA
;
636 hr
= D3DPreprocess(buffer
, len
, NULL
,
637 (const D3D_SHADER_MACRO
*)defines
,
638 (ID3DInclude
*) include
,
639 (ID3DBlob
**)shader
, (ID3DBlob
**)error_messages
);
641 ID3DXInclude_Close(include
, buffer
);
642 LeaveCriticalSection(&from_file_mutex
);
643 HeapFree(GetProcessHeap(), 0, filename_a
);
647 HRESULT WINAPI
D3DXPreprocessShaderFromResourceA(HMODULE module
, const char *resource
, const D3DXMACRO
*defines
,
648 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
654 TRACE("module %p, resource %s, defines %p, include %p, shader %p, error_messages %p.\n",
655 module
, debugstr_a(resource
), defines
, include
, shader
, error_messages
);
657 if (!(res
= FindResourceA(module
, resource
, (const char *)RT_RCDATA
)))
658 return D3DXERR_INVALIDDATA
;
659 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
660 return D3DXERR_INVALIDDATA
;
661 return D3DXPreprocessShader(buffer
, len
, defines
, include
,
662 shader
, error_messages
);
665 HRESULT WINAPI
D3DXPreprocessShaderFromResourceW(HMODULE module
, const WCHAR
*resource
, const D3DXMACRO
*defines
,
666 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
672 TRACE("module %p, resource %s, defines %p, include %p, shader %p, error_messages %p.\n",
673 module
, debugstr_w(resource
), defines
, include
, shader
, error_messages
);
675 if (!(res
= FindResourceW(module
, resource
, (const WCHAR
*)RT_RCDATA
)))
676 return D3DXERR_INVALIDDATA
;
677 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
678 return D3DXERR_INVALIDDATA
;
679 return D3DXPreprocessShader(buffer
, len
, defines
, include
,
680 shader
, error_messages
);
684 struct ctab_constant
{
685 D3DXCONSTANT_DESC desc
;
686 struct ctab_constant
*constants
;
689 struct ID3DXConstantTableImpl
{
690 ID3DXConstantTable ID3DXConstantTable_iface
;
694 D3DXCONSTANTTABLE_DESC desc
;
695 struct ctab_constant
*constants
;
698 static void free_constant(struct ctab_constant
*constant
)
700 if (constant
->constants
)
702 UINT i
, count
= constant
->desc
.Elements
> 1 ? constant
->desc
.Elements
: constant
->desc
.StructMembers
;
704 for (i
= 0; i
< count
; ++i
)
706 free_constant(&constant
->constants
[i
]);
708 HeapFree(GetProcessHeap(), 0, constant
->constants
);
712 static void free_constant_table(struct ID3DXConstantTableImpl
*table
)
714 if (table
->constants
)
718 for (i
= 0; i
< table
->desc
.Constants
; ++i
)
720 free_constant(&table
->constants
[i
]);
722 HeapFree(GetProcessHeap(), 0, table
->constants
);
724 HeapFree(GetProcessHeap(), 0, table
->ctab
);
727 static inline struct ID3DXConstantTableImpl
*impl_from_ID3DXConstantTable(ID3DXConstantTable
*iface
)
729 return CONTAINING_RECORD(iface
, struct ID3DXConstantTableImpl
, ID3DXConstantTable_iface
);
732 static inline BOOL
is_vertex_shader(DWORD version
)
734 return (version
& 0xffff0000) == 0xfffe0000;
737 static inline D3DXHANDLE
handle_from_constant(struct ctab_constant
*constant
)
739 return (D3DXHANDLE
)constant
;
742 static struct ctab_constant
*get_constant_by_name(struct ID3DXConstantTableImpl
*table
,
743 struct ctab_constant
*constant
, const char *name
);
745 static struct ctab_constant
*get_constant_element_by_name(struct ctab_constant
*constant
, const char *name
)
750 TRACE("constant %p, name %s\n", constant
, debugstr_a(name
));
752 if (!name
|| !*name
) return NULL
;
754 element
= atoi(name
);
755 part
= strchr(name
, ']') + 1;
757 if (constant
->desc
.Elements
> element
)
759 struct ctab_constant
*c
= constant
->constants
? &constant
->constants
[element
] : constant
;
764 return get_constant_by_name(NULL
, c
, part
);
767 return get_constant_element_by_name(c
, part
);
770 TRACE("Returning parameter %p\n", c
);
774 FIXME("Unhandled case \"%c\"\n", *--part
);
779 TRACE("Constant not found\n");
783 static struct ctab_constant
*get_constant_by_name(struct ID3DXConstantTableImpl
*table
,
784 struct ctab_constant
*constant
, const char *name
)
786 UINT i
, count
, length
;
787 struct ctab_constant
*handles
;
790 TRACE("table %p, constant %p, name %s\n", table
, constant
, debugstr_a(name
));
792 if (!name
|| !*name
) return NULL
;
796 count
= table
->desc
.Constants
;
797 handles
= table
->constants
;
801 count
= constant
->desc
.StructMembers
;
802 handles
= constant
->constants
;
805 length
= strcspn(name
, "[.");
806 part
= name
+ length
;
808 for (i
= 0; i
< count
; i
++)
810 if (strlen(handles
[i
].desc
.Name
) == length
&& !strncmp(handles
[i
].desc
.Name
, name
, length
))
815 return get_constant_by_name(NULL
, &handles
[i
], part
);
818 return get_constant_element_by_name(&handles
[i
], part
);
821 TRACE("Returning parameter %p\n", &handles
[i
]);
827 TRACE("Constant not found\n");
831 static struct ctab_constant
*is_valid_sub_constant(struct ctab_constant
*parent
, D3DXHANDLE handle
)
833 struct ctab_constant
*c
;
836 /* all variable have at least elements = 1, but not always elements */
837 if (!parent
->constants
) return NULL
;
839 count
= parent
->desc
.Elements
> 1 ? parent
->desc
.Elements
: parent
->desc
.StructMembers
;
840 for (i
= 0; i
< count
; ++i
)
842 if (handle_from_constant(&parent
->constants
[i
]) == handle
)
843 return &parent
->constants
[i
];
845 c
= is_valid_sub_constant(&parent
->constants
[i
], handle
);
852 static inline struct ctab_constant
*get_valid_constant(struct ID3DXConstantTableImpl
*table
, D3DXHANDLE handle
)
854 struct ctab_constant
*c
;
857 if (!handle
) return NULL
;
859 for (i
= 0; i
< table
->desc
.Constants
; ++i
)
861 if (handle_from_constant(&table
->constants
[i
]) == handle
)
862 return &table
->constants
[i
];
864 c
= is_valid_sub_constant(&table
->constants
[i
], handle
);
868 return get_constant_by_name(table
, NULL
, handle
);
871 /*** IUnknown methods ***/
872 static HRESULT WINAPI
ID3DXConstantTableImpl_QueryInterface(ID3DXConstantTable
*iface
, REFIID riid
, void **out
)
874 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
876 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
877 IsEqualGUID(riid
, &IID_ID3DXBuffer
) ||
878 IsEqualGUID(riid
, &IID_ID3DXConstantTable
))
880 ID3DXConstantTable_AddRef(iface
);
885 WARN("Interface %s not found.\n", debugstr_guid(riid
));
887 return E_NOINTERFACE
;
890 static ULONG WINAPI
ID3DXConstantTableImpl_AddRef(ID3DXConstantTable
*iface
)
892 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
894 TRACE("(%p)->(): AddRef from %d\n", This
, This
->ref
);
896 return InterlockedIncrement(&This
->ref
);
899 static ULONG WINAPI
ID3DXConstantTableImpl_Release(ID3DXConstantTable
*iface
)
901 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
902 ULONG ref
= InterlockedDecrement(&This
->ref
);
904 TRACE("(%p)->(): Release from %d\n", This
, ref
+ 1);
908 free_constant_table(This
);
909 HeapFree(GetProcessHeap(), 0, This
);
915 /*** ID3DXBuffer methods ***/
916 static void * WINAPI
ID3DXConstantTableImpl_GetBufferPointer(ID3DXConstantTable
*iface
)
918 struct ID3DXConstantTableImpl
*table
= impl_from_ID3DXConstantTable(iface
);
920 TRACE("iface %p.\n", iface
);
925 static DWORD WINAPI
ID3DXConstantTableImpl_GetBufferSize(ID3DXConstantTable
*iface
)
927 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
929 TRACE("(%p)->()\n", This
);
934 /*** ID3DXConstantTable methods ***/
935 static HRESULT WINAPI
ID3DXConstantTableImpl_GetDesc(ID3DXConstantTable
*iface
, D3DXCONSTANTTABLE_DESC
*desc
)
937 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
939 TRACE("(%p)->(%p)\n", This
, desc
);
942 return D3DERR_INVALIDCALL
;
949 static HRESULT WINAPI
ID3DXConstantTableImpl_GetConstantDesc(ID3DXConstantTable
*iface
, D3DXHANDLE constant
,
950 D3DXCONSTANT_DESC
*desc
, UINT
*count
)
952 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
953 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
955 TRACE("(%p)->(%p, %p, %p)\n", This
, constant
, desc
, count
);
959 WARN("Invalid argument specified\n");
960 return D3DERR_INVALIDCALL
;
963 if (desc
) *desc
= c
->desc
;
964 if (count
) *count
= 1;
969 static UINT WINAPI
ID3DXConstantTableImpl_GetSamplerIndex(ID3DXConstantTable
*iface
, D3DXHANDLE constant
)
971 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
972 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
974 TRACE("(%p)->(%p)\n", This
, constant
);
976 if (!c
|| c
->desc
.RegisterSet
!= D3DXRS_SAMPLER
)
978 WARN("Invalid argument specified\n");
982 TRACE("Returning RegisterIndex %u\n", c
->desc
.RegisterIndex
);
983 return c
->desc
.RegisterIndex
;
986 static D3DXHANDLE WINAPI
ID3DXConstantTableImpl_GetConstant(ID3DXConstantTable
*iface
, D3DXHANDLE constant
, UINT index
)
988 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
989 struct ctab_constant
*c
;
991 TRACE("(%p)->(%p, %d)\n", This
, constant
, index
);
995 c
= get_valid_constant(This
, constant
);
996 if (c
&& index
< c
->desc
.StructMembers
)
998 c
= &c
->constants
[index
];
999 TRACE("Returning constant %p\n", c
);
1000 return handle_from_constant(c
);
1005 if (index
< This
->desc
.Constants
)
1007 c
= &This
->constants
[index
];
1008 TRACE("Returning constant %p\n", c
);
1009 return handle_from_constant(c
);
1013 WARN("Index out of range\n");
1017 static D3DXHANDLE WINAPI
ID3DXConstantTableImpl_GetConstantByName(ID3DXConstantTable
*iface
,
1018 D3DXHANDLE constant
, const char *name
)
1020 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1021 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
1023 TRACE("iface %p, constant %p, name %s.\n", iface
, constant
, debugstr_a(name
));
1025 c
= get_constant_by_name(This
, c
, name
);
1026 TRACE("Returning constant %p\n", c
);
1028 return handle_from_constant(c
);
1031 static D3DXHANDLE WINAPI
ID3DXConstantTableImpl_GetConstantElement(ID3DXConstantTable
*iface
, D3DXHANDLE constant
, UINT index
)
1033 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1034 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
1036 TRACE("(%p)->(%p, %d)\n", This
, constant
, index
);
1038 if (c
&& index
< c
->desc
.Elements
)
1040 if (c
->desc
.Elements
> 1) c
= &c
->constants
[index
];
1041 TRACE("Returning constant %p\n", c
);
1042 return handle_from_constant(c
);
1045 WARN("Invalid argument specified\n");
1049 static inline DWORD
get_index(const void **indata
, UINT index
, BOOL is_pointer
)
1055 return ((DWORD
**)indata
)[index
/ 16][index
% 16];
1057 return (*((DWORD
**)indata
))[index
];
1060 static UINT
set(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, struct ctab_constant
*constant
,
1061 const void **indata
, D3DXPARAMETER_TYPE intype
, UINT
*size
, UINT incol
, D3DXPARAMETER_CLASS inclass
, UINT index
,
1064 D3DXCONSTANT_DESC
*desc
= &constant
->desc
;
1065 UINT l
, i
, regcount
= 1, regsize
= 1, cin
= 1, rin
= 1, ret
, last
= 0;
1068 /* size too small to set anything */
1069 if (*size
< desc
->Rows
* desc
->Columns
)
1075 /* D3DXPC_STRUCT is somewhat special */
1076 if (desc
->Class
== D3DXPC_STRUCT
)
1079 * Struct array sets the last complete input to the first struct element, all other
1080 * elements are not set.
1081 * E.g.: struct {int i;} s1[2];
1082 * SetValue(device, "s1", [1, 2], 8) => s1 = {2, x};
1084 * struct {int i; int n} s2[2];
1085 * SetValue(device, "s2", [1, 2, 3, 4, 5], 20) => s1 = {{3, 4}, {x, x}};
1087 if (desc
->Elements
> 1)
1089 UINT offset
= *size
/ (desc
->Rows
* desc
->Columns
) - 1;
1091 offset
= min(desc
->Elements
- 1, offset
);
1092 last
= offset
* desc
->Rows
* desc
->Columns
;
1094 if ((is_pointer
|| inclass
== D3DXPC_MATRIX_ROWS
) && desc
->RegisterSet
!= D3DXRS_BOOL
)
1096 set(table
, device
, &constant
->constants
[0], NULL
, intype
, size
, incol
, inclass
, 0, is_pointer
);
1100 last
+= set(table
, device
, &constant
->constants
[0], indata
, intype
, size
, incol
, inclass
,
1101 index
+ last
, is_pointer
);
1107 * D3DXRS_BOOL is always set. As there are only 16 bools and there are
1108 * exactly 16 input values, use matrix transpose.
1110 if (inclass
== D3DXPC_MATRIX_ROWS
&& desc
->RegisterSet
== D3DXRS_BOOL
)
1112 D3DXMATRIX mat
, *m
, min
;
1113 D3DXMatrixTranspose(&mat
, &min
);
1116 min
= *(D3DXMATRIX
*)(indata
[index
/ 16]);
1118 min
= **(D3DXMATRIX
**)indata
;
1120 D3DXMatrixTranspose(&mat
, &min
);
1122 for (i
= 0; i
< desc
->StructMembers
; ++i
)
1124 last
+= set(table
, device
, &constant
->constants
[i
], (const void **)&m
, intype
, size
, incol
,
1125 D3DXPC_SCALAR
, index
+ last
, is_pointer
);
1129 * For pointers or for matrix rows, only the first member is set.
1130 * All other members are set to 0. This is not true for D3DXRS_BOOL.
1131 * E.g.: struct {int i; int n} s;
1132 * SetValue(device, "s", [1, 2], 8) => s = {1, 0};
1134 else if ((is_pointer
|| inclass
== D3DXPC_MATRIX_ROWS
) && desc
->RegisterSet
!= D3DXRS_BOOL
)
1136 last
= set(table
, device
, &constant
->constants
[0], indata
, intype
, size
, incol
, inclass
,
1137 index
+ last
, is_pointer
);
1139 for (i
= 1; i
< desc
->StructMembers
; ++i
)
1141 set(table
, device
, &constant
->constants
[i
], NULL
, intype
, size
, incol
, inclass
, 0, is_pointer
);
1146 for (i
= 0; i
< desc
->StructMembers
; ++i
)
1148 last
+= set(table
, device
, &constant
->constants
[i
], indata
, intype
, size
, incol
, D3DXPC_SCALAR
,
1149 index
+ last
, is_pointer
);
1158 if (desc
->Elements
> 1)
1160 for (i
= 0; i
< desc
->Elements
&& *size
> 0; ++i
)
1162 last
+= set(table
, device
, &constant
->constants
[i
], indata
, intype
, size
, incol
, inclass
,
1163 index
+ last
, is_pointer
);
1165 /* adjust the vector size for matrix rows */
1166 if (inclass
== D3DXPC_MATRIX_ROWS
&& desc
->Class
== D3DXPC_VECTOR
&& (i
% 4) == 3)
1169 *size
= *size
< 12 ? 0 : *size
- 12;
1176 switch (desc
->Class
)
1180 case D3DXPC_MATRIX_ROWS
:
1181 regcount
= min(desc
->RegisterCount
, desc
->Rows
);
1182 if (inclass
== D3DXPC_MATRIX_ROWS
) cin
= incol
;
1184 regsize
= desc
->Columns
;
1187 case D3DXPC_MATRIX_COLUMNS
:
1188 regcount
= min(desc
->RegisterCount
, desc
->Columns
);
1189 if (inclass
== D3DXPC_MATRIX_ROWS
) rin
= incol
;
1191 regsize
= desc
->Rows
;
1195 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1199 /* specific stuff for different in types */
1203 ret
= desc
->Columns
* desc
->Rows
;
1204 *size
-= desc
->Columns
* desc
->Rows
;
1208 switch (desc
->Class
)
1210 case D3DXPC_MATRIX_ROWS
:
1211 if (*size
< regcount
* 4)
1217 *size
-= 4 * regcount
;
1220 case D3DXPC_MATRIX_COLUMNS
:
1222 *size
-= 4 * regcount
;
1236 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1241 case D3DXPC_MATRIX_ROWS
:
1242 switch (desc
->Class
)
1244 case D3DXPC_MATRIX_ROWS
:
1245 case D3DXPC_MATRIX_COLUMNS
:
1263 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1269 case D3DXPC_MATRIX_COLUMNS
:
1270 switch (desc
->Class
)
1272 case D3DXPC_MATRIX_ROWS
:
1273 case D3DXPC_MATRIX_COLUMNS
:
1291 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1298 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(inclass
));
1302 /* set the registers */
1303 switch (desc
->RegisterSet
)
1306 regcount
= min(desc
->RegisterCount
, desc
->Columns
* desc
->Rows
);
1308 for (i
= 0; i
< regcount
; ++i
)
1311 DWORD t
= get_index(indata
, index
+ i
/ regsize
* rin
+ l
* cin
, is_pointer
);
1313 set_number(&tmp
, desc
->Type
, &t
, intype
);
1314 set_number(&out
, D3DXPT_BOOL
, &tmp
, desc
->Type
);
1315 if (is_vertex_shader(table
->desc
.Version
))
1316 IDirect3DDevice9_SetVertexShaderConstantB(device
, desc
->RegisterIndex
+ i
, &out
, 1);
1318 IDirect3DDevice9_SetPixelShaderConstantB(device
, desc
->RegisterIndex
+ i
, &out
, 1);
1320 if (++l
>= regsize
) l
= 0;
1325 for (i
= 0; i
< regcount
; ++i
)
1327 INT vec
[4] = {0, 0, 1, 0};
1329 for (l
= 0; l
< regsize
; ++l
)
1331 DWORD t
= get_index(indata
, index
+ i
* rin
+ l
* cin
, is_pointer
);
1333 set_number(&tmp
, desc
->Type
, &t
, intype
);
1334 set_number(&vec
[l
], D3DXPT_INT
, &tmp
, desc
->Type
);
1336 if (is_vertex_shader(table
->desc
.Version
))
1337 IDirect3DDevice9_SetVertexShaderConstantI(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1339 IDirect3DDevice9_SetPixelShaderConstantI(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1344 for (i
= 0; i
< regcount
; ++i
)
1348 for (l
= 0; l
< regsize
; ++l
)
1350 DWORD t
= get_index(indata
, index
+ i
* rin
+ l
* cin
, is_pointer
);
1352 set_number(&tmp
, desc
->Type
, &t
, intype
);
1353 set_number(&vec
[l
], D3DXPT_FLOAT
, &tmp
, desc
->Type
);
1355 if (is_vertex_shader(table
->desc
.Version
))
1356 IDirect3DDevice9_SetVertexShaderConstantF(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1358 IDirect3DDevice9_SetPixelShaderConstantF(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1363 FIXME("Unhandled register set %s\n", debug_d3dxparameter_registerset(desc
->RegisterSet
));
1368 static HRESULT
set_scalar(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1369 const void *indata
, D3DXPARAMETER_TYPE intype
)
1371 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1376 WARN("Invalid argument specified\n");
1377 return D3DERR_INVALIDCALL
;
1380 switch (c
->desc
.Class
)
1383 set(table
, device
, c
, &indata
, intype
, &count
, c
->desc
.Columns
, D3DXPC_SCALAR
, 0, FALSE
);
1387 case D3DXPC_MATRIX_ROWS
:
1388 case D3DXPC_MATRIX_COLUMNS
:
1393 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1394 return D3DERR_INVALIDCALL
;
1398 static HRESULT
set_scalar_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1399 const void *indata
, UINT count
, D3DXPARAMETER_TYPE intype
)
1401 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1405 WARN("Invalid argument specified\n");
1406 return D3DERR_INVALIDCALL
;
1409 switch (c
->desc
.Class
)
1413 case D3DXPC_MATRIX_ROWS
:
1414 case D3DXPC_MATRIX_COLUMNS
:
1416 set(table
, device
, c
, &indata
, intype
, &count
, c
->desc
.Columns
, D3DXPC_SCALAR
, 0, FALSE
);
1420 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1421 return D3DERR_INVALIDCALL
;
1425 static HRESULT
set_vector(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1426 const void *indata
, D3DXPARAMETER_TYPE intype
)
1428 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1433 WARN("Invalid argument specified\n");
1434 return D3DERR_INVALIDCALL
;
1437 switch (c
->desc
.Class
)
1442 set(table
, device
, c
, &indata
, intype
, &count
, 4, D3DXPC_VECTOR
, 0, FALSE
);
1445 case D3DXPC_MATRIX_ROWS
:
1446 case D3DXPC_MATRIX_COLUMNS
:
1450 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1451 return D3DERR_INVALIDCALL
;
1455 static HRESULT
set_vector_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1456 const void *indata
, UINT count
, D3DXPARAMETER_TYPE intype
)
1458 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1462 WARN("Invalid argument specified\n");
1463 return D3DERR_INVALIDCALL
;
1466 switch (c
->desc
.Class
)
1470 case D3DXPC_MATRIX_ROWS
:
1471 case D3DXPC_MATRIX_COLUMNS
:
1474 set(table
, device
, c
, &indata
, intype
, &count
, 4, D3DXPC_VECTOR
, 0, FALSE
);
1478 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1479 return D3DERR_INVALIDCALL
;
1483 static HRESULT
set_matrix_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1484 const void *indata
, UINT count
, BOOL transpose
)
1486 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1490 WARN("Invalid argument specified\n");
1491 return D3DERR_INVALIDCALL
;
1494 switch (c
->desc
.Class
)
1498 case D3DXPC_MATRIX_ROWS
:
1499 case D3DXPC_MATRIX_COLUMNS
:
1502 set(table
, device
, c
, &indata
, D3DXPT_FLOAT
, &count
, 4,
1503 transpose
? D3DXPC_MATRIX_ROWS
: D3DXPC_MATRIX_COLUMNS
, 0, FALSE
);
1507 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1508 return D3DERR_INVALIDCALL
;
1512 static HRESULT
set_matrix_pointer_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
,
1513 D3DXHANDLE constant
, const void **indata
, UINT count
, BOOL transpose
)
1515 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1519 WARN("Invalid argument specified\n");
1520 return D3DERR_INVALIDCALL
;
1523 switch (c
->desc
.Class
)
1527 case D3DXPC_MATRIX_ROWS
:
1528 case D3DXPC_MATRIX_COLUMNS
:
1531 set(table
, device
, c
, indata
, D3DXPT_FLOAT
, &count
, 4,
1532 transpose
? D3DXPC_MATRIX_ROWS
: D3DXPC_MATRIX_COLUMNS
, 0, TRUE
);
1536 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1537 return D3DERR_INVALIDCALL
;
1541 static HRESULT WINAPI
ID3DXConstantTableImpl_SetDefaults(struct ID3DXConstantTable
*iface
,
1542 struct IDirect3DDevice9
*device
)
1544 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1547 TRACE("iface %p, device %p\n", iface
, device
);
1551 WARN("Invalid argument specified\n");
1552 return D3DERR_INVALIDCALL
;
1555 for (i
= 0; i
< This
->desc
.Constants
; i
++)
1557 D3DXCONSTANT_DESC
*desc
= &This
->constants
[i
].desc
;
1560 if (!desc
->DefaultValue
)
1563 switch (desc
->RegisterSet
)
1566 if (is_vertex_shader(This
->desc
.Version
))
1567 hr
= IDirect3DDevice9_SetVertexShaderConstantB(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1568 desc
->RegisterCount
);
1570 hr
= IDirect3DDevice9_SetPixelShaderConstantB(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1571 desc
->RegisterCount
);
1575 if (is_vertex_shader(This
->desc
.Version
))
1576 hr
= IDirect3DDevice9_SetVertexShaderConstantI(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1577 desc
->RegisterCount
);
1579 hr
= IDirect3DDevice9_SetPixelShaderConstantI(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1580 desc
->RegisterCount
);
1584 if (is_vertex_shader(This
->desc
.Version
))
1585 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1586 desc
->RegisterCount
);
1588 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1589 desc
->RegisterCount
);
1593 FIXME("Unhandled register set %s\n", debug_d3dxparameter_registerset(desc
->RegisterSet
));
1605 static HRESULT WINAPI
ID3DXConstantTableImpl_SetValue(struct ID3DXConstantTable
*iface
,
1606 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const void *data
, unsigned int bytes
)
1608 struct ID3DXConstantTableImpl
*table
= impl_from_ID3DXConstantTable(iface
);
1609 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1610 D3DXCONSTANT_DESC
*desc
;
1612 TRACE("iface %p, device %p, constant %p, data %p, bytes %u\n", iface
, device
, constant
, data
, bytes
);
1614 if (!device
|| !c
|| !data
)
1616 WARN("Invalid argument specified\n");
1617 return D3DERR_INVALIDCALL
;
1622 switch (desc
->Class
)
1626 case D3DXPC_MATRIX_ROWS
:
1627 case D3DXPC_MATRIX_COLUMNS
:
1630 set(table
, device
, c
, &data
, desc
->Type
, &bytes
, desc
->Columns
, D3DXPC_SCALAR
, 0, FALSE
);
1634 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(desc
->Class
));
1635 return D3DERR_INVALIDCALL
;
1639 static HRESULT WINAPI
ID3DXConstantTableImpl_SetBool(struct ID3DXConstantTable
*iface
,
1640 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, BOOL b
)
1642 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1644 TRACE("iface %p, device %p, constant %p, b %d\n", iface
, device
, constant
, b
);
1646 return set_scalar(This
, device
, constant
, &b
, D3DXPT_BOOL
);
1649 static HRESULT WINAPI
ID3DXConstantTableImpl_SetBoolArray(struct ID3DXConstantTable
*iface
,
1650 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const BOOL
*b
, UINT count
)
1652 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1654 TRACE("iface %p, device %p, constant %p, b %p, count %d\n", iface
, device
, constant
, b
, count
);
1656 return set_scalar_array(This
, device
, constant
, b
, count
, D3DXPT_BOOL
);
1659 static HRESULT WINAPI
ID3DXConstantTableImpl_SetInt(struct ID3DXConstantTable
*iface
,
1660 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, INT n
)
1662 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1664 TRACE("iface %p, device %p, constant %p, n %d\n", iface
, device
, constant
, n
);
1666 return set_scalar(This
, device
, constant
, &n
, D3DXPT_INT
);
1669 static HRESULT WINAPI
ID3DXConstantTableImpl_SetIntArray(struct ID3DXConstantTable
*iface
,
1670 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const INT
*n
, UINT count
)
1672 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1674 TRACE("iface %p, device %p, constant %p, n %p, count %d\n", iface
, device
, constant
, n
, count
);
1676 return set_scalar_array(This
, device
, constant
, n
, count
, D3DXPT_INT
);
1679 static HRESULT WINAPI
ID3DXConstantTableImpl_SetFloat(struct ID3DXConstantTable
*iface
,
1680 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, float f
)
1682 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1684 TRACE("iface %p, device %p, constant %p, f %f\n", iface
, device
, constant
, f
);
1686 return set_scalar(This
, device
, constant
, &f
, D3DXPT_FLOAT
);
1689 static HRESULT WINAPI
ID3DXConstantTableImpl_SetFloatArray(struct ID3DXConstantTable
*iface
,
1690 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const float *f
, UINT count
)
1692 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1694 TRACE("iface %p, device %p, constant %p, f %p, count %d\n", iface
, device
, constant
, f
, count
);
1696 return set_scalar_array(This
, device
, constant
, f
, count
, D3DXPT_FLOAT
);
1699 static HRESULT WINAPI
ID3DXConstantTableImpl_SetVector(struct ID3DXConstantTable
*iface
,
1700 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXVECTOR4
*vector
)
1702 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1704 TRACE("iface %p, device %p, constant %p, vector %p\n", iface
, device
, constant
, vector
);
1706 return set_vector(This
, device
, constant
, vector
, D3DXPT_FLOAT
);
1709 static HRESULT WINAPI
ID3DXConstantTableImpl_SetVectorArray(struct ID3DXConstantTable
*iface
,
1710 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXVECTOR4
*vector
, UINT count
)
1712 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1714 TRACE("iface %p, device %p, constant %p, vector %p, count %u\n", iface
, device
, constant
, vector
, count
);
1716 return set_vector_array(This
, device
, constant
, vector
, count
, D3DXPT_FLOAT
);
1719 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrix(struct ID3DXConstantTable
*iface
,
1720 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
)
1722 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1724 TRACE("iface %p, device %p, constant %p, matrix %p\n", iface
, device
, constant
, matrix
);
1726 return set_matrix_array(This
, device
, constant
, matrix
, 1, FALSE
);
1729 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixArray(struct ID3DXConstantTable
*iface
,
1730 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
, UINT count
)
1732 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1734 TRACE("iface %p, device %p, constant %p, matrix %p, count %u\n", iface
, device
, constant
, matrix
, count
);
1736 return set_matrix_array(This
, device
, constant
, matrix
, count
, FALSE
);
1739 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixPointerArray(struct ID3DXConstantTable
*iface
,
1740 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
**matrix
, UINT count
)
1742 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1744 TRACE("iface %p, device %p, constant %p, matrix %p, count %u)\n", iface
, device
, constant
, matrix
, count
);
1746 return set_matrix_pointer_array(This
, device
, constant
, (const void **)matrix
, count
, FALSE
);
1749 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixTranspose(struct ID3DXConstantTable
*iface
,
1750 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
)
1752 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1754 TRACE("iface %p, device %p, constant %p, matrix %p\n", iface
, device
, constant
, matrix
);
1756 return set_matrix_array(This
, device
, constant
, matrix
, 1, TRUE
);
1759 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixTransposeArray(struct ID3DXConstantTable
*iface
,
1760 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
, UINT count
)
1762 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1764 TRACE("iface %p, device %p, constant %p, matrix %p, count %u\n", iface
, device
, constant
, matrix
, count
);
1766 return set_matrix_array(This
, device
, constant
, matrix
, count
, TRUE
);
1769 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixTransposePointerArray(struct ID3DXConstantTable
*iface
,
1770 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
**matrix
, UINT count
)
1772 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1774 TRACE("iface %p, device %p, constant %p, matrix %p, count %u)\n", iface
, device
, constant
, matrix
, count
);
1776 return set_matrix_pointer_array(This
, device
, constant
, (const void **)matrix
, count
, TRUE
);
1779 static const struct ID3DXConstantTableVtbl ID3DXConstantTable_Vtbl
=
1781 /*** IUnknown methods ***/
1782 ID3DXConstantTableImpl_QueryInterface
,
1783 ID3DXConstantTableImpl_AddRef
,
1784 ID3DXConstantTableImpl_Release
,
1785 /*** ID3DXBuffer methods ***/
1786 ID3DXConstantTableImpl_GetBufferPointer
,
1787 ID3DXConstantTableImpl_GetBufferSize
,
1788 /*** ID3DXConstantTable methods ***/
1789 ID3DXConstantTableImpl_GetDesc
,
1790 ID3DXConstantTableImpl_GetConstantDesc
,
1791 ID3DXConstantTableImpl_GetSamplerIndex
,
1792 ID3DXConstantTableImpl_GetConstant
,
1793 ID3DXConstantTableImpl_GetConstantByName
,
1794 ID3DXConstantTableImpl_GetConstantElement
,
1795 ID3DXConstantTableImpl_SetDefaults
,
1796 ID3DXConstantTableImpl_SetValue
,
1797 ID3DXConstantTableImpl_SetBool
,
1798 ID3DXConstantTableImpl_SetBoolArray
,
1799 ID3DXConstantTableImpl_SetInt
,
1800 ID3DXConstantTableImpl_SetIntArray
,
1801 ID3DXConstantTableImpl_SetFloat
,
1802 ID3DXConstantTableImpl_SetFloatArray
,
1803 ID3DXConstantTableImpl_SetVector
,
1804 ID3DXConstantTableImpl_SetVectorArray
,
1805 ID3DXConstantTableImpl_SetMatrix
,
1806 ID3DXConstantTableImpl_SetMatrixArray
,
1807 ID3DXConstantTableImpl_SetMatrixPointerArray
,
1808 ID3DXConstantTableImpl_SetMatrixTranspose
,
1809 ID3DXConstantTableImpl_SetMatrixTransposeArray
,
1810 ID3DXConstantTableImpl_SetMatrixTransposePointerArray
1813 static HRESULT
parse_ctab_constant_type(const char *ctab
, DWORD typeoffset
, struct ctab_constant
*constant
,
1814 BOOL is_element
, WORD index
, WORD max_index
, DWORD
*offset
, DWORD nameoffset
, UINT regset
)
1816 const D3DXSHADER_TYPEINFO
*type
= (LPD3DXSHADER_TYPEINFO
)(ctab
+ typeoffset
);
1817 const D3DXSHADER_STRUCTMEMBERINFO
*memberinfo
= NULL
;
1818 HRESULT hr
= D3D_OK
;
1822 constant
->desc
.DefaultValue
= offset
? ctab
+ *offset
: NULL
;
1823 constant
->desc
.Class
= type
->Class
;
1824 constant
->desc
.Type
= type
->Type
;
1825 constant
->desc
.Rows
= type
->Rows
;
1826 constant
->desc
.Columns
= type
->Columns
;
1827 constant
->desc
.Elements
= is_element
? 1 : type
->Elements
;
1828 constant
->desc
.StructMembers
= type
->StructMembers
;
1829 constant
->desc
.Name
= ctab
+ nameoffset
;
1830 constant
->desc
.RegisterSet
= regset
;
1831 constant
->desc
.RegisterIndex
= index
;
1833 TRACE("name %s, elements %u, index %u, defaultvalue %p, regset %s\n", constant
->desc
.Name
,
1834 constant
->desc
.Elements
, index
, constant
->desc
.DefaultValue
,
1835 debug_d3dxparameter_registerset(regset
));
1836 TRACE("class %s, type %s, rows %d, columns %d, elements %d, struct_members %d\n",
1837 debug_d3dxparameter_class(type
->Class
), debug_d3dxparameter_type(type
->Type
),
1838 type
->Rows
, type
->Columns
, type
->Elements
, type
->StructMembers
);
1840 if (type
->Elements
> 1 && !is_element
)
1842 count
= type
->Elements
;
1844 else if ((type
->Class
== D3DXPC_STRUCT
) && type
->StructMembers
)
1846 memberinfo
= (D3DXSHADER_STRUCTMEMBERINFO
*)(ctab
+ type
->StructMemberInfo
);
1847 count
= type
->StructMembers
;
1852 constant
->constants
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*constant
->constants
) * count
);
1853 if (!constant
->constants
)
1855 ERR("Out of memory\n");
1860 for (i
= 0; i
< count
; ++i
)
1862 hr
= parse_ctab_constant_type(ctab
, memberinfo
? memberinfo
[i
].TypeInfo
: typeoffset
,
1863 &constant
->constants
[i
], memberinfo
== NULL
, index
+ size
, max_index
, offset
,
1864 memberinfo
? memberinfo
[i
].Name
: nameoffset
, regset
);
1868 size
+= constant
->constants
[i
].desc
.RegisterCount
;
1873 WORD offsetdiff
= type
->Columns
* type
->Rows
;
1876 size
= type
->Columns
* type
->Rows
;
1881 fail
= type
->Class
!= D3DXPC_SCALAR
&& type
->Class
!= D3DXPC_VECTOR
1882 && type
->Class
!= D3DXPC_MATRIX_ROWS
&& type
->Class
!= D3DXPC_MATRIX_COLUMNS
;
1887 switch (type
->Class
)
1893 offsetdiff
= type
->Rows
* 4;
1896 case D3DXPC_MATRIX_ROWS
:
1897 offsetdiff
= type
->Rows
* 4;
1901 case D3DXPC_MATRIX_COLUMNS
:
1902 offsetdiff
= type
->Columns
* 4;
1903 size
= type
->Columns
;
1912 case D3DXRS_SAMPLER
:
1914 fail
= type
->Class
!= D3DXPC_OBJECT
;
1924 FIXME("Unhandled register set %s, type class %s\n", debug_d3dxparameter_registerset(regset
),
1925 debug_d3dxparameter_class(type
->Class
));
1928 /* offset in bytes => offsetdiff * sizeof(DWORD) */
1929 if (offset
) *offset
+= offsetdiff
* 4;
1932 constant
->desc
.RegisterCount
= max(0, min(max_index
- index
, size
));
1933 constant
->desc
.Bytes
= 4 * constant
->desc
.Elements
* type
->Rows
* type
->Columns
;
1938 if (constant
->constants
)
1940 for (i
= 0; i
< count
; ++i
)
1942 free_constant(&constant
->constants
[i
]);
1944 HeapFree(GetProcessHeap(), 0, constant
->constants
);
1945 constant
->constants
= NULL
;
1951 HRESULT WINAPI
D3DXGetShaderConstantTableEx(const DWORD
*byte_code
, DWORD flags
, ID3DXConstantTable
**constant_table
)
1953 struct ID3DXConstantTableImpl
*object
= NULL
;
1957 const D3DXSHADER_CONSTANTTABLE
*ctab_header
;
1958 const D3DXSHADER_CONSTANTINFO
*constant_info
;
1961 TRACE("byte_code %p, flags %x, constant_table %p\n", byte_code
, flags
, constant_table
);
1963 if (constant_table
) *constant_table
= NULL
;
1965 if (!byte_code
|| !constant_table
)
1967 WARN("Invalid argument specified.\n");
1968 return D3DERR_INVALIDCALL
;
1971 if (!is_valid_bytecode(*byte_code
))
1973 WARN("Invalid byte_code specified.\n");
1977 if (flags
) FIXME("Flags (%#x) are not handled, yet!\n", flags
);
1979 hr
= D3DXFindShaderComment(byte_code
, MAKEFOURCC('C','T','A','B'), &data
, &size
);
1982 WARN("CTAB not found.\n");
1983 return D3DXERR_INVALIDDATA
;
1986 if (size
< sizeof(*ctab_header
))
1988 WARN("Invalid CTAB size.\n");
1989 return D3DXERR_INVALIDDATA
;
1992 ctab_header
= (const D3DXSHADER_CONSTANTTABLE
*)data
;
1993 if (ctab_header
->Size
!= sizeof(*ctab_header
))
1995 WARN("Invalid D3DXSHADER_CONSTANTTABLE size.\n");
1996 return D3DXERR_INVALIDDATA
;
1999 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2001 return E_OUTOFMEMORY
;
2003 object
->ID3DXConstantTable_iface
.lpVtbl
= &ID3DXConstantTable_Vtbl
;
2006 object
->ctab
= HeapAlloc(GetProcessHeap(), 0, size
);
2009 ERR("Out of memory\n");
2010 HeapFree(GetProcessHeap(), 0, object
);
2011 return E_OUTOFMEMORY
;
2013 object
->size
= size
;
2014 memcpy(object
->ctab
, data
, object
->size
);
2016 object
->desc
.Creator
= ctab_header
->Creator
? object
->ctab
+ ctab_header
->Creator
: NULL
;
2017 object
->desc
.Version
= ctab_header
->Version
;
2018 object
->desc
.Constants
= ctab_header
->Constants
;
2019 TRACE("Creator %s, Version %x, Constants %u, Target %s\n",
2020 debugstr_a(object
->desc
.Creator
), object
->desc
.Version
, object
->desc
.Constants
,
2021 debugstr_a(ctab_header
->Target
? object
->ctab
+ ctab_header
->Target
: NULL
));
2023 object
->constants
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2024 sizeof(*object
->constants
) * object
->desc
.Constants
);
2025 if (!object
->constants
)
2027 ERR("Out of memory\n");
2032 constant_info
= (const D3DXSHADER_CONSTANTINFO
*)(object
->ctab
+ ctab_header
->ConstantInfo
);
2033 for (i
= 0; i
< ctab_header
->Constants
; i
++)
2035 DWORD offset
= constant_info
[i
].DefaultValue
;
2037 hr
= parse_ctab_constant_type(object
->ctab
, constant_info
[i
].TypeInfo
,
2038 &object
->constants
[i
], FALSE
, constant_info
[i
].RegisterIndex
,
2039 constant_info
[i
].RegisterIndex
+ constant_info
[i
].RegisterCount
,
2040 offset
? &offset
: NULL
, constant_info
[i
].Name
, constant_info
[i
].RegisterSet
);
2045 * Set the register count, it may differ for D3DXRS_INT4, because somehow
2046 * it makes the assumption that the register size is 1 instead of 4, so the
2047 * count is 4 times bigger. This holds true only for toplevel shader
2048 * constants. The count of elements and members is always based on a
2049 * register size of 4.
2051 if (object
->constants
[i
].desc
.RegisterSet
== D3DXRS_INT4
)
2053 object
->constants
[i
].desc
.RegisterCount
= constant_info
[i
].RegisterCount
;
2057 *constant_table
= &object
->ID3DXConstantTable_iface
;
2062 free_constant_table(object
);
2063 HeapFree(GetProcessHeap(), 0, object
);
2068 HRESULT WINAPI
D3DXGetShaderConstantTable(const DWORD
*byte_code
, ID3DXConstantTable
**constant_table
)
2070 TRACE("(%p, %p): Forwarded to D3DXGetShaderConstantTableEx\n", byte_code
, constant_table
);
2072 return D3DXGetShaderConstantTableEx(byte_code
, 0, constant_table
);
2075 HRESULT WINAPI
D3DXCreateFragmentLinker(IDirect3DDevice9
*device
, UINT size
, ID3DXFragmentLinker
**linker
)
2077 FIXME("device %p, size %u, linker %p: stub.\n", device
, size
, linker
);
2086 HRESULT WINAPI
D3DXCreateFragmentLinkerEx(IDirect3DDevice9
*device
, UINT size
, DWORD flags
, ID3DXFragmentLinker
**linker
)
2088 FIXME("device %p, size %u, flags %#x, linker %p: stub.\n", device
, size
, flags
, linker
);
2096 HRESULT WINAPI
D3DXGetShaderSamplers(const DWORD
*byte_code
, const char **samplers
, UINT
*count
)
2098 UINT i
, sampler_count
= 0;
2101 const D3DXSHADER_CONSTANTTABLE
*ctab_header
;
2102 const D3DXSHADER_CONSTANTINFO
*constant_info
;
2104 TRACE("byte_code %p, samplers %p, count %p\n", byte_code
, samplers
, count
);
2106 if (count
) *count
= 0;
2108 if (D3DXFindShaderComment(byte_code
, MAKEFOURCC('C','T','A','B'), (const void **)&data
, &size
) != D3D_OK
)
2111 if (size
< sizeof(*ctab_header
)) return D3D_OK
;
2113 ctab_header
= (const D3DXSHADER_CONSTANTTABLE
*)data
;
2114 if (ctab_header
->Size
!= sizeof(*ctab_header
)) return D3D_OK
;
2116 constant_info
= (const D3DXSHADER_CONSTANTINFO
*)(data
+ ctab_header
->ConstantInfo
);
2117 for (i
= 0; i
< ctab_header
->Constants
; i
++)
2119 const D3DXSHADER_TYPEINFO
*type
;
2121 TRACE("name = %s\n", data
+ constant_info
[i
].Name
);
2123 type
= (const D3DXSHADER_TYPEINFO
*)(data
+ constant_info
[i
].TypeInfo
);
2125 if (type
->Type
== D3DXPT_SAMPLER
2126 || type
->Type
== D3DXPT_SAMPLER1D
2127 || type
->Type
== D3DXPT_SAMPLER2D
2128 || type
->Type
== D3DXPT_SAMPLER3D
2129 || type
->Type
== D3DXPT_SAMPLERCUBE
)
2131 if (samplers
) samplers
[sampler_count
] = data
+ constant_info
[i
].Name
;
2137 TRACE("Found %u samplers\n", sampler_count
);
2139 if (count
) *count
= sampler_count
;
2144 HRESULT WINAPI
D3DXDisassembleShader(const DWORD
*shader
, BOOL colorcode
, const char *comments
, ID3DXBuffer
**disassembly
)
2146 FIXME("%p %d %s %p: stub\n", shader
, colorcode
, debugstr_a(comments
), disassembly
);
2147 return E_OUTOFMEMORY
;
2150 struct d3dx9_texture_shader
2152 ID3DXTextureShader ID3DXTextureShader_iface
;
2156 static inline struct d3dx9_texture_shader
*impl_from_ID3DXTextureShader(ID3DXTextureShader
*iface
)
2158 return CONTAINING_RECORD(iface
, struct d3dx9_texture_shader
, ID3DXTextureShader_iface
);
2161 static HRESULT WINAPI
d3dx9_texture_shader_QueryInterface(ID3DXTextureShader
*iface
, REFIID riid
, void **out
)
2163 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
2165 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
2166 IsEqualGUID(riid
, &IID_ID3DXTextureShader
))
2168 iface
->lpVtbl
->AddRef(iface
);
2173 WARN("Interface %s not found.\n", debugstr_guid(riid
));
2175 return E_NOINTERFACE
;
2178 static ULONG WINAPI
d3dx9_texture_shader_AddRef(ID3DXTextureShader
*iface
)
2180 struct d3dx9_texture_shader
*texture_shader
= impl_from_ID3DXTextureShader(iface
);
2181 ULONG refcount
= InterlockedIncrement(&texture_shader
->ref
);
2183 TRACE("%p increasing refcount to %u.\n", texture_shader
, refcount
);
2188 static ULONG WINAPI
d3dx9_texture_shader_Release(ID3DXTextureShader
*iface
)
2190 struct d3dx9_texture_shader
*texture_shader
= impl_from_ID3DXTextureShader(iface
);
2191 ULONG refcount
= InterlockedDecrement(&texture_shader
->ref
);
2193 TRACE("%p decreasing refcount to %u.\n", texture_shader
, refcount
);
2197 HeapFree(GetProcessHeap(), 0, texture_shader
);
2203 static HRESULT WINAPI
d3dx9_texture_shader_GetFunction(ID3DXTextureShader
*iface
, struct ID3DXBuffer
**function
)
2205 FIXME("iface %p, function %p stub.\n", iface
, function
);
2210 static HRESULT WINAPI
d3dx9_texture_shader_GetConstantBuffer(ID3DXTextureShader
*iface
, struct ID3DXBuffer
**constant_buffer
)
2212 FIXME("iface %p, constant_buffer %p stub.\n", iface
, constant_buffer
);
2217 static HRESULT WINAPI
d3dx9_texture_shader_GetDesc(ID3DXTextureShader
*iface
, D3DXCONSTANTTABLE_DESC
*desc
)
2219 FIXME("iface %p, desc %p stub.\n", iface
, desc
);
2224 static HRESULT WINAPI
d3dx9_texture_shader_GetConstantDesc(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, D3DXCONSTANT_DESC
*constant_desc
, UINT
*count
)
2226 FIXME("iface %p, constant %p, constant_desc %p, count %p stub.\n", iface
, constant
, constant_desc
, count
);
2231 static D3DXHANDLE WINAPI
d3dx9_texture_shader_GetConstant(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, UINT index
)
2233 FIXME("iface %p, constant %p, index %u stub.\n", iface
, constant
, index
);
2238 static D3DXHANDLE WINAPI
d3dx9_texture_shader_GetConstantByName(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const char *name
)
2240 FIXME("iface %p, constant %p, name %s stub.\n", iface
, constant
, debugstr_a(name
));
2245 static D3DXHANDLE WINAPI
d3dx9_texture_shader_GetConstantElement(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, UINT index
)
2247 FIXME("iface %p, constant %p, index %u stub.\n", iface
, constant
, index
);
2252 static HRESULT WINAPI
d3dx9_texture_shader_SetDefaults(ID3DXTextureShader
*iface
)
2254 FIXME("iface %p stub.\n", iface
);
2259 static HRESULT WINAPI
d3dx9_texture_shader_SetValue(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const void *data
, UINT bytes
)
2261 FIXME("iface %p, constant %p, data %p, bytes %u stub.\n", iface
, constant
, data
, bytes
);
2266 static HRESULT WINAPI
d3dx9_texture_shader_SetBool(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, BOOL b
)
2268 FIXME("iface %p, constant %p, b %u stub.\n", iface
, constant
, b
);
2273 static HRESULT WINAPI
d3dx9_texture_shader_SetBoolArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const BOOL
*b
, UINT count
)
2275 FIXME("iface %p, constant %p, b %p, count %u stub.\n", iface
, constant
, b
, count
);
2280 static HRESULT WINAPI
d3dx9_texture_shader_SetInt(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, INT n
)
2282 FIXME("iface %p, constant %p, n %d stub.\n", iface
, constant
, n
);
2287 static HRESULT WINAPI
d3dx9_texture_shader_SetIntArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const INT
*n
, UINT count
)
2289 FIXME("iface %p, constant %p, n %p, count %u stub.\n", iface
, constant
, n
, count
);
2294 static HRESULT WINAPI
d3dx9_texture_shader_SetFloat(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, FLOAT f
)
2296 FIXME("iface %p, constant %p, f %f stub.\n", iface
, constant
, f
);
2301 static HRESULT WINAPI
d3dx9_texture_shader_SetFloatArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const FLOAT
*f
, UINT count
)
2303 FIXME("iface %p, constant %p, f %p, count %u stub.\n", iface
, constant
, f
, count
);
2308 static HRESULT WINAPI
d3dx9_texture_shader_SetVector(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXVECTOR4
*vector
)
2310 FIXME("iface %p, constant %p, vector %p stub.\n", iface
, constant
, vector
);
2315 static HRESULT WINAPI
d3dx9_texture_shader_SetVectorArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXVECTOR4
*vector
, UINT count
)
2317 FIXME("iface %p, constant %p, vector %p, count %u stub.\n", iface
, constant
, vector
, count
);
2322 static HRESULT WINAPI
d3dx9_texture_shader_SetMatrix(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
)
2324 FIXME("iface %p, constant %p, matrix %p stub.\n", iface
, constant
, matrix
);
2329 static HRESULT WINAPI
d3dx9_texture_shader_SetMatrixArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
, UINT count
)
2331 FIXME("iface %p, constant %p, matrix %p, count %u stub.\n", iface
, constant
, matrix
, count
);
2336 static HRESULT WINAPI
d3dx9_texture_shader_SetMatrixPointerArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXMATRIX
**matrix
, UINT count
)
2338 FIXME("iface %p, constant %p, matrix %p, count %u stub.\n", iface
, constant
, matrix
, count
);
2343 static HRESULT WINAPI
d3dx9_texture_shader_SetMatrixTranspose(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
)
2345 FIXME("iface %p, constant %p, matrix %p stub.\n", iface
, constant
, matrix
);
2350 static HRESULT WINAPI
d3dx9_texture_shader_SetMatrixTransposeArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
, UINT count
)
2352 FIXME("iface %p, constant %p, matrix %p, count %u stub.\n", iface
, constant
, matrix
, count
);
2357 static HRESULT WINAPI
d3dx9_texture_shader_SetMatrixTransposePointerArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXMATRIX
**matrix
, UINT count
)
2359 FIXME("iface %p, constant %p, matrix %p, count %u stub.\n", iface
, constant
, matrix
, count
);
2364 static const struct ID3DXTextureShaderVtbl d3dx9_texture_shader_vtbl
=
2366 /*** IUnknown methods ***/
2367 d3dx9_texture_shader_QueryInterface
,
2368 d3dx9_texture_shader_AddRef
,
2369 d3dx9_texture_shader_Release
,
2370 /*** ID3DXTextureShader methods ***/
2371 d3dx9_texture_shader_GetFunction
,
2372 d3dx9_texture_shader_GetConstantBuffer
,
2373 d3dx9_texture_shader_GetDesc
,
2374 d3dx9_texture_shader_GetConstantDesc
,
2375 d3dx9_texture_shader_GetConstant
,
2376 d3dx9_texture_shader_GetConstantByName
,
2377 d3dx9_texture_shader_GetConstantElement
,
2378 d3dx9_texture_shader_SetDefaults
,
2379 d3dx9_texture_shader_SetValue
,
2380 d3dx9_texture_shader_SetBool
,
2381 d3dx9_texture_shader_SetBoolArray
,
2382 d3dx9_texture_shader_SetInt
,
2383 d3dx9_texture_shader_SetIntArray
,
2384 d3dx9_texture_shader_SetFloat
,
2385 d3dx9_texture_shader_SetFloatArray
,
2386 d3dx9_texture_shader_SetVector
,
2387 d3dx9_texture_shader_SetVectorArray
,
2388 d3dx9_texture_shader_SetMatrix
,
2389 d3dx9_texture_shader_SetMatrixArray
,
2390 d3dx9_texture_shader_SetMatrixPointerArray
,
2391 d3dx9_texture_shader_SetMatrixTranspose
,
2392 d3dx9_texture_shader_SetMatrixTransposeArray
,
2393 d3dx9_texture_shader_SetMatrixTransposePointerArray
2396 HRESULT WINAPI
D3DXCreateTextureShader(const DWORD
*function
, ID3DXTextureShader
**texture_shader
)
2398 struct d3dx9_texture_shader
*object
;
2400 TRACE("function %p, texture_shader %p.\n", function
, texture_shader
);
2402 if (!function
|| !texture_shader
)
2403 return D3DERR_INVALIDCALL
;
2405 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
2407 return E_OUTOFMEMORY
;
2409 object
->ID3DXTextureShader_iface
.lpVtbl
= &d3dx9_texture_shader_vtbl
;
2412 *texture_shader
= &object
->ID3DXTextureShader_iface
;