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-05-06 10:05:45 +02:00
|
|
|
static void pshader_set_limits(IWineD3DPixelShaderImpl *This)
|
|
|
|
{
|
2009-05-06 17:59:21 +02:00
|
|
|
DWORD shader_version = WINED3D_SHADER_VERSION(This->baseShader.reg_maps.shader_version.major,
|
|
|
|
This->baseShader.reg_maps.shader_version.minor);
|
|
|
|
|
2009-05-06 10:05:45 +02:00
|
|
|
This->baseShader.limits.attributes = 0;
|
|
|
|
This->baseShader.limits.address = 0;
|
|
|
|
This->baseShader.limits.packed_output = 0;
|
|
|
|
|
2009-05-06 17:59:21 +02:00
|
|
|
switch (shader_version)
|
2009-05-06 10:05:45 +02:00
|
|
|
{
|
2009-05-06 17:59:21 +02:00
|
|
|
case WINED3D_SHADER_VERSION(1,0):
|
|
|
|
case WINED3D_SHADER_VERSION(1,1):
|
|
|
|
case WINED3D_SHADER_VERSION(1,2):
|
|
|
|
case WINED3D_SHADER_VERSION(1,3):
|
2009-05-06 10:05:45 +02:00
|
|
|
This->baseShader.limits.temporary = 2;
|
|
|
|
This->baseShader.limits.constant_float = 8;
|
|
|
|
This->baseShader.limits.constant_int = 0;
|
|
|
|
This->baseShader.limits.constant_bool = 0;
|
|
|
|
This->baseShader.limits.texcoord = 4;
|
|
|
|
This->baseShader.limits.sampler = 4;
|
|
|
|
This->baseShader.limits.packed_input = 0;
|
|
|
|
This->baseShader.limits.label = 0;
|
|
|
|
break;
|
|
|
|
|
2009-05-06 17:59:21 +02:00
|
|
|
case WINED3D_SHADER_VERSION(1,4):
|
2009-05-06 10:05:45 +02:00
|
|
|
This->baseShader.limits.temporary = 6;
|
|
|
|
This->baseShader.limits.constant_float = 8;
|
|
|
|
This->baseShader.limits.constant_int = 0;
|
|
|
|
This->baseShader.limits.constant_bool = 0;
|
|
|
|
This->baseShader.limits.texcoord = 6;
|
|
|
|
This->baseShader.limits.sampler = 6;
|
|
|
|
This->baseShader.limits.packed_input = 0;
|
|
|
|
This->baseShader.limits.label = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* FIXME: temporaries must match D3DPSHADERCAPS2_0.NumTemps */
|
2009-05-06 17:59:21 +02:00
|
|
|
case WINED3D_SHADER_VERSION(2,0):
|
2009-05-06 10:05:45 +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;
|
|
|
|
|
2009-05-06 17:59:21 +02:00
|
|
|
case WINED3D_SHADER_VERSION(2,1):
|
2009-05-06 10:05:45 +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;
|
|
|
|
This->baseShader.limits.label = 16;
|
|
|
|
break;
|
|
|
|
|
2009-05-26 09:15:12 +02:00
|
|
|
case WINED3D_SHADER_VERSION(4,0):
|
|
|
|
FIXME("Using 3.0 limits for 4.0 shader\n");
|
|
|
|
/* Fall through */
|
|
|
|
|
2009-05-06 17:59:21 +02:00
|
|
|
case WINED3D_SHADER_VERSION(3,0):
|
2009-05-06 10:05:45 +02:00
|
|
|
This->baseShader.limits.temporary = 32;
|
|
|
|
This->baseShader.limits.constant_float = 224;
|
|
|
|
This->baseShader.limits.constant_int = 16;
|
|
|
|
This->baseShader.limits.constant_bool = 16;
|
|
|
|
This->baseShader.limits.texcoord = 0;
|
|
|
|
This->baseShader.limits.sampler = 16;
|
|
|
|
This->baseShader.limits.packed_input = 12;
|
|
|
|
This->baseShader.limits.label = 16; /* FIXME: 2048 */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
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;
|
|
|
|
This->baseShader.limits.label = 0;
|
2009-05-06 17:59:21 +02:00
|
|
|
FIXME("Unrecognized pixel shader version %u.%u\n",
|
|
|
|
This->baseShader.reg_maps.shader_version.major,
|
|
|
|
This->baseShader.reg_maps.shader_version.minor);
|
2009-05-06 10:05:45 +02:00
|
|
|
}
|
2006-05-08 23:09:21 +02:00
|
|
|
}
|
|
|
|
|
2009-05-08 17:44:25 +02:00
|
|
|
static HRESULT WINAPI IWineD3DPixelShaderImpl_SetFunction(IWineD3DPixelShader *iface,
|
|
|
|
const DWORD *pFunction, const struct wined3d_shader_signature *output_signature)
|
|
|
|
{
|
2006-06-12 08:54:30 +02:00
|
|
|
IWineD3DPixelShaderImpl *This =(IWineD3DPixelShaderImpl *)iface;
|
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;
|
2009-05-04 09:49:27 +02:00
|
|
|
const struct wined3d_shader_frontend *fe;
|
2008-12-11 11:52:37 +01:00
|
|
|
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);
|
|
|
|
|
2009-05-04 09:49:27 +02:00
|
|
|
fe = shader_select_frontend(*pFunction);
|
|
|
|
if (!fe)
|
|
|
|
{
|
|
|
|
FIXME("Unable to find frontend for shader.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2009-05-05 09:38:03 +02:00
|
|
|
This->baseShader.frontend = fe;
|
2009-05-08 17:44:25 +02:00
|
|
|
This->baseShader.frontend_data = fe->shader_init(pFunction, output_signature);
|
2009-05-05 09:38:03 +02:00
|
|
|
if (!This->baseShader.frontend_data)
|
|
|
|
{
|
|
|
|
FIXME("Failed to initialize frontend.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2009-05-04 09:49:27 +02:00
|
|
|
|
2006-07-04 10:01:46 +02:00
|
|
|
/* First pass: trace shader */
|
2009-05-05 09:38:03 +02:00
|
|
|
if (TRACE_ON(d3d_shader)) shader_trace_init(fe, This->baseShader.frontend_data, pFunction);
|
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.. */
|
2009-05-27 10:24:50 +02:00
|
|
|
hr = shader_get_registers_used((IWineD3DBaseShader *)This, fe,
|
2009-05-27 10:24:50 +02:00
|
|
|
reg_maps, NULL, This->input_signature, NULL,
|
2009-05-27 10:24:50 +02:00
|
|
|
pFunction, GL_LIMITS(pshader_constantsF));
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-05-26 13:43:43 +02:00
|
|
|
void pixelshader_update_samplers(struct shader_reg_maps *reg_maps, IWineD3DBaseTexture * const *textures)
|
2008-12-12 09:33:51 +01:00
|
|
|
{
|
2009-04-29 09:55:06 +02:00
|
|
|
WINED3DSAMPLER_TEXTURE_TYPE *sampler_type = reg_maps->sampler_type;
|
2008-12-12 09:33:51 +01:00
|
|
|
unsigned int i;
|
|
|
|
|
2009-05-06 17:59:21 +02:00
|
|
|
if (reg_maps->shader_version.major != 1) return;
|
2008-12-12 09:33:51 +01:00
|
|
|
|
|
|
|
for (i = 0; i < max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS); ++i)
|
|
|
|
{
|
|
|
|
/* We don't sample from this sampler */
|
2009-04-29 09:55:06 +02:00
|
|
|
if (!sampler_type[i]) continue;
|
2008-12-12 09:33:51 +01:00
|
|
|
|
|
|
|
if (!textures[i])
|
|
|
|
{
|
|
|
|
ERR("No texture bound to sampler %u, using 2D\n", i);
|
2009-04-29 09:55:06 +02:00
|
|
|
sampler_type[i] = WINED3DSTT_2D;
|
2008-12-12 09:33:51 +01:00
|
|
|
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 */
|
2009-04-29 09:55:06 +02:00
|
|
|
sampler_type[i] = WINED3DSTT_2D;
|
2008-12-12 09:33:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TEXTURE_3D:
|
2009-04-29 09:55:06 +02:00
|
|
|
sampler_type[i] = WINED3DSTT_VOLUME;
|
2008-12-12 09:33:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_ARB:
|
2009-04-29 09:55:06 +02:00
|
|
|
sampler_type[i] = WINED3DSTT_CUBE;
|
2008-12-12 09:33:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unrecognized texture type %#x, using 2D\n",
|
|
|
|
IWineD3DBaseTexture_GetTextureDimensions(textures[i]));
|
2009-04-29 09:55:06 +02:00
|
|
|
sampler_type[i] = WINED3DSTT_2D;
|
2008-12-12 09:33:51 +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++) {
|
2009-04-29 09:55:06 +02:00
|
|
|
if (!shader->baseShader.reg_maps.sampler_type[i]) continue;
|
2009-02-16 14:58:52 +01:00
|
|
|
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
|
|
|
}
|
2009-05-06 17:59:21 +02:00
|
|
|
if (shader->baseShader.reg_maps.shader_version.major >= 3)
|
2008-12-15 12:10:14 +01:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|