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 ID3DXConstantTableImpl
{
685 ID3DXConstantTable ID3DXConstantTable_iface
;
689 D3DXCONSTANTTABLE_DESC desc
;
690 struct ctab_constant
*constants
;
693 static void free_constant(struct ctab_constant
*constant
)
695 if (constant
->constants
)
697 UINT i
, count
= constant
->desc
.Elements
> 1 ? constant
->desc
.Elements
: constant
->desc
.StructMembers
;
699 for (i
= 0; i
< count
; ++i
)
701 free_constant(&constant
->constants
[i
]);
703 HeapFree(GetProcessHeap(), 0, constant
->constants
);
707 static void free_constant_table(struct ID3DXConstantTableImpl
*table
)
709 if (table
->constants
)
713 for (i
= 0; i
< table
->desc
.Constants
; ++i
)
715 free_constant(&table
->constants
[i
]);
717 HeapFree(GetProcessHeap(), 0, table
->constants
);
719 HeapFree(GetProcessHeap(), 0, table
->ctab
);
722 static inline struct ID3DXConstantTableImpl
*impl_from_ID3DXConstantTable(ID3DXConstantTable
*iface
)
724 return CONTAINING_RECORD(iface
, struct ID3DXConstantTableImpl
, ID3DXConstantTable_iface
);
727 static inline BOOL
is_vertex_shader(DWORD version
)
729 return (version
& 0xffff0000) == 0xfffe0000;
732 static inline D3DXHANDLE
handle_from_constant(struct ctab_constant
*constant
)
734 return (D3DXHANDLE
)constant
;
737 static struct ctab_constant
*get_constant_by_name(struct ID3DXConstantTableImpl
*table
,
738 struct ctab_constant
*constant
, const char *name
);
740 static struct ctab_constant
*get_constant_element_by_name(struct ctab_constant
*constant
, const char *name
)
745 TRACE("constant %p, name %s\n", constant
, debugstr_a(name
));
747 if (!name
|| !*name
) return NULL
;
749 element
= atoi(name
);
750 part
= strchr(name
, ']') + 1;
752 if (constant
->desc
.Elements
> element
)
754 struct ctab_constant
*c
= constant
->constants
? &constant
->constants
[element
] : constant
;
759 return get_constant_by_name(NULL
, c
, part
);
762 return get_constant_element_by_name(c
, part
);
765 TRACE("Returning parameter %p\n", c
);
769 FIXME("Unhandled case \"%c\"\n", *--part
);
774 TRACE("Constant not found\n");
778 static struct ctab_constant
*get_constant_by_name(struct ID3DXConstantTableImpl
*table
,
779 struct ctab_constant
*constant
, const char *name
)
781 UINT i
, count
, length
;
782 struct ctab_constant
*handles
;
785 TRACE("table %p, constant %p, name %s\n", table
, constant
, debugstr_a(name
));
787 if (!name
|| !*name
) return NULL
;
791 count
= table
->desc
.Constants
;
792 handles
= table
->constants
;
796 count
= constant
->desc
.StructMembers
;
797 handles
= constant
->constants
;
800 length
= strcspn(name
, "[.");
801 part
= name
+ length
;
803 for (i
= 0; i
< count
; i
++)
805 if (strlen(handles
[i
].desc
.Name
) == length
&& !strncmp(handles
[i
].desc
.Name
, name
, length
))
810 return get_constant_by_name(NULL
, &handles
[i
], part
);
813 return get_constant_element_by_name(&handles
[i
], part
);
816 TRACE("Returning parameter %p\n", &handles
[i
]);
822 TRACE("Constant not found\n");
826 static struct ctab_constant
*is_valid_sub_constant(struct ctab_constant
*parent
, D3DXHANDLE handle
)
828 struct ctab_constant
*c
;
831 /* all variable have at least elements = 1, but not always elements */
832 if (!parent
->constants
) return NULL
;
834 count
= parent
->desc
.Elements
> 1 ? parent
->desc
.Elements
: parent
->desc
.StructMembers
;
835 for (i
= 0; i
< count
; ++i
)
837 if (handle_from_constant(&parent
->constants
[i
]) == handle
)
838 return &parent
->constants
[i
];
840 c
= is_valid_sub_constant(&parent
->constants
[i
], handle
);
847 static inline struct ctab_constant
*get_valid_constant(struct ID3DXConstantTableImpl
*table
, D3DXHANDLE handle
)
849 struct ctab_constant
*c
;
852 if (!handle
) return NULL
;
854 for (i
= 0; i
< table
->desc
.Constants
; ++i
)
856 if (handle_from_constant(&table
->constants
[i
]) == handle
)
857 return &table
->constants
[i
];
859 c
= is_valid_sub_constant(&table
->constants
[i
], handle
);
863 return get_constant_by_name(table
, NULL
, handle
);
866 /*** IUnknown methods ***/
867 static HRESULT WINAPI
ID3DXConstantTableImpl_QueryInterface(ID3DXConstantTable
*iface
, REFIID riid
, void **out
)
869 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
871 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
872 IsEqualGUID(riid
, &IID_ID3DXBuffer
) ||
873 IsEqualGUID(riid
, &IID_ID3DXConstantTable
))
875 ID3DXConstantTable_AddRef(iface
);
880 WARN("Interface %s not found.\n", debugstr_guid(riid
));
882 return E_NOINTERFACE
;
885 static ULONG WINAPI
ID3DXConstantTableImpl_AddRef(ID3DXConstantTable
*iface
)
887 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
889 TRACE("(%p)->(): AddRef from %d\n", This
, This
->ref
);
891 return InterlockedIncrement(&This
->ref
);
894 static ULONG WINAPI
ID3DXConstantTableImpl_Release(ID3DXConstantTable
*iface
)
896 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
897 ULONG ref
= InterlockedDecrement(&This
->ref
);
899 TRACE("(%p)->(): Release from %d\n", This
, ref
+ 1);
903 free_constant_table(This
);
904 HeapFree(GetProcessHeap(), 0, This
);
910 /*** ID3DXBuffer methods ***/
911 static void * WINAPI
ID3DXConstantTableImpl_GetBufferPointer(ID3DXConstantTable
*iface
)
913 struct ID3DXConstantTableImpl
*table
= impl_from_ID3DXConstantTable(iface
);
915 TRACE("iface %p.\n", iface
);
920 static DWORD WINAPI
ID3DXConstantTableImpl_GetBufferSize(ID3DXConstantTable
*iface
)
922 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
924 TRACE("(%p)->()\n", This
);
929 /*** ID3DXConstantTable methods ***/
930 static HRESULT WINAPI
ID3DXConstantTableImpl_GetDesc(ID3DXConstantTable
*iface
, D3DXCONSTANTTABLE_DESC
*desc
)
932 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
934 TRACE("(%p)->(%p)\n", This
, desc
);
937 return D3DERR_INVALIDCALL
;
944 const struct ctab_constant
*d3dx_shader_get_ctab_constant(ID3DXConstantTable
*iface
, D3DXHANDLE constant
)
946 struct ID3DXConstantTableImpl
*ctab
= impl_from_ID3DXConstantTable(iface
);
948 return get_valid_constant(ctab
, constant
);
951 static HRESULT WINAPI
ID3DXConstantTableImpl_GetConstantDesc(ID3DXConstantTable
*iface
, D3DXHANDLE constant
,
952 D3DXCONSTANT_DESC
*desc
, UINT
*count
)
954 struct ID3DXConstantTableImpl
*ctab
= impl_from_ID3DXConstantTable(iface
);
955 struct ctab_constant
*c
= get_valid_constant(ctab
, constant
);
957 TRACE("(%p)->(%p, %p, %p)\n", ctab
, constant
, desc
, count
);
961 WARN("Invalid argument specified\n");
962 return D3DERR_INVALIDCALL
;
965 if (desc
) *desc
= c
->desc
;
966 if (count
) *count
= 1;
971 static UINT WINAPI
ID3DXConstantTableImpl_GetSamplerIndex(ID3DXConstantTable
*iface
, D3DXHANDLE constant
)
973 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
974 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
976 TRACE("(%p)->(%p)\n", This
, constant
);
978 if (!c
|| c
->desc
.RegisterSet
!= D3DXRS_SAMPLER
)
980 WARN("Invalid argument specified\n");
984 TRACE("Returning RegisterIndex %u\n", c
->desc
.RegisterIndex
);
985 return c
->desc
.RegisterIndex
;
988 static D3DXHANDLE WINAPI
ID3DXConstantTableImpl_GetConstant(ID3DXConstantTable
*iface
, D3DXHANDLE constant
, UINT index
)
990 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
991 struct ctab_constant
*c
;
993 TRACE("(%p)->(%p, %d)\n", This
, constant
, index
);
997 c
= get_valid_constant(This
, constant
);
998 if (c
&& index
< c
->desc
.StructMembers
)
1000 c
= &c
->constants
[index
];
1001 TRACE("Returning constant %p\n", c
);
1002 return handle_from_constant(c
);
1007 if (index
< This
->desc
.Constants
)
1009 c
= &This
->constants
[index
];
1010 TRACE("Returning constant %p\n", c
);
1011 return handle_from_constant(c
);
1015 WARN("Index out of range\n");
1019 static D3DXHANDLE WINAPI
ID3DXConstantTableImpl_GetConstantByName(ID3DXConstantTable
*iface
,
1020 D3DXHANDLE constant
, const char *name
)
1022 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1023 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
1025 TRACE("iface %p, constant %p, name %s.\n", iface
, constant
, debugstr_a(name
));
1027 c
= get_constant_by_name(This
, c
, name
);
1028 TRACE("Returning constant %p\n", c
);
1030 return handle_from_constant(c
);
1033 static D3DXHANDLE WINAPI
ID3DXConstantTableImpl_GetConstantElement(ID3DXConstantTable
*iface
, D3DXHANDLE constant
, UINT index
)
1035 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1036 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
1038 TRACE("(%p)->(%p, %d)\n", This
, constant
, index
);
1040 if (c
&& index
< c
->desc
.Elements
)
1042 if (c
->desc
.Elements
> 1) c
= &c
->constants
[index
];
1043 TRACE("Returning constant %p\n", c
);
1044 return handle_from_constant(c
);
1047 WARN("Invalid argument specified\n");
1051 static inline DWORD
get_index(const void **indata
, UINT index
, BOOL is_pointer
)
1057 return ((DWORD
**)indata
)[index
/ 16][index
% 16];
1059 return (*((DWORD
**)indata
))[index
];
1062 static UINT
set(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, struct ctab_constant
*constant
,
1063 const void **indata
, D3DXPARAMETER_TYPE intype
, UINT
*size
, UINT incol
, D3DXPARAMETER_CLASS inclass
, UINT index
,
1066 D3DXCONSTANT_DESC
*desc
= &constant
->desc
;
1067 UINT l
, i
, regcount
= 1, regsize
= 1, cin
= 1, rin
= 1, ret
, last
= 0;
1070 /* size too small to set anything */
1071 if (*size
< desc
->Rows
* desc
->Columns
)
1077 /* D3DXPC_STRUCT is somewhat special */
1078 if (desc
->Class
== D3DXPC_STRUCT
)
1081 * Struct array sets the last complete input to the first struct element, all other
1082 * elements are not set.
1083 * E.g.: struct {int i;} s1[2];
1084 * SetValue(device, "s1", [1, 2], 8) => s1 = {2, x};
1086 * struct {int i; int n} s2[2];
1087 * SetValue(device, "s2", [1, 2, 3, 4, 5], 20) => s1 = {{3, 4}, {x, x}};
1089 if (desc
->Elements
> 1)
1091 UINT offset
= *size
/ (desc
->Rows
* desc
->Columns
) - 1;
1093 offset
= min(desc
->Elements
- 1, offset
);
1094 last
= offset
* desc
->Rows
* desc
->Columns
;
1096 if ((is_pointer
|| inclass
== D3DXPC_MATRIX_ROWS
) && desc
->RegisterSet
!= D3DXRS_BOOL
)
1098 set(table
, device
, &constant
->constants
[0], NULL
, intype
, size
, incol
, inclass
, 0, is_pointer
);
1102 last
+= set(table
, device
, &constant
->constants
[0], indata
, intype
, size
, incol
, inclass
,
1103 index
+ last
, is_pointer
);
1109 * D3DXRS_BOOL is always set. As there are only 16 bools and there are
1110 * exactly 16 input values, use matrix transpose.
1112 if (inclass
== D3DXPC_MATRIX_ROWS
&& desc
->RegisterSet
== D3DXRS_BOOL
)
1114 D3DXMATRIX mat
, *m
, min
;
1115 D3DXMatrixTranspose(&mat
, &min
);
1118 min
= *(D3DXMATRIX
*)(indata
[index
/ 16]);
1120 min
= **(D3DXMATRIX
**)indata
;
1122 D3DXMatrixTranspose(&mat
, &min
);
1124 for (i
= 0; i
< desc
->StructMembers
; ++i
)
1126 last
+= set(table
, device
, &constant
->constants
[i
], (const void **)&m
, intype
, size
, incol
,
1127 D3DXPC_SCALAR
, index
+ last
, is_pointer
);
1131 * For pointers or for matrix rows, only the first member is set.
1132 * All other members are set to 0. This is not true for D3DXRS_BOOL.
1133 * E.g.: struct {int i; int n} s;
1134 * SetValue(device, "s", [1, 2], 8) => s = {1, 0};
1136 else if ((is_pointer
|| inclass
== D3DXPC_MATRIX_ROWS
) && desc
->RegisterSet
!= D3DXRS_BOOL
)
1138 last
= set(table
, device
, &constant
->constants
[0], indata
, intype
, size
, incol
, inclass
,
1139 index
+ last
, is_pointer
);
1141 for (i
= 1; i
< desc
->StructMembers
; ++i
)
1143 set(table
, device
, &constant
->constants
[i
], NULL
, intype
, size
, incol
, inclass
, 0, is_pointer
);
1148 for (i
= 0; i
< desc
->StructMembers
; ++i
)
1150 last
+= set(table
, device
, &constant
->constants
[i
], indata
, intype
, size
, incol
, D3DXPC_SCALAR
,
1151 index
+ last
, is_pointer
);
1160 if (desc
->Elements
> 1)
1162 for (i
= 0; i
< desc
->Elements
&& *size
> 0; ++i
)
1164 last
+= set(table
, device
, &constant
->constants
[i
], indata
, intype
, size
, incol
, inclass
,
1165 index
+ last
, is_pointer
);
1167 /* adjust the vector size for matrix rows */
1168 if (inclass
== D3DXPC_MATRIX_ROWS
&& desc
->Class
== D3DXPC_VECTOR
&& (i
% 4) == 3)
1171 *size
= *size
< 12 ? 0 : *size
- 12;
1178 switch (desc
->Class
)
1182 case D3DXPC_MATRIX_ROWS
:
1183 regcount
= min(desc
->RegisterCount
, desc
->Rows
);
1184 if (inclass
== D3DXPC_MATRIX_ROWS
) cin
= incol
;
1186 regsize
= desc
->Columns
;
1189 case D3DXPC_MATRIX_COLUMNS
:
1190 regcount
= min(desc
->RegisterCount
, desc
->Columns
);
1191 if (inclass
== D3DXPC_MATRIX_ROWS
) rin
= incol
;
1193 regsize
= desc
->Rows
;
1197 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1201 /* specific stuff for different in types */
1205 ret
= desc
->Columns
* desc
->Rows
;
1206 *size
-= desc
->Columns
* desc
->Rows
;
1210 switch (desc
->Class
)
1212 case D3DXPC_MATRIX_ROWS
:
1213 if (*size
< regcount
* 4)
1219 *size
-= 4 * regcount
;
1222 case D3DXPC_MATRIX_COLUMNS
:
1224 *size
-= 4 * regcount
;
1238 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1243 case D3DXPC_MATRIX_ROWS
:
1244 switch (desc
->Class
)
1246 case D3DXPC_MATRIX_ROWS
:
1247 case D3DXPC_MATRIX_COLUMNS
:
1265 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1271 case D3DXPC_MATRIX_COLUMNS
:
1272 switch (desc
->Class
)
1274 case D3DXPC_MATRIX_ROWS
:
1275 case D3DXPC_MATRIX_COLUMNS
:
1293 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1300 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(inclass
));
1304 /* set the registers */
1305 switch (desc
->RegisterSet
)
1308 regcount
= min(desc
->RegisterCount
, desc
->Columns
* desc
->Rows
);
1310 for (i
= 0; i
< regcount
; ++i
)
1313 DWORD t
= get_index(indata
, index
+ i
/ regsize
* rin
+ l
* cin
, is_pointer
);
1315 set_number(&tmp
, desc
->Type
, &t
, intype
);
1316 set_number(&out
, D3DXPT_BOOL
, &tmp
, desc
->Type
);
1317 if (is_vertex_shader(table
->desc
.Version
))
1318 IDirect3DDevice9_SetVertexShaderConstantB(device
, desc
->RegisterIndex
+ i
, &out
, 1);
1320 IDirect3DDevice9_SetPixelShaderConstantB(device
, desc
->RegisterIndex
+ i
, &out
, 1);
1322 if (++l
>= regsize
) l
= 0;
1327 for (i
= 0; i
< regcount
; ++i
)
1329 INT vec
[4] = {0, 0, 1, 0};
1331 for (l
= 0; l
< regsize
; ++l
)
1333 DWORD t
= get_index(indata
, index
+ i
* rin
+ l
* cin
, is_pointer
);
1335 set_number(&tmp
, desc
->Type
, &t
, intype
);
1336 set_number(&vec
[l
], D3DXPT_INT
, &tmp
, desc
->Type
);
1338 if (is_vertex_shader(table
->desc
.Version
))
1339 IDirect3DDevice9_SetVertexShaderConstantI(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1341 IDirect3DDevice9_SetPixelShaderConstantI(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1346 for (i
= 0; i
< regcount
; ++i
)
1350 for (l
= 0; l
< regsize
; ++l
)
1352 DWORD t
= get_index(indata
, index
+ i
* rin
+ l
* cin
, is_pointer
);
1354 set_number(&tmp
, desc
->Type
, &t
, intype
);
1355 set_number(&vec
[l
], D3DXPT_FLOAT
, &tmp
, desc
->Type
);
1357 if (is_vertex_shader(table
->desc
.Version
))
1358 IDirect3DDevice9_SetVertexShaderConstantF(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1360 IDirect3DDevice9_SetPixelShaderConstantF(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1365 FIXME("Unhandled register set %s\n", debug_d3dxparameter_registerset(desc
->RegisterSet
));
1370 static HRESULT
set_scalar(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1371 const void *indata
, D3DXPARAMETER_TYPE intype
)
1373 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1378 WARN("Invalid argument specified\n");
1379 return D3DERR_INVALIDCALL
;
1382 switch (c
->desc
.Class
)
1385 set(table
, device
, c
, &indata
, intype
, &count
, c
->desc
.Columns
, D3DXPC_SCALAR
, 0, FALSE
);
1389 case D3DXPC_MATRIX_ROWS
:
1390 case D3DXPC_MATRIX_COLUMNS
:
1395 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1396 return D3DERR_INVALIDCALL
;
1400 static HRESULT
set_scalar_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1401 const void *indata
, UINT count
, D3DXPARAMETER_TYPE intype
)
1403 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1407 WARN("Invalid argument specified\n");
1408 return D3DERR_INVALIDCALL
;
1411 switch (c
->desc
.Class
)
1415 case D3DXPC_MATRIX_ROWS
:
1416 case D3DXPC_MATRIX_COLUMNS
:
1418 set(table
, device
, c
, &indata
, intype
, &count
, c
->desc
.Columns
, D3DXPC_SCALAR
, 0, FALSE
);
1422 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1423 return D3DERR_INVALIDCALL
;
1427 static HRESULT
set_vector(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1428 const void *indata
, D3DXPARAMETER_TYPE intype
)
1430 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1435 WARN("Invalid argument specified\n");
1436 return D3DERR_INVALIDCALL
;
1439 switch (c
->desc
.Class
)
1444 set(table
, device
, c
, &indata
, intype
, &count
, 4, D3DXPC_VECTOR
, 0, FALSE
);
1447 case D3DXPC_MATRIX_ROWS
:
1448 case D3DXPC_MATRIX_COLUMNS
:
1452 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1453 return D3DERR_INVALIDCALL
;
1457 static HRESULT
set_vector_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1458 const void *indata
, UINT count
, D3DXPARAMETER_TYPE intype
)
1460 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1464 WARN("Invalid argument specified\n");
1465 return D3DERR_INVALIDCALL
;
1468 switch (c
->desc
.Class
)
1472 case D3DXPC_MATRIX_ROWS
:
1473 case D3DXPC_MATRIX_COLUMNS
:
1476 set(table
, device
, c
, &indata
, intype
, &count
, 4, D3DXPC_VECTOR
, 0, FALSE
);
1480 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1481 return D3DERR_INVALIDCALL
;
1485 static HRESULT
set_matrix_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1486 const void *indata
, UINT count
, BOOL transpose
)
1488 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1492 WARN("Invalid argument specified\n");
1493 return D3DERR_INVALIDCALL
;
1496 switch (c
->desc
.Class
)
1500 case D3DXPC_MATRIX_ROWS
:
1501 case D3DXPC_MATRIX_COLUMNS
:
1504 set(table
, device
, c
, &indata
, D3DXPT_FLOAT
, &count
, 4,
1505 transpose
? D3DXPC_MATRIX_ROWS
: D3DXPC_MATRIX_COLUMNS
, 0, FALSE
);
1509 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1510 return D3DERR_INVALIDCALL
;
1514 static HRESULT
set_matrix_pointer_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
,
1515 D3DXHANDLE constant
, const void **indata
, UINT count
, BOOL transpose
)
1517 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1521 WARN("Invalid argument specified\n");
1522 return D3DERR_INVALIDCALL
;
1525 switch (c
->desc
.Class
)
1529 case D3DXPC_MATRIX_ROWS
:
1530 case D3DXPC_MATRIX_COLUMNS
:
1533 set(table
, device
, c
, indata
, D3DXPT_FLOAT
, &count
, 4,
1534 transpose
? D3DXPC_MATRIX_ROWS
: D3DXPC_MATRIX_COLUMNS
, 0, TRUE
);
1538 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1539 return D3DERR_INVALIDCALL
;
1543 static HRESULT WINAPI
ID3DXConstantTableImpl_SetDefaults(struct ID3DXConstantTable
*iface
,
1544 struct IDirect3DDevice9
*device
)
1546 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1549 TRACE("iface %p, device %p\n", iface
, device
);
1553 WARN("Invalid argument specified\n");
1554 return D3DERR_INVALIDCALL
;
1557 for (i
= 0; i
< This
->desc
.Constants
; i
++)
1559 D3DXCONSTANT_DESC
*desc
= &This
->constants
[i
].desc
;
1562 if (!desc
->DefaultValue
)
1565 switch (desc
->RegisterSet
)
1568 if (is_vertex_shader(This
->desc
.Version
))
1569 hr
= IDirect3DDevice9_SetVertexShaderConstantB(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1570 desc
->RegisterCount
);
1572 hr
= IDirect3DDevice9_SetPixelShaderConstantB(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1573 desc
->RegisterCount
);
1577 if (is_vertex_shader(This
->desc
.Version
))
1578 hr
= IDirect3DDevice9_SetVertexShaderConstantI(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1579 desc
->RegisterCount
);
1581 hr
= IDirect3DDevice9_SetPixelShaderConstantI(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1582 desc
->RegisterCount
);
1586 if (is_vertex_shader(This
->desc
.Version
))
1587 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1588 desc
->RegisterCount
);
1590 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1591 desc
->RegisterCount
);
1595 FIXME("Unhandled register set %s\n", debug_d3dxparameter_registerset(desc
->RegisterSet
));
1607 static HRESULT WINAPI
ID3DXConstantTableImpl_SetValue(struct ID3DXConstantTable
*iface
,
1608 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const void *data
, unsigned int bytes
)
1610 struct ID3DXConstantTableImpl
*table
= impl_from_ID3DXConstantTable(iface
);
1611 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1612 D3DXCONSTANT_DESC
*desc
;
1614 TRACE("iface %p, device %p, constant %p, data %p, bytes %u\n", iface
, device
, constant
, data
, bytes
);
1616 if (!device
|| !c
|| !data
)
1618 WARN("Invalid argument specified\n");
1619 return D3DERR_INVALIDCALL
;
1624 switch (desc
->Class
)
1628 case D3DXPC_MATRIX_ROWS
:
1629 case D3DXPC_MATRIX_COLUMNS
:
1632 set(table
, device
, c
, &data
, desc
->Type
, &bytes
, desc
->Columns
, D3DXPC_SCALAR
, 0, FALSE
);
1636 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(desc
->Class
));
1637 return D3DERR_INVALIDCALL
;
1641 static HRESULT WINAPI
ID3DXConstantTableImpl_SetBool(struct ID3DXConstantTable
*iface
,
1642 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, BOOL b
)
1644 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1646 TRACE("iface %p, device %p, constant %p, b %d\n", iface
, device
, constant
, b
);
1648 return set_scalar(This
, device
, constant
, &b
, D3DXPT_BOOL
);
1651 static HRESULT WINAPI
ID3DXConstantTableImpl_SetBoolArray(struct ID3DXConstantTable
*iface
,
1652 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const BOOL
*b
, UINT count
)
1654 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1656 TRACE("iface %p, device %p, constant %p, b %p, count %d\n", iface
, device
, constant
, b
, count
);
1658 return set_scalar_array(This
, device
, constant
, b
, count
, D3DXPT_BOOL
);
1661 static HRESULT WINAPI
ID3DXConstantTableImpl_SetInt(struct ID3DXConstantTable
*iface
,
1662 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, INT n
)
1664 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1666 TRACE("iface %p, device %p, constant %p, n %d\n", iface
, device
, constant
, n
);
1668 return set_scalar(This
, device
, constant
, &n
, D3DXPT_INT
);
1671 static HRESULT WINAPI
ID3DXConstantTableImpl_SetIntArray(struct ID3DXConstantTable
*iface
,
1672 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const INT
*n
, UINT count
)
1674 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1676 TRACE("iface %p, device %p, constant %p, n %p, count %d\n", iface
, device
, constant
, n
, count
);
1678 return set_scalar_array(This
, device
, constant
, n
, count
, D3DXPT_INT
);
1681 static HRESULT WINAPI
ID3DXConstantTableImpl_SetFloat(struct ID3DXConstantTable
*iface
,
1682 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, float f
)
1684 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1686 TRACE("iface %p, device %p, constant %p, f %f\n", iface
, device
, constant
, f
);
1688 return set_scalar(This
, device
, constant
, &f
, D3DXPT_FLOAT
);
1691 static HRESULT WINAPI
ID3DXConstantTableImpl_SetFloatArray(struct ID3DXConstantTable
*iface
,
1692 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const float *f
, UINT count
)
1694 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1696 TRACE("iface %p, device %p, constant %p, f %p, count %d\n", iface
, device
, constant
, f
, count
);
1698 return set_scalar_array(This
, device
, constant
, f
, count
, D3DXPT_FLOAT
);
1701 static HRESULT WINAPI
ID3DXConstantTableImpl_SetVector(struct ID3DXConstantTable
*iface
,
1702 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXVECTOR4
*vector
)
1704 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1706 TRACE("iface %p, device %p, constant %p, vector %p\n", iface
, device
, constant
, vector
);
1708 return set_vector(This
, device
, constant
, vector
, D3DXPT_FLOAT
);
1711 static HRESULT WINAPI
ID3DXConstantTableImpl_SetVectorArray(struct ID3DXConstantTable
*iface
,
1712 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXVECTOR4
*vector
, UINT count
)
1714 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1716 TRACE("iface %p, device %p, constant %p, vector %p, count %u\n", iface
, device
, constant
, vector
, count
);
1718 return set_vector_array(This
, device
, constant
, vector
, count
, D3DXPT_FLOAT
);
1721 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrix(struct ID3DXConstantTable
*iface
,
1722 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
)
1724 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1726 TRACE("iface %p, device %p, constant %p, matrix %p\n", iface
, device
, constant
, matrix
);
1728 return set_matrix_array(This
, device
, constant
, matrix
, 1, FALSE
);
1731 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixArray(struct ID3DXConstantTable
*iface
,
1732 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
, UINT count
)
1734 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1736 TRACE("iface %p, device %p, constant %p, matrix %p, count %u\n", iface
, device
, constant
, matrix
, count
);
1738 return set_matrix_array(This
, device
, constant
, matrix
, count
, FALSE
);
1741 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixPointerArray(struct ID3DXConstantTable
*iface
,
1742 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
**matrix
, UINT count
)
1744 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1746 TRACE("iface %p, device %p, constant %p, matrix %p, count %u)\n", iface
, device
, constant
, matrix
, count
);
1748 return set_matrix_pointer_array(This
, device
, constant
, (const void **)matrix
, count
, FALSE
);
1751 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixTranspose(struct ID3DXConstantTable
*iface
,
1752 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
)
1754 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1756 TRACE("iface %p, device %p, constant %p, matrix %p\n", iface
, device
, constant
, matrix
);
1758 return set_matrix_array(This
, device
, constant
, matrix
, 1, TRUE
);
1761 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixTransposeArray(struct ID3DXConstantTable
*iface
,
1762 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
, UINT count
)
1764 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1766 TRACE("iface %p, device %p, constant %p, matrix %p, count %u\n", iface
, device
, constant
, matrix
, count
);
1768 return set_matrix_array(This
, device
, constant
, matrix
, count
, TRUE
);
1771 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixTransposePointerArray(struct ID3DXConstantTable
*iface
,
1772 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
**matrix
, UINT count
)
1774 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1776 TRACE("iface %p, device %p, constant %p, matrix %p, count %u)\n", iface
, device
, constant
, matrix
, count
);
1778 return set_matrix_pointer_array(This
, device
, constant
, (const void **)matrix
, count
, TRUE
);
1781 static const struct ID3DXConstantTableVtbl ID3DXConstantTable_Vtbl
=
1783 /*** IUnknown methods ***/
1784 ID3DXConstantTableImpl_QueryInterface
,
1785 ID3DXConstantTableImpl_AddRef
,
1786 ID3DXConstantTableImpl_Release
,
1787 /*** ID3DXBuffer methods ***/
1788 ID3DXConstantTableImpl_GetBufferPointer
,
1789 ID3DXConstantTableImpl_GetBufferSize
,
1790 /*** ID3DXConstantTable methods ***/
1791 ID3DXConstantTableImpl_GetDesc
,
1792 ID3DXConstantTableImpl_GetConstantDesc
,
1793 ID3DXConstantTableImpl_GetSamplerIndex
,
1794 ID3DXConstantTableImpl_GetConstant
,
1795 ID3DXConstantTableImpl_GetConstantByName
,
1796 ID3DXConstantTableImpl_GetConstantElement
,
1797 ID3DXConstantTableImpl_SetDefaults
,
1798 ID3DXConstantTableImpl_SetValue
,
1799 ID3DXConstantTableImpl_SetBool
,
1800 ID3DXConstantTableImpl_SetBoolArray
,
1801 ID3DXConstantTableImpl_SetInt
,
1802 ID3DXConstantTableImpl_SetIntArray
,
1803 ID3DXConstantTableImpl_SetFloat
,
1804 ID3DXConstantTableImpl_SetFloatArray
,
1805 ID3DXConstantTableImpl_SetVector
,
1806 ID3DXConstantTableImpl_SetVectorArray
,
1807 ID3DXConstantTableImpl_SetMatrix
,
1808 ID3DXConstantTableImpl_SetMatrixArray
,
1809 ID3DXConstantTableImpl_SetMatrixPointerArray
,
1810 ID3DXConstantTableImpl_SetMatrixTranspose
,
1811 ID3DXConstantTableImpl_SetMatrixTransposeArray
,
1812 ID3DXConstantTableImpl_SetMatrixTransposePointerArray
1815 static HRESULT
parse_ctab_constant_type(const char *ctab
, DWORD typeoffset
, struct ctab_constant
*constant
,
1816 BOOL is_element
, WORD index
, WORD max_index
, DWORD
*offset
, DWORD nameoffset
, UINT regset
)
1818 const D3DXSHADER_TYPEINFO
*type
= (LPD3DXSHADER_TYPEINFO
)(ctab
+ typeoffset
);
1819 const D3DXSHADER_STRUCTMEMBERINFO
*memberinfo
= NULL
;
1820 HRESULT hr
= D3D_OK
;
1824 constant
->desc
.DefaultValue
= offset
? ctab
+ *offset
: NULL
;
1825 constant
->desc
.Class
= type
->Class
;
1826 constant
->desc
.Type
= type
->Type
;
1827 constant
->desc
.Rows
= type
->Rows
;
1828 constant
->desc
.Columns
= type
->Columns
;
1829 constant
->desc
.Elements
= is_element
? 1 : type
->Elements
;
1830 constant
->desc
.StructMembers
= type
->StructMembers
;
1831 constant
->desc
.Name
= ctab
+ nameoffset
;
1832 constant
->desc
.RegisterSet
= regset
;
1833 constant
->desc
.RegisterIndex
= index
;
1835 TRACE("name %s, elements %u, index %u, defaultvalue %p, regset %s\n", constant
->desc
.Name
,
1836 constant
->desc
.Elements
, index
, constant
->desc
.DefaultValue
,
1837 debug_d3dxparameter_registerset(regset
));
1838 TRACE("class %s, type %s, rows %d, columns %d, elements %d, struct_members %d\n",
1839 debug_d3dxparameter_class(type
->Class
), debug_d3dxparameter_type(type
->Type
),
1840 type
->Rows
, type
->Columns
, type
->Elements
, type
->StructMembers
);
1842 if (type
->Elements
> 1 && !is_element
)
1844 count
= type
->Elements
;
1846 else if ((type
->Class
== D3DXPC_STRUCT
) && type
->StructMembers
)
1848 memberinfo
= (D3DXSHADER_STRUCTMEMBERINFO
*)(ctab
+ type
->StructMemberInfo
);
1849 count
= type
->StructMembers
;
1854 constant
->constants
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*constant
->constants
) * count
);
1855 if (!constant
->constants
)
1857 ERR("Out of memory\n");
1862 for (i
= 0; i
< count
; ++i
)
1864 hr
= parse_ctab_constant_type(ctab
, memberinfo
? memberinfo
[i
].TypeInfo
: typeoffset
,
1865 &constant
->constants
[i
], memberinfo
== NULL
, index
+ size
, max_index
, offset
,
1866 memberinfo
? memberinfo
[i
].Name
: nameoffset
, regset
);
1870 size
+= constant
->constants
[i
].desc
.RegisterCount
;
1875 WORD offsetdiff
= type
->Columns
* type
->Rows
;
1878 size
= type
->Columns
* type
->Rows
;
1883 fail
= type
->Class
!= D3DXPC_SCALAR
&& type
->Class
!= D3DXPC_VECTOR
1884 && type
->Class
!= D3DXPC_MATRIX_ROWS
&& type
->Class
!= D3DXPC_MATRIX_COLUMNS
;
1889 switch (type
->Class
)
1895 offsetdiff
= type
->Rows
* 4;
1898 case D3DXPC_MATRIX_ROWS
:
1899 offsetdiff
= type
->Rows
* 4;
1903 case D3DXPC_MATRIX_COLUMNS
:
1904 offsetdiff
= type
->Columns
* 4;
1905 size
= type
->Columns
;
1914 case D3DXRS_SAMPLER
:
1916 fail
= type
->Class
!= D3DXPC_OBJECT
;
1926 FIXME("Unhandled register set %s, type class %s\n", debug_d3dxparameter_registerset(regset
),
1927 debug_d3dxparameter_class(type
->Class
));
1930 /* offset in bytes => offsetdiff * sizeof(DWORD) */
1931 if (offset
) *offset
+= offsetdiff
* 4;
1934 constant
->desc
.RegisterCount
= max(0, min(max_index
- index
, size
));
1935 constant
->desc
.Bytes
= 4 * constant
->desc
.Elements
* type
->Rows
* type
->Columns
;
1940 if (constant
->constants
)
1942 for (i
= 0; i
< count
; ++i
)
1944 free_constant(&constant
->constants
[i
]);
1946 HeapFree(GetProcessHeap(), 0, constant
->constants
);
1947 constant
->constants
= NULL
;
1953 HRESULT WINAPI
D3DXGetShaderConstantTableEx(const DWORD
*byte_code
, DWORD flags
, ID3DXConstantTable
**constant_table
)
1955 struct ID3DXConstantTableImpl
*object
= NULL
;
1959 const D3DXSHADER_CONSTANTTABLE
*ctab_header
;
1960 const D3DXSHADER_CONSTANTINFO
*constant_info
;
1963 TRACE("byte_code %p, flags %x, constant_table %p\n", byte_code
, flags
, constant_table
);
1965 if (constant_table
) *constant_table
= NULL
;
1967 if (!byte_code
|| !constant_table
)
1969 WARN("Invalid argument specified.\n");
1970 return D3DERR_INVALIDCALL
;
1973 if (!is_valid_bytecode(*byte_code
))
1975 WARN("Invalid byte_code specified.\n");
1979 if (flags
) FIXME("Flags (%#x) are not handled, yet!\n", flags
);
1981 hr
= D3DXFindShaderComment(byte_code
, MAKEFOURCC('C','T','A','B'), &data
, &size
);
1984 WARN("CTAB not found.\n");
1985 return D3DXERR_INVALIDDATA
;
1988 if (size
< sizeof(*ctab_header
))
1990 WARN("Invalid CTAB size.\n");
1991 return D3DXERR_INVALIDDATA
;
1994 ctab_header
= (const D3DXSHADER_CONSTANTTABLE
*)data
;
1995 if (ctab_header
->Size
!= sizeof(*ctab_header
))
1997 WARN("Invalid D3DXSHADER_CONSTANTTABLE size.\n");
1998 return D3DXERR_INVALIDDATA
;
2001 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2003 return E_OUTOFMEMORY
;
2005 object
->ID3DXConstantTable_iface
.lpVtbl
= &ID3DXConstantTable_Vtbl
;
2008 object
->ctab
= HeapAlloc(GetProcessHeap(), 0, size
);
2011 ERR("Out of memory\n");
2012 HeapFree(GetProcessHeap(), 0, object
);
2013 return E_OUTOFMEMORY
;
2015 object
->size
= size
;
2016 memcpy(object
->ctab
, data
, object
->size
);
2018 object
->desc
.Creator
= ctab_header
->Creator
? object
->ctab
+ ctab_header
->Creator
: NULL
;
2019 object
->desc
.Version
= ctab_header
->Version
;
2020 object
->desc
.Constants
= ctab_header
->Constants
;
2021 TRACE("Creator %s, Version %x, Constants %u, Target %s\n",
2022 debugstr_a(object
->desc
.Creator
), object
->desc
.Version
, object
->desc
.Constants
,
2023 debugstr_a(ctab_header
->Target
? object
->ctab
+ ctab_header
->Target
: NULL
));
2025 object
->constants
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2026 sizeof(*object
->constants
) * object
->desc
.Constants
);
2027 if (!object
->constants
)
2029 ERR("Out of memory\n");
2034 constant_info
= (const D3DXSHADER_CONSTANTINFO
*)(object
->ctab
+ ctab_header
->ConstantInfo
);
2035 for (i
= 0; i
< ctab_header
->Constants
; i
++)
2037 DWORD offset
= constant_info
[i
].DefaultValue
;
2039 hr
= parse_ctab_constant_type(object
->ctab
, constant_info
[i
].TypeInfo
,
2040 &object
->constants
[i
], FALSE
, constant_info
[i
].RegisterIndex
,
2041 constant_info
[i
].RegisterIndex
+ constant_info
[i
].RegisterCount
,
2042 offset
? &offset
: NULL
, constant_info
[i
].Name
, constant_info
[i
].RegisterSet
);
2047 * Set the register count, it may differ for D3DXRS_INT4, because somehow
2048 * it makes the assumption that the register size is 1 instead of 4, so the
2049 * count is 4 times bigger. This holds true only for toplevel shader
2050 * constants. The count of elements and members is always based on a
2051 * register size of 4.
2053 if (object
->constants
[i
].desc
.RegisterSet
== D3DXRS_INT4
)
2055 object
->constants
[i
].desc
.RegisterCount
= constant_info
[i
].RegisterCount
;
2057 object
->constants
[i
].constantinfo_reserved
= constant_info
[i
].Reserved
;
2060 *constant_table
= &object
->ID3DXConstantTable_iface
;
2065 free_constant_table(object
);
2066 HeapFree(GetProcessHeap(), 0, object
);
2071 HRESULT WINAPI
D3DXGetShaderConstantTable(const DWORD
*byte_code
, ID3DXConstantTable
**constant_table
)
2073 TRACE("(%p, %p): Forwarded to D3DXGetShaderConstantTableEx\n", byte_code
, constant_table
);
2075 return D3DXGetShaderConstantTableEx(byte_code
, 0, constant_table
);
2078 HRESULT WINAPI
D3DXCreateFragmentLinker(IDirect3DDevice9
*device
, UINT size
, ID3DXFragmentLinker
**linker
)
2080 FIXME("device %p, size %u, linker %p: stub.\n", device
, size
, linker
);
2089 HRESULT WINAPI
D3DXCreateFragmentLinkerEx(IDirect3DDevice9
*device
, UINT size
, DWORD flags
, ID3DXFragmentLinker
**linker
)
2091 FIXME("device %p, size %u, flags %#x, linker %p: stub.\n", device
, size
, flags
, linker
);
2099 HRESULT WINAPI
D3DXGetShaderSamplers(const DWORD
*byte_code
, const char **samplers
, UINT
*count
)
2101 UINT i
, sampler_count
= 0;
2104 const D3DXSHADER_CONSTANTTABLE
*ctab_header
;
2105 const D3DXSHADER_CONSTANTINFO
*constant_info
;
2107 TRACE("byte_code %p, samplers %p, count %p\n", byte_code
, samplers
, count
);
2109 if (count
) *count
= 0;
2111 if (D3DXFindShaderComment(byte_code
, MAKEFOURCC('C','T','A','B'), (const void **)&data
, &size
) != D3D_OK
)
2114 if (size
< sizeof(*ctab_header
)) return D3D_OK
;
2116 ctab_header
= (const D3DXSHADER_CONSTANTTABLE
*)data
;
2117 if (ctab_header
->Size
!= sizeof(*ctab_header
)) return D3D_OK
;
2119 constant_info
= (const D3DXSHADER_CONSTANTINFO
*)(data
+ ctab_header
->ConstantInfo
);
2120 for (i
= 0; i
< ctab_header
->Constants
; i
++)
2122 const D3DXSHADER_TYPEINFO
*type
;
2124 TRACE("name = %s\n", data
+ constant_info
[i
].Name
);
2126 type
= (const D3DXSHADER_TYPEINFO
*)(data
+ constant_info
[i
].TypeInfo
);
2128 if (type
->Type
== D3DXPT_SAMPLER
2129 || type
->Type
== D3DXPT_SAMPLER1D
2130 || type
->Type
== D3DXPT_SAMPLER2D
2131 || type
->Type
== D3DXPT_SAMPLER3D
2132 || type
->Type
== D3DXPT_SAMPLERCUBE
)
2134 if (samplers
) samplers
[sampler_count
] = data
+ constant_info
[i
].Name
;
2140 TRACE("Found %u samplers\n", sampler_count
);
2142 if (count
) *count
= sampler_count
;
2147 HRESULT WINAPI
D3DXDisassembleShader(const DWORD
*shader
, BOOL colorcode
, const char *comments
, ID3DXBuffer
**disassembly
)
2149 FIXME("%p %d %s %p: stub\n", shader
, colorcode
, debugstr_a(comments
), disassembly
);
2150 return E_OUTOFMEMORY
;
2153 struct d3dx9_texture_shader
2155 ID3DXTextureShader ID3DXTextureShader_iface
;
2159 static inline struct d3dx9_texture_shader
*impl_from_ID3DXTextureShader(ID3DXTextureShader
*iface
)
2161 return CONTAINING_RECORD(iface
, struct d3dx9_texture_shader
, ID3DXTextureShader_iface
);
2164 static HRESULT WINAPI
d3dx9_texture_shader_QueryInterface(ID3DXTextureShader
*iface
, REFIID riid
, void **out
)
2166 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
2168 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
2169 IsEqualGUID(riid
, &IID_ID3DXTextureShader
))
2171 iface
->lpVtbl
->AddRef(iface
);
2176 WARN("Interface %s not found.\n", debugstr_guid(riid
));
2178 return E_NOINTERFACE
;
2181 static ULONG WINAPI
d3dx9_texture_shader_AddRef(ID3DXTextureShader
*iface
)
2183 struct d3dx9_texture_shader
*texture_shader
= impl_from_ID3DXTextureShader(iface
);
2184 ULONG refcount
= InterlockedIncrement(&texture_shader
->ref
);
2186 TRACE("%p increasing refcount to %u.\n", texture_shader
, refcount
);
2191 static ULONG WINAPI
d3dx9_texture_shader_Release(ID3DXTextureShader
*iface
)
2193 struct d3dx9_texture_shader
*texture_shader
= impl_from_ID3DXTextureShader(iface
);
2194 ULONG refcount
= InterlockedDecrement(&texture_shader
->ref
);
2196 TRACE("%p decreasing refcount to %u.\n", texture_shader
, refcount
);
2200 HeapFree(GetProcessHeap(), 0, texture_shader
);
2206 static HRESULT WINAPI
d3dx9_texture_shader_GetFunction(ID3DXTextureShader
*iface
, struct ID3DXBuffer
**function
)
2208 FIXME("iface %p, function %p stub.\n", iface
, function
);
2213 static HRESULT WINAPI
d3dx9_texture_shader_GetConstantBuffer(ID3DXTextureShader
*iface
, struct ID3DXBuffer
**constant_buffer
)
2215 FIXME("iface %p, constant_buffer %p stub.\n", iface
, constant_buffer
);
2220 static HRESULT WINAPI
d3dx9_texture_shader_GetDesc(ID3DXTextureShader
*iface
, D3DXCONSTANTTABLE_DESC
*desc
)
2222 FIXME("iface %p, desc %p stub.\n", iface
, desc
);
2227 static HRESULT WINAPI
d3dx9_texture_shader_GetConstantDesc(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, D3DXCONSTANT_DESC
*constant_desc
, UINT
*count
)
2229 FIXME("iface %p, constant %p, constant_desc %p, count %p stub.\n", iface
, constant
, constant_desc
, count
);
2234 static D3DXHANDLE WINAPI
d3dx9_texture_shader_GetConstant(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, UINT index
)
2236 FIXME("iface %p, constant %p, index %u stub.\n", iface
, constant
, index
);
2241 static D3DXHANDLE WINAPI
d3dx9_texture_shader_GetConstantByName(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const char *name
)
2243 FIXME("iface %p, constant %p, name %s stub.\n", iface
, constant
, debugstr_a(name
));
2248 static D3DXHANDLE WINAPI
d3dx9_texture_shader_GetConstantElement(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, UINT index
)
2250 FIXME("iface %p, constant %p, index %u stub.\n", iface
, constant
, index
);
2255 static HRESULT WINAPI
d3dx9_texture_shader_SetDefaults(ID3DXTextureShader
*iface
)
2257 FIXME("iface %p stub.\n", iface
);
2262 static HRESULT WINAPI
d3dx9_texture_shader_SetValue(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const void *data
, UINT bytes
)
2264 FIXME("iface %p, constant %p, data %p, bytes %u stub.\n", iface
, constant
, data
, bytes
);
2269 static HRESULT WINAPI
d3dx9_texture_shader_SetBool(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, BOOL b
)
2271 FIXME("iface %p, constant %p, b %u stub.\n", iface
, constant
, b
);
2276 static HRESULT WINAPI
d3dx9_texture_shader_SetBoolArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const BOOL
*b
, UINT count
)
2278 FIXME("iface %p, constant %p, b %p, count %u stub.\n", iface
, constant
, b
, count
);
2283 static HRESULT WINAPI
d3dx9_texture_shader_SetInt(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, INT n
)
2285 FIXME("iface %p, constant %p, n %d stub.\n", iface
, constant
, n
);
2290 static HRESULT WINAPI
d3dx9_texture_shader_SetIntArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const INT
*n
, UINT count
)
2292 FIXME("iface %p, constant %p, n %p, count %u stub.\n", iface
, constant
, n
, count
);
2297 static HRESULT WINAPI
d3dx9_texture_shader_SetFloat(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, FLOAT f
)
2299 FIXME("iface %p, constant %p, f %f stub.\n", iface
, constant
, f
);
2304 static HRESULT WINAPI
d3dx9_texture_shader_SetFloatArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const FLOAT
*f
, UINT count
)
2306 FIXME("iface %p, constant %p, f %p, count %u stub.\n", iface
, constant
, f
, count
);
2311 static HRESULT WINAPI
d3dx9_texture_shader_SetVector(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXVECTOR4
*vector
)
2313 FIXME("iface %p, constant %p, vector %p stub.\n", iface
, constant
, vector
);
2318 static HRESULT WINAPI
d3dx9_texture_shader_SetVectorArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXVECTOR4
*vector
, UINT count
)
2320 FIXME("iface %p, constant %p, vector %p, count %u stub.\n", iface
, constant
, vector
, count
);
2325 static HRESULT WINAPI
d3dx9_texture_shader_SetMatrix(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
)
2327 FIXME("iface %p, constant %p, matrix %p stub.\n", iface
, constant
, matrix
);
2332 static HRESULT WINAPI
d3dx9_texture_shader_SetMatrixArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
, UINT count
)
2334 FIXME("iface %p, constant %p, matrix %p, count %u stub.\n", iface
, constant
, matrix
, count
);
2339 static HRESULT WINAPI
d3dx9_texture_shader_SetMatrixPointerArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXMATRIX
**matrix
, UINT count
)
2341 FIXME("iface %p, constant %p, matrix %p, count %u stub.\n", iface
, constant
, matrix
, count
);
2346 static HRESULT WINAPI
d3dx9_texture_shader_SetMatrixTranspose(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
)
2348 FIXME("iface %p, constant %p, matrix %p stub.\n", iface
, constant
, matrix
);
2353 static HRESULT WINAPI
d3dx9_texture_shader_SetMatrixTransposeArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
, UINT count
)
2355 FIXME("iface %p, constant %p, matrix %p, count %u stub.\n", iface
, constant
, matrix
, count
);
2360 static HRESULT WINAPI
d3dx9_texture_shader_SetMatrixTransposePointerArray(ID3DXTextureShader
*iface
, D3DXHANDLE constant
, const D3DXMATRIX
**matrix
, UINT count
)
2362 FIXME("iface %p, constant %p, matrix %p, count %u stub.\n", iface
, constant
, matrix
, count
);
2367 static const struct ID3DXTextureShaderVtbl d3dx9_texture_shader_vtbl
=
2369 /*** IUnknown methods ***/
2370 d3dx9_texture_shader_QueryInterface
,
2371 d3dx9_texture_shader_AddRef
,
2372 d3dx9_texture_shader_Release
,
2373 /*** ID3DXTextureShader methods ***/
2374 d3dx9_texture_shader_GetFunction
,
2375 d3dx9_texture_shader_GetConstantBuffer
,
2376 d3dx9_texture_shader_GetDesc
,
2377 d3dx9_texture_shader_GetConstantDesc
,
2378 d3dx9_texture_shader_GetConstant
,
2379 d3dx9_texture_shader_GetConstantByName
,
2380 d3dx9_texture_shader_GetConstantElement
,
2381 d3dx9_texture_shader_SetDefaults
,
2382 d3dx9_texture_shader_SetValue
,
2383 d3dx9_texture_shader_SetBool
,
2384 d3dx9_texture_shader_SetBoolArray
,
2385 d3dx9_texture_shader_SetInt
,
2386 d3dx9_texture_shader_SetIntArray
,
2387 d3dx9_texture_shader_SetFloat
,
2388 d3dx9_texture_shader_SetFloatArray
,
2389 d3dx9_texture_shader_SetVector
,
2390 d3dx9_texture_shader_SetVectorArray
,
2391 d3dx9_texture_shader_SetMatrix
,
2392 d3dx9_texture_shader_SetMatrixArray
,
2393 d3dx9_texture_shader_SetMatrixPointerArray
,
2394 d3dx9_texture_shader_SetMatrixTranspose
,
2395 d3dx9_texture_shader_SetMatrixTransposeArray
,
2396 d3dx9_texture_shader_SetMatrixTransposePointerArray
2399 HRESULT WINAPI
D3DXCreateTextureShader(const DWORD
*function
, ID3DXTextureShader
**texture_shader
)
2401 struct d3dx9_texture_shader
*object
;
2403 TRACE("function %p, texture_shader %p.\n", function
, texture_shader
);
2405 if (!function
|| !texture_shader
)
2406 return D3DERR_INVALIDCALL
;
2408 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
2410 return E_OUTOFMEMORY
;
2412 object
->ID3DXTextureShader_iface
.lpVtbl
= &d3dx9_texture_shader_vtbl
;
2415 *texture_shader
= &object
->ID3DXTextureShader_iface
;