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
21 #include "wine/port.h"
22 #include "wine/debug.h"
23 #include "wine/unicode.h"
27 #include "d3dx9_36_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
31 LPCSTR WINAPI D3DXGetPixelShaderProfile(LPDIRECT3DDEVICE9 device)
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):
46 case D3DPS_VERSION(1, 2):
49 case D3DPS_VERSION(1, 3):
52 case D3DPS_VERSION(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))
65 if ((caps.PS20Caps.NumTemps>=32) &&
66 (caps.PS20Caps.Caps&D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT))
72 case D3DPS_VERSION(3, 0):
79 UINT WINAPI D3DXGetShaderSize(const DWORD *byte_code)
81 const DWORD *ptr = byte_code;
83 TRACE("byte_code %p\n", byte_code);
87 /* Look for the END token, skipping the VERSION token */
88 while (*++ptr != D3DSIO_END)
91 if ((*ptr & D3DSI_OPCODE_MASK) == D3DSIO_COMMENT)
93 ptr += ((*ptr & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT);
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)
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):
123 case D3DVS_VERSION(2, 0):
124 if ((caps.VS20Caps.NumTemps>=13) &&
125 (caps.VS20Caps.DynamicFlowControlDepth==24) &&
126 (caps.VS20Caps.Caps&D3DPS20CAPS_PREDICATION))
131 case D3DVS_VERSION(3, 0):
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);
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;
163 TRACE("Returning comment data at %p with size %d\n", ctab_data, ctab_size);
173 #define BUFFER_INITIAL_CAPACITY 256
182 struct mem_file_desc current_shader;
183 LPD3DXINCLUDE current_include;
185 #define INCLUDES_INITIAL_CAPACITY 4
187 struct loaded_include
193 struct loaded_include *includes;
194 int includes_capacity, includes_size;
195 const char *parent_include;
198 int wpp_output_capacity, wpp_output_size;
201 int wpp_messages_capacity, wpp_messages_size;
203 /* Mutex used to guarantee a single invocation
204 of the D3DXAssembleShader function (or its variants) at a time.
205 This is needed as wpp isn't thread-safe */
206 static CRITICAL_SECTION wpp_mutex;
207 static CRITICAL_SECTION_DEBUG wpp_mutex_debug =
210 { &wpp_mutex_debug.ProcessLocksList,
211 &wpp_mutex_debug.ProcessLocksList },
212 0, 0, { (DWORD_PTR)(__FILE__ ": wpp_mutex") }
214 static CRITICAL_SECTION wpp_mutex = { &wpp_mutex_debug, -1, 0, 0, 0, 0 };
216 /* Preprocessor error reporting functions */
217 static void wpp_write_message(const char *fmt, va_list args)
222 if(wpp_messages_capacity == 0)
224 wpp_messages = HeapAlloc(GetProcessHeap(), 0, MESSAGEBUFFER_INITIAL_SIZE);
225 if(wpp_messages == NULL)
227 ERR("Error allocating memory for parser messages\n");
230 wpp_messages_capacity = MESSAGEBUFFER_INITIAL_SIZE;
235 rc = vsnprintf(wpp_messages + wpp_messages_size,
236 wpp_messages_capacity - wpp_messages_size, fmt, args);
238 if (rc < 0 || /* C89 */
239 rc >= wpp_messages_capacity - wpp_messages_size) { /* C99 */
240 /* Resize the buffer */
241 newsize = wpp_messages_capacity * 2;
242 newbuffer = HeapReAlloc(GetProcessHeap(), 0, wpp_messages, newsize);
243 if(newbuffer == NULL)
245 ERR("Error reallocating memory for parser messages\n");
248 wpp_messages = newbuffer;
249 wpp_messages_capacity = newsize;
253 wpp_messages_size += rc;
259 static void PRINTF_ATTR(1,2) wpp_write_message_var(const char *fmt, ...)
264 wpp_write_message(fmt, args);
268 static void wpp_error(const char *file, int line, int col, const char *near,
269 const char *msg, va_list ap)
271 wpp_write_message_var("%s:%d:%d: %s: ", file ? file : "'main file'",
273 wpp_write_message(msg, ap);
274 wpp_write_message_var("\n");
277 static void wpp_warning(const char *file, int line, int col, const char *near,
278 const char *msg, va_list ap)
280 wpp_write_message_var("%s:%d:%d: %s: ", file ? file : "'main file'",
281 line, col, "Warning");
282 wpp_write_message(msg, ap);
283 wpp_write_message_var("\n");
286 static char *wpp_lookup_mem(const char *filename, const char *parent_name,
287 char **include_path, int include_path_count)
289 /* Here we return always ok. We will maybe fail on the next wpp_open_mem */
293 parent_include = NULL;
294 if(parent_name[0] != '\0')
296 for(i = 0; i < includes_size; i++)
298 if(!strcmp(parent_name, includes[i].name))
300 parent_include = includes[i].data;
304 if(parent_include == NULL)
306 ERR("Parent include file missing\n");
311 path = malloc(strlen(filename) + 1);
313 memcpy(path, filename, strlen(filename) + 1);
317 static void *wpp_open_mem(const char *filename, int type)
319 struct mem_file_desc *desc;
322 if(filename[0] == '\0') /* "" means to load the initial shader */
324 current_shader.pos = 0;
325 return ¤t_shader;
328 if(current_include == NULL) return NULL;
329 desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc));
332 ERR("Error allocating memory\n");
335 hr = ID3DXInclude_Open(current_include,
336 type ? D3DXINC_SYSTEM : D3DXINC_LOCAL,
337 filename, parent_include, (LPCVOID *)&desc->buffer,
341 HeapFree(GetProcessHeap(), 0, desc);
345 if(includes_capacity == includes_size)
347 if(includes_capacity == 0)
349 includes = HeapAlloc(GetProcessHeap(), 0, INCLUDES_INITIAL_CAPACITY);
352 ERR("Error allocating memory for the loaded includes structure\n");
355 includes_capacity = INCLUDES_INITIAL_CAPACITY;
359 int newcapacity = includes_capacity * 2;
360 struct loaded_include *newincludes =
361 HeapReAlloc(GetProcessHeap(), 0, includes, newcapacity);
362 if(newincludes == NULL)
364 ERR("Error reallocating memory for the loaded includes structure\n");
367 includes = newincludes;
368 includes_capacity = newcapacity;
371 includes[includes_size].name = filename;
372 includes[includes_size++].data = desc->buffer;
378 ID3DXInclude_Close(current_include, desc->buffer);
379 HeapFree(GetProcessHeap(), 0, desc);
383 static void wpp_close_mem(void *file)
385 struct mem_file_desc *desc = file;
387 if(desc != ¤t_shader)
390 ID3DXInclude_Close(current_include, desc->buffer);
392 ERR("current_include == NULL, desc == %p, buffer = %s\n",
395 HeapFree(GetProcessHeap(), 0, desc);
399 static int wpp_read_mem(void *file, char *buffer, unsigned int len)
401 struct mem_file_desc *desc = file;
403 len = min(len, desc->size - desc->pos);
404 memcpy(buffer, desc->buffer + desc->pos, len);
409 static void wpp_write_mem(const char *buffer, unsigned int len)
411 char *new_wpp_output;
413 if(wpp_output_capacity == 0)
415 wpp_output = HeapAlloc(GetProcessHeap(), 0, BUFFER_INITIAL_CAPACITY);
418 ERR("Error allocating memory\n");
421 wpp_output_capacity = BUFFER_INITIAL_CAPACITY;
423 if(len > wpp_output_capacity - wpp_output_size)
425 while(len > wpp_output_capacity - wpp_output_size)
427 wpp_output_capacity *= 2;
429 new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output,
430 wpp_output_capacity);
433 ERR("Error allocating memory\n");
436 wpp_output = new_wpp_output;
438 memcpy(wpp_output + wpp_output_size, buffer, len);
439 wpp_output_size += len;
442 static int wpp_close_output(void)
444 char *new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output,
445 wpp_output_size + 1);
446 if(!new_wpp_output) return 0;
447 wpp_output = new_wpp_output;
448 wpp_output[wpp_output_size]='\0';
452 static HRESULT assemble_shader(const char *preprocShader, const char *preprocMessages,
453 LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs)
455 struct bwriter_shader *shader;
456 char *messages = NULL;
463 shader = SlAssembleShader(preprocShader, &messages);
465 if(messages || preprocMessages)
469 TRACE("Preprocessor messages:\n");
470 TRACE("%s", preprocMessages);
474 TRACE("Assembler messages:\n");
475 TRACE("%s", messages);
478 TRACE("Shader source:\n");
479 TRACE("%s\n", debugstr_a(preprocShader));
483 size = (messages ? strlen(messages) : 0) +
484 (preprocMessages ? strlen(preprocMessages) : 0) + 1;
485 hr = D3DXCreateBuffer(size, &buffer);
488 HeapFree(GetProcessHeap(), 0, messages);
489 if(shader) SlDeleteShader(shader);
492 pos = ID3DXBuffer_GetBufferPointer(buffer);
495 CopyMemory(pos, preprocMessages, strlen(preprocMessages) + 1);
496 pos += strlen(preprocMessages);
499 CopyMemory(pos, messages, strlen(messages) + 1);
501 *ppErrorMsgs = buffer;
504 HeapFree(GetProcessHeap(), 0, messages);
509 ERR("Asm reading failed\n");
510 return D3DXERR_INVALIDDATA;
513 hr = SlWriteBytecode(shader, 9, &res);
514 SlDeleteShader(shader);
517 ERR("SlWriteBytecode failed with 0x%08x\n", hr);
518 return D3DXERR_INVALIDDATA;
523 size = HeapSize(GetProcessHeap(), 0, res);
524 hr = D3DXCreateBuffer(size, &buffer);
527 HeapFree(GetProcessHeap(), 0, res);
530 CopyMemory(ID3DXBuffer_GetBufferPointer(buffer), res, size);
534 HeapFree(GetProcessHeap(), 0, res);
539 HRESULT WINAPI D3DXAssembleShader(LPCSTR data,
541 CONST D3DXMACRO* defines,
542 LPD3DXINCLUDE include,
544 LPD3DXBUFFER* shader,
545 LPD3DXBUFFER* error_messages)
549 CONST D3DXMACRO* def = defines;
551 static const struct wpp_callbacks wpp_callbacks = {
561 EnterCriticalSection(&wpp_mutex);
564 if(flags) FIXME("flags: %x\n", flags);
568 while(def->Name != NULL)
570 wpp_add_define(def->Name, def->Definition);
574 current_include = include;
577 if(shader) *shader = NULL;
578 if(error_messages) *error_messages = NULL;
579 wpp_output_size = wpp_output_capacity = 0;
582 /* Preprocess shader */
583 wpp_set_callbacks(&wpp_callbacks);
584 wpp_messages_size = wpp_messages_capacity = 0;
586 current_shader.buffer = data;
587 current_shader.size = data_len;
589 ret = wpp_parse("", NULL);
590 if(!wpp_close_output())
594 TRACE("Error during shader preprocessing\n");
600 TRACE("Preprocessor messages:\n");
601 TRACE("%s", wpp_messages);
605 size = strlen(wpp_messages) + 1;
606 hr = D3DXCreateBuffer(size, &buffer);
607 if(FAILED(hr)) goto cleanup;
608 CopyMemory(ID3DXBuffer_GetBufferPointer(buffer), wpp_messages, size);
609 *error_messages = buffer;
614 TRACE("Shader source:\n");
615 TRACE("%s\n", debugstr_an(data, data_len));
617 hr = D3DXERR_INVALIDDATA;
621 hr = assemble_shader(wpp_output, wpp_messages, shader, error_messages);
624 /* Remove the previously added defines */
627 while(defines->Name != NULL)
629 wpp_del_define(defines->Name);
633 HeapFree(GetProcessHeap(), 0, wpp_messages);
634 HeapFree(GetProcessHeap(), 0, wpp_output);
635 LeaveCriticalSection(&wpp_mutex);
639 /* D3DXInclude private implementation, used to implement
640 D3DXAssembleShaderFromFile from D3DXAssembleShader */
641 /* To be able to correctly resolve include search paths we have to store
642 the pathname of each include file. We store the pathname pointer right
643 before the file data. */
644 static HRESULT WINAPI d3dincludefromfile_open(ID3DXInclude *iface,
645 D3DXINCLUDE_TYPE include_type,
646 LPCSTR filename, LPCVOID parent_data,
647 LPCVOID *data, UINT *bytes) {
648 const char *p, *parent_name = "";
649 char *pathname = NULL;
650 char **buffer = NULL;
654 if(parent_data != NULL)
655 parent_name = *((const char **)parent_data - 1);
657 TRACE("Looking up for include file %s, parent %s\n", debugstr_a(filename), debugstr_a(parent_name));
659 if ((p = strrchr(parent_name, '\\')) || (p = strrchr(parent_name, '/'))) p++;
660 else p = parent_name;
661 pathname = HeapAlloc(GetProcessHeap(), 0, (p - parent_name) + strlen(filename) + 1);
663 return HRESULT_FROM_WIN32(GetLastError());
665 memcpy(pathname, parent_name, p - parent_name);
666 strcpy(pathname + (p - parent_name), filename);
668 file = CreateFileA(pathname, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
669 if(file == INVALID_HANDLE_VALUE)
672 TRACE("Include file found at pathname = %s\n", debugstr_a(pathname));
674 size = GetFileSize(file, NULL);
675 if(size == INVALID_FILE_SIZE)
678 buffer = HeapAlloc(GetProcessHeap(), 0, size + sizeof(char *));
682 if(!ReadFile(file, buffer + 1, size, bytes, NULL))
692 HeapFree(GetProcessHeap(), 0, pathname);
693 HeapFree(GetProcessHeap(), 0, buffer);
694 return HRESULT_FROM_WIN32(GetLastError());
697 static HRESULT WINAPI d3dincludefromfile_close(ID3DXInclude *iface, LPCVOID data) {
698 HeapFree(GetProcessHeap(), 0, *((char **)data - 1));
699 HeapFree(GetProcessHeap(), 0, (char **)data - 1);
703 static const struct ID3DXIncludeVtbl D3DXInclude_Vtbl = {
704 d3dincludefromfile_open,
705 d3dincludefromfile_close
708 struct D3DXIncludeImpl {
709 const ID3DXIncludeVtbl *lpVtbl;
712 HRESULT WINAPI D3DXAssembleShaderFromFileA(LPCSTR filename,
713 CONST D3DXMACRO* defines,
714 LPD3DXINCLUDE include,
716 LPD3DXBUFFER* shader,
717 LPD3DXBUFFER* error_messages)
719 LPWSTR filename_w = NULL;
723 if (!filename) return D3DXERR_INVALIDDATA;
725 len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
726 filename_w = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
727 if (!filename_w) return E_OUTOFMEMORY;
728 MultiByteToWideChar(CP_ACP, 0, filename, -1, filename_w, len);
730 ret = D3DXAssembleShaderFromFileW(filename_w, defines, include, flags, shader, error_messages);
732 HeapFree(GetProcessHeap(), 0, filename_w);
736 HRESULT WINAPI D3DXAssembleShaderFromFileW(LPCWSTR filename,
737 CONST D3DXMACRO* defines,
738 LPD3DXINCLUDE include,
740 LPD3DXBUFFER* shader,
741 LPD3DXBUFFER* error_messages)
746 struct D3DXIncludeImpl includefromfile;
748 if(FAILED(map_view_of_file(filename, &buffer, &len)))
749 return D3DXERR_INVALIDDATA;
753 includefromfile.lpVtbl = &D3DXInclude_Vtbl;
754 include = (LPD3DXINCLUDE)&includefromfile;
757 hr = D3DXAssembleShader(buffer, len, defines, include, flags,
758 shader, error_messages);
760 UnmapViewOfFile(buffer);
764 HRESULT WINAPI D3DXAssembleShaderFromResourceA(HMODULE module,
766 CONST D3DXMACRO* defines,
767 LPD3DXINCLUDE include,
769 LPD3DXBUFFER* shader,
770 LPD3DXBUFFER* error_messages)
776 if (!(res = FindResourceA(module, resource, (LPCSTR)RT_RCDATA)))
777 return D3DXERR_INVALIDDATA;
778 if (FAILED(load_resource_into_memory(module, res, (LPVOID *)&buffer, &len)))
779 return D3DXERR_INVALIDDATA;
780 return D3DXAssembleShader(buffer, len, defines, include, flags,
781 shader, error_messages);
784 HRESULT WINAPI D3DXAssembleShaderFromResourceW(HMODULE module,
786 CONST D3DXMACRO* defines,
787 LPD3DXINCLUDE include,
789 LPD3DXBUFFER* shader,
790 LPD3DXBUFFER* error_messages)
796 if (!(res = FindResourceW(module, resource, (LPCWSTR)RT_RCDATA)))
797 return D3DXERR_INVALIDDATA;
798 if (FAILED(load_resource_into_memory(module, res, (LPVOID *)&buffer, &len)))
799 return D3DXERR_INVALIDDATA;
800 return D3DXAssembleShader(buffer, len, defines, include, flags,
801 shader, error_messages);
804 HRESULT WINAPI D3DXCompileShader(LPCSTR pSrcData,
806 CONST D3DXMACRO* pDefines,
807 LPD3DXINCLUDE pInclude,
808 LPCSTR pFunctionName,
811 LPD3DXBUFFER* ppShader,
812 LPD3DXBUFFER* ppErrorMsgs,
813 LPD3DXCONSTANTTABLE * ppConstantTable)
815 FIXME("(%p, %d, %p, %p, %s, %s, %x, %p, %p, %p): stub\n",
816 pSrcData, srcDataLen, pDefines, pInclude, debugstr_a(pFunctionName),
817 debugstr_a(pProfile), Flags, ppShader, ppErrorMsgs, ppConstantTable);
819 TRACE("Shader source:\n");
820 TRACE("%s\n", debugstr_an(pSrcData, srcDataLen));
823 D3DXCreateBuffer(1, ppErrorMsgs); /* zero fill used as string end */
824 return D3DERR_INVALIDCALL;
827 static const struct ID3DXConstantTableVtbl ID3DXConstantTable_Vtbl;
829 typedef struct ID3DXConstantTableImpl {
830 const ID3DXConstantTableVtbl *lpVtbl;
834 D3DXCONSTANTTABLE_DESC desc;
835 } ID3DXConstantTableImpl;
837 /*** IUnknown methods ***/
838 static HRESULT WINAPI ID3DXConstantTableImpl_QueryInterface(ID3DXConstantTable* iface, REFIID riid, void** ppvObject)
840 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
842 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
844 if (IsEqualGUID(riid, &IID_IUnknown) ||
845 IsEqualGUID(riid, &IID_ID3DXBuffer) ||
846 IsEqualGUID(riid, &IID_ID3DXConstantTable))
848 ID3DXConstantTable_AddRef(iface);
853 WARN("Interface %s not found.\n", debugstr_guid(riid));
855 return E_NOINTERFACE;
858 static ULONG WINAPI ID3DXConstantTableImpl_AddRef(ID3DXConstantTable* iface)
860 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
862 TRACE("(%p)->(): AddRef from %d\n", This, This->ref);
864 return InterlockedIncrement(&This->ref);
867 static ULONG WINAPI ID3DXConstantTableImpl_Release(ID3DXConstantTable* iface)
869 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
870 ULONG ref = InterlockedDecrement(&This->ref);
872 TRACE("(%p)->(): Release from %d\n", This, ref + 1);
876 HeapFree(GetProcessHeap(), 0, This->ctab);
877 HeapFree(GetProcessHeap(), 0, This);
883 /*** ID3DXBuffer methods ***/
884 static LPVOID WINAPI ID3DXConstantTableImpl_GetBufferPointer(ID3DXConstantTable* iface)
886 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
888 TRACE("(%p)->()\n", This);
893 static DWORD WINAPI ID3DXConstantTableImpl_GetBufferSize(ID3DXConstantTable* iface)
895 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
897 TRACE("(%p)->()\n", This);
902 /*** ID3DXConstantTable methods ***/
903 static HRESULT WINAPI ID3DXConstantTableImpl_GetDesc(ID3DXConstantTable* iface, D3DXCONSTANTTABLE_DESC *desc)
905 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
907 TRACE("(%p)->(%p)\n", This, desc);
910 return D3DERR_INVALIDCALL;
912 memcpy(desc, &This->desc, sizeof(This->desc));
917 static HRESULT WINAPI ID3DXConstantTableImpl_GetConstantDesc(ID3DXConstantTable* iface, D3DXHANDLE constant,
918 D3DXCONSTANT_DESC *desc, UINT *count)
920 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
922 FIXME("(%p)->(%p, %p, %p): stub\n", This, constant, desc, count);
927 static UINT WINAPI ID3DXConstantTableImpl_GetSamplerIndex(LPD3DXCONSTANTTABLE iface, D3DXHANDLE constant)
929 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
931 FIXME("(%p)->(%p): stub\n", This, constant);
936 static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstant(ID3DXConstantTable* iface, D3DXHANDLE constant, UINT index)
938 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
940 FIXME("(%p)->(%p, %d): stub\n", This, constant, index);
945 static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstantByName(ID3DXConstantTable* iface, D3DXHANDLE constant, LPCSTR name)
947 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
949 FIXME("(%p)->(%p, %s): stub\n", This, constant, name);
954 static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstantElement(ID3DXConstantTable* iface, D3DXHANDLE constant, UINT index)
956 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
958 FIXME("(%p)->(%p, %d): stub\n", This, constant, index);
963 static HRESULT WINAPI ID3DXConstantTableImpl_SetDefaults(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device)
965 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
967 FIXME("(%p)->(%p): stub\n", This, device);
972 static HRESULT WINAPI ID3DXConstantTableImpl_SetValue(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
973 D3DXHANDLE constant, LPCVOID data, UINT bytes)
975 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
977 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, data, bytes);
982 static HRESULT WINAPI ID3DXConstantTableImpl_SetBool(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
983 D3DXHANDLE constant, BOOL b)
985 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
987 FIXME("(%p)->(%p, %p, %d): stub\n", This, device, constant, b);
992 static HRESULT WINAPI ID3DXConstantTableImpl_SetBoolArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
993 D3DXHANDLE constant, CONST BOOL* b, UINT count)
995 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
997 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, b, count);
1002 static HRESULT WINAPI ID3DXConstantTableImpl_SetInt(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device, D3DXHANDLE constant, INT n)
1004 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
1006 FIXME("(%p)->(%p, %p, %d): stub\n", This, device, constant, n);
1011 static HRESULT WINAPI ID3DXConstantTableImpl_SetIntArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
1012 D3DXHANDLE constant, CONST INT* n, UINT count)
1014 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
1016 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, n, count);
1021 static HRESULT WINAPI ID3DXConstantTableImpl_SetFloat(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
1022 D3DXHANDLE constant, FLOAT f)
1024 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
1026 FIXME("(%p)->(%p, %p, %f): stub\n", This, device, constant, f);
1031 static HRESULT WINAPI ID3DXConstantTableImpl_SetFloatArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
1032 D3DXHANDLE constant, CONST FLOAT* f, UINT count)
1034 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
1036 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, f, count);
1041 static HRESULT WINAPI ID3DXConstantTableImpl_SetVector(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
1042 D3DXHANDLE constant, CONST D3DXVECTOR4* vector)
1044 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
1046 FIXME("(%p)->(%p, %p, %p): stub\n", This, device, constant, vector);
1051 static HRESULT WINAPI ID3DXConstantTableImpl_SetVectorArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
1052 D3DXHANDLE constant, CONST D3DXVECTOR4* vector, UINT count)
1054 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
1056 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, vector, count);
1061 static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrix(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
1062 D3DXHANDLE constant, CONST D3DXMATRIX* matrix)
1064 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
1066 FIXME("(%p)->(%p, %p, %p): stub\n", This, device, constant, matrix);
1071 static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
1072 D3DXHANDLE constant, CONST D3DXMATRIX* matrix, UINT count)
1074 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
1076 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, matrix, count);
1081 static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixPointerArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
1082 D3DXHANDLE constant, CONST D3DXMATRIX** matrix, UINT count)
1084 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
1086 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, matrix, count);
1091 static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixTranspose(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
1092 D3DXHANDLE constant, CONST D3DXMATRIX* matrix)
1094 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
1096 FIXME("(%p)->(%p, %p, %p): stub\n", This, device, constant, matrix);
1101 static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixTransposeArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
1102 D3DXHANDLE constant, CONST D3DXMATRIX* matrix, UINT count)
1104 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
1106 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, matrix, count);
1111 static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixTransposePointerArray(ID3DXConstantTable* iface, LPDIRECT3DDEVICE9 device,
1112 D3DXHANDLE constant, CONST D3DXMATRIX** matrix, UINT count)
1114 ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
1116 FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, matrix, count);
1121 static const struct ID3DXConstantTableVtbl ID3DXConstantTable_Vtbl =
1123 /*** IUnknown methods ***/
1124 ID3DXConstantTableImpl_QueryInterface,
1125 ID3DXConstantTableImpl_AddRef,
1126 ID3DXConstantTableImpl_Release,
1127 /*** ID3DXBuffer methods ***/
1128 ID3DXConstantTableImpl_GetBufferPointer,
1129 ID3DXConstantTableImpl_GetBufferSize,
1130 /*** ID3DXConstantTable methods ***/
1131 ID3DXConstantTableImpl_GetDesc,
1132 ID3DXConstantTableImpl_GetConstantDesc,
1133 ID3DXConstantTableImpl_GetSamplerIndex,
1134 ID3DXConstantTableImpl_GetConstant,
1135 ID3DXConstantTableImpl_GetConstantByName,
1136 ID3DXConstantTableImpl_GetConstantElement,
1137 ID3DXConstantTableImpl_SetDefaults,
1138 ID3DXConstantTableImpl_SetValue,
1139 ID3DXConstantTableImpl_SetBool,
1140 ID3DXConstantTableImpl_SetBoolArray,
1141 ID3DXConstantTableImpl_SetInt,
1142 ID3DXConstantTableImpl_SetIntArray,
1143 ID3DXConstantTableImpl_SetFloat,
1144 ID3DXConstantTableImpl_SetFloatArray,
1145 ID3DXConstantTableImpl_SetVector,
1146 ID3DXConstantTableImpl_SetVectorArray,
1147 ID3DXConstantTableImpl_SetMatrix,
1148 ID3DXConstantTableImpl_SetMatrixArray,
1149 ID3DXConstantTableImpl_SetMatrixPointerArray,
1150 ID3DXConstantTableImpl_SetMatrixTranspose,
1151 ID3DXConstantTableImpl_SetMatrixTransposeArray,
1152 ID3DXConstantTableImpl_SetMatrixTransposePointerArray
1155 HRESULT WINAPI D3DXGetShaderConstantTableEx(CONST DWORD* byte_code,
1157 LPD3DXCONSTANTTABLE* constant_table)
1159 ID3DXConstantTableImpl* object = NULL;
1163 const D3DXSHADER_CONSTANTTABLE* ctab_header;
1165 FIXME("(%p, %x, %p): semi-stub\n", byte_code, flags, constant_table);
1167 if (!byte_code || !constant_table)
1168 return D3DERR_INVALIDCALL;
1170 hr = D3DXFindShaderComment(byte_code, MAKEFOURCC('C','T','A','B'), &data, &size);
1172 return D3DXERR_INVALIDDATA;
1174 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXConstantTableImpl));
1177 ERR("Out of memory\n");
1178 return E_OUTOFMEMORY;
1181 object->lpVtbl = &ID3DXConstantTable_Vtbl;
1184 if (size < sizeof(D3DXSHADER_CONSTANTTABLE))
1187 object->ctab = HeapAlloc(GetProcessHeap(), 0, size);
1190 HeapFree(GetProcessHeap(), 0, object);
1191 ERR("Out of memory\n");
1192 return E_OUTOFMEMORY;
1194 object->size = size;
1195 memcpy(object->ctab, data, object->size);
1197 ctab_header = (const D3DXSHADER_CONSTANTTABLE*)data;
1198 if (ctab_header->Size != sizeof(D3DXSHADER_CONSTANTTABLE))
1200 object->desc.Creator = ctab_header->Creator ? (LPCSTR)object->ctab + ctab_header->Creator : NULL;
1201 object->desc.Version = ctab_header->Version;
1202 object->desc.Constants = ctab_header->Constants;
1204 *constant_table = (LPD3DXCONSTANTTABLE)object;
1210 HeapFree(GetProcessHeap(), 0, object->ctab);
1211 HeapFree(GetProcessHeap(), 0, object);
1213 return D3DXERR_INVALIDDATA;
1216 HRESULT WINAPI D3DXGetShaderConstantTable(CONST DWORD* byte_code,
1217 LPD3DXCONSTANTTABLE* constant_table)
1219 TRACE("(%p, %p): Forwarded to D3DXGetShaderConstantTableEx\n", byte_code, constant_table);
1221 return D3DXGetShaderConstantTableEx(byte_code, 0, constant_table);