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
|
2009-09-25 13:31:43 +02:00
|
|
|
* Copyright 2009 Henri Verbeet 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);
|
2009-09-25 13:31:44 +02:00
|
|
|
This->baseShader.parent_ops->wined3d_object_destroyed(This->baseShader.parent);
|
2008-12-09 09:52:39 +01:00
|
|
|
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;
|
|
|
|
|
2009-09-25 13:31:44 +02:00
|
|
|
*parent = This->baseShader.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-09-25 13:31:43 +02:00
|
|
|
static HRESULT pixelshader_set_function(IWineD3DPixelShaderImpl *shader,
|
|
|
|
const DWORD *byte_code, const struct wined3d_shader_signature *output_signature)
|
2009-05-08 17:44:25 +02:00
|
|
|
{
|
2009-09-25 13:31:43 +02:00
|
|
|
IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)shader->baseShader.device;
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2008-12-11 11:52:37 +01:00
|
|
|
unsigned int i, highest_reg_used = 0, num_regs_used = 0;
|
2009-09-25 13:31:43 +02:00
|
|
|
shader_reg_maps *reg_maps = &shader->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
|
|
|
|
2009-09-25 13:31:43 +02:00
|
|
|
TRACE("shader %p, byte_code %p, output_signature %p.\n", shader, byte_code, output_signature);
|
2006-07-25 00:51:03 +02:00
|
|
|
|
2009-09-25 13:31:43 +02:00
|
|
|
fe = shader_select_frontend(*byte_code);
|
2009-05-04 09:49:27 +02:00
|
|
|
if (!fe)
|
|
|
|
{
|
|
|
|
FIXME("Unable to find frontend for shader.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2009-09-25 13:31:43 +02:00
|
|
|
shader->baseShader.frontend = fe;
|
|
|
|
shader->baseShader.frontend_data = fe->shader_init(byte_code, output_signature);
|
|
|
|
if (!shader->baseShader.frontend_data)
|
2009-05-05 09:38:03 +02:00
|
|
|
{
|
|
|
|
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-09-25 13:31:43 +02:00
|
|
|
if (TRACE_ON(d3d_shader)) shader_trace_init(fe, shader->baseShader.frontend_data, byte_code);
|
2005-11-21 17:27:55 +01:00
|
|
|
|
2006-07-10 06:51:03 +02:00
|
|
|
/* Initialize immediate constant lists */
|
2009-09-25 13:31:43 +02:00
|
|
|
list_init(&shader->baseShader.constantsF);
|
|
|
|
list_init(&shader->baseShader.constantsB);
|
|
|
|
list_init(&shader->baseShader.constantsI);
|
2006-07-10 06:51:03 +02:00
|
|
|
|
2008-12-11 11:52:37 +01:00
|
|
|
/* Second pass: figure out which registers are used, what the semantics are, etc.. */
|
2009-09-25 13:31:43 +02:00
|
|
|
hr = shader_get_registers_used((IWineD3DBaseShader *)shader, fe,
|
|
|
|
reg_maps, NULL, shader->input_signature, NULL,
|
|
|
|
byte_code, gl_info->max_pshader_constantsF);
|
2008-12-11 11:52:37 +01:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2009-09-25 13:31:43 +02:00
|
|
|
pshader_set_limits(shader);
|
2008-12-11 11:52:37 +01:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_REG_INPUT; ++i)
|
|
|
|
{
|
2009-09-25 13:31:43 +02:00
|
|
|
if (shader->input_reg_used[i])
|
2008-12-11 11:52:37 +01:00
|
|
|
{
|
|
|
|
++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 */
|
2009-09-25 13:31:43 +02:00
|
|
|
if (highest_reg_used < (gl_info->max_glsl_varyings / 4)
|
|
|
|
|| num_regs_used > (gl_info->max_glsl_varyings / 4))
|
2008-12-11 11:52:37 +01:00
|
|
|
{
|
2009-09-25 13:31:43 +02:00
|
|
|
if (num_regs_used > (gl_info->max_glsl_varyings / 4))
|
2008-12-11 11:52:37 +01:00
|
|
|
{
|
|
|
|
/* 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)
|
|
|
|
{
|
2009-09-25 13:31:43 +02:00
|
|
|
shader->input_reg_map[i] = i;
|
2007-10-28 00:12:37 +02:00
|
|
|
}
|
2008-12-11 11:52:37 +01:00
|
|
|
|
2009-09-25 13:31:43 +02:00
|
|
|
shader->declared_in_count = highest_reg_used + 1;
|
2007-06-07 23:52:48 +02:00
|
|
|
}
|
2008-12-11 11:52:37 +01:00
|
|
|
else
|
|
|
|
{
|
2009-09-25 13:31:43 +02:00
|
|
|
shader->declared_in_count = 0;
|
2008-12-11 11:52:37 +01:00
|
|
|
for (i = 0; i < MAX_REG_INPUT; ++i)
|
|
|
|
{
|
2009-09-25 13:31:43 +02:00
|
|
|
if (shader->input_reg_used[i]) shader->input_reg_map[i] = shader->declared_in_count++;
|
|
|
|
else shader->input_reg_map[i] = ~0U;
|
2008-12-11 11:52:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-25 13:31:43 +02:00
|
|
|
shader->baseShader.load_local_constsF = FALSE;
|
2007-06-07 23:52:48 +02:00
|
|
|
|
2009-09-25 13:31:43 +02:00
|
|
|
TRACE("(%p) : Copying byte code.\n", shader);
|
2008-12-15 16:35:14 +01:00
|
|
|
|
2009-09-25 13:31:43 +02:00
|
|
|
shader->baseShader.function = HeapAlloc(GetProcessHeap(), 0, shader->baseShader.functionLength);
|
|
|
|
if (!shader->baseShader.function) return E_OUTOFMEMORY;
|
|
|
|
memcpy(shader->baseShader.function, byte_code, shader->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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-23 18:42:09 +02:00
|
|
|
static const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl =
|
2005-08-25 21:24:21 +02:00
|
|
|
{
|
|
|
|
/*** 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 ***/
|
2005-08-25 21:24:21 +02:00
|
|
|
IWineD3DPixelShaderImpl_GetDevice,
|
2006-03-28 21:10:51 +02:00
|
|
|
IWineD3DPixelShaderImpl_GetFunction
|
2009-09-25 13:31:42 +02:00
|
|
|
/*** IWineD3DPixelShader methods ***/
|
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
|
|
|
}
|
|
|
|
}
|
2009-09-23 18:42:09 +02:00
|
|
|
|
|
|
|
HRESULT pixelshader_init(IWineD3DPixelShaderImpl *shader, IWineD3DDeviceImpl *device,
|
|
|
|
const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
|
2009-09-23 18:42:13 +02:00
|
|
|
IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
|
2009-09-23 18:42:09 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!byte_code) return WINED3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
shader->lpVtbl = &IWineD3DPixelShader_Vtbl;
|
2009-09-25 13:31:44 +02:00
|
|
|
shader_init(&shader->baseShader, device, parent, parent_ops);
|
2009-09-23 18:42:09 +02:00
|
|
|
|
2009-09-25 13:31:43 +02:00
|
|
|
hr = pixelshader_set_function(shader, byte_code, output_signature);
|
2009-09-23 18:42:09 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to set function, hr %#x.\n", hr);
|
|
|
|
shader_cleanup((IWineD3DBaseShader *)shader);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|