2008-07-14 22:47:19 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Luis Busquets
|
2010-03-28 16:00:36 +02:00
|
|
|
* Copyright 2009 Matteo Bruni
|
2011-06-21 21:14:30 +02:00
|
|
|
* Copyright 2011 Travis Athougies
|
2008-07-14 22:47:19 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
2011-06-25 13:26:25 +02:00
|
|
|
|
2008-07-14 22:47:19 +02:00
|
|
|
#include "wine/debug.h"
|
2009-09-15 20:17:14 +02:00
|
|
|
#include "wine/unicode.h"
|
2008-07-14 22:47:19 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "wingdi.h"
|
2010-08-24 23:05:12 +02:00
|
|
|
#include "objbase.h"
|
|
|
|
#include "d3dcommon.h"
|
2010-08-25 18:43:42 +02:00
|
|
|
#include "d3dcompiler.h"
|
2009-09-15 20:23:00 +02:00
|
|
|
#include "d3dx9_36_private.h"
|
2008-07-14 22:47:19 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
|
|
|
|
|
2013-09-02 09:45:44 +02:00
|
|
|
/* This function is not declared in the SDK headers yet. */
|
|
|
|
HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filename,
|
|
|
|
const D3D_SHADER_MACRO *defines, ID3DInclude *include, UINT flags,
|
|
|
|
ID3DBlob **shader, ID3DBlob **error_messages);
|
2010-08-24 23:05:12 +02:00
|
|
|
|
2013-01-07 21:57:07 +01:00
|
|
|
static inline BOOL is_valid_bytecode(DWORD token)
|
|
|
|
{
|
|
|
|
return (token & 0xfffe0000) == 0xfffe0000;
|
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
const char * WINAPI D3DXGetPixelShaderProfile(struct IDirect3DDevice9 *device)
|
2008-08-01 21:18:08 +02:00
|
|
|
{
|
|
|
|
D3DCAPS9 caps;
|
|
|
|
|
2008-08-24 23:43:27 +02:00
|
|
|
TRACE("device %p\n", device);
|
2008-08-01 21:18:08 +02:00
|
|
|
|
|
|
|
if (!device) return NULL;
|
|
|
|
|
|
|
|
IDirect3DDevice9_GetDeviceCaps(device,&caps);
|
|
|
|
|
|
|
|
switch (caps.PixelShaderVersion)
|
|
|
|
{
|
|
|
|
case D3DPS_VERSION(1, 1):
|
|
|
|
return "ps_1_1";
|
|
|
|
|
|
|
|
case D3DPS_VERSION(1, 2):
|
|
|
|
return "ps_1_2";
|
|
|
|
|
|
|
|
case D3DPS_VERSION(1, 3):
|
|
|
|
return "ps_1_3";
|
|
|
|
|
|
|
|
case D3DPS_VERSION(1, 4):
|
|
|
|
return "ps_1_4";
|
|
|
|
|
|
|
|
case D3DPS_VERSION(2, 0):
|
|
|
|
if ((caps.PS20Caps.NumTemps>=22) &&
|
|
|
|
(caps.PS20Caps.Caps&D3DPS20CAPS_ARBITRARYSWIZZLE) &&
|
|
|
|
(caps.PS20Caps.Caps&D3DPS20CAPS_GRADIENTINSTRUCTIONS) &&
|
|
|
|
(caps.PS20Caps.Caps&D3DPS20CAPS_PREDICATION) &&
|
|
|
|
(caps.PS20Caps.Caps&D3DPS20CAPS_NODEPENDENTREADLIMIT) &&
|
|
|
|
(caps.PS20Caps.Caps&D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT))
|
|
|
|
{
|
|
|
|
return "ps_2_a";
|
|
|
|
}
|
|
|
|
if ((caps.PS20Caps.NumTemps>=32) &&
|
|
|
|
(caps.PS20Caps.Caps&D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT))
|
|
|
|
{
|
|
|
|
return "ps_2_b";
|
|
|
|
}
|
|
|
|
return "ps_2_0";
|
|
|
|
|
|
|
|
case D3DPS_VERSION(3, 0):
|
|
|
|
return "ps_3_0";
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-07-14 22:47:19 +02:00
|
|
|
UINT WINAPI D3DXGetShaderSize(const DWORD *byte_code)
|
|
|
|
{
|
|
|
|
const DWORD *ptr = byte_code;
|
|
|
|
|
|
|
|
TRACE("byte_code %p\n", byte_code);
|
|
|
|
|
|
|
|
if (!ptr) return 0;
|
|
|
|
|
|
|
|
/* Look for the END token, skipping the VERSION token */
|
|
|
|
while (*++ptr != D3DSIO_END)
|
|
|
|
{
|
|
|
|
/* Skip comments */
|
|
|
|
if ((*ptr & D3DSI_OPCODE_MASK) == D3DSIO_COMMENT)
|
|
|
|
{
|
|
|
|
ptr += ((*ptr & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++ptr;
|
|
|
|
|
|
|
|
/* Return the shader size in bytes */
|
|
|
|
return (ptr - byte_code) * sizeof(*ptr);
|
|
|
|
}
|
2008-07-20 22:07:42 +02:00
|
|
|
|
|
|
|
DWORD WINAPI D3DXGetShaderVersion(const DWORD *byte_code)
|
|
|
|
{
|
|
|
|
TRACE("byte_code %p\n", byte_code);
|
|
|
|
|
|
|
|
return byte_code ? *byte_code : 0;
|
|
|
|
}
|
2008-08-01 21:19:11 +02:00
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
const char * WINAPI D3DXGetVertexShaderProfile(struct IDirect3DDevice9 *device)
|
2008-08-01 21:19:11 +02:00
|
|
|
{
|
|
|
|
D3DCAPS9 caps;
|
|
|
|
|
2008-08-24 23:43:27 +02:00
|
|
|
TRACE("device %p\n", device);
|
2008-08-01 21:19:11 +02:00
|
|
|
|
|
|
|
if (!device) return NULL;
|
|
|
|
|
|
|
|
IDirect3DDevice9_GetDeviceCaps(device,&caps);
|
|
|
|
|
|
|
|
switch (caps.VertexShaderVersion)
|
|
|
|
{
|
|
|
|
case D3DVS_VERSION(1, 1):
|
|
|
|
return "vs_1_1";
|
|
|
|
case D3DVS_VERSION(2, 0):
|
|
|
|
if ((caps.VS20Caps.NumTemps>=13) &&
|
2008-08-05 07:09:57 +02:00
|
|
|
(caps.VS20Caps.DynamicFlowControlDepth==24) &&
|
2008-08-01 21:19:11 +02:00
|
|
|
(caps.VS20Caps.Caps&D3DPS20CAPS_PREDICATION))
|
|
|
|
{
|
|
|
|
return "vs_2_a";
|
|
|
|
}
|
|
|
|
return "vs_2_0";
|
|
|
|
case D3DVS_VERSION(3, 0):
|
|
|
|
return "vs_3_0";
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-09-15 20:17:14 +02:00
|
|
|
|
2013-01-07 21:57:07 +01:00
|
|
|
HRESULT WINAPI D3DXFindShaderComment(const DWORD *byte_code, DWORD fourcc, const void **data, UINT *size)
|
2010-03-01 09:39:24 +01:00
|
|
|
{
|
2013-01-07 21:57:07 +01:00
|
|
|
const DWORD *ptr = byte_code;
|
2013-09-30 01:19:00 +02:00
|
|
|
DWORD version;
|
2010-03-01 09:39:24 +01:00
|
|
|
|
2013-01-07 21:57:07 +01:00
|
|
|
TRACE("byte_code %p, fourcc %x, data %p, size %p\n", byte_code, fourcc, data, size);
|
2010-03-01 09:39:24 +01:00
|
|
|
|
2011-10-25 10:39:25 +02:00
|
|
|
if (data) *data = NULL;
|
|
|
|
if (size) *size = 0;
|
|
|
|
|
2013-01-07 21:57:07 +01:00
|
|
|
if (!byte_code) return D3DERR_INVALIDCALL;
|
2013-09-30 01:19:00 +02:00
|
|
|
|
|
|
|
version = *ptr >> 16;
|
|
|
|
if (version != 0x4658 /* FX */
|
|
|
|
&& version != 0x5458 /* TX */
|
|
|
|
&& version != 0x7ffe
|
|
|
|
&& version != 0x7fff
|
|
|
|
&& version != 0xfffe /* VS */
|
|
|
|
&& version != 0xffff) /* PS */
|
|
|
|
{
|
|
|
|
WARN("Invalid data supplied\n");
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
2010-03-01 09:39:24 +01:00
|
|
|
|
|
|
|
while (*++ptr != D3DSIO_END)
|
|
|
|
{
|
|
|
|
/* Check if it is a comment */
|
|
|
|
if ((*ptr & D3DSI_OPCODE_MASK) == D3DSIO_COMMENT)
|
|
|
|
{
|
|
|
|
DWORD comment_size = (*ptr & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
|
|
|
|
|
|
|
|
/* Check if this is the comment we are looking for */
|
|
|
|
if (*(ptr + 1) == fourcc)
|
|
|
|
{
|
2010-03-04 08:20:44 +01:00
|
|
|
UINT ctab_size = (comment_size - 1) * sizeof(DWORD);
|
2013-09-03 09:47:25 +02:00
|
|
|
const void *ctab_data = ptr + 2;
|
2010-03-01 09:39:24 +01:00
|
|
|
if (size)
|
2010-03-04 08:20:44 +01:00
|
|
|
*size = ctab_size;
|
2010-03-01 09:39:24 +01:00
|
|
|
if (data)
|
2010-03-04 08:20:44 +01:00
|
|
|
*data = ctab_data;
|
|
|
|
TRACE("Returning comment data at %p with size %d\n", ctab_data, ctab_size);
|
2010-03-01 09:39:24 +01:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
ptr += comment_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-24 17:17:05 +01:00
|
|
|
HRESULT WINAPI D3DXAssembleShader(const char *data, UINT data_len, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, DWORD flags, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
|
2009-09-15 20:17:14 +02:00
|
|
|
{
|
2013-07-22 08:48:17 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("data %p, data_len %u, defines %p, include %p, flags %#x, shader %p, error_messages %p\n",
|
|
|
|
data, data_len, defines, include, flags, shader, error_messages);
|
|
|
|
|
2010-08-24 23:05:12 +02:00
|
|
|
/* Forward to d3dcompiler: the parameter types aren't really different,
|
|
|
|
the actual data types are equivalent */
|
2013-07-22 08:48:17 +02:00
|
|
|
hr = D3DAssemble(data, data_len, NULL, (D3D_SHADER_MACRO *)defines,
|
|
|
|
(ID3DInclude *)include, flags, (ID3DBlob **)shader,
|
|
|
|
(ID3DBlob **)error_messages);
|
2010-03-28 16:00:36 +02:00
|
|
|
|
2010-08-24 23:05:12 +02:00
|
|
|
if(hr == E_FAIL) hr = D3DXERR_INVALIDDATA;
|
2010-03-28 16:00:36 +02:00
|
|
|
return hr;
|
2009-09-15 20:17:14 +02:00
|
|
|
}
|
|
|
|
|
2014-06-26 19:52:33 +02:00
|
|
|
static const void *main_file_data;
|
|
|
|
|
|
|
|
static CRITICAL_SECTION from_file_mutex;
|
|
|
|
static CRITICAL_SECTION_DEBUG from_file_mutex_debug =
|
|
|
|
{
|
|
|
|
0, 0, &from_file_mutex,
|
|
|
|
{
|
|
|
|
&from_file_mutex_debug.ProcessLocksList,
|
|
|
|
&from_file_mutex_debug.ProcessLocksList
|
|
|
|
},
|
|
|
|
0, 0, {(DWORD_PTR)(__FILE__ ": from_file_mutex")}
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION from_file_mutex = {&from_file_mutex_debug, -1, 0, 0, 0, 0};
|
|
|
|
|
2010-07-28 17:32:42 +02:00
|
|
|
/* D3DXInclude private implementation, used to implement
|
2013-09-02 09:45:44 +02:00
|
|
|
* D3DXAssembleShaderFromFile() from D3DXAssembleShader(). */
|
|
|
|
/* To be able to correctly resolve include search paths we have to store the
|
|
|
|
* pathname of each include file. We store the pathname pointer right before
|
|
|
|
* the file data. */
|
|
|
|
static HRESULT WINAPI d3dincludefromfile_open(ID3DXInclude *iface, D3DXINCLUDE_TYPE include_type,
|
|
|
|
const char *filename, const void *parent_data, const void **data, UINT *bytes)
|
|
|
|
{
|
2010-07-28 17:32:42 +02:00
|
|
|
const char *p, *parent_name = "";
|
2014-08-25 20:36:51 +02:00
|
|
|
char *pathname = NULL, *ptr;
|
2010-07-28 17:32:42 +02:00
|
|
|
char **buffer = NULL;
|
|
|
|
HANDLE file;
|
|
|
|
UINT size;
|
|
|
|
|
2014-06-26 19:52:33 +02:00
|
|
|
if (parent_data)
|
|
|
|
{
|
2010-07-28 17:32:42 +02:00
|
|
|
parent_name = *((const char **)parent_data - 1);
|
2014-06-26 19:52:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (main_file_data)
|
|
|
|
parent_name = *((const char **)main_file_data - 1);
|
|
|
|
}
|
2010-07-28 17:32:42 +02:00
|
|
|
|
|
|
|
TRACE("Looking up for include file %s, parent %s\n", debugstr_a(filename), debugstr_a(parent_name));
|
|
|
|
|
2014-08-25 20:36:51 +02:00
|
|
|
if ((p = strrchr(parent_name, '\\')))
|
|
|
|
++p;
|
|
|
|
else
|
|
|
|
p = parent_name;
|
2010-07-28 17:32:42 +02:00
|
|
|
pathname = HeapAlloc(GetProcessHeap(), 0, (p - parent_name) + strlen(filename) + 1);
|
|
|
|
if(!pathname)
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
|
|
|
memcpy(pathname, parent_name, p - parent_name);
|
|
|
|
strcpy(pathname + (p - parent_name), filename);
|
2014-08-25 20:36:51 +02:00
|
|
|
ptr = pathname + (p - parent_name);
|
|
|
|
while (*ptr)
|
|
|
|
{
|
|
|
|
if (*ptr == '/')
|
|
|
|
*ptr = '\\';
|
|
|
|
++ptr;
|
|
|
|
}
|
2010-07-28 17:32:42 +02:00
|
|
|
|
|
|
|
file = CreateFileA(pathname, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
|
|
|
|
if(file == INVALID_HANDLE_VALUE)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
TRACE("Include file found at pathname = %s\n", debugstr_a(pathname));
|
|
|
|
|
|
|
|
size = GetFileSize(file, NULL);
|
|
|
|
if(size == INVALID_FILE_SIZE)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(), 0, size + sizeof(char *));
|
|
|
|
if(!buffer)
|
|
|
|
goto error;
|
|
|
|
*buffer = pathname;
|
|
|
|
if(!ReadFile(file, buffer + 1, size, bytes, NULL))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
*data = buffer + 1;
|
2014-06-26 19:52:33 +02:00
|
|
|
if (!main_file_data)
|
|
|
|
main_file_data = *data;
|
2010-07-28 17:32:42 +02:00
|
|
|
|
|
|
|
CloseHandle(file);
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
error:
|
|
|
|
CloseHandle(file);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pathname);
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
|
|
|
|
2013-09-03 09:47:25 +02:00
|
|
|
static HRESULT WINAPI d3dincludefromfile_close(ID3DXInclude *iface, const void *data)
|
|
|
|
{
|
2010-07-28 17:32:42 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, *((char **)data - 1));
|
|
|
|
HeapFree(GetProcessHeap(), 0, (char **)data - 1);
|
2014-06-26 19:52:33 +02:00
|
|
|
if (main_file_data == data)
|
|
|
|
main_file_data = NULL;
|
2010-07-28 17:32:42 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ID3DXIncludeVtbl D3DXInclude_Vtbl = {
|
|
|
|
d3dincludefromfile_open,
|
|
|
|
d3dincludefromfile_close
|
|
|
|
};
|
|
|
|
|
|
|
|
struct D3DXIncludeImpl {
|
2011-01-27 00:21:38 +01:00
|
|
|
ID3DXInclude ID3DXInclude_iface;
|
2010-07-28 17:32:42 +02:00
|
|
|
};
|
|
|
|
|
2012-11-24 17:17:05 +01:00
|
|
|
HRESULT WINAPI D3DXAssembleShaderFromFileA(const char *filename, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, DWORD flags, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
|
2009-09-15 20:17:14 +02:00
|
|
|
{
|
2013-09-02 09:45:43 +02:00
|
|
|
WCHAR *filename_w;
|
2009-09-15 20:17:14 +02:00
|
|
|
DWORD len;
|
|
|
|
HRESULT ret;
|
|
|
|
|
2013-09-02 09:45:43 +02:00
|
|
|
TRACE("filename %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
|
|
|
|
debugstr_a(filename), defines, include, flags, shader, error_messages);
|
|
|
|
|
2009-09-15 20:17:14 +02:00
|
|
|
if (!filename) return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
|
|
|
|
filename_w = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!filename_w) return E_OUTOFMEMORY;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, filename, -1, filename_w, len);
|
|
|
|
|
|
|
|
ret = D3DXAssembleShaderFromFileW(filename_w, defines, include, flags, shader, error_messages);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, filename_w);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-24 17:17:05 +01:00
|
|
|
HRESULT WINAPI D3DXAssembleShaderFromFileW(const WCHAR *filename, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, DWORD flags, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
|
2009-09-15 20:17:14 +02:00
|
|
|
{
|
2013-09-03 16:29:43 +02:00
|
|
|
const void *buffer;
|
2010-07-28 17:32:42 +02:00
|
|
|
DWORD len;
|
|
|
|
HRESULT hr;
|
|
|
|
struct D3DXIncludeImpl includefromfile;
|
2013-09-03 16:29:43 +02:00
|
|
|
char *filename_a;
|
2010-07-28 17:32:42 +02:00
|
|
|
|
2013-09-03 16:29:42 +02:00
|
|
|
TRACE("filename %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
|
|
|
|
debugstr_w(filename), defines, include, flags, shader, error_messages);
|
|
|
|
|
2010-07-28 17:32:42 +02:00
|
|
|
if(!include)
|
|
|
|
{
|
2011-01-27 00:21:38 +01:00
|
|
|
includefromfile.ID3DXInclude_iface.lpVtbl = &D3DXInclude_Vtbl;
|
|
|
|
include = &includefromfile.ID3DXInclude_iface;
|
2010-07-28 17:32:42 +02:00
|
|
|
}
|
|
|
|
|
2013-09-03 16:29:43 +02:00
|
|
|
len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL);
|
|
|
|
filename_a = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
|
|
|
|
if (!filename_a)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL);
|
2010-07-28 17:32:42 +02:00
|
|
|
|
2014-06-26 19:52:33 +02:00
|
|
|
EnterCriticalSection(&from_file_mutex);
|
2013-09-03 16:29:43 +02:00
|
|
|
hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2014-06-26 19:52:33 +02:00
|
|
|
LeaveCriticalSection(&from_file_mutex);
|
2013-09-03 16:29:43 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, filename_a);
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = D3DXAssembleShader(buffer, len, defines, include, flags, shader, error_messages);
|
|
|
|
|
|
|
|
ID3DXInclude_Close(include, buffer);
|
2014-06-26 19:52:33 +02:00
|
|
|
LeaveCriticalSection(&from_file_mutex);
|
2013-09-03 16:29:43 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, filename_a);
|
2010-07-28 17:32:42 +02:00
|
|
|
return hr;
|
2009-09-15 20:17:14 +02:00
|
|
|
}
|
2009-09-15 20:23:00 +02:00
|
|
|
|
2012-11-24 17:17:05 +01:00
|
|
|
HRESULT WINAPI D3DXAssembleShaderFromResourceA(HMODULE module, const char *resource, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, DWORD flags, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
|
2009-09-15 20:23:00 +02:00
|
|
|
{
|
2013-08-30 08:42:47 +02:00
|
|
|
void *buffer;
|
2009-09-15 20:23:00 +02:00
|
|
|
HRSRC res;
|
|
|
|
DWORD len;
|
|
|
|
|
2013-09-03 16:29:42 +02:00
|
|
|
TRACE("module %p, resource %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
|
|
|
|
module, debugstr_a(resource), defines, include, flags, shader, error_messages);
|
|
|
|
|
2013-09-02 09:45:44 +02:00
|
|
|
if (!(res = FindResourceA(module, resource, (const char *)RT_RCDATA)))
|
2009-09-15 20:23:00 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
2013-08-30 08:42:47 +02:00
|
|
|
if (FAILED(load_resource_into_memory(module, res, &buffer, &len)))
|
2009-09-15 20:23:00 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
return D3DXAssembleShader(buffer, len, defines, include, flags,
|
|
|
|
shader, error_messages);
|
|
|
|
}
|
|
|
|
|
2012-11-24 17:17:05 +01:00
|
|
|
HRESULT WINAPI D3DXAssembleShaderFromResourceW(HMODULE module, const WCHAR *resource, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, DWORD flags, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
|
2009-09-15 20:23:00 +02:00
|
|
|
{
|
2013-08-30 08:42:47 +02:00
|
|
|
void *buffer;
|
2009-09-15 20:23:00 +02:00
|
|
|
HRSRC res;
|
|
|
|
DWORD len;
|
|
|
|
|
2013-08-30 08:42:48 +02:00
|
|
|
TRACE("module %p, resource %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
|
|
|
|
module, debugstr_w(resource), defines, include, flags, shader, error_messages);
|
|
|
|
|
|
|
|
if (!(res = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA)))
|
2009-09-15 20:23:00 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
2013-08-30 08:42:47 +02:00
|
|
|
if (FAILED(load_resource_into_memory(module, res, &buffer, &len)))
|
2009-09-15 20:23:00 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
return D3DXAssembleShader(buffer, len, defines, include, flags,
|
|
|
|
shader, error_messages);
|
|
|
|
}
|
2010-02-11 07:38:08 +01:00
|
|
|
|
2013-07-22 08:48:17 +02:00
|
|
|
HRESULT WINAPI D3DXCompileShader(const char *data, UINT length, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, const char *function, const char *profile, DWORD flags,
|
|
|
|
ID3DXBuffer **shader, ID3DXBuffer **error_msgs, ID3DXConstantTable **constant_table)
|
2010-02-11 07:38:08 +01:00
|
|
|
{
|
2013-07-22 08:48:17 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2013-09-03 16:29:42 +02:00
|
|
|
TRACE("data %s, length %u, defines %p, include %p, function %s, profile %s, "
|
|
|
|
"flags %#x, shader %p, error_msgs %p, constant_table %p.\n",
|
|
|
|
debugstr_a(data), length, defines, include, debugstr_a(function), debugstr_a(profile),
|
|
|
|
flags, shader, error_msgs, constant_table);
|
2013-07-22 08:48:17 +02:00
|
|
|
|
|
|
|
hr = D3DCompile(data, length, NULL, (D3D_SHADER_MACRO *)defines, (ID3DInclude *)include,
|
|
|
|
function, profile, flags, 0, (ID3DBlob **)shader, (ID3DBlob **)error_msgs);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr) && constant_table)
|
2013-07-23 08:20:30 +02:00
|
|
|
{
|
2013-07-22 08:48:17 +02:00
|
|
|
hr = D3DXGetShaderConstantTable(ID3DXBuffer_GetBufferPointer(*shader), constant_table);
|
2013-07-23 08:20:30 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ID3DXBuffer_Release(*shader);
|
|
|
|
*shader = NULL;
|
|
|
|
}
|
|
|
|
}
|
2013-07-22 08:48:17 +02:00
|
|
|
|
2010-08-25 18:43:42 +02:00
|
|
|
return hr;
|
2010-02-11 07:38:08 +01:00
|
|
|
}
|
2010-02-21 22:30:27 +01:00
|
|
|
|
2012-11-22 21:13:36 +01:00
|
|
|
HRESULT WINAPI D3DXCompileShaderFromFileA(const char *filename, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, const char *entrypoint, const char *profile, DWORD flags,
|
|
|
|
ID3DXBuffer **shader, ID3DXBuffer **error_messages, ID3DXConstantTable **constant_table)
|
2010-09-01 22:53:13 +02:00
|
|
|
{
|
2013-09-02 09:45:43 +02:00
|
|
|
WCHAR *filename_w;
|
2010-09-01 22:53:13 +02:00
|
|
|
DWORD len;
|
|
|
|
HRESULT ret;
|
|
|
|
|
2013-09-02 09:45:43 +02:00
|
|
|
TRACE("filename %s, defines %p, include %p, entrypoint %s, profile %s, "
|
|
|
|
"flags %#x, shader %p, error_messages %p, constant_table %p.\n",
|
|
|
|
debugstr_a(filename), defines, include, debugstr_a(entrypoint),
|
|
|
|
debugstr_a(profile), flags, shader, error_messages, constant_table);
|
|
|
|
|
2010-09-01 22:53:13 +02:00
|
|
|
if (!filename) return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
|
|
|
|
filename_w = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!filename_w) return E_OUTOFMEMORY;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, filename, -1, filename_w, len);
|
|
|
|
|
|
|
|
ret = D3DXCompileShaderFromFileW(filename_w, defines, include,
|
|
|
|
entrypoint, profile, flags,
|
|
|
|
shader, error_messages, constant_table);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, filename_w);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-22 21:13:36 +01:00
|
|
|
HRESULT WINAPI D3DXCompileShaderFromFileW(const WCHAR *filename, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, const char *entrypoint, const char *profile, DWORD flags,
|
|
|
|
ID3DXBuffer **shader, ID3DXBuffer **error_messages, ID3DXConstantTable **constant_table)
|
2010-09-01 22:53:13 +02:00
|
|
|
{
|
2013-09-03 16:29:43 +02:00
|
|
|
const void *buffer;
|
2010-09-08 16:07:07 +02:00
|
|
|
DWORD len, filename_len;
|
2010-09-01 22:53:13 +02:00
|
|
|
HRESULT hr;
|
|
|
|
struct D3DXIncludeImpl includefromfile;
|
|
|
|
char *filename_a;
|
|
|
|
|
2013-09-03 16:29:42 +02:00
|
|
|
TRACE("filename %s, defines %p, include %p, entrypoint %s, profile %s, "
|
|
|
|
"flags %#x, shader %p, error_messages %p, constant_table %p.\n",
|
|
|
|
debugstr_w(filename), defines, include, debugstr_a(entrypoint), debugstr_a(profile),
|
|
|
|
flags, shader, error_messages, constant_table);
|
|
|
|
|
2010-09-01 22:53:13 +02:00
|
|
|
if (!include)
|
|
|
|
{
|
2011-01-27 00:21:38 +01:00
|
|
|
includefromfile.ID3DXInclude_iface.lpVtbl = &D3DXInclude_Vtbl;
|
|
|
|
include = &includefromfile.ID3DXInclude_iface;
|
2010-09-01 22:53:13 +02:00
|
|
|
}
|
|
|
|
|
2010-09-08 16:07:07 +02:00
|
|
|
filename_len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL);
|
|
|
|
filename_a = HeapAlloc(GetProcessHeap(), 0, filename_len * sizeof(char));
|
2010-09-01 22:53:13 +02:00
|
|
|
if (!filename_a)
|
|
|
|
return E_OUTOFMEMORY;
|
2010-09-08 16:07:07 +02:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, filename_len, NULL, NULL);
|
2010-09-01 22:53:13 +02:00
|
|
|
|
2014-06-26 19:52:33 +02:00
|
|
|
EnterCriticalSection(&from_file_mutex);
|
2013-09-03 16:29:43 +02:00
|
|
|
hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2014-06-26 19:52:33 +02:00
|
|
|
LeaveCriticalSection(&from_file_mutex);
|
2013-09-03 16:29:43 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, filename_a);
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2010-09-09 18:41:39 +02:00
|
|
|
hr = D3DCompile(buffer, len, filename_a, (const D3D_SHADER_MACRO *)defines,
|
2010-09-01 22:53:13 +02:00
|
|
|
(ID3DInclude *)include, entrypoint, profile, flags, 0,
|
|
|
|
(ID3DBlob **)shader, (ID3DBlob **)error_messages);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr) && constant_table)
|
|
|
|
hr = D3DXGetShaderConstantTable(ID3DXBuffer_GetBufferPointer(*shader),
|
|
|
|
constant_table);
|
|
|
|
|
2013-09-03 16:29:43 +02:00
|
|
|
ID3DXInclude_Close(include, buffer);
|
2014-06-26 19:52:33 +02:00
|
|
|
LeaveCriticalSection(&from_file_mutex);
|
2010-09-01 22:53:13 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, filename_a);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-11-22 21:13:36 +01:00
|
|
|
HRESULT WINAPI D3DXCompileShaderFromResourceA(HMODULE module, const char *resource, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, const char *entrypoint, const char *profile, DWORD flags,
|
|
|
|
ID3DXBuffer **shader, ID3DXBuffer **error_messages, ID3DXConstantTable **constant_table)
|
2010-09-01 23:15:44 +02:00
|
|
|
{
|
2013-08-30 08:42:47 +02:00
|
|
|
void *buffer;
|
2010-09-01 23:15:44 +02:00
|
|
|
HRSRC res;
|
|
|
|
DWORD len;
|
|
|
|
|
2013-09-03 16:29:42 +02:00
|
|
|
TRACE("module %p, resource %s, defines %p, include %p, entrypoint %s, profile %s, "
|
|
|
|
"flags %#x, shader %p, error_messages %p, constant_table %p.\n",
|
|
|
|
module, debugstr_a(resource), defines, include, debugstr_a(entrypoint), debugstr_a(profile),
|
|
|
|
flags, shader, error_messages, constant_table);
|
|
|
|
|
2013-09-02 09:45:44 +02:00
|
|
|
if (!(res = FindResourceA(module, resource, (const char *)RT_RCDATA)))
|
2010-09-01 23:15:44 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
2013-08-30 08:42:47 +02:00
|
|
|
if (FAILED(load_resource_into_memory(module, res, &buffer, &len)))
|
2010-09-01 23:15:44 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
return D3DXCompileShader(buffer, len, defines, include, entrypoint, profile,
|
|
|
|
flags, shader, error_messages, constant_table);
|
|
|
|
}
|
|
|
|
|
2012-11-22 21:13:36 +01:00
|
|
|
HRESULT WINAPI D3DXCompileShaderFromResourceW(HMODULE module, const WCHAR *resource, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, const char *entrypoint, const char *profile, DWORD flags,
|
|
|
|
ID3DXBuffer **shader, ID3DXBuffer **error_messages, ID3DXConstantTable **constant_table)
|
2010-09-01 23:15:44 +02:00
|
|
|
{
|
2013-08-30 08:42:47 +02:00
|
|
|
void *buffer;
|
2010-09-01 23:15:44 +02:00
|
|
|
HRSRC res;
|
|
|
|
DWORD len;
|
|
|
|
|
2013-08-30 08:42:48 +02:00
|
|
|
TRACE("module %p, resource %s, defines %p, include %p, entrypoint %s, profile %s, "
|
|
|
|
"flags %#x, shader %p, error_messages %p, constant_table %p.\n",
|
|
|
|
module, debugstr_w(resource), defines, include, debugstr_a(entrypoint), debugstr_a(profile),
|
|
|
|
flags, shader, error_messages, constant_table);
|
|
|
|
|
|
|
|
if (!(res = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA)))
|
2010-09-01 23:15:44 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
2013-08-30 08:42:47 +02:00
|
|
|
if (FAILED(load_resource_into_memory(module, res, &buffer, &len)))
|
2010-09-01 23:15:44 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
return D3DXCompileShader(buffer, len, defines, include, entrypoint, profile,
|
|
|
|
flags, shader, error_messages, constant_table);
|
|
|
|
}
|
|
|
|
|
2012-11-24 17:17:05 +01:00
|
|
|
HRESULT WINAPI D3DXPreprocessShader(const char *data, UINT data_len, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
|
2010-09-09 18:41:39 +02:00
|
|
|
{
|
2013-09-03 16:29:42 +02:00
|
|
|
TRACE("data %s, data_len %u, defines %p, include %p, shader %p, error_messages %p.\n",
|
|
|
|
debugstr_a(data), data_len, defines, include, shader, error_messages);
|
|
|
|
|
2010-09-09 18:41:39 +02:00
|
|
|
return D3DPreprocess(data, data_len, NULL,
|
|
|
|
(const D3D_SHADER_MACRO *)defines, (ID3DInclude *)include,
|
|
|
|
(ID3DBlob **)shader, (ID3DBlob **)error_messages);
|
|
|
|
}
|
|
|
|
|
2012-11-24 17:17:05 +01:00
|
|
|
HRESULT WINAPI D3DXPreprocessShaderFromFileA(const char *filename, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
|
2010-09-09 18:41:39 +02:00
|
|
|
{
|
|
|
|
WCHAR *filename_w = NULL;
|
|
|
|
DWORD len;
|
|
|
|
HRESULT ret;
|
|
|
|
|
2013-09-03 16:29:42 +02:00
|
|
|
TRACE("filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
|
|
|
|
debugstr_a(filename), defines, include, shader, error_messages);
|
|
|
|
|
2010-09-09 18:41:39 +02:00
|
|
|
if (!filename) return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
|
|
|
|
filename_w = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!filename_w) return E_OUTOFMEMORY;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, filename, -1, filename_w, len);
|
|
|
|
|
|
|
|
ret = D3DXPreprocessShaderFromFileW(filename_w, defines, include, shader, error_messages);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, filename_w);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-24 17:17:05 +01:00
|
|
|
HRESULT WINAPI D3DXPreprocessShaderFromFileW(const WCHAR *filename, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
|
2010-09-09 18:41:39 +02:00
|
|
|
{
|
2013-09-03 16:29:43 +02:00
|
|
|
const void *buffer;
|
2010-09-14 21:56:21 +02:00
|
|
|
DWORD len;
|
2010-09-09 18:41:39 +02:00
|
|
|
HRESULT hr;
|
|
|
|
struct D3DXIncludeImpl includefromfile;
|
2013-09-03 16:29:43 +02:00
|
|
|
char *filename_a;
|
2010-09-09 18:41:39 +02:00
|
|
|
|
2013-09-03 16:29:42 +02:00
|
|
|
TRACE("filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
|
|
|
|
debugstr_w(filename), defines, include, shader, error_messages);
|
|
|
|
|
2010-09-09 18:41:39 +02:00
|
|
|
if (!include)
|
|
|
|
{
|
2011-01-27 00:21:38 +01:00
|
|
|
includefromfile.ID3DXInclude_iface.lpVtbl = &D3DXInclude_Vtbl;
|
|
|
|
include = &includefromfile.ID3DXInclude_iface;
|
2010-09-09 18:41:39 +02:00
|
|
|
}
|
|
|
|
|
2013-09-03 16:29:43 +02:00
|
|
|
len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL);
|
|
|
|
filename_a = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
|
|
|
|
if (!filename_a)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL);
|
|
|
|
|
2014-06-26 19:52:33 +02:00
|
|
|
EnterCriticalSection(&from_file_mutex);
|
2013-09-03 16:29:43 +02:00
|
|
|
hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2014-06-26 19:52:33 +02:00
|
|
|
LeaveCriticalSection(&from_file_mutex);
|
2013-09-03 16:29:43 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, filename_a);
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2010-09-09 18:41:39 +02:00
|
|
|
hr = D3DPreprocess(buffer, len, NULL,
|
|
|
|
(const D3D_SHADER_MACRO *)defines,
|
|
|
|
(ID3DInclude *) include,
|
|
|
|
(ID3DBlob **)shader, (ID3DBlob **)error_messages);
|
|
|
|
|
2013-09-03 16:29:43 +02:00
|
|
|
ID3DXInclude_Close(include, buffer);
|
2014-06-26 19:52:33 +02:00
|
|
|
LeaveCriticalSection(&from_file_mutex);
|
2013-09-03 16:29:43 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, filename_a);
|
2010-09-09 18:41:39 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-11-24 17:17:05 +01:00
|
|
|
HRESULT WINAPI D3DXPreprocessShaderFromResourceA(HMODULE module, const char *resource, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
|
2010-09-09 18:41:39 +02:00
|
|
|
{
|
2013-08-30 08:42:47 +02:00
|
|
|
void *buffer;
|
2010-09-09 18:41:39 +02:00
|
|
|
HRSRC res;
|
|
|
|
DWORD len;
|
|
|
|
|
2013-09-03 16:29:42 +02:00
|
|
|
TRACE("module %p, resource %s, defines %p, include %p, shader %p, error_messages %p.\n",
|
|
|
|
module, debugstr_a(resource), defines, include, shader, error_messages);
|
|
|
|
|
2013-09-02 09:45:44 +02:00
|
|
|
if (!(res = FindResourceA(module, resource, (const char *)RT_RCDATA)))
|
2010-09-09 18:41:39 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
2013-08-30 08:42:47 +02:00
|
|
|
if (FAILED(load_resource_into_memory(module, res, &buffer, &len)))
|
2010-09-09 18:41:39 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
return D3DXPreprocessShader(buffer, len, defines, include,
|
|
|
|
shader, error_messages);
|
|
|
|
}
|
|
|
|
|
2012-11-24 17:17:05 +01:00
|
|
|
HRESULT WINAPI D3DXPreprocessShaderFromResourceW(HMODULE module, const WCHAR *resource, const D3DXMACRO *defines,
|
|
|
|
ID3DXInclude *include, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
|
2010-09-09 18:41:39 +02:00
|
|
|
{
|
2013-08-30 08:42:47 +02:00
|
|
|
void *buffer;
|
2010-09-09 18:41:39 +02:00
|
|
|
HRSRC res;
|
|
|
|
DWORD len;
|
|
|
|
|
2013-09-03 16:29:42 +02:00
|
|
|
TRACE("module %p, resource %s, defines %p, include %p, shader %p, error_messages %p.\n",
|
|
|
|
module, debugstr_w(resource), defines, include, shader, error_messages);
|
|
|
|
|
2010-09-09 18:41:39 +02:00
|
|
|
if (!(res = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2013-08-30 08:42:47 +02:00
|
|
|
if (FAILED(load_resource_into_memory(module, res, &buffer, &len)))
|
2010-09-09 18:41:39 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
return D3DXPreprocessShader(buffer, len, defines, include,
|
|
|
|
shader, error_messages);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-08-23 21:36:27 +02:00
|
|
|
struct ctab_constant {
|
2010-09-10 18:42:45 +02:00
|
|
|
D3DXCONSTANT_DESC desc;
|
2012-08-23 21:36:50 +02:00
|
|
|
struct ctab_constant *constants;
|
2012-08-23 21:36:27 +02:00
|
|
|
};
|
2010-09-10 18:42:45 +02:00
|
|
|
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl {
|
2010-12-21 11:30:28 +01:00
|
|
|
ID3DXConstantTable ID3DXConstantTable_iface;
|
2010-03-01 09:39:18 +01:00
|
|
|
LONG ref;
|
2010-09-10 18:42:45 +02:00
|
|
|
char *ctab;
|
2010-03-01 09:39:29 +01:00
|
|
|
DWORD size;
|
2010-03-19 11:54:05 +01:00
|
|
|
D3DXCONSTANTTABLE_DESC desc;
|
2012-08-23 21:36:27 +02:00
|
|
|
struct ctab_constant *constants;
|
2012-01-22 11:29:03 +01:00
|
|
|
};
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-23 21:36:50 +02:00
|
|
|
static void free_constant(struct ctab_constant *constant)
|
|
|
|
{
|
|
|
|
if (constant->constants)
|
|
|
|
{
|
|
|
|
UINT i, count = constant->desc.Elements > 1 ? constant->desc.Elements : constant->desc.StructMembers;
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
free_constant(&constant->constants[i]);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, constant->constants);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-22 11:28:52 +01:00
|
|
|
static void free_constant_table(struct ID3DXConstantTableImpl *table)
|
|
|
|
{
|
2012-08-23 21:36:50 +02:00
|
|
|
if (table->constants)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
for (i = 0; i < table->desc.Constants; ++i)
|
|
|
|
{
|
|
|
|
free_constant(&table->constants[i]);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, table->constants);
|
|
|
|
}
|
2012-01-22 11:28:52 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, table->ctab);
|
|
|
|
}
|
|
|
|
|
2012-01-22 11:29:03 +01:00
|
|
|
static inline struct ID3DXConstantTableImpl *impl_from_ID3DXConstantTable(ID3DXConstantTable *iface)
|
2010-12-21 11:30:28 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
return CONTAINING_RECORD(iface, struct ID3DXConstantTableImpl, ID3DXConstantTable_iface);
|
2010-12-21 11:30:28 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 22:23:31 +01:00
|
|
|
static inline BOOL is_vertex_shader(DWORD version)
|
2011-06-21 21:14:30 +02:00
|
|
|
{
|
2013-01-10 22:23:31 +01:00
|
|
|
return (version & 0xffff0000) == 0xfffe0000;
|
2011-06-21 21:14:30 +02:00
|
|
|
}
|
|
|
|
|
2012-08-23 21:36:46 +02:00
|
|
|
static inline D3DXHANDLE handle_from_constant(struct ctab_constant *constant)
|
2012-08-14 11:42:30 +02:00
|
|
|
{
|
2012-08-23 21:36:46 +02:00
|
|
|
return (D3DXHANDLE)constant;
|
2012-08-14 11:42:30 +02:00
|
|
|
}
|
|
|
|
|
2013-09-02 09:45:44 +02:00
|
|
|
static struct ctab_constant *get_constant_by_name(struct ID3DXConstantTableImpl *table,
|
|
|
|
struct ctab_constant *constant, const char *name);
|
2012-08-25 16:28:12 +02:00
|
|
|
|
2013-09-02 09:45:44 +02:00
|
|
|
static struct ctab_constant *get_constant_element_by_name(struct ctab_constant *constant, const char *name)
|
2012-08-25 16:28:12 +02:00
|
|
|
{
|
2013-09-02 09:45:44 +02:00
|
|
|
const char *part;
|
2012-08-25 16:28:12 +02:00
|
|
|
UINT element;
|
|
|
|
|
|
|
|
TRACE("constant %p, name %s\n", constant, debugstr_a(name));
|
|
|
|
|
|
|
|
if (!name || !*name) return NULL;
|
|
|
|
|
|
|
|
element = atoi(name);
|
|
|
|
part = strchr(name, ']') + 1;
|
|
|
|
|
|
|
|
if (constant->desc.Elements > element)
|
|
|
|
{
|
|
|
|
struct ctab_constant *c = constant->constants ? &constant->constants[element] : constant;
|
|
|
|
|
|
|
|
switch (*part++)
|
|
|
|
{
|
|
|
|
case '.':
|
|
|
|
return get_constant_by_name(NULL, c, part);
|
|
|
|
|
|
|
|
case '[':
|
|
|
|
return get_constant_element_by_name(c, part);
|
|
|
|
|
|
|
|
case '\0':
|
|
|
|
TRACE("Returning parameter %p\n", c);
|
|
|
|
return c;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled case \"%c\"\n", *--part);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Constant not found\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ctab_constant *get_constant_by_name(struct ID3DXConstantTableImpl *table,
|
2013-09-02 09:45:44 +02:00
|
|
|
struct ctab_constant *constant, const char *name)
|
2012-08-25 16:28:12 +02:00
|
|
|
{
|
|
|
|
UINT i, count, length;
|
|
|
|
struct ctab_constant *handles;
|
2013-09-02 09:45:44 +02:00
|
|
|
const char *part;
|
2012-08-25 16:28:12 +02:00
|
|
|
|
|
|
|
TRACE("table %p, constant %p, name %s\n", table, constant, debugstr_a(name));
|
|
|
|
|
|
|
|
if (!name || !*name) return NULL;
|
|
|
|
|
|
|
|
if (!constant)
|
|
|
|
{
|
|
|
|
count = table->desc.Constants;
|
|
|
|
handles = table->constants;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
count = constant->desc.StructMembers;
|
|
|
|
handles = constant->constants;
|
|
|
|
}
|
|
|
|
|
2012-09-04 09:44:38 +02:00
|
|
|
length = strcspn(name, "[.");
|
2012-08-25 16:28:12 +02:00
|
|
|
part = name + length;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (strlen(handles[i].desc.Name) == length && !strncmp(handles[i].desc.Name, name, length))
|
|
|
|
{
|
|
|
|
switch (*part++)
|
|
|
|
{
|
|
|
|
case '.':
|
|
|
|
return get_constant_by_name(NULL, &handles[i], part);
|
|
|
|
|
|
|
|
case '[':
|
|
|
|
return get_constant_element_by_name(&handles[i], part);
|
|
|
|
|
2012-09-04 09:44:38 +02:00
|
|
|
default:
|
2012-08-25 16:28:12 +02:00
|
|
|
TRACE("Returning parameter %p\n", &handles[i]);
|
|
|
|
return &handles[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Constant not found\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:34 +02:00
|
|
|
static struct ctab_constant *is_valid_sub_constant(struct ctab_constant *parent, D3DXHANDLE handle)
|
2012-08-23 21:36:58 +02:00
|
|
|
{
|
2013-07-22 14:35:34 +02:00
|
|
|
struct ctab_constant *c;
|
2012-08-23 21:36:58 +02:00
|
|
|
UINT i, count;
|
|
|
|
|
2013-07-22 14:35:34 +02:00
|
|
|
/* all variable have at least elements = 1, but not always elements */
|
2012-08-23 21:36:58 +02:00
|
|
|
if (!parent->constants) return NULL;
|
|
|
|
|
2013-07-22 14:35:34 +02:00
|
|
|
count = parent->desc.Elements > 1 ? parent->desc.Elements : parent->desc.StructMembers;
|
2012-08-23 21:36:58 +02:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
2013-07-22 14:35:34 +02:00
|
|
|
if (handle_from_constant(&parent->constants[i]) == handle)
|
|
|
|
return &parent->constants[i];
|
2012-08-23 21:36:58 +02:00
|
|
|
|
2013-07-22 14:35:34 +02:00
|
|
|
c = is_valid_sub_constant(&parent->constants[i], handle);
|
|
|
|
if (c) return c;
|
2012-08-23 21:36:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:34 +02:00
|
|
|
static inline struct ctab_constant *get_valid_constant(struct ID3DXConstantTableImpl *table, D3DXHANDLE handle)
|
2012-08-14 11:42:30 +02:00
|
|
|
{
|
2013-07-22 14:35:34 +02:00
|
|
|
struct ctab_constant *c;
|
2012-08-23 21:36:46 +02:00
|
|
|
UINT i;
|
|
|
|
|
2013-07-22 14:35:34 +02:00
|
|
|
if (!handle) return NULL;
|
2012-08-23 21:36:46 +02:00
|
|
|
|
|
|
|
for (i = 0; i < table->desc.Constants; ++i)
|
|
|
|
{
|
2013-07-22 14:35:34 +02:00
|
|
|
if (handle_from_constant(&table->constants[i]) == handle)
|
|
|
|
return &table->constants[i];
|
2012-08-23 21:36:58 +02:00
|
|
|
|
2013-07-22 14:35:34 +02:00
|
|
|
c = is_valid_sub_constant(&table->constants[i], handle);
|
|
|
|
if (c) return c;
|
2012-08-23 21:36:46 +02:00
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:34 +02:00
|
|
|
return get_constant_by_name(table, NULL, handle);
|
2012-08-25 16:28:12 +02:00
|
|
|
}
|
|
|
|
|
2010-03-01 09:39:18 +01:00
|
|
|
/*** IUnknown methods ***/
|
2012-04-08 19:13:25 +02:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_QueryInterface(ID3DXConstantTable *iface, REFIID riid, void **out)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-04-08 19:13:25 +02:00
|
|
|
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
2010-03-14 21:53:21 +01:00
|
|
|
IsEqualGUID(riid, &IID_ID3DXBuffer) ||
|
2010-03-01 09:39:18 +01:00
|
|
|
IsEqualGUID(riid, &IID_ID3DXConstantTable))
|
|
|
|
{
|
|
|
|
ID3DXConstantTable_AddRef(iface);
|
2012-04-08 19:13:25 +02:00
|
|
|
*out = iface;
|
2010-03-01 09:39:18 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-14 21:53:22 +01:00
|
|
|
WARN("Interface %s not found.\n", debugstr_guid(riid));
|
2010-03-01 09:39:18 +01:00
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2012-01-22 11:29:03 +01:00
|
|
|
static ULONG WINAPI ID3DXConstantTableImpl_AddRef(ID3DXConstantTable *iface)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(): AddRef from %d\n", This, This->ref);
|
|
|
|
|
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
2012-01-22 11:28:52 +01:00
|
|
|
static ULONG WINAPI ID3DXConstantTableImpl_Release(ID3DXConstantTable *iface)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(): Release from %d\n", This, ref + 1);
|
|
|
|
|
|
|
|
if (!ref)
|
2010-03-01 09:39:29 +01:00
|
|
|
{
|
2012-01-22 11:28:52 +01:00
|
|
|
free_constant_table(This);
|
2010-03-01 09:39:18 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2010-03-01 09:39:29 +01:00
|
|
|
}
|
2010-03-01 09:39:18 +01:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** ID3DXBuffer methods ***/
|
2013-09-04 08:56:46 +02:00
|
|
|
static void * WINAPI ID3DXConstantTableImpl_GetBufferPointer(ID3DXConstantTable *iface)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2013-09-04 08:56:46 +02:00
|
|
|
struct ID3DXConstantTableImpl *table = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-09-04 08:56:46 +02:00
|
|
|
TRACE("iface %p.\n", iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-09-04 08:56:46 +02:00
|
|
|
return table->ctab;
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-01-22 11:29:03 +01:00
|
|
|
static DWORD WINAPI ID3DXConstantTableImpl_GetBufferSize(ID3DXConstantTable *iface)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2010-03-01 09:39:29 +01:00
|
|
|
TRACE("(%p)->()\n", This);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2010-03-01 09:39:29 +01:00
|
|
|
return This->size;
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** ID3DXConstantTable methods ***/
|
2012-01-22 11:29:03 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_GetDesc(ID3DXConstantTable *iface, D3DXCONSTANTTABLE_DESC *desc)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2010-03-19 11:54:05 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, desc);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2010-03-19 11:54:05 +01:00
|
|
|
if (!desc)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
2012-09-03 09:57:49 +02:00
|
|
|
*desc = This->desc;
|
2010-03-19 11:54:05 +01:00
|
|
|
|
|
|
|
return D3D_OK;
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-01-22 11:29:03 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_GetConstantDesc(ID3DXConstantTable *iface, D3DXHANDLE constant,
|
2010-03-01 09:39:18 +01:00
|
|
|
D3DXCONSTANT_DESC *desc, UINT *count)
|
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2012-08-25 16:28:27 +02:00
|
|
|
struct ctab_constant *c = get_valid_constant(This, constant);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2010-09-10 18:42:45 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p)\n", This, constant, desc, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-25 16:28:27 +02:00
|
|
|
if (!c)
|
2011-07-18 21:45:13 +02:00
|
|
|
{
|
2012-08-25 16:28:27 +02:00
|
|
|
WARN("Invalid argument specified\n");
|
|
|
|
return D3DERR_INVALIDCALL;
|
2011-07-18 21:45:13 +02:00
|
|
|
}
|
2010-09-10 18:42:45 +02:00
|
|
|
|
2012-08-25 16:28:27 +02:00
|
|
|
if (desc) *desc = c->desc;
|
|
|
|
if (count) *count = 1;
|
2010-09-10 18:42:45 +02:00
|
|
|
|
|
|
|
return D3D_OK;
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2011-06-22 22:10:51 +02:00
|
|
|
static UINT WINAPI ID3DXConstantTableImpl_GetSamplerIndex(ID3DXConstantTable *iface, D3DXHANDLE constant)
|
2010-03-19 11:54:11 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2012-08-28 13:43:14 +02:00
|
|
|
struct ctab_constant *c = get_valid_constant(This, constant);
|
2011-06-22 22:10:51 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, constant);
|
|
|
|
|
2012-08-28 13:43:14 +02:00
|
|
|
if (!c || c->desc.RegisterSet != D3DXRS_SAMPLER)
|
|
|
|
{
|
|
|
|
WARN("Invalid argument specified\n");
|
2011-06-22 22:10:51 +02:00
|
|
|
return (UINT)-1;
|
2012-08-28 13:43:14 +02:00
|
|
|
}
|
2010-03-19 11:54:11 +01:00
|
|
|
|
2012-08-28 13:43:14 +02:00
|
|
|
TRACE("Returning RegisterIndex %u\n", c->desc.RegisterIndex);
|
|
|
|
return c->desc.RegisterIndex;
|
2010-03-19 11:54:11 +01:00
|
|
|
}
|
|
|
|
|
2012-01-22 11:29:03 +01:00
|
|
|
static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstant(ID3DXConstantTable *iface, D3DXHANDLE constant, UINT index)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2012-08-25 16:28:22 +02:00
|
|
|
struct ctab_constant *c;
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2010-09-10 18:42:45 +02:00
|
|
|
TRACE("(%p)->(%p, %d)\n", This, constant, index);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2011-07-18 21:45:13 +02:00
|
|
|
if (constant)
|
2011-07-14 23:06:49 +02:00
|
|
|
{
|
2012-08-25 16:28:22 +02:00
|
|
|
c = get_valid_constant(This, constant);
|
|
|
|
if (c && index < c->desc.StructMembers)
|
|
|
|
{
|
|
|
|
c = &c->constants[index];
|
|
|
|
TRACE("Returning constant %p\n", c);
|
|
|
|
return handle_from_constant(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (index < This->desc.Constants)
|
|
|
|
{
|
|
|
|
c = &This->constants[index];
|
|
|
|
TRACE("Returning constant %p\n", c);
|
|
|
|
return handle_from_constant(c);
|
|
|
|
}
|
2011-07-14 23:06:49 +02:00
|
|
|
}
|
2011-07-18 21:45:13 +02:00
|
|
|
|
2012-08-25 16:28:22 +02:00
|
|
|
WARN("Index out of range\n");
|
|
|
|
return NULL;
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2013-09-02 09:45:44 +02:00
|
|
|
static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstantByName(ID3DXConstantTable *iface,
|
|
|
|
D3DXHANDLE constant, const char *name)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2012-08-25 16:28:12 +02:00
|
|
|
struct ctab_constant *c = get_valid_constant(This, constant);
|
2010-09-10 18:42:45 +02:00
|
|
|
|
2013-09-02 09:45:44 +02:00
|
|
|
TRACE("iface %p, constant %p, name %s.\n", iface, constant, debugstr_a(name));
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-25 16:28:12 +02:00
|
|
|
c = get_constant_by_name(This, c, name);
|
|
|
|
TRACE("Returning constant %p\n", c);
|
2011-07-18 21:45:13 +02:00
|
|
|
|
2012-08-25 16:28:12 +02:00
|
|
|
return handle_from_constant(c);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-01-22 11:29:03 +01:00
|
|
|
static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstantElement(ID3DXConstantTable *iface, D3DXHANDLE constant, UINT index)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2012-08-25 16:28:30 +02:00
|
|
|
struct ctab_constant *c = get_valid_constant(This, constant);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p, %d)\n", This, constant, index);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-25 16:28:30 +02:00
|
|
|
if (c && index < c->desc.Elements)
|
|
|
|
{
|
2012-09-04 09:44:28 +02:00
|
|
|
if (c->desc.Elements > 1) c = &c->constants[index];
|
2012-08-25 16:28:30 +02:00
|
|
|
TRACE("Returning constant %p\n", c);
|
|
|
|
return handle_from_constant(c);
|
|
|
|
}
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-25 16:28:30 +02:00
|
|
|
WARN("Invalid argument specified\n");
|
2010-03-01 09:39:18 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
static inline DWORD get_index(const void **indata, UINT index, BOOL is_pointer)
|
2011-06-21 21:14:30 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
if (!indata)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (is_pointer)
|
|
|
|
return ((DWORD **)indata)[index / 16][index % 16];
|
|
|
|
|
|
|
|
return (*((DWORD **)indata))[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT set(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device, struct ctab_constant *constant,
|
|
|
|
const void **indata, D3DXPARAMETER_TYPE intype, UINT *size, UINT incol, D3DXPARAMETER_CLASS inclass, UINT index,
|
|
|
|
BOOL is_pointer)
|
|
|
|
{
|
|
|
|
D3DXCONSTANT_DESC *desc = &constant->desc;
|
|
|
|
UINT l, i, regcount = 1, regsize = 1, cin = 1, rin = 1, ret, last = 0;
|
|
|
|
DWORD tmp;
|
2011-06-21 21:14:30 +02:00
|
|
|
|
2014-01-06 02:13:41 +01:00
|
|
|
/* size too small to set anything */
|
2013-07-22 14:35:41 +02:00
|
|
|
if (*size < desc->Rows * desc->Columns)
|
2011-06-21 21:14:30 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
*size = 0;
|
|
|
|
return 0;
|
2011-06-21 21:14:30 +02:00
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
/* D3DXPC_STRUCT is somewhat special */
|
|
|
|
if (desc->Class == D3DXPC_STRUCT)
|
|
|
|
{
|
2013-07-24 22:30:21 +02:00
|
|
|
/*
|
|
|
|
* Struct array sets the last complete input to the first struct element, all other
|
|
|
|
* elements are not set.
|
|
|
|
* E.g.: struct {int i;} s1[2];
|
|
|
|
* SetValue(device, "s1", [1, 2], 8) => s1 = {2, x};
|
|
|
|
*
|
|
|
|
* struct {int i; int n} s2[2];
|
|
|
|
* SetValue(device, "s2", [1, 2, 3, 4, 5], 20) => s1 = {{3, 4}, {x, x}};
|
|
|
|
*/
|
|
|
|
if (desc->Elements > 1)
|
|
|
|
{
|
|
|
|
UINT offset = *size / (desc->Rows * desc->Columns) - 1;
|
|
|
|
|
|
|
|
offset = min(desc->Elements - 1, offset);
|
|
|
|
last = offset * desc->Rows * desc->Columns;
|
|
|
|
|
|
|
|
if ((is_pointer || (!is_pointer && inclass == D3DXPC_MATRIX_ROWS)) && desc->RegisterSet != D3DXRS_BOOL)
|
|
|
|
{
|
|
|
|
set(table, device, &constant->constants[0], NULL, intype, size, incol, inclass, 0, is_pointer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
last += set(table, device, &constant->constants[0], indata, intype, size, incol, inclass,
|
|
|
|
index + last, is_pointer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* D3DXRS_BOOL is always set. As there are only 16 bools and there are
|
|
|
|
* exactly 16 input values, use matrix transpose.
|
|
|
|
*/
|
|
|
|
if (inclass == D3DXPC_MATRIX_ROWS && desc->RegisterSet == D3DXRS_BOOL)
|
|
|
|
{
|
|
|
|
D3DXMATRIX mat, *m, min;
|
|
|
|
D3DXMatrixTranspose(&mat, &min);
|
|
|
|
|
|
|
|
if (is_pointer)
|
|
|
|
min = *(D3DXMATRIX *)(indata[index / 16]);
|
|
|
|
else
|
|
|
|
min = **(D3DXMATRIX **)indata;
|
|
|
|
|
|
|
|
D3DXMatrixTranspose(&mat, &min);
|
|
|
|
m = &mat;
|
|
|
|
for (i = 0; i < desc->StructMembers; ++i)
|
|
|
|
{
|
|
|
|
last += set(table, device, &constant->constants[i], (const void **)&m, intype, size, incol,
|
|
|
|
D3DXPC_SCALAR, index + last, is_pointer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* For pointers or for matrix rows, only the first member is set.
|
|
|
|
* All other members are set to 0. This is not true for D3DXRS_BOOL.
|
|
|
|
* E.g.: struct {int i; int n} s;
|
|
|
|
* SetValue(device, "s", [1, 2], 8) => s = {1, 0};
|
|
|
|
*/
|
|
|
|
else if ((is_pointer || (!is_pointer && inclass == D3DXPC_MATRIX_ROWS)) && desc->RegisterSet != D3DXRS_BOOL)
|
|
|
|
{
|
|
|
|
last = set(table, device, &constant->constants[0], indata, intype, size, incol, inclass,
|
|
|
|
index + last, is_pointer);
|
|
|
|
|
|
|
|
for (i = 1; i < desc->StructMembers; ++i)
|
|
|
|
{
|
|
|
|
set(table, device, &constant->constants[i], NULL, intype, size, incol, inclass, 0, is_pointer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < desc->StructMembers; ++i)
|
|
|
|
{
|
|
|
|
last += set(table, device, &constant->constants[i], indata, intype, size, incol, D3DXPC_SCALAR,
|
|
|
|
index + last, is_pointer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return last;
|
2013-07-22 14:35:41 +02:00
|
|
|
}
|
2012-08-21 14:52:16 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
/* elements */
|
|
|
|
if (desc->Elements > 1)
|
2011-06-21 21:14:30 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
for (i = 0; i < desc->Elements && *size > 0; ++i)
|
|
|
|
{
|
|
|
|
last += set(table, device, &constant->constants[i], indata, intype, size, incol, inclass,
|
|
|
|
index + last, is_pointer);
|
|
|
|
|
|
|
|
/* adjust the vector size for matrix rows */
|
|
|
|
if (inclass == D3DXPC_MATRIX_ROWS && desc->Class == D3DXPC_VECTOR && (i % 4) == 3)
|
2011-06-21 21:14:30 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
last += 12;
|
|
|
|
*size = *size < 12 ? 0 : *size - 12;
|
2011-06-21 21:14:30 +02:00
|
|
|
}
|
2013-07-22 14:35:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (desc->Class)
|
|
|
|
{
|
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
regcount = min(desc->RegisterCount, desc->Rows);
|
|
|
|
if (inclass == D3DXPC_MATRIX_ROWS) cin = incol;
|
|
|
|
else rin = incol;
|
|
|
|
regsize = desc->Columns;
|
2011-06-21 21:14:30 +02:00
|
|
|
break;
|
2013-07-22 14:35:41 +02:00
|
|
|
|
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
2013-09-18 23:16:33 +02:00
|
|
|
regcount = min(desc->RegisterCount, desc->Columns);
|
2013-07-22 14:35:41 +02:00
|
|
|
if (inclass == D3DXPC_MATRIX_ROWS) rin = incol;
|
|
|
|
else cin = incol;
|
|
|
|
regsize = desc->Rows;
|
|
|
|
break;
|
|
|
|
|
2011-06-21 21:14:30 +02:00
|
|
|
default:
|
2013-07-22 14:35:41 +02:00
|
|
|
FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc->Class));
|
|
|
|
return 0;
|
2011-06-21 21:14:30 +02:00
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
/* specific stuff for different in types */
|
|
|
|
switch (inclass)
|
|
|
|
{
|
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
ret = desc->Columns * desc->Rows;
|
|
|
|
*size -= desc->Columns * desc->Rows;
|
|
|
|
break;
|
2011-06-21 21:14:30 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
switch (desc->Class)
|
|
|
|
{
|
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
if (*size < regcount * 4)
|
|
|
|
{
|
|
|
|
*size = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ret = 4 * regcount;
|
|
|
|
*size -= 4 * regcount;
|
|
|
|
break;
|
2012-08-16 17:21:20 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
|
|
|
ret = 4 * regsize;
|
|
|
|
*size -= 4 * regcount;
|
|
|
|
break;
|
2012-08-16 17:21:20 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
ret = 1;
|
|
|
|
*size -= ret;
|
|
|
|
break;
|
2012-08-21 14:52:15 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
ret = 4;
|
|
|
|
*size -= ret;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc->Class));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
switch (desc->Class)
|
2012-08-16 17:21:20 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
|
|
|
if (*size < 16)
|
|
|
|
{
|
|
|
|
*size = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ret = 16;
|
|
|
|
break;
|
2012-08-16 17:21:20 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
ret = 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc->Class));
|
|
|
|
return 0;
|
2012-08-16 17:21:20 +02:00
|
|
|
}
|
2013-07-22 14:35:41 +02:00
|
|
|
*size -= ret;
|
2012-08-16 17:21:20 +02:00
|
|
|
break;
|
2013-07-22 14:35:41 +02:00
|
|
|
|
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
|
|
|
switch (desc->Class)
|
|
|
|
{
|
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
|
|
|
if (*size < 16)
|
|
|
|
{
|
|
|
|
*size = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ret = 16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
ret = 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc->Class));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*size -= ret;
|
|
|
|
break;
|
|
|
|
|
2012-08-16 17:21:20 +02:00
|
|
|
default:
|
2013-07-22 14:35:41 +02:00
|
|
|
FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(inclass));
|
|
|
|
return 0;
|
2012-08-16 17:21:20 +02:00
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
/* set the registers */
|
|
|
|
switch (desc->RegisterSet)
|
|
|
|
{
|
|
|
|
case D3DXRS_BOOL:
|
|
|
|
regcount = min(desc->RegisterCount, desc->Columns * desc->Rows);
|
|
|
|
l = 0;
|
|
|
|
for (i = 0; i < regcount; ++i)
|
|
|
|
{
|
|
|
|
BOOL out;
|
|
|
|
DWORD t = get_index(indata, index + i / regsize * rin + l * cin, is_pointer);
|
2012-08-16 17:21:20 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
set_number(&tmp, desc->Type, &t, intype);
|
|
|
|
set_number(&out, D3DXPT_BOOL, &tmp, desc->Type);
|
|
|
|
if (is_vertex_shader(table->desc.Version))
|
|
|
|
IDirect3DDevice9_SetVertexShaderConstantB(device, desc->RegisterIndex + i, &out, 1);
|
|
|
|
else
|
|
|
|
IDirect3DDevice9_SetPixelShaderConstantB(device, desc->RegisterIndex + i, &out, 1);
|
2012-08-21 14:52:17 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
if (++l >= regsize) l = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
case D3DXRS_INT4:
|
|
|
|
for (i = 0; i < regcount; ++i)
|
2012-08-21 14:52:17 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
INT vec[4] = {0, 0, 1, 0};
|
|
|
|
|
|
|
|
for (l = 0; l < regsize; ++l)
|
|
|
|
{
|
|
|
|
DWORD t = get_index(indata, index + i * rin + l * cin, is_pointer);
|
|
|
|
|
|
|
|
set_number(&tmp, desc->Type, &t, intype);
|
|
|
|
set_number(&vec[l], D3DXPT_INT, &tmp, desc->Type);
|
|
|
|
}
|
|
|
|
if (is_vertex_shader(table->desc.Version))
|
|
|
|
IDirect3DDevice9_SetVertexShaderConstantI(device, desc->RegisterIndex + i, vec, 1);
|
|
|
|
else
|
|
|
|
IDirect3DDevice9_SetPixelShaderConstantI(device, desc->RegisterIndex + i, vec, 1);
|
2012-08-21 14:52:17 +02:00
|
|
|
}
|
2013-07-22 14:35:41 +02:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
case D3DXRS_FLOAT4:
|
|
|
|
for (i = 0; i < regcount; ++i)
|
2012-08-21 14:52:17 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
FLOAT vec[4] = {0};
|
|
|
|
|
|
|
|
for (l = 0; l < regsize; ++l)
|
|
|
|
{
|
|
|
|
DWORD t = get_index(indata, index + i * rin + l * cin, is_pointer);
|
|
|
|
|
|
|
|
set_number(&tmp, desc->Type, &t, intype);
|
|
|
|
set_number(&vec[l], D3DXPT_FLOAT, &tmp, desc->Type);
|
|
|
|
}
|
|
|
|
if (is_vertex_shader(table->desc.Version))
|
|
|
|
IDirect3DDevice9_SetVertexShaderConstantF(device, desc->RegisterIndex + i, vec, 1);
|
|
|
|
else
|
|
|
|
IDirect3DDevice9_SetPixelShaderConstantF(device, desc->RegisterIndex + i, vec, 1);
|
2012-08-21 14:52:17 +02:00
|
|
|
}
|
2013-07-22 14:35:41 +02:00
|
|
|
return ret;
|
|
|
|
|
2012-08-21 14:52:17 +02:00
|
|
|
default:
|
2013-07-22 14:35:41 +02:00
|
|
|
FIXME("Unhandled register set %s\n", debug_d3dxparameter_registerset(desc->RegisterSet));
|
|
|
|
return 0;
|
2012-08-21 14:52:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
static HRESULT set_scalar(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device, D3DXHANDLE constant,
|
|
|
|
const void *indata, D3DXPARAMETER_TYPE intype)
|
2012-08-16 17:21:20 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
struct ctab_constant *c = get_valid_constant(table, constant);
|
|
|
|
UINT count = 1;
|
2012-08-16 17:21:20 +02:00
|
|
|
|
2012-08-28 13:42:55 +02:00
|
|
|
if (!c)
|
2012-08-16 17:21:20 +02:00
|
|
|
{
|
2012-08-28 13:42:55 +02:00
|
|
|
WARN("Invalid argument specified\n");
|
2012-08-16 17:21:20 +02:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
switch (c->desc.Class)
|
2012-08-16 17:21:20 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
set(table, device, c, &indata, intype, &count, c->desc.Columns, D3DXPC_SCALAR, 0, FALSE);
|
|
|
|
return D3D_OK;
|
2012-08-28 13:43:04 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
|
|
|
case D3DXPC_STRUCT:
|
|
|
|
return D3D_OK;
|
2012-08-21 14:52:17 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c->desc.Class));
|
|
|
|
return D3DERR_INVALIDCALL;
|
2012-08-21 14:52:14 +02:00
|
|
|
}
|
2013-07-22 14:35:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT set_scalar_array(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device, D3DXHANDLE constant,
|
|
|
|
const void *indata, UINT count, D3DXPARAMETER_TYPE intype)
|
|
|
|
{
|
|
|
|
struct ctab_constant *c = get_valid_constant(table, constant);
|
|
|
|
|
|
|
|
if (!c)
|
2012-08-16 17:21:20 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
WARN("Invalid argument specified\n");
|
|
|
|
return D3DERR_INVALIDCALL;
|
2012-08-16 17:21:20 +02:00
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
switch (c->desc.Class)
|
2012-08-16 17:21:20 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
|
|
|
case D3DXPC_STRUCT:
|
|
|
|
set(table, device, c, &indata, intype, &count, c->desc.Columns, D3DXPC_SCALAR, 0, FALSE);
|
|
|
|
return D3D_OK;
|
2012-08-21 14:52:17 +02:00
|
|
|
|
2012-08-16 17:21:20 +02:00
|
|
|
default:
|
2013-07-22 14:35:41 +02:00
|
|
|
FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c->desc.Class));
|
|
|
|
return D3DERR_INVALIDCALL;
|
2012-08-16 17:21:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
static HRESULT set_vector(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device, D3DXHANDLE constant,
|
|
|
|
const void *indata, D3DXPARAMETER_TYPE intype)
|
2012-08-21 14:52:19 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
struct ctab_constant *c = get_valid_constant(table, constant);
|
|
|
|
UINT count = 4;
|
|
|
|
|
|
|
|
if (!c)
|
2012-08-21 14:52:19 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
WARN("Invalid argument specified\n");
|
2012-08-21 14:52:19 +02:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
switch (c->desc.Class)
|
2012-08-21 14:52:19 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
case D3DXPC_STRUCT:
|
|
|
|
set(table, device, c, &indata, intype, &count, 4, D3DXPC_VECTOR, 0, FALSE);
|
|
|
|
return D3D_OK;
|
2012-08-21 14:52:19 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
|
|
|
return D3D_OK;
|
2012-08-21 14:52:19 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c->desc.Class));
|
|
|
|
return D3DERR_INVALIDCALL;
|
2012-08-21 14:52:19 +02:00
|
|
|
}
|
2013-07-22 14:35:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT set_vector_array(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device, D3DXHANDLE constant,
|
|
|
|
const void *indata, UINT count, D3DXPARAMETER_TYPE intype)
|
|
|
|
{
|
|
|
|
struct ctab_constant *c = get_valid_constant(table, constant);
|
|
|
|
|
|
|
|
if (!c)
|
2012-08-21 14:52:19 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
WARN("Invalid argument specified\n");
|
|
|
|
return D3DERR_INVALIDCALL;
|
2012-08-21 14:52:19 +02:00
|
|
|
}
|
2013-07-22 14:35:41 +02:00
|
|
|
|
|
|
|
switch (c->desc.Class)
|
2012-08-21 14:52:19 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
|
|
|
case D3DXPC_STRUCT:
|
|
|
|
count *= 4;
|
|
|
|
set(table, device, c, &indata, intype, &count, 4, D3DXPC_VECTOR, 0, FALSE);
|
|
|
|
return D3D_OK;
|
2012-08-21 14:52:20 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c->desc.Class));
|
|
|
|
return D3DERR_INVALIDCALL;
|
2012-08-21 14:52:19 +02:00
|
|
|
}
|
2013-07-22 14:35:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT set_matrix_array(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device, D3DXHANDLE constant,
|
|
|
|
const void *indata, UINT count, BOOL transpose)
|
|
|
|
{
|
|
|
|
struct ctab_constant *c = get_valid_constant(table, constant);
|
|
|
|
|
|
|
|
if (!c)
|
2012-08-21 14:52:19 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
WARN("Invalid argument specified\n");
|
|
|
|
return D3DERR_INVALIDCALL;
|
2012-08-21 14:52:19 +02:00
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
switch (c->desc.Class)
|
2012-08-21 14:52:19 +02:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
|
|
|
case D3DXPC_STRUCT:
|
|
|
|
count *= 16;
|
|
|
|
set(table, device, c, &indata, D3DXPT_FLOAT, &count, 4,
|
|
|
|
transpose ? D3DXPC_MATRIX_ROWS : D3DXPC_MATRIX_COLUMNS, 0, FALSE);
|
|
|
|
return D3D_OK;
|
2012-08-21 14:52:19 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c->desc.Class));
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
}
|
2012-08-21 14:52:19 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
static HRESULT set_matrix_pointer_array(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device,
|
|
|
|
D3DXHANDLE constant, const void **indata, UINT count, BOOL transpose)
|
|
|
|
{
|
|
|
|
struct ctab_constant *c = get_valid_constant(table, constant);
|
2012-08-21 14:52:19 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
if (!c)
|
|
|
|
{
|
|
|
|
WARN("Invalid argument specified\n");
|
|
|
|
return D3DERR_INVALIDCALL;
|
2012-08-21 14:52:19 +02:00
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
switch (c->desc.Class)
|
|
|
|
{
|
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
|
|
|
case D3DXPC_STRUCT:
|
|
|
|
count *= 16;
|
|
|
|
set(table, device, c, indata, D3DXPT_FLOAT, &count, 4,
|
|
|
|
transpose ? D3DXPC_MATRIX_ROWS : D3DXPC_MATRIX_COLUMNS, 0, TRUE);
|
|
|
|
return D3D_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(c->desc.Class));
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
2012-08-21 14:52:19 +02:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetDefaults(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2012-08-14 11:42:33 +02:00
|
|
|
UINT i;
|
|
|
|
|
2013-07-29 11:13:54 +02:00
|
|
|
TRACE("iface %p, device %p\n", iface, device);
|
2012-08-14 11:42:33 +02:00
|
|
|
|
|
|
|
if (!device)
|
2013-07-29 11:13:54 +02:00
|
|
|
{
|
|
|
|
WARN("Invalid argument specified\n");
|
2012-08-14 11:42:33 +02:00
|
|
|
return D3DERR_INVALIDCALL;
|
2013-07-29 11:13:54 +02:00
|
|
|
}
|
2012-08-14 11:42:33 +02:00
|
|
|
|
|
|
|
for (i = 0; i < This->desc.Constants; i++)
|
|
|
|
{
|
|
|
|
D3DXCONSTANT_DESC *desc = &This->constants[i].desc;
|
2013-07-29 11:13:54 +02:00
|
|
|
HRESULT hr;
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-14 11:42:33 +02:00
|
|
|
if (!desc->DefaultValue)
|
|
|
|
continue;
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-29 11:13:54 +02:00
|
|
|
switch (desc->RegisterSet)
|
|
|
|
{
|
|
|
|
case D3DXRS_BOOL:
|
|
|
|
if (is_vertex_shader(This->desc.Version))
|
|
|
|
hr = IDirect3DDevice9_SetVertexShaderConstantB(device, desc->RegisterIndex, desc->DefaultValue,
|
|
|
|
desc->RegisterCount);
|
|
|
|
else
|
|
|
|
hr = IDirect3DDevice9_SetPixelShaderConstantB(device, desc->RegisterIndex, desc->DefaultValue,
|
|
|
|
desc->RegisterCount);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DXRS_INT4:
|
|
|
|
if (is_vertex_shader(This->desc.Version))
|
|
|
|
hr = IDirect3DDevice9_SetVertexShaderConstantI(device, desc->RegisterIndex, desc->DefaultValue,
|
|
|
|
desc->RegisterCount);
|
|
|
|
else
|
|
|
|
hr = IDirect3DDevice9_SetPixelShaderConstantI(device, desc->RegisterIndex, desc->DefaultValue,
|
|
|
|
desc->RegisterCount);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DXRS_FLOAT4:
|
|
|
|
if (is_vertex_shader(This->desc.Version))
|
|
|
|
hr = IDirect3DDevice9_SetVertexShaderConstantF(device, desc->RegisterIndex, desc->DefaultValue,
|
|
|
|
desc->RegisterCount);
|
|
|
|
else
|
|
|
|
hr = IDirect3DDevice9_SetPixelShaderConstantF(device, desc->RegisterIndex, desc->DefaultValue,
|
|
|
|
desc->RegisterCount);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled register set %s\n", debug_d3dxparameter_registerset(desc->RegisterSet));
|
|
|
|
hr = E_NOTIMPL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hr != D3D_OK)
|
|
|
|
return hr;
|
2012-08-14 11:42:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return D3D_OK;
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetValue(struct ID3DXConstantTable *iface,
|
2013-07-22 14:35:41 +02:00
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, const void *data, unsigned int bytes)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2013-07-22 14:35:41 +02:00
|
|
|
struct ID3DXConstantTableImpl *table = impl_from_ID3DXConstantTable(iface);
|
|
|
|
struct ctab_constant *c = get_valid_constant(table, constant);
|
|
|
|
D3DXCONSTANT_DESC *desc;
|
2012-08-16 17:21:20 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, data %p, bytes %u\n", iface, device, constant, data, bytes);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
if (!device || !c || !data)
|
|
|
|
{
|
|
|
|
WARN("Invalid argument specified\n");
|
2012-08-16 17:21:20 +02:00
|
|
|
return D3DERR_INVALIDCALL;
|
2013-07-22 14:35:41 +02:00
|
|
|
}
|
2012-08-16 17:21:20 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
desc = &c->desc;
|
2012-08-16 17:21:20 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
switch (desc->Class)
|
2012-08-16 17:21:20 +02:00
|
|
|
{
|
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
2013-07-22 14:35:41 +02:00
|
|
|
case D3DXPC_STRUCT:
|
|
|
|
bytes /= 4;
|
|
|
|
set(table, device, c, &data, desc->Type, &bytes, desc->Columns, D3DXPC_SCALAR, 0, FALSE);
|
|
|
|
return D3D_OK;
|
|
|
|
|
2012-08-16 17:21:20 +02:00
|
|
|
default:
|
2013-07-22 14:35:41 +02:00
|
|
|
FIXME("Unhandled parameter class %s\n", debug_d3dxparameter_class(desc->Class));
|
2012-08-16 17:21:20 +02:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetBool(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, BOOL b)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, b %d\n", iface, device, constant, b);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
return set_scalar(This, device, constant, &b, D3DXPT_BOOL);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetBoolArray(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, const BOOL *b, UINT count)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, b %p, count %d\n", iface, device, constant, b, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
return set_scalar_array(This, device, constant, b, count, D3DXPT_BOOL);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetInt(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, INT n)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, n %d\n", iface, device, constant, n);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
return set_scalar(This, device, constant, &n, D3DXPT_INT);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetIntArray(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, const INT *n, UINT count)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, n %p, count %d\n", iface, device, constant, n, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
return set_scalar_array(This, device, constant, n, count, D3DXPT_INT);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetFloat(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, float f)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, f %f\n", iface, device, constant, f);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
return set_scalar(This, device, constant, &f, D3DXPT_FLOAT);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetFloatArray(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, const float *f, UINT count)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, f %p, count %d\n", iface, device, constant, f, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
return set_scalar_array(This, device, constant, f, count, D3DXPT_FLOAT);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetVector(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, const D3DXVECTOR4 *vector)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, vector %p\n", iface, device, constant, vector);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
return set_vector(This, device, constant, vector, D3DXPT_FLOAT);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetVectorArray(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, const D3DXVECTOR4 *vector, UINT count)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2011-06-21 21:14:32 +02:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, vector %p, count %u\n", iface, device, constant, vector, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
return set_vector_array(This, device, constant, vector, count, D3DXPT_FLOAT);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrix(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, const D3DXMATRIX *matrix)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, matrix %p\n", iface, device, constant, matrix);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
return set_matrix_array(This, device, constant, matrix, 1, FALSE);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixArray(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, const D3DXMATRIX *matrix, UINT count)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, matrix %p, count %u\n", iface, device, constant, matrix, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
return set_matrix_array(This, device, constant, matrix, count, FALSE);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixPointerArray(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, const D3DXMATRIX **matrix, UINT count)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, matrix %p, count %u)\n", iface, device, constant, matrix, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
return set_matrix_pointer_array(This, device, constant, (const void **)matrix, count, FALSE);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixTranspose(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, const D3DXMATRIX *matrix)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, matrix %p\n", iface, device, constant, matrix);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
return set_matrix_array(This, device, constant, matrix, 1, TRUE);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixTransposeArray(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, const D3DXMATRIX *matrix, UINT count)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, matrix %p, count %u\n", iface, device, constant, matrix, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
return set_matrix_array(This, device, constant, matrix, count, TRUE);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 20:54:52 +01:00
|
|
|
static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixTransposePointerArray(struct ID3DXConstantTable *iface,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, const D3DXMATRIX **matrix, UINT count)
|
2010-03-01 09:39:18 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
TRACE("iface %p, device %p, constant %p, matrix %p, count %u)\n", iface, device, constant, matrix, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-07-22 14:35:41 +02:00
|
|
|
return set_matrix_pointer_array(This, device, constant, (const void **)matrix, count, TRUE);
|
2010-03-01 09:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ID3DXConstantTableVtbl ID3DXConstantTable_Vtbl =
|
|
|
|
{
|
|
|
|
/*** IUnknown methods ***/
|
|
|
|
ID3DXConstantTableImpl_QueryInterface,
|
|
|
|
ID3DXConstantTableImpl_AddRef,
|
|
|
|
ID3DXConstantTableImpl_Release,
|
|
|
|
/*** ID3DXBuffer methods ***/
|
|
|
|
ID3DXConstantTableImpl_GetBufferPointer,
|
|
|
|
ID3DXConstantTableImpl_GetBufferSize,
|
|
|
|
/*** ID3DXConstantTable methods ***/
|
|
|
|
ID3DXConstantTableImpl_GetDesc,
|
|
|
|
ID3DXConstantTableImpl_GetConstantDesc,
|
2010-03-19 11:54:11 +01:00
|
|
|
ID3DXConstantTableImpl_GetSamplerIndex,
|
2010-03-01 09:39:18 +01:00
|
|
|
ID3DXConstantTableImpl_GetConstant,
|
|
|
|
ID3DXConstantTableImpl_GetConstantByName,
|
2010-03-19 11:54:17 +01:00
|
|
|
ID3DXConstantTableImpl_GetConstantElement,
|
2010-03-01 09:39:18 +01:00
|
|
|
ID3DXConstantTableImpl_SetDefaults,
|
|
|
|
ID3DXConstantTableImpl_SetValue,
|
|
|
|
ID3DXConstantTableImpl_SetBool,
|
|
|
|
ID3DXConstantTableImpl_SetBoolArray,
|
|
|
|
ID3DXConstantTableImpl_SetInt,
|
|
|
|
ID3DXConstantTableImpl_SetIntArray,
|
|
|
|
ID3DXConstantTableImpl_SetFloat,
|
|
|
|
ID3DXConstantTableImpl_SetFloatArray,
|
|
|
|
ID3DXConstantTableImpl_SetVector,
|
|
|
|
ID3DXConstantTableImpl_SetVectorArray,
|
|
|
|
ID3DXConstantTableImpl_SetMatrix,
|
|
|
|
ID3DXConstantTableImpl_SetMatrixArray,
|
|
|
|
ID3DXConstantTableImpl_SetMatrixPointerArray,
|
|
|
|
ID3DXConstantTableImpl_SetMatrixTranspose,
|
|
|
|
ID3DXConstantTableImpl_SetMatrixTransposeArray,
|
|
|
|
ID3DXConstantTableImpl_SetMatrixTransposePointerArray
|
|
|
|
};
|
|
|
|
|
2012-08-23 21:36:50 +02:00
|
|
|
static HRESULT parse_ctab_constant_type(const char *ctab, DWORD typeoffset, struct ctab_constant *constant,
|
2014-03-03 17:48:12 +01:00
|
|
|
BOOL is_element, WORD index, WORD max_index, DWORD *offset, DWORD nameoffset, UINT regset)
|
2010-09-10 18:42:45 +02:00
|
|
|
{
|
2012-08-23 21:36:50 +02:00
|
|
|
const D3DXSHADER_TYPEINFO *type = (LPD3DXSHADER_TYPEINFO)(ctab + typeoffset);
|
|
|
|
const D3DXSHADER_STRUCTMEMBERINFO *memberinfo = NULL;
|
|
|
|
HRESULT hr = D3D_OK;
|
|
|
|
UINT i, count = 0;
|
|
|
|
WORD size = 0;
|
|
|
|
|
|
|
|
constant->desc.DefaultValue = offset ? ctab + *offset : NULL;
|
2010-09-10 18:42:45 +02:00
|
|
|
constant->desc.Class = type->Class;
|
|
|
|
constant->desc.Type = type->Type;
|
|
|
|
constant->desc.Rows = type->Rows;
|
|
|
|
constant->desc.Columns = type->Columns;
|
2012-08-23 21:36:50 +02:00
|
|
|
constant->desc.Elements = is_element ? 1 : type->Elements;
|
2010-09-10 18:42:45 +02:00
|
|
|
constant->desc.StructMembers = type->StructMembers;
|
2012-08-23 21:36:50 +02:00
|
|
|
constant->desc.Name = ctab + nameoffset;
|
|
|
|
constant->desc.RegisterSet = regset;
|
|
|
|
constant->desc.RegisterIndex = index;
|
2010-09-10 18:42:45 +02:00
|
|
|
|
2012-08-25 16:28:53 +02:00
|
|
|
TRACE("name %s, elements %u, index %u, defaultvalue %p, regset %s\n", constant->desc.Name,
|
|
|
|
constant->desc.Elements, index, constant->desc.DefaultValue,
|
|
|
|
debug_d3dxparameter_registerset(regset));
|
2012-08-25 16:28:49 +02:00
|
|
|
TRACE("class %s, type %s, rows %d, columns %d, elements %d, struct_members %d\n",
|
|
|
|
debug_d3dxparameter_class(type->Class), debug_d3dxparameter_type(type->Type),
|
|
|
|
type->Rows, type->Columns, type->Elements, type->StructMembers);
|
2010-09-10 18:42:45 +02:00
|
|
|
|
2012-08-23 21:36:50 +02:00
|
|
|
if (type->Elements > 1 && !is_element)
|
|
|
|
{
|
|
|
|
count = type->Elements;
|
|
|
|
}
|
|
|
|
else if ((type->Class == D3DXPC_STRUCT) && type->StructMembers)
|
2010-09-10 18:42:45 +02:00
|
|
|
{
|
2012-08-23 21:36:50 +02:00
|
|
|
memberinfo = (D3DXSHADER_STRUCTMEMBERINFO*)(ctab + type->StructMemberInfo);
|
|
|
|
count = type->StructMembers;
|
2010-09-10 18:42:45 +02:00
|
|
|
}
|
|
|
|
|
2012-08-23 21:36:50 +02:00
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
constant->constants = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*constant->constants) * count);
|
|
|
|
if (!constant->constants)
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
hr = parse_ctab_constant_type(ctab, memberinfo ? memberinfo[i].TypeInfo : typeoffset,
|
2014-03-03 17:48:12 +01:00
|
|
|
&constant->constants[i], memberinfo == NULL, index + size, max_index, offset,
|
2012-08-23 21:36:50 +02:00
|
|
|
memberinfo ? memberinfo[i].Name : nameoffset, regset);
|
|
|
|
if (hr != D3D_OK)
|
|
|
|
goto error;
|
|
|
|
|
2012-08-25 16:28:34 +02:00
|
|
|
size += constant->constants[i].desc.RegisterCount;
|
2012-08-23 21:36:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-22 14:35:23 +02:00
|
|
|
WORD offsetdiff = type->Columns * type->Rows;
|
|
|
|
BOOL fail = FALSE;
|
2012-08-23 21:36:50 +02:00
|
|
|
|
2013-07-22 14:35:23 +02:00
|
|
|
size = type->Columns * type->Rows;
|
|
|
|
|
|
|
|
switch (regset)
|
2012-08-23 21:36:50 +02:00
|
|
|
{
|
2013-07-22 14:35:23 +02:00
|
|
|
case D3DXRS_BOOL:
|
|
|
|
fail = type->Class != D3DXPC_SCALAR && type->Class != D3DXPC_VECTOR
|
|
|
|
&& type->Class != D3DXPC_MATRIX_ROWS && type->Class != D3DXPC_MATRIX_COLUMNS;
|
2012-08-23 21:36:50 +02:00
|
|
|
break;
|
|
|
|
|
2013-07-22 14:35:23 +02:00
|
|
|
case D3DXRS_FLOAT4:
|
|
|
|
case D3DXRS_INT4:
|
|
|
|
switch (type->Class)
|
|
|
|
{
|
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
size = 1;
|
|
|
|
/* fall through */
|
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
offsetdiff = type->Rows * 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
offsetdiff = type->Rows * 4;
|
2014-03-03 17:48:12 +01:00
|
|
|
size = type->Rows;
|
2013-07-22 14:35:23 +02:00
|
|
|
break;
|
2012-08-23 21:36:50 +02:00
|
|
|
|
2013-07-22 14:35:23 +02:00
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
|
|
|
offsetdiff = type->Columns * 4;
|
|
|
|
size = type->Columns;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fail = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2012-08-23 21:36:50 +02:00
|
|
|
break;
|
|
|
|
|
2013-07-22 14:35:23 +02:00
|
|
|
case D3DXRS_SAMPLER:
|
2012-08-23 21:36:50 +02:00
|
|
|
size = 1;
|
2013-07-22 14:35:23 +02:00
|
|
|
fail = type->Class != D3DXPC_OBJECT;
|
2012-08-23 21:36:50 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-07-22 14:35:23 +02:00
|
|
|
fail = TRUE;
|
2012-08-23 21:36:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-07-22 14:35:23 +02:00
|
|
|
if (fail)
|
2012-09-26 12:22:02 +02:00
|
|
|
{
|
2013-07-22 14:35:23 +02:00
|
|
|
FIXME("Unhandled register set %s, type class %s\n", debug_d3dxparameter_registerset(regset),
|
|
|
|
debug_d3dxparameter_class(type->Class));
|
2012-09-26 12:22:02 +02:00
|
|
|
}
|
2013-07-22 14:35:23 +02:00
|
|
|
|
|
|
|
/* offset in bytes => offsetdiff * sizeof(DWORD) */
|
|
|
|
if (offset) *offset += offsetdiff * 4;
|
2012-08-23 21:36:50 +02:00
|
|
|
}
|
|
|
|
|
2014-03-03 17:48:12 +01:00
|
|
|
constant->desc.RegisterCount = max(0, min(max_index - index, size));
|
2012-09-26 12:21:54 +02:00
|
|
|
constant->desc.Bytes = 4 * constant->desc.Elements * type->Rows * type->Columns;
|
2012-08-23 21:36:50 +02:00
|
|
|
|
2010-09-10 18:42:45 +02:00
|
|
|
return D3D_OK;
|
2012-08-23 21:36:50 +02:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (constant->constants)
|
|
|
|
{
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
free_constant(&constant->constants[i]);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, constant->constants);
|
|
|
|
constant->constants = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2010-09-10 18:42:45 +02:00
|
|
|
}
|
|
|
|
|
2012-11-22 21:13:36 +01:00
|
|
|
HRESULT WINAPI D3DXGetShaderConstantTableEx(const DWORD *byte_code, DWORD flags, ID3DXConstantTable **constant_table)
|
2010-02-21 22:30:27 +01:00
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *object = NULL;
|
2013-09-03 09:47:25 +02:00
|
|
|
const void *data;
|
2010-03-01 09:39:29 +01:00
|
|
|
HRESULT hr;
|
|
|
|
UINT size;
|
2013-01-07 21:57:24 +01:00
|
|
|
const D3DXSHADER_CONSTANTTABLE *ctab_header;
|
2013-01-07 21:57:29 +01:00
|
|
|
const D3DXSHADER_CONSTANTINFO *constant_info;
|
2010-09-10 18:42:45 +02:00
|
|
|
DWORD i;
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2013-01-07 21:57:13 +01:00
|
|
|
TRACE("byte_code %p, flags %x, constant_table %p\n", byte_code, flags, constant_table);
|
|
|
|
|
|
|
|
if (constant_table) *constant_table = NULL;
|
2010-02-21 22:30:27 +01:00
|
|
|
|
2010-03-08 08:56:22 +01:00
|
|
|
if (!byte_code || !constant_table)
|
2012-01-22 11:29:08 +01:00
|
|
|
{
|
|
|
|
WARN("Invalid argument specified.\n");
|
2010-02-21 22:30:27 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
2012-01-22 11:29:08 +01:00
|
|
|
}
|
2010-02-21 22:30:27 +01:00
|
|
|
|
2013-01-07 21:57:18 +01:00
|
|
|
if (!is_valid_bytecode(*byte_code))
|
|
|
|
{
|
|
|
|
WARN("Invalid byte_code specified.\n");
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-23 21:36:36 +02:00
|
|
|
if (flags) FIXME("Flags (%#x) are not handled, yet!\n", flags);
|
|
|
|
|
2010-03-08 08:56:22 +01:00
|
|
|
hr = D3DXFindShaderComment(byte_code, MAKEFOURCC('C','T','A','B'), &data, &size);
|
2010-03-01 09:39:29 +01:00
|
|
|
if (hr != D3D_OK)
|
2012-01-22 11:29:08 +01:00
|
|
|
{
|
|
|
|
WARN("CTAB not found.\n");
|
2010-03-01 09:39:29 +01:00
|
|
|
return D3DXERR_INVALIDDATA;
|
2012-01-22 11:29:08 +01:00
|
|
|
}
|
|
|
|
|
2013-01-07 21:57:24 +01:00
|
|
|
if (size < sizeof(*ctab_header))
|
2012-01-22 11:29:08 +01:00
|
|
|
{
|
|
|
|
WARN("Invalid CTAB size.\n");
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctab_header = (const D3DXSHADER_CONSTANTTABLE *)data;
|
2013-01-07 21:57:24 +01:00
|
|
|
if (ctab_header->Size != sizeof(*ctab_header))
|
2012-01-22 11:29:08 +01:00
|
|
|
{
|
|
|
|
WARN("Invalid D3DXSHADER_CONSTANTTABLE size.\n");
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
2010-03-01 09:39:29 +01:00
|
|
|
|
2011-09-16 08:38:47 +02:00
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
2010-03-01 09:39:18 +01:00
|
|
|
if (!object)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2010-12-21 11:30:28 +01:00
|
|
|
object->ID3DXConstantTable_iface.lpVtbl = &ID3DXConstantTable_Vtbl;
|
2010-03-01 09:39:18 +01:00
|
|
|
object->ref = 1;
|
|
|
|
|
2010-03-02 08:37:07 +01:00
|
|
|
object->ctab = HeapAlloc(GetProcessHeap(), 0, size);
|
2010-03-01 09:39:29 +01:00
|
|
|
if (!object->ctab)
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
2012-01-22 11:29:08 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
return E_OUTOFMEMORY;
|
2010-03-01 09:39:29 +01:00
|
|
|
}
|
|
|
|
object->size = size;
|
|
|
|
memcpy(object->ctab, data, object->size);
|
|
|
|
|
2010-09-10 18:42:45 +02:00
|
|
|
object->desc.Creator = ctab_header->Creator ? object->ctab + ctab_header->Creator : NULL;
|
2010-03-19 11:54:05 +01:00
|
|
|
object->desc.Version = ctab_header->Version;
|
|
|
|
object->desc.Constants = ctab_header->Constants;
|
2012-01-22 11:29:32 +01:00
|
|
|
TRACE("Creator %s, Version %x, Constants %u, Target %s\n",
|
|
|
|
debugstr_a(object->desc.Creator), object->desc.Version, object->desc.Constants,
|
|
|
|
debugstr_a(ctab_header->Target ? object->ctab + ctab_header->Target : NULL));
|
2010-09-10 18:42:45 +02:00
|
|
|
|
|
|
|
object->constants = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
sizeof(*object->constants) * object->desc.Constants);
|
|
|
|
if (!object->constants)
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-01-07 21:57:29 +01:00
|
|
|
constant_info = (const D3DXSHADER_CONSTANTINFO *)(object->ctab + ctab_header->ConstantInfo);
|
2010-09-10 18:42:45 +02:00
|
|
|
for (i = 0; i < ctab_header->Constants; i++)
|
|
|
|
{
|
2012-08-23 21:36:50 +02:00
|
|
|
DWORD offset = constant_info[i].DefaultValue;
|
|
|
|
|
|
|
|
hr = parse_ctab_constant_type(object->ctab, constant_info[i].TypeInfo,
|
|
|
|
&object->constants[i], FALSE, constant_info[i].RegisterIndex,
|
|
|
|
constant_info[i].RegisterIndex + constant_info[i].RegisterCount,
|
|
|
|
offset ? &offset : NULL, constant_info[i].Name, constant_info[i].RegisterSet);
|
2010-09-10 18:42:45 +02:00
|
|
|
if (hr != D3D_OK)
|
|
|
|
goto error;
|
2013-07-22 14:35:23 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the register count, it may differ for D3DXRS_INT4, because somehow
|
|
|
|
* it makes the assumption that the register size is 1 instead of 4, so the
|
|
|
|
* count is 4 times bigger. This holds true only for toplevel shader
|
|
|
|
* constants. The count of elements and members is always based on a
|
|
|
|
* register size of 4.
|
|
|
|
*/
|
|
|
|
if (object->constants[i].desc.RegisterSet == D3DXRS_INT4)
|
|
|
|
{
|
|
|
|
object->constants[i].desc.RegisterCount = constant_info[i].RegisterCount;
|
|
|
|
}
|
2010-09-10 18:42:45 +02:00
|
|
|
}
|
2010-03-19 11:54:05 +01:00
|
|
|
|
2010-12-21 11:30:28 +01:00
|
|
|
*constant_table = &object->ID3DXConstantTable_iface;
|
2010-03-01 09:39:18 +01:00
|
|
|
|
|
|
|
return D3D_OK;
|
2010-03-19 11:54:05 +01:00
|
|
|
|
|
|
|
error:
|
2012-01-22 11:28:52 +01:00
|
|
|
free_constant_table(object);
|
2011-07-18 21:45:13 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
2010-03-19 11:54:05 +01:00
|
|
|
|
2010-09-10 18:42:45 +02:00
|
|
|
return hr;
|
2010-02-21 22:30:27 +01:00
|
|
|
}
|
|
|
|
|
2012-11-22 21:13:36 +01:00
|
|
|
HRESULT WINAPI D3DXGetShaderConstantTable(const DWORD *byte_code, ID3DXConstantTable **constant_table)
|
2010-02-21 22:30:27 +01:00
|
|
|
{
|
2010-03-08 08:56:22 +01:00
|
|
|
TRACE("(%p, %p): Forwarded to D3DXGetShaderConstantTableEx\n", byte_code, constant_table);
|
2010-02-21 22:30:27 +01:00
|
|
|
|
2010-03-08 08:56:22 +01:00
|
|
|
return D3DXGetShaderConstantTableEx(byte_code, 0, constant_table);
|
2010-02-21 22:30:27 +01:00
|
|
|
}
|
2011-07-15 10:52:36 +02:00
|
|
|
|
2015-07-29 08:23:10 +02:00
|
|
|
HRESULT WINAPI D3DXCreateFragmentLinker(IDirect3DDevice9 *device, UINT size, ID3DXFragmentLinker **linker)
|
|
|
|
{
|
|
|
|
FIXME("device %p, size %u, linker %p: stub.\n", device, size, linker);
|
|
|
|
|
|
|
|
if (linker)
|
|
|
|
*linker = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI D3DXCreateFragmentLinkerEx(IDirect3DDevice9 *device, UINT size, DWORD flags, ID3DXFragmentLinker **linker)
|
|
|
|
{
|
|
|
|
FIXME("device %p, size %u, flags %#x, linker %p: stub.\n", device, size, flags, linker);
|
|
|
|
|
|
|
|
if (linker)
|
|
|
|
*linker = NULL;
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2013-01-07 21:57:29 +01:00
|
|
|
HRESULT WINAPI D3DXGetShaderSamplers(const DWORD *byte_code, const char **samplers, UINT *count)
|
2011-07-15 10:52:36 +02:00
|
|
|
{
|
|
|
|
UINT i, sampler_count = 0;
|
2011-09-16 08:38:24 +02:00
|
|
|
UINT size;
|
2013-01-07 21:57:33 +01:00
|
|
|
const char *data;
|
2011-09-16 08:38:24 +02:00
|
|
|
const D3DXSHADER_CONSTANTTABLE *ctab_header;
|
|
|
|
const D3DXSHADER_CONSTANTINFO *constant_info;
|
2011-07-15 10:52:36 +02:00
|
|
|
|
|
|
|
TRACE("byte_code %p, samplers %p, count %p\n", byte_code, samplers, count);
|
|
|
|
|
|
|
|
if (count) *count = 0;
|
|
|
|
|
2013-01-07 21:57:33 +01:00
|
|
|
if (D3DXFindShaderComment(byte_code, MAKEFOURCC('C','T','A','B'), (const void **)&data, &size) != D3D_OK)
|
|
|
|
return D3D_OK;
|
2011-07-15 10:52:36 +02:00
|
|
|
|
2013-01-07 21:57:24 +01:00
|
|
|
if (size < sizeof(*ctab_header)) return D3D_OK;
|
2011-07-15 10:52:36 +02:00
|
|
|
|
2011-09-16 08:38:24 +02:00
|
|
|
ctab_header = (const D3DXSHADER_CONSTANTTABLE *)data;
|
|
|
|
if (ctab_header->Size != sizeof(*ctab_header)) return D3D_OK;
|
2011-07-15 10:52:36 +02:00
|
|
|
|
2013-01-07 21:57:29 +01:00
|
|
|
constant_info = (const D3DXSHADER_CONSTANTINFO *)(data + ctab_header->ConstantInfo);
|
2011-09-16 08:38:24 +02:00
|
|
|
for (i = 0; i < ctab_header->Constants; i++)
|
2011-07-15 10:52:36 +02:00
|
|
|
{
|
2011-09-16 08:38:24 +02:00
|
|
|
const D3DXSHADER_TYPEINFO *type;
|
2011-07-15 10:52:36 +02:00
|
|
|
|
2011-09-16 08:38:24 +02:00
|
|
|
TRACE("name = %s\n", data + constant_info[i].Name);
|
|
|
|
|
2013-01-07 21:57:29 +01:00
|
|
|
type = (const D3DXSHADER_TYPEINFO *)(data + constant_info[i].TypeInfo);
|
2011-07-15 10:52:36 +02:00
|
|
|
|
2011-09-16 08:38:24 +02:00
|
|
|
if (type->Type == D3DXPT_SAMPLER
|
|
|
|
|| type->Type == D3DXPT_SAMPLER1D
|
|
|
|
|| type->Type == D3DXPT_SAMPLER2D
|
|
|
|
|| type->Type == D3DXPT_SAMPLER3D
|
|
|
|
|| type->Type == D3DXPT_SAMPLERCUBE)
|
2011-07-15 10:52:36 +02:00
|
|
|
{
|
2011-09-16 08:38:24 +02:00
|
|
|
if (samplers) samplers[sampler_count] = data + constant_info[i].Name;
|
2011-07-15 10:52:36 +02:00
|
|
|
|
|
|
|
++sampler_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Found %u samplers\n", sampler_count);
|
|
|
|
|
|
|
|
if (count) *count = sampler_count;
|
|
|
|
|
2011-09-16 08:38:24 +02:00
|
|
|
return D3D_OK;
|
2011-07-15 10:52:36 +02:00
|
|
|
}
|
2015-02-11 00:30:00 +01:00
|
|
|
|
|
|
|
HRESULT WINAPI D3DXDisassembleShader(const DWORD *shader, BOOL colorcode, const char *comments, ID3DXBuffer **disassembly)
|
|
|
|
{
|
|
|
|
FIXME("%p %d %s %p: stub\n", shader, colorcode, debugstr_a(comments), disassembly);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|