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
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
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);
|
|
|
|
|
2010-08-24 23:05:12 +02:00
|
|
|
/* This function is not declared in the SDK headers yet */
|
|
|
|
HRESULT WINAPI D3DAssemble(LPCVOID data, SIZE_T datasize, LPCSTR filename,
|
|
|
|
const D3D_SHADER_MACRO *defines, ID3DInclude *include,
|
|
|
|
UINT flags,
|
|
|
|
ID3DBlob **shader, ID3DBlob **error_messages);
|
|
|
|
|
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
|
|
|
|
2010-03-01 09:39:24 +01:00
|
|
|
HRESULT WINAPI D3DXFindShaderComment(CONST DWORD* byte_code, DWORD fourcc, LPCVOID* data, UINT* size)
|
|
|
|
{
|
|
|
|
CONST DWORD *ptr = byte_code;
|
|
|
|
|
2010-03-20 15:25:25 +01:00
|
|
|
TRACE("(%p, %x, %p, %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;
|
|
|
|
|
2010-03-01 09:39:24 +01:00
|
|
|
if (!byte_code)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
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);
|
|
|
|
LPCVOID 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
|
|
|
{
|
2010-08-24 23:05:12 +02:00
|
|
|
/* Forward to d3dcompiler: the parameter types aren't really different,
|
|
|
|
the actual data types are equivalent */
|
|
|
|
HRESULT 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
|
|
|
}
|
|
|
|
|
2010-07-28 17:32:42 +02:00
|
|
|
/* D3DXInclude private implementation, used to implement
|
|
|
|
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,
|
|
|
|
LPCSTR filename, LPCVOID parent_data,
|
|
|
|
LPCVOID *data, UINT *bytes) {
|
|
|
|
const char *p, *parent_name = "";
|
|
|
|
char *pathname = NULL;
|
|
|
|
char **buffer = NULL;
|
|
|
|
HANDLE file;
|
|
|
|
UINT size;
|
|
|
|
|
|
|
|
if(parent_data != NULL)
|
|
|
|
parent_name = *((const char **)parent_data - 1);
|
|
|
|
|
|
|
|
TRACE("Looking up for include file %s, parent %s\n", debugstr_a(filename), debugstr_a(parent_name));
|
|
|
|
|
|
|
|
if ((p = strrchr(parent_name, '\\')) || (p = strrchr(parent_name, '/'))) p++;
|
|
|
|
else p = parent_name;
|
|
|
|
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);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
CloseHandle(file);
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
error:
|
|
|
|
CloseHandle(file);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pathname);
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI d3dincludefromfile_close(ID3DXInclude *iface, LPCVOID data) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, *((char **)data - 1));
|
|
|
|
HeapFree(GetProcessHeap(), 0, (char **)data - 1);
|
|
|
|
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
|
|
|
{
|
|
|
|
LPWSTR filename_w = NULL;
|
|
|
|
DWORD len;
|
|
|
|
HRESULT ret;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2010-07-28 17:32:42 +02:00
|
|
|
void *buffer;
|
|
|
|
DWORD len;
|
|
|
|
HRESULT hr;
|
|
|
|
struct D3DXIncludeImpl includefromfile;
|
|
|
|
|
|
|
|
if(FAILED(map_view_of_file(filename, &buffer, &len)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
hr = D3DXAssembleShader(buffer, len, defines, include, flags,
|
|
|
|
shader, error_messages);
|
|
|
|
|
|
|
|
UnmapViewOfFile(buffer);
|
|
|
|
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
|
|
|
{
|
|
|
|
HRSRC res;
|
|
|
|
LPCSTR buffer;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if (!(res = FindResourceA(module, resource, (LPCSTR)RT_RCDATA)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
if (FAILED(load_resource_into_memory(module, res, (LPVOID *)&buffer, &len)))
|
|
|
|
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
|
|
|
{
|
|
|
|
HRSRC res;
|
|
|
|
LPCSTR buffer;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if (!(res = FindResourceW(module, resource, (LPCWSTR)RT_RCDATA)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
if (FAILED(load_resource_into_memory(module, res, (LPVOID *)&buffer, &len)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
return D3DXAssembleShader(buffer, len, defines, include, flags,
|
|
|
|
shader, error_messages);
|
|
|
|
}
|
2010-02-11 07:38:08 +01:00
|
|
|
|
2012-11-22 21:13:36 +01:00
|
|
|
HRESULT WINAPI D3DXCompileShader(const char *pSrcData, UINT srcDataLen, const D3DXMACRO *pDefines,
|
|
|
|
ID3DXInclude *pInclude, const char *pFunctionName, const char *pProfile, DWORD Flags,
|
|
|
|
ID3DXBuffer **ppShader, ID3DXBuffer **ppErrorMsgs, ID3DXConstantTable **ppConstantTable)
|
2010-02-11 07:38:08 +01:00
|
|
|
{
|
2010-08-25 18:43:42 +02:00
|
|
|
HRESULT hr = D3DCompile(pSrcData, srcDataLen, NULL,
|
|
|
|
(D3D_SHADER_MACRO *)pDefines, (ID3DInclude *)pInclude,
|
|
|
|
pFunctionName, pProfile, Flags, 0,
|
|
|
|
(ID3DBlob **)ppShader, (ID3DBlob **)ppErrorMsgs);
|
|
|
|
|
|
|
|
if(SUCCEEDED(hr) && ppConstantTable)
|
|
|
|
return D3DXGetShaderConstantTable(ID3DXBuffer_GetBufferPointer(*ppShader),
|
|
|
|
ppConstantTable);
|
|
|
|
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
|
|
|
{
|
|
|
|
LPWSTR filename_w = NULL;
|
|
|
|
DWORD len;
|
|
|
|
HRESULT ret;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (FAILED(map_view_of_file(filename, &buffer, &len)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
UnmapViewOfFile(buffer);
|
|
|
|
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
|
|
|
|
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);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, filename_a);
|
|
|
|
UnmapViewOfFile(buffer);
|
|
|
|
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
|
|
|
{
|
|
|
|
HRSRC res;
|
|
|
|
LPCSTR buffer;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if (!(res = FindResourceA(module, resource, (LPCSTR)RT_RCDATA)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
if (FAILED(load_resource_into_memory(module, res, (LPVOID *)&buffer, &len)))
|
|
|
|
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
|
|
|
{
|
|
|
|
HRSRC res;
|
|
|
|
LPCSTR buffer;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if (!(res = FindResourceW(module, resource, (LPCWSTR)RT_RCDATA)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
if (FAILED(load_resource_into_memory(module, res, (LPVOID *)&buffer, &len)))
|
|
|
|
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
|
|
|
{
|
|
|
|
TRACE("Forward to D3DPreprocess\n");
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (FAILED(map_view_of_file(filename, &buffer, &len)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
hr = D3DPreprocess(buffer, len, NULL,
|
|
|
|
(const D3D_SHADER_MACRO *)defines,
|
|
|
|
(ID3DInclude *) include,
|
|
|
|
(ID3DBlob **)shader, (ID3DBlob **)error_messages);
|
|
|
|
|
|
|
|
UnmapViewOfFile(buffer);
|
|
|
|
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
|
|
|
{
|
|
|
|
HRSRC res;
|
|
|
|
const char *buffer;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if (!(res = FindResourceA(module, resource, (LPCSTR)RT_RCDATA)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
if (FAILED(load_resource_into_memory(module, res, (LPVOID *)&buffer, &len)))
|
|
|
|
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
|
|
|
{
|
|
|
|
HRSRC res;
|
|
|
|
const char *buffer;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if (!(res = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
if (FAILED(load_resource_into_memory(module, res, (void **)&buffer, &len)))
|
|
|
|
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
|
|
|
|
2010-03-01 09:39:18 +01:00
|
|
|
static const struct ID3DXConstantTableVtbl ID3DXConstantTable_Vtbl;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-06-21 21:14:30 +02:00
|
|
|
static inline int is_vertex_shader(DWORD version)
|
|
|
|
{
|
|
|
|
return (version & 0xFFFF0000) == 0xFFFE0000;
|
|
|
|
}
|
|
|
|
|
2012-08-23 21:36:46 +02:00
|
|
|
static inline struct ctab_constant *constant_from_handle(D3DXHANDLE handle)
|
2012-08-14 11:42:30 +02:00
|
|
|
{
|
2012-08-23 21:36:46 +02:00
|
|
|
return (struct ctab_constant *)handle;
|
2012-08-14 11:42: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
|
|
|
}
|
|
|
|
|
2012-08-25 16:28:12 +02:00
|
|
|
static struct ctab_constant *get_constant_by_name(struct ID3DXConstantTableImpl *, struct ctab_constant *, LPCSTR);
|
|
|
|
|
|
|
|
static struct ctab_constant *get_constant_element_by_name(struct ctab_constant *constant, LPCSTR name)
|
|
|
|
{
|
|
|
|
UINT element;
|
|
|
|
LPCSTR part;
|
|
|
|
|
|
|
|
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,
|
|
|
|
struct ctab_constant *constant, LPCSTR name)
|
|
|
|
{
|
|
|
|
UINT i, count, length;
|
|
|
|
struct ctab_constant *handles;
|
|
|
|
LPCSTR part;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-08-23 21:36:58 +02:00
|
|
|
static struct ctab_constant *is_valid_sub_constant(struct ctab_constant *parent, struct ctab_constant *constant)
|
|
|
|
{
|
|
|
|
UINT i, count;
|
|
|
|
|
|
|
|
/* all variable have at least elements = 1, but no elements */
|
|
|
|
if (!parent->constants) return NULL;
|
|
|
|
|
|
|
|
if (parent->desc.Elements > 1) count = parent->desc.Elements;
|
|
|
|
else count = parent->desc.StructMembers;
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
if (&parent->constants[i] == constant)
|
|
|
|
return constant;
|
|
|
|
|
|
|
|
if (is_valid_sub_constant(&parent->constants[i], constant))
|
|
|
|
return constant;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-08-23 21:36:46 +02:00
|
|
|
static inline struct ctab_constant *is_valid_constant(struct ID3DXConstantTableImpl *table, D3DXHANDLE handle)
|
2012-08-14 11:42:30 +02:00
|
|
|
{
|
2012-08-23 21:36:46 +02:00
|
|
|
struct ctab_constant *c = constant_from_handle(handle);
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
if (!c) return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < table->desc.Constants; ++i)
|
|
|
|
{
|
2012-08-23 21:36:58 +02:00
|
|
|
if (&table->constants[i] == c)
|
|
|
|
return c;
|
|
|
|
|
|
|
|
if (is_valid_sub_constant(&table->constants[i], c))
|
|
|
|
return c;
|
2012-08-23 21:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2012-08-14 11:42:30 +02:00
|
|
|
}
|
|
|
|
|
2012-08-25 16:28:12 +02:00
|
|
|
static inline struct ctab_constant *get_valid_constant(struct ID3DXConstantTableImpl *table, D3DXHANDLE handle)
|
|
|
|
{
|
|
|
|
struct ctab_constant *constant = is_valid_constant(table, handle);
|
|
|
|
|
|
|
|
if (!constant) constant = get_constant_by_name(table, NULL, handle);
|
|
|
|
|
|
|
|
return constant;
|
|
|
|
}
|
|
|
|
|
2012-08-14 11:42:31 +02:00
|
|
|
static inline void set_float_shader_constant(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device,
|
|
|
|
UINT register_index, const FLOAT *data, UINT count)
|
|
|
|
{
|
|
|
|
if (is_vertex_shader(table->desc.Version))
|
|
|
|
IDirect3DDevice9_SetVertexShaderConstantF(device, register_index, data, count);
|
|
|
|
else
|
|
|
|
IDirect3DDevice9_SetPixelShaderConstantF(device, register_index, data, count);
|
|
|
|
}
|
|
|
|
|
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 ***/
|
2012-01-22 11:29:03 +01:00
|
|
|
static LPVOID WINAPI ID3DXConstantTableImpl_GetBufferPointer(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->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
|
|
|
}
|
|
|
|
|
2012-01-22 11:29:03 +01:00
|
|
|
static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstantByName(ID3DXConstantTable *iface, D3DXHANDLE constant, LPCSTR 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
|
|
|
|
|
|
|
TRACE("(%p)->(%p, %s)\n", This, constant, 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;
|
|
|
|
}
|
|
|
|
|
2012-08-16 17:21:17 +02:00
|
|
|
static HRESULT set_scalar_array(ID3DXConstantTable *iface, IDirect3DDevice9 *device, D3DXHANDLE constant, const void *data,
|
2011-06-21 21:14:30 +02:00
|
|
|
UINT count, D3DXPARAMETER_TYPE type)
|
|
|
|
{
|
2012-01-22 11:29:03 +01:00
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2011-06-21 21:14:30 +02:00
|
|
|
D3DXCONSTANT_DESC desc;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT i, desc_count = 1;
|
|
|
|
float row[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
hr = ID3DXConstantTable_GetConstantDesc(iface, constant, &desc, &desc_count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-06-25 13:49:53 +02:00
|
|
|
TRACE("ID3DXConstantTable_GetConstantDesc failed: %08x\n", hr);
|
2011-06-21 21:14:30 +02:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2012-08-21 14:52:16 +02:00
|
|
|
if (desc.Class != D3DXPC_SCALAR)
|
|
|
|
return D3D_OK;
|
|
|
|
|
2011-06-21 21:14:30 +02:00
|
|
|
switch (desc.RegisterSet)
|
|
|
|
{
|
|
|
|
case D3DXRS_FLOAT4:
|
2012-08-16 17:21:17 +02:00
|
|
|
for (i = 0; i < min(count, desc.RegisterCount); i++)
|
2011-06-21 21:14:30 +02:00
|
|
|
{
|
|
|
|
/* We need the for loop since each IDirect3DDevice9_Set*ShaderConstantF expects a float4 */
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case D3DXPT_FLOAT:
|
|
|
|
row[0] = ((float *)data)[i];
|
|
|
|
break;
|
2011-06-21 21:14:31 +02:00
|
|
|
case D3DXPT_INT:
|
|
|
|
row[0] = (float)((int *)data)[i];
|
|
|
|
break;
|
2012-08-16 17:21:17 +02:00
|
|
|
case D3DXPT_BOOL:
|
|
|
|
row[0] = ((BOOL *)data)[i] ? 1.0f : 0.0f;
|
|
|
|
break;
|
2011-06-21 21:14:30 +02:00
|
|
|
default:
|
2012-08-25 16:28:49 +02:00
|
|
|
FIXME("Unhandled type %s\n", debug_d3dxparameter_type(type));
|
2011-06-21 21:14:30 +02:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
2012-08-14 11:42:31 +02:00
|
|
|
set_float_shader_constant(This, device, desc.RegisterIndex + i, row, 1);
|
2011-06-21 21:14:30 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2012-08-25 16:28:53 +02:00
|
|
|
FIXME("Unhandled register set %s\n", debug_d3dxparameter_registerset(desc.RegisterSet));
|
2011-06-21 21:14:30 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-16 17:21:20 +02:00
|
|
|
static HRESULT set_vector_array(ID3DXConstantTable *iface, IDirect3DDevice9 *device, D3DXHANDLE constant, const void *data,
|
|
|
|
UINT count, D3DXPARAMETER_TYPE type)
|
|
|
|
{
|
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
|
|
|
D3DXCONSTANT_DESC desc;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT i, j, desc_count = 1;
|
|
|
|
float vec[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
hr = ID3DXConstantTable_GetConstantDesc(iface, constant, &desc, &desc_count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
TRACE("ID3DXConstantTable_GetConstantDesc failed: %08x\n", hr);
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2012-08-21 14:52:15 +02:00
|
|
|
if (desc.Class == D3DXPC_MATRIX_ROWS || desc.Class == D3DXPC_MATRIX_COLUMNS)
|
|
|
|
return D3D_OK;
|
|
|
|
|
2012-08-16 17:21:20 +02:00
|
|
|
switch (desc.RegisterSet)
|
|
|
|
{
|
|
|
|
case D3DXRS_FLOAT4:
|
|
|
|
for (i = 0; i < min(count, desc.RegisterCount); i++)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case D3DXPT_FLOAT:
|
|
|
|
memcpy(vec, ((float *)data) + i * desc.Columns, desc.Columns * sizeof(float));
|
|
|
|
break;
|
|
|
|
case D3DXPT_INT:
|
|
|
|
for (j = 0; j < desc.Columns; j++)
|
|
|
|
vec[j] = (float)((int *)data)[i * desc.Columns + j];
|
|
|
|
break;
|
|
|
|
case D3DXPT_BOOL:
|
|
|
|
for (j = 0; j < desc.Columns; j++)
|
|
|
|
vec[j] = ((BOOL *)data)[i * desc.Columns + j] ? 1.0f : 0.0f;
|
|
|
|
break;
|
|
|
|
default:
|
2012-08-25 16:28:49 +02:00
|
|
|
FIXME("Unhandled type %s\n", debug_d3dxparameter_type(type));
|
2012-08-16 17:21:20 +02:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_float_shader_constant(This, device, desc.RegisterIndex + i, vec, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2012-08-25 16:28:53 +02:00
|
|
|
FIXME("Unhandled register set %s\n", debug_d3dxparameter_registerset(desc.RegisterSet));
|
2012-08-16 17:21:20 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-21 14:52:17 +02:00
|
|
|
static HRESULT set_float_matrix(FLOAT *matrix, const D3DXCONSTANT_DESC *desc,
|
|
|
|
UINT row_offset, UINT column_offset, UINT rows, UINT columns,
|
|
|
|
const void *data, D3DXPARAMETER_TYPE type, UINT src_columns)
|
|
|
|
{
|
|
|
|
UINT i, j;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case D3DXPT_FLOAT:
|
|
|
|
for (i = 0; i < rows; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < columns; j++)
|
|
|
|
matrix[i * row_offset + j * column_offset] = ((FLOAT *)data)[i * src_columns + j];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case D3DXPT_INT:
|
|
|
|
for (i = 0; i < rows; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < columns; j++)
|
|
|
|
matrix[i * row_offset + j * column_offset] = ((INT *)data)[i * src_columns + j];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2012-08-25 16:28:49 +02:00
|
|
|
FIXME("Unhandled type %s\n", debug_d3dxparameter_type(type));
|
2012-08-21 14:52:17 +02:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-16 17:21:20 +02:00
|
|
|
static HRESULT set_matrix_array(ID3DXConstantTable *iface, IDirect3DDevice9 *device, D3DXHANDLE constant, const void *data,
|
2012-08-21 14:52:17 +02:00
|
|
|
UINT count, D3DXPARAMETER_CLASS class, D3DXPARAMETER_TYPE type, UINT rows, UINT columns)
|
2012-08-16 17:21:20 +02:00
|
|
|
{
|
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
2012-08-28 13:42:55 +02:00
|
|
|
struct ctab_constant *c = get_valid_constant(This, constant);
|
|
|
|
D3DXCONSTANT_DESC *desc;
|
|
|
|
UINT registers_per_matrix, num_rows, num_columns, i;
|
|
|
|
UINT row_offset = 1, column_offset = 1;
|
2012-08-21 14:52:17 +02:00
|
|
|
const DWORD *data_ptr;
|
2012-08-16 17:21:20 +02:00
|
|
|
FLOAT matrix[16] = {0.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
|
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;
|
|
|
|
}
|
2012-08-28 13:42:55 +02:00
|
|
|
desc = &c->desc;
|
2012-08-16 17:21:20 +02:00
|
|
|
|
2012-08-28 13:42:55 +02:00
|
|
|
if (desc->Class == D3DXPC_MATRIX_ROWS
|
|
|
|
|| desc->Class == D3DXPC_MATRIX_COLUMNS
|
2012-08-28 13:43:04 +02:00
|
|
|
|| desc->Class == D3DXPC_VECTOR
|
2012-08-28 13:42:55 +02:00
|
|
|
|| desc->Class == D3DXPC_SCALAR)
|
2012-08-16 17:21:20 +02:00
|
|
|
{
|
2012-08-28 13:42:55 +02:00
|
|
|
if (desc->Class == class) row_offset = 4;
|
|
|
|
else column_offset = 4;
|
2012-08-21 14:52:17 +02:00
|
|
|
|
|
|
|
if (class == D3DXPC_MATRIX_ROWS)
|
|
|
|
{
|
2012-08-28 13:43:04 +02:00
|
|
|
if (desc->Class == D3DXPC_VECTOR) return D3D_OK;
|
|
|
|
|
2012-08-28 13:43:09 +02:00
|
|
|
num_rows = desc->Rows;
|
|
|
|
num_columns = desc->Columns;
|
2012-08-21 14:52:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-28 13:43:09 +02:00
|
|
|
num_rows = desc->Columns;
|
|
|
|
num_columns = desc->Rows;
|
2012-08-21 14:52:17 +02:00
|
|
|
}
|
|
|
|
|
2012-08-28 13:42:55 +02:00
|
|
|
registers_per_matrix = (desc->Class == D3DXPC_MATRIX_COLUMNS) ? desc->Columns : desc->Rows;
|
2012-08-21 14:52:14 +02:00
|
|
|
}
|
2012-08-16 17:21:20 +02:00
|
|
|
else
|
|
|
|
{
|
2012-08-28 13:42:55 +02:00
|
|
|
FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc->Class));
|
2012-08-28 13:43:04 +02:00
|
|
|
return E_NOTIMPL;
|
2012-08-16 17:21:20 +02:00
|
|
|
}
|
|
|
|
|
2012-08-28 13:42:55 +02:00
|
|
|
switch (desc->RegisterSet)
|
2012-08-16 17:21:20 +02:00
|
|
|
{
|
|
|
|
case D3DXRS_FLOAT4:
|
2012-08-21 14:52:17 +02:00
|
|
|
data_ptr = data;
|
2012-08-16 17:21:20 +02:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2012-08-28 13:42:55 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (registers_per_matrix * (i + 1) > desc->RegisterCount)
|
2012-08-16 17:21:20 +02:00
|
|
|
break;
|
|
|
|
|
2012-08-28 13:42:55 +02:00
|
|
|
hr = set_float_matrix(matrix, desc, row_offset, column_offset, num_rows, num_columns, data_ptr, type, columns);
|
2012-08-21 14:52:17 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
2012-08-16 17:21:20 +02:00
|
|
|
|
2012-08-28 13:42:55 +02:00
|
|
|
set_float_shader_constant(This, device, desc->RegisterIndex + i * registers_per_matrix, matrix, registers_per_matrix);
|
2012-08-21 14:52:17 +02:00
|
|
|
|
|
|
|
data_ptr += rows * columns;
|
2012-08-16 17:21:20 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2012-08-28 13:42:55 +02:00
|
|
|
FIXME("Unhandled register set %s\n", debug_d3dxparameter_registerset(desc->RegisterSet));
|
2012-08-16 17:21:20 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-21 14:52:19 +02:00
|
|
|
static HRESULT set_matrix_pointer_array(ID3DXConstantTable *iface, IDirect3DDevice9 *device, D3DXHANDLE constant,
|
|
|
|
const D3DXMATRIX **data, UINT count, D3DXPARAMETER_CLASS class)
|
|
|
|
{
|
|
|
|
struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
|
|
|
|
D3DXCONSTANT_DESC desc;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT registers_per_matrix;
|
|
|
|
UINT i, desc_count = 1;
|
|
|
|
UINT num_rows, num_columns;
|
|
|
|
UINT row_offset, column_offset;
|
|
|
|
FLOAT matrix[16] = {0.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
hr = ID3DXConstantTable_GetConstantDesc(iface, constant, &desc, &desc_count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
TRACE("ID3DXConstantTable_GetConstantDesc failed: %08x\n", hr);
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc.Class == D3DXPC_MATRIX_ROWS || desc.Class == D3DXPC_MATRIX_COLUMNS)
|
|
|
|
{
|
|
|
|
if (desc.Class == class)
|
|
|
|
{
|
|
|
|
column_offset = 1;
|
|
|
|
row_offset = 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
column_offset = 4;
|
|
|
|
row_offset = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (class == D3DXPC_MATRIX_ROWS)
|
|
|
|
{
|
|
|
|
num_rows = desc.Rows;
|
|
|
|
num_columns = desc.Columns;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
num_rows = desc.Columns;
|
|
|
|
num_columns = desc.Rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
registers_per_matrix = (desc.Class == D3DXPC_MATRIX_ROWS) ? desc.Rows : desc.Columns;
|
|
|
|
}
|
|
|
|
else if (desc.Class == D3DXPC_SCALAR)
|
|
|
|
{
|
|
|
|
registers_per_matrix = 1;
|
|
|
|
column_offset = 1;
|
|
|
|
row_offset = 1;
|
|
|
|
num_rows = desc.Rows;
|
|
|
|
num_columns = desc.Columns;
|
|
|
|
}
|
|
|
|
else if (desc.Class == D3DXPC_VECTOR)
|
|
|
|
{
|
|
|
|
registers_per_matrix = 1;
|
2012-08-21 14:52:20 +02:00
|
|
|
|
|
|
|
if (class == D3DXPC_MATRIX_ROWS)
|
|
|
|
{
|
|
|
|
column_offset = 1;
|
|
|
|
row_offset = 4;
|
|
|
|
num_rows = desc.Rows;
|
|
|
|
num_columns = desc.Columns;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
column_offset = 4;
|
|
|
|
row_offset = 1;
|
|
|
|
num_rows = desc.Columns;
|
|
|
|
num_columns = desc.Rows;
|
|
|
|
}
|
2012-08-21 14:52:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-25 16:28:49 +02:00
|
|
|
FIXME("Unhandled variable class %s\n", debug_d3dxparameter_class(desc.Class));
|
2012-08-21 14:52:19 +02:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (desc.RegisterSet)
|
|
|
|
{
|
|
|
|
case D3DXRS_FLOAT4:
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (registers_per_matrix * (i + 1) > desc.RegisterCount)
|
|
|
|
break;
|
|
|
|
|
|
|
|
hr = set_float_matrix(matrix, &desc, row_offset, column_offset, num_rows, num_columns, *data, D3DXPT_FLOAT, 4);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
set_float_shader_constant(This, device, desc.RegisterIndex + i * registers_per_matrix, matrix, registers_per_matrix);
|
|
|
|
|
|
|
|
data++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2012-08-25 16:28:53 +02:00
|
|
|
FIXME("Unhandled register set %s\n", debug_d3dxparameter_registerset(desc.RegisterSet));
|
2012-08-21 14:52:19 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, device);
|
|
|
|
|
|
|
|
if (!device)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
for (i = 0; i < This->desc.Constants; i++)
|
|
|
|
{
|
|
|
|
D3DXCONSTANT_DESC *desc = &This->constants[i].desc;
|
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
|
|
|
|
2012-08-14 11:42:33 +02:00
|
|
|
set_float_shader_constant(This, device, desc->RegisterIndex, desc->DefaultValue, desc->RegisterCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
struct IDirect3DDevice9 *device, D3DXHANDLE constant, const void *data, UINT bytes)
|
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-16 17:21:20 +02:00
|
|
|
HRESULT hr;
|
|
|
|
UINT elements;
|
|
|
|
UINT count = 1;
|
|
|
|
D3DXCONSTANT_DESC desc;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p, %p, %p, %d)\n", This, device, constant, data, bytes);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-16 17:21:20 +02:00
|
|
|
if (!device || !constant || !data)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
hr = ID3DXConstantTable_GetConstantDesc(iface, constant, &desc, &count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-16 17:21:20 +02:00
|
|
|
elements = bytes / (desc.Bytes / desc.Elements);
|
|
|
|
|
|
|
|
switch (desc.Class)
|
|
|
|
{
|
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
return set_scalar_array(iface, device, constant, data, elements, desc.Type);
|
|
|
|
case D3DXPC_VECTOR:
|
2012-08-25 16:28:49 +02:00
|
|
|
return set_vector_array(iface, device, constant, data, elements, desc.Type);
|
2012-08-16 17:21:20 +02:00
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
2012-08-21 14:52:17 +02:00
|
|
|
return set_matrix_array(iface, device, constant, data, elements,
|
|
|
|
D3DXPC_MATRIX_ROWS, desc.Type, desc.Rows, desc.Columns);
|
2012-08-16 17:21:20 +02:00
|
|
|
default:
|
2012-08-25 16:28:49 +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
|
|
|
|
2012-08-16 17:21:17 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %d)\n", This, device, constant, b);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-16 17:21:17 +02:00
|
|
|
return set_scalar_array(iface, device, constant, &b, 1, 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
|
|
|
|
2012-08-16 17:21:18 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p, %d)\n", This, device, constant, b, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-16 17:21:18 +02:00
|
|
|
return set_scalar_array(iface, 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
|
|
|
|
2011-06-21 21:14:31 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %d)\n", This, device, constant, n);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-16 17:21:17 +02:00
|
|
|
return set_scalar_array(iface, device, constant, &n, 1, 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
|
|
|
|
2011-06-21 21:14:31 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p, %d)\n", This, device, constant, n, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-16 17:21:17 +02:00
|
|
|
return set_scalar_array(iface, 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
|
|
|
|
2011-06-21 21:14:30 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %f)\n", This, device, constant, f);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-16 17:21:17 +02:00
|
|
|
return set_scalar_array(iface, device, constant, &f, 1, 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
|
|
|
|
2011-06-21 21:14:30 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p, %d)\n", This, device, constant, f, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-16 17:21:17 +02:00
|
|
|
return set_scalar_array(iface, 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
|
|
|
|
2011-06-21 21:14:32 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p)\n", This, device, constant, vector);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-16 17:21:22 +02:00
|
|
|
return set_vector_array(iface, device, constant, vector, 1, 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
|
|
|
|
|
|
|
TRACE("(%p)->(%p, %p, %p, %d)\n", This, device, constant, vector, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-16 17:21:22 +02:00
|
|
|
return set_vector_array(iface, 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
|
|
|
|
2011-06-21 21:14:33 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p)\n", This, device, constant, matrix);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-21 14:52:17 +02:00
|
|
|
return set_matrix_array(iface, device, constant, matrix, 1, D3DXPC_MATRIX_ROWS, D3DXPT_FLOAT, 4, 4);
|
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
|
|
|
|
2011-06-21 21:14:33 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p, %d)\n", This, device, constant, matrix, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-21 14:52:17 +02:00
|
|
|
return set_matrix_array(iface, device, constant, matrix, count, D3DXPC_MATRIX_ROWS, D3DXPT_FLOAT, 4, 4);
|
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
|
|
|
|
2012-08-21 14:52:19 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p, %d)\n", This, device, constant, matrix, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-21 14:52:19 +02:00
|
|
|
return set_matrix_pointer_array(iface, device, constant, matrix, count, D3DXPC_MATRIX_ROWS);
|
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
|
|
|
|
2012-08-21 14:52:18 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p)\n", This, device, constant, matrix);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-21 14:52:18 +02:00
|
|
|
return set_matrix_array(iface, device, constant, matrix, 1, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 4, 4);
|
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
|
|
|
|
2012-08-21 14:52:17 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p, %d)\n", This, device, constant, matrix, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-21 14:52:17 +02:00
|
|
|
return set_matrix_array(iface, device, constant, matrix, count, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 4, 4);
|
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
|
|
|
|
2012-08-21 14:52:20 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p, %d)\n", This, device, constant, matrix, count);
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2012-08-21 14:52:20 +02:00
|
|
|
return set_matrix_pointer_array(iface, device, constant, matrix, count, D3DXPC_MATRIX_COLUMNS);
|
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,
|
|
|
|
BOOL is_element, WORD index, WORD max, 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,
|
|
|
|
&constant->constants[i], memberinfo == NULL, index + size, max, offset,
|
|
|
|
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
|
|
|
|
{
|
|
|
|
WORD offsetdiff = 0;
|
|
|
|
|
|
|
|
switch (type->Class)
|
|
|
|
{
|
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
offsetdiff = 1;
|
|
|
|
size = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
size = is_element ? type->Rows : max(type->Rows, type->Columns);
|
|
|
|
offsetdiff = type->Rows;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
|
|
|
size = type->Columns;
|
|
|
|
offsetdiff = type->Columns;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DXPC_OBJECT:
|
|
|
|
size = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-08-25 16:28:49 +02:00
|
|
|
FIXME("Unhandled type class %s\n", debug_d3dxparameter_class(type->Class));
|
2012-08-23 21:36:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* offset in bytes => offsetdiff * components(4) * sizeof(DWORD) */
|
|
|
|
if (offset) *offset += offsetdiff * 4 * 4;
|
2012-09-26 12:22:02 +02:00
|
|
|
|
|
|
|
/* int and bool registerset have different sizes */
|
|
|
|
if (regset == D3DXRS_INT4 || regset == D3DXRS_BOOL)
|
|
|
|
{
|
|
|
|
switch (type->Class)
|
|
|
|
{
|
|
|
|
case D3DXPC_SCALAR:
|
|
|
|
case D3DXPC_VECTOR:
|
|
|
|
size = type->Columns;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DXPC_MATRIX_ROWS:
|
|
|
|
case D3DXPC_MATRIX_COLUMNS:
|
|
|
|
size = 4 * type->Columns;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled type class %s\n", debug_d3dxparameter_class(type->Class));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 21:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
constant->desc.RegisterCount = max(0, min(max - 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;
|
2010-03-01 09:39:29 +01:00
|
|
|
HRESULT hr;
|
|
|
|
LPCVOID data;
|
|
|
|
UINT size;
|
2010-03-27 10:55:51 +01:00
|
|
|
const D3DXSHADER_CONSTANTTABLE* ctab_header;
|
2010-09-10 18:42:45 +02:00
|
|
|
D3DXSHADER_CONSTANTINFO* constant_info;
|
|
|
|
DWORD i;
|
2010-03-01 09:39:18 +01:00
|
|
|
|
2010-09-10 18:42:45 +02:00
|
|
|
TRACE("(%p, %x, %p)\n", byte_code, flags, constant_table);
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (size < sizeof(D3DXSHADER_CONSTANTTABLE))
|
|
|
|
{
|
|
|
|
WARN("Invalid CTAB size.\n");
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctab_header = (const D3DXSHADER_CONSTANTTABLE *)data;
|
|
|
|
if (ctab_header->Size != sizeof(D3DXSHADER_CONSTANTTABLE))
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
constant_info = (LPD3DXSHADER_CONSTANTINFO)(object->ctab + ctab_header->ConstantInfo);
|
|
|
|
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;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
HRESULT WINAPI D3DXGetShaderSamplers(CONST DWORD *byte_code, LPCSTR *samplers, UINT *count)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
UINT i, sampler_count = 0;
|
2011-09-16 08:38:24 +02:00
|
|
|
UINT size;
|
|
|
|
LPCSTR data;
|
|
|
|
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;
|
|
|
|
|
2011-09-16 08:38:24 +02:00
|
|
|
hr = D3DXFindShaderComment(byte_code, MAKEFOURCC('C','T','A','B'), (LPCVOID *)&data, &size);
|
|
|
|
if (hr != D3D_OK) return D3D_OK;
|
2011-07-15 10:52:36 +02:00
|
|
|
|
2011-09-16 08:38:24 +02:00
|
|
|
if (size < sizeof(D3DXSHADER_CONSTANTTABLE)) 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
|
|
|
|
2011-09-16 08:38:24 +02:00
|
|
|
constant_info = (D3DXSHADER_CONSTANTINFO *)(data + ctab_header->ConstantInfo);
|
|
|
|
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);
|
|
|
|
|
|
|
|
type = (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
|
|
|
}
|