2006-05-08 21:44:25 +02:00
|
|
|
/*
|
|
|
|
* shaders implementation
|
|
|
|
*
|
|
|
|
* 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-04-17 09:46:56 +02:00
|
|
|
* Copyright 2009 Henri Verbeet for CodeWeavers
|
2006-05-08 21:44:25 +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
|
2006-05-08 21:44:25 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
|
2008-12-03 14:53:43 +01:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d);
|
2006-05-08 21:44:25 +02:00
|
|
|
|
2009-04-23 09:24:26 +02:00
|
|
|
/* DCL usage masks */
|
|
|
|
#define WINED3DSP_DCL_USAGE_SHIFT 0
|
|
|
|
#define WINED3DSP_DCL_USAGE_MASK (0xf << WINED3DSP_DCL_USAGE_SHIFT)
|
|
|
|
#define WINED3DSP_DCL_USAGEINDEX_SHIFT 16
|
|
|
|
#define WINED3DSP_DCL_USAGEINDEX_MASK (0xf << WINED3DSP_DCL_USAGEINDEX_SHIFT)
|
|
|
|
|
|
|
|
/* Opcode-related masks */
|
|
|
|
#define WINED3DSI_OPCODE_MASK 0x0000ffff
|
|
|
|
|
|
|
|
#define WINED3D_OPCODESPECIFICCONTROL_SHIFT 16
|
|
|
|
#define WINED3D_OPCODESPECIFICCONTROL_MASK (0xff << WINED3D_OPCODESPECIFICCONTROL_SHIFT)
|
|
|
|
|
|
|
|
#define WINED3DSI_INSTLENGTH_SHIFT 24
|
|
|
|
#define WINED3DSI_INSTLENGTH_MASK (0xf << WINED3DSI_INSTLENGTH_SHIFT)
|
|
|
|
|
|
|
|
#define WINED3DSI_COISSUE (1 << 30)
|
|
|
|
|
|
|
|
#define WINED3DSI_COMMENTSIZE_SHIFT 16
|
|
|
|
#define WINED3DSI_COMMENTSIZE_MASK (0x7fff << WINED3DSI_COMMENTSIZE_SHIFT)
|
|
|
|
|
|
|
|
#define WINED3DSHADER_INSTRUCTION_PREDICATED (1 << 28)
|
|
|
|
|
|
|
|
/* Register number mask */
|
|
|
|
#define WINED3DSP_REGNUM_MASK 0x000007ff
|
|
|
|
|
|
|
|
/* Register type masks */
|
|
|
|
#define WINED3DSP_REGTYPE_SHIFT 28
|
|
|
|
#define WINED3DSP_REGTYPE_MASK (0x7 << WINED3DSP_REGTYPE_SHIFT)
|
|
|
|
#define WINED3DSP_REGTYPE_SHIFT2 8
|
|
|
|
#define WINED3DSP_REGTYPE_MASK2 (0x18 << WINED3DSP_REGTYPE_SHIFT2)
|
|
|
|
|
|
|
|
/* Relative addressing mask */
|
|
|
|
#define WINED3DSHADER_ADDRESSMODE_SHIFT 13
|
|
|
|
#define WINED3DSHADER_ADDRESSMODE_MASK (1 << WINED3DSHADER_ADDRESSMODE_SHIFT)
|
|
|
|
|
|
|
|
/* Destination modifier mask */
|
|
|
|
#define WINED3DSP_DSTMOD_SHIFT 20
|
|
|
|
#define WINED3DSP_DSTMOD_MASK (0xf << WINED3DSP_DSTMOD_SHIFT)
|
|
|
|
|
|
|
|
/* Destination shift mask */
|
|
|
|
#define WINED3DSP_DSTSHIFT_SHIFT 24
|
|
|
|
#define WINED3DSP_DSTSHIFT_MASK (0xf << WINED3DSP_DSTSHIFT_SHIFT)
|
|
|
|
|
|
|
|
/* Swizzle mask */
|
|
|
|
#define WINED3DSP_SWIZZLE_SHIFT 16
|
|
|
|
#define WINED3DSP_SWIZZLE_MASK (0xff << WINED3DSP_SWIZZLE_SHIFT)
|
|
|
|
|
|
|
|
/* Source modifier mask */
|
|
|
|
#define WINED3DSP_SRCMOD_SHIFT 24
|
|
|
|
#define WINED3DSP_SRCMOD_MASK (0xf << WINED3DSP_SRCMOD_SHIFT)
|
|
|
|
|
|
|
|
typedef enum _WINED3DSHADER_ADDRESSMODE_TYPE
|
|
|
|
{
|
|
|
|
WINED3DSHADER_ADDRMODE_ABSOLUTE = 0 << WINED3DSHADER_ADDRESSMODE_SHIFT,
|
|
|
|
WINED3DSHADER_ADDRMODE_RELATIVE = 1 << WINED3DSHADER_ADDRESSMODE_SHIFT,
|
|
|
|
WINED3DSHADER_ADDRMODE_FORCE_DWORD = 0x7fffffff,
|
|
|
|
} WINED3DSHADER_ADDRESSMODE_TYPE;
|
|
|
|
|
2008-12-04 17:41:31 +01:00
|
|
|
static void shader_dump_param(const DWORD param, const DWORD addr_token, int input, DWORD shader_version);
|
2008-12-02 18:41:33 +01:00
|
|
|
|
2009-04-24 09:17:58 +02:00
|
|
|
/* Read a parameter opcode from the input stream,
|
|
|
|
* and possibly a relative addressing token.
|
|
|
|
* Return the number of tokens read */
|
|
|
|
static int shader_get_param(const DWORD *ptr, DWORD shader_version, DWORD *token, DWORD *addr_token)
|
|
|
|
{
|
|
|
|
UINT count = 1;
|
|
|
|
|
|
|
|
*token = *ptr;
|
|
|
|
|
|
|
|
/* PS >= 3.0 have relative addressing (with token)
|
|
|
|
* VS >= 2.0 have relative addressing (with token)
|
|
|
|
* VS >= 1.0 < 2.0 have relative addressing (without token)
|
|
|
|
* The version check below should work in general */
|
|
|
|
if (*ptr & WINED3DSHADER_ADDRMODE_RELATIVE)
|
|
|
|
{
|
|
|
|
if (WINED3DSHADER_VERSION_MAJOR(shader_version) < 2)
|
|
|
|
{
|
|
|
|
*addr_token = (1 << 31)
|
|
|
|
| ((WINED3DSPR_ADDR << WINED3DSP_REGTYPE_SHIFT2) & WINED3DSP_REGTYPE_MASK2)
|
|
|
|
| ((WINED3DSPR_ADDR << WINED3DSP_REGTYPE_SHIFT) & WINED3DSP_REGTYPE_MASK)
|
|
|
|
| (WINED3DSP_NOSWIZZLE << WINED3DSP_SWIZZLE_SHIFT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*addr_token = *(ptr + 1);
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const SHADER_OPCODE *shader_get_opcode(const SHADER_OPCODE *opcode_table, DWORD shader_version, DWORD code)
|
|
|
|
{
|
|
|
|
DWORD i = 0;
|
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
while (opcode_table[i].handler_idx != WINED3DSIH_TABLE_SIZE)
|
2009-04-24 09:17:58 +02:00
|
|
|
{
|
|
|
|
if ((code & WINED3DSI_OPCODE_MASK) == opcode_table[i].opcode
|
|
|
|
&& shader_version >= opcode_table[i].min_version
|
|
|
|
&& (!opcode_table[i].max_version || shader_version <= opcode_table[i].max_version))
|
|
|
|
{
|
|
|
|
return &opcode_table[i];
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("Unsupported opcode %#x(%d) masked %#x, shader version %#x\n",
|
|
|
|
code, code, code & WINED3DSI_OPCODE_MASK, shader_version);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the number of parameters to skip for an opcode */
|
|
|
|
static inline int shader_skip_opcode(const SHADER_OPCODE *opcode_info, DWORD opcode_token, DWORD shader_version)
|
|
|
|
{
|
|
|
|
/* Shaders >= 2.0 may contain address tokens, but fortunately they
|
|
|
|
* have a useful length mask - use it here. Shaders 1.0 contain no such tokens */
|
|
|
|
return (WINED3DSHADER_VERSION_MAJOR(shader_version) >= 2)
|
|
|
|
? ((opcode_token & WINED3DSI_INSTLENGTH_MASK) >> WINED3DSI_INSTLENGTH_SHIFT) : opcode_info->num_params;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the parameters of an unrecognized opcode from the input stream
|
|
|
|
* Return the number of tokens read.
|
|
|
|
*
|
|
|
|
* Note: This function assumes source or destination token format.
|
|
|
|
* It will not work with specially-formatted tokens like DEF or DCL,
|
|
|
|
* but hopefully those would be recognized */
|
|
|
|
static int shader_skip_unrecognized(const DWORD *ptr, DWORD shader_version)
|
|
|
|
{
|
|
|
|
int tokens_read = 0;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
/* TODO: Think of a good name for 0x80000000 and replace it with a constant */
|
|
|
|
while (*ptr & 0x80000000)
|
|
|
|
{
|
|
|
|
DWORD token, addr_token = 0;
|
|
|
|
tokens_read += shader_get_param(ptr, shader_version, &token, &addr_token);
|
|
|
|
ptr += tokens_read;
|
|
|
|
|
|
|
|
FIXME("Unrecognized opcode param: token=0x%08x addr_token=0x%08x name=", token, addr_token);
|
|
|
|
shader_dump_param(token, addr_token, i, shader_version);
|
|
|
|
FIXME("\n");
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return tokens_read;
|
|
|
|
}
|
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
static void shader_parse_src_param(DWORD param, const struct wined3d_shader_src_param *rel_addr,
|
|
|
|
struct wined3d_shader_src_param *src)
|
|
|
|
{
|
|
|
|
src->register_type = ((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT)
|
|
|
|
| ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2);
|
|
|
|
src->register_idx = param & WINED3DSP_REGNUM_MASK;
|
|
|
|
src->swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
|
|
|
|
src->modifiers = (param & WINED3DSP_SRCMOD_MASK) >> WINED3DSP_SRCMOD_SHIFT;
|
|
|
|
src->rel_addr = rel_addr;
|
|
|
|
}
|
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
static void shader_parse_dst_param(DWORD param, const struct wined3d_shader_src_param *rel_addr,
|
|
|
|
struct wined3d_shader_dst_param *dst)
|
|
|
|
{
|
|
|
|
dst->register_type = ((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT)
|
|
|
|
| ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2);
|
|
|
|
dst->register_idx = param & WINED3DSP_REGNUM_MASK;
|
|
|
|
dst->write_mask = param & WINED3DSP_WRITEMASK_ALL;
|
|
|
|
dst->modifiers = (param & WINED3DSP_DSTMOD_MASK) >> WINED3DSP_DSTMOD_SHIFT;
|
|
|
|
dst->shift = (param & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT;
|
|
|
|
dst->rel_addr = rel_addr;
|
|
|
|
}
|
|
|
|
|
2009-04-24 09:17:58 +02:00
|
|
|
static void shader_sm1_read_opcode(const DWORD **ptr, struct wined3d_shader_instruction *ins, UINT *param_size,
|
|
|
|
const SHADER_OPCODE *opcode_table, DWORD shader_version)
|
|
|
|
{
|
|
|
|
const SHADER_OPCODE *opcode_info;
|
|
|
|
DWORD opcode_token;
|
|
|
|
|
|
|
|
opcode_token = *(*ptr)++;
|
|
|
|
opcode_info = shader_get_opcode(opcode_table, shader_version, opcode_token);
|
|
|
|
if (!opcode_info)
|
|
|
|
{
|
|
|
|
FIXME("Unrecognized opcode: token=0x%08x\n", opcode_token);
|
|
|
|
ins->handler_idx = WINED3DSIH_TABLE_SIZE;
|
|
|
|
*param_size = shader_skip_unrecognized(*ptr, shader_version);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ins->handler_idx = opcode_info->handler_idx;
|
|
|
|
ins->flags = (opcode_token & WINED3D_OPCODESPECIFICCONTROL_MASK) >> WINED3D_OPCODESPECIFICCONTROL_SHIFT;
|
|
|
|
ins->coissue = opcode_token & WINED3DSI_COISSUE;
|
|
|
|
ins->predicate = opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED;
|
|
|
|
ins->dst_count = opcode_info->dst_token ? 1 : 0;
|
|
|
|
ins->src_count = opcode_info->num_params - opcode_info->dst_token;
|
|
|
|
*param_size = shader_skip_opcode(opcode_info, opcode_token, shader_version);
|
|
|
|
}
|
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
static void shader_sm1_read_src_param(const DWORD **ptr, struct wined3d_shader_src_param *src_param,
|
|
|
|
struct wined3d_shader_src_param *src_rel_addr, DWORD shader_version)
|
|
|
|
{
|
|
|
|
DWORD token, addr_token;
|
|
|
|
|
|
|
|
*ptr += shader_get_param(*ptr, shader_version, &token, &addr_token);
|
|
|
|
if (token & WINED3DSHADER_ADDRMODE_RELATIVE)
|
|
|
|
{
|
|
|
|
shader_parse_src_param(addr_token, NULL, src_rel_addr);
|
|
|
|
shader_parse_src_param(token, src_rel_addr, src_param);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shader_parse_src_param(token, NULL, src_param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
static void shader_sm1_read_dst_param(const DWORD **ptr, struct wined3d_shader_dst_param *dst_param,
|
|
|
|
struct wined3d_shader_src_param *dst_rel_addr, DWORD shader_version)
|
|
|
|
{
|
|
|
|
DWORD token, addr_token;
|
|
|
|
|
|
|
|
*ptr += shader_get_param(*ptr, shader_version, &token, &addr_token);
|
|
|
|
if (token & WINED3DSHADER_ADDRMODE_RELATIVE)
|
|
|
|
{
|
|
|
|
shader_parse_src_param(addr_token, NULL, dst_rel_addr);
|
|
|
|
shader_parse_dst_param(token, dst_rel_addr, dst_param);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shader_parse_dst_param(token, NULL, dst_param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
static const char *shader_opcode_names[] =
|
|
|
|
{
|
|
|
|
/* WINED3DSIH_ABS */ "abs",
|
|
|
|
/* WINED3DSIH_ADD */ "add",
|
|
|
|
/* WINED3DSIH_BEM */ "bem",
|
|
|
|
/* WINED3DSIH_BREAK */ "break",
|
|
|
|
/* WINED3DSIH_BREAKC */ "breakc",
|
|
|
|
/* WINED3DSIH_BREAKP */ "breakp",
|
|
|
|
/* WINED3DSIH_CALL */ "call",
|
|
|
|
/* WINED3DSIH_CALLNZ */ "callnz",
|
|
|
|
/* WINED3DSIH_CMP */ "cmp",
|
|
|
|
/* WINED3DSIH_CND */ "cnd",
|
|
|
|
/* WINED3DSIH_CRS */ "crs",
|
|
|
|
/* WINED3DSIH_DCL */ "dcl",
|
|
|
|
/* WINED3DSIH_DEF */ "def",
|
|
|
|
/* WINED3DSIH_DEFB */ "defb",
|
|
|
|
/* WINED3DSIH_DEFI */ "defi",
|
|
|
|
/* WINED3DSIH_DP2ADD */ "dp2add",
|
|
|
|
/* WINED3DSIH_DP3 */ "dp3",
|
|
|
|
/* WINED3DSIH_DP4 */ "dp4",
|
|
|
|
/* WINED3DSIH_DST */ "dst",
|
|
|
|
/* WINED3DSIH_DSX */ "dsx",
|
|
|
|
/* WINED3DSIH_DSY */ "dsy",
|
|
|
|
/* WINED3DSIH_ELSE */ "else",
|
|
|
|
/* WINED3DSIH_ENDIF */ "endif",
|
|
|
|
/* WINED3DSIH_ENDLOOP */ "endloop",
|
|
|
|
/* WINED3DSIH_ENDREP */ "endrep",
|
|
|
|
/* WINED3DSIH_EXP */ "exp",
|
|
|
|
/* WINED3DSIH_EXPP */ "expp",
|
|
|
|
/* WINED3DSIH_FRC */ "frc",
|
|
|
|
/* WINED3DSIH_IF */ "if",
|
|
|
|
/* WINED3DSIH_IFC */ "ifc",
|
|
|
|
/* WINED3DSIH_LABEL */ "label",
|
|
|
|
/* WINED3DSIH_LIT */ "lit",
|
|
|
|
/* WINED3DSIH_LOG */ "log",
|
|
|
|
/* WINED3DSIH_LOGP */ "logp",
|
|
|
|
/* WINED3DSIH_LOOP */ "loop",
|
|
|
|
/* WINED3DSIH_LRP */ "lrp",
|
|
|
|
/* WINED3DSIH_M3x2 */ "m3x2",
|
|
|
|
/* WINED3DSIH_M3x3 */ "m3x3",
|
|
|
|
/* WINED3DSIH_M3x4 */ "m3x4",
|
|
|
|
/* WINED3DSIH_M4x3 */ "m4x3",
|
|
|
|
/* WINED3DSIH_M4x4 */ "m4x4",
|
|
|
|
/* WINED3DSIH_MAD */ "mad",
|
|
|
|
/* WINED3DSIH_MAX */ "max",
|
|
|
|
/* WINED3DSIH_MIN */ "min",
|
|
|
|
/* WINED3DSIH_MOV */ "mov",
|
|
|
|
/* WINED3DSIH_MOVA */ "mova",
|
|
|
|
/* WINED3DSIH_MUL */ "mul",
|
|
|
|
/* WINED3DSIH_NOP */ "nop",
|
|
|
|
/* WINED3DSIH_NRM */ "nrm",
|
|
|
|
/* WINED3DSIH_PHASE */ "phase",
|
|
|
|
/* WINED3DSIH_POW */ "pow",
|
|
|
|
/* WINED3DSIH_RCP */ "rcp",
|
|
|
|
/* WINED3DSIH_REP */ "rep",
|
|
|
|
/* WINED3DSIH_RET */ "ret",
|
|
|
|
/* WINED3DSIH_RSQ */ "rsq",
|
|
|
|
/* WINED3DSIH_SETP */ "setp",
|
|
|
|
/* WINED3DSIH_SGE */ "sge",
|
|
|
|
/* WINED3DSIH_SGN */ "sgn",
|
|
|
|
/* WINED3DSIH_SINCOS */ "sincos",
|
|
|
|
/* WINED3DSIH_SLT */ "slt",
|
|
|
|
/* WINED3DSIH_SUB */ "sub",
|
|
|
|
/* WINED3DSIH_TEX */ "texld",
|
|
|
|
/* WINED3DSIH_TEXBEM */ "texbem",
|
|
|
|
/* WINED3DSIH_TEXBEML */ "texbeml",
|
|
|
|
/* WINED3DSIH_TEXCOORD */ "texcrd",
|
|
|
|
/* WINED3DSIH_TEXDEPTH */ "texdepth",
|
|
|
|
/* WINED3DSIH_TEXDP3 */ "texdp3",
|
|
|
|
/* WINED3DSIH_TEXDP3TEX */ "texdp3tex",
|
|
|
|
/* WINED3DSIH_TEXKILL */ "texkill",
|
|
|
|
/* WINED3DSIH_TEXLDD */ "texldd",
|
|
|
|
/* WINED3DSIH_TEXLDL */ "texldl",
|
|
|
|
/* WINED3DSIH_TEXM3x2DEPTH */ "texm3x2depth",
|
|
|
|
/* WINED3DSIH_TEXM3x2PAD */ "texm3x2pad",
|
|
|
|
/* WINED3DSIH_TEXM3x2TEX */ "texm3x2tex",
|
|
|
|
/* WINED3DSIH_TEXM3x3 */ "texm3x3",
|
|
|
|
/* WINED3DSIH_TEXM3x3DIFF */ "texm3x3diff",
|
|
|
|
/* WINED3DSIH_TEXM3x3PAD */ "texm3x3pad",
|
|
|
|
/* WINED3DSIH_TEXM3x3SPEC */ "texm3x3spec",
|
|
|
|
/* WINED3DSIH_TEXM3x3TEX */ "texm3x3tex",
|
|
|
|
/* WINED3DSIH_TEXM3x3VSPEC */ "texm3x3vspec",
|
|
|
|
/* WINED3DSIH_TEXREG2AR */ "texreg2ar",
|
|
|
|
/* WINED3DSIH_TEXREG2GB */ "texreg2gb",
|
|
|
|
/* WINED3DSIH_TEXREG2RGB */ "texreg2rgb",
|
|
|
|
};
|
|
|
|
|
2007-03-17 11:39:40 +01:00
|
|
|
static inline BOOL shader_is_version_token(DWORD token) {
|
2006-05-14 15:43:31 +02:00
|
|
|
return shader_is_pshader_version(token) ||
|
|
|
|
shader_is_vshader_version(token);
|
2006-05-10 00:03:09 +02:00
|
|
|
}
|
|
|
|
|
2008-12-09 09:52:38 +01:00
|
|
|
void shader_buffer_init(struct SHADER_BUFFER *buffer)
|
|
|
|
{
|
|
|
|
buffer->buffer = HeapAlloc(GetProcessHeap(), 0, SHADER_PGMSIZE);
|
|
|
|
buffer->buffer[0] = '\0';
|
|
|
|
buffer->bsize = 0;
|
|
|
|
buffer->lineNo = 0;
|
|
|
|
buffer->newline = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void shader_buffer_free(struct SHADER_BUFFER *buffer)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer->buffer);
|
|
|
|
}
|
|
|
|
|
2009-03-10 09:19:04 +01:00
|
|
|
int shader_vaddline(SHADER_BUFFER* buffer, const char *format, va_list args)
|
|
|
|
{
|
2006-05-08 21:44:25 +02:00
|
|
|
char* base = buffer->buffer + buffer->bsize;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = vsnprintf(base, SHADER_PGMSIZE - 1 - buffer->bsize, format, args);
|
|
|
|
|
|
|
|
if (rc < 0 || /* C89 */
|
|
|
|
rc > SHADER_PGMSIZE - 1 - buffer->bsize) { /* C99 */
|
|
|
|
|
|
|
|
ERR("The buffer allocated for the shader program string "
|
|
|
|
"is too small at %d bytes.\n", SHADER_PGMSIZE);
|
|
|
|
buffer->bsize = SHADER_PGMSIZE - 1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:30:41 +01:00
|
|
|
if (buffer->newline) {
|
|
|
|
TRACE("GL HW (%u, %u) : %s", buffer->lineNo + 1, buffer->bsize, base);
|
|
|
|
buffer->newline = FALSE;
|
|
|
|
} else {
|
2007-01-18 23:41:27 +01:00
|
|
|
TRACE("%s", base);
|
2007-01-15 19:30:41 +01:00
|
|
|
}
|
|
|
|
|
2006-05-08 21:44:25 +02:00
|
|
|
buffer->bsize += rc;
|
2007-01-15 19:30:41 +01:00
|
|
|
if (buffer->buffer[buffer->bsize-1] == '\n') {
|
|
|
|
buffer->lineNo++;
|
|
|
|
buffer->newline = TRUE;
|
|
|
|
}
|
2006-05-08 21:44:25 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-10 09:19:04 +01:00
|
|
|
int shader_addline(SHADER_BUFFER* buffer, const char *format, ...)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
ret = shader_vaddline(buffer, format, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-01-12 10:17:50 +01:00
|
|
|
void shader_init(struct IWineD3DBaseShaderClass *shader,
|
|
|
|
IWineD3DDevice *device, const SHADER_OPCODE *instruction_table)
|
|
|
|
{
|
|
|
|
shader->ref = 1;
|
|
|
|
shader->device = device;
|
|
|
|
shader->shader_ins = instruction_table;
|
|
|
|
list_init(&shader->linked_programs);
|
|
|
|
}
|
|
|
|
|
2009-04-23 09:24:26 +02:00
|
|
|
static inline WINED3DSHADER_PARAM_REGISTER_TYPE shader_get_regtype(DWORD param)
|
|
|
|
{
|
|
|
|
return ((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT)
|
|
|
|
| ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline DWORD shader_get_writemask(DWORD param)
|
|
|
|
{
|
|
|
|
return param & WINED3DSP_WRITEMASK_ALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL shader_is_comment(DWORD token)
|
|
|
|
{
|
|
|
|
return WINED3DSIO_COMMENT == (token & WINED3DSI_OPCODE_MASK);
|
|
|
|
}
|
|
|
|
|
2006-06-06 08:40:08 +02:00
|
|
|
/* Convert floating point offset relative
|
|
|
|
* to a register file to an absolute offset for float constants */
|
2008-12-02 18:41:33 +01:00
|
|
|
static unsigned int shader_get_float_offset(const DWORD reg)
|
|
|
|
{
|
2006-10-10 01:47:12 +02:00
|
|
|
unsigned int regnum = reg & WINED3DSP_REGNUM_MASK;
|
2006-06-06 08:40:08 +02:00
|
|
|
int regtype = shader_get_regtype(reg);
|
|
|
|
|
|
|
|
switch (regtype) {
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_CONST: return regnum;
|
|
|
|
case WINED3DSPR_CONST2: return 2048 + regnum;
|
|
|
|
case WINED3DSPR_CONST3: return 4096 + regnum;
|
|
|
|
case WINED3DSPR_CONST4: return 6144 + regnum;
|
2006-06-06 08:40:08 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unsupported register type: %d\n", regtype);
|
|
|
|
return regnum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-08 22:31:24 +01:00
|
|
|
static void shader_delete_constant_list(struct list* clist) {
|
|
|
|
|
|
|
|
struct list *ptr;
|
|
|
|
struct local_constant* constant;
|
|
|
|
|
|
|
|
ptr = list_head(clist);
|
|
|
|
while (ptr) {
|
|
|
|
constant = LIST_ENTRY(ptr, struct local_constant, entry);
|
|
|
|
ptr = list_next(clist, ptr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, constant);
|
|
|
|
}
|
|
|
|
list_init(clist);
|
|
|
|
}
|
|
|
|
|
2009-04-28 09:53:28 +02:00
|
|
|
static void shader_record_register_usage(IWineD3DBaseShaderImpl *This, struct shader_reg_maps *reg_maps,
|
|
|
|
DWORD register_type, UINT register_idx, BOOL has_rel_addr, BOOL pshader)
|
|
|
|
{
|
|
|
|
switch (register_type)
|
|
|
|
{
|
|
|
|
case WINED3DSPR_TEXTURE: /* WINED3DSPR_ADDR */
|
|
|
|
if (pshader) reg_maps->texcoord[register_idx] = 1;
|
|
|
|
else reg_maps->address[register_idx] = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DSPR_TEMP:
|
|
|
|
reg_maps->temporary[register_idx] = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DSPR_INPUT:
|
|
|
|
if (!pshader) reg_maps->attributes[register_idx] = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (has_rel_addr)
|
|
|
|
{
|
|
|
|
/* If relative addressing is used, we must assume that all registers
|
|
|
|
* are used. Even if it is a construct like v3[aL], we can't assume
|
|
|
|
* that v0, v1 and v2 aren't read because aL can be negative */
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < MAX_REG_INPUT; ++i)
|
|
|
|
{
|
|
|
|
((IWineD3DPixelShaderImpl *)This)->input_reg_used[i] = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
((IWineD3DPixelShaderImpl *)This)->input_reg_used[register_idx] = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DSPR_RASTOUT:
|
|
|
|
if (register_idx == 1) reg_maps->fog = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DSPR_MISCTYPE:
|
|
|
|
if (pshader && register_idx == 0) reg_maps->vpos = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DSPR_CONST:
|
|
|
|
if (has_rel_addr)
|
|
|
|
{
|
|
|
|
if (!pshader)
|
|
|
|
{
|
|
|
|
if (register_idx <= ((IWineD3DVertexShaderImpl *)This)->min_rel_offset)
|
|
|
|
((IWineD3DVertexShaderImpl *)This)->min_rel_offset = register_idx;
|
|
|
|
else if (register_idx >= ((IWineD3DVertexShaderImpl *)This)->max_rel_offset)
|
|
|
|
((IWineD3DVertexShaderImpl *)This)->max_rel_offset = register_idx;
|
|
|
|
}
|
|
|
|
reg_maps->usesrelconstF = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DSPR_CONSTINT:
|
|
|
|
reg_maps->integer_constants |= (1 << register_idx);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DSPR_CONSTBOOL:
|
|
|
|
reg_maps->boolean_constants |= (1 << register_idx);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
TRACE("Not recording register of type %#x and idx %u\n", register_type, register_idx);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-21 23:16:17 +02:00
|
|
|
/* Note that this does not count the loop register
|
|
|
|
* as an address register. */
|
2006-05-10 00:03:09 +02:00
|
|
|
|
2008-12-11 11:52:37 +01:00
|
|
|
HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, struct shader_reg_maps *reg_maps,
|
2009-04-08 08:35:06 +02:00
|
|
|
struct wined3d_shader_semantic *semantics_in, struct wined3d_shader_semantic *semantics_out,
|
|
|
|
const DWORD *byte_code)
|
2008-12-11 11:52:37 +01:00
|
|
|
{
|
2006-05-10 04:31:09 +02:00
|
|
|
IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
|
2008-12-04 17:41:31 +01:00
|
|
|
const SHADER_OPCODE *shader_ins = This->baseShader.shader_ins;
|
2008-12-15 12:10:14 +01:00
|
|
|
DWORD shader_version;
|
2007-09-14 13:21:52 +02:00
|
|
|
unsigned int cur_loop_depth = 0, max_loop_depth = 0;
|
2008-12-11 11:52:37 +01:00
|
|
|
const DWORD* pToken = byte_code;
|
|
|
|
char pshader;
|
2006-05-10 00:03:09 +02:00
|
|
|
|
2006-06-12 08:55:30 +02:00
|
|
|
/* There are some minor differences between pixel and vertex shaders */
|
|
|
|
|
2008-03-05 03:18:55 +01:00
|
|
|
memset(reg_maps->bumpmat, 0, sizeof(reg_maps->bumpmat));
|
|
|
|
memset(reg_maps->luminanceparams, 0, sizeof(reg_maps->luminanceparams));
|
2007-03-26 23:34:32 +02:00
|
|
|
|
2008-01-08 22:31:24 +01:00
|
|
|
/* get_registers_used is called on every compile on some 1.x shaders, which can result
|
|
|
|
* in stacking up a collection of local constants. Delete the old constants if existing
|
|
|
|
*/
|
|
|
|
shader_delete_constant_list(&This->baseShader.constantsF);
|
|
|
|
shader_delete_constant_list(&This->baseShader.constantsB);
|
|
|
|
shader_delete_constant_list(&This->baseShader.constantsI);
|
|
|
|
|
2008-12-11 11:52:37 +01:00
|
|
|
/* The version token is supposed to be the first token */
|
|
|
|
if (!shader_is_version_token(*pToken))
|
|
|
|
{
|
|
|
|
FIXME("First token is not a version token, invalid shader.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2008-12-15 12:10:14 +01:00
|
|
|
reg_maps->shader_version = shader_version = *pToken++;
|
2008-12-11 11:52:37 +01:00
|
|
|
pshader = shader_is_pshader_version(shader_version);
|
|
|
|
|
2006-10-13 05:36:41 +02:00
|
|
|
while (WINED3DVS_END() != *pToken) {
|
2009-04-24 09:17:58 +02:00
|
|
|
struct wined3d_shader_instruction ins;
|
|
|
|
UINT param_size;
|
2006-05-10 00:03:09 +02:00
|
|
|
|
|
|
|
/* Skip comments */
|
2008-12-11 11:52:37 +01:00
|
|
|
if (shader_is_comment(*pToken))
|
|
|
|
{
|
2006-10-13 05:34:13 +02:00
|
|
|
DWORD comment_len = (*pToken & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
|
2006-05-10 00:03:09 +02:00
|
|
|
++pToken;
|
|
|
|
pToken += comment_len;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fetch opcode */
|
2009-04-24 09:17:58 +02:00
|
|
|
shader_sm1_read_opcode(&pToken, &ins, ¶m_size, shader_ins, shader_version);
|
2006-05-10 00:03:09 +02:00
|
|
|
|
|
|
|
/* Unhandled opcode, and its parameters */
|
2009-04-24 09:17:58 +02:00
|
|
|
if (ins.handler_idx == WINED3DSIH_TABLE_SIZE)
|
|
|
|
{
|
|
|
|
TRACE("Skipping unrecognized instruction.\n");
|
|
|
|
pToken += param_size;
|
|
|
|
continue;
|
|
|
|
}
|
2006-05-10 00:03:09 +02:00
|
|
|
|
2006-06-12 08:53:32 +02:00
|
|
|
/* Handle declarations */
|
2009-04-24 09:17:58 +02:00
|
|
|
if (ins.handler_idx == WINED3DSIH_DCL)
|
|
|
|
{
|
2006-06-12 08:53:32 +02:00
|
|
|
DWORD usage = *pToken++;
|
|
|
|
DWORD param = *pToken++;
|
|
|
|
DWORD regtype = shader_get_regtype(param);
|
2006-10-10 01:47:12 +02:00
|
|
|
unsigned int regnum = param & WINED3DSP_REGNUM_MASK;
|
2006-06-12 08:53:32 +02:00
|
|
|
|
2006-06-12 08:59:16 +02:00
|
|
|
/* Vshader: mark attributes used
|
|
|
|
Pshader: mark 3.0 input registers used, save token */
|
2006-10-10 01:45:55 +02:00
|
|
|
if (WINED3DSPR_INPUT == regtype) {
|
2006-06-12 08:55:30 +02:00
|
|
|
|
|
|
|
if (!pshader)
|
|
|
|
reg_maps->attributes[regnum] = 1;
|
2006-06-12 08:57:07 +02:00
|
|
|
else
|
|
|
|
reg_maps->packed_input[regnum] = 1;
|
2006-06-12 08:55:30 +02:00
|
|
|
|
2009-04-08 08:35:07 +02:00
|
|
|
semantics_in[regnum].usage = (usage & WINED3DSP_DCL_USAGE_MASK) >> WINED3DSP_DCL_USAGE_SHIFT;
|
|
|
|
semantics_in[regnum].usage_idx =
|
|
|
|
(usage & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
|
2009-04-17 09:46:56 +02:00
|
|
|
shader_parse_dst_param(param, NULL, &semantics_in[regnum].reg);
|
2006-06-12 08:53:32 +02:00
|
|
|
|
2006-06-12 08:59:16 +02:00
|
|
|
/* Vshader: mark 3.0 output registers used, save token */
|
2006-10-10 01:45:55 +02:00
|
|
|
} else if (WINED3DSPR_OUTPUT == regtype) {
|
2006-06-12 08:57:07 +02:00
|
|
|
reg_maps->packed_output[regnum] = 1;
|
2009-04-08 08:35:07 +02:00
|
|
|
semantics_out[regnum].usage = (usage & WINED3DSP_DCL_USAGE_MASK) >> WINED3DSP_DCL_USAGE_SHIFT;
|
|
|
|
semantics_out[regnum].usage_idx =
|
|
|
|
(usage & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
|
2009-04-17 09:46:56 +02:00
|
|
|
shader_parse_dst_param(param, NULL, &semantics_out[regnum].reg);
|
2009-04-08 08:35:06 +02:00
|
|
|
|
2007-04-12 19:08:51 +02:00
|
|
|
if (usage & (WINED3DDECLUSAGE_FOG << WINED3DSP_DCL_USAGE_SHIFT))
|
|
|
|
reg_maps->fog = 1;
|
2006-06-12 08:53:32 +02:00
|
|
|
|
2006-06-12 08:59:16 +02:00
|
|
|
/* Save sampler usage token */
|
2006-10-10 01:45:55 +02:00
|
|
|
} else if (WINED3DSPR_SAMPLER == regtype)
|
2006-06-12 08:59:16 +02:00
|
|
|
reg_maps->samplers[regnum] = usage;
|
2009-04-24 09:17:58 +02:00
|
|
|
}
|
|
|
|
else if (ins.handler_idx == WINED3DSIH_DEF)
|
|
|
|
{
|
2006-07-10 06:51:03 +02:00
|
|
|
local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
|
|
|
|
if (!lconst) return E_OUTOFMEMORY;
|
2006-10-10 01:47:12 +02:00
|
|
|
lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
|
2008-07-11 22:58:34 +02:00
|
|
|
memcpy(lconst->value, pToken + 1, 4 * sizeof(DWORD));
|
2007-09-13 13:34:29 +02:00
|
|
|
|
|
|
|
/* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
|
2008-12-15 12:10:14 +01:00
|
|
|
if (WINED3DSHADER_VERSION_MAJOR(shader_version) == 1 && pshader)
|
|
|
|
{
|
2007-09-13 13:34:29 +02:00
|
|
|
float *value = (float *) lconst->value;
|
|
|
|
if(value[0] < -1.0) value[0] = -1.0;
|
|
|
|
else if(value[0] > 1.0) value[0] = 1.0;
|
|
|
|
if(value[1] < -1.0) value[1] = -1.0;
|
|
|
|
else if(value[1] > 1.0) value[1] = 1.0;
|
|
|
|
if(value[2] < -1.0) value[2] = -1.0;
|
|
|
|
else if(value[2] > 1.0) value[2] = 1.0;
|
|
|
|
if(value[3] < -1.0) value[3] = -1.0;
|
|
|
|
else if(value[3] > 1.0) value[3] = 1.0;
|
|
|
|
}
|
|
|
|
|
2006-07-10 06:51:03 +02:00
|
|
|
list_add_head(&This->baseShader.constantsF, &lconst->entry);
|
2009-04-24 09:17:58 +02:00
|
|
|
pToken += param_size;
|
|
|
|
}
|
|
|
|
else if (ins.handler_idx == WINED3DSIH_DEFI)
|
|
|
|
{
|
2006-07-10 06:51:03 +02:00
|
|
|
local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
|
|
|
|
if (!lconst) return E_OUTOFMEMORY;
|
2006-10-10 01:47:12 +02:00
|
|
|
lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
|
2008-07-11 22:58:34 +02:00
|
|
|
memcpy(lconst->value, pToken + 1, 4 * sizeof(DWORD));
|
2006-07-10 06:51:03 +02:00
|
|
|
list_add_head(&This->baseShader.constantsI, &lconst->entry);
|
2009-04-24 09:17:58 +02:00
|
|
|
pToken += param_size;
|
|
|
|
}
|
|
|
|
else if (ins.handler_idx == WINED3DSIH_DEFB)
|
|
|
|
{
|
2006-07-10 06:51:03 +02:00
|
|
|
local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
|
|
|
|
if (!lconst) return E_OUTOFMEMORY;
|
2006-10-10 01:47:12 +02:00
|
|
|
lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
|
2008-07-11 22:58:34 +02:00
|
|
|
memcpy(lconst->value, pToken + 1, 1 * sizeof(DWORD));
|
2006-07-10 06:51:03 +02:00
|
|
|
list_add_head(&This->baseShader.constantsB, &lconst->entry);
|
2009-04-24 09:17:58 +02:00
|
|
|
pToken += param_size;
|
|
|
|
}
|
2006-06-16 22:13:01 +02:00
|
|
|
/* If there's a loop in the shader */
|
2009-04-24 09:17:58 +02:00
|
|
|
else if (ins.handler_idx == WINED3DSIH_LOOP
|
|
|
|
|| ins.handler_idx == WINED3DSIH_REP)
|
|
|
|
{
|
2009-04-22 21:39:14 +02:00
|
|
|
DWORD reg;
|
|
|
|
|
|
|
|
if(ins.handler_idx == WINED3DSIH_LOOP) {
|
|
|
|
reg = pToken[1];
|
|
|
|
} else {
|
|
|
|
reg = pToken[0];
|
|
|
|
}
|
|
|
|
|
2007-09-14 13:21:52 +02:00
|
|
|
cur_loop_depth++;
|
|
|
|
if(cur_loop_depth > max_loop_depth)
|
|
|
|
max_loop_depth = cur_loop_depth;
|
2009-04-24 09:17:58 +02:00
|
|
|
pToken += param_size;
|
2007-09-14 13:21:52 +02:00
|
|
|
|
2008-11-27 01:21:36 +01:00
|
|
|
/* Rep and Loop always use an integer constant for the control parameters */
|
2009-04-28 09:53:28 +02:00
|
|
|
reg_maps->integer_constants |= (1 << (reg & WINED3DSP_REGNUM_MASK));
|
2009-04-24 09:17:58 +02:00
|
|
|
}
|
|
|
|
else if (ins.handler_idx == WINED3DSIH_ENDLOOP
|
|
|
|
|| ins.handler_idx == WINED3DSIH_ENDREP)
|
|
|
|
{
|
2007-09-14 13:21:52 +02:00
|
|
|
cur_loop_depth--;
|
2009-04-24 09:17:58 +02:00
|
|
|
}
|
2006-07-10 12:35:15 +02:00
|
|
|
/* For subroutine prototypes */
|
2009-04-24 09:17:58 +02:00
|
|
|
else if (ins.handler_idx == WINED3DSIH_LABEL)
|
|
|
|
{
|
2006-07-10 12:35:15 +02:00
|
|
|
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD snum = *pToken & WINED3DSP_REGNUM_MASK;
|
2006-07-10 12:35:15 +02:00
|
|
|
reg_maps->labels[snum] = 1;
|
2009-04-24 09:17:58 +02:00
|
|
|
pToken += param_size;
|
|
|
|
}
|
2006-06-12 08:59:16 +02:00
|
|
|
/* Set texture, address, temporary registers */
|
2009-04-24 09:17:58 +02:00
|
|
|
else
|
|
|
|
{
|
2006-05-18 03:09:56 +02:00
|
|
|
int i, limit;
|
2006-05-10 00:03:09 +02:00
|
|
|
|
2006-06-12 08:59:16 +02:00
|
|
|
/* Declare 1.X samplers implicitly, based on the destination reg. number */
|
2008-12-15 12:10:14 +01:00
|
|
|
if (WINED3DSHADER_VERSION_MAJOR(shader_version) == 1
|
|
|
|
&& pshader /* Filter different instructions with the same enum values in VS */
|
2009-04-24 09:17:58 +02:00
|
|
|
&& (ins.handler_idx == WINED3DSIH_TEX
|
|
|
|
|| ins.handler_idx == WINED3DSIH_TEXBEM
|
|
|
|
|| ins.handler_idx == WINED3DSIH_TEXBEML
|
|
|
|
|| ins.handler_idx == WINED3DSIH_TEXDP3TEX
|
|
|
|
|| ins.handler_idx == WINED3DSIH_TEXM3x2TEX
|
|
|
|
|| ins.handler_idx == WINED3DSIH_TEXM3x3SPEC
|
|
|
|
|| ins.handler_idx == WINED3DSIH_TEXM3x3TEX
|
|
|
|
|| ins.handler_idx == WINED3DSIH_TEXM3x3VSPEC
|
|
|
|
|| ins.handler_idx == WINED3DSIH_TEXREG2AR
|
|
|
|
|| ins.handler_idx == WINED3DSIH_TEXREG2GB
|
|
|
|
|| ins.handler_idx == WINED3DSIH_TEXREG2RGB))
|
2008-12-15 12:10:14 +01:00
|
|
|
{
|
2006-06-12 08:59:16 +02:00
|
|
|
/* Fake sampler usage, only set reserved bit and ttype */
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD sampler_code = *pToken & WINED3DSP_REGNUM_MASK;
|
2006-08-27 19:16:01 +02:00
|
|
|
|
2008-12-12 09:33:51 +01:00
|
|
|
TRACE("Setting fake 2D sampler for 1.x pixelshader\n");
|
|
|
|
reg_maps->samplers[sampler_code] = (0x1 << 31) | WINED3DSTT_2D;
|
2007-02-15 03:05:17 +01:00
|
|
|
|
|
|
|
/* texbem is only valid with < 1.4 pixel shaders */
|
2009-04-24 09:17:58 +02:00
|
|
|
if (ins.handler_idx == WINED3DSIH_TEXBEM
|
|
|
|
|| ins.handler_idx == WINED3DSIH_TEXBEML)
|
|
|
|
{
|
2008-03-05 03:18:55 +01:00
|
|
|
reg_maps->bumpmat[sampler_code] = TRUE;
|
2009-04-24 09:17:58 +02:00
|
|
|
if (ins.handler_idx == WINED3DSIH_TEXBEML)
|
|
|
|
{
|
2008-03-05 03:18:55 +01:00
|
|
|
reg_maps->luminanceparams[sampler_code] = TRUE;
|
2007-02-15 03:05:17 +01:00
|
|
|
}
|
|
|
|
}
|
2006-06-12 08:59:16 +02:00
|
|
|
}
|
2009-04-24 09:17:58 +02:00
|
|
|
if (ins.handler_idx == WINED3DSIH_NRM)
|
|
|
|
{
|
2007-09-05 20:09:06 +02:00
|
|
|
reg_maps->usesnrm = 1;
|
2009-04-24 09:17:58 +02:00
|
|
|
}
|
|
|
|
else if (pshader && ins.handler_idx == WINED3DSIH_BEM)
|
|
|
|
{
|
2007-09-05 20:12:06 +02:00
|
|
|
DWORD regnum = *pToken & WINED3DSP_REGNUM_MASK;
|
2008-03-05 03:18:55 +01:00
|
|
|
reg_maps->bumpmat[regnum] = TRUE;
|
2009-04-24 09:17:58 +02:00
|
|
|
}
|
|
|
|
else if (ins.handler_idx == WINED3DSIH_DSY)
|
|
|
|
{
|
2007-10-13 13:03:56 +02:00
|
|
|
reg_maps->usesdsy = 1;
|
2007-09-05 20:09:06 +02:00
|
|
|
}
|
2006-06-12 08:59:16 +02:00
|
|
|
|
2006-05-18 03:09:56 +02:00
|
|
|
/* This will loop over all the registers and try to
|
2009-04-28 09:53:28 +02:00
|
|
|
* make a bitmask of the ones we're interested in.
|
2006-05-18 03:09:56 +02:00
|
|
|
*
|
2009-04-28 09:53:28 +02:00
|
|
|
* Relative addressing tokens are ignored, but that's
|
|
|
|
* okay, since we'll catch any address registers when
|
2006-05-18 03:09:56 +02:00
|
|
|
* they are initialized (required by spec) */
|
|
|
|
|
2009-04-28 09:53:28 +02:00
|
|
|
if (ins.dst_count)
|
|
|
|
{
|
|
|
|
struct wined3d_shader_dst_param dst_param;
|
|
|
|
struct wined3d_shader_src_param dst_rel_addr;
|
2006-05-17 08:04:30 +02:00
|
|
|
|
2009-04-28 09:53:28 +02:00
|
|
|
shader_sm1_read_dst_param(&pToken, &dst_param, &dst_rel_addr, shader_version);
|
2006-05-17 08:04:30 +02:00
|
|
|
|
2009-04-28 09:53:28 +02:00
|
|
|
/* WINED3DSPR_TEXCRDOUT is the same as WINED3DSPR_OUTPUT. _OUTPUT can be > MAX_REG_TEXCRD and
|
|
|
|
* is used in >= 3.0 shaders. Filter 3.0 shaders to prevent overflows, and also filter pixel
|
|
|
|
* shaders because TECRDOUT isn't used in them, but future register types might cause issues */
|
2009-04-28 09:53:28 +02:00
|
|
|
if (!pshader && WINED3DSHADER_VERSION_MAJOR(shader_version) < 3
|
|
|
|
&& dst_param.register_type == WINED3DSPR_TEXCRDOUT)
|
2008-12-15 12:10:14 +01:00
|
|
|
{
|
2009-04-28 09:53:28 +02:00
|
|
|
reg_maps->texcoord_mask[dst_param.register_type] |= dst_param.write_mask;
|
2007-12-06 22:10:11 +01:00
|
|
|
}
|
2009-04-28 09:53:28 +02:00
|
|
|
else
|
|
|
|
{
|
2009-04-28 09:53:28 +02:00
|
|
|
shader_record_register_usage(This, reg_maps, dst_param.register_type,
|
|
|
|
dst_param.register_idx, !!dst_param.rel_addr, pshader);
|
2009-04-28 09:53:28 +02:00
|
|
|
}
|
2007-09-05 20:09:06 +02:00
|
|
|
}
|
2009-04-28 09:53:28 +02:00
|
|
|
|
|
|
|
limit = ins.src_count + (ins.predicate ? 1 : 0);
|
|
|
|
for (i = 0; i < limit; ++i)
|
|
|
|
{
|
|
|
|
struct wined3d_shader_src_param src_param, src_rel_addr;
|
|
|
|
|
|
|
|
shader_sm1_read_src_param(&pToken, &src_param, &src_rel_addr, shader_version);
|
|
|
|
shader_record_register_usage(This, reg_maps, src_param.register_type,
|
|
|
|
src_param.register_idx, !!src_param.rel_addr, pshader);
|
|
|
|
}
|
2006-05-10 00:03:09 +02:00
|
|
|
}
|
|
|
|
}
|
2008-12-11 11:52:37 +01:00
|
|
|
++pToken;
|
2007-09-14 13:21:52 +02:00
|
|
|
reg_maps->loop_depth = max_loop_depth;
|
2006-07-10 06:51:03 +02:00
|
|
|
|
2008-12-11 11:52:37 +01:00
|
|
|
This->baseShader.functionLength = ((char *)pToken - (char *)byte_code);
|
|
|
|
|
2006-07-10 06:51:03 +02:00
|
|
|
return WINED3D_OK;
|
2006-05-10 00:03:09 +02:00
|
|
|
}
|
|
|
|
|
2008-12-04 17:41:31 +01:00
|
|
|
static void shader_dump_decl_usage(DWORD decl, DWORD param, DWORD shader_version)
|
|
|
|
{
|
2006-05-10 04:26:05 +02:00
|
|
|
DWORD regtype = shader_get_regtype(param);
|
2006-07-03 08:03:47 +02:00
|
|
|
|
|
|
|
TRACE("dcl");
|
2006-05-10 04:26:05 +02:00
|
|
|
|
2006-10-10 01:45:55 +02:00
|
|
|
if (regtype == WINED3DSPR_SAMPLER) {
|
2006-07-28 21:34:39 +02:00
|
|
|
DWORD ttype = decl & WINED3DSP_TEXTURETYPE_MASK;
|
2006-05-10 04:26:05 +02:00
|
|
|
|
|
|
|
switch (ttype) {
|
2006-07-28 21:34:39 +02:00
|
|
|
case WINED3DSTT_2D: TRACE("_2d"); break;
|
|
|
|
case WINED3DSTT_CUBE: TRACE("_cube"); break;
|
|
|
|
case WINED3DSTT_VOLUME: TRACE("_volume"); break;
|
2008-07-15 23:54:37 +02:00
|
|
|
default: TRACE("_unknown_ttype(0x%08x)", ttype);
|
2006-05-10 04:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2006-10-10 01:46:35 +02:00
|
|
|
DWORD usage = decl & WINED3DSP_DCL_USAGE_MASK;
|
|
|
|
DWORD idx = (decl & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
|
2006-05-10 04:26:05 +02:00
|
|
|
|
2006-07-03 08:03:47 +02:00
|
|
|
/* Pixel shaders 3.0 don't have usage semantics */
|
2008-12-04 17:41:31 +01:00
|
|
|
if (shader_is_pshader_version(shader_version) && shader_version < WINED3DPS_VERSION(3,0))
|
2006-07-03 08:03:47 +02:00
|
|
|
return;
|
|
|
|
else
|
|
|
|
TRACE("_");
|
|
|
|
|
2006-05-10 04:26:05 +02:00
|
|
|
switch(usage) {
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_POSITION:
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("position%d", idx);
|
2006-05-10 04:26:05 +02:00
|
|
|
break;
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_BLENDINDICES:
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("blend");
|
2006-05-10 04:26:05 +02:00
|
|
|
break;
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_BLENDWEIGHT:
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("weight");
|
2006-05-10 04:26:05 +02:00
|
|
|
break;
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_NORMAL:
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("normal%d", idx);
|
2006-05-10 04:26:05 +02:00
|
|
|
break;
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_PSIZE:
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("psize");
|
2006-05-10 04:26:05 +02:00
|
|
|
break;
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_COLOR:
|
2006-05-10 04:26:05 +02:00
|
|
|
if(idx == 0) {
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("color");
|
2006-05-10 04:26:05 +02:00
|
|
|
} else {
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("specular%d", (idx - 1));
|
2006-05-10 04:26:05 +02:00
|
|
|
}
|
|
|
|
break;
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_TEXCOORD:
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("texture%d", idx);
|
2006-05-10 04:26:05 +02:00
|
|
|
break;
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_TANGENT:
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("tangent");
|
2006-05-10 04:26:05 +02:00
|
|
|
break;
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_BINORMAL:
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("binormal");
|
2006-05-10 04:26:05 +02:00
|
|
|
break;
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_TESSFACTOR:
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("tessfactor");
|
2006-05-10 04:26:05 +02:00
|
|
|
break;
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_POSITIONT:
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("positionT%d", idx);
|
2006-05-10 04:26:05 +02:00
|
|
|
break;
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_FOG:
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("fog");
|
2006-05-10 04:26:05 +02:00
|
|
|
break;
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_DEPTH:
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("depth");
|
2006-05-10 04:26:05 +02:00
|
|
|
break;
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_SAMPLE:
|
2006-10-10 19:23:01 +02:00
|
|
|
TRACE("sample");
|
2006-05-10 04:26:05 +02:00
|
|
|
break;
|
|
|
|
default:
|
2008-07-15 23:54:37 +02:00
|
|
|
FIXME("unknown_semantics(0x%08x)", usage);
|
2006-05-10 04:26:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-04 17:41:31 +01:00
|
|
|
static void shader_dump_arr_entry(const DWORD param, const DWORD addr_token,
|
|
|
|
unsigned int reg, int input, DWORD shader_version)
|
|
|
|
{
|
2006-05-17 08:05:49 +02:00
|
|
|
char relative =
|
2006-10-13 05:35:03 +02:00
|
|
|
((param & WINED3DSHADER_ADDRESSMODE_MASK) == WINED3DSHADER_ADDRMODE_RELATIVE);
|
2006-05-17 08:05:49 +02:00
|
|
|
|
|
|
|
if (relative) {
|
2006-06-06 08:40:08 +02:00
|
|
|
TRACE("[");
|
2006-05-17 08:05:49 +02:00
|
|
|
if (addr_token)
|
2008-12-04 17:41:31 +01:00
|
|
|
shader_dump_param(addr_token, 0, input, shader_version);
|
2006-05-17 08:05:49 +02:00
|
|
|
else
|
|
|
|
TRACE("a0.x");
|
|
|
|
TRACE(" + ");
|
|
|
|
}
|
2006-06-06 08:40:08 +02:00
|
|
|
TRACE("%u", reg);
|
|
|
|
if (relative)
|
|
|
|
TRACE("]");
|
2006-05-17 08:05:49 +02:00
|
|
|
}
|
|
|
|
|
2008-12-04 17:41:31 +01:00
|
|
|
static void shader_dump_param(const DWORD param, const DWORD addr_token, int input, DWORD shader_version)
|
2008-12-02 18:41:33 +01:00
|
|
|
{
|
2006-12-14 15:47:59 +01:00
|
|
|
static const char * const rastout_reg_names[] = { "oPos", "oFog", "oPts" };
|
2007-05-03 21:01:09 +02:00
|
|
|
static const char * const misctype_reg_names[] = { "vPos", "vFace"};
|
2008-12-19 19:21:56 +01:00
|
|
|
const char *swizzle_reg_chars = "xyzw";
|
2006-05-14 15:43:31 +02:00
|
|
|
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD reg = param & WINED3DSP_REGNUM_MASK;
|
2006-05-14 15:43:31 +02:00
|
|
|
DWORD regtype = shader_get_regtype(param);
|
2006-10-10 01:47:42 +02:00
|
|
|
DWORD modifier = param & WINED3DSP_SRCMOD_MASK;
|
2006-05-14 15:43:31 +02:00
|
|
|
|
|
|
|
/* There are some minor differences between pixel and vertex shaders */
|
2008-12-04 17:41:31 +01:00
|
|
|
char pshader = shader_is_pshader_version(shader_version);
|
2006-05-14 15:43:31 +02:00
|
|
|
|
|
|
|
if (input) {
|
2006-10-10 01:47:42 +02:00
|
|
|
if ( (modifier == WINED3DSPSM_NEG) ||
|
|
|
|
(modifier == WINED3DSPSM_BIASNEG) ||
|
|
|
|
(modifier == WINED3DSPSM_SIGNNEG) ||
|
|
|
|
(modifier == WINED3DSPSM_X2NEG) ||
|
|
|
|
(modifier == WINED3DSPSM_ABSNEG) )
|
2006-05-14 15:43:31 +02:00
|
|
|
TRACE("-");
|
2006-10-10 01:47:42 +02:00
|
|
|
else if (modifier == WINED3DSPSM_COMP)
|
2006-05-14 15:43:31 +02:00
|
|
|
TRACE("1-");
|
2006-10-10 01:47:42 +02:00
|
|
|
else if (modifier == WINED3DSPSM_NOT)
|
2006-05-18 03:09:56 +02:00
|
|
|
TRACE("!");
|
2006-07-07 08:29:39 +02:00
|
|
|
|
2006-10-10 01:47:42 +02:00
|
|
|
if (modifier == WINED3DSPSM_ABS || modifier == WINED3DSPSM_ABSNEG)
|
2006-07-07 08:29:39 +02:00
|
|
|
TRACE("abs(");
|
2006-05-14 15:43:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (regtype) {
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_TEMP:
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("r%u", reg);
|
2006-05-14 15:43:31 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_INPUT:
|
2006-06-06 08:40:08 +02:00
|
|
|
TRACE("v");
|
2008-12-04 17:41:31 +01:00
|
|
|
shader_dump_arr_entry(param, addr_token, reg, input, shader_version);
|
2006-05-14 15:43:31 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_CONST:
|
|
|
|
case WINED3DSPR_CONST2:
|
|
|
|
case WINED3DSPR_CONST3:
|
|
|
|
case WINED3DSPR_CONST4:
|
2006-05-17 08:05:49 +02:00
|
|
|
TRACE("c");
|
2008-12-04 17:41:31 +01:00
|
|
|
shader_dump_arr_entry(param, addr_token, shader_get_float_offset(param), input, shader_version);
|
2006-05-14 15:43:31 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_TEXTURE: /* vs: case D3DSPR_ADDR */
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("%c%u", (pshader? 't':'a'), reg);
|
2006-05-14 15:43:31 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_RASTOUT:
|
2006-05-14 15:43:31 +02:00
|
|
|
TRACE("%s", rastout_reg_names[reg]);
|
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_COLOROUT:
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("oC%u", reg);
|
2006-05-14 15:43:31 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_DEPTHOUT:
|
2006-05-14 15:43:31 +02:00
|
|
|
TRACE("oDepth");
|
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_ATTROUT:
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("oD%u", reg);
|
2006-05-14 15:43:31 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_TEXCRDOUT:
|
2006-05-18 03:08:29 +02:00
|
|
|
|
|
|
|
/* Vertex shaders >= 3.0 use general purpose output registers
|
2006-10-10 01:45:55 +02:00
|
|
|
* (WINED3DSPR_OUTPUT), which can include an address token */
|
2006-05-18 03:08:29 +02:00
|
|
|
|
2008-12-04 17:41:31 +01:00
|
|
|
if (WINED3DSHADER_VERSION_MAJOR(shader_version) >= 3) {
|
2006-05-18 03:08:29 +02:00
|
|
|
TRACE("o");
|
2008-12-04 17:41:31 +01:00
|
|
|
shader_dump_arr_entry(param, addr_token, reg, input, shader_version);
|
2006-05-18 03:08:29 +02:00
|
|
|
}
|
|
|
|
else
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("oT%u", reg);
|
2006-05-14 15:43:31 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_CONSTINT:
|
2006-05-17 08:05:49 +02:00
|
|
|
TRACE("i");
|
2008-12-04 17:41:31 +01:00
|
|
|
shader_dump_arr_entry(param, addr_token, reg, input, shader_version);
|
2006-05-14 15:43:31 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_CONSTBOOL:
|
2006-05-17 08:05:49 +02:00
|
|
|
TRACE("b");
|
2008-12-04 17:41:31 +01:00
|
|
|
shader_dump_arr_entry(param, addr_token, reg, input, shader_version);
|
2006-05-14 15:43:31 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_LABEL:
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("l%u", reg);
|
2006-05-14 15:43:31 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_LOOP:
|
2006-05-17 08:05:49 +02:00
|
|
|
TRACE("aL");
|
2006-05-14 15:43:31 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_SAMPLER:
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("s%u", reg);
|
2006-05-14 15:43:31 +02:00
|
|
|
break;
|
2007-05-03 21:01:09 +02:00
|
|
|
case WINED3DSPR_MISCTYPE:
|
|
|
|
if (reg > 1) {
|
|
|
|
FIXME("Unhandled misctype register %d\n", reg);
|
|
|
|
} else {
|
|
|
|
TRACE("%s", misctype_reg_names[reg]);
|
|
|
|
}
|
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_PREDICATE:
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("p%u", reg);
|
2006-05-18 03:08:29 +02:00
|
|
|
break;
|
2006-05-14 15:43:31 +02:00
|
|
|
default:
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("unhandled_rtype(%#x)", regtype);
|
2006-05-14 15:43:31 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!input) {
|
|
|
|
/* operand output (for modifiers and shift, see dump_ins_modifiers) */
|
|
|
|
|
2006-10-10 01:48:12 +02:00
|
|
|
if ((param & WINED3DSP_WRITEMASK_ALL) != WINED3DSP_WRITEMASK_ALL) {
|
2006-05-14 15:43:31 +02:00
|
|
|
TRACE(".");
|
2006-10-10 01:48:12 +02:00
|
|
|
if (param & WINED3DSP_WRITEMASK_0) TRACE("%c", swizzle_reg_chars[0]);
|
|
|
|
if (param & WINED3DSP_WRITEMASK_1) TRACE("%c", swizzle_reg_chars[1]);
|
|
|
|
if (param & WINED3DSP_WRITEMASK_2) TRACE("%c", swizzle_reg_chars[2]);
|
|
|
|
if (param & WINED3DSP_WRITEMASK_3) TRACE("%c", swizzle_reg_chars[3]);
|
2006-05-14 15:43:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/** operand input */
|
2006-10-10 01:47:42 +02:00
|
|
|
DWORD swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
|
2008-12-19 19:21:56 +01:00
|
|
|
DWORD swizzle_x = swizzle & 0x03;
|
|
|
|
DWORD swizzle_y = (swizzle >> 2) & 0x03;
|
|
|
|
DWORD swizzle_z = (swizzle >> 4) & 0x03;
|
|
|
|
DWORD swizzle_w = (swizzle >> 6) & 0x03;
|
2006-05-14 15:43:31 +02:00
|
|
|
|
2006-07-07 08:29:39 +02:00
|
|
|
if (0 != modifier) {
|
|
|
|
switch (modifier) {
|
2006-10-10 01:47:42 +02:00
|
|
|
case WINED3DSPSM_NONE: break;
|
|
|
|
case WINED3DSPSM_NEG: break;
|
|
|
|
case WINED3DSPSM_NOT: break;
|
|
|
|
case WINED3DSPSM_BIAS: TRACE("_bias"); break;
|
|
|
|
case WINED3DSPSM_BIASNEG: TRACE("_bias"); break;
|
|
|
|
case WINED3DSPSM_SIGN: TRACE("_bx2"); break;
|
|
|
|
case WINED3DSPSM_SIGNNEG: TRACE("_bx2"); break;
|
|
|
|
case WINED3DSPSM_COMP: break;
|
|
|
|
case WINED3DSPSM_X2: TRACE("_x2"); break;
|
|
|
|
case WINED3DSPSM_X2NEG: TRACE("_x2"); break;
|
|
|
|
case WINED3DSPSM_DZ: TRACE("_dz"); break;
|
|
|
|
case WINED3DSPSM_DW: TRACE("_dw"); break;
|
|
|
|
case WINED3DSPSM_ABSNEG: TRACE(")"); break;
|
|
|
|
case WINED3DSPSM_ABS: TRACE(")"); break;
|
2006-05-14 15:43:31 +02:00
|
|
|
default:
|
2009-04-22 10:48:34 +02:00
|
|
|
TRACE("_unknown_modifier(%#x)", modifier);
|
2006-05-14 15:43:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* swizzle bits fields:
|
|
|
|
* RRGGBBAA
|
|
|
|
*/
|
2009-04-22 10:48:34 +02:00
|
|
|
if (swizzle != WINED3DSP_NOSWIZZLE)
|
2009-04-22 10:48:34 +02:00
|
|
|
{
|
2008-12-19 19:21:56 +01:00
|
|
|
if (swizzle_x == swizzle_y &&
|
|
|
|
swizzle_x == swizzle_z &&
|
|
|
|
swizzle_x == swizzle_w) {
|
|
|
|
TRACE(".%c", swizzle_reg_chars[swizzle_x]);
|
2006-05-14 15:43:31 +02:00
|
|
|
} else {
|
|
|
|
TRACE(".%c%c%c%c",
|
2008-12-19 19:21:56 +01:00
|
|
|
swizzle_reg_chars[swizzle_x],
|
|
|
|
swizzle_reg_chars[swizzle_y],
|
|
|
|
swizzle_reg_chars[swizzle_z],
|
|
|
|
swizzle_reg_chars[swizzle_w]);
|
2006-05-14 15:43:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-15 12:10:15 +01:00
|
|
|
/* Shared code in order to generate the bulk of the shader string.
|
|
|
|
* NOTE: A description of how to parse tokens can be found on msdn */
|
2008-11-25 14:36:09 +01:00
|
|
|
void shader_generate_main(IWineD3DBaseShader *iface, SHADER_BUFFER* buffer,
|
|
|
|
const shader_reg_maps* reg_maps, CONST DWORD* pFunction)
|
|
|
|
{
|
2006-05-10 04:32:34 +02:00
|
|
|
IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
|
2007-09-21 23:53:57 +02:00
|
|
|
IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device; /* To access shader backend callbacks */
|
2008-12-04 17:41:31 +01:00
|
|
|
const SHADER_OPCODE *opcode_table = This->baseShader.shader_ins;
|
2008-09-23 17:39:34 +02:00
|
|
|
const SHADER_HANDLER *handler_table = device->shader_backend->shader_instruction_handler_table;
|
2008-12-15 12:10:14 +01:00
|
|
|
DWORD shader_version = reg_maps->shader_version;
|
2009-04-17 09:46:56 +02:00
|
|
|
struct wined3d_shader_src_param src_rel_addr[4];
|
2009-04-15 10:06:28 +02:00
|
|
|
struct wined3d_shader_src_param src_param[4];
|
2009-04-17 09:46:56 +02:00
|
|
|
struct wined3d_shader_src_param dst_rel_addr;
|
2009-04-03 10:36:38 +02:00
|
|
|
struct wined3d_shader_dst_param dst_param;
|
2009-04-01 12:23:01 +02:00
|
|
|
struct wined3d_shader_instruction ins;
|
2009-04-15 10:06:28 +02:00
|
|
|
struct wined3d_shader_context ctx;
|
2006-05-10 04:32:34 +02:00
|
|
|
const DWORD *pToken = pFunction;
|
2008-12-15 12:10:15 +01:00
|
|
|
SHADER_HANDLER hw_fct;
|
2006-05-10 04:32:34 +02:00
|
|
|
DWORD i;
|
2006-06-09 09:33:33 +02:00
|
|
|
|
2006-05-10 04:32:34 +02:00
|
|
|
/* Initialize current parsing state */
|
2009-04-15 10:06:28 +02:00
|
|
|
ctx.shader = iface;
|
|
|
|
ctx.reg_maps = reg_maps;
|
|
|
|
ctx.buffer = buffer;
|
|
|
|
|
|
|
|
ins.ctx = &ctx;
|
2009-04-03 10:36:38 +02:00
|
|
|
ins.dst = &dst_param;
|
2009-04-15 10:06:28 +02:00
|
|
|
ins.src = src_param;
|
2006-05-10 04:32:34 +02:00
|
|
|
This->baseShader.parse_state.current_row = 0;
|
|
|
|
|
2009-04-24 09:17:58 +02:00
|
|
|
if (!shader_is_version_token(*pToken++))
|
|
|
|
{
|
|
|
|
ERR("First token is not a version token, invalid shader.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-15 12:10:15 +01:00
|
|
|
while (WINED3DPS_END() != *pToken)
|
|
|
|
{
|
2009-04-24 09:17:58 +02:00
|
|
|
UINT param_size;
|
2009-04-01 12:23:00 +02:00
|
|
|
|
2008-12-15 12:10:15 +01:00
|
|
|
/* Skip comment tokens */
|
|
|
|
if (shader_is_comment(*pToken))
|
|
|
|
{
|
|
|
|
pToken += (*pToken & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
|
|
|
|
++pToken;
|
|
|
|
continue;
|
|
|
|
}
|
2006-05-10 04:32:34 +02:00
|
|
|
|
2008-12-15 12:10:15 +01:00
|
|
|
/* Read opcode */
|
2009-04-24 09:17:58 +02:00
|
|
|
shader_sm1_read_opcode(&pToken, &ins, ¶m_size, opcode_table, shader_version);
|
2006-05-17 08:04:30 +02:00
|
|
|
|
2008-12-15 12:10:15 +01:00
|
|
|
/* Unknown opcode and its parameters */
|
2009-04-24 09:17:58 +02:00
|
|
|
if (ins.handler_idx == WINED3DSIH_TABLE_SIZE)
|
2008-12-15 12:10:15 +01:00
|
|
|
{
|
2009-04-24 09:17:58 +02:00
|
|
|
TRACE("Skipping unrecognized instruction.\n");
|
|
|
|
pToken += param_size;
|
2008-12-15 12:10:15 +01:00
|
|
|
continue;
|
|
|
|
}
|
2006-05-10 04:32:34 +02:00
|
|
|
|
2008-12-15 12:10:15 +01:00
|
|
|
/* Nothing to do */
|
2009-04-24 09:17:58 +02:00
|
|
|
if (ins.handler_idx == WINED3DSIH_DCL
|
|
|
|
|| ins.handler_idx == WINED3DSIH_NOP
|
|
|
|
|| ins.handler_idx == WINED3DSIH_DEF
|
|
|
|
|| ins.handler_idx == WINED3DSIH_DEFI
|
|
|
|
|| ins.handler_idx == WINED3DSIH_DEFB
|
|
|
|
|| ins.handler_idx == WINED3DSIH_PHASE
|
|
|
|
|| ins.handler_idx == WINED3DSIH_RET)
|
2008-12-15 12:10:15 +01:00
|
|
|
{
|
2009-04-24 09:17:58 +02:00
|
|
|
pToken += param_size;
|
2008-12-15 12:10:15 +01:00
|
|
|
continue;
|
|
|
|
}
|
2006-05-17 08:04:30 +02:00
|
|
|
|
2008-12-15 12:10:15 +01:00
|
|
|
/* Select handler */
|
2009-04-24 09:17:58 +02:00
|
|
|
hw_fct = handler_table[ins.handler_idx];
|
2006-05-18 03:09:56 +02:00
|
|
|
|
2008-12-15 12:10:15 +01:00
|
|
|
/* Unhandled opcode */
|
|
|
|
if (!hw_fct)
|
|
|
|
{
|
2009-04-24 09:17:58 +02:00
|
|
|
FIXME("Backend can't handle opcode %#x\n", ins.handler_idx);
|
|
|
|
pToken += param_size;
|
2008-12-15 12:10:15 +01:00
|
|
|
continue;
|
|
|
|
}
|
2006-05-17 08:04:30 +02:00
|
|
|
|
2008-12-15 12:10:15 +01:00
|
|
|
/* Destination token */
|
2009-04-27 09:37:14 +02:00
|
|
|
if (ins.dst_count) shader_sm1_read_dst_param(&pToken, &dst_param, &dst_rel_addr, shader_version);
|
2006-05-10 04:47:35 +02:00
|
|
|
|
2008-12-15 12:10:15 +01:00
|
|
|
/* Predication token */
|
2009-04-24 09:17:58 +02:00
|
|
|
if (ins.predicate) ins.predicate = *pToken++;
|
2007-09-21 23:53:57 +02:00
|
|
|
|
2008-12-15 12:10:15 +01:00
|
|
|
/* Other source tokens */
|
2009-04-02 10:41:00 +02:00
|
|
|
for (i = 0; i < ins.src_count; ++i)
|
2008-12-15 12:10:15 +01:00
|
|
|
{
|
2009-04-27 09:37:14 +02:00
|
|
|
shader_sm1_read_src_param(&pToken, &src_param[i], &src_rel_addr[i], shader_version);
|
2008-12-15 12:10:15 +01:00
|
|
|
}
|
2006-06-14 04:32:14 +02:00
|
|
|
|
2008-12-15 12:10:15 +01:00
|
|
|
/* Call appropriate function for output target */
|
2009-04-01 12:23:01 +02:00
|
|
|
hw_fct(&ins);
|
2006-05-10 04:32:34 +02:00
|
|
|
|
2008-12-15 12:10:15 +01:00
|
|
|
/* Process instruction modifiers for GLSL apps ( _sat, etc. ) */
|
|
|
|
/* FIXME: This should be internal to the shader backend.
|
|
|
|
* Also, right now this is the only reason "shader_mode" exists. */
|
2009-04-01 12:23:01 +02:00
|
|
|
if (This->baseShader.shader_mode == SHADER_GLSL) shader_glsl_add_instruction_modifiers(&ins);
|
2006-05-10 04:32:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-02 18:41:33 +01:00
|
|
|
static void shader_dump_ins_modifiers(const DWORD output)
|
|
|
|
{
|
2006-10-10 01:48:12 +02:00
|
|
|
DWORD shift = (output & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT;
|
|
|
|
DWORD mmask = output & WINED3DSP_DSTMOD_MASK;
|
2006-05-10 19:53:07 +02:00
|
|
|
|
|
|
|
switch (shift) {
|
|
|
|
case 0: break;
|
|
|
|
case 13: TRACE("_d8"); break;
|
|
|
|
case 14: TRACE("_d4"); break;
|
|
|
|
case 15: TRACE("_d2"); break;
|
|
|
|
case 1: TRACE("_x2"); break;
|
|
|
|
case 2: TRACE("_x4"); break;
|
|
|
|
case 3: TRACE("_x8"); break;
|
2006-10-01 05:20:10 +02:00
|
|
|
default: TRACE("_unhandled_shift(%d)", shift); break;
|
2006-05-10 19:53:07 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:48:12 +02:00
|
|
|
if (mmask & WINED3DSPDM_SATURATE) TRACE("_sat");
|
|
|
|
if (mmask & WINED3DSPDM_PARTIALPRECISION) TRACE("_pp");
|
|
|
|
if (mmask & WINED3DSPDM_MSAMPCENTROID) TRACE("_centroid");
|
2006-05-17 07:58:19 +02:00
|
|
|
|
2006-10-10 01:48:12 +02:00
|
|
|
mmask &= ~(WINED3DSPDM_SATURATE | WINED3DSPDM_PARTIALPRECISION | WINED3DSPDM_MSAMPCENTROID);
|
2006-05-17 07:58:19 +02:00
|
|
|
if (mmask)
|
2009-04-23 09:24:26 +02:00
|
|
|
FIXME("_unrecognized_modifier(%#x)", mmask);
|
2006-05-10 19:53:07 +02:00
|
|
|
}
|
|
|
|
|
2008-12-11 11:52:37 +01:00
|
|
|
void shader_trace_init(const DWORD *pFunction, const SHADER_OPCODE *opcode_table)
|
|
|
|
{
|
2006-06-12 08:54:30 +02:00
|
|
|
const DWORD* pToken = pFunction;
|
2008-12-11 11:52:37 +01:00
|
|
|
DWORD shader_version;
|
2006-06-12 08:54:30 +02:00
|
|
|
DWORD i;
|
|
|
|
|
2008-12-11 11:52:37 +01:00
|
|
|
TRACE("Parsing %p\n", pFunction);
|
2006-06-12 08:54:30 +02:00
|
|
|
|
2008-12-11 11:52:37 +01:00
|
|
|
/* The version token is supposed to be the first token */
|
|
|
|
if (!shader_is_version_token(*pToken))
|
|
|
|
{
|
|
|
|
FIXME("First token is not a version token, invalid shader.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
shader_version = *pToken++;
|
|
|
|
TRACE("%s_%u_%u\n", shader_is_pshader_version(shader_version) ? "ps": "vs",
|
|
|
|
WINED3DSHADER_VERSION_MAJOR(shader_version), WINED3DSHADER_VERSION_MINOR(shader_version));
|
|
|
|
|
2008-12-08 10:30:02 +01:00
|
|
|
while (WINED3DVS_END() != *pToken)
|
|
|
|
{
|
2009-04-27 09:37:14 +02:00
|
|
|
struct wined3d_shader_instruction ins;
|
|
|
|
UINT param_size;
|
|
|
|
|
2008-12-08 10:30:02 +01:00
|
|
|
if (shader_is_comment(*pToken)) /* comment */
|
|
|
|
{
|
|
|
|
DWORD comment_len = (*pToken & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
|
|
|
|
++pToken;
|
|
|
|
TRACE("//%s\n", (const char*)pToken);
|
|
|
|
pToken += comment_len;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
shader_sm1_read_opcode(&pToken, &ins, ¶m_size, opcode_table, shader_version);
|
|
|
|
if (ins.handler_idx == WINED3DSIH_TABLE_SIZE)
|
2008-12-08 10:30:02 +01:00
|
|
|
{
|
2009-04-27 09:37:14 +02:00
|
|
|
TRACE("Skipping unrecognized instruction.\n");
|
|
|
|
pToken += param_size;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ins.handler_idx == WINED3DSIH_DCL)
|
|
|
|
{
|
|
|
|
DWORD usage = *pToken;
|
|
|
|
DWORD param = *(pToken + 1);
|
|
|
|
|
|
|
|
shader_dump_decl_usage(usage, param, shader_version);
|
|
|
|
shader_dump_ins_modifiers(param);
|
|
|
|
TRACE(" ");
|
|
|
|
shader_dump_param(param, 0, 0, shader_version);
|
|
|
|
pToken += 2;
|
|
|
|
}
|
|
|
|
else if (ins.handler_idx == WINED3DSIH_DEF)
|
|
|
|
{
|
|
|
|
unsigned int offset = shader_get_float_offset(*pToken);
|
|
|
|
|
|
|
|
TRACE("def c%u = %f, %f, %f, %f", offset,
|
|
|
|
*(const float *)(pToken + 1),
|
|
|
|
*(const float *)(pToken + 2),
|
|
|
|
*(const float *)(pToken + 3),
|
|
|
|
*(const float *)(pToken + 4));
|
|
|
|
pToken += 5;
|
|
|
|
}
|
|
|
|
else if (ins.handler_idx == WINED3DSIH_DEFI)
|
|
|
|
{
|
|
|
|
TRACE("defi i%u = %d, %d, %d, %d", *pToken & WINED3DSP_REGNUM_MASK,
|
|
|
|
*(pToken + 1),
|
|
|
|
*(pToken + 2),
|
|
|
|
*(pToken + 3),
|
|
|
|
*(pToken + 4));
|
|
|
|
pToken += 5;
|
|
|
|
}
|
|
|
|
else if (ins.handler_idx == WINED3DSIH_DEFB)
|
|
|
|
{
|
|
|
|
TRACE("defb b%u = %s", *pToken & WINED3DSP_REGNUM_MASK,
|
|
|
|
*(pToken + 1)? "true": "false");
|
|
|
|
pToken += 2;
|
2008-12-08 10:30:02 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-27 09:37:14 +02:00
|
|
|
DWORD param, addr_token = 0;
|
|
|
|
int tokens_read;
|
2008-12-08 10:30:02 +01:00
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
/* Print out predication source token first - it follows
|
|
|
|
* the destination token. */
|
|
|
|
if (ins.predicate)
|
2008-12-08 10:30:02 +01:00
|
|
|
{
|
2009-04-27 09:37:14 +02:00
|
|
|
TRACE("(");
|
|
|
|
shader_dump_param(*(pToken + 2), 0, 1, shader_version);
|
|
|
|
TRACE(") ");
|
2008-12-08 10:30:02 +01:00
|
|
|
}
|
2006-06-12 08:54:30 +02:00
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
/* PixWin marks instructions with the coissue flag with a '+' */
|
|
|
|
if (ins.coissue) TRACE("+");
|
2008-12-08 10:30:02 +01:00
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
TRACE("%s", shader_opcode_names[ins.handler_idx]);
|
2008-12-08 10:30:02 +01:00
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
if (ins.handler_idx == WINED3DSIH_IFC
|
|
|
|
|| ins.handler_idx == WINED3DSIH_BREAKC)
|
|
|
|
{
|
|
|
|
switch (ins.flags)
|
2008-12-08 10:30:02 +01:00
|
|
|
{
|
2009-04-27 09:37:14 +02:00
|
|
|
case COMPARISON_GT: TRACE("_gt"); break;
|
|
|
|
case COMPARISON_EQ: TRACE("_eq"); break;
|
|
|
|
case COMPARISON_GE: TRACE("_ge"); break;
|
|
|
|
case COMPARISON_LT: TRACE("_lt"); break;
|
|
|
|
case COMPARISON_NE: TRACE("_ne"); break;
|
|
|
|
case COMPARISON_LE: TRACE("_le"); break;
|
|
|
|
default: TRACE("_(%u)", ins.flags);
|
2008-12-08 10:30:02 +01:00
|
|
|
}
|
2009-04-27 09:37:14 +02:00
|
|
|
}
|
|
|
|
else if (ins.handler_idx == WINED3DSIH_TEX
|
|
|
|
&& shader_version >= WINED3DPS_VERSION(2,0)
|
|
|
|
&& (ins.flags & WINED3DSI_TEXLD_PROJECT))
|
|
|
|
{
|
|
|
|
TRACE("p");
|
|
|
|
}
|
2006-06-12 12:57:04 +02:00
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
/* Destination token */
|
|
|
|
if (ins.dst_count)
|
|
|
|
{
|
|
|
|
tokens_read = shader_get_param(pToken, shader_version, ¶m, &addr_token);
|
|
|
|
pToken += tokens_read;
|
2006-06-12 12:57:04 +02:00
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
shader_dump_ins_modifiers(param);
|
|
|
|
TRACE(" ");
|
|
|
|
shader_dump_param(param, addr_token, 0, shader_version);
|
|
|
|
}
|
2006-06-12 12:57:04 +02:00
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
/* Predication token - already printed out, just skip it */
|
|
|
|
if (ins.predicate) ++pToken;
|
2006-06-12 08:54:30 +02:00
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
/* Other source tokens */
|
|
|
|
for (i = ins.dst_count; i < (ins.dst_count + ins.src_count); ++i)
|
|
|
|
{
|
|
|
|
tokens_read = shader_get_param(pToken, shader_version, ¶m, &addr_token);
|
|
|
|
pToken += tokens_read;
|
2008-12-08 10:30:02 +01:00
|
|
|
|
2009-04-27 09:37:14 +02:00
|
|
|
TRACE((i == 0)? " " : ", ");
|
|
|
|
shader_dump_param(param, addr_token, 1, shader_version);
|
2006-06-12 08:54:30 +02:00
|
|
|
}
|
|
|
|
}
|
2009-04-27 09:37:14 +02:00
|
|
|
TRACE("\n");
|
2006-06-12 08:54:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-09 09:52:39 +01:00
|
|
|
void shader_cleanup(IWineD3DBaseShader *iface)
|
|
|
|
{
|
|
|
|
IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)iface;
|
|
|
|
|
|
|
|
((IWineD3DDeviceImpl *)This->baseShader.device)->shader_backend->shader_destroy(iface);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->baseShader.function);
|
|
|
|
shader_delete_constant_list(&This->baseShader.constantsF);
|
|
|
|
shader_delete_constant_list(&This->baseShader.constantsB);
|
|
|
|
shader_delete_constant_list(&This->baseShader.constantsI);
|
|
|
|
list_remove(&This->baseShader.shader_list_entry);
|
|
|
|
}
|
|
|
|
|
2008-09-23 17:39:34 +02:00
|
|
|
static const SHADER_HANDLER shader_none_instruction_handler_table[WINED3DSIH_TABLE_SIZE] = {0};
|
2006-11-27 20:50:37 +01:00
|
|
|
static void shader_none_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {}
|
2008-10-27 18:31:31 +01:00
|
|
|
static void shader_none_select_depth_blt(IWineD3DDevice *iface, enum tex_types tex_type) {}
|
2008-07-10 17:57:35 +02:00
|
|
|
static void shader_none_deselect_depth_blt(IWineD3DDevice *iface) {}
|
2008-12-17 17:07:25 +01:00
|
|
|
static void shader_none_update_float_vertex_constants(IWineD3DDevice *iface, UINT start, UINT count) {}
|
|
|
|
static void shader_none_update_float_pixel_constants(IWineD3DDevice *iface, UINT start, UINT count) {}
|
2006-11-27 20:50:37 +01:00
|
|
|
static void shader_none_load_constants(IWineD3DDevice *iface, char usePS, char useVS) {}
|
2009-04-09 00:55:38 +02:00
|
|
|
static void shader_none_load_np2fixup_constants(IWineD3DDevice *iface, char usePS, char useVS) {}
|
2007-11-20 17:40:54 +01:00
|
|
|
static void shader_none_destroy(IWineD3DBaseShader *iface) {}
|
2008-02-24 11:23:53 +01:00
|
|
|
static HRESULT shader_none_alloc(IWineD3DDevice *iface) {return WINED3D_OK;}
|
|
|
|
static void shader_none_free(IWineD3DDevice *iface) {}
|
2008-03-04 02:30:23 +01:00
|
|
|
static BOOL shader_none_dirty_const(IWineD3DDevice *iface) {return FALSE;}
|
2008-12-14 15:40:07 +01:00
|
|
|
static GLuint shader_none_generate_pshader(IWineD3DPixelShader *iface, SHADER_BUFFER *buffer, const struct ps_compile_args *args) {
|
2008-03-18 19:19:16 +01:00
|
|
|
FIXME("NONE shader backend asked to generate a pixel shader\n");
|
2008-11-24 11:55:50 +01:00
|
|
|
return 0;
|
2008-03-18 19:19:16 +01:00
|
|
|
}
|
2009-02-05 19:44:32 +01:00
|
|
|
static GLuint shader_none_generate_vshader(IWineD3DVertexShader *iface, SHADER_BUFFER *buffer, const struct vs_compile_args *args) {
|
2008-03-18 19:19:16 +01:00
|
|
|
FIXME("NONE shader backend asked to generate a vertex shader\n");
|
2009-02-05 19:44:32 +01:00
|
|
|
return 0;
|
2008-03-18 19:19:16 +01:00
|
|
|
}
|
2006-11-27 20:50:37 +01:00
|
|
|
|
2008-03-18 19:39:26 +01:00
|
|
|
#define GLINFO_LOCATION (*gl_info)
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_none_get_caps(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct shader_caps *pCaps)
|
|
|
|
{
|
2008-03-22 14:27:53 +01:00
|
|
|
/* Set the shader caps to 0 for the none shader backend */
|
|
|
|
pCaps->VertexShaderVersion = 0;
|
|
|
|
pCaps->PixelShaderVersion = 0;
|
|
|
|
pCaps->PixelShader1xMaxValue = 0.0;
|
2008-03-18 19:39:26 +01:00
|
|
|
}
|
|
|
|
#undef GLINFO_LOCATION
|
2008-12-03 14:53:43 +01:00
|
|
|
static BOOL shader_none_color_fixup_supported(struct color_fixup_desc fixup)
|
|
|
|
{
|
|
|
|
if (TRACE_ON(d3d_shader) && TRACE_ON(d3d))
|
|
|
|
{
|
|
|
|
TRACE("Checking support for fixup:\n");
|
|
|
|
dump_color_fixup_desc(fixup);
|
2008-08-07 21:51:35 +02:00
|
|
|
}
|
2008-12-03 14:53:43 +01:00
|
|
|
|
|
|
|
/* Faked to make some apps happy. */
|
|
|
|
if (!is_yuv_fixup(fixup))
|
|
|
|
{
|
|
|
|
TRACE("[OK]\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("[FAILED]\n");
|
|
|
|
return FALSE;
|
2008-08-07 21:51:35 +02:00
|
|
|
}
|
2008-03-18 19:39:26 +01:00
|
|
|
|
2006-11-27 20:50:37 +01:00
|
|
|
const shader_backend_t none_shader_backend = {
|
2008-09-23 17:39:34 +02:00
|
|
|
shader_none_instruction_handler_table,
|
2008-07-06 14:00:52 +02:00
|
|
|
shader_none_select,
|
|
|
|
shader_none_select_depth_blt,
|
2008-07-10 17:57:35 +02:00
|
|
|
shader_none_deselect_depth_blt,
|
2008-12-17 17:07:25 +01:00
|
|
|
shader_none_update_float_vertex_constants,
|
|
|
|
shader_none_update_float_pixel_constants,
|
2008-07-06 14:00:52 +02:00
|
|
|
shader_none_load_constants,
|
2009-04-09 00:55:38 +02:00
|
|
|
shader_none_load_np2fixup_constants,
|
2008-07-06 14:00:52 +02:00
|
|
|
shader_none_destroy,
|
|
|
|
shader_none_alloc,
|
|
|
|
shader_none_free,
|
|
|
|
shader_none_dirty_const,
|
|
|
|
shader_none_generate_pshader,
|
|
|
|
shader_none_generate_vshader,
|
|
|
|
shader_none_get_caps,
|
2008-12-03 14:53:43 +01:00
|
|
|
shader_none_color_fixup_supported,
|
2006-11-27 20:50:37 +01:00
|
|
|
};
|