058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/*
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2002-2003 Jason Edmeades
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2002-2003 Raphael Junqueira
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2004 Christian Costa
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2005 Oliver Stieber
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2006 Ivan Gyurdiev
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2007-2008, 2013 Stefan Dösinger for CodeWeavers
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2009-2011 Henri Verbeet for CodeWeavers
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * This library is free software; you can redistribute it and/or
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * modify it under the terms of the GNU Lesser General Public
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * License as published by the Free Software Foundation; either
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * version 2.1 of the License, or (at your option) any later version.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * This library is distributed in the hope that it will be useful,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * but WITHOUT ANY WARRANTY; without even the implied warranty of
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Lesser General Public License for more details.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * You should have received a copy of the GNU Lesser General Public
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * License along with this library; if not, write to the Free Software
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync/*
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * a choice of LGPL license versions is made available with the language indicating
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * that LGPLv2 or any later version may be used, or where a choice of which version
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * of the LGPL is applied is otherwise unspecified.
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync */
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include "config.h"
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include "wine/port.h"
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include <math.h>
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include <stdio.h>
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include <string.h>
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include "wined3d_private.h"
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncWINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WINE_WITH_SHADER_CACHE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_chache_put(PVBOXEXT_HASHCACHE pCache, struct wined3d_shader *shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync/* pow, mul_high, sub_high, mul_low */
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncconst float wined3d_srgb_const0[] = {0.41666f, 1.055f, 0.055f, 12.92f};
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync/* cmp */
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncconst float wined3d_srgb_const1[] = {0.0031308f, 0.0f, 0.0f, 0.0f};
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic const char * const shader_opcode_names[] =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_ABS */ "abs",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_ADD */ "add",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_AND */ "and",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_BEM */ "bem",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_BREAK */ "break",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_BREAKC */ "breakc",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_BREAKP */ "breakp",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_CALL */ "call",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_CALLNZ */ "callnz",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_CMP */ "cmp",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_CND */ "cnd",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_CRS */ "crs",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_CUT */ "cut",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DCL */ "dcl",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DCL_CONSTANT_BUFFER */ "dcl_constantBuffer",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DCL_INPUT_PRIMITIVE */ "dcl_inputPrimitive",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DCL_OUTPUT_TOPOLOGY */ "dcl_outputTopology",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DCL_VERTICES_OUT */ "dcl_maxOutputVertexCount",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DEF */ "def",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DEFB */ "defb",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DEFI */ "defi",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DIV */ "div",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DP2ADD */ "dp2add",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DP3 */ "dp3",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DP4 */ "dp4",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DST */ "dst",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DSX */ "dsx",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_DSY */ "dsy",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_ELSE */ "else",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_EMIT */ "emit",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_ENDIF */ "endif",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_ENDLOOP */ "endloop",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_ENDREP */ "endrep",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_EQ */ "eq",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_EXP */ "exp",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_EXPP */ "expp",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_FRC */ "frc",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_FTOI */ "ftoi",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_GE */ "ge",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_IADD */ "iadd",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_IEQ */ "ieq",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_IF */ "if",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_IFC */ "ifc",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_IGE */ "ige",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_IMUL */ "imul",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_ITOF */ "itof",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_LABEL */ "label",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_LD */ "ld",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_LIT */ "lit",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_LOG */ "log",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_LOGP */ "logp",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_LOOP */ "loop",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_LRP */ "lrp",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_LT */ "lt",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_M3x2 */ "m3x2",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_M3x3 */ "m3x3",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_M3x4 */ "m3x4",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_M4x3 */ "m4x3",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_M4x4 */ "m4x4",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_MAD */ "mad",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_MAX */ "max",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_MIN */ "min",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_MOV */ "mov",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_MOVA */ "mova",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_MOVC */ "movc",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_MUL */ "mul",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_NOP */ "nop",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_NRM */ "nrm",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_PHASE */ "phase",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_POW */ "pow",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_RCP */ "rcp",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_REP */ "rep",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_RET */ "ret",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_ROUND_NI */ "round_ni",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_RSQ */ "rsq",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_SAMPLE */ "sample",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_SAMPLE_GRAD */ "sample_d",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_SAMPLE_LOD */ "sample_l",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_SETP */ "setp",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_SGE */ "sge",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_SGN */ "sgn",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_SINCOS */ "sincos",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_SLT */ "slt",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_SQRT */ "sqrt",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_SUB */ "sub",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEX */ "texld",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXBEM */ "texbem",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXBEML */ "texbeml",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXCOORD */ "texcrd",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXDEPTH */ "texdepth",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXDP3 */ "texdp3",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXDP3TEX */ "texdp3tex",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXKILL */ "texkill",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXLDD */ "texldd",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXLDL */ "texldl",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXM3x2DEPTH */ "texm3x2depth",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXM3x2PAD */ "texm3x2pad",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXM3x2TEX */ "texm3x2tex",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXM3x3 */ "texm3x3",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXM3x3DIFF */ "texm3x3diff",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXM3x3PAD */ "texm3x3pad",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXM3x3SPEC */ "texm3x3spec",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXM3x3TEX */ "texm3x3tex",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXM3x3VSPEC */ "texm3x3vspec",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXREG2AR */ "texreg2ar",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXREG2GB */ "texreg2gb",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_TEXREG2RGB */ "texreg2rgb",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_UDIV */ "udiv",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_USHR */ "ushr",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_UTOF */ "utof",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSIH_XOR */ "xor",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic const char * const semantic_names[] =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3D_DECL_USAGE_POSITION */ "SV_POSITION",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3D_DECL_USAGE_BLEND_WEIGHT */ "BLENDWEIGHT",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3D_DECL_USAGE_BLEND_INDICES */ "BLENDINDICES",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3D_DECL_USAGE_NORMAL */ "NORMAL",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3D_DECL_USAGE_PSIZE */ "PSIZE",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3D_DECL_USAGE_TEXCOORD */ "TEXCOORD",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3D_DECL_USAGE_TANGENT */ "TANGENT",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3D_DECL_USAGE_BINORMAL */ "BINORMAL",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3D_DECL_USAGE_TESS_FACTOR */ "TESSFACTOR",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3D_DECL_USAGE_POSITIONT */ "POSITIONT",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3D_DECL_USAGE_COLOR */ "COLOR",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3D_DECL_USAGE_FOG */ "FOG",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3D_DECL_USAGE_DEPTH */ "DEPTH",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3D_DECL_USAGE_SAMPLE */ "SAMPLE",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic const char *shader_semantic_name_from_usage(enum wined3d_decl_usage usage)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (usage >= sizeof(semantic_names) / sizeof(*semantic_names))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unrecognized usage %#x.\n", usage);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return "UNRECOGNIZED";
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return semantic_names[usage];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic enum wined3d_decl_usage shader_usage_from_semantic_name(const char *name)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < sizeof(semantic_names) / sizeof(*semantic_names); ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!strcmp(name, semantic_names[i])) return i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return ~0U;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncBOOL shader_match_semantic(const char *semantic_name, enum wined3d_decl_usage usage)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return !strcmp(semantic_name, shader_semantic_name_from_usage(usage));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_signature_from_semantic(struct wined3d_shader_signature_element *e,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader_semantic *s)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->semantic_name = shader_semantic_name_from_usage(s->usage);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->semantic_idx = s->usage_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->sysval_semantic = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->component_type = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->register_idx = s->reg.reg.idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->mask = s->reg.write_mask;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_signature_from_usage(struct wined3d_shader_signature_element *e,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_decl_usage usage, UINT usage_idx, UINT reg_idx, DWORD write_mask)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->semantic_name = shader_semantic_name_from_usage(usage);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->semantic_idx = usage_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->sysval_semantic = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->component_type = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->register_idx = reg_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync e->mask = write_mask;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic const struct wined3d_shader_frontend *shader_select_frontend(DWORD version_token)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (version_token >> 16)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SM1_VS:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SM1_PS:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return &sm1_shader_frontend;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SM4_PS:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SM4_VS:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SM4_GS:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return &sm4_shader_frontend;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unrecognised version token %#x\n", version_token);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid shader_buffer_clear(struct wined3d_shader_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->buffer[0] = '\0';
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->content_size = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->lineNo = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->newline = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncBOOL shader_buffer_init(struct wined3d_shader_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->buffer = HeapAlloc(GetProcessHeap(), 0, SHADER_PGMSIZE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!buffer->buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to allocate shader buffer memory.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->buffer_size = SHADER_PGMSIZE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_buffer_clear(buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid shader_buffer_free(struct wined3d_shader_buffer *buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, buffer->buffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncint shader_vaddline(struct wined3d_shader_buffer *buffer, const char *format, va_list args)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync char *base = buffer->buffer + buffer->content_size;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync int rc;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync char *new_buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync while(1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync rc = vsnprintf(base, buffer->buffer_size - buffer->content_size, format, args);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (rc < 0 /* C89 */ || (unsigned int)rc >= buffer->buffer_size - buffer->content_size /* C99 */)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync new_buffer = HeapReAlloc(GetProcessHeap(), 0, buffer->buffer, buffer->buffer_size * 2);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!new_buffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("The buffer allocated for the shader program string is too small at %d bytes.\n", buffer->buffer_size);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->content_size = buffer->buffer_size - 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return -1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->buffer = new_buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->buffer_size = buffer->buffer_size * 2;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync base = buffer->buffer + buffer->content_size;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->newline)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("GL HW (%u, %u) : %s", buffer->lineNo + 1, buffer->content_size, base);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->newline = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%s", base);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->content_size += rc;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (buffer->buffer[buffer->content_size-1] == '\n')
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ++buffer->lineNo;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync buffer->newline = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncint shader_addline(struct wined3d_shader_buffer *buffer, const char *format, ...)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync va_list args;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync int ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync va_start(args, format);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ret = shader_vaddline(buffer, format, args);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync va_end(args);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return ret;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_init(struct wined3d_shader *shader, struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync void *parent, const struct wined3d_parent_ops *parent_ops)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->ref = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->device = device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->parent = parent;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->parent_ops = parent_ops;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_init(&shader->linked_programs);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_add_head(&device->shaders, &shader->shader_list_entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Convert floating point offset relative to a register file to an absolute
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * offset for float constants. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic unsigned int shader_get_float_offset(enum wined3d_shader_register_type register_type, UINT register_idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (register_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_CONST: return register_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_CONST2: return 2048 + register_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_CONST3: return 4096 + register_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_CONST4: return 6144 + register_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unsupported register type: %u.\n", register_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return register_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_delete_constant_list(struct list *clist)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_lconst *constant;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct list *ptr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ptr = list_head(clist);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync while (ptr)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync constant = LIST_ENTRY(ptr, struct wined3d_shader_lconst, entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ptr = list_next(clist, ptr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, constant);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_init(clist);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic inline void set_bitmap_bit(DWORD *bitmap, DWORD bit)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD idx, shift;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync idx = bit >> 5;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shift = bit & 0x1f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync bitmap[idx] |= (1 << shift);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_record_register_usage(struct wined3d_shader *shader, struct wined3d_shader_reg_maps *reg_maps,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader_register *reg, enum wined3d_shader_type shader_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (reg->type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_TEXTURE: /* WINED3DSPR_ADDR */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader_type == WINED3D_SHADER_TYPE_PIXEL)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->texcoord |= 1 << reg->idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->address |= 1 << reg->idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_TEMP:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->temporary |= 1 << reg->idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_INPUT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader_type == WINED3D_SHADER_TYPE_PIXEL)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg->idx[0].rel_addr)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* If relative addressing is used, we must assume that all registers
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * are used. Even if it is a construct like v3[aL], we can't assume
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * that v0, v1 and v2 aren't read because aL can be negative */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_REG_INPUT; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.ps.input_reg_used[i] = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.ps.input_reg_used[reg->idx[0].offset] = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->input_registers |= 1 << reg->idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_RASTOUT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg->idx[0].offset == 1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->fog = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_MISCTYPE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader_type == WINED3D_SHADER_TYPE_PIXEL)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!reg->idx[0].offset)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->vpos = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (reg->idx[0].offset == 1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->usesfacing = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_CONST:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg->idx[0].rel_addr)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg->idx[0].offset < reg_maps->min_rel_offset)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->min_rel_offset = reg->idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg->idx[0].offset > reg_maps->max_rel_offset)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->max_rel_offset = reg->idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->usesrelconstF = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync set_bitmap_bit(reg_maps->constf, reg->idx[0].offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_CONSTINT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->integer_constants |= (1 << reg->idx[0].offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_CONSTBOOL:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->boolean_constants |= (1 << reg->idx[0].offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_COLOROUT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->rt_mask |= (1 << reg->idx[0].offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Not recording register of type %#x and [%#x][%#x].\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg->type, reg->idx[0].offset, reg->idx[1].offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic unsigned int get_instr_extra_regcount(enum WINED3D_SHADER_INSTRUCTION_HANDLER instr, unsigned int param)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (instr)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSIH_M4x4:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSIH_M3x4:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return param == 1 ? 3 : 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSIH_M4x3:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSIH_M3x3:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return param == 1 ? 2 : 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSIH_M3x2:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return param == 1 ? 1 : 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Note that this does not count the loop register as an address register. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT shader_get_registers_used(struct wined3d_shader *shader, const struct wined3d_shader_frontend *fe,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_reg_maps *reg_maps, struct wined3d_shader_signature_element *input_signature,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_signature_element *output_signature, const DWORD *byte_code, DWORD constf_size)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int cur_loop_depth = 0, max_loop_depth = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync void *fe_data = shader->frontend_data;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_version shader_version;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const DWORD *ptr = byte_code;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memset(reg_maps, 0, sizeof(*reg_maps));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->min_rel_offset = ~0U;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync fe->shader_read_header(fe_data, &ptr, &shader_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->shader_version = shader_version;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->constf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sizeof(*reg_maps->constf) * ((constf_size + 31) / 32));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!reg_maps->constf)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to allocate constant map memory.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync while (!fe->shader_is_end(fe_data, &ptr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_instruction ins;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Fetch opcode. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync fe->shader_read_instruction(fe_data, &ptr, &ins);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Unhandled opcode, and its parameters. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.handler_idx == WINED3DSIH_TABLE_SIZE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Skipping unrecognized instruction.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Handle declarations. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.handler_idx == WINED3DSIH_DCL)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_semantic *semantic = &ins.declaration.semantic;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (semantic->reg.reg.type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Mark input registers used. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_INPUT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->input_registers |= 1 << semantic->reg.reg.idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_signature_from_semantic(&input_signature[semantic->reg.reg.idx[0].offset], semantic);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Vertex shader: mark 3.0 output registers used, save token. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_OUTPUT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->output_registers |= 1 << semantic->reg.reg.idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_signature_from_semantic(&output_signature[semantic->reg.reg.idx[0].offset], semantic);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (semantic->usage == WINED3D_DECL_USAGE_FOG)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->fog = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Save sampler usage token. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_SAMPLER:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->sampler_type[semantic->reg.reg.idx[0].offset] = semantic->sampler_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Not recording DCL register type %#x.\n", semantic->reg.reg.type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DCL_CONSTANT_BUFFER)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_register *reg = &ins.declaration.src.reg;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg->idx[0].offset >= WINED3D_MAX_CBS)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Invalid CB index %u.\n", reg->idx[0].offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->cb_sizes[reg->idx[0].offset] = reg->idx[1].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DCL_INPUT_PRIMITIVE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader_version.type == WINED3D_SHADER_TYPE_GEOMETRY)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.gs.input_type = ins.declaration.primitive_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Invalid instruction %#x for shader type %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ins.handler_idx, shader_version.type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DCL_OUTPUT_TOPOLOGY)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader_version.type == WINED3D_SHADER_TYPE_GEOMETRY)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.gs.output_type = ins.declaration.primitive_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Invalid instruction %#x for shader type %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ins.handler_idx, shader_version.type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DCL_VERTICES_OUT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader_version.type == WINED3D_SHADER_TYPE_GEOMETRY)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.gs.vertices_out = ins.declaration.count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Invalid instruction %#x for shader type %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ins.handler_idx, shader_version.type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DEF)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync float *value;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!lconst) return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync lconst->idx = ins.dst[0].reg.idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(lconst->value, ins.src[0].reg.immconst_data, 4 * sizeof(DWORD));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync value = (float *)lconst->value;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader_version.major == 1 && shader_version.type == WINED3D_SHADER_TYPE_PIXEL)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (value[0] < -1.0f) value[0] = -1.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (value[0] > 1.0f) value[0] = 1.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (value[1] < -1.0f) value[1] = -1.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (value[1] > 1.0f) value[1] = 1.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (value[2] < -1.0f) value[2] = -1.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (value[2] > 1.0f) value[2] = 1.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (value[3] < -1.0f) value[3] = -1.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (value[3] > 1.0f) value[3] = 1.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_add_head(&shader->constantsF, &lconst->entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (isinf(value[0]) || isnan(value[0]) || isinf(value[1]) || isnan(value[1])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || isinf(value[2]) || isnan(value[2]) || isinf(value[3]) || isnan(value[3]))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->lconst_inf_or_nan = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DEFI)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!lconst) return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync lconst->idx = ins.dst[0].reg.idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(lconst->value, ins.src[0].reg.immconst_data, 4 * sizeof(DWORD));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_add_head(&shader->constantsI, &lconst->entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->local_int_consts |= (1 << lconst->idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DEFB)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!lconst) return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync lconst->idx = ins.dst[0].reg.idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(lconst->value, ins.src[0].reg.immconst_data, sizeof(DWORD));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_add_head(&shader->constantsB, &lconst->entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->local_bool_consts |= (1 << lconst->idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* For subroutine prototypes. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_LABEL)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->labels |= 1 << ins.src[0].reg.idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Set texture, address, temporary registers. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL color0_mov = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* This will loop over all the registers and try to
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * make a bitmask of the ones we're interested in.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Relative addressing tokens are ignored, but that's
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * okay, since we'll catch any address registers when
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * they are initialized (required by spec). */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < ins.dst_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_record_register_usage(shader, reg_maps, &ins.dst[i].reg, shader_version.type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* WINED3DSPR_TEXCRDOUT is the same as WINED3DSPR_OUTPUT. _OUTPUT can be > MAX_REG_TEXCRD and
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * is used in >= 3.0 shaders. Filter 3.0 shaders to prevent overflows, and also filter pixel
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * shaders because TECRDOUT isn't used in them, but future register types might cause issues */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader_version.type == WINED3D_SHADER_TYPE_VERTEX && shader_version.major < 3)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT idx = ins.dst[i].reg.idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (ins.dst[i].reg.type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_RASTOUT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (idx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case 0: /* oPos */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->output_registers |= 1 << 10;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_signature_from_usage(&output_signature[10],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WINED3D_DECL_USAGE_POSITION, 0, 10, WINED3DSP_WRITEMASK_ALL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case 1: /* oFog */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->output_registers |= 1 << 11;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_signature_from_usage(&output_signature[11],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WINED3D_DECL_USAGE_FOG, 0, 11, WINED3DSP_WRITEMASK_0);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case 2: /* oPts */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->output_registers |= 1 << 11;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_signature_from_usage(&output_signature[11],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WINED3D_DECL_USAGE_PSIZE, 0, 11, WINED3DSP_WRITEMASK_1);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_ATTROUT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (idx < 2)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync idx += 8;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg_maps->output_registers & (1 << idx))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync output_signature[idx].mask |= ins.dst[i].write_mask;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->output_registers |= 1 << idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_signature_from_usage(&output_signature[idx],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WINED3D_DECL_USAGE_COLOR, idx - 8, idx, ins.dst[i].write_mask);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_TEXCRDOUT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->texcoord_mask[idx] |= ins.dst[i].write_mask;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg_maps->output_registers & (1 << idx))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync output_signature[idx].mask |= ins.dst[i].write_mask;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->output_registers |= 1 << idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_signature_from_usage(&output_signature[idx],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WINED3D_DECL_USAGE_TEXCOORD, idx, idx, ins.dst[i].write_mask);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader_version.type == WINED3D_SHADER_TYPE_PIXEL)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.dst[i].reg.type == WINED3DSPR_COLOROUT && !ins.dst[i].reg.idx[0].offset)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * the mov and perform the sRGB write correction from the source register.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * However, if the mov is only partial, we can't do this, and if the write
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * comes from an instruction other than MOV it is hard to do as well. If
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * COLOROUT 0 is overwritten partially later, the marker is dropped again. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.ps.color0_mov = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.handler_idx == WINED3DSIH_MOV
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && ins.dst[i].write_mask == WINED3DSP_WRITEMASK_ALL)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Used later when the source register is read. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync color0_mov = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Also drop the MOV marker if the source register is overwritten prior to the shader
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * end
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.dst[i].reg.type == WINED3DSPR_TEMP
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && ins.dst[i].reg.idx[0].offset == shader->u.ps.color0_reg)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.ps.color0_mov = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Declare 1.x samplers implicitly, based on the destination reg. number. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader_version.major == 1
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && (ins.handler_idx == WINED3DSIH_TEX
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_TEXBEM
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_TEXBEML
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_TEXDP3TEX
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_TEXM3x2TEX
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_TEXM3x3SPEC
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_TEXM3x3TEX
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_TEXM3x3VSPEC
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_TEXREG2AR
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_TEXREG2GB
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_TEXREG2RGB))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Fake sampler usage, only set reserved bit and type. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD sampler_code = ins.dst[i].reg.idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Setting fake 2D sampler for 1.x pixelshader.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->sampler_type[sampler_code] = WINED3DSTT_2D;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* texbem is only valid with < 1.4 pixel shaders */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.handler_idx == WINED3DSIH_TEXBEM
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_TEXBEML)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->bumpmat |= 1 << ins.dst[i].reg.idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.handler_idx == WINED3DSIH_TEXBEML)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->luminanceparams |= 1 << ins.dst[i].reg.idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_BEM)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->bumpmat |= 1 << ins.dst[i].reg.idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.handler_idx == WINED3DSIH_NRM) reg_maps->usesnrm = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DSY) reg_maps->usesdsy = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DSX) reg_maps->usesdsx = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_TEXLDD) reg_maps->usestexldd = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_TEXLDL) reg_maps->usestexldl = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_MOVA) reg_maps->usesmova = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_IFC) reg_maps->usesifc = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_CALL) reg_maps->usescall = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_POW) reg_maps->usespow = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_LOOP
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_REP)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ++cur_loop_depth;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (cur_loop_depth > max_loop_depth)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync max_loop_depth = cur_loop_depth;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_ENDLOOP
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_ENDREP)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync --cur_loop_depth;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.predicate)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_record_register_usage(shader, reg_maps, &ins.predicate->reg, shader_version.type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < ins.src_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int count = get_instr_extra_regcount(ins.handler_idx, i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_register reg = ins.src[i].reg;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_record_register_usage(shader, reg_maps, &ins.src[i].reg, shader_version.type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync while (count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ++reg.idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_record_register_usage(shader, reg_maps, &reg, shader_version.type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync --count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (color0_mov)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.src[i].reg.type == WINED3DSPR_TEMP
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && ins.src[i].swizzle == WINED3DSP_NOSWIZZLE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.ps.color0_mov = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.ps.color0_reg = ins.src[i].reg.idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->loop_depth = max_loop_depth;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* PS before 2.0 don't have explicit color outputs. Instead the value of
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * R0 is written to the render target. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader_version.major < 2 && shader_version.type == WINED3D_SHADER_TYPE_PIXEL)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->rt_mask |= (1 << 0);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->functionLength = ((const char *)ptr - (const char *)byte_code);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncunsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps *reg_maps, unsigned int max)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD map = 1 << max;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync map |= map - 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync map &= reg_maps->shader_version.major < 3 ? ~reg_maps->texcoord : ~reg_maps->input_registers;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return wined3d_log2i(map);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_dump_decl_usage(const struct wined3d_shader_semantic *semantic,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader_version *shader_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("dcl");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (semantic->reg.reg.type == WINED3DSPR_SAMPLER)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (semantic->sampler_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSTT_2D: TRACE("_2d"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSTT_CUBE: TRACE("_cube"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSTT_VOLUME: TRACE("_volume"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default: TRACE("_unknown_ttype(0x%08x)", semantic->sampler_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Pixel shaders 3.0 don't have usage semantics. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader_version->major < 3 && shader_version->type == WINED3D_SHADER_TYPE_PIXEL) return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else TRACE("_");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (semantic->usage)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DECL_USAGE_POSITION:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("position%u", semantic->usage_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DECL_USAGE_BLEND_INDICES:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("blend");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DECL_USAGE_BLEND_WEIGHT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("weight");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DECL_USAGE_NORMAL:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("normal%u", semantic->usage_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DECL_USAGE_PSIZE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("psize");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DECL_USAGE_COLOR:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!semantic->usage_idx) TRACE("color");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else TRACE("specular%u", (semantic->usage_idx - 1));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DECL_USAGE_TEXCOORD:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("texture%u", semantic->usage_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DECL_USAGE_TANGENT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("tangent");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DECL_USAGE_BINORMAL:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("binormal");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DECL_USAGE_TESS_FACTOR:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("tessfactor");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DECL_USAGE_POSITIONT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("positionT%u", semantic->usage_idx);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DECL_USAGE_FOG:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("fog");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DECL_USAGE_DEPTH:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("depth");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DECL_USAGE_SAMPLE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("sample");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("unknown_semantics(0x%08x)", semantic->usage);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_dump_register(const struct wined3d_shader_register *reg,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader_version *shader_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync static const char * const rastout_reg_names[] = {"oPos", "oFog", "oPts"};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync static const char * const misctype_reg_names[] = {"vPos", "vFace"};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT offset = reg->idx[0].offset;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (reg->type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_TEMP:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("r");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_INPUT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("v");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_CONST:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_CONST2:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_CONST3:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_CONST4:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("c");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync offset = shader_get_float_offset(reg->type, offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_TEXTURE: /* vs: case WINED3DSPR_ADDR */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%c", shader_version->type == WINED3D_SHADER_TYPE_PIXEL ? 't' : 'a');
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_RASTOUT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%s", rastout_reg_names[offset]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_COLOROUT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("oC");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_DEPTHOUT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("oDepth");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_ATTROUT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("oD");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_TEXCRDOUT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Vertex shaders >= 3.0 use general purpose output registers
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * (WINED3DSPR_OUTPUT), which can include an address token. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader_version->major >= 3) TRACE("o");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else TRACE("oT");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_CONSTINT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("i");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_CONSTBOOL:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("b");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_LABEL:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("l");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_LOOP:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("aL");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_SAMPLER:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("s");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_MISCTYPE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (offset > 1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unhandled misctype register %u.\n", offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%s", misctype_reg_names[offset]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_PREDICATE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("p");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_IMMCONST:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("l");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_CONSTBUFFER:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("cb");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_PRIMID:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("primID");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_NULL:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("null");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPR_RESOURCE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("t");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("unhandled_rtype(%#x)", reg->type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg->type == WINED3DSPR_IMMCONST)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("(");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (reg->immconst_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_IMMCONST_SCALAR:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (reg->data_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DATA_FLOAT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%.8e", *(const float *)reg->immconst_data);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DATA_INT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%d", reg->immconst_data[0]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DATA_RESOURCE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DATA_SAMPLER:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DATA_UINT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%u", reg->immconst_data[0]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("<unhandled data type %#x>", reg->data_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_IMMCONST_VEC4:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (reg->data_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DATA_FLOAT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%.8e, %.8e, %.8e, %.8e",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *(const float *)&reg->immconst_data[0], *(const float *)&reg->immconst_data[1],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *(const float *)&reg->immconst_data[2], *(const float *)&reg->immconst_data[3]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DATA_INT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%d, %d, %d, %d",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg->immconst_data[0], reg->immconst_data[1],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg->immconst_data[2], reg->immconst_data[3]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DATA_RESOURCE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DATA_SAMPLER:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_DATA_UINT:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%u, %u, %u, %u",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg->immconst_data[0], reg->immconst_data[1],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg->immconst_data[2], reg->immconst_data[3]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("<unhandled data type %#x>", reg->data_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("<unhandled immconst_type %#x>", reg->immconst_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE(")");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (reg->type != WINED3DSPR_RASTOUT
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && reg->type != WINED3DSPR_MISCTYPE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && reg->type != WINED3DSPR_NULL)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (offset != ~0U)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("[");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg->idx[0].rel_addr)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_dump_src_param(reg->idx[0].rel_addr, shader_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE(" + ");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%u]", offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg->idx[1].offset != ~0U)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("[");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg->idx[1].rel_addr)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_dump_src_param(reg->idx[1].rel_addr, shader_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE(" + ");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%u]", reg->idx[1].offset);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid shader_dump_dst_param(const struct wined3d_shader_dst_param *param,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader_version *shader_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD write_mask = param->write_mask;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_dump_register(&param->reg, shader_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (write_mask && write_mask != WINED3DSP_WRITEMASK_ALL)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync static const char *write_mask_chars = "xyzw";
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE(".");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (write_mask & WINED3DSP_WRITEMASK_0) TRACE("%c", write_mask_chars[0]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (write_mask & WINED3DSP_WRITEMASK_1) TRACE("%c", write_mask_chars[1]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (write_mask & WINED3DSP_WRITEMASK_2) TRACE("%c", write_mask_chars[2]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (write_mask & WINED3DSP_WRITEMASK_3) TRACE("%c", write_mask_chars[3]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid shader_dump_src_param(const struct wined3d_shader_src_param *param,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader_version *shader_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_shader_src_modifier src_modifier = param->modifiers;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD swizzle = param->swizzle;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (src_modifier == WINED3DSPSM_NEG
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || src_modifier == WINED3DSPSM_BIASNEG
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || src_modifier == WINED3DSPSM_SIGNNEG
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || src_modifier == WINED3DSPSM_X2NEG
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || src_modifier == WINED3DSPSM_ABSNEG)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("-");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (src_modifier == WINED3DSPSM_COMP)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("1-");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (src_modifier == WINED3DSPSM_NOT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("!");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (src_modifier == WINED3DSPSM_ABS || src_modifier == WINED3DSPSM_ABSNEG)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("abs(");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_dump_register(&param->reg, shader_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (src_modifier)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (src_modifier)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPSM_NONE: break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPSM_NEG: break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPSM_NOT: break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPSM_BIAS: TRACE("_bias"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPSM_BIASNEG: TRACE("_bias"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPSM_SIGN: TRACE("_bx2"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPSM_SIGNNEG: TRACE("_bx2"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPSM_COMP: break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPSM_X2: TRACE("_x2"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPSM_X2NEG: TRACE("_x2"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPSM_DZ: TRACE("_dz"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPSM_DW: TRACE("_dw"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPSM_ABSNEG: TRACE(")"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3DSPSM_ABS: TRACE(")"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default: TRACE("_unknown_modifier(%#x)", src_modifier);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swizzle != WINED3DSP_NOSWIZZLE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync static const char *swizzle_chars = "xyzw";
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD swizzle_x = swizzle & 0x03;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD swizzle_y = (swizzle >> 2) & 0x03;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD swizzle_z = (swizzle >> 4) & 0x03;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD swizzle_w = (swizzle >> 6) & 0x03;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swizzle_x == swizzle_y
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && swizzle_x == swizzle_z
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && swizzle_x == swizzle_w)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE(".%c", swizzle_chars[swizzle_x]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE(".%c%c%c%c", swizzle_chars[swizzle_x], swizzle_chars[swizzle_y],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swizzle_chars[swizzle_z], swizzle_chars[swizzle_w]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Shared code in order to generate the bulk of the shader string.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * NOTE: A description of how to parse tokens can be found on MSDN. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid shader_generate_main(const struct wined3d_shader *shader, struct wined3d_shader_buffer *buffer,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader_reg_maps *reg_maps, const DWORD *byte_code, void *backend_ctx)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_device *device = shader->device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader_frontend *fe = shader->frontend;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync void *fe_data = shader->frontend_data;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_version shader_version;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_loop_state loop_state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_instruction ins;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_tex_mx tex_mx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_context ctx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const DWORD *ptr = byte_code;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Initialize current parsing state. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync tex_mx.current_row = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync loop_state.current_depth = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync loop_state.current_reg = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ctx.shader = shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ctx.gl_info = &device->adapter->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ctx.reg_maps = reg_maps;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ctx.buffer = buffer;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ctx.tex_mx = &tex_mx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ctx.loop_state = &loop_state;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ctx.backend_data = backend_ctx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ins.ctx = &ctx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync fe->shader_read_header(fe_data, &ptr, &shader_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync while (!fe->shader_is_end(fe_data, &ptr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Read opcode. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync fe->shader_read_instruction(fe_data, &ptr, &ins);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Unknown opcode and its parameters. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.handler_idx == WINED3DSIH_TABLE_SIZE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Skipping unrecognized instruction.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.predicate)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Predicates not implemented.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Call appropriate function for output target */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_backend->shader_handle_instruction(&ins);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_dump_ins_modifiers(const struct wined3d_shader_dst_param *dst)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD mmask = dst->modifiers;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (dst->shift)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case 0: break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case 13: TRACE("_d8"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case 14: TRACE("_d4"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case 15: TRACE("_d2"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case 1: TRACE("_x2"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case 2: TRACE("_x4"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case 3: TRACE("_x8"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default: TRACE("_unhandled_shift(%d)", dst->shift); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (mmask & WINED3DSPDM_SATURATE) TRACE("_sat");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (mmask & WINED3DSPDM_PARTIALPRECISION) TRACE("_pp");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (mmask & WINED3DSPDM_MSAMPCENTROID) TRACE("_centroid");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mmask &= ~(WINED3DSPDM_SATURATE | WINED3DSPDM_PARTIALPRECISION | WINED3DSPDM_MSAMPCENTROID);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (mmask) FIXME("_unrecognized_modifier(%#x)", mmask);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_dump_primitive_type(enum wined3d_primitive_type primitive_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (primitive_type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_UNDEFINED:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("undefined");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_POINTLIST:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("pointlist");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_LINELIST:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("linelist");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_LINESTRIP:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("linestrip");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_TRIANGLELIST:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("trianglelist");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_TRIANGLESTRIP:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("trianglestrip");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_TRIANGLEFAN:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("trianglefan");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_LINELIST_ADJ:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("linelist_adj");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_LINESTRIP_ADJ:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("linestrip_adj");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_TRIANGLELIST_ADJ:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("trianglelist_adj");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_PT_TRIANGLESTRIP_ADJ:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("trianglestrip_adj");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("<unrecognized_primitive_type %#x>", primitive_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_trace_init(const struct wined3d_shader_frontend *fe, void *fe_data, const DWORD *byte_code)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_version shader_version;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const DWORD *ptr = byte_code;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const char *type_prefix;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Parsing %p.\n", byte_code);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync fe->shader_read_header(fe_data, &ptr, &shader_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (shader_version.type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_TYPE_VERTEX:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync type_prefix = "vs";
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_TYPE_GEOMETRY:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync type_prefix = "gs";
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_TYPE_PIXEL:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync type_prefix = "ps";
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unhandled shader type %#x.\n", shader_version.type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync type_prefix = "unknown";
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%s_%u_%u\n", type_prefix, shader_version.major, shader_version.minor);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync while (!fe->shader_is_end(fe_data, &ptr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_instruction ins;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync fe->shader_read_instruction(fe_data, &ptr, &ins);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.handler_idx == WINED3DSIH_TABLE_SIZE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Skipping unrecognized instruction.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.handler_idx == WINED3DSIH_DCL)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_dump_decl_usage(&ins.declaration.semantic, &shader_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_dump_ins_modifiers(&ins.declaration.semantic.reg);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE(" ");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_dump_dst_param(&ins.declaration.semantic.reg, &shader_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DCL_CONSTANT_BUFFER)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%s ", shader_opcode_names[ins.handler_idx]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_dump_src_param(&ins.declaration.src, &shader_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE(", %s", ins.flags & WINED3DSI_INDEXED_DYNAMIC ? "dynamicIndexed" : "immediateIndexed");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DCL_INPUT_PRIMITIVE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_DCL_OUTPUT_TOPOLOGY)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%s ", shader_opcode_names[ins.handler_idx]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_dump_primitive_type(ins.declaration.primitive_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DCL_VERTICES_OUT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%s %u", shader_opcode_names[ins.handler_idx], ins.declaration.count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DEF)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("def c%u = %f, %f, %f, %f", shader_get_float_offset(ins.dst[0].reg.type,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ins.dst[0].reg.idx[0].offset),
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *(const float *)&ins.src[0].reg.immconst_data[0],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *(const float *)&ins.src[0].reg.immconst_data[1],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *(const float *)&ins.src[0].reg.immconst_data[2],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *(const float *)&ins.src[0].reg.immconst_data[3]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DEFI)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("defi i%u = %d, %d, %d, %d", ins.dst[0].reg.idx[0].offset,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ins.src[0].reg.immconst_data[0],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ins.src[0].reg.immconst_data[1],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ins.src[0].reg.immconst_data[2],
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ins.src[0].reg.immconst_data[3]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_DEFB)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("defb b%u = %s", ins.dst[0].reg.idx[0].offset, ins.src[0].reg.immconst_data[0] ? "true" : "false");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.predicate)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("(");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_dump_src_param(ins.predicate, &shader_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE(") ");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* PixWin marks instructions with the coissue flag with a '+' */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.coissue) TRACE("+");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%s", shader_opcode_names[ins.handler_idx]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (ins.handler_idx == WINED3DSIH_IFC
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || ins.handler_idx == WINED3DSIH_BREAKC)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (ins.flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_REL_OP_GT: TRACE("_gt"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_REL_OP_EQ: TRACE("_eq"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_REL_OP_GE: TRACE("_ge"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_REL_OP_LT: TRACE("_lt"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_REL_OP_NE: TRACE("_ne"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_REL_OP_LE: TRACE("_le"); break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default: TRACE("_(%u)", ins.flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (ins.handler_idx == WINED3DSIH_TEX
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && shader_version.major >= 2
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && (ins.flags & WINED3DSI_TEXLD_PROJECT))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("p");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < ins.dst_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_dump_ins_modifiers(&ins.dst[i]);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE(!i ? " " : ", ");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_dump_dst_param(&ins.dst[i], &shader_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Other source tokens */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = ins.dst_count; i < (ins.dst_count + ins.src_count); ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE(!i ? " " : ", ");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_dump_src_param(&ins.src[i - ins.dst_count], &shader_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_cleanup(struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->device->shader_backend->shader_destroy(shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, shader->reg_maps.constf);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, shader->function);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_delete_constant_list(&shader->constantsF);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_delete_constant_list(&shader->constantsB);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_delete_constant_list(&shader->constantsI);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_remove(&shader->shader_list_entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader->frontend && shader->frontend_data)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->frontend->shader_free(shader->frontend_data);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct shader_none_priv
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_vertex_pipe_ops *vertex_pipe;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct fragment_pipeline *fragment_pipe;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BOOL ffp_proj_control;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_none_handle_instruction(const struct wined3d_shader_instruction *ins) {}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_none_select_depth_blt(void *shader_priv, const struct wined3d_gl_info *gl_info,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum tex_types tex_type, const SIZE *ds_mask_size) {}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_none_deselect_depth_blt(void *shader_priv, const struct wined3d_gl_info *gl_info) {}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_none_update_float_vertex_constants(struct wined3d_device *device, UINT start, UINT count) {}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_none_update_float_pixel_constants(struct wined3d_device *device, UINT start, UINT count) {}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_none_load_constants(void *shader_priv, const struct wined3d_context *context,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_state *state) {}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_none_load_np2fixup_constants(void *shader_priv,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info, const struct wined3d_state *state) {}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_none_destroy(struct wined3d_shader *shader) {}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_none_context_destroyed(void *shader_priv, const struct wined3d_context *context) {}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Context activation is done by the caller. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_none_select(void *shader_priv, const struct wined3d_context *context,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_state *state)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info = context->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct shader_none_priv *priv = shader_priv;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync priv->vertex_pipe->vp_enable(gl_info, !use_vs(state));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync priv->fragment_pipe->enable_extension(gl_info, !use_ps(state));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Context activation is done by the caller. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_none_disable(void *shader_priv, const struct wined3d_context *context)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct shader_none_priv *priv = shader_priv;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info = context->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync priv->vertex_pipe->vp_enable(gl_info, FALSE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync priv->fragment_pipe->enable_extension(gl_info, FALSE);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT shader_none_alloc(struct wined3d_device *device, const struct wined3d_vertex_pipe_ops *vertex_pipe,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct fragment_pipeline *fragment_pipe)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct fragment_caps fragment_caps;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync void *vertex_priv, *fragment_priv;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct shader_none_priv *priv;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv))))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(vertex_priv = vertex_pipe->vp_alloc(&none_shader_backend, priv)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to initialize vertex pipe.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, priv);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_FAIL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(fragment_priv = fragment_pipe->alloc_private(&none_shader_backend, priv)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("Failed to initialize fragment pipe.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync vertex_pipe->vp_free(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, priv);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_FAIL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync priv->vertex_pipe = vertex_pipe;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync priv->fragment_pipe = fragment_pipe;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync fragment_pipe->get_caps(&device->adapter->gl_info, &fragment_caps);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync priv->ffp_proj_control = fragment_caps.wined3d_caps & WINED3D_FRAGMENT_CAP_PROJ_CONTROL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->vertex_priv = vertex_priv;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->fragment_priv = fragment_priv;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device->shader_priv = priv;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_none_free(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct shader_none_priv *priv = device->shader_priv;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync priv->fragment_pipe->free_private(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync priv->vertex_pipe->vp_free(device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, priv);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_none_get_caps(const struct wined3d_gl_info *gl_info, struct shader_caps *caps)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Set the shader caps to 0 for the none shader backend */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync caps->vs_version = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync caps->gs_version = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync caps->ps_version = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync caps->vs_uniform_count = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync caps->ps_uniform_count = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync caps->ps_1x_max_value = 0.0f;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync caps->wined3d_caps = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic BOOL shader_none_color_fixup_supported(struct color_fixup_desc fixup)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* We "support" every possible fixup, since we don't support any shader
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * model, and will never have to actually sample a texture. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic BOOL shader_none_has_ffp_proj_control(void *shader_priv)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct shader_none_priv *priv = shader_priv;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return priv->ffp_proj_control;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncconst struct wined3d_shader_backend_ops none_shader_backend =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_handle_instruction,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_select,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_disable,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_select_depth_blt,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_deselect_depth_blt,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_update_float_vertex_constants,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_update_float_pixel_constants,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_load_constants,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_load_np2fixup_constants,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_destroy,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_alloc,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_free,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_context_destroyed,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_get_caps,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_color_fixup_supported,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_none_has_ffp_proj_control,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT shader_set_function(struct wined3d_shader *shader, const DWORD *byte_code,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader_signature *output_signature, DWORD float_const_count,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_shader_type type, unsigned int max_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader_frontend *fe;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int backend_version;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_d3d_info *d3d_info = &shader->device->adapter->d3d_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("shader %p, byte_code %p, output_signature %p, float_const_count %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader, byte_code, output_signature, float_const_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync fe = shader_select_frontend(*byte_code);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!fe)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unable to find frontend for shader.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->frontend = fe;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->frontend_data = fe->shader_init(byte_code, output_signature);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!shader->frontend_data)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Failed to initialize frontend.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* First pass: trace shader. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (TRACE_ON(d3d_shader))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_trace_init(fe, shader->frontend_data, byte_code);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Initialize immediate constant lists. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_init(&shader->constantsF);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_init(&shader->constantsB);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_init(&shader->constantsI);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->lconst_inf_or_nan = FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Second pass: figure out which registers are used, what the semantics are, etc. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = shader_get_registers_used(shader, fe,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps, shader->input_signature, shader->output_signature,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync byte_code, float_const_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr)) return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg_maps->shader_version.type != type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Wrong shader type %d.\n", reg_maps->shader_version.type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg_maps->shader_version.major > max_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Shader version %d not supported by this D3D API version.\n", reg_maps->shader_version.major);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (type)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_TYPE_VERTEX:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync backend_version = d3d_info->limits.vs_version;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_TYPE_GEOMETRY:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync backend_version = d3d_info->limits.gs_version;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_TYPE_PIXEL:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync backend_version = d3d_info->limits.ps_version;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("No backend version-checking for this shader type\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync backend_version = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg_maps->shader_version.major > backend_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Shader version %d.%d not supported by your GPU with the current shader backend.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->shader_version.major, reg_maps->shader_version.minor);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->function = HeapAlloc(GetProcessHeap(), 0, shader->functionLength);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!shader->function)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(shader->function, byte_code, shader->functionLength);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncULONG CDECL wined3d_shader_incref(struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedIncrement(&shader->ref);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p increasing refcount to %u.\n", shader, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return refcount;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Do not call while under the GL lock. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncULONG CDECL wined3d_shader_decref(struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedDecrement(&shader->ref);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p decreasing refcount to %u.\n", shader, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!refcount)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WINE_WITH_SHADER_CACHE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_chache_put(shader->shaderCache, shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_cleanup(shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->parent_ops->wined3d_object_destroyed(shader->parent);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return refcount;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid * CDECL wined3d_shader_get_parent(const struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("shader %p.\n", shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return shader->parent;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_shader_get_byte_code(const struct wined3d_shader *shader,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync void *byte_code, UINT *byte_code_size)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("shader %p, byte_code %p, byte_code_size %p.\n", shader, byte_code, byte_code_size);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!byte_code)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *byte_code_size = shader->functionLength;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (*byte_code_size < shader->functionLength)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* MSDN claims (for d3d8 at least) that if *byte_code_size is smaller
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * than the required size we should write the required size and
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * return D3DERR_MOREDATA. That's not actually true. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(byte_code, shader->function, shader->functionLength);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* Set local constants for d3d8 shaders. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_shader_set_local_constants_float(struct wined3d_shader *shader,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT start_idx, const float *src_data, UINT count)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT end_idx = start_idx + count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("shader %p, start_idx %u, src_data %p, count %u.\n", shader, start_idx, src_data, count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (end_idx > shader->limits.constant_float)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("end_idx %u > float constants limit %u.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync end_idx, shader->limits.constant_float);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync end_idx = shader->limits.constant_float;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = start_idx; i < end_idx; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync float *value;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!lconst)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync lconst->idx = i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync value = (float *)lconst->value;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memcpy(value, src_data + (i - start_idx) * 4 /* 4 components */, 4 * sizeof(float));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync list_add_head(&shader->constantsF, &lconst->entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (isinf(value[0]) || isnan(value[0]) || isinf(value[1]) || isnan(value[1])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || isinf(value[2]) || isnan(value[2]) || isinf(value[3]) || isnan(value[3]))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->lconst_inf_or_nan = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid find_vs_compile_args(const struct wined3d_state *state,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader *shader, struct vs_compile_args *args)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->fog_src = state->render_states[WINED3D_RS_FOGTABLEMODE]
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync == WINED3D_FOG_NONE ? VS_FOG_COORD : VS_FOG_Z;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->clip_enabled = state->render_states[WINED3D_RS_CLIPPING]
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && state->render_states[WINED3D_RS_CLIPPLANEENABLE];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->swizzle_map = shader->device->stream_info.swizzle_map;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic BOOL match_usage(BYTE usage1, BYTE usage_idx1, BYTE usage2, BYTE usage_idx2)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (usage_idx1 != usage_idx2)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (usage1 == usage2)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (usage1 == WINED3D_DECL_USAGE_POSITION && usage2 == WINED3D_DECL_USAGE_POSITIONT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (usage2 == WINED3D_DECL_USAGE_POSITION && usage1 == WINED3D_DECL_USAGE_POSITIONT)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncBOOL vshader_get_input(const struct wined3d_shader *shader,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync BYTE usage_req, BYTE usage_idx_req, unsigned int *regnum)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WORD map = shader->reg_maps.input_registers;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; map; map >>= 1, ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(map & 1)) continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (match_usage(shader->u.vs.attributes[i].usage,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.vs.attributes[i].usage_idx, usage_req, usage_idx_req))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *regnum = i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void vertexshader_set_limits(struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD shader_version = WINED3D_SHADER_VERSION(shader->reg_maps.shader_version.major,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->reg_maps.shader_version.minor);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_device *device = shader->device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const DWORD vs_uniform_count = device->adapter->d3d_info.limits.vs_uniform_count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_input = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (shader_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(1, 0):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(1, 1):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_bool = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_int = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_output = 12;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.sampler = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* TODO: vs_1_1 has a minimum of 96 constants. What happens when
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * a vs_1_1 shader is used on a vs_3_0 capable card that has 256
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * constants? */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_float = min(256, vs_uniform_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(2, 0):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(2, 1):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_bool = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_int = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_output = 12;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.sampler = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_float = min(256, vs_uniform_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(3, 0):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_bool = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_int = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_output = 12;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.sampler = 4;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* DX10 cards on Windows advertise a d3d9 constant limit of 256
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * even though they are capable of supporting much more (GL
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * drivers advertise 1024). d3d9.dll and d3d8.dll clamp the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * wined3d-advertised maximum. Clamp the constant limit for <= 3.0
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * shaders to 256. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_float = min(256, vs_uniform_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(4, 0):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.sampler = 16; /* FIXME: 128 resources, 16 sampler states */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_int = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_float = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_bool = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_output = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_input = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_bool = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_int = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_output = 12;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.sampler = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_float = min(256, vs_uniform_count);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unrecognized vertex shader version \"%u.%u\".\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->reg_maps.shader_version.major,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->reg_maps.shader_version.minor);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT vertexshader_init(struct wined3d_shader *shader, struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync void *parent, const struct wined3d_parent_ops *parent_ops, unsigned int max_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WORD map;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const DWORD vs_uniform_count = device->adapter->d3d_info.limits.vs_uniform_count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!byte_code) return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_init(shader, device, parent, parent_ops);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = shader_set_function(shader, byte_code, output_signature, vs_uniform_count,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WINED3D_SHADER_TYPE_VERTEX, max_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to set function, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_cleanup(shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync map = reg_maps->input_registers;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; map; map >>= 1, ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(map & 1) || !shader->input_signature[i].semantic_name)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.vs.attributes[i].usage =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_usage_from_semantic_name(shader->input_signature[i].semantic_name);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.vs.attributes[i].usage_idx = shader->input_signature[i].semantic_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (output_signature)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < output_signature->element_count; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_signature_element *e = &output_signature->elements[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync reg_maps->output_registers |= 1 << e->register_idx;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->output_signature[e->register_idx] = *e;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync vertexshader_set_limits(shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->load_local_constsF = (reg_maps->usesrelconstF && !list_empty(&shader->constantsF)) ||
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->lconst_inf_or_nan;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void geometryshader_set_limits(struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD shader_version = WINED3D_SHADER_VERSION(shader->reg_maps.shader_version.major,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->reg_maps.shader_version.minor);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (shader_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(4, 0):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.sampler = 16; /* FIXME: 128 resources, 16 sampler states */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_int = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_float = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_bool = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_output = 32;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_input = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memset(&shader->limits, 0, sizeof(shader->limits));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unhandled geometry shader version \"%u.%u\".\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->reg_maps.shader_version.major,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->reg_maps.shader_version.minor);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT geometryshader_init(struct wined3d_shader *shader, struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync void *parent, const struct wined3d_parent_ops *parent_ops, unsigned int max_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_init(shader, device, parent, parent_ops);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = shader_set_function(shader, byte_code, output_signature, 0,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WINED3D_SHADER_TYPE_GEOMETRY, max_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to set function, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_cleanup(shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync geometryshader_set_limits(shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->load_local_constsF = shader->lconst_inf_or_nan;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid find_ps_compile_args(const struct wined3d_state *state,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader *shader, struct ps_compile_args *args)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_device *device = shader->device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_texture *texture;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync memset(args, 0, sizeof(*args)); /* FIXME: Make sure all bits are set. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!gl_info->supported[ARB_FRAMEBUFFER_SRGB] && state->render_states[WINED3D_RS_SRGBWRITEENABLE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_surface *rt = state->fb->render_targets[0];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (rt->resource.format->flags & WINED3DFMT_FLAG_SRGB_WRITE)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync static unsigned int warned = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->srgb_correction = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->render_states[WINED3D_RS_ALPHABLENDENABLE] && !warned++)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB "
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync "support, expect rendering artifacts.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader->reg_maps.shader_version.major == 1
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && shader->reg_maps.shader_version.minor <= 3)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < shader->limits.sampler; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD flags = state->texture_states[i][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (flags & WINED3D_TTFF_PROJECTED)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD tex_transform = flags & ~WINED3D_TTFF_PROJECTED;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!state->vertex_shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int j;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int index = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD max_valid = WINED3D_TTFF_COUNT4;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_sampler_texture_type sampler_type = shader->reg_maps.sampler_type[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (j = 0; j < state->vertex_declaration->element_count; ++j)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_vertex_declaration_element *element =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync &state->vertex_declaration->elements[j];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (element->usage == WINED3D_DECL_USAGE_TEXCOORD
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && element->usage_idx == index)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync max_valid = element->format->component_count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!tex_transform || tex_transform > max_valid)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Fixing up projected texture transform flags from %#x to %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync tex_transform, max_valid);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync tex_transform = max_valid;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((sampler_type == WINED3DSTT_1D && tex_transform > WINED3D_TTFF_COUNT1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || (sampler_type == WINED3DSTT_2D && tex_transform > WINED3D_TTFF_COUNT2)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || (sampler_type == WINED3DSTT_VOLUME && tex_transform > WINED3D_TTFF_COUNT3))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync tex_transform |= WINED3D_PSARGS_PROJECTED;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Application requested projected texture with unsuitable texture coordinates.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("(texture unit %u, transform flags %#x, sampler type %u).\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync i, tex_transform, sampler_type);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync tex_transform = WINED3D_TTFF_COUNT4 | WINED3D_PSARGS_PROJECTED;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->tex_transform |= tex_transform << i * WINED3D_PSARGS_TEXTRANSFORM_SHIFT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader->reg_maps.shader_version.major == 1
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync && shader->reg_maps.shader_version.minor <= 4)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < shader->limits.sampler; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_texture *texture = state->textures[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!shader->reg_maps.sampler_type[i])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Treat unbound textures as 2D. The dummy texture will provide
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * the proper sample value. The tex_types bitmap defaults to
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * 2D because of the memset. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!texture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (texture->target)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* RECT textures are distinguished from 2D textures via np2_fixup */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case GL_TEXTURE_RECTANGLE_ARB:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case GL_TEXTURE_2D:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case GL_TEXTURE_3D:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->tex_types |= WINED3D_SHADER_TEX_3D << i * WINED3D_PSARGS_TEXTYPE_SHIFT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case GL_TEXTURE_CUBE_MAP_ARB:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->tex_types |= WINED3D_SHADER_TEX_CUBE << i * WINED3D_PSARGS_TEXTYPE_SHIFT;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!shader->reg_maps.sampler_type[i])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync texture = state->textures[i];
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!texture)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->color_fixup[i] = COLOR_FIXUP_IDENTITY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->color_fixup[i] = texture->resource.format->color_fixup;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (texture->resource.format->flags & WINED3DFMT_FLAG_SHADOW)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->shadow |= 1 << i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Flag samplers that need NP2 texcoord fixup. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(texture->flags & WINED3D_TEXTURE_POW2_MAT_IDENT))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->np2_fixup |= (1 << i);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader->reg_maps.shader_version.major >= 3)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->stream_info.position_transformed)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->vp_mode = pretransformed;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else if (use_vs(state))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->vp_mode = vertexshader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->vp_mode = fixedfunction;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->fog = WINED3D_FFP_PS_FOG_OFF;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->vp_mode = vertexshader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (state->render_states[WINED3D_RS_FOGENABLE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (state->render_states[WINED3D_RS_FOGTABLEMODE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_FOG_NONE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (device->stream_info.position_transformed || use_vs(state))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->fog = WINED3D_FFP_PS_FOG_LINEAR;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (state->render_states[WINED3D_RS_FOGVERTEXMODE])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_FOG_NONE: /* Fall through. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_FOG_LINEAR: args->fog = WINED3D_FFP_PS_FOG_LINEAR; break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_FOG_EXP: args->fog = WINED3D_FFP_PS_FOG_EXP; break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_FOG_EXP2: args->fog = WINED3D_FFP_PS_FOG_EXP2; break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_FOG_LINEAR: args->fog = WINED3D_FFP_PS_FOG_LINEAR; break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_FOG_EXP: args->fog = WINED3D_FFP_PS_FOG_EXP; break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_FOG_EXP2: args->fog = WINED3D_FFP_PS_FOG_EXP2; break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync args->fog = WINED3D_FFP_PS_FOG_OFF;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void pixelshader_set_limits(struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD shader_version = WINED3D_SHADER_VERSION(shader->reg_maps.shader_version.major,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->reg_maps.shader_version.minor);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_output = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch (shader_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(1, 0):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(1, 1):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(1, 2):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(1, 3):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_float = 8;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_int = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_bool = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.sampler = 4;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_input = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(1, 4):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_float = 8;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_int = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_bool = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.sampler = 6;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_input = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* FIXME: Temporaries must match D3DPSHADERCAPS2_0.NumTemps. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(2, 0):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_float = 32;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_int = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_bool = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.sampler = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_input = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(2, 1):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_float = 32;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_int = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_bool = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.sampler = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_input = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(3, 0):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_float = 224;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_int = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_bool = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.sampler = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_input = 12;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_VERSION(4, 0):
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.sampler = 16; /* FIXME: 128 resources, 16 sampler states */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_int = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_float = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_bool = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_input = 32;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync default:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_float = 32;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_int = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.constant_bool = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.sampler = 16;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->limits.packed_input = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync FIXME("Unrecognized pixel shader version %u.%u\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->reg_maps.shader_version.major,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->reg_maps.shader_version.minor);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT pixelshader_init(struct wined3d_shader *shader, struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync void *parent, const struct wined3d_parent_ops *parent_ops, unsigned int max_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i, highest_reg_used = 0, num_regs_used = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const DWORD ps_uniform_count = device->adapter->d3d_info.limits.ps_uniform_count;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!byte_code) return WINED3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_init(shader, device, parent, parent_ops);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = shader_set_function(shader, byte_code, output_signature, ps_uniform_count,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WINED3D_SHADER_TYPE_PIXEL, max_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to set function, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_cleanup(shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync pixelshader_set_limits(shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_REG_INPUT; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader->u.ps.input_reg_used[i])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ++num_regs_used;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync highest_reg_used = i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Don't do any register mapping magic if it is not needed, or if we can't
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * achieve anything anyway */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (highest_reg_used < (gl_info->limits.glsl_varyings / 4)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || num_regs_used > (gl_info->limits.glsl_varyings / 4))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (num_regs_used > (gl_info->limits.glsl_varyings / 4))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* This happens with relative addressing. The input mapper function
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * warns about this if the higher registers are declared too, so
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * don't write a FIXME here */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("More varying registers used than supported\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_REG_INPUT; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.ps.input_reg_map[i] = i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.ps.declared_in_count = highest_reg_used + 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.ps.declared_in_count = 0;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < MAX_REG_INPUT; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader->u.ps.input_reg_used[i])
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u.ps.input_reg_map[i] = shader->u.ps.declared_in_count++;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else shader->u.ps.input_reg_map[i] = ~0U;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->load_local_constsF = shader->lconst_inf_or_nan;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid pixelshader_update_samplers(struct wined3d_shader *shader, WORD tex_types)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync enum wined3d_sampler_texture_type *sampler_type = reg_maps->sampler_type;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unsigned int i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (reg_maps->shader_version.major != 1) return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < shader->limits.sampler; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* We don't sample from this sampler. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!sampler_type[i]) continue;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync switch ((tex_types >> i * WINED3D_PSARGS_TEXTYPE_SHIFT) & WINED3D_PSARGS_TEXTYPE_MASK)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_TEX_2D:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sampler_type[i] = WINED3DSTT_2D;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_TEX_3D:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sampler_type[i] = WINED3DSTT_VOLUME;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync case WINED3D_SHADER_TEX_CUBE:
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync sampler_type[i] = WINED3DSTT_CUBE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync break;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_shader_create_gs(struct wined3d_device *device, const DWORD *byte_code,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader_signature *output_signature, void *parent,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, byte_code %p, output_signature %p, parent %p, parent_ops %p, shader %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, byte_code, output_signature, parent, parent_ops, shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = geometryshader_init(object, device, byte_code, output_signature, parent, parent_ops, max_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Created geometry shader %p.\n", object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *shader = object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_shader_create_ps(struct wined3d_device *device, const DWORD *byte_code,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader_signature *output_signature, void *parent,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, byte_code %p, output_signature %p, parent %p, parent_ops %p, shader %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, byte_code, output_signature, parent, parent_ops, shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = pixelshader_init(object, device, byte_code, output_signature, parent, parent_ops, max_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WINE_WITH_SHADER_CACHE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object = pixelshader_check_cached(device, object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Created pixel shader %p.\n", object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *shader = object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT CDECL wined3d_shader_create_vs(struct wined3d_device *device, const DWORD *byte_code,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_shader_signature *output_signature, void *parent,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("device %p, byte_code %p, output_signature %p, parent %p, parent_ops %p, shader %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync device, byte_code, output_signature, parent, parent_ops, shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = vertexshader_init(object, device, byte_code, output_signature, parent, parent_ops, max_version);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WINE_WITH_SHADER_CACHE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object = vertexshader_check_cached(device, object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Created vertex shader %p.\n", object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *shader = object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return WINED3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WINE_WITH_SHADER_CACHE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_reinit(struct wined3d_shader *shader, struct wined3d_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync void *parent, const struct wined3d_parent_ops *parent_ops)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->ref = 1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->device = device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->parent = parent;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->parent_ops = parent_ops;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef DEBUG
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *tst_shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LIST_FOR_EACH_ENTRY(tst_shader, &device->shaders, struct wined3d_shader, shader_list_entry) {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (tst_shader == shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ERR("shader not in list!");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic DECLCALLBACK(uint32_t) shader_cache_hash(void *pvKey)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync uint32_t u32Hash, i;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync DWORD *function;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader * shader = (struct wined3d_shader *)pvKey;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader->u32CacheDataInited)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return shader->u32Hash;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync u32Hash = shader->functionLength;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync function = shader->function;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < shader->functionLength / 4; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync u32Hash += *function++;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync for (i = 0; i < shader->functionLength % 4; ++i)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync u32Hash += *((uint8_t*)function)++;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u32Hash = u32Hash;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->u32CacheDataInited = TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return shader->u32Hash;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic DECLCALLBACK(bool) shader_cache_equal(void *pvKey1, void *pvKey2)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *shader1 = (struct wined3d_shader *)pvKey1;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *shader2 = (struct wined3d_shader *)pvKey2;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader1 == shader2)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return TRUE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader1->functionLength != shader2->functionLength)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader_cache_hash(pvKey1) != shader_cache_hash(pvKey2))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef DEBUG_misha
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync Assert(memcmp(shader1->function, shader2->function, shader1->functionLength));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return FALSE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return !memcmp(shader1->function, shader2->function, shader1->functionLength);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#define VBOX_SHADER_FROM_CACHE_ENTRY(_pEntry) RT_FROM_MEMBER((_pEntry), struct wined3d_shader, CacheEntry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic DECLCALLBACK(void) shader_cache_cleanup_entry(void *pvKey, struct VBOXEXT_HASHCACHE_ENTRY *pEntry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *shader = VBOX_SHADER_FROM_CACHE_ENTRY(pEntry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_cleanup(shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader->parent)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->parent_ops->wined3d_object_destroyed(shader->parent);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_chache_init(PVBOXEXT_HASHCACHE pCache)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync VBoxExtCacheInit(pCache, 1024, shader_cache_hash, shader_cache_equal, shader_cache_cleanup_entry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_chache_term(PVBOXEXT_HASHCACHE pCache)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync VBoxExtCacheTerm(pCache);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void shader_chache_put(PVBOXEXT_HASHCACHE pCache, struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (shader->parent)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->parent_ops->wined3d_object_destroyed(shader->parent);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->parent = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync VBoxExtCachePut(pCache, shader, &shader->CacheEntry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic struct wined3d_shader* shader_chache_get(PVBOXEXT_HASHCACHE pCache, struct wined3d_shader *shader)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync PVBOXEXT_HASHCACHE_ENTRY pEntry = VBoxExtCacheGet(pCache, shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_shader *cached_shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!pEntry)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync cached_shader = VBOX_SHADER_FROM_CACHE_ENTRY(pEntry);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_reinit(cached_shader, shader->device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->parent, shader->parent_ops);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader->parent = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* we can not do a IWineD3DBaseShader_Release here since this would result in putting a shader to the cache */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_cleanup(shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, shader);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return cached_shader;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_shader * vertexshader_check_cached(struct wined3d_device *device, struct wined3d_shader *object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->shaderCache = &device->vshaderCache;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return shader_chache_get(&device->vshaderCache, (struct wined3d_shader *)object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstruct wined3d_shader * pixelshader_check_cached(struct wined3d_device *device, struct wined3d_shader *object)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync object->shaderCache = &device->pshaderCache;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return shader_chache_get(&device->pshaderCache, (struct wined3d_shader *)object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid shader_chaches_init(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_chache_init(&device->vshaderCache);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_chache_init(&device->pshaderCache);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncvoid shader_chaches_term(struct wined3d_device *device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_chache_term(&device->vshaderCache);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync shader_chache_term(&device->pshaderCache);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif