comctl32/treeview: Fix possible crash in TVS_SINGELEXPAND helper (Coverity).
[wine/wine-gecko.git] / dlls / d3dx9_36 / shader.c
blob2c21773c29fb85914164d1f57776bf5b91376f87
1 /*
2 * Copyright 2008 Luis Busquets
3 * Copyright 2009 Matteo Bruni
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
22 #include "wine/debug.h"
23 #include "wine/unicode.h"
24 #include "windef.h"
25 #include "wingdi.h"
26 #include "wine/wpp.h"
27 #include "d3dx9_36_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
31 LPCSTR WINAPI D3DXGetPixelShaderProfile(LPDIRECT3DDEVICE9 device)
33 D3DCAPS9 caps;
35 TRACE("device %p\n", device);
37 if (!device) return NULL;
39 IDirect3DDevice9_GetDeviceCaps(device,&caps);
41 switch (caps.PixelShaderVersion)
43 case D3DPS_VERSION(1, 1):
44 return "ps_1_1";
46 case D3DPS_VERSION(1, 2):
47 return "ps_1_2";
49 case D3DPS_VERSION(1, 3):
50 return "ps_1_3";
52 case D3DPS_VERSION(1, 4):
53 return "ps_1_4";
55 case D3DPS_VERSION(2, 0):
56 if ((caps.PS20Caps.NumTemps>=22) &&
57 (caps.PS20Caps.Caps&D3DPS20CAPS_ARBITRARYSWIZZLE) &&
58 (caps.PS20Caps.Caps&D3DPS20CAPS_GRADIENTINSTRUCTIONS) &&
59 (caps.PS20Caps.Caps&D3DPS20CAPS_PREDICATION) &&
60 (caps.PS20Caps.Caps&D3DPS20CAPS_NODEPENDENTREADLIMIT) &&
61 (caps.PS20Caps.Caps&D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT))
63 return "ps_2_a";
65 if ((caps.PS20Caps.NumTemps>=32) &&
66 (caps.PS20Caps.Caps&D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT))
68 return "ps_2_b";
70 return "ps_2_0";
72 case D3DPS_VERSION(3, 0):
73 return "ps_3_0";
76 return NULL;
79 UINT WINAPI D3DXGetShaderSize(const DWORD *byte_code)
81 const DWORD *ptr = byte_code;
83 TRACE("byte_code %p\n", byte_code);
85 if (!ptr) return 0;
87 /* Look for the END token, skipping the VERSION token */
88 while (*++ptr != D3DSIO_END)
90 /* Skip comments */
91 if ((*ptr & D3DSI_OPCODE_MASK) == D3DSIO_COMMENT)
93 ptr += ((*ptr & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT);
96 ++ptr;
98 /* Return the shader size in bytes */
99 return (ptr - byte_code) * sizeof(*ptr);
102 DWORD WINAPI D3DXGetShaderVersion(const DWORD *byte_code)
104 TRACE("byte_code %p\n", byte_code);
106 return byte_code ? *byte_code : 0;
109 LPCSTR WINAPI D3DXGetVertexShaderProfile(LPDIRECT3DDEVICE9 device)
111 D3DCAPS9 caps;
113 TRACE("device %p\n", device);
115 if (!device) return NULL;
117 IDirect3DDevice9_GetDeviceCaps(device,&caps);
119 switch (caps.VertexShaderVersion)
121 case D3DVS_VERSION(1, 1):
122 return "vs_1_1";
123 case D3DVS_VERSION(2, 0):
124 if ((caps.VS20Caps.NumTemps>=13) &&
125 (caps.VS20Caps.DynamicFlowControlDepth==24) &&
126 (caps.VS20Caps.Caps&D3DPS20CAPS_PREDICATION))
128 return "vs_2_a";
130 return "vs_2_0";
131 case D3DVS_VERSION(3, 0):
132 return "vs_3_0";
135 return NULL;
138 HRESULT WINAPI D3DXFindShaderComment(CONST DWORD* byte_code, DWORD fourcc, LPCVOID* data, UINT* size)
140 CONST DWORD *ptr = byte_code;
142 TRACE("(%p, %x, %p, %p)\n", byte_code, fourcc, data, size);
144 if (!byte_code)
145 return D3DERR_INVALIDCALL;
147 while (*++ptr != D3DSIO_END)
149 /* Check if it is a comment */
150 if ((*ptr & D3DSI_OPCODE_MASK) == D3DSIO_COMMENT)
152 DWORD comment_size = (*ptr & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
154 /* Check if this is the comment we are looking for */
155 if (*(ptr + 1) == fourcc)
157 UINT ctab_size = (comment_size - 1) * sizeof(DWORD);
158 LPCVOID ctab_data = ptr + 2;
159 if (size)
160 *size = ctab_size;
161 if (data)
162 *data = ctab_data;
163 TRACE("Returning comment data at %p with size %d\n", ctab_data, ctab_size);
164 return D3D_OK;
166 ptr += comment_size;
170 return S_FALSE;
173 #define BUFFER_INITIAL_CAPACITY 256
175 struct mem_file_desc
177 const char *buffer;
178 unsigned int size;
179 unsigned int pos;
182 struct mem_file_desc current_shader;
183 LPD3DXINCLUDE current_include;
184 char *wpp_output;
185 int wpp_output_capacity, wpp_output_size;
187 char *wpp_messages;
188 int wpp_messages_capacity, wpp_messages_size;
190 /* Mutex used to guarantee a single invocation
191 of the D3DXAssembleShader function (or its variants) at a time.
192 This is needed as wpp isn't thread-safe */
193 static CRITICAL_SECTION wpp_mutex;
194 static CRITICAL_SECTION_DEBUG wpp_mutex_debug =
196 0, 0, &wpp_mutex,
197 { &wpp_mutex_debug.ProcessLocksList,
198 &wpp_mutex_debug.ProcessLocksList },
199 0, 0, { (DWORD_PTR)(__FILE__ ": wpp_mutex") }
201 static CRITICAL_SECTION wpp_mutex = { &wpp_mutex_debug, -1, 0, 0, 0, 0 };
203 /* Preprocessor error reporting functions */
204 static void wpp_write_message(const char *fmt, va_list args)
206 char* newbuffer;
207 int rc, newsize;
209 if(wpp_messages_capacity == 0)
211 wpp_messages = HeapAlloc(GetProcessHeap(), 0, MESSAGEBUFFER_INITIAL_SIZE);
212 if(wpp_messages == NULL)
214 ERR("Error allocating memory for parser messages\n");
215 return;
217 wpp_messages_capacity = MESSAGEBUFFER_INITIAL_SIZE;
220 while(1)
222 rc = vsnprintf(wpp_messages + wpp_messages_size,
223 wpp_messages_capacity - wpp_messages_size, fmt, args);
225 if (rc < 0 || /* C89 */
226 rc >= wpp_messages_capacity - wpp_messages_size) { /* C99 */
227 /* Resize the buffer */
228 newsize = wpp_messages_capacity * 2;
229 newbuffer = HeapReAlloc(GetProcessHeap(), 0, wpp_messages, newsize);
230 if(newbuffer == NULL)
232 ERR("Error reallocating memory for parser messages\n");
233 return;
235 wpp_messages = newbuffer;
236 wpp_messages_capacity = newsize;
238 else
240 wpp_messages_size += rc;
241 return;
246 static void PRINTF_ATTR(1,2) wpp_write_message_var(const char *fmt, ...)
248 va_list args;
250 va_start(args, fmt);
251 wpp_write_message(fmt, args);
252 va_end(args);
255 static void wpp_error(const char *file, int line, int col, const char *near,
256 const char *msg, va_list ap)
258 wpp_write_message_var("%s:%d:%d: %s: ", file ? file : "'main file'",
259 line, col, "Error");
260 wpp_write_message(msg, ap);
261 wpp_write_message_var("\n");
264 static void wpp_warning(const char *file, int line, int col, const char *near,
265 const char *msg, va_list ap)
267 wpp_write_message_var("%s:%d:%d: %s: ", file ? file : "'main file'",
268 line, col, "Warning");
269 wpp_write_message(msg, ap);
270 wpp_write_message_var("\n");
273 static char *wpp_lookup_mem(const char *filename, const char *parent_name,
274 char **include_path, int include_path_count)
276 /* Here we return always ok. We will maybe fail on the next wpp_open_mem */
277 char *path;
279 path = malloc(strlen(filename) + 1);
280 if(!path) return NULL;
281 memcpy(path, filename, strlen(filename) + 1);
282 return path;
285 static void *wpp_open_mem(const char *filename, int type)
287 struct mem_file_desc *desc;
288 HRESULT hr;
290 if(filename[0] == '\0') /* "" means to load the initial shader */
292 current_shader.pos = 0;
293 return &current_shader;
296 if(current_include == NULL) return NULL;
297 desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc));
298 if(!desc)
300 ERR("Error allocating memory\n");
301 return NULL;
303 hr = ID3DXInclude_Open(current_include,
304 type ? D3DXINC_SYSTEM : D3DXINC_LOCAL,
305 filename, NULL, (LPCVOID *)&desc->buffer,
306 &desc->size);
307 if(FAILED(hr))
309 HeapFree(GetProcessHeap(), 0, desc);
310 return NULL;
312 desc->pos = 0;
313 return desc;
316 static void wpp_close_mem(void *file)
318 struct mem_file_desc *desc = file;
320 if(desc != &current_shader)
322 if(current_include)
323 ID3DXInclude_Close(current_include, desc->buffer);
324 else
325 ERR("current_include == NULL, desc == %p, buffer = %s\n",
326 desc, desc->buffer);
328 HeapFree(GetProcessHeap(), 0, desc);
332 static int wpp_read_mem(void *file, char *buffer, unsigned int len)
334 struct mem_file_desc *desc = file;
336 len = min(len, desc->size - desc->pos);
337 memcpy(buffer, desc->buffer + desc->pos, len);
338 desc->pos += len;
339 return len;
342 static void wpp_write_mem(const char *buffer, unsigned int len)
344 char *new_wpp_output;
346 if(wpp_output_capacity == 0)
348 wpp_output = HeapAlloc(GetProcessHeap(), 0, BUFFER_INITIAL_CAPACITY);
349 if(!wpp_output)
351 ERR("Error allocating memory\n");
352 return;
354 wpp_output_capacity = BUFFER_INITIAL_CAPACITY;
356 if(len > wpp_output_capacity - wpp_output_size)
358 while(len > wpp_output_capacity - wpp_output_size)
360 wpp_output_capacity *= 2;
362 new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output,
363 wpp_output_capacity);
364 if(!new_wpp_output)
366 ERR("Error allocating memory\n");
367 return;
369 wpp_output = new_wpp_output;
371 memcpy(wpp_output + wpp_output_size, buffer, len);
372 wpp_output_size += len;
375 static int wpp_close_output(void)
377 char *new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output,
378 wpp_output_size + 1);
379 if(!new_wpp_output) return 0;
380 wpp_output = new_wpp_output;
381 wpp_output[wpp_output_size]='\0';
382 return 1;
385 static HRESULT assemble_shader(const char *preprocShader, const char *preprocMessages,
386 LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs)
388 struct bwriter_shader *shader;
389 char *messages = NULL;
390 HRESULT hr;
391 DWORD *res;
392 LPD3DXBUFFER buffer;
393 int size;
394 char *pos;
396 shader = SlAssembleShader(preprocShader, &messages);
398 if(messages || preprocMessages)
400 if(preprocMessages)
402 TRACE("Preprocessor messages:\n");
403 TRACE("%s", preprocMessages);
405 if(messages)
407 TRACE("Assembler messages:\n");
408 TRACE("%s", messages);
411 TRACE("Shader source:\n");
412 TRACE("%s\n", debugstr_a(preprocShader));
414 if(ppErrorMsgs)
416 size = (messages ? strlen(messages) : 0) +
417 (preprocMessages ? strlen(preprocMessages) : 0) + 1;
418 hr = D3DXCreateBuffer(size, &buffer);
419 if(FAILED(hr))
421 HeapFree(GetProcessHeap(), 0, messages);
422 if(shader) SlDeleteShader(shader);
423 return hr;
425 pos = ID3DXBuffer_GetBufferPointer(buffer);
426 if(preprocMessages)
428 CopyMemory(pos, preprocMessages, strlen(preprocMessages) + 1);
429 pos += strlen(preprocMessages);
431 if(messages)
432 CopyMemory(pos, messages, strlen(messages) + 1);
434 *ppErrorMsgs = buffer;
437 HeapFree(GetProcessHeap(), 0, messages);
440 if(shader == NULL)
442 ERR("Asm reading failed\n");
443 return D3DXERR_INVALIDDATA;
446 hr = SlWriteBytecode(shader, 9, &res);
447 SlDeleteShader(shader);
448 if(FAILED(hr))
450 ERR("SlWriteBytecode failed with 0x%08x\n", hr);
451 return D3DXERR_INVALIDDATA;
454 if(ppShader)
456 size = HeapSize(GetProcessHeap(), 0, res);
457 hr = D3DXCreateBuffer(size, &buffer);
458 if(FAILED(hr))
460 HeapFree(GetProcessHeap(), 0, res);
461 return hr;
463 CopyMemory(ID3DXBuffer_GetBufferPointer(buffer), res, size);
464 *ppShader = buffer;
467 HeapFree(GetProcessHeap(), 0, res);
469 return D3D_OK;
472 HRESULT WINAPI D3DXAssembleShader(LPCSTR data,
473 UINT data_len,
474 CONST D3DXMACRO* defines,
475 LPD3DXINCLUDE include,
476 DWORD flags,
477 LPD3DXBUFFER* shader,
478 LPD3DXBUFFER* error_messages)
480 int ret;
481 HRESULT hr;
482 CONST D3DXMACRO* def = defines;
484 static const struct wpp_callbacks wpp_callbacks = {
485 wpp_lookup_mem,
486 wpp_open_mem,
487 wpp_close_mem,
488 wpp_read_mem,
489 wpp_write_mem,
490 wpp_error,
491 wpp_warning,
494 EnterCriticalSection(&wpp_mutex);
496 /* TODO: flags */
497 if(flags) FIXME("flags: %x\n", flags);
499 if(def != NULL)
501 while(def->Name != NULL)
503 wpp_add_define(def->Name, def->Definition);
504 def++;
507 current_include = include;
509 if(shader) *shader = NULL;
510 if(error_messages) *error_messages = NULL;
511 wpp_output_size = wpp_output_capacity = 0;
512 wpp_output = NULL;
514 /* Preprocess shader */
515 wpp_set_callbacks(&wpp_callbacks);
516 wpp_messages_size = wpp_messages_capacity = 0;
517 wpp_messages = NULL;
518 current_shader.buffer = data;
519 current_shader.size = data_len;
521 ret = wpp_parse("", NULL);
522 if(!wpp_close_output())
523 ret = 1;
524 if(ret)
526 TRACE("Error during shader preprocessing\n");
527 if(wpp_messages)
529 int size;
530 LPD3DXBUFFER buffer;
532 TRACE("Preprocessor messages:\n");
533 TRACE("%s", wpp_messages);
535 if(error_messages)
537 size = strlen(wpp_messages) + 1;
538 hr = D3DXCreateBuffer(size, &buffer);
539 if(FAILED(hr)) goto cleanup;
540 CopyMemory(ID3DXBuffer_GetBufferPointer(buffer), wpp_messages, size);
541 *error_messages = buffer;
544 if(data)
546 TRACE("Shader source:\n");
547 TRACE("%s\n", debugstr_an(data, data_len));
549 hr = D3DXERR_INVALIDDATA;
550 goto cleanup;
553 hr = assemble_shader(wpp_output, wpp_messages, shader, error_messages);
555 cleanup:
556 /* Remove the previously added defines */
557 if(defines != NULL)
559 while(defines->Name != NULL)
561 wpp_del_define(defines->Name);
562 defines++;
565 HeapFree(GetProcessHeap(), 0, wpp_messages);
566 HeapFree(GetProcessHeap(), 0, wpp_output);
567 LeaveCriticalSection(&wpp_mutex);
568 return hr;
571 HRESULT WINAPI D3DXAssembleShaderFromFileA(LPCSTR filename,
572 CONST D3DXMACRO* defines,
573 LPD3DXINCLUDE include,
574 DWORD flags,
575 LPD3DXBUFFER* shader,
576 LPD3DXBUFFER* error_messages)
578 LPWSTR filename_w = NULL;
579 DWORD len;
580 HRESULT ret;
582 if (!filename) return D3DXERR_INVALIDDATA;
584 len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
585 filename_w = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
586 if (!filename_w) return E_OUTOFMEMORY;
587 MultiByteToWideChar(CP_ACP, 0, filename, -1, filename_w, len);
589 ret = D3DXAssembleShaderFromFileW(filename_w, defines, include, flags, shader, error_messages);
591 HeapFree(GetProcessHeap(), 0, filename_w);
592 return ret;
595 HRESULT WINAPI D3DXAssembleShaderFromFileW(LPCWSTR filename,
596 CONST D3DXMACRO* defines,
597 LPD3DXINCLUDE include,
598 DWORD flags,
599 LPD3DXBUFFER* shader,
600 LPD3DXBUFFER* error_messages)
602 FIXME("(%s, %p, %p, %x, %p, %p): stub\n", debugstr_w(filename), defines, include, flags, shader, error_messages);
603 return D3DERR_INVALIDCALL;
606 HRESULT WINAPI D3DXAssembleShaderFromResourceA(HMODULE module,
607 LPCSTR resource,
608 CONST D3DXMACRO* defines,
609 LPD3DXINCLUDE include,
610 DWORD flags,
611 LPD3DXBUFFER* shader,
612 LPD3DXBUFFER* error_messages)
614 HRSRC res;
615 LPCSTR buffer;
616 DWORD len;
618 if (!(res = FindResourceA(module, resource, (LPCSTR)RT_RCDATA)))
619 return D3DXERR_INVALIDDATA;
620 if (FAILED(load_resource_into_memory(module, res, (LPVOID *)&buffer, &len)))
621 return D3DXERR_INVALIDDATA;
622 return D3DXAssembleShader(buffer, len, defines, include, flags,
623 shader, error_messages);
626 HRESULT WINAPI D3DXAssembleShaderFromResourceW(HMODULE module,
627 LPCWSTR resource,
628 CONST D3DXMACRO* defines,
629 LPD3DXINCLUDE include,
630 DWORD flags,
631 LPD3DXBUFFER* shader,
632 LPD3DXBUFFER* error_messages)
634 HRSRC res;
635 LPCSTR buffer;
636 DWORD len;
638 if (!(res = FindResourceW(module, resource, (LPCWSTR)RT_RCDATA)))
639 return D3DXERR_INVALIDDATA;
640 if (FAILED(load_resource_into_memory(module, res, (LPVOID *)&buffer, &len)))
641 return D3DXERR_INVALIDDATA;
642 return D3DXAssembleShader(buffer, len, defines, include, flags,
643 shader, error_messages);
646 HRESULT WINAPI D3DXCompileShader(LPCSTR pSrcData,
647 UINT srcDataLen,
648 CONST D3DXMACRO* pDefines,
649 LPD3DXINCLUDE pInclude,
650 LPCSTR pFunctionName,
651 LPCSTR pProfile,
652 DWORD Flags,
653 LPD3DXBUFFER* ppShader,
654 LPD3DXBUFFER* ppErrorMsgs,
655 LPD3DXCONSTANTTABLE * ppConstantTable)
657 FIXME("(%p, %d, %p, %p, %s, %s, %x, %p, %p, %p): stub\n",
658 pSrcData, srcDataLen, pDefines, pInclude, debugstr_a(pFunctionName),
659 debugstr_a(pProfile), Flags, ppShader, ppErrorMsgs, ppConstantTable);
661 TRACE("Shader source:\n");
662 TRACE("%s\n", debugstr_an(pSrcData, srcDataLen));
664 if (ppErrorMsgs)
665 D3DXCreateBuffer(1, ppErrorMsgs); /* zero fill used as string end */
666 return D3DERR_INVALIDCALL;
669 static const struct ID3DXConstantTableVtbl ID3DXConstantTable_Vtbl;
671 typedef struct ID3DXConstantTableImpl {
672 const ID3DXConstantTableVtbl *lpVtbl;
673 LONG ref;
674 LPVOID ctab;
675 DWORD size;
676 D3DXCONSTANTTABLE_DESC desc;
677 } ID3DXConstantTableImpl;
679 /*** IUnknown methods ***/
680 static HRESULT WINAPI ID3DXConstantTableImpl_QueryInterface(ID3DXConstantTable* iface, REFIID riid, void** ppvObject)
682 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
684 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
686 if (IsEqualGUID(riid, &IID_IUnknown) ||
687 IsEqualGUID(riid, &IID_ID3DXBuffer) ||
688 IsEqualGUID(riid, &IID_ID3DXConstantTable))
690 ID3DXConstantTable_AddRef(iface);
691 *ppvObject = This;
692 return S_OK;
695 WARN("Interface %s not found.\n", debugstr_guid(riid));
697 return E_NOINTERFACE;
700 static ULONG WINAPI ID3DXConstantTableImpl_AddRef(ID3DXConstantTable* iface)
702 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
704 TRACE("(%p)->(): AddRef from %d\n", This, This->ref);
706 return InterlockedIncrement(&This->ref);
709 static ULONG WINAPI ID3DXConstantTableImpl_Release(ID3DXConstantTable* iface)
711 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
712 ULONG ref = InterlockedDecrement(&This->ref);
714 TRACE("(%p)->(): Release from %d\n", This, ref + 1);
716 if (!ref)
718 HeapFree(GetProcessHeap(), 0, This->ctab);
719 HeapFree(GetProcessHeap(), 0, This);
722 return ref;
725 /*** ID3DXBuffer methods ***/
726 static LPVOID WINAPI ID3DXConstantTableImpl_GetBufferPointer(ID3DXConstantTable* iface)
728 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
730 TRACE("(%p)->()\n", This);
732 return This->ctab;
735 static DWORD WINAPI ID3DXConstantTableImpl_GetBufferSize(ID3DXConstantTable* iface)
737 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
739 TRACE("(%p)->()\n", This);
741 return This->size;
744 /*** ID3DXConstantTable methods ***/
745 static HRESULT WINAPI ID3DXConstantTableImpl_GetDesc(ID3DXConstantTable* iface, D3DXCONSTANTTABLE_DESC *desc)
747 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
749 TRACE("(%p)->(%p)\n", This, desc);
751 if (!desc)
752 return D3DERR_INVALIDCALL;
754 memcpy(desc, &This->desc, sizeof(This->desc));
756 return D3D_OK;
759 static HRESULT WINAPI ID3DXConstantTableImpl_GetConstantDesc(ID3DXConstantTable* iface, D3DXHANDLE constant,
760 D3DXCONSTANT_DESC *desc, UINT *count)
762 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
764 FIXME("(%p)->(%p, %p, %p): stub\n", This, constant, desc, count);
766 return E_NOTIMPL;
769 static UINT WINAPI ID3DXConstantTableImpl_GetSamplerIndex(LPD3DXCONSTANTTABLE iface, D3DXHANDLE constant)
771 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
773 FIXME("(%p)->(%p): stub\n", This, constant);
775 return (UINT)-1;
778 static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstant(ID3DXConstantTable* iface, D3DXHANDLE constant, UINT index)
780 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
782 FIXME("(%p)->(%p, %d): stub\n", This, constant, index);
784 return NULL;
787 static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstantByName(ID3DXConstantTable* iface, D3DXHANDLE constant, LPCSTR name)
789 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
791 FIXME("(%p)->(%p, %s): stub\n", This, constant, name);
793 return NULL;
796 static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstantElement(ID3DXConstantTable* iface, D3DXHANDLE constant, UINT index)
798 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
800 FIXME("(%p)->(%p, %d): stub\n", This, constant, index);
802 return NULL;
805 static HRESULT WINAPI ID3DXConstantTableImpl_SetDefaults(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device)
807 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
809 FIXME("(%p)->(%p): stub\n", This, device);
811 return E_NOTIMPL;
814 static HRESULT WINAPI ID3DXConstantTableImpl_SetValue(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
815 D3DXHANDLE constant, LPCVOID data, UINT bytes)
817 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
819 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, data, bytes);
821 return E_NOTIMPL;
824 static HRESULT WINAPI ID3DXConstantTableImpl_SetBool(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
825 D3DXHANDLE constant, BOOL b)
827 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
829 FIXME("(%p)->(%p, %p, %d): stub\n", This, device, constant, b);
831 return E_NOTIMPL;
834 static HRESULT WINAPI ID3DXConstantTableImpl_SetBoolArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
835 D3DXHANDLE constant, CONST BOOL* b, UINT count)
837 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
839 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, b, count);
841 return E_NOTIMPL;
844 static HRESULT WINAPI ID3DXConstantTableImpl_SetInt(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device, D3DXHANDLE constant, INT n)
846 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
848 FIXME("(%p)->(%p, %p, %d): stub\n", This, device, constant, n);
850 return E_NOTIMPL;
853 static HRESULT WINAPI ID3DXConstantTableImpl_SetIntArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
854 D3DXHANDLE constant, CONST INT* n, UINT count)
856 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
858 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, n, count);
860 return E_NOTIMPL;
863 static HRESULT WINAPI ID3DXConstantTableImpl_SetFloat(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
864 D3DXHANDLE constant, FLOAT f)
866 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
868 FIXME("(%p)->(%p, %p, %f): stub\n", This, device, constant, f);
870 return E_NOTIMPL;
873 static HRESULT WINAPI ID3DXConstantTableImpl_SetFloatArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
874 D3DXHANDLE constant, CONST FLOAT* f, UINT count)
876 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
878 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, f, count);
880 return E_NOTIMPL;
883 static HRESULT WINAPI ID3DXConstantTableImpl_SetVector(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
884 D3DXHANDLE constant, CONST D3DXVECTOR4* vector)
886 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
888 FIXME("(%p)->(%p, %p, %p): stub\n", This, device, constant, vector);
890 return E_NOTIMPL;
893 static HRESULT WINAPI ID3DXConstantTableImpl_SetVectorArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
894 D3DXHANDLE constant, CONST D3DXVECTOR4* vector, UINT count)
896 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
898 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, vector, count);
900 return E_NOTIMPL;
903 static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrix(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
904 D3DXHANDLE constant, CONST D3DXMATRIX* matrix)
906 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
908 FIXME("(%p)->(%p, %p, %p): stub\n", This, device, constant, matrix);
910 return E_NOTIMPL;
913 static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
914 D3DXHANDLE constant, CONST D3DXMATRIX* matrix, UINT count)
916 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
918 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, matrix, count);
920 return E_NOTIMPL;
923 static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixPointerArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
924 D3DXHANDLE constant, CONST D3DXMATRIX** matrix, UINT count)
926 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
928 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, matrix, count);
930 return E_NOTIMPL;
933 static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixTranspose(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
934 D3DXHANDLE constant, CONST D3DXMATRIX* matrix)
936 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
938 FIXME("(%p)->(%p, %p, %p): stub\n", This, device, constant, matrix);
940 return E_NOTIMPL;
943 static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixTransposeArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
944 D3DXHANDLE constant, CONST D3DXMATRIX* matrix, UINT count)
946 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
948 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, matrix, count);
950 return E_NOTIMPL;
953 static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixTransposePointerArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
954 D3DXHANDLE constant, CONST D3DXMATRIX** matrix, UINT count)
956 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
958 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, matrix, count);
960 return E_NOTIMPL;
963 static const struct ID3DXConstantTableVtbl ID3DXConstantTable_Vtbl =
965 /*** IUnknown methods ***/
966 ID3DXConstantTableImpl_QueryInterface,
967 ID3DXConstantTableImpl_AddRef,
968 ID3DXConstantTableImpl_Release,
969 /*** ID3DXBuffer methods ***/
970 ID3DXConstantTableImpl_GetBufferPointer,
971 ID3DXConstantTableImpl_GetBufferSize,
972 /*** ID3DXConstantTable methods ***/
973 ID3DXConstantTableImpl_GetDesc,
974 ID3DXConstantTableImpl_GetConstantDesc,
975 ID3DXConstantTableImpl_GetSamplerIndex,
976 ID3DXConstantTableImpl_GetConstant,
977 ID3DXConstantTableImpl_GetConstantByName,
978 ID3DXConstantTableImpl_GetConstantElement,
979 ID3DXConstantTableImpl_SetDefaults,
980 ID3DXConstantTableImpl_SetValue,
981 ID3DXConstantTableImpl_SetBool,
982 ID3DXConstantTableImpl_SetBoolArray,
983 ID3DXConstantTableImpl_SetInt,
984 ID3DXConstantTableImpl_SetIntArray,
985 ID3DXConstantTableImpl_SetFloat,
986 ID3DXConstantTableImpl_SetFloatArray,
987 ID3DXConstantTableImpl_SetVector,
988 ID3DXConstantTableImpl_SetVectorArray,
989 ID3DXConstantTableImpl_SetMatrix,
990 ID3DXConstantTableImpl_SetMatrixArray,
991 ID3DXConstantTableImpl_SetMatrixPointerArray,
992 ID3DXConstantTableImpl_SetMatrixTranspose,
993 ID3DXConstantTableImpl_SetMatrixTransposeArray,
994 ID3DXConstantTableImpl_SetMatrixTransposePointerArray
997 HRESULT WINAPI D3DXGetShaderConstantTableEx(CONST DWORD* byte_code,
998 DWORD flags,
999 LPD3DXCONSTANTTABLE* constant_table)
1001 ID3DXConstantTableImpl* object = NULL;
1002 HRESULT hr;
1003 LPCVOID data;
1004 UINT size;
1005 const D3DXSHADER_CONSTANTTABLE* ctab_header;
1007 FIXME("(%p, %x, %p): semi-stub\n", byte_code, flags, constant_table);
1009 if (!byte_code || !constant_table)
1010 return D3DERR_INVALIDCALL;
1012 hr = D3DXFindShaderComment(byte_code, MAKEFOURCC('C','T','A','B'), &data, &size);
1013 if (hr != D3D_OK)
1014 return D3DXERR_INVALIDDATA;
1016 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXConstantTableImpl));
1017 if (!object)
1019 ERR("Out of memory\n");
1020 return E_OUTOFMEMORY;
1023 object->lpVtbl = &ID3DXConstantTable_Vtbl;
1024 object->ref = 1;
1026 if (size < sizeof(D3DXSHADER_CONSTANTTABLE))
1027 goto error;
1029 object->ctab = HeapAlloc(GetProcessHeap(), 0, size);
1030 if (!object->ctab)
1032 HeapFree(GetProcessHeap(), 0, object);
1033 ERR("Out of memory\n");
1034 return E_OUTOFMEMORY;
1036 object->size = size;
1037 memcpy(object->ctab, data, object->size);
1039 ctab_header = (const D3DXSHADER_CONSTANTTABLE*)data;
1040 if (ctab_header->Size != sizeof(D3DXSHADER_CONSTANTTABLE))
1041 goto error;
1042 object->desc.Creator = ctab_header->Creator ? (LPCSTR)object->ctab + ctab_header->Creator : NULL;
1043 object->desc.Version = ctab_header->Version;
1044 object->desc.Constants = ctab_header->Constants;
1046 *constant_table = (LPD3DXCONSTANTTABLE)object;
1048 return D3D_OK;
1050 error:
1052 HeapFree(GetProcessHeap(), 0, object->ctab);
1053 HeapFree(GetProcessHeap(), 0, object);
1055 return D3DXERR_INVALIDDATA;
1058 HRESULT WINAPI D3DXGetShaderConstantTable(CONST DWORD* byte_code,
1059 LPD3DXCONSTANTTABLE* constant_table)
1061 TRACE("(%p, %p): Forwarded to D3DXGetShaderConstantTableEx\n", byte_code, constant_table);
1063 return D3DXGetShaderConstantTableEx(byte_code, 0, constant_table);