shader_sm1.c revision d200be7337d4aad2bec2961a885e856f7866d4f6
/*
* Copyright 2002-2003 Jason Edmeades
* Copyright 2002-2003 Raphael Junqueira
* Copyright 2004 Christian Costa
* Copyright 2005 Oliver Stieber
* Copyright 2006 Ivan Gyurdiev
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
* Copyright 2009 Henri Verbeet for CodeWeavers
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Oracle elects to use only
* the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
* a choice of LGPL license versions is made available with the language indicating
* that LGPLv2 or any later version may be used, or where a choice of which version
* of the LGPL is applied is otherwise unspecified.
*/
#include "config.h"
#include "wined3d_private.h"
/* DCL usage masks */
#define WINED3DSP_DCL_USAGE_SHIFT 0
#define WINED3DSP_DCL_USAGEINDEX_SHIFT 16
/* DCL sampler type */
#define WINED3DSP_TEXTURETYPE_SHIFT 27
/* Opcode-related masks */
#define WINED3DSI_OPCODE_MASK 0x0000ffff
#define WINED3D_OPCODESPECIFICCONTROL_SHIFT 16
#define WINED3DSI_INSTLENGTH_SHIFT 24
#define WINED3DSI_COMMENTSIZE_SHIFT 16
/* Register number mask */
#define WINED3DSP_REGNUM_MASK 0x000007ff
/* Register type masks */
#define WINED3DSP_REGTYPE_SHIFT 28
#define WINED3DSP_REGTYPE_SHIFT2 8
/* Relative addressing mask */
#define WINED3DSHADER_ADDRESSMODE_SHIFT 13
/* Destination modifier mask */
#define WINED3DSP_DSTMOD_SHIFT 20
/* Destination shift mask */
#define WINED3DSP_DSTSHIFT_SHIFT 24
/* Write mask */
#define WINED3D_SM1_WRITEMASK_SHIFT 16
/* Swizzle mask */
#define WINED3DSP_SWIZZLE_SHIFT 16
/* Source modifier mask */
#define WINED3DSP_SRCMOD_SHIFT 24
#define WINED3DSP_END 0x0000ffff
{
};
enum wined3d_sm1_opcode
{
WINED3D_SM1_OP_NOP = 0x00,
WINED3D_SM1_OP_MOV = 0x01,
WINED3D_SM1_OP_ADD = 0x02,
WINED3D_SM1_OP_SUB = 0x03,
WINED3D_SM1_OP_MAD = 0x04,
WINED3D_SM1_OP_MUL = 0x05,
WINED3D_SM1_OP_RCP = 0x06,
WINED3D_SM1_OP_RSQ = 0x07,
WINED3D_SM1_OP_DP3 = 0x08,
WINED3D_SM1_OP_DP4 = 0x09,
WINED3D_SM1_OP_MIN = 0x0a,
WINED3D_SM1_OP_MAX = 0x0b,
WINED3D_SM1_OP_SLT = 0x0c,
WINED3D_SM1_OP_SGE = 0x0d,
WINED3D_SM1_OP_EXP = 0x0e,
WINED3D_SM1_OP_LOG = 0x0f,
WINED3D_SM1_OP_LIT = 0x10,
WINED3D_SM1_OP_DST = 0x11,
WINED3D_SM1_OP_LRP = 0x12,
WINED3D_SM1_OP_FRC = 0x13,
WINED3D_SM1_OP_M4x4 = 0x14,
WINED3D_SM1_OP_M4x3 = 0x15,
WINED3D_SM1_OP_M3x4 = 0x16,
WINED3D_SM1_OP_M3x3 = 0x17,
WINED3D_SM1_OP_M3x2 = 0x18,
WINED3D_SM1_OP_CALL = 0x19,
WINED3D_SM1_OP_CALLNZ = 0x1a,
WINED3D_SM1_OP_LOOP = 0x1b,
WINED3D_SM1_OP_RET = 0x1c,
WINED3D_SM1_OP_ENDLOOP = 0x1d,
WINED3D_SM1_OP_LABEL = 0x1e,
WINED3D_SM1_OP_DCL = 0x1f,
WINED3D_SM1_OP_POW = 0x20,
WINED3D_SM1_OP_CRS = 0x21,
WINED3D_SM1_OP_SGN = 0x22,
WINED3D_SM1_OP_ABS = 0x23,
WINED3D_SM1_OP_NRM = 0x24,
WINED3D_SM1_OP_SINCOS = 0x25,
WINED3D_SM1_OP_REP = 0x26,
WINED3D_SM1_OP_ENDREP = 0x27,
WINED3D_SM1_OP_IF = 0x28,
WINED3D_SM1_OP_IFC = 0x29,
WINED3D_SM1_OP_ELSE = 0x2a,
WINED3D_SM1_OP_ENDIF = 0x2b,
WINED3D_SM1_OP_BREAK = 0x2c,
WINED3D_SM1_OP_BREAKC = 0x2d,
WINED3D_SM1_OP_MOVA = 0x2e,
WINED3D_SM1_OP_DEFB = 0x2f,
WINED3D_SM1_OP_DEFI = 0x30,
WINED3D_SM1_OP_TEXCOORD = 0x40,
WINED3D_SM1_OP_TEXKILL = 0x41,
WINED3D_SM1_OP_TEX = 0x42,
WINED3D_SM1_OP_TEXBEM = 0x43,
WINED3D_SM1_OP_TEXBEML = 0x44,
WINED3D_SM1_OP_TEXREG2AR = 0x45,
WINED3D_SM1_OP_TEXREG2GB = 0x46,
WINED3D_SM1_OP_TEXM3x2PAD = 0x47,
WINED3D_SM1_OP_TEXM3x2TEX = 0x48,
WINED3D_SM1_OP_TEXM3x3PAD = 0x49,
WINED3D_SM1_OP_TEXM3x3TEX = 0x4a,
WINED3D_SM1_OP_TEXM3x3DIFF = 0x4b,
WINED3D_SM1_OP_TEXM3x3SPEC = 0x4c,
WINED3D_SM1_OP_TEXM3x3VSPEC = 0x4d,
WINED3D_SM1_OP_EXPP = 0x4e,
WINED3D_SM1_OP_LOGP = 0x4f,
WINED3D_SM1_OP_CND = 0x50,
WINED3D_SM1_OP_DEF = 0x51,
WINED3D_SM1_OP_TEXREG2RGB = 0x52,
WINED3D_SM1_OP_TEXDP3TEX = 0x53,
WINED3D_SM1_OP_TEXM3x2DEPTH = 0x54,
WINED3D_SM1_OP_TEXDP3 = 0x55,
WINED3D_SM1_OP_TEXM3x3 = 0x56,
WINED3D_SM1_OP_TEXDEPTH = 0x57,
WINED3D_SM1_OP_CMP = 0x58,
WINED3D_SM1_OP_BEM = 0x59,
WINED3D_SM1_OP_DP2ADD = 0x5a,
WINED3D_SM1_OP_DSX = 0x5b,
WINED3D_SM1_OP_DSY = 0x5c,
WINED3D_SM1_OP_TEXLDD = 0x5d,
WINED3D_SM1_OP_SETP = 0x5e,
WINED3D_SM1_OP_TEXLDL = 0x5f,
WINED3D_SM1_OP_BREAKP = 0x60,
WINED3D_SM1_OP_PHASE = 0xfffd,
WINED3D_SM1_OP_COMMENT = 0xfffe,
WINED3D_SM1_OP_END = 0Xffff,
};
struct wined3d_sm1_opcode_info
{
enum wined3d_sm1_opcode opcode;
};
struct wined3d_sm1_data
{
struct wined3d_shader_version shader_version;
const struct wined3d_sm1_opcode_info *opcode_table;
};
/* This table is not order or position dependent. */
static const struct wined3d_sm1_opcode_info vs_opcode_table[] =
{
/* Arithmetic */
{WINED3D_SM1_OP_NOP, 0, 0, WINED3DSIH_NOP, 0, 0 },
#ifdef VBOX_WITH_VMSVGA /* appears incorrect */
#else
{WINED3D_SM1_OP_SGN, 1, 4, WINED3DSIH_SGN, WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
#endif
{WINED3D_SM1_OP_SINCOS, 1, 4, WINED3DSIH_SINCOS, WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
/* Matrix */
/* Declare registers */
/* Constant definitions */
/* Flow control */
{0, 0, 0, WINED3DSIH_TABLE_SIZE, 0, 0 },
};
static const struct wined3d_sm1_opcode_info ps_opcode_table[] =
{
/* Arithmetic */
{WINED3D_SM1_OP_NOP, 0, 0, WINED3DSIH_NOP, 0, 0 },
{WINED3D_SM1_OP_CND, 1, 4, WINED3DSIH_CND, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,4)},
{WINED3D_SM1_OP_CMP, 1, 4, WINED3DSIH_CMP, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(3,0)},
{WINED3D_SM1_OP_SINCOS, 1, 4, WINED3DSIH_SINCOS, WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
/* Matrix */
/* Register declarations */
/* Flow control */
/* Constant definitions */
/* Texture */
{WINED3D_SM1_OP_TEXCOORD, 1, 2, WINED3DSIH_TEXCOORD, WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
{WINED3D_SM1_OP_TEXKILL, 1, 1, WINED3DSIH_TEXKILL, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(3,0)},
{WINED3D_SM1_OP_TEX, 1, 2, WINED3DSIH_TEX, WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
{WINED3D_SM1_OP_TEXBEML, 1, 2, WINED3DSIH_TEXBEML, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
{WINED3D_SM1_OP_TEXREG2AR, 1, 2, WINED3DSIH_TEXREG2AR, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
{WINED3D_SM1_OP_TEXREG2GB, 1, 2, WINED3DSIH_TEXREG2GB, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
{WINED3D_SM1_OP_TEXREG2RGB, 1, 2, WINED3DSIH_TEXREG2RGB, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
{WINED3D_SM1_OP_TEXM3x2PAD, 1, 2, WINED3DSIH_TEXM3x2PAD, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
{WINED3D_SM1_OP_TEXM3x2TEX, 1, 2, WINED3DSIH_TEXM3x2TEX, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
{WINED3D_SM1_OP_TEXM3x3PAD, 1, 2, WINED3DSIH_TEXM3x3PAD, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
{WINED3D_SM1_OP_TEXM3x3DIFF, 1, 2, WINED3DSIH_TEXM3x3DIFF, WINED3D_SHADER_VERSION(0,0), WINED3D_SHADER_VERSION(0,0)},
{WINED3D_SM1_OP_TEXM3x3SPEC, 1, 3, WINED3DSIH_TEXM3x3SPEC, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
{WINED3D_SM1_OP_TEXM3x3VSPEC, 1, 2, WINED3DSIH_TEXM3x3VSPEC, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
{WINED3D_SM1_OP_TEXM3x3TEX, 1, 2, WINED3DSIH_TEXM3x3TEX, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
{WINED3D_SM1_OP_TEXDP3TEX, 1, 2, WINED3DSIH_TEXDP3TEX, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
{WINED3D_SM1_OP_TEXM3x2DEPTH, 1, 2, WINED3DSIH_TEXM3x2DEPTH, WINED3D_SHADER_VERSION(1,3), WINED3D_SHADER_VERSION(1,3)},
{WINED3D_SM1_OP_TEXDP3, 1, 2, WINED3DSIH_TEXDP3, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
{WINED3D_SM1_OP_TEXM3x3, 1, 2, WINED3DSIH_TEXM3x3, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
{WINED3D_SM1_OP_TEXDEPTH, 1, 1, WINED3DSIH_TEXDEPTH, WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
{WINED3D_SM1_OP_BEM, 1, 3, WINED3DSIH_BEM, WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
{WINED3D_SM1_OP_PHASE, 0, 0, WINED3DSIH_PHASE, 0, 0 },
{0, 0, 0, WINED3DSIH_TABLE_SIZE, 0, 0 },
};
/* 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 struct wined3d_sm1_data *priv, const DWORD *ptr, DWORD *token, DWORD *addr_token)
{
/* 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)
{
{
}
else
{
++count;
}
}
return count;
}
static const struct wined3d_sm1_opcode_info *shader_get_opcode(const struct wined3d_sm1_data *priv, DWORD code)
{
DWORD shader_version = WINED3D_SHADER_VERSION(priv->shader_version.major, priv->shader_version.minor);
DWORD i = 0;
{
{
return &opcode_table[i];
}
++i;
}
FIXME("Unsupported opcode %#x(%d) masked %#x, shader version %#x\n",
return NULL;
}
/* Return the number of parameters to skip for an opcode */
{
/* 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 */
? ((opcode_token & WINED3DSI_INSTLENGTH_MASK) >> WINED3DSI_INSTLENGTH_SHIFT) : opcode_info->param_count;
}
struct wined3d_shader_src_param *src)
{
}
struct wined3d_shader_dst_param *dst)
{
}
/* 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 */
{
int tokens_read = 0;
int i = 0;
/* TODO: Think of a good name for 0x80000000 and replace it with a constant */
while (*ptr & 0x80000000)
{
struct wined3d_shader_src_param rel_addr;
ptr += tokens_read;
if (!i)
{
struct wined3d_shader_dst_param dst;
}
else
{
struct wined3d_shader_src_param src;
}
FIXME("\n");
++i;
}
return tokens_read;
}
static void *shader_sm1_init(const DWORD *byte_code, const struct wined3d_shader_signature *output_signature)
{
struct wined3d_sm1_data *priv;
{
return NULL;
}
if (!priv)
{
ERR("Failed to allocate private data\n");
return NULL;
}
if (output_signature)
{
FIXME("SM 1-3 shader shouldn't have output signatures.\n");
}
switch (*byte_code >> 16)
{
case WINED3D_SM1_VS:
break;
case WINED3D_SM1_PS:
break;
default:
return NULL;
}
return priv;
}
static void shader_sm1_free(void *data)
{
}
static void shader_sm1_read_header(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version)
{
version_token = *(*ptr)++;
}
static void shader_sm1_read_opcode(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins,
{
const struct wined3d_sm1_opcode_info *opcode_info;
opcode_token = *(*ptr)++;
if (!opcode_info)
{
return;
}
ins->flags = (opcode_token & WINED3D_OPCODESPECIFICCONTROL_MASK) >> WINED3D_OPCODESPECIFICCONTROL_SHIFT;
}
static void shader_sm1_read_src_param(void *data, const DWORD **ptr, struct wined3d_shader_src_param *src_param,
struct wined3d_shader_src_param *src_rel_addr)
{
{
}
else
{
}
}
static void shader_sm1_read_dst_param(void *data, const DWORD **ptr, struct wined3d_shader_dst_param *dst_param,
struct wined3d_shader_src_param *dst_rel_addr)
{
{
}
else
{
}
}
{
semantic->usage_idx = (usage_token & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
}
{
{
return;
}
}
{
if (**ptr == WINED3DSP_END)
{
++(*ptr);
return TRUE;
}
return FALSE;
}
const struct wined3d_shader_frontend sm1_shader_frontend =
{
};