2005-08-25 21:24:21 +02:00
|
|
|
/*
|
|
|
|
* shaders implementation
|
|
|
|
*
|
2006-05-08 21:44:25 +02:00
|
|
|
* Copyright 2002-2003 Jason Edmeades
|
|
|
|
* Copyright 2002-2003 Raphael Junqueira
|
2006-07-17 20:35:14 +02:00
|
|
|
* Copyright 2004 Christian Costa
|
2006-05-08 21:44:25 +02:00
|
|
|
* Copyright 2005 Oliver Stieber
|
2006-05-17 08:04:30 +02:00
|
|
|
* Copyright 2006 Ivan Gyurdiev
|
2008-10-18 19:21:20 +02:00
|
|
|
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
2005-08-25 21:24:21 +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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-08-25 21:24:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
2005-11-21 17:27:55 +01:00
|
|
|
#include <stdio.h>
|
2005-08-25 21:24:21 +02:00
|
|
|
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
|
|
|
|
|
2007-06-09 14:27:41 +02:00
|
|
|
#define GLINFO_LOCATION ((IWineD3DDeviceImpl *) This->baseShader.device)->adapter->gl_info
|
2005-08-25 21:24:21 +02:00
|
|
|
|
2007-11-16 21:01:33 +01:00
|
|
|
static HRESULT WINAPI IWineD3DPixelShaderImpl_QueryInterface(IWineD3DPixelShader *iface, REFIID riid, LPVOID *ppobj) {
|
2008-12-09 09:52:39 +01:00
|
|
|
TRACE("iface %p, riid %s, ppobj %p\n", iface, debugstr_guid(riid), ppobj);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IWineD3DPixelShader)
|
|
|
|
|| IsEqualGUID(riid, &IID_IWineD3DBaseShader)
|
|
|
|
|| IsEqualGUID(riid, &IID_IWineD3DBase)
|
|
|
|
|| IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
*ppobj = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
*ppobj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
2005-08-25 21:24:21 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static ULONG WINAPI IWineD3DPixelShaderImpl_AddRef(IWineD3DPixelShader *iface) {
|
2008-12-09 09:52:39 +01:00
|
|
|
IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
|
|
|
|
ULONG refcount = InterlockedIncrement(&This->baseShader.ref);
|
|
|
|
|
|
|
|
TRACE("%p increasing refcount to %u\n", This, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
2005-08-25 21:24:21 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static ULONG WINAPI IWineD3DPixelShaderImpl_Release(IWineD3DPixelShader *iface) {
|
2008-12-09 09:52:39 +01:00
|
|
|
IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
|
|
|
|
ULONG refcount = InterlockedDecrement(&This->baseShader.ref);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u\n", This, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
|
|
|
shader_cleanup((IWineD3DBaseShader *)iface);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
2005-08-25 21:24:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* *******************************************
|
|
|
|
IWineD3DPixelShader IWineD3DPixelShader parts follow
|
|
|
|
******************************************* */
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DPixelShaderImpl_GetParent(IWineD3DPixelShader *iface, IUnknown** parent){
|
2005-08-25 21:24:21 +02:00
|
|
|
IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
|
|
|
|
|
2005-12-03 18:10:56 +01:00
|
|
|
*parent = This->parent;
|
2005-08-25 21:24:21 +02:00
|
|
|
IUnknown_AddRef(*parent);
|
|
|
|
TRACE("(%p) : returning %p\n", This, *parent);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-08-25 21:24:21 +02:00
|
|
|
}
|
2005-11-21 17:27:55 +01:00
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DPixelShaderImpl_GetDevice(IWineD3DPixelShader* iface, IWineD3DDevice **pDevice){
|
2005-08-25 21:24:21 +02:00
|
|
|
IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
|
2006-09-27 13:14:46 +02:00
|
|
|
IWineD3DDevice_AddRef(This->baseShader.device);
|
|
|
|
*pDevice = This->baseShader.device;
|
2005-08-25 21:24:21 +02:00
|
|
|
TRACE("(%p) returning %p\n", This, *pDevice);
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-08-25 21:24:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DPixelShaderImpl_GetFunction(IWineD3DPixelShader* impl, VOID* pData, UINT* pSizeOfData) {
|
2005-08-25 21:24:21 +02:00
|
|
|
IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)impl;
|
2006-06-09 23:46:38 +02:00
|
|
|
TRACE("(%p) : pData(%p), pSizeOfData(%p)\n", This, pData, pSizeOfData);
|
2005-08-25 21:24:21 +02:00
|
|
|
|
|
|
|
if (NULL == pData) {
|
2006-03-30 19:14:31 +02:00
|
|
|
*pSizeOfData = This->baseShader.functionLength;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-08-25 21:24:21 +02:00
|
|
|
}
|
2006-03-30 19:14:31 +02:00
|
|
|
if (*pSizeOfData < This->baseShader.functionLength) {
|
2007-03-08 01:16:09 +01:00
|
|
|
/* MSDN claims (for d3d8 at least) that if *pSizeOfData is smaller
|
|
|
|
* than the required size we should write the required size and
|
|
|
|
* return D3DERR_MOREDATA. That's not actually true. */
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-08-25 21:24:21 +02:00
|
|
|
}
|
2008-12-15 16:35:14 +01:00
|
|
|
|
|
|
|
TRACE("(%p) : GetFunction copying to %p\n", This, pData);
|
|
|
|
memcpy(pData, This->baseShader.function, This->baseShader.functionLength);
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-08-25 21:24:21 +02:00
|
|
|
}
|
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
const SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[] =
|
|
|
|
{
|
2008-01-09 20:37:05 +01:00
|
|
|
/* Arithmetic */
|
2009-04-27 09:37:14 +02:00
|
|
|
{WINED3DSIO_NOP, 0, 0, WINED3DSIH_NOP, 0, 0 },
|
|
|
|
{WINED3DSIO_MOV, 1, 2, WINED3DSIH_MOV, 0, 0 },
|
|
|
|
{WINED3DSIO_ADD, 1, 3, WINED3DSIH_ADD, 0, 0 },
|
|
|
|
{WINED3DSIO_SUB, 1, 3, WINED3DSIH_SUB, 0, 0 },
|
|
|
|
{WINED3DSIO_MAD, 1, 4, WINED3DSIH_MAD, 0, 0 },
|
|
|
|
{WINED3DSIO_MUL, 1, 3, WINED3DSIH_MUL, 0, 0 },
|
|
|
|
{WINED3DSIO_RCP, 1, 2, WINED3DSIH_RCP, 0, 0 },
|
|
|
|
{WINED3DSIO_RSQ, 1, 2, WINED3DSIH_RSQ, 0, 0 },
|
|
|
|
{WINED3DSIO_DP3, 1, 3, WINED3DSIH_DP3, 0, 0 },
|
|
|
|
{WINED3DSIO_DP4, 1, 3, WINED3DSIH_DP4, 0, 0 },
|
|
|
|
{WINED3DSIO_MIN, 1, 3, WINED3DSIH_MIN, 0, 0 },
|
|
|
|
{WINED3DSIO_MAX, 1, 3, WINED3DSIH_MAX, 0, 0 },
|
|
|
|
{WINED3DSIO_SLT, 1, 3, WINED3DSIH_SLT, 0, 0 },
|
|
|
|
{WINED3DSIO_SGE, 1, 3, WINED3DSIH_SGE, 0, 0 },
|
|
|
|
{WINED3DSIO_ABS, 1, 2, WINED3DSIH_ABS, 0, 0 },
|
|
|
|
{WINED3DSIO_EXP, 1, 2, WINED3DSIH_EXP, 0, 0 },
|
|
|
|
{WINED3DSIO_LOG, 1, 2, WINED3DSIH_LOG, 0, 0 },
|
|
|
|
{WINED3DSIO_EXPP, 1, 2, WINED3DSIH_EXPP, 0, 0 },
|
|
|
|
{WINED3DSIO_LOGP, 1, 2, WINED3DSIH_LOGP, 0, 0 },
|
|
|
|
{WINED3DSIO_DST, 1, 3, WINED3DSIH_DST, 0, 0 },
|
|
|
|
{WINED3DSIO_LRP, 1, 4, WINED3DSIH_LRP, 0, 0 },
|
|
|
|
{WINED3DSIO_FRC, 1, 2, WINED3DSIH_FRC, 0, 0 },
|
|
|
|
{WINED3DSIO_CND, 1, 4, WINED3DSIH_CND, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,4)},
|
|
|
|
{WINED3DSIO_CMP, 1, 4, WINED3DSIH_CMP, WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(3,0)},
|
|
|
|
{WINED3DSIO_POW, 1, 3, WINED3DSIH_POW, 0, 0 },
|
|
|
|
{WINED3DSIO_CRS, 1, 3, WINED3DSIH_CRS, 0, 0 },
|
|
|
|
{WINED3DSIO_NRM, 1, 2, WINED3DSIH_NRM, 0, 0 },
|
|
|
|
{WINED3DSIO_SINCOS, 1, 4, WINED3DSIH_SINCOS, WINED3DPS_VERSION(2,0), WINED3DPS_VERSION(2,1)},
|
|
|
|
{WINED3DSIO_SINCOS, 1, 2, WINED3DSIH_SINCOS, WINED3DPS_VERSION(3,0), -1 },
|
|
|
|
{WINED3DSIO_DP2ADD, 1, 4, WINED3DSIH_DP2ADD, WINED3DPS_VERSION(2,0), -1 },
|
2006-05-10 00:05:26 +02:00
|
|
|
/* Matrix */
|
2009-04-27 09:37:14 +02:00
|
|
|
{WINED3DSIO_M4x4, 1, 3, WINED3DSIH_M4x4, 0, 0 },
|
|
|
|
{WINED3DSIO_M4x3, 1, 3, WINED3DSIH_M4x3, 0, 0 },
|
|
|
|
{WINED3DSIO_M3x4, 1, 3, WINED3DSIH_M3x4, 0, 0 },
|
|
|
|
{WINED3DSIO_M3x3, 1, 3, WINED3DSIH_M3x3, 0, 0 },
|
|
|
|
{WINED3DSIO_M3x2, 1, 3, WINED3DSIH_M3x2, 0, 0 },
|
2006-05-10 00:05:26 +02:00
|
|
|
/* Register declarations */
|
2009-04-27 09:37:14 +02:00
|
|
|
{WINED3DSIO_DCL, 0, 2, WINED3DSIH_DCL, 0, 0 },
|
|
|
|
/* Flow control */
|
|
|
|
{WINED3DSIO_REP, 0, 1, WINED3DSIH_REP, WINED3DPS_VERSION(2,1), -1 },
|
|
|
|
{WINED3DSIO_ENDREP, 0, 0, WINED3DSIH_ENDREP, WINED3DPS_VERSION(2,1), -1 },
|
|
|
|
{WINED3DSIO_IF, 0, 1, WINED3DSIH_IF, WINED3DPS_VERSION(2,1), -1 },
|
|
|
|
{WINED3DSIO_IFC, 0, 2, WINED3DSIH_IFC, WINED3DPS_VERSION(2,1), -1 },
|
|
|
|
{WINED3DSIO_ELSE, 0, 0, WINED3DSIH_ELSE, WINED3DPS_VERSION(2,1), -1 },
|
|
|
|
{WINED3DSIO_ENDIF, 0, 0, WINED3DSIH_ENDIF, WINED3DPS_VERSION(2,1), -1 },
|
|
|
|
{WINED3DSIO_BREAK, 0, 0, WINED3DSIH_BREAK, WINED3DPS_VERSION(2,1), -1 },
|
|
|
|
{WINED3DSIO_BREAKC, 0, 2, WINED3DSIH_BREAKC, WINED3DPS_VERSION(2,1), -1 },
|
|
|
|
{WINED3DSIO_BREAKP, 0, 1, WINED3DSIH_BREAKP, 0, 0 },
|
|
|
|
{WINED3DSIO_CALL, 0, 1, WINED3DSIH_CALL, WINED3DPS_VERSION(2,1), -1 },
|
|
|
|
{WINED3DSIO_CALLNZ, 0, 2, WINED3DSIH_CALLNZ, WINED3DPS_VERSION(2,1), -1 },
|
|
|
|
{WINED3DSIO_LOOP, 0, 2, WINED3DSIH_LOOP, WINED3DPS_VERSION(3,0), -1 },
|
|
|
|
{WINED3DSIO_RET, 0, 0, WINED3DSIH_RET, WINED3DPS_VERSION(2,1), -1 },
|
|
|
|
{WINED3DSIO_ENDLOOP, 0, 0, WINED3DSIH_ENDLOOP, WINED3DPS_VERSION(3,0), -1 },
|
|
|
|
{WINED3DSIO_LABEL, 0, 1, WINED3DSIH_LABEL, WINED3DPS_VERSION(2,1), -1 },
|
2006-05-10 00:05:26 +02:00
|
|
|
/* Constant definitions */
|
2009-04-27 09:37:14 +02:00
|
|
|
{WINED3DSIO_DEF, 1, 5, WINED3DSIH_DEF, 0, 0 },
|
|
|
|
{WINED3DSIO_DEFB, 1, 2, WINED3DSIH_DEFB, 0, 0 },
|
|
|
|
{WINED3DSIO_DEFI, 1, 5, WINED3DSIH_DEFI, 0, 0 },
|
2006-05-10 00:05:26 +02:00
|
|
|
/* Texture */
|
2009-04-27 09:37:14 +02:00
|
|
|
{WINED3DSIO_TEXCOORD, 1, 1, WINED3DSIH_TEXCOORD, 0, WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXCOORD, 1, 2, WINED3DSIH_TEXCOORD, WINED3DPS_VERSION(1,4), WINED3DPS_VERSION(1,4)},
|
|
|
|
{WINED3DSIO_TEXKILL, 1, 1, WINED3DSIH_TEXKILL, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(3,0)},
|
|
|
|
{WINED3DSIO_TEX, 1, 1, WINED3DSIH_TEX, 0, WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEX, 1, 2, WINED3DSIH_TEX, WINED3DPS_VERSION(1,4), WINED3DPS_VERSION(1,4)},
|
|
|
|
{WINED3DSIO_TEX, 1, 3, WINED3DSIH_TEX, WINED3DPS_VERSION(2,0), -1 },
|
|
|
|
{WINED3DSIO_TEXBEM, 1, 2, WINED3DSIH_TEXBEM, 0, WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXBEML, 1, 2, WINED3DSIH_TEXBEML, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXREG2AR, 1, 2, WINED3DSIH_TEXREG2AR, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXREG2GB, 1, 2, WINED3DSIH_TEXREG2GB, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXREG2RGB, 1, 2, WINED3DSIH_TEXREG2RGB, WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXM3x2PAD, 1, 2, WINED3DSIH_TEXM3x2PAD, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXM3x2TEX, 1, 2, WINED3DSIH_TEXM3x2TEX, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXM3x3PAD, 1, 2, WINED3DSIH_TEXM3x3PAD, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXM3x3DIFF, 1, 2, WINED3DSIH_TEXM3x3DIFF, WINED3DPS_VERSION(0,0), WINED3DPS_VERSION(0,0)},
|
|
|
|
{WINED3DSIO_TEXM3x3SPEC, 1, 3, WINED3DSIH_TEXM3x3SPEC, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXM3x3VSPEC, 1, 2, WINED3DSIH_TEXM3x3VSPEC, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXM3x3TEX, 1, 2, WINED3DSIH_TEXM3x3TEX, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXDP3TEX, 1, 2, WINED3DSIH_TEXDP3TEX, WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXM3x2DEPTH, 1, 2, WINED3DSIH_TEXM3x2DEPTH, WINED3DPS_VERSION(1,3), WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXDP3, 1, 2, WINED3DSIH_TEXDP3, WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXM3x3, 1, 2, WINED3DSIH_TEXM3x3, WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(1,3)},
|
|
|
|
{WINED3DSIO_TEXDEPTH, 1, 1, WINED3DSIH_TEXDEPTH, WINED3DPS_VERSION(1,4), WINED3DPS_VERSION(1,4)},
|
|
|
|
{WINED3DSIO_BEM, 1, 3, WINED3DSIH_BEM, WINED3DPS_VERSION(1,4), WINED3DPS_VERSION(1,4)},
|
|
|
|
{WINED3DSIO_DSX, 1, 2, WINED3DSIH_DSX, WINED3DPS_VERSION(2,1), -1 },
|
|
|
|
{WINED3DSIO_DSY, 1, 2, WINED3DSIH_DSY, WINED3DPS_VERSION(2,1), -1 },
|
|
|
|
{WINED3DSIO_TEXLDD, 1, 5, WINED3DSIH_TEXLDD, WINED3DPS_VERSION(2,1), -1 },
|
|
|
|
{WINED3DSIO_SETP, 1, 3, WINED3DSIH_SETP, 0, 0 },
|
|
|
|
{WINED3DSIO_TEXLDL, 1, 3, WINED3DSIH_TEXLDL, WINED3DPS_VERSION(3,0), -1 },
|
|
|
|
{WINED3DSIO_PHASE, 0, 0, WINED3DSIH_PHASE, 0, 0 },
|
|
|
|
{0, 0, 0, WINED3DSIH_TABLE_SIZE, 0, 0 },
|
2005-11-21 17:27:55 +01:00
|
|
|
};
|
|
|
|
|
2006-06-12 08:54:30 +02:00
|
|
|
static void pshader_set_limits(
|
|
|
|
IWineD3DPixelShaderImpl *This) {
|
2006-05-08 23:09:21 +02:00
|
|
|
|
2006-05-26 17:52:33 +02:00
|
|
|
This->baseShader.limits.attributes = 0;
|
2006-05-08 23:09:21 +02:00
|
|
|
This->baseShader.limits.address = 0;
|
2006-06-12 08:57:07 +02:00
|
|
|
This->baseShader.limits.packed_output = 0;
|
2006-05-08 23:09:21 +02:00
|
|
|
|
2008-12-15 12:10:14 +01:00
|
|
|
switch (This->baseShader.reg_maps.shader_version)
|
|
|
|
{
|
2006-10-13 05:36:41 +02:00
|
|
|
case WINED3DPS_VERSION(1,0):
|
|
|
|
case WINED3DPS_VERSION(1,1):
|
|
|
|
case WINED3DPS_VERSION(1,2):
|
|
|
|
case WINED3DPS_VERSION(1,3):
|
2006-06-12 08:54:30 +02:00
|
|
|
This->baseShader.limits.temporary = 2;
|
2006-05-08 23:09:21 +02:00
|
|
|
This->baseShader.limits.constant_float = 8;
|
|
|
|
This->baseShader.limits.constant_int = 0;
|
|
|
|
This->baseShader.limits.constant_bool = 0;
|
2006-06-12 08:59:16 +02:00
|
|
|
This->baseShader.limits.texcoord = 4;
|
|
|
|
This->baseShader.limits.sampler = 4;
|
2006-06-12 08:57:07 +02:00
|
|
|
This->baseShader.limits.packed_input = 0;
|
2006-07-10 12:35:15 +02:00
|
|
|
This->baseShader.limits.label = 0;
|
2006-05-08 23:09:21 +02:00
|
|
|
break;
|
|
|
|
|
2006-10-13 05:36:41 +02:00
|
|
|
case WINED3DPS_VERSION(1,4):
|
2006-06-12 08:54:30 +02:00
|
|
|
This->baseShader.limits.temporary = 6;
|
2006-05-08 23:09:21 +02:00
|
|
|
This->baseShader.limits.constant_float = 8;
|
|
|
|
This->baseShader.limits.constant_int = 0;
|
|
|
|
This->baseShader.limits.constant_bool = 0;
|
2006-06-12 08:59:16 +02:00
|
|
|
This->baseShader.limits.texcoord = 6;
|
|
|
|
This->baseShader.limits.sampler = 6;
|
2006-06-12 08:57:07 +02:00
|
|
|
This->baseShader.limits.packed_input = 0;
|
2006-07-10 12:35:15 +02:00
|
|
|
This->baseShader.limits.label = 0;
|
2006-05-08 23:09:21 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* FIXME: temporaries must match D3DPSHADERCAPS2_0.NumTemps */
|
2006-10-13 05:36:41 +02:00
|
|
|
case WINED3DPS_VERSION(2,0):
|
2006-07-10 12:35:15 +02:00
|
|
|
This->baseShader.limits.temporary = 32;
|
|
|
|
This->baseShader.limits.constant_float = 32;
|
|
|
|
This->baseShader.limits.constant_int = 16;
|
|
|
|
This->baseShader.limits.constant_bool = 16;
|
|
|
|
This->baseShader.limits.texcoord = 8;
|
|
|
|
This->baseShader.limits.sampler = 16;
|
|
|
|
This->baseShader.limits.packed_input = 0;
|
|
|
|
break;
|
|
|
|
|
2006-10-13 05:36:41 +02:00
|
|
|
case WINED3DPS_VERSION(2,1):
|
2006-06-12 08:54:30 +02:00
|
|
|
This->baseShader.limits.temporary = 32;
|
2006-05-08 23:09:21 +02:00
|
|
|
This->baseShader.limits.constant_float = 32;
|
|
|
|
This->baseShader.limits.constant_int = 16;
|
|
|
|
This->baseShader.limits.constant_bool = 16;
|
2006-06-12 08:59:16 +02:00
|
|
|
This->baseShader.limits.texcoord = 8;
|
|
|
|
This->baseShader.limits.sampler = 16;
|
2006-06-12 08:57:07 +02:00
|
|
|
This->baseShader.limits.packed_input = 0;
|
2006-07-10 12:35:15 +02:00
|
|
|
This->baseShader.limits.label = 16;
|
2006-05-08 23:09:21 +02:00
|
|
|
break;
|
|
|
|
|
2006-10-13 05:36:41 +02:00
|
|
|
case WINED3DPS_VERSION(3,0):
|
2006-06-12 08:54:30 +02:00
|
|
|
This->baseShader.limits.temporary = 32;
|
2006-05-08 23:09:21 +02:00
|
|
|
This->baseShader.limits.constant_float = 224;
|
|
|
|
This->baseShader.limits.constant_int = 16;
|
|
|
|
This->baseShader.limits.constant_bool = 16;
|
2006-06-12 08:59:16 +02:00
|
|
|
This->baseShader.limits.texcoord = 0;
|
|
|
|
This->baseShader.limits.sampler = 16;
|
2006-06-12 08:57:07 +02:00
|
|
|
This->baseShader.limits.packed_input = 12;
|
2006-07-10 12:35:15 +02:00
|
|
|
This->baseShader.limits.label = 16; /* FIXME: 2048 */
|
2006-05-08 23:09:21 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: This->baseShader.limits.temporary = 32;
|
2006-06-12 08:59:16 +02:00
|
|
|
This->baseShader.limits.constant_float = 32;
|
|
|
|
This->baseShader.limits.constant_int = 16;
|
|
|
|
This->baseShader.limits.constant_bool = 16;
|
|
|
|
This->baseShader.limits.texcoord = 8;
|
|
|
|
This->baseShader.limits.sampler = 16;
|
2006-06-12 08:57:07 +02:00
|
|
|
This->baseShader.limits.packed_input = 0;
|
2006-07-10 12:35:15 +02:00
|
|
|
This->baseShader.limits.label = 0;
|
2008-12-15 12:10:14 +01:00
|
|
|
FIXME("Unrecognized pixel shader version %#x\n",
|
|
|
|
This->baseShader.reg_maps.shader_version);
|
2006-05-08 23:09:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DPixelShaderImpl_SetFunction(IWineD3DPixelShader *iface, CONST DWORD *pFunction) {
|
2006-06-12 08:54:30 +02:00
|
|
|
|
|
|
|
IWineD3DPixelShaderImpl *This =(IWineD3DPixelShaderImpl *)iface;
|
2006-10-08 05:25:01 +02:00
|
|
|
IWineD3DDeviceImpl *deviceImpl = (IWineD3DDeviceImpl *) This->baseShader.device;
|
2008-12-11 11:52:37 +01:00
|
|
|
unsigned int i, highest_reg_used = 0, num_regs_used = 0;
|
|
|
|
shader_reg_maps *reg_maps = &This->baseShader.reg_maps;
|
|
|
|
HRESULT hr;
|
2006-06-12 08:54:30 +02:00
|
|
|
|
2006-07-25 00:51:03 +02:00
|
|
|
TRACE("(%p) : pFunction %p\n", iface, pFunction);
|
|
|
|
|
2006-07-04 10:01:46 +02:00
|
|
|
/* First pass: trace shader */
|
2008-12-11 11:52:37 +01:00
|
|
|
if (TRACE_ON(d3d_shader)) shader_trace_init(pFunction, This->baseShader.shader_ins);
|
2005-11-21 17:27:55 +01:00
|
|
|
|
2006-07-10 06:51:03 +02:00
|
|
|
/* Initialize immediate constant lists */
|
|
|
|
list_init(&This->baseShader.constantsF);
|
|
|
|
list_init(&This->baseShader.constantsB);
|
|
|
|
list_init(&This->baseShader.constantsI);
|
|
|
|
|
2008-12-11 11:52:37 +01:00
|
|
|
/* Second pass: figure out which registers are used, what the semantics are, etc.. */
|
|
|
|
memset(reg_maps, 0, sizeof(shader_reg_maps));
|
2008-12-12 09:33:51 +01:00
|
|
|
hr = shader_get_registers_used((IWineD3DBaseShader *)This, reg_maps, This->semantics_in, NULL, pFunction);
|
2008-12-11 11:52:37 +01:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
pshader_set_limits(This);
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_REG_INPUT; ++i)
|
|
|
|
{
|
|
|
|
if (This->input_reg_used[i])
|
|
|
|
{
|
|
|
|
++num_regs_used;
|
|
|
|
highest_reg_used = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't do any register mapping magic if it is not needed, or if we can't
|
|
|
|
* achieve anything anyway */
|
|
|
|
if (highest_reg_used < (GL_LIMITS(glsl_varyings) / 4)
|
|
|
|
|| num_regs_used > (GL_LIMITS(glsl_varyings) / 4))
|
|
|
|
{
|
|
|
|
if (num_regs_used > (GL_LIMITS(glsl_varyings) / 4))
|
|
|
|
{
|
|
|
|
/* This happens with relative addressing. The input mapper function
|
|
|
|
* warns about this if the higher registers are declared too, so
|
|
|
|
* don't write a FIXME here */
|
|
|
|
WARN("More varying registers used than supported\n");
|
2007-11-06 12:34:22 +01:00
|
|
|
}
|
|
|
|
|
2008-12-11 11:52:37 +01:00
|
|
|
for (i = 0; i < MAX_REG_INPUT; ++i)
|
|
|
|
{
|
|
|
|
This->input_reg_map[i] = i;
|
2007-10-28 00:12:37 +02:00
|
|
|
}
|
2008-12-11 11:52:37 +01:00
|
|
|
|
|
|
|
This->declared_in_count = highest_reg_used + 1;
|
2007-06-07 23:52:48 +02:00
|
|
|
}
|
2008-12-11 11:52:37 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
This->declared_in_count = 0;
|
|
|
|
for (i = 0; i < MAX_REG_INPUT; ++i)
|
|
|
|
{
|
|
|
|
if (This->input_reg_used[i]) This->input_reg_map[i] = This->declared_in_count++;
|
2009-03-25 10:12:27 +01:00
|
|
|
else This->input_reg_map[i] = ~0U;
|
2008-12-11 11:52:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-09 14:48:47 +01:00
|
|
|
This->baseShader.load_local_constsF = FALSE;
|
2007-06-07 23:52:48 +02:00
|
|
|
|
2006-10-08 05:25:01 +02:00
|
|
|
This->baseShader.shader_mode = deviceImpl->ps_selected_mode;
|
2005-11-21 17:27:55 +01:00
|
|
|
|
|
|
|
TRACE("(%p) : Copying the function\n", This);
|
2008-12-15 16:35:14 +01:00
|
|
|
|
|
|
|
This->baseShader.function = HeapAlloc(GetProcessHeap(), 0, This->baseShader.functionLength);
|
|
|
|
if (!This->baseShader.function) return E_OUTOFMEMORY;
|
|
|
|
memcpy(This->baseShader.function, pFunction, This->baseShader.functionLength);
|
2005-11-21 17:27:55 +01:00
|
|
|
|
2006-08-05 18:15:35 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2008-12-15 12:10:14 +01:00
|
|
|
static void pixelshader_update_samplers(struct shader_reg_maps *reg_maps, IWineD3DBaseTexture * const *textures)
|
2008-12-12 09:33:51 +01:00
|
|
|
{
|
2008-12-15 12:10:14 +01:00
|
|
|
DWORD shader_version = reg_maps->shader_version;
|
2008-12-12 09:33:51 +01:00
|
|
|
DWORD *samplers = reg_maps->samplers;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (WINED3DSHADER_VERSION_MAJOR(shader_version) != 1) return;
|
|
|
|
|
|
|
|
for (i = 0; i < max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS); ++i)
|
|
|
|
{
|
|
|
|
/* We don't sample from this sampler */
|
|
|
|
if (!samplers[i]) continue;
|
|
|
|
|
|
|
|
if (!textures[i])
|
|
|
|
{
|
|
|
|
ERR("No texture bound to sampler %u, using 2D\n", i);
|
|
|
|
samplers[i] = (0x1 << 31) | WINED3DSTT_2D;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (IWineD3DBaseTexture_GetTextureDimensions(textures[i]))
|
|
|
|
{
|
|
|
|
case GL_TEXTURE_RECTANGLE_ARB:
|
|
|
|
case GL_TEXTURE_2D:
|
|
|
|
/* We have to select between texture rectangles and 2D textures later because 2.0 and
|
|
|
|
* 3.0 shaders only have WINED3DSTT_2D as well */
|
|
|
|
samplers[i] = (1 << 31) | WINED3DSTT_2D;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TEXTURE_3D:
|
|
|
|
samplers[i] = (1 << 31) | WINED3DSTT_VOLUME;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_ARB:
|
|
|
|
samplers[i] = (1 << 31) | WINED3DSTT_CUBE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unrecognized texture type %#x, using 2D\n",
|
|
|
|
IWineD3DBaseTexture_GetTextureDimensions(textures[i]));
|
|
|
|
samplers[i] = (0x1 << 31) | WINED3DSTT_2D;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-01 15:32:15 +01:00
|
|
|
static GLuint pixelshader_compile(IWineD3DPixelShaderImpl *This, const struct ps_compile_args *args)
|
|
|
|
{
|
2006-08-05 18:15:35 +02:00
|
|
|
CONST DWORD *function = This->baseShader.function;
|
2008-11-24 11:55:50 +01:00
|
|
|
GLuint retval;
|
2008-12-15 19:24:36 +01:00
|
|
|
SHADER_BUFFER buffer;
|
2008-12-14 15:40:07 +01:00
|
|
|
IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device;
|
2006-08-05 18:15:35 +02:00
|
|
|
|
2008-11-24 11:55:50 +01:00
|
|
|
TRACE("(%p) : function %p\n", This, function);
|
2007-09-21 23:47:40 +02:00
|
|
|
|
2008-12-12 09:33:51 +01:00
|
|
|
pixelshader_update_samplers(&This->baseShader.reg_maps,
|
2008-12-15 12:10:14 +01:00
|
|
|
((IWineD3DDeviceImpl *)This->baseShader.device)->stateBlock->textures);
|
2006-08-05 18:15:35 +02:00
|
|
|
|
|
|
|
/* Generate the HW shader */
|
|
|
|
TRACE("(%p) : Generating hardware program\n", This);
|
2009-02-16 14:58:52 +01:00
|
|
|
This->cur_args = args;
|
2008-12-15 19:24:36 +01:00
|
|
|
shader_buffer_init(&buffer);
|
2008-12-14 15:40:07 +01:00
|
|
|
retval = device->shader_backend->shader_generate_pshader((IWineD3DPixelShader *)This, &buffer, args);
|
2008-12-15 19:24:36 +01:00
|
|
|
shader_buffer_free(&buffer);
|
2009-02-16 14:58:52 +01:00
|
|
|
This->cur_args = NULL;
|
2006-08-05 18:15:35 +02:00
|
|
|
|
2008-11-24 11:55:50 +01:00
|
|
|
return retval;
|
2005-11-21 17:27:55 +01:00
|
|
|
}
|
2005-08-25 21:24:21 +02:00
|
|
|
|
|
|
|
const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl =
|
|
|
|
{
|
|
|
|
/*** IUnknown methods ***/
|
|
|
|
IWineD3DPixelShaderImpl_QueryInterface,
|
|
|
|
IWineD3DPixelShaderImpl_AddRef,
|
|
|
|
IWineD3DPixelShaderImpl_Release,
|
2006-03-28 21:10:51 +02:00
|
|
|
/*** IWineD3DBase methods ***/
|
2005-08-25 21:24:21 +02:00
|
|
|
IWineD3DPixelShaderImpl_GetParent,
|
2006-03-28 21:10:51 +02:00
|
|
|
/*** IWineD3DBaseShader methods ***/
|
|
|
|
IWineD3DPixelShaderImpl_SetFunction,
|
|
|
|
/*** IWineD3DPixelShader methods ***/
|
2005-08-25 21:24:21 +02:00
|
|
|
IWineD3DPixelShaderImpl_GetDevice,
|
2006-03-28 21:10:51 +02:00
|
|
|
IWineD3DPixelShaderImpl_GetFunction
|
2005-08-25 21:24:21 +02:00
|
|
|
};
|
2008-11-20 02:55:17 +01:00
|
|
|
|
|
|
|
void find_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWineD3DStateBlockImpl *stateblock, struct ps_compile_args *args) {
|
2009-02-16 14:58:52 +01:00
|
|
|
UINT i;
|
2008-11-20 02:55:17 +01:00
|
|
|
IWineD3DBaseTextureImpl *tex;
|
|
|
|
|
2008-12-15 19:35:40 +01:00
|
|
|
memset(args, 0, sizeof(*args)); /* FIXME: Make sure all bits are set */
|
2008-11-20 02:55:17 +01:00
|
|
|
args->srgb_correction = stateblock->renderState[WINED3DRS_SRGBWRITEENABLE] ? 1 : 0;
|
2009-04-09 19:14:03 +02:00
|
|
|
args->np2_fixup = 0;
|
2008-11-20 02:55:17 +01:00
|
|
|
|
2009-02-16 14:58:52 +01:00
|
|
|
for(i = 0; i < MAX_FRAGMENT_SAMPLERS; i++) {
|
|
|
|
if(shader->baseShader.reg_maps.samplers[i] == 0) continue;
|
|
|
|
tex = (IWineD3DBaseTextureImpl *) stateblock->textures[i];
|
2008-11-20 02:55:17 +01:00
|
|
|
if(!tex) {
|
2009-02-16 14:58:52 +01:00
|
|
|
args->color_fixup[i] = COLOR_FIXUP_IDENTITY;
|
2008-11-20 02:55:17 +01:00
|
|
|
continue;
|
|
|
|
}
|
2009-03-12 09:53:15 +01:00
|
|
|
args->color_fixup[i] = tex->resource.format_desc->color_fixup;
|
2009-03-26 03:15:21 +01:00
|
|
|
|
|
|
|
/* Flag samplers that need NP2 texcoord fixup. */
|
|
|
|
if(!tex->baseTexture.pow2Matrix_identity) {
|
2009-04-09 19:14:03 +02:00
|
|
|
args->np2_fixup |= (1 << i);
|
2009-03-26 03:15:21 +01:00
|
|
|
}
|
2008-11-20 02:55:17 +01:00
|
|
|
}
|
2008-12-15 12:10:14 +01:00
|
|
|
if (shader->baseShader.reg_maps.shader_version >= WINED3DPS_VERSION(3,0))
|
|
|
|
{
|
2009-01-08 10:19:16 +01:00
|
|
|
if (((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.position_transformed)
|
|
|
|
{
|
2008-11-20 02:55:17 +01:00
|
|
|
args->vp_mode = pretransformed;
|
2008-12-30 14:56:49 +01:00
|
|
|
}
|
|
|
|
else if (use_vs(stateblock))
|
|
|
|
{
|
2008-11-20 02:55:17 +01:00
|
|
|
args->vp_mode = vertexshader;
|
|
|
|
} else {
|
|
|
|
args->vp_mode = fixedfunction;
|
|
|
|
}
|
2008-12-15 19:35:40 +01:00
|
|
|
args->fog = FOG_OFF;
|
2008-11-20 02:55:17 +01:00
|
|
|
} else {
|
|
|
|
args->vp_mode = vertexshader;
|
2008-12-15 19:35:40 +01:00
|
|
|
if(stateblock->renderState[WINED3DRS_FOGENABLE]) {
|
|
|
|
switch(stateblock->renderState[WINED3DRS_FOGTABLEMODE]) {
|
|
|
|
case WINED3DFOG_NONE:
|
2009-01-08 10:19:16 +01:00
|
|
|
if (((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.position_transformed
|
2008-12-30 14:56:49 +01:00
|
|
|
|| use_vs(stateblock))
|
|
|
|
{
|
2008-12-15 19:35:40 +01:00
|
|
|
args->fog = FOG_LINEAR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch(stateblock->renderState[WINED3DRS_FOGVERTEXMODE]) {
|
|
|
|
case WINED3DFOG_NONE: /* Drop through */
|
|
|
|
case WINED3DFOG_LINEAR: args->fog = FOG_LINEAR; break;
|
|
|
|
case WINED3DFOG_EXP: args->fog = FOG_EXP; break;
|
|
|
|
case WINED3DFOG_EXP2: args->fog = FOG_EXP2; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DFOG_LINEAR: args->fog = FOG_LINEAR; break;
|
|
|
|
case WINED3DFOG_EXP: args->fog = FOG_EXP; break;
|
|
|
|
case WINED3DFOG_EXP2: args->fog = FOG_EXP2; break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
args->fog = FOG_OFF;
|
|
|
|
}
|
2008-11-20 02:55:17 +01:00
|
|
|
}
|
|
|
|
}
|
2008-11-24 11:55:50 +01:00
|
|
|
|
2008-12-01 15:32:15 +01:00
|
|
|
GLuint find_gl_pshader(IWineD3DPixelShaderImpl *shader, const struct ps_compile_args *args)
|
|
|
|
{
|
2008-11-24 11:55:50 +01:00
|
|
|
UINT i;
|
2009-01-19 18:39:36 +01:00
|
|
|
DWORD new_size;
|
|
|
|
struct ps_compiled_shader *new_array;
|
2008-11-24 11:55:50 +01:00
|
|
|
|
|
|
|
/* Usually we have very few GL shaders for each d3d shader(just 1 or maybe 2),
|
2009-01-19 18:39:36 +01:00
|
|
|
* so a linear search is more performant than a hashmap or a binary search
|
|
|
|
* (cache coherency etc)
|
2008-11-24 11:55:50 +01:00
|
|
|
*/
|
|
|
|
for(i = 0; i < shader->num_gl_shaders; i++) {
|
|
|
|
if(memcmp(&shader->gl_shaders[i].args, args, sizeof(*args)) == 0) {
|
|
|
|
return shader->gl_shaders[i].prgId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("No matching GL shader found, compiling a new shader\n");
|
2009-01-19 18:39:36 +01:00
|
|
|
if(shader->shader_array_size == shader->num_gl_shaders) {
|
2009-03-24 10:09:21 +01:00
|
|
|
if (shader->num_gl_shaders)
|
|
|
|
{
|
2009-01-19 18:39:36 +01:00
|
|
|
new_size = shader->shader_array_size + max(1, shader->shader_array_size / 2);
|
|
|
|
new_array = HeapReAlloc(GetProcessHeap(), 0, shader->gl_shaders,
|
|
|
|
new_size * sizeof(*shader->gl_shaders));
|
|
|
|
} else {
|
|
|
|
new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*shader->gl_shaders));
|
|
|
|
new_size = 1;
|
|
|
|
}
|
2008-11-24 11:55:50 +01:00
|
|
|
|
2009-01-19 18:39:36 +01:00
|
|
|
if(!new_array) {
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
shader->gl_shaders = new_array;
|
|
|
|
shader->shader_array_size = new_size;
|
2008-11-24 11:55:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
shader->gl_shaders[shader->num_gl_shaders].args = *args;
|
|
|
|
shader->gl_shaders[shader->num_gl_shaders].prgId = pixelshader_compile(shader, args);
|
|
|
|
return shader->gl_shaders[shader->num_gl_shaders++].prgId;
|
|
|
|
}
|