2 * Copyright 2008 Luis Busquets
3 * Copyright 2009 Matteo Bruni
4 * Copyright 2011 Travis Athougies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "d3dx9_36_private.h"
22 #include "d3dcompiler.h"
25 /* This function is not declared in the SDK headers yet. */
26 HRESULT WINAPI
D3DAssemble(const void *data
, SIZE_T datasize
, const char *filename
,
27 const D3D_SHADER_MACRO
*defines
, ID3DInclude
*include
, UINT flags
,
28 ID3DBlob
**shader
, ID3DBlob
**error_messages
);
30 static inline BOOL
is_valid_bytecode(DWORD token
)
32 return (token
& 0xfffe0000) == 0xfffe0000;
35 const char * WINAPI
D3DXGetPixelShaderProfile(struct IDirect3DDevice9
*device
)
39 TRACE("device %p\n", device
);
41 if (!device
) return NULL
;
43 IDirect3DDevice9_GetDeviceCaps(device
,&caps
);
45 switch (caps
.PixelShaderVersion
)
47 case D3DPS_VERSION(1, 1):
50 case D3DPS_VERSION(1, 2):
53 case D3DPS_VERSION(1, 3):
56 case D3DPS_VERSION(1, 4):
59 case D3DPS_VERSION(2, 0):
60 if ((caps
.PS20Caps
.NumTemps
>=22) &&
61 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_ARBITRARYSWIZZLE
) &&
62 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_GRADIENTINSTRUCTIONS
) &&
63 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_PREDICATION
) &&
64 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_NODEPENDENTREADLIMIT
) &&
65 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT
))
69 if ((caps
.PS20Caps
.NumTemps
>=32) &&
70 (caps
.PS20Caps
.Caps
&D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT
))
76 case D3DPS_VERSION(3, 0):
83 UINT WINAPI
D3DXGetShaderSize(const DWORD
*byte_code
)
85 const DWORD
*ptr
= byte_code
;
87 TRACE("byte_code %p\n", byte_code
);
91 /* Look for the END token, skipping the VERSION token */
92 while (*++ptr
!= D3DSIO_END
)
95 if ((*ptr
& D3DSI_OPCODE_MASK
) == D3DSIO_COMMENT
)
97 ptr
+= ((*ptr
& D3DSI_COMMENTSIZE_MASK
) >> D3DSI_COMMENTSIZE_SHIFT
);
102 /* Return the shader size in bytes */
103 return (ptr
- byte_code
) * sizeof(*ptr
);
106 DWORD WINAPI
D3DXGetShaderVersion(const DWORD
*byte_code
)
108 TRACE("byte_code %p\n", byte_code
);
110 return byte_code
? *byte_code
: 0;
113 const char * WINAPI
D3DXGetVertexShaderProfile(struct IDirect3DDevice9
*device
)
117 TRACE("device %p\n", device
);
119 if (!device
) return NULL
;
121 IDirect3DDevice9_GetDeviceCaps(device
,&caps
);
123 switch (caps
.VertexShaderVersion
)
125 case D3DVS_VERSION(1, 1):
127 case D3DVS_VERSION(2, 0):
128 if ((caps
.VS20Caps
.NumTemps
>=13) &&
129 (caps
.VS20Caps
.DynamicFlowControlDepth
==24) &&
130 (caps
.VS20Caps
.Caps
&D3DPS20CAPS_PREDICATION
))
135 case D3DVS_VERSION(3, 0):
142 HRESULT WINAPI
D3DXFindShaderComment(const DWORD
*byte_code
, DWORD fourcc
, const void **data
, UINT
*size
)
144 const DWORD
*ptr
= byte_code
;
147 TRACE("byte_code %p, fourcc %x, data %p, size %p\n", byte_code
, fourcc
, data
, size
);
149 if (data
) *data
= NULL
;
152 if (!byte_code
) return D3DERR_INVALIDCALL
;
154 version
= *ptr
>> 16;
155 if (version
!= 0x4658 /* FX */
156 && version
!= 0x5458 /* TX */
159 && version
!= 0xfffe /* VS */
160 && version
!= 0xffff) /* PS */
162 WARN("Invalid data supplied\n");
163 return D3DXERR_INVALIDDATA
;
166 while (*++ptr
!= D3DSIO_END
)
168 /* Check if it is a comment */
169 if ((*ptr
& D3DSI_OPCODE_MASK
) == D3DSIO_COMMENT
)
171 DWORD comment_size
= (*ptr
& D3DSI_COMMENTSIZE_MASK
) >> D3DSI_COMMENTSIZE_SHIFT
;
173 /* Check if this is the comment we are looking for */
174 if (*(ptr
+ 1) == fourcc
)
176 UINT ctab_size
= (comment_size
- 1) * sizeof(DWORD
);
177 const void *ctab_data
= ptr
+ 2;
182 TRACE("Returning comment data at %p with size %d\n", ctab_data
, ctab_size
);
192 HRESULT WINAPI
D3DXAssembleShader(const char *data
, UINT data_len
, const D3DXMACRO
*defines
,
193 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
197 TRACE("data %p, data_len %u, defines %p, include %p, flags %#x, shader %p, error_messages %p\n",
198 data
, data_len
, defines
, include
, flags
, shader
, error_messages
);
200 /* Forward to d3dcompiler: the parameter types aren't really different,
201 the actual data types are equivalent */
202 hr
= D3DAssemble(data
, data_len
, NULL
, (D3D_SHADER_MACRO
*)defines
,
203 (ID3DInclude
*)include
, flags
, (ID3DBlob
**)shader
,
204 (ID3DBlob
**)error_messages
);
206 if(hr
== E_FAIL
) hr
= D3DXERR_INVALIDDATA
;
210 static const void *main_file_data
;
212 static CRITICAL_SECTION from_file_mutex
;
213 static CRITICAL_SECTION_DEBUG from_file_mutex_debug
=
215 0, 0, &from_file_mutex
,
217 &from_file_mutex_debug
.ProcessLocksList
,
218 &from_file_mutex_debug
.ProcessLocksList
220 0, 0, {(DWORD_PTR
)(__FILE__
": from_file_mutex")}
222 static CRITICAL_SECTION from_file_mutex
= {&from_file_mutex_debug
, -1, 0, 0, 0, 0};
224 /* D3DXInclude private implementation, used to implement
225 * D3DXAssembleShaderFromFile() from D3DXAssembleShader(). */
226 /* To be able to correctly resolve include search paths we have to store the
227 * pathname of each include file. We store the pathname pointer right before
229 static HRESULT WINAPI
d3dincludefromfile_open(ID3DXInclude
*iface
, D3DXINCLUDE_TYPE include_type
,
230 const char *filename
, const void *parent_data
, const void **data
, UINT
*bytes
)
232 const char *p
, *parent_name
= "";
233 char *pathname
= NULL
, *ptr
;
234 char **buffer
= NULL
;
240 parent_name
= *((const char **)parent_data
- 1);
245 parent_name
= *((const char **)main_file_data
- 1);
248 TRACE("Looking up for include file %s, parent %s\n", debugstr_a(filename
), debugstr_a(parent_name
));
250 if ((p
= strrchr(parent_name
, '\\')))
254 pathname
= HeapAlloc(GetProcessHeap(), 0, (p
- parent_name
) + strlen(filename
) + 1);
256 return HRESULT_FROM_WIN32(GetLastError());
258 memcpy(pathname
, parent_name
, p
- parent_name
);
259 strcpy(pathname
+ (p
- parent_name
), filename
);
260 ptr
= pathname
+ (p
- parent_name
);
268 file
= CreateFileA(pathname
, GENERIC_READ
, FILE_SHARE_READ
, 0, OPEN_EXISTING
, 0, 0);
269 if(file
== INVALID_HANDLE_VALUE
)
272 TRACE("Include file found at pathname = %s\n", debugstr_a(pathname
));
274 size
= GetFileSize(file
, NULL
);
275 if(size
== INVALID_FILE_SIZE
)
278 buffer
= HeapAlloc(GetProcessHeap(), 0, size
+ sizeof(char *));
282 if(!ReadFile(file
, buffer
+ 1, size
, bytes
, NULL
))
287 main_file_data
= *data
;
294 HeapFree(GetProcessHeap(), 0, pathname
);
295 HeapFree(GetProcessHeap(), 0, buffer
);
296 return HRESULT_FROM_WIN32(GetLastError());
299 static HRESULT WINAPI
d3dincludefromfile_close(ID3DXInclude
*iface
, const void *data
)
301 HeapFree(GetProcessHeap(), 0, *((char **)data
- 1));
302 HeapFree(GetProcessHeap(), 0, (char **)data
- 1);
303 if (main_file_data
== data
)
304 main_file_data
= NULL
;
308 static const struct ID3DXIncludeVtbl D3DXInclude_Vtbl
= {
309 d3dincludefromfile_open
,
310 d3dincludefromfile_close
313 struct D3DXIncludeImpl
{
314 ID3DXInclude ID3DXInclude_iface
;
317 HRESULT WINAPI
D3DXAssembleShaderFromFileA(const char *filename
, const D3DXMACRO
*defines
,
318 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
324 TRACE("filename %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
325 debugstr_a(filename
), defines
, include
, flags
, shader
, error_messages
);
327 if (!filename
) return D3DXERR_INVALIDDATA
;
329 len
= MultiByteToWideChar(CP_ACP
, 0, filename
, -1, NULL
, 0);
330 filename_w
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
331 if (!filename_w
) return E_OUTOFMEMORY
;
332 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filename_w
, len
);
334 ret
= D3DXAssembleShaderFromFileW(filename_w
, defines
, include
, flags
, shader
, error_messages
);
336 HeapFree(GetProcessHeap(), 0, filename_w
);
340 HRESULT WINAPI
D3DXAssembleShaderFromFileW(const WCHAR
*filename
, const D3DXMACRO
*defines
,
341 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
346 struct D3DXIncludeImpl includefromfile
;
349 TRACE("filename %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
350 debugstr_w(filename
), defines
, include
, flags
, shader
, error_messages
);
354 includefromfile
.ID3DXInclude_iface
.lpVtbl
= &D3DXInclude_Vtbl
;
355 include
= &includefromfile
.ID3DXInclude_iface
;
358 len
= WideCharToMultiByte(CP_ACP
, 0, filename
, -1, NULL
, 0, NULL
, NULL
);
359 filename_a
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(char));
361 return E_OUTOFMEMORY
;
362 WideCharToMultiByte(CP_ACP
, 0, filename
, -1, filename_a
, len
, NULL
, NULL
);
364 EnterCriticalSection(&from_file_mutex
);
365 hr
= ID3DXInclude_Open(include
, D3D_INCLUDE_LOCAL
, filename_a
, NULL
, &buffer
, &len
);
368 LeaveCriticalSection(&from_file_mutex
);
369 HeapFree(GetProcessHeap(), 0, filename_a
);
370 return D3DXERR_INVALIDDATA
;
373 hr
= D3DXAssembleShader(buffer
, len
, defines
, include
, flags
, shader
, error_messages
);
375 ID3DXInclude_Close(include
, buffer
);
376 LeaveCriticalSection(&from_file_mutex
);
377 HeapFree(GetProcessHeap(), 0, filename_a
);
381 HRESULT WINAPI
D3DXAssembleShaderFromResourceA(HMODULE module
, const char *resource
, const D3DXMACRO
*defines
,
382 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
388 TRACE("module %p, resource %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
389 module
, debugstr_a(resource
), defines
, include
, flags
, shader
, error_messages
);
391 if (!(res
= FindResourceA(module
, resource
, (const char *)RT_RCDATA
)))
392 return D3DXERR_INVALIDDATA
;
393 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
394 return D3DXERR_INVALIDDATA
;
395 return D3DXAssembleShader(buffer
, len
, defines
, include
, flags
,
396 shader
, error_messages
);
399 HRESULT WINAPI
D3DXAssembleShaderFromResourceW(HMODULE module
, const WCHAR
*resource
, const D3DXMACRO
*defines
,
400 ID3DXInclude
*include
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
406 TRACE("module %p, resource %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
407 module
, debugstr_w(resource
), defines
, include
, flags
, shader
, error_messages
);
409 if (!(res
= FindResourceW(module
, resource
, (const WCHAR
*)RT_RCDATA
)))
410 return D3DXERR_INVALIDDATA
;
411 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
412 return D3DXERR_INVALIDDATA
;
413 return D3DXAssembleShader(buffer
, len
, defines
, include
, flags
,
414 shader
, error_messages
);
417 HRESULT WINAPI
D3DXCompileShader(const char *data
, UINT length
, const D3DXMACRO
*defines
,
418 ID3DXInclude
*include
, const char *function
, const char *profile
, DWORD flags
,
419 ID3DXBuffer
**shader
, ID3DXBuffer
**error_msgs
, ID3DXConstantTable
**constant_table
)
423 TRACE("data %s, length %u, defines %p, include %p, function %s, profile %s, "
424 "flags %#x, shader %p, error_msgs %p, constant_table %p.\n",
425 debugstr_a(data
), length
, defines
, include
, debugstr_a(function
), debugstr_a(profile
),
426 flags
, shader
, error_msgs
, constant_table
);
428 hr
= D3DCompile(data
, length
, NULL
, (D3D_SHADER_MACRO
*)defines
, (ID3DInclude
*)include
,
429 function
, profile
, flags
, 0, (ID3DBlob
**)shader
, (ID3DBlob
**)error_msgs
);
431 if (SUCCEEDED(hr
) && constant_table
)
433 hr
= D3DXGetShaderConstantTable(ID3DXBuffer_GetBufferPointer(*shader
), constant_table
);
436 ID3DXBuffer_Release(*shader
);
444 HRESULT WINAPI
D3DXCompileShaderFromFileA(const char *filename
, const D3DXMACRO
*defines
,
445 ID3DXInclude
*include
, const char *entrypoint
, const char *profile
, DWORD flags
,
446 ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
, ID3DXConstantTable
**constant_table
)
452 TRACE("filename %s, defines %p, include %p, entrypoint %s, profile %s, "
453 "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
454 debugstr_a(filename
), defines
, include
, debugstr_a(entrypoint
),
455 debugstr_a(profile
), flags
, shader
, error_messages
, constant_table
);
457 if (!filename
) return D3DXERR_INVALIDDATA
;
459 len
= MultiByteToWideChar(CP_ACP
, 0, filename
, -1, NULL
, 0);
460 filename_w
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
461 if (!filename_w
) return E_OUTOFMEMORY
;
462 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filename_w
, len
);
464 ret
= D3DXCompileShaderFromFileW(filename_w
, defines
, include
,
465 entrypoint
, profile
, flags
,
466 shader
, error_messages
, constant_table
);
468 HeapFree(GetProcessHeap(), 0, filename_w
);
472 HRESULT WINAPI
D3DXCompileShaderFromFileW(const WCHAR
*filename
, const D3DXMACRO
*defines
,
473 ID3DXInclude
*include
, const char *entrypoint
, const char *profile
, DWORD flags
,
474 ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
, ID3DXConstantTable
**constant_table
)
477 DWORD len
, filename_len
;
479 struct D3DXIncludeImpl includefromfile
;
482 TRACE("filename %s, defines %p, include %p, entrypoint %s, profile %s, "
483 "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
484 debugstr_w(filename
), defines
, include
, debugstr_a(entrypoint
), debugstr_a(profile
),
485 flags
, shader
, error_messages
, constant_table
);
489 includefromfile
.ID3DXInclude_iface
.lpVtbl
= &D3DXInclude_Vtbl
;
490 include
= &includefromfile
.ID3DXInclude_iface
;
493 filename_len
= WideCharToMultiByte(CP_ACP
, 0, filename
, -1, NULL
, 0, NULL
, NULL
);
494 filename_a
= HeapAlloc(GetProcessHeap(), 0, filename_len
* sizeof(char));
496 return E_OUTOFMEMORY
;
497 WideCharToMultiByte(CP_ACP
, 0, filename
, -1, filename_a
, filename_len
, NULL
, NULL
);
499 EnterCriticalSection(&from_file_mutex
);
500 hr
= ID3DXInclude_Open(include
, D3D_INCLUDE_LOCAL
, filename_a
, NULL
, &buffer
, &len
);
503 LeaveCriticalSection(&from_file_mutex
);
504 HeapFree(GetProcessHeap(), 0, filename_a
);
505 return D3DXERR_INVALIDDATA
;
508 hr
= D3DCompile(buffer
, len
, filename_a
, (const D3D_SHADER_MACRO
*)defines
,
509 (ID3DInclude
*)include
, entrypoint
, profile
, flags
, 0,
510 (ID3DBlob
**)shader
, (ID3DBlob
**)error_messages
);
512 if (SUCCEEDED(hr
) && constant_table
)
513 hr
= D3DXGetShaderConstantTable(ID3DXBuffer_GetBufferPointer(*shader
),
516 ID3DXInclude_Close(include
, buffer
);
517 LeaveCriticalSection(&from_file_mutex
);
518 HeapFree(GetProcessHeap(), 0, filename_a
);
522 HRESULT WINAPI
D3DXCompileShaderFromResourceA(HMODULE module
, const char *resource
, const D3DXMACRO
*defines
,
523 ID3DXInclude
*include
, const char *entrypoint
, const char *profile
, DWORD flags
,
524 ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
, ID3DXConstantTable
**constant_table
)
530 TRACE("module %p, resource %s, defines %p, include %p, entrypoint %s, profile %s, "
531 "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
532 module
, debugstr_a(resource
), defines
, include
, debugstr_a(entrypoint
), debugstr_a(profile
),
533 flags
, shader
, error_messages
, constant_table
);
535 if (!(res
= FindResourceA(module
, resource
, (const char *)RT_RCDATA
)))
536 return D3DXERR_INVALIDDATA
;
537 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
538 return D3DXERR_INVALIDDATA
;
539 return D3DXCompileShader(buffer
, len
, defines
, include
, entrypoint
, profile
,
540 flags
, shader
, error_messages
, constant_table
);
543 HRESULT WINAPI
D3DXCompileShaderFromResourceW(HMODULE module
, const WCHAR
*resource
, const D3DXMACRO
*defines
,
544 ID3DXInclude
*include
, const char *entrypoint
, const char *profile
, DWORD flags
,
545 ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
, ID3DXConstantTable
**constant_table
)
551 TRACE("module %p, resource %s, defines %p, include %p, entrypoint %s, profile %s, "
552 "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
553 module
, debugstr_w(resource
), defines
, include
, debugstr_a(entrypoint
), debugstr_a(profile
),
554 flags
, shader
, error_messages
, constant_table
);
556 if (!(res
= FindResourceW(module
, resource
, (const WCHAR
*)RT_RCDATA
)))
557 return D3DXERR_INVALIDDATA
;
558 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
559 return D3DXERR_INVALIDDATA
;
560 return D3DXCompileShader(buffer
, len
, defines
, include
, entrypoint
, profile
,
561 flags
, shader
, error_messages
, constant_table
);
564 HRESULT WINAPI
D3DXPreprocessShader(const char *data
, UINT data_len
, const D3DXMACRO
*defines
,
565 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
567 TRACE("data %s, data_len %u, defines %p, include %p, shader %p, error_messages %p.\n",
568 debugstr_a(data
), data_len
, defines
, include
, shader
, error_messages
);
570 return D3DPreprocess(data
, data_len
, NULL
,
571 (const D3D_SHADER_MACRO
*)defines
, (ID3DInclude
*)include
,
572 (ID3DBlob
**)shader
, (ID3DBlob
**)error_messages
);
575 HRESULT WINAPI
D3DXPreprocessShaderFromFileA(const char *filename
, const D3DXMACRO
*defines
,
576 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
578 WCHAR
*filename_w
= NULL
;
582 TRACE("filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
583 debugstr_a(filename
), defines
, include
, shader
, error_messages
);
585 if (!filename
) return D3DXERR_INVALIDDATA
;
587 len
= MultiByteToWideChar(CP_ACP
, 0, filename
, -1, NULL
, 0);
588 filename_w
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
589 if (!filename_w
) return E_OUTOFMEMORY
;
590 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filename_w
, len
);
592 ret
= D3DXPreprocessShaderFromFileW(filename_w
, defines
, include
, shader
, error_messages
);
594 HeapFree(GetProcessHeap(), 0, filename_w
);
598 HRESULT WINAPI
D3DXPreprocessShaderFromFileW(const WCHAR
*filename
, const D3DXMACRO
*defines
,
599 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
604 struct D3DXIncludeImpl includefromfile
;
607 TRACE("filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
608 debugstr_w(filename
), defines
, include
, shader
, error_messages
);
612 includefromfile
.ID3DXInclude_iface
.lpVtbl
= &D3DXInclude_Vtbl
;
613 include
= &includefromfile
.ID3DXInclude_iface
;
616 len
= WideCharToMultiByte(CP_ACP
, 0, filename
, -1, NULL
, 0, NULL
, NULL
);
617 filename_a
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(char));
619 return E_OUTOFMEMORY
;
620 WideCharToMultiByte(CP_ACP
, 0, filename
, -1, filename_a
, len
, NULL
, NULL
);
622 EnterCriticalSection(&from_file_mutex
);
623 hr
= ID3DXInclude_Open(include
, D3D_INCLUDE_LOCAL
, filename_a
, NULL
, &buffer
, &len
);
626 LeaveCriticalSection(&from_file_mutex
);
627 HeapFree(GetProcessHeap(), 0, filename_a
);
628 return D3DXERR_INVALIDDATA
;
631 hr
= D3DPreprocess(buffer
, len
, NULL
,
632 (const D3D_SHADER_MACRO
*)defines
,
633 (ID3DInclude
*) include
,
634 (ID3DBlob
**)shader
, (ID3DBlob
**)error_messages
);
636 ID3DXInclude_Close(include
, buffer
);
637 LeaveCriticalSection(&from_file_mutex
);
638 HeapFree(GetProcessHeap(), 0, filename_a
);
642 HRESULT WINAPI
D3DXPreprocessShaderFromResourceA(HMODULE module
, const char *resource
, const D3DXMACRO
*defines
,
643 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
649 TRACE("module %p, resource %s, defines %p, include %p, shader %p, error_messages %p.\n",
650 module
, debugstr_a(resource
), defines
, include
, shader
, error_messages
);
652 if (!(res
= FindResourceA(module
, resource
, (const char *)RT_RCDATA
)))
653 return D3DXERR_INVALIDDATA
;
654 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
655 return D3DXERR_INVALIDDATA
;
656 return D3DXPreprocessShader(buffer
, len
, defines
, include
,
657 shader
, error_messages
);
660 HRESULT WINAPI
D3DXPreprocessShaderFromResourceW(HMODULE module
, const WCHAR
*resource
, const D3DXMACRO
*defines
,
661 ID3DXInclude
*include
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_messages
)
667 TRACE("module %p, resource %s, defines %p, include %p, shader %p, error_messages %p.\n",
668 module
, debugstr_w(resource
), defines
, include
, shader
, error_messages
);
670 if (!(res
= FindResourceW(module
, resource
, (const WCHAR
*)RT_RCDATA
)))
671 return D3DXERR_INVALIDDATA
;
672 if (FAILED(load_resource_into_memory(module
, res
, &buffer
, &len
)))
673 return D3DXERR_INVALIDDATA
;
674 return D3DXPreprocessShader(buffer
, len
, defines
, include
,
675 shader
, error_messages
);
679 struct ctab_constant
{
680 D3DXCONSTANT_DESC desc
;
681 struct ctab_constant
*constants
;
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 static HRESULT WINAPI
ID3DXConstantTableImpl_GetConstantDesc(ID3DXConstantTable
*iface
, D3DXHANDLE constant
,
945 D3DXCONSTANT_DESC
*desc
, UINT
*count
)
947 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
948 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
950 TRACE("(%p)->(%p, %p, %p)\n", This
, constant
, desc
, count
);
954 WARN("Invalid argument specified\n");
955 return D3DERR_INVALIDCALL
;
958 if (desc
) *desc
= c
->desc
;
959 if (count
) *count
= 1;
964 static UINT WINAPI
ID3DXConstantTableImpl_GetSamplerIndex(ID3DXConstantTable
*iface
, D3DXHANDLE constant
)
966 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
967 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
969 TRACE("(%p)->(%p)\n", This
, constant
);
971 if (!c
|| c
->desc
.RegisterSet
!= D3DXRS_SAMPLER
)
973 WARN("Invalid argument specified\n");
977 TRACE("Returning RegisterIndex %u\n", c
->desc
.RegisterIndex
);
978 return c
->desc
.RegisterIndex
;
981 static D3DXHANDLE WINAPI
ID3DXConstantTableImpl_GetConstant(ID3DXConstantTable
*iface
, D3DXHANDLE constant
, UINT index
)
983 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
984 struct ctab_constant
*c
;
986 TRACE("(%p)->(%p, %d)\n", This
, constant
, index
);
990 c
= get_valid_constant(This
, constant
);
991 if (c
&& index
< c
->desc
.StructMembers
)
993 c
= &c
->constants
[index
];
994 TRACE("Returning constant %p\n", c
);
995 return handle_from_constant(c
);
1000 if (index
< This
->desc
.Constants
)
1002 c
= &This
->constants
[index
];
1003 TRACE("Returning constant %p\n", c
);
1004 return handle_from_constant(c
);
1008 WARN("Index out of range\n");
1012 static D3DXHANDLE WINAPI
ID3DXConstantTableImpl_GetConstantByName(ID3DXConstantTable
*iface
,
1013 D3DXHANDLE constant
, const char *name
)
1015 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1016 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
1018 TRACE("iface %p, constant %p, name %s.\n", iface
, constant
, debugstr_a(name
));
1020 c
= get_constant_by_name(This
, c
, name
);
1021 TRACE("Returning constant %p\n", c
);
1023 return handle_from_constant(c
);
1026 static D3DXHANDLE WINAPI
ID3DXConstantTableImpl_GetConstantElement(ID3DXConstantTable
*iface
, D3DXHANDLE constant
, UINT index
)
1028 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1029 struct ctab_constant
*c
= get_valid_constant(This
, constant
);
1031 TRACE("(%p)->(%p, %d)\n", This
, constant
, index
);
1033 if (c
&& index
< c
->desc
.Elements
)
1035 if (c
->desc
.Elements
> 1) c
= &c
->constants
[index
];
1036 TRACE("Returning constant %p\n", c
);
1037 return handle_from_constant(c
);
1040 WARN("Invalid argument specified\n");
1044 static inline DWORD
get_index(const void **indata
, UINT index
, BOOL is_pointer
)
1050 return ((DWORD
**)indata
)[index
/ 16][index
% 16];
1052 return (*((DWORD
**)indata
))[index
];
1055 static UINT
set(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, struct ctab_constant
*constant
,
1056 const void **indata
, D3DXPARAMETER_TYPE intype
, UINT
*size
, UINT incol
, D3DXPARAMETER_CLASS inclass
, UINT index
,
1059 D3DXCONSTANT_DESC
*desc
= &constant
->desc
;
1060 UINT l
, i
, regcount
= 1, regsize
= 1, cin
= 1, rin
= 1, ret
, last
= 0;
1063 /* size too small to set anything */
1064 if (*size
< desc
->Rows
* desc
->Columns
)
1070 /* D3DXPC_STRUCT is somewhat special */
1071 if (desc
->Class
== D3DXPC_STRUCT
)
1074 * Struct array sets the last complete input to the first struct element, all other
1075 * elements are not set.
1076 * E.g.: struct {int i;} s1[2];
1077 * SetValue(device, "s1", [1, 2], 8) => s1 = {2, x};
1079 * struct {int i; int n} s2[2];
1080 * SetValue(device, "s2", [1, 2, 3, 4, 5], 20) => s1 = {{3, 4}, {x, x}};
1082 if (desc
->Elements
> 1)
1084 UINT offset
= *size
/ (desc
->Rows
* desc
->Columns
) - 1;
1086 offset
= min(desc
->Elements
- 1, offset
);
1087 last
= offset
* desc
->Rows
* desc
->Columns
;
1089 if ((is_pointer
|| (!is_pointer
&& inclass
== D3DXPC_MATRIX_ROWS
)) && desc
->RegisterSet
!= D3DXRS_BOOL
)
1091 set(table
, device
, &constant
->constants
[0], NULL
, intype
, size
, incol
, inclass
, 0, is_pointer
);
1095 last
+= set(table
, device
, &constant
->constants
[0], indata
, intype
, size
, incol
, inclass
,
1096 index
+ last
, is_pointer
);
1102 * D3DXRS_BOOL is always set. As there are only 16 bools and there are
1103 * exactly 16 input values, use matrix transpose.
1105 if (inclass
== D3DXPC_MATRIX_ROWS
&& desc
->RegisterSet
== D3DXRS_BOOL
)
1107 D3DXMATRIX mat
, *m
, min
;
1108 D3DXMatrixTranspose(&mat
, &min
);
1111 min
= *(D3DXMATRIX
*)(indata
[index
/ 16]);
1113 min
= **(D3DXMATRIX
**)indata
;
1115 D3DXMatrixTranspose(&mat
, &min
);
1117 for (i
= 0; i
< desc
->StructMembers
; ++i
)
1119 last
+= set(table
, device
, &constant
->constants
[i
], (const void **)&m
, intype
, size
, incol
,
1120 D3DXPC_SCALAR
, index
+ last
, is_pointer
);
1124 * For pointers or for matrix rows, only the first member is set.
1125 * All other members are set to 0. This is not true for D3DXRS_BOOL.
1126 * E.g.: struct {int i; int n} s;
1127 * SetValue(device, "s", [1, 2], 8) => s = {1, 0};
1129 else if ((is_pointer
|| (!is_pointer
&& inclass
== D3DXPC_MATRIX_ROWS
)) && desc
->RegisterSet
!= D3DXRS_BOOL
)
1131 last
= set(table
, device
, &constant
->constants
[0], indata
, intype
, size
, incol
, inclass
,
1132 index
+ last
, is_pointer
);
1134 for (i
= 1; i
< desc
->StructMembers
; ++i
)
1136 set(table
, device
, &constant
->constants
[i
], NULL
, intype
, size
, incol
, inclass
, 0, is_pointer
);
1141 for (i
= 0; i
< desc
->StructMembers
; ++i
)
1143 last
+= set(table
, device
, &constant
->constants
[i
], indata
, intype
, size
, incol
, D3DXPC_SCALAR
,
1144 index
+ last
, is_pointer
);
1153 if (desc
->Elements
> 1)
1155 for (i
= 0; i
< desc
->Elements
&& *size
> 0; ++i
)
1157 last
+= set(table
, device
, &constant
->constants
[i
], indata
, intype
, size
, incol
, inclass
,
1158 index
+ last
, is_pointer
);
1160 /* adjust the vector size for matrix rows */
1161 if (inclass
== D3DXPC_MATRIX_ROWS
&& desc
->Class
== D3DXPC_VECTOR
&& (i
% 4) == 3)
1164 *size
= *size
< 12 ? 0 : *size
- 12;
1171 switch (desc
->Class
)
1175 case D3DXPC_MATRIX_ROWS
:
1176 regcount
= min(desc
->RegisterCount
, desc
->Rows
);
1177 if (inclass
== D3DXPC_MATRIX_ROWS
) cin
= incol
;
1179 regsize
= desc
->Columns
;
1182 case D3DXPC_MATRIX_COLUMNS
:
1183 regcount
= min(desc
->RegisterCount
, desc
->Columns
);
1184 if (inclass
== D3DXPC_MATRIX_ROWS
) rin
= incol
;
1186 regsize
= desc
->Rows
;
1190 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1194 /* specific stuff for different in types */
1198 ret
= desc
->Columns
* desc
->Rows
;
1199 *size
-= desc
->Columns
* desc
->Rows
;
1203 switch (desc
->Class
)
1205 case D3DXPC_MATRIX_ROWS
:
1206 if (*size
< regcount
* 4)
1212 *size
-= 4 * regcount
;
1215 case D3DXPC_MATRIX_COLUMNS
:
1217 *size
-= 4 * regcount
;
1231 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1236 case D3DXPC_MATRIX_ROWS
:
1237 switch (desc
->Class
)
1239 case D3DXPC_MATRIX_ROWS
:
1240 case D3DXPC_MATRIX_COLUMNS
:
1258 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1264 case D3DXPC_MATRIX_COLUMNS
:
1265 switch (desc
->Class
)
1267 case D3DXPC_MATRIX_ROWS
:
1268 case D3DXPC_MATRIX_COLUMNS
:
1286 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc
->Class
));
1293 FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(inclass
));
1297 /* set the registers */
1298 switch (desc
->RegisterSet
)
1301 regcount
= min(desc
->RegisterCount
, desc
->Columns
* desc
->Rows
);
1303 for (i
= 0; i
< regcount
; ++i
)
1306 DWORD t
= get_index(indata
, index
+ i
/ regsize
* rin
+ l
* cin
, is_pointer
);
1308 set_number(&tmp
, desc
->Type
, &t
, intype
);
1309 set_number(&out
, D3DXPT_BOOL
, &tmp
, desc
->Type
);
1310 if (is_vertex_shader(table
->desc
.Version
))
1311 IDirect3DDevice9_SetVertexShaderConstantB(device
, desc
->RegisterIndex
+ i
, &out
, 1);
1313 IDirect3DDevice9_SetPixelShaderConstantB(device
, desc
->RegisterIndex
+ i
, &out
, 1);
1315 if (++l
>= regsize
) l
= 0;
1320 for (i
= 0; i
< regcount
; ++i
)
1322 INT vec
[4] = {0, 0, 1, 0};
1324 for (l
= 0; l
< regsize
; ++l
)
1326 DWORD t
= get_index(indata
, index
+ i
* rin
+ l
* cin
, is_pointer
);
1328 set_number(&tmp
, desc
->Type
, &t
, intype
);
1329 set_number(&vec
[l
], D3DXPT_INT
, &tmp
, desc
->Type
);
1331 if (is_vertex_shader(table
->desc
.Version
))
1332 IDirect3DDevice9_SetVertexShaderConstantI(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1334 IDirect3DDevice9_SetPixelShaderConstantI(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1339 for (i
= 0; i
< regcount
; ++i
)
1343 for (l
= 0; l
< regsize
; ++l
)
1345 DWORD t
= get_index(indata
, index
+ i
* rin
+ l
* cin
, is_pointer
);
1347 set_number(&tmp
, desc
->Type
, &t
, intype
);
1348 set_number(&vec
[l
], D3DXPT_FLOAT
, &tmp
, desc
->Type
);
1350 if (is_vertex_shader(table
->desc
.Version
))
1351 IDirect3DDevice9_SetVertexShaderConstantF(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1353 IDirect3DDevice9_SetPixelShaderConstantF(device
, desc
->RegisterIndex
+ i
, vec
, 1);
1358 FIXME("Unhandled register set %s\n", debug_d3dxparameter_registerset(desc
->RegisterSet
));
1363 static HRESULT
set_scalar(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1364 const void *indata
, D3DXPARAMETER_TYPE intype
)
1366 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1371 WARN("Invalid argument specified\n");
1372 return D3DERR_INVALIDCALL
;
1375 switch (c
->desc
.Class
)
1378 set(table
, device
, c
, &indata
, intype
, &count
, c
->desc
.Columns
, D3DXPC_SCALAR
, 0, FALSE
);
1382 case D3DXPC_MATRIX_ROWS
:
1383 case D3DXPC_MATRIX_COLUMNS
:
1388 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1389 return D3DERR_INVALIDCALL
;
1393 static HRESULT
set_scalar_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1394 const void *indata
, UINT count
, D3DXPARAMETER_TYPE intype
)
1396 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1400 WARN("Invalid argument specified\n");
1401 return D3DERR_INVALIDCALL
;
1404 switch (c
->desc
.Class
)
1408 case D3DXPC_MATRIX_ROWS
:
1409 case D3DXPC_MATRIX_COLUMNS
:
1411 set(table
, device
, c
, &indata
, intype
, &count
, c
->desc
.Columns
, D3DXPC_SCALAR
, 0, FALSE
);
1415 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1416 return D3DERR_INVALIDCALL
;
1420 static HRESULT
set_vector(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1421 const void *indata
, D3DXPARAMETER_TYPE intype
)
1423 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1428 WARN("Invalid argument specified\n");
1429 return D3DERR_INVALIDCALL
;
1432 switch (c
->desc
.Class
)
1437 set(table
, device
, c
, &indata
, intype
, &count
, 4, D3DXPC_VECTOR
, 0, FALSE
);
1440 case D3DXPC_MATRIX_ROWS
:
1441 case D3DXPC_MATRIX_COLUMNS
:
1445 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1446 return D3DERR_INVALIDCALL
;
1450 static HRESULT
set_vector_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1451 const void *indata
, UINT count
, D3DXPARAMETER_TYPE intype
)
1453 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1457 WARN("Invalid argument specified\n");
1458 return D3DERR_INVALIDCALL
;
1461 switch (c
->desc
.Class
)
1465 case D3DXPC_MATRIX_ROWS
:
1466 case D3DXPC_MATRIX_COLUMNS
:
1469 set(table
, device
, c
, &indata
, intype
, &count
, 4, D3DXPC_VECTOR
, 0, FALSE
);
1473 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1474 return D3DERR_INVALIDCALL
;
1478 static HRESULT
set_matrix_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
, D3DXHANDLE constant
,
1479 const void *indata
, UINT count
, BOOL transpose
)
1481 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1485 WARN("Invalid argument specified\n");
1486 return D3DERR_INVALIDCALL
;
1489 switch (c
->desc
.Class
)
1493 case D3DXPC_MATRIX_ROWS
:
1494 case D3DXPC_MATRIX_COLUMNS
:
1497 set(table
, device
, c
, &indata
, D3DXPT_FLOAT
, &count
, 4,
1498 transpose
? D3DXPC_MATRIX_ROWS
: D3DXPC_MATRIX_COLUMNS
, 0, FALSE
);
1502 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1503 return D3DERR_INVALIDCALL
;
1507 static HRESULT
set_matrix_pointer_array(struct ID3DXConstantTableImpl
*table
, IDirect3DDevice9
*device
,
1508 D3DXHANDLE constant
, const void **indata
, UINT count
, BOOL transpose
)
1510 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1514 WARN("Invalid argument specified\n");
1515 return D3DERR_INVALIDCALL
;
1518 switch (c
->desc
.Class
)
1522 case D3DXPC_MATRIX_ROWS
:
1523 case D3DXPC_MATRIX_COLUMNS
:
1526 set(table
, device
, c
, indata
, D3DXPT_FLOAT
, &count
, 4,
1527 transpose
? D3DXPC_MATRIX_ROWS
: D3DXPC_MATRIX_COLUMNS
, 0, TRUE
);
1531 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c
->desc
.Class
));
1532 return D3DERR_INVALIDCALL
;
1536 static HRESULT WINAPI
ID3DXConstantTableImpl_SetDefaults(struct ID3DXConstantTable
*iface
,
1537 struct IDirect3DDevice9
*device
)
1539 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1542 TRACE("iface %p, device %p\n", iface
, device
);
1546 WARN("Invalid argument specified\n");
1547 return D3DERR_INVALIDCALL
;
1550 for (i
= 0; i
< This
->desc
.Constants
; i
++)
1552 D3DXCONSTANT_DESC
*desc
= &This
->constants
[i
].desc
;
1555 if (!desc
->DefaultValue
)
1558 switch (desc
->RegisterSet
)
1561 if (is_vertex_shader(This
->desc
.Version
))
1562 hr
= IDirect3DDevice9_SetVertexShaderConstantB(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1563 desc
->RegisterCount
);
1565 hr
= IDirect3DDevice9_SetPixelShaderConstantB(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1566 desc
->RegisterCount
);
1570 if (is_vertex_shader(This
->desc
.Version
))
1571 hr
= IDirect3DDevice9_SetVertexShaderConstantI(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1572 desc
->RegisterCount
);
1574 hr
= IDirect3DDevice9_SetPixelShaderConstantI(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1575 desc
->RegisterCount
);
1579 if (is_vertex_shader(This
->desc
.Version
))
1580 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1581 desc
->RegisterCount
);
1583 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, desc
->RegisterIndex
, desc
->DefaultValue
,
1584 desc
->RegisterCount
);
1588 FIXME("Unhandled register set %s\n", debug_d3dxparameter_registerset(desc
->RegisterSet
));
1600 static HRESULT WINAPI
ID3DXConstantTableImpl_SetValue(struct ID3DXConstantTable
*iface
,
1601 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const void *data
, unsigned int bytes
)
1603 struct ID3DXConstantTableImpl
*table
= impl_from_ID3DXConstantTable(iface
);
1604 struct ctab_constant
*c
= get_valid_constant(table
, constant
);
1605 D3DXCONSTANT_DESC
*desc
;
1607 TRACE("iface %p, device %p, constant %p, data %p, bytes %u\n", iface
, device
, constant
, data
, bytes
);
1609 if (!device
|| !c
|| !data
)
1611 WARN("Invalid argument specified\n");
1612 return D3DERR_INVALIDCALL
;
1617 switch (desc
->Class
)
1621 case D3DXPC_MATRIX_ROWS
:
1622 case D3DXPC_MATRIX_COLUMNS
:
1625 set(table
, device
, c
, &data
, desc
->Type
, &bytes
, desc
->Columns
, D3DXPC_SCALAR
, 0, FALSE
);
1629 FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(desc
->Class
));
1630 return D3DERR_INVALIDCALL
;
1634 static HRESULT WINAPI
ID3DXConstantTableImpl_SetBool(struct ID3DXConstantTable
*iface
,
1635 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, BOOL b
)
1637 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1639 TRACE("iface %p, device %p, constant %p, b %d\n", iface
, device
, constant
, b
);
1641 return set_scalar(This
, device
, constant
, &b
, D3DXPT_BOOL
);
1644 static HRESULT WINAPI
ID3DXConstantTableImpl_SetBoolArray(struct ID3DXConstantTable
*iface
,
1645 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const BOOL
*b
, UINT count
)
1647 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1649 TRACE("iface %p, device %p, constant %p, b %p, count %d\n", iface
, device
, constant
, b
, count
);
1651 return set_scalar_array(This
, device
, constant
, b
, count
, D3DXPT_BOOL
);
1654 static HRESULT WINAPI
ID3DXConstantTableImpl_SetInt(struct ID3DXConstantTable
*iface
,
1655 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, INT n
)
1657 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1659 TRACE("iface %p, device %p, constant %p, n %d\n", iface
, device
, constant
, n
);
1661 return set_scalar(This
, device
, constant
, &n
, D3DXPT_INT
);
1664 static HRESULT WINAPI
ID3DXConstantTableImpl_SetIntArray(struct ID3DXConstantTable
*iface
,
1665 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const INT
*n
, UINT count
)
1667 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1669 TRACE("iface %p, device %p, constant %p, n %p, count %d\n", iface
, device
, constant
, n
, count
);
1671 return set_scalar_array(This
, device
, constant
, n
, count
, D3DXPT_INT
);
1674 static HRESULT WINAPI
ID3DXConstantTableImpl_SetFloat(struct ID3DXConstantTable
*iface
,
1675 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, float f
)
1677 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1679 TRACE("iface %p, device %p, constant %p, f %f\n", iface
, device
, constant
, f
);
1681 return set_scalar(This
, device
, constant
, &f
, D3DXPT_FLOAT
);
1684 static HRESULT WINAPI
ID3DXConstantTableImpl_SetFloatArray(struct ID3DXConstantTable
*iface
,
1685 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const float *f
, UINT count
)
1687 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1689 TRACE("iface %p, device %p, constant %p, f %p, count %d\n", iface
, device
, constant
, f
, count
);
1691 return set_scalar_array(This
, device
, constant
, f
, count
, D3DXPT_FLOAT
);
1694 static HRESULT WINAPI
ID3DXConstantTableImpl_SetVector(struct ID3DXConstantTable
*iface
,
1695 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXVECTOR4
*vector
)
1697 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1699 TRACE("iface %p, device %p, constant %p, vector %p\n", iface
, device
, constant
, vector
);
1701 return set_vector(This
, device
, constant
, vector
, D3DXPT_FLOAT
);
1704 static HRESULT WINAPI
ID3DXConstantTableImpl_SetVectorArray(struct ID3DXConstantTable
*iface
,
1705 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXVECTOR4
*vector
, UINT count
)
1707 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1709 TRACE("iface %p, device %p, constant %p, vector %p, count %u\n", iface
, device
, constant
, vector
, count
);
1711 return set_vector_array(This
, device
, constant
, vector
, count
, D3DXPT_FLOAT
);
1714 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrix(struct ID3DXConstantTable
*iface
,
1715 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
)
1717 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1719 TRACE("iface %p, device %p, constant %p, matrix %p\n", iface
, device
, constant
, matrix
);
1721 return set_matrix_array(This
, device
, constant
, matrix
, 1, FALSE
);
1724 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixArray(struct ID3DXConstantTable
*iface
,
1725 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
, UINT count
)
1727 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1729 TRACE("iface %p, device %p, constant %p, matrix %p, count %u\n", iface
, device
, constant
, matrix
, count
);
1731 return set_matrix_array(This
, device
, constant
, matrix
, count
, FALSE
);
1734 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixPointerArray(struct ID3DXConstantTable
*iface
,
1735 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
**matrix
, UINT count
)
1737 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1739 TRACE("iface %p, device %p, constant %p, matrix %p, count %u)\n", iface
, device
, constant
, matrix
, count
);
1741 return set_matrix_pointer_array(This
, device
, constant
, (const void **)matrix
, count
, FALSE
);
1744 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixTranspose(struct ID3DXConstantTable
*iface
,
1745 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
)
1747 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1749 TRACE("iface %p, device %p, constant %p, matrix %p\n", iface
, device
, constant
, matrix
);
1751 return set_matrix_array(This
, device
, constant
, matrix
, 1, TRUE
);
1754 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixTransposeArray(struct ID3DXConstantTable
*iface
,
1755 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
*matrix
, UINT count
)
1757 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1759 TRACE("iface %p, device %p, constant %p, matrix %p, count %u\n", iface
, device
, constant
, matrix
, count
);
1761 return set_matrix_array(This
, device
, constant
, matrix
, count
, TRUE
);
1764 static HRESULT WINAPI
ID3DXConstantTableImpl_SetMatrixTransposePointerArray(struct ID3DXConstantTable
*iface
,
1765 struct IDirect3DDevice9
*device
, D3DXHANDLE constant
, const D3DXMATRIX
**matrix
, UINT count
)
1767 struct ID3DXConstantTableImpl
*This
= impl_from_ID3DXConstantTable(iface
);
1769 TRACE("iface %p, device %p, constant %p, matrix %p, count %u)\n", iface
, device
, constant
, matrix
, count
);
1771 return set_matrix_pointer_array(This
, device
, constant
, (const void **)matrix
, count
, TRUE
);
1774 static const struct ID3DXConstantTableVtbl ID3DXConstantTable_Vtbl
=
1776 /*** IUnknown methods ***/
1777 ID3DXConstantTableImpl_QueryInterface
,
1778 ID3DXConstantTableImpl_AddRef
,
1779 ID3DXConstantTableImpl_Release
,
1780 /*** ID3DXBuffer methods ***/
1781 ID3DXConstantTableImpl_GetBufferPointer
,
1782 ID3DXConstantTableImpl_GetBufferSize
,
1783 /*** ID3DXConstantTable methods ***/
1784 ID3DXConstantTableImpl_GetDesc
,
1785 ID3DXConstantTableImpl_GetConstantDesc
,
1786 ID3DXConstantTableImpl_GetSamplerIndex
,
1787 ID3DXConstantTableImpl_GetConstant
,
1788 ID3DXConstantTableImpl_GetConstantByName
,
1789 ID3DXConstantTableImpl_GetConstantElement
,
1790 ID3DXConstantTableImpl_SetDefaults
,
1791 ID3DXConstantTableImpl_SetValue
,
1792 ID3DXConstantTableImpl_SetBool
,
1793 ID3DXConstantTableImpl_SetBoolArray
,
1794 ID3DXConstantTableImpl_SetInt
,
1795 ID3DXConstantTableImpl_SetIntArray
,
1796 ID3DXConstantTableImpl_SetFloat
,
1797 ID3DXConstantTableImpl_SetFloatArray
,
1798 ID3DXConstantTableImpl_SetVector
,
1799 ID3DXConstantTableImpl_SetVectorArray
,
1800 ID3DXConstantTableImpl_SetMatrix
,
1801 ID3DXConstantTableImpl_SetMatrixArray
,
1802 ID3DXConstantTableImpl_SetMatrixPointerArray
,
1803 ID3DXConstantTableImpl_SetMatrixTranspose
,
1804 ID3DXConstantTableImpl_SetMatrixTransposeArray
,
1805 ID3DXConstantTableImpl_SetMatrixTransposePointerArray
1808 static HRESULT
parse_ctab_constant_type(const char *ctab
, DWORD typeoffset
, struct ctab_constant
*constant
,
1809 BOOL is_element
, WORD index
, WORD max_index
, DWORD
*offset
, DWORD nameoffset
, UINT regset
)
1811 const D3DXSHADER_TYPEINFO
*type
= (LPD3DXSHADER_TYPEINFO
)(ctab
+ typeoffset
);
1812 const D3DXSHADER_STRUCTMEMBERINFO
*memberinfo
= NULL
;
1813 HRESULT hr
= D3D_OK
;
1817 constant
->desc
.DefaultValue
= offset
? ctab
+ *offset
: NULL
;
1818 constant
->desc
.Class
= type
->Class
;
1819 constant
->desc
.Type
= type
->Type
;
1820 constant
->desc
.Rows
= type
->Rows
;
1821 constant
->desc
.Columns
= type
->Columns
;
1822 constant
->desc
.Elements
= is_element
? 1 : type
->Elements
;
1823 constant
->desc
.StructMembers
= type
->StructMembers
;
1824 constant
->desc
.Name
= ctab
+ nameoffset
;
1825 constant
->desc
.RegisterSet
= regset
;
1826 constant
->desc
.RegisterIndex
= index
;
1828 TRACE("name %s, elements %u, index %u, defaultvalue %p, regset %s\n", constant
->desc
.Name
,
1829 constant
->desc
.Elements
, index
, constant
->desc
.DefaultValue
,
1830 debug_d3dxparameter_registerset(regset
));
1831 TRACE("class %s, type %s, rows %d, columns %d, elements %d, struct_members %d\n",
1832 debug_d3dxparameter_class(type
->Class
), debug_d3dxparameter_type(type
->Type
),
1833 type
->Rows
, type
->Columns
, type
->Elements
, type
->StructMembers
);
1835 if (type
->Elements
> 1 && !is_element
)
1837 count
= type
->Elements
;
1839 else if ((type
->Class
== D3DXPC_STRUCT
) && type
->StructMembers
)
1841 memberinfo
= (D3DXSHADER_STRUCTMEMBERINFO
*)(ctab
+ type
->StructMemberInfo
);
1842 count
= type
->StructMembers
;
1847 constant
->constants
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*constant
->constants
) * count
);
1848 if (!constant
->constants
)
1850 ERR("Out of memory\n");
1855 for (i
= 0; i
< count
; ++i
)
1857 hr
= parse_ctab_constant_type(ctab
, memberinfo
? memberinfo
[i
].TypeInfo
: typeoffset
,
1858 &constant
->constants
[i
], memberinfo
== NULL
, index
+ size
, max_index
, offset
,
1859 memberinfo
? memberinfo
[i
].Name
: nameoffset
, regset
);
1863 size
+= constant
->constants
[i
].desc
.RegisterCount
;
1868 WORD offsetdiff
= type
->Columns
* type
->Rows
;
1871 size
= type
->Columns
* type
->Rows
;
1876 fail
= type
->Class
!= D3DXPC_SCALAR
&& type
->Class
!= D3DXPC_VECTOR
1877 && type
->Class
!= D3DXPC_MATRIX_ROWS
&& type
->Class
!= D3DXPC_MATRIX_COLUMNS
;
1882 switch (type
->Class
)
1888 offsetdiff
= type
->Rows
* 4;
1891 case D3DXPC_MATRIX_ROWS
:
1892 offsetdiff
= type
->Rows
* 4;
1896 case D3DXPC_MATRIX_COLUMNS
:
1897 offsetdiff
= type
->Columns
* 4;
1898 size
= type
->Columns
;
1907 case D3DXRS_SAMPLER
:
1909 fail
= type
->Class
!= D3DXPC_OBJECT
;
1919 FIXME("Unhandled register set %s, type class %s\n", debug_d3dxparameter_registerset(regset
),
1920 debug_d3dxparameter_class(type
->Class
));
1923 /* offset in bytes => offsetdiff * sizeof(DWORD) */
1924 if (offset
) *offset
+= offsetdiff
* 4;
1927 constant
->desc
.RegisterCount
= max(0, min(max_index
- index
, size
));
1928 constant
->desc
.Bytes
= 4 * constant
->desc
.Elements
* type
->Rows
* type
->Columns
;
1933 if (constant
->constants
)
1935 for (i
= 0; i
< count
; ++i
)
1937 free_constant(&constant
->constants
[i
]);
1939 HeapFree(GetProcessHeap(), 0, constant
->constants
);
1940 constant
->constants
= NULL
;
1946 HRESULT WINAPI
D3DXGetShaderConstantTableEx(const DWORD
*byte_code
, DWORD flags
, ID3DXConstantTable
**constant_table
)
1948 struct ID3DXConstantTableImpl
*object
= NULL
;
1952 const D3DXSHADER_CONSTANTTABLE
*ctab_header
;
1953 const D3DXSHADER_CONSTANTINFO
*constant_info
;
1956 TRACE("byte_code %p, flags %x, constant_table %p\n", byte_code
, flags
, constant_table
);
1958 if (constant_table
) *constant_table
= NULL
;
1960 if (!byte_code
|| !constant_table
)
1962 WARN("Invalid argument specified.\n");
1963 return D3DERR_INVALIDCALL
;
1966 if (!is_valid_bytecode(*byte_code
))
1968 WARN("Invalid byte_code specified.\n");
1972 if (flags
) FIXME("Flags (%#x) are not handled, yet!\n", flags
);
1974 hr
= D3DXFindShaderComment(byte_code
, MAKEFOURCC('C','T','A','B'), &data
, &size
);
1977 WARN("CTAB not found.\n");
1978 return D3DXERR_INVALIDDATA
;
1981 if (size
< sizeof(*ctab_header
))
1983 WARN("Invalid CTAB size.\n");
1984 return D3DXERR_INVALIDDATA
;
1987 ctab_header
= (const D3DXSHADER_CONSTANTTABLE
*)data
;
1988 if (ctab_header
->Size
!= sizeof(*ctab_header
))
1990 WARN("Invalid D3DXSHADER_CONSTANTTABLE size.\n");
1991 return D3DXERR_INVALIDDATA
;
1994 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1996 return E_OUTOFMEMORY
;
1998 object
->ID3DXConstantTable_iface
.lpVtbl
= &ID3DXConstantTable_Vtbl
;
2001 object
->ctab
= HeapAlloc(GetProcessHeap(), 0, size
);
2004 ERR("Out of memory\n");
2005 HeapFree(GetProcessHeap(), 0, object
);
2006 return E_OUTOFMEMORY
;
2008 object
->size
= size
;
2009 memcpy(object
->ctab
, data
, object
->size
);
2011 object
->desc
.Creator
= ctab_header
->Creator
? object
->ctab
+ ctab_header
->Creator
: NULL
;
2012 object
->desc
.Version
= ctab_header
->Version
;
2013 object
->desc
.Constants
= ctab_header
->Constants
;
2014 TRACE("Creator %s, Version %x, Constants %u, Target %s\n",
2015 debugstr_a(object
->desc
.Creator
), object
->desc
.Version
, object
->desc
.Constants
,
2016 debugstr_a(ctab_header
->Target
? object
->ctab
+ ctab_header
->Target
: NULL
));
2018 object
->constants
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2019 sizeof(*object
->constants
) * object
->desc
.Constants
);
2020 if (!object
->constants
)
2022 ERR("Out of memory\n");
2027 constant_info
= (const D3DXSHADER_CONSTANTINFO
*)(object
->ctab
+ ctab_header
->ConstantInfo
);
2028 for (i
= 0; i
< ctab_header
->Constants
; i
++)
2030 DWORD offset
= constant_info
[i
].DefaultValue
;
2032 hr
= parse_ctab_constant_type(object
->ctab
, constant_info
[i
].TypeInfo
,
2033 &object
->constants
[i
], FALSE
, constant_info
[i
].RegisterIndex
,
2034 constant_info
[i
].RegisterIndex
+ constant_info
[i
].RegisterCount
,
2035 offset
? &offset
: NULL
, constant_info
[i
].Name
, constant_info
[i
].RegisterSet
);
2040 * Set the register count, it may differ for D3DXRS_INT4, because somehow
2041 * it makes the assumption that the register size is 1 instead of 4, so the
2042 * count is 4 times bigger. This holds true only for toplevel shader
2043 * constants. The count of elements and members is always based on a
2044 * register size of 4.
2046 if (object
->constants
[i
].desc
.RegisterSet
== D3DXRS_INT4
)
2048 object
->constants
[i
].desc
.RegisterCount
= constant_info
[i
].RegisterCount
;
2052 *constant_table
= &object
->ID3DXConstantTable_iface
;
2057 free_constant_table(object
);
2058 HeapFree(GetProcessHeap(), 0, object
);
2063 HRESULT WINAPI
D3DXGetShaderConstantTable(const DWORD
*byte_code
, ID3DXConstantTable
**constant_table
)
2065 TRACE("(%p, %p): Forwarded to D3DXGetShaderConstantTableEx\n", byte_code
, constant_table
);
2067 return D3DXGetShaderConstantTableEx(byte_code
, 0, constant_table
);
2070 HRESULT WINAPI
D3DXGetShaderSamplers(const DWORD
*byte_code
, const char **samplers
, UINT
*count
)
2072 UINT i
, sampler_count
= 0;
2075 const D3DXSHADER_CONSTANTTABLE
*ctab_header
;
2076 const D3DXSHADER_CONSTANTINFO
*constant_info
;
2078 TRACE("byte_code %p, samplers %p, count %p\n", byte_code
, samplers
, count
);
2080 if (count
) *count
= 0;
2082 if (D3DXFindShaderComment(byte_code
, MAKEFOURCC('C','T','A','B'), (const void **)&data
, &size
) != D3D_OK
)
2085 if (size
< sizeof(*ctab_header
)) return D3D_OK
;
2087 ctab_header
= (const D3DXSHADER_CONSTANTTABLE
*)data
;
2088 if (ctab_header
->Size
!= sizeof(*ctab_header
)) return D3D_OK
;
2090 constant_info
= (const D3DXSHADER_CONSTANTINFO
*)(data
+ ctab_header
->ConstantInfo
);
2091 for (i
= 0; i
< ctab_header
->Constants
; i
++)
2093 const D3DXSHADER_TYPEINFO
*type
;
2095 TRACE("name = %s\n", data
+ constant_info
[i
].Name
);
2097 type
= (const D3DXSHADER_TYPEINFO
*)(data
+ constant_info
[i
].TypeInfo
);
2099 if (type
->Type
== D3DXPT_SAMPLER
2100 || type
->Type
== D3DXPT_SAMPLER1D
2101 || type
->Type
== D3DXPT_SAMPLER2D
2102 || type
->Type
== D3DXPT_SAMPLER3D
2103 || type
->Type
== D3DXPT_SAMPLERCUBE
)
2105 if (samplers
) samplers
[sampler_count
] = data
+ constant_info
[i
].Name
;
2111 TRACE("Found %u samplers\n", sampler_count
);
2113 if (count
) *count
= sampler_count
;