2005-08-25 19:24:21 +00:00
|
|
|
/*
|
|
|
|
* shaders implementation
|
|
|
|
*
|
2006-05-08 19:44:25 +00:00
|
|
|
* Copyright 2002-2003 Jason Edmeades
|
|
|
|
* Copyright 2002-2003 Raphael Junqueira
|
2006-07-17 18:35:14 +00:00
|
|
|
* Copyright 2004 Christian Costa
|
2006-05-08 19:44:25 +00:00
|
|
|
* Copyright 2005 Oliver Stieber
|
2006-05-17 06:04:30 +00:00
|
|
|
* Copyright 2006 Ivan Gyurdiev
|
2008-10-18 17:21:20 +00:00
|
|
|
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
2005-08-25 19:24:21 +00: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 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-08-25 19:24:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
2005-11-21 16:27:55 +00:00
|
|
|
#include <stdio.h>
|
2005-08-25 19:24:21 +00:00
|
|
|
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
|
|
|
|
|
2007-06-09 12:27:41 +00:00
|
|
|
#define GLINFO_LOCATION ((IWineD3DDeviceImpl *) This->baseShader.device)->adapter->gl_info
|
2005-08-25 19:24:21 +00:00
|
|
|
|
2007-11-16 20:01:33 +00:00
|
|
|
static HRESULT WINAPI IWineD3DPixelShaderImpl_QueryInterface(IWineD3DPixelShader *iface, REFIID riid, LPVOID *ppobj) {
|
2008-12-09 08:52:39 +00: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 19:24:21 +00:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
static ULONG WINAPI IWineD3DPixelShaderImpl_AddRef(IWineD3DPixelShader *iface) {
|
2008-12-09 08:52:39 +00: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 19:24:21 +00:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
static ULONG WINAPI IWineD3DPixelShaderImpl_Release(IWineD3DPixelShader *iface) {
|
2008-12-09 08:52:39 +00: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 19:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* *******************************************
|
|
|
|
IWineD3DPixelShader IWineD3DPixelShader parts follow
|
|
|
|
******************************************* */
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
static HRESULT WINAPI IWineD3DPixelShaderImpl_GetParent(IWineD3DPixelShader *iface, IUnknown** parent){
|
2005-08-25 19:24:21 +00:00
|
|
|
IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
|
|
|
|
|
2005-12-03 17:10:56 +00:00
|
|
|
*parent = This->parent;
|
2005-08-25 19:24:21 +00:00
|
|
|
IUnknown_AddRef(*parent);
|
|
|
|
TRACE("(%p) : returning %p\n", This, *parent);
|
2006-04-07 10:51:12 +00:00
|
|
|
return WINED3D_OK;
|
2005-08-25 19:24:21 +00:00
|
|
|
}
|
2005-11-21 16:27:55 +00:00
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
static HRESULT WINAPI IWineD3DPixelShaderImpl_GetDevice(IWineD3DPixelShader* iface, IWineD3DDevice **pDevice){
|
2005-08-25 19:24:21 +00:00
|
|
|
IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
|
2006-09-27 11:14:46 +00:00
|
|
|
IWineD3DDevice_AddRef(This->baseShader.device);
|
|
|
|
*pDevice = This->baseShader.device;
|
2005-08-25 19:24:21 +00:00
|
|
|
TRACE("(%p) returning %p\n", This, *pDevice);
|
2006-04-07 10:51:12 +00:00
|
|
|
return WINED3D_OK;
|
2005-08-25 19:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
static HRESULT WINAPI IWineD3DPixelShaderImpl_GetFunction(IWineD3DPixelShader* impl, VOID* pData, UINT* pSizeOfData) {
|
2005-08-25 19:24:21 +00:00
|
|
|
IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)impl;
|
2006-06-09 21:46:38 +00:00
|
|
|
TRACE("(%p) : pData(%p), pSizeOfData(%p)\n", This, pData, pSizeOfData);
|
2005-08-25 19:24:21 +00:00
|
|
|
|
|
|
|
if (NULL == pData) {
|
2006-03-30 17:14:31 +00:00
|
|
|
*pSizeOfData = This->baseShader.functionLength;
|
2006-04-07 10:51:12 +00:00
|
|
|
return WINED3D_OK;
|
2005-08-25 19:24:21 +00:00
|
|
|
}
|
2006-03-30 17:14:31 +00:00
|
|
|
if (*pSizeOfData < This->baseShader.functionLength) {
|
2007-03-08 00:16:09 +00: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 19:24:21 +00:00
|
|
|
}
|
2008-12-15 15:35:14 +00:00
|
|
|
|
|
|
|
TRACE("(%p) : GetFunction copying to %p\n", This, pData);
|
|
|
|
memcpy(pData, This->baseShader.function, This->baseShader.functionLength);
|
|
|
|
|
2006-04-07 10:51:12 +00:00
|
|
|
return WINED3D_OK;
|
2005-08-25 19:24:21 +00:00
|
|
|
}
|
|
|
|
|
2009-05-06 08:05:45 +00:00
|
|
|
static void pshader_set_limits(IWineD3DPixelShaderImpl *This)
|
|
|
|
{
|
2009-05-06 15:59:21 +00:00
|
|
|
DWORD shader_version = WINED3D_SHADER_VERSION(This->baseShader.reg_maps.shader_version.major,
|
|
|
|
This->baseShader.reg_maps.shader_version.minor);
|
|
|
|
|
2009-05-06 08:05:45 +00:00
|
|
|
This->baseShader.limits.attributes = 0;
|
|
|
|
This->baseShader.limits.address = 0;
|
|
|
|
This->baseShader.limits.packed_output = 0;
|
|
|
|
|
2009-05-06 15:59:21 +00:00
|
|
|
switch (shader_version)
|
2009-05-06 08:05:45 +00:00
|
|
|
{
|
2009-05-06 15:59:21 +00: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 08:05:45 +00: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 15:59:21 +00:00
|
|
|
case WINED3D_SHADER_VERSION(1,4):
|
2009-05-06 08:05:45 +00: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 15:59:21 +00:00
|
|
|
case WINED3D_SHADER_VERSION(2,0):
|
2009-05-06 08:05:45 +00: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 15:59:21 +00:00
|
|
|
case WINED3D_SHADER_VERSION(2,1):
|
2009-05-06 08:05:45 +00: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 07:15:12 +00:00
|
|
|
case WINED3D_SHADER_VERSION(4,0):
|
|
|
|
FIXME("Using 3.0 limits for 4.0 shader\n");
|
|
|
|
/* Fall through */
|
|
|
|
|
2009-05-06 15:59:21 +00:00
|
|
|
case WINED3D_SHADER_VERSION(3,0):
|
2009-05-06 08:05:45 +00: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 15:59:21 +00: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 08:05:45 +00:00
|
|
|
}
|
2006-05-08 21:09:21 +00:00
|
|
|
}
|
|
|
|
|
2009-05-08 15:44:25 +00:00
|
|
|
static HRESULT WINAPI IWineD3DPixelShaderImpl_SetFunction(IWineD3DPixelShader *iface,
|
|
|
|
const DWORD *pFunction, const struct wined3d_shader_signature *output_signature)
|
|
|
|
{
|
2006-06-12 06:54:30 +00:00
|
|
|
IWineD3DPixelShaderImpl *This =(IWineD3DPixelShaderImpl *)iface;
|
2008-12-11 10:52:37 +00:00
|
|
|
unsigned int i, highest_reg_used = 0, num_regs_used = 0;
|
|
|
|
shader_reg_maps *reg_maps = &This->baseShader.reg_maps;
|
2009-05-04 07:49:27 +00:00
|
|
|
const struct wined3d_shader_frontend *fe;
|
2008-12-11 10:52:37 +00:00
|
|
|
HRESULT hr;
|
2006-06-12 06:54:30 +00:00
|
|
|
|
2006-07-24 22:51:03 +00:00
|
|
|
TRACE("(%p) : pFunction %p\n", iface, pFunction);
|
|
|
|
|
2009-05-04 07:49:27 +00:00
|
|
|
fe = shader_select_frontend(*pFunction);
|
|
|
|
if (!fe)
|
|
|
|
{
|
|
|
|
FIXME("Unable to find frontend for shader.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2009-05-05 07:38:03 +00:00
|
|
|
This->baseShader.frontend = fe;
|
2009-05-08 15:44:25 +00:00
|
|
|
This->baseShader.frontend_data = fe->shader_init(pFunction, output_signature);
|
2009-05-05 07:38:03 +00:00
|
|
|
if (!This->baseShader.frontend_data)
|
|
|
|
{
|
|
|
|
FIXME("Failed to initialize frontend.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2009-05-04 07:49:27 +00:00
|
|
|
|
2006-07-04 08:01:46 +00:00
|
|
|
/* First pass: trace shader */
|
2009-05-05 07:38:03 +00:00
|
|
|
if (TRACE_ON(d3d_shader)) shader_trace_init(fe, This->baseShader.frontend_data, pFunction);
|
2005-11-21 16:27:55 +00:00
|
|
|
|
2006-07-10 04:51:03 +00:00
|
|
|
/* Initialize immediate constant lists */
|
|
|
|
list_init(&This->baseShader.constantsF);
|
|
|
|
list_init(&This->baseShader.constantsB);
|
|
|
|
list_init(&This->baseShader.constantsI);
|
|
|
|
|
2008-12-11 10:52:37 +00:00
|
|
|
/* Second pass: figure out which registers are used, what the semantics are, etc.. */
|
2009-05-27 08:24:50 +00:00
|
|
|
hr = shader_get_registers_used((IWineD3DBaseShader *)This, fe,
|
2009-05-27 08:24:50 +00:00
|
|
|
reg_maps, NULL, This->input_signature, NULL,
|
2009-05-27 08:24:50 +00:00
|
|
|
pFunction, GL_LIMITS(pshader_constantsF));
|
2008-12-11 10:52:37 +00: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 11:34:22 +00:00
|
|
|
}
|
|
|
|
|
2008-12-11 10:52:37 +00:00
|
|
|
for (i = 0; i < MAX_REG_INPUT; ++i)
|
|
|
|
{
|
|
|
|
This->input_reg_map[i] = i;
|
2007-10-27 22:12:37 +00:00
|
|
|
}
|
2008-12-11 10:52:37 +00:00
|
|
|
|
|
|
|
This->declared_in_count = highest_reg_used + 1;
|
2007-06-07 21:52:48 +00:00
|
|
|
}
|
2008-12-11 10:52:37 +00: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 09:12:27 +00:00
|
|
|
else This->input_reg_map[i] = ~0U;
|
2008-12-11 10:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-09 13:48:47 +00:00
|
|
|
This->baseShader.load_local_constsF = FALSE;
|
2007-06-07 21:52:48 +00:00
|
|
|
|
2005-11-21 16:27:55 +00:00
|
|
|
TRACE("(%p) : Copying the function\n", This);
|
2008-12-15 15:35:14 +00: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 16:27:55 +00:00
|
|
|
|
2006-08-05 16:15:35 +00:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2008-12-15 11:10:14 +00:00
|
|
|
static void pixelshader_update_samplers(struct shader_reg_maps *reg_maps, IWineD3DBaseTexture * const *textures)
|
2008-12-12 08:33:51 +00:00
|
|
|
{
|
2009-04-29 07:55:06 +00:00
|
|
|
WINED3DSAMPLER_TEXTURE_TYPE *sampler_type = reg_maps->sampler_type;
|
2008-12-12 08:33:51 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
2009-05-06 15:59:21 +00:00
|
|
|
if (reg_maps->shader_version.major != 1) return;
|
2008-12-12 08:33:51 +00:00
|
|
|
|
|
|
|
for (i = 0; i < max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS); ++i)
|
|
|
|
{
|
|
|
|
/* We don't sample from this sampler */
|
2009-04-29 07:55:06 +00:00
|
|
|
if (!sampler_type[i]) continue;
|
2008-12-12 08:33:51 +00:00
|
|
|
|
|
|
|
if (!textures[i])
|
|
|
|
{
|
|
|
|
ERR("No texture bound to sampler %u, using 2D\n", i);
|
2009-04-29 07:55:06 +00:00
|
|
|
sampler_type[i] = WINED3DSTT_2D;
|
2008-12-12 08:33:51 +00: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 07:55:06 +00:00
|
|
|
sampler_type[i] = WINED3DSTT_2D;
|
2008-12-12 08:33:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TEXTURE_3D:
|
2009-04-29 07:55:06 +00:00
|
|
|
sampler_type[i] = WINED3DSTT_VOLUME;
|
2008-12-12 08:33:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_ARB:
|
2009-04-29 07:55:06 +00:00
|
|
|
sampler_type[i] = WINED3DSTT_CUBE;
|
2008-12-12 08:33:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unrecognized texture type %#x, using 2D\n",
|
|
|
|
IWineD3DBaseTexture_GetTextureDimensions(textures[i]));
|
2009-04-29 07:55:06 +00:00
|
|
|
sampler_type[i] = WINED3DSTT_2D;
|
2008-12-12 08:33:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-14 17:40:56 +00:00
|
|
|
/* GL locking is done by the caller */
|
2008-12-01 14:32:15 +00:00
|
|
|
static GLuint pixelshader_compile(IWineD3DPixelShaderImpl *This, const struct ps_compile_args *args)
|
|
|
|
{
|
2006-08-05 16:15:35 +00:00
|
|
|
CONST DWORD *function = This->baseShader.function;
|
2008-11-24 10:55:50 +00:00
|
|
|
GLuint retval;
|
2008-12-15 18:24:36 +00:00
|
|
|
SHADER_BUFFER buffer;
|
2008-12-14 14:40:07 +00:00
|
|
|
IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device;
|
2006-08-05 16:15:35 +00:00
|
|
|
|
2008-11-24 10:55:50 +00:00
|
|
|
TRACE("(%p) : function %p\n", This, function);
|
2007-09-21 21:47:40 +00:00
|
|
|
|
2008-12-12 08:33:51 +00:00
|
|
|
pixelshader_update_samplers(&This->baseShader.reg_maps,
|
2008-12-15 11:10:14 +00:00
|
|
|
((IWineD3DDeviceImpl *)This->baseShader.device)->stateBlock->textures);
|
2006-08-05 16:15:35 +00:00
|
|
|
|
|
|
|
/* Generate the HW shader */
|
|
|
|
TRACE("(%p) : Generating hardware program\n", This);
|
2008-12-15 18:24:36 +00:00
|
|
|
shader_buffer_init(&buffer);
|
2009-05-05 07:38:03 +00:00
|
|
|
retval = device->shader_backend->shader_generate_pshader((IWineD3DPixelShader *)This, &buffer, args);
|
2008-12-15 18:24:36 +00:00
|
|
|
shader_buffer_free(&buffer);
|
2006-08-05 16:15:35 +00:00
|
|
|
|
2008-11-24 10:55:50 +00:00
|
|
|
return retval;
|
2005-11-21 16:27:55 +00:00
|
|
|
}
|
2005-08-25 19:24:21 +00:00
|
|
|
|
|
|
|
const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl =
|
|
|
|
{
|
|
|
|
/*** IUnknown methods ***/
|
|
|
|
IWineD3DPixelShaderImpl_QueryInterface,
|
|
|
|
IWineD3DPixelShaderImpl_AddRef,
|
|
|
|
IWineD3DPixelShaderImpl_Release,
|
2006-03-28 19:10:51 +00:00
|
|
|
/*** IWineD3DBase methods ***/
|
2005-08-25 19:24:21 +00:00
|
|
|
IWineD3DPixelShaderImpl_GetParent,
|
2006-03-28 19:10:51 +00:00
|
|
|
/*** IWineD3DBaseShader methods ***/
|
|
|
|
IWineD3DPixelShaderImpl_SetFunction,
|
|
|
|
/*** IWineD3DPixelShader methods ***/
|
2005-08-25 19:24:21 +00:00
|
|
|
IWineD3DPixelShaderImpl_GetDevice,
|
2006-03-28 19:10:51 +00:00
|
|
|
IWineD3DPixelShaderImpl_GetFunction
|
2005-08-25 19:24:21 +00:00
|
|
|
};
|
2008-11-20 01:55:17 +00:00
|
|
|
|
|
|
|
void find_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWineD3DStateBlockImpl *stateblock, struct ps_compile_args *args) {
|
2009-02-16 13:58:52 +00:00
|
|
|
UINT i;
|
2008-11-20 01:55:17 +00:00
|
|
|
IWineD3DBaseTextureImpl *tex;
|
|
|
|
|
2008-12-15 18:35:40 +00:00
|
|
|
memset(args, 0, sizeof(*args)); /* FIXME: Make sure all bits are set */
|
2008-11-20 01:55:17 +00:00
|
|
|
args->srgb_correction = stateblock->renderState[WINED3DRS_SRGBWRITEENABLE] ? 1 : 0;
|
2009-04-09 17:14:03 +00:00
|
|
|
args->np2_fixup = 0;
|
2008-11-20 01:55:17 +00:00
|
|
|
|
2009-02-16 13:58:52 +00:00
|
|
|
for(i = 0; i < MAX_FRAGMENT_SAMPLERS; i++) {
|
2009-04-29 07:55:06 +00:00
|
|
|
if (!shader->baseShader.reg_maps.sampler_type[i]) continue;
|
2009-02-16 13:58:52 +00:00
|
|
|
tex = (IWineD3DBaseTextureImpl *) stateblock->textures[i];
|
2008-11-20 01:55:17 +00:00
|
|
|
if(!tex) {
|
2009-02-16 13:58:52 +00:00
|
|
|
args->color_fixup[i] = COLOR_FIXUP_IDENTITY;
|
2008-11-20 01:55:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-03-12 08:53:15 +00:00
|
|
|
args->color_fixup[i] = tex->resource.format_desc->color_fixup;
|
2009-03-26 02:15:21 +00:00
|
|
|
|
|
|
|
/* Flag samplers that need NP2 texcoord fixup. */
|
|
|
|
if(!tex->baseTexture.pow2Matrix_identity) {
|
2009-04-09 17:14:03 +00:00
|
|
|
args->np2_fixup |= (1 << i);
|
2009-03-26 02:15:21 +00:00
|
|
|
}
|
2008-11-20 01:55:17 +00:00
|
|
|
}
|
2009-05-06 15:59:21 +00:00
|
|
|
if (shader->baseShader.reg_maps.shader_version.major >= 3)
|
2008-12-15 11:10:14 +00:00
|
|
|
{
|
2009-01-08 09:19:16 +00:00
|
|
|
if (((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.position_transformed)
|
|
|
|
{
|
2008-11-20 01:55:17 +00:00
|
|
|
args->vp_mode = pretransformed;
|
2008-12-30 13:56:49 +00:00
|
|
|
}
|
|
|
|
else if (use_vs(stateblock))
|
|
|
|
{
|
2008-11-20 01:55:17 +00:00
|
|
|
args->vp_mode = vertexshader;
|
|
|
|
} else {
|
|
|
|
args->vp_mode = fixedfunction;
|
|
|
|
}
|
2008-12-15 18:35:40 +00:00
|
|
|
args->fog = FOG_OFF;
|
2008-11-20 01:55:17 +00:00
|
|
|
} else {
|
|
|
|
args->vp_mode = vertexshader;
|
2008-12-15 18:35:40 +00:00
|
|
|
if(stateblock->renderState[WINED3DRS_FOGENABLE]) {
|
|
|
|
switch(stateblock->renderState[WINED3DRS_FOGTABLEMODE]) {
|
|
|
|
case WINED3DFOG_NONE:
|
2009-01-08 09:19:16 +00:00
|
|
|
if (((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.position_transformed
|
2008-12-30 13:56:49 +00:00
|
|
|
|| use_vs(stateblock))
|
|
|
|
{
|
2008-12-15 18:35:40 +00: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 01:55:17 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-24 10:55:50 +00:00
|
|
|
|
2009-05-14 17:40:56 +00:00
|
|
|
/* GL locking is done by the caller */
|
2008-12-01 14:32:15 +00:00
|
|
|
GLuint find_gl_pshader(IWineD3DPixelShaderImpl *shader, const struct ps_compile_args *args)
|
|
|
|
{
|
2008-11-24 10:55:50 +00:00
|
|
|
UINT i;
|
2009-01-19 17:39:36 +00:00
|
|
|
DWORD new_size;
|
|
|
|
struct ps_compiled_shader *new_array;
|
2008-11-24 10:55:50 +00:00
|
|
|
|
|
|
|
/* Usually we have very few GL shaders for each d3d shader(just 1 or maybe 2),
|
2009-01-19 17:39:36 +00:00
|
|
|
* so a linear search is more performant than a hashmap or a binary search
|
|
|
|
* (cache coherency etc)
|
2008-11-24 10:55:50 +00: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 17:39:36 +00:00
|
|
|
if(shader->shader_array_size == shader->num_gl_shaders) {
|
2009-03-24 09:09:21 +00:00
|
|
|
if (shader->num_gl_shaders)
|
|
|
|
{
|
2009-01-19 17:39:36 +00: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 10:55:50 +00:00
|
|
|
|
2009-01-19 17:39:36 +00: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 10:55:50 +00: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;
|
|
|
|
}
|