glsl_shader.c revision bab68815afb87d2f4d3d6e0c5064010578c04a5a
/*
* GLSL pixel and vertex shader implementation
*
* Copyright 2006 Jason Green
* Copyright 2006-2007 Henri Verbeet
* Copyright 2007-2009, 2013 Stefan Dösinger for CodeWeavers
* Copyright 2009-2011 Henri Verbeet for CodeWeavers
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* D3D shader asm has swizzles on source parameters, and write masks for
* destination parameters. GLSL uses swizzles for both. The result of this is
* that for example "mov dst.xw, src.zyxw" becomes "dst.xw = src.zw" in GLSL.
* Ie, to generate a proper GLSL source swizzle, we need to take the D3D write
* mask for the destination parameter into account.
*/
#include "config.h"
#include <limits.h>
#include <stdio.h>
#include "wined3d_private.h"
#define WINED3D_GLSL_SAMPLE_PROJECTED 0x1
#define WINED3D_GLSL_SAMPLE_NPOT 0x2
#define WINED3D_GLSL_SAMPLE_LOD 0x4
#define WINED3D_GLSL_SAMPLE_GRAD 0x8
struct glsl_dst_param
{
char reg_name[150];
char mask_str[6];
};
struct glsl_src_param
{
char reg_name[150];
char param_str[200];
};
struct glsl_sample_function
{
const char *name;
};
enum heap_node_op
{
};
struct constant_entry
{
unsigned int idx;
unsigned int version;
};
struct constant_heap
{
struct constant_entry *entries;
unsigned int *positions;
unsigned int size;
};
/* GLSL shader private data */
struct shader_glsl_priv {
struct wined3d_shader_buffer shader_buffer;
struct wine_rb_tree program_lookup;
struct glsl_shader_prog_link *glsl_program;
struct constant_heap vconst_heap;
struct constant_heap pconst_heap;
unsigned char *stack;
const struct wined3d_vertex_pipe_ops *vertex_pipe;
const struct fragment_pipeline *fragment_pipe;
struct wine_rb_tree ffp_vertex_shaders;
struct wine_rb_tree ffp_fragment_shaders;
};
struct glsl_vs_program
{
struct list shader_entry;
};
struct glsl_gs_program
{
struct list shader_entry;
};
struct glsl_ps_program
{
struct list shader_entry;
const struct ps_np2fixup_info *np2_fixup_info;
};
/* Struct to maintain data about a linked GLSL program */
struct glsl_shader_prog_link
{
struct wine_rb_entry program_lookup_entry;
struct glsl_vs_program vs;
struct glsl_gs_program gs;
struct glsl_ps_program ps;
};
struct glsl_program_key
{
};
struct shader_glsl_ctx_priv {
const struct vs_compile_args *cur_vs_args;
const struct ps_compile_args *cur_ps_args;
struct ps_np2fixup_info *cur_np2fixup_info;
};
struct glsl_ps_compiled_shader
{
struct ps_compile_args args;
struct ps_np2fixup_info np2fixup;
};
struct glsl_vs_compiled_shader
{
struct vs_compile_args args;
};
struct glsl_gs_compiled_shader
{
};
struct glsl_shader_private
{
union
{
struct glsl_vs_compiled_shader *vs;
struct glsl_gs_compiled_shader *gs;
struct glsl_ps_compiled_shader *ps;
} gl_shaders;
};
struct glsl_ffp_vertex_shader
{
struct wined3d_ffp_vs_desc desc;
struct list linked_programs;
};
struct glsl_ffp_fragment_shader
{
struct ffp_frag_desc entry;
struct list linked_programs;
};
struct glsl_ffp_destroy_ctx
{
struct shader_glsl_priv *priv;
const struct wined3d_gl_info *gl_info;
};
{
switch (type)
{
#define WINED3D_TO_STR(u) case u: return #u
default:
}
}
{
switch (type)
{
return "vs";
return "gs";
return "ps";
default:
return "unknown";
}
}
/* Extract a line from the info log.
* Note that this modifies the source string. */
static char *get_info_log_line(char **ptr)
{
char *p, *q;
p = *ptr;
if (!(q = strstr(p, "\n")))
{
if (!*p) return NULL;
return p;
}
*q = '\0';
*ptr = q + 1;
return p;
}
/* Context activation is done by the caller. */
{
int infologLength = 0;
char *infoLog;
return;
&infologLength));
/* A size of 1 is just a null-terminated string, so the log should be bigger than
* that if there are errors. */
if (infologLength > 1)
{
/* The info log is supposed to be zero-terminated, but at least some
* versions of fglrx don't terminate the string properly. The reported
* length does include the terminator, so explicitly set it to zero
* here. */
{
}
else
{
}
}
}
/* Context activation is done by the caller. */
static void shader_glsl_compile(const struct wined3d_gl_info *gl_info, GLhandleARB shader, const char *src)
{
checkGLcall("glShaderSourceARB");
checkGLcall("glCompileShaderARB");
}
/* Context activation is done by the caller. */
static void shader_glsl_dump_program_source(const struct wined3d_gl_info *gl_info, GLhandleARB program)
{
if (!objects)
{
ERR("Failed to allocate object array memory.\n");
return;
}
for (i = 0; i < object_count; ++i)
{
if (source_size < tmp)
{
if (!source)
{
return;
}
source_size = tmp;
}
FIXME("\n");
FIXME("\n");
}
}
/* Context activation is done by the caller. */
{
if (tmp == GL_PROGRAM_OBJECT_ARB)
{
if (!tmp)
{
}
}
}
/* Context activation is done by the caller. */
{
char sampler_name[20];
unsigned int i;
for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
{
if (name_loc != -1) {
{
checkGLcall("glUniform1iARB");
} else {
}
}
}
}
/* Context activation is done by the caller. */
{
char sampler_name[20];
unsigned int i;
for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i)
{
if (name_loc != -1) {
{
checkGLcall("glUniform1iARB");
} else {
}
}
}
}
/* Context activation is done by the caller. */
static inline void walk_constant_heap(const struct wined3d_gl_info *gl_info, const float *constants,
const GLint *constant_locations, const struct constant_heap *heap, unsigned char *stack, DWORD version)
{
int stack_idx = 0;
unsigned int heap_idx = 1;
unsigned int idx;
if (constant_locations[idx] != -1) GL_EXTCALL(glUniform4fvARB(constant_locations[idx], 1, &constants[idx * 4]));
while (stack_idx >= 0)
{
/* Note that we fall through to the next case statement. */
{
case HEAP_NODE_TRAVERSE_LEFT:
{
{
break;
}
}
case HEAP_NODE_TRAVERSE_RIGHT:
{
{
break;
}
}
case HEAP_NODE_POP:
heap_idx >>= 1;
--stack_idx;
break;
}
}
checkGLcall("walk_constant_heap()");
}
/* Context activation is done by the caller. */
static inline void apply_clamped_constant(const struct wined3d_gl_info *gl_info, GLint location, const GLfloat *data)
{
if (location == -1) return;
}
/* Context activation is done by the caller. */
static inline void walk_constant_heap_clamped(const struct wined3d_gl_info *gl_info, const float *constants,
const GLint *constant_locations, const struct constant_heap *heap, unsigned char *stack, DWORD version)
{
int stack_idx = 0;
unsigned int heap_idx = 1;
unsigned int idx;
while (stack_idx >= 0)
{
/* Note that we fall through to the next case statement. */
{
case HEAP_NODE_TRAVERSE_LEFT:
{
{
break;
}
}
case HEAP_NODE_TRAVERSE_RIGHT:
{
{
break;
}
}
case HEAP_NODE_POP:
heap_idx >>= 1;
--stack_idx;
break;
}
}
checkGLcall("walk_constant_heap_clamped()");
}
/* Context activation is done by the caller. */
static void shader_glsl_load_constantsF(const struct wined3d_shader *shader, const struct wined3d_gl_info *gl_info,
{
const struct wined3d_shader_lconst *lconst;
/* 1.X pshaders have the constants clamped to [-1;1] implicitly. */
else
if (!shader->load_local_constsF)
{
TRACE("No need to load local float constants for this shader\n");
return;
}
/* Immediate constants are clamped to [-1;1] at shader creation time if needed */
{
}
checkGLcall("glUniform4fvARB()");
}
/* Context activation is done by the caller. */
static void shader_glsl_load_constantsI(const struct wined3d_shader *shader, const struct wined3d_gl_info *gl_info,
{
unsigned int i;
{
if (!(constants_set & 1)) continue;
/* We found this uniform name in the program - go ahead and send the data */
checkGLcall("glUniform4ivARB");
}
/* Load immediate constants */
while (ptr)
{
const struct wined3d_shader_lconst *lconst = LIST_ENTRY(ptr, const struct wined3d_shader_lconst, entry);
/* We found this uniform name in the program - go ahead and send the data */
checkGLcall("glUniform4ivARB");
}
}
/* Context activation is done by the caller. */
static void shader_glsl_load_constantsB(const struct wined3d_shader *shader, const struct wined3d_gl_info *gl_info,
{
unsigned int i;
char tmp_name[10];
const char *prefix;
/* TODO: Benchmark and see if it would be beneficial to store the
* locations of the constants to avoid looking up each time */
{
if (!(constants_set & 1)) continue;
/* TODO: Benchmark and see if it would be beneficial to store the
* locations of the constants to avoid looking up each time */
}
/* Load immediate constants */
while (ptr)
{
const struct wined3d_shader_lconst *lconst = LIST_ENTRY(ptr, const struct wined3d_shader_lconst, entry);
}
checkGLcall("shader_glsl_load_constantsB()");
}
{
WINE_RB_ENTRY_VALUE(entry, struct glsl_shader_prog_link, program_lookup_entry)->constant_version = 0;
}
/* Context activation is done by the caller (state handler). */
static void shader_glsl_load_np2fixup_constants(void *shader_priv,
{
/* No GLSL program set - nothing to do. */
if (!prog) return;
/* NP2 texcoord fixup is (currently) only done for pixelshaders. */
{
UINT i;
{
if (!tex)
{
ERR("Nonexistent texture is flagged for NP2 texcoord fixup.\n");
continue;
}
if (idx % 2)
{
}
else
{
}
}
}
}
/* Context activation is done by the caller (state handler). */
const struct wined3d_state *state)
{
float position_fixup[4];
int i;
if (!prog) {
/* No GLSL program set - nothing to do. */
return;
}
{
/* Upload the position fixup params */
checkGLcall("glUniform4fvARB");
}
{
/* Upload the environment bump map matrix if needed. The needsbumpmat
* member specifies the texture stage to load the matrix from. It
* can't be 0 for a valid texbem instruction. */
for (i = 0; i < MAX_TEXTURES; ++i)
{
const float *data;
continue;
checkGLcall("glUniformMatrix2fvARB");
/* texbeml needs the luminance scale and offset too. If texbeml
* is used, needsbumpmat is set too, so we can check that in the
* needsbumpmat check. */
{
checkGLcall("glUniform1fvARB");
checkGLcall("glUniform1fvARB");
}
}
{
float correction_params[4];
if (context->render_offscreen)
{
correction_params[0] = 0.0f;
} else {
/* position is window relative, not viewport relative */
}
}
}
{
float col[4];
for (i = 0; i < MAX_TEXTURES; ++i)
{
}
else
checkGLcall("fixed function uniforms");
}
{
TRACE("Max constant version reached, resetting to 0.\n");
}
else
{
}
}
{
unsigned int parent_idx;
while (heap_idx > 1)
{
}
}
static void shader_glsl_update_float_vertex_constants(struct wined3d_device *device, UINT start, UINT count)
{
UINT i;
{
else
}
}
static void shader_glsl_update_float_pixel_constants(struct wined3d_device *device, UINT start, UINT count)
{
UINT i;
{
else
}
}
{
/* 4.0 shaders do not write clip coords because d3d10 does not support user clipplanes */
/* 3.0 shaders may need an extra varying for the clip coord on some cards(mostly dx10 ones) */
return ret;
}
/** Generate the variable & register declarations for the GLSL output target */
{
unsigned int i, extra_constants_needed = 0;
const struct wined3d_shader_lconst *lconst;
const char *prefix;
/* Prototype the subroutines */
{
}
/* Declare the constants (aka uniforms) */
{
unsigned max_constantsF;
/* Unless the shader uses indirect addressing, always declare the
* maximum array size and ignore that we need some uniforms privately.
* E.g. if GL supports 256 uniforms, and we need 2 for the pos fixup
* and immediate values, still declare VC[256]. If the shader needs
* more uniforms than we have it won't work in any case. If it uses
* less, the compiler will figure out which uniforms are really used
* and strip them out. This allows a shader to use c255 on a dx9 card,
* as long as it doesn't also use all the other constants.
*
* If the shader uses indirect addressing the compiler must assume
* that all declared uniforms are used. In this case, declare only the
* amount that we're assured to have.
*
* Thus we run into problems in these two cases:
* 1) The shader really uses more uniforms than supported.
* 2) The shader uses indirect addressing, less constants than
* supported, but uses a constant index > #supported consts. */
{
/* No indirect addressing here. */
}
else
{
if (reg_maps->usesrelconstF)
{
/* Subtract the other potential uniforms from the max
* available (bools, ints, and 1 row of projection matrix).
* Subtract another uniform for immediate values, which have
* to be loaded via uniform by the driver as well. The shader
* code only uses 0.5, 2.0, 1.0, 128 and -128 in vertex
* shader code, so one vec4 should be enough. (Unfortunately
* the Nvidia driver doesn't store 128 and -128 in one float).
*
* Writing gl_ClipVertex requires one uniform for each
* clipplane as well. */
{
}
/* Strictly speaking a bool only uses one scalar, but the nvidia(Linux) compiler doesn't pack them properly,
* so each scalar requires a full vec4. We could work around this by packing the booleans ourselves, but
* for now take this into account when calculating the number of available constants
*/
/* Set by driver quirks in directx.c */
{
static unsigned int once;
if (!once++)
" it may not render correctly.\n");
else
WARN("The hardware does not support enough uniform components to run this shader.\n");
}
}
else
{
}
}
}
/* Always declare the full set of constants, the compiler can remove the
* unused ones because d3d doesn't (yet) support indirect int and bool
* constant addressing. This avoids problems if the app uses e.g. i0 and i9. */
for (i = 0; i < WINED3D_MAX_CBS; ++i)
{
}
/* Declare texture samplers */
{
if (reg_maps->sampler_type[i])
{
switch (reg_maps->sampler_type[i])
{
case WINED3DSTT_1D:
if (shadow_sampler)
else
break;
case WINED3DSTT_2D:
if (shadow_sampler)
{
if (tex_rect)
else
}
else
{
if (tex_rect)
else
}
break;
case WINED3DSTT_CUBE:
if (shadow_sampler)
FIXME("Unsupported Cube shadow sampler.\n");
break;
case WINED3DSTT_VOLUME:
if (shadow_sampler)
FIXME("Unsupported 3D shadow sampler.\n");
break;
default:
break;
}
}
}
/* Declare uniforms for NP2 texcoord fixup:
* This is NOT done inside the loop that declares the texture samplers
* since the NP2 fixup code is currently only used for the GeforceFX
* series and when forcing the ARB_npot extension off. Modern cards just
* skip the code anyway, so put it inside a separate loop. */
{
* while D3D has them in the (normalized) [0,1]x[0,1] range.
* samplerNP2Fixup stores texture dimensions and is updated through
* shader_glsl_load_np2fixup_constants when the sampler changes. */
{
if (reg_maps->sampler_type[i])
{
FIXME("Non-2D texture is flagged for NP2 texcoord fixup.\n");
continue;
}
}
}
}
/* Declare address variables */
{
}
/* Declare texture coordinate temporaries and initialize them */
{
}
{
/* Declare attributes. */
{
if (map & 1)
}
}
{
}
{
{
else
/* TODO: Write a replacement shader for the fixed function
* vertex pipeline, so this isn't needed. For fixed function
* vertex processing + 3.0 pixel shader we need a separate
* function in the pixel shader that reads the fixed function
* color into the packed input registers. */
}
{
if (!(map & 1))
continue;
{
}
}
if (ps_args->srgb_correction)
{
srgb_cmp);
}
{
{
}
else
{
/* This happens because we do not have proper tracking of the constant registers that are
* actually used, only the max limit of the shader version
*/
FIXME("Cannot find a free uniform for vpos correction params\n");
}
}
}
/* Declare output register temporaries */
/* Declare temporary variables */
{
}
/* Declare loop registers aLx */
{
for (i = 0; i < reg_maps->loop_depth; ++i)
{
}
}
/* Temporary variables for matrix operations */
if (!shader->load_local_constsF)
{
{
const float *value;
}
}
/* Start the main program. */
/* Direct3D applications expect integer vPos values, while OpenGL drivers
* add approximately 0.5. This causes off-by-one problems as spotted by
* the vPos d3d9 visual test. Unfortunately ATI cards do not add exactly
* 0.5, but rather something like 0.49999999 or 0.50000001, which still
* causes precision troubles when we just subtract 0.5.
*
* To deal with that, just floor() the position. This will eliminate the
* fraction on all cards.
*
* TODO: Test how this behaves with multisampling.
*
* An advantage of floor is that it works even if the driver doesn't add
* 0.5. It is somewhat questionable if 1.5, 2.5, ... are the proper values
* to return in gl_FragCoord, even though coordinates specify the pixel
* centers instead of the pixel corners. This code will behave correctly
* on drivers that returns integer values. */
"vpos = floor(vec4(0, ycorrection[0], 0, 0) + gl_FragCoord * vec4(1, ycorrection[1], 1, 1));\n");
}
/*****************************************************************************
* Functions to generate GLSL strings from DirectX Shader bytecode begin here.
*
* For more information, see http://wiki.winehq.org/DirectX-Shaders
****************************************************************************/
/* Prototypes */
/** Used for opcode modifiers - They multiply the result by the specified amount */
static const char * const shift_glsl_tab[] = {
"", /* 0 (none) */
"2.0 * ", /* 1 (x2) */
"4.0 * ", /* 2 (x4) */
"8.0 * ", /* 3 (x8) */
"16.0 * ", /* 4 (x16) */
"32.0 * ", /* 5 (x32) */
"", /* 6 (x64) */
"", /* 7 (x128) */
"", /* 8 (d256) */
"", /* 9 (d128) */
"", /* 10 (d64) */
"", /* 11 (d32) */
"0.0625 * ", /* 12 (d16) */
"0.125 * ", /* 13 (d8) */
"0.25 * ", /* 14 (d4) */
"0.5 * " /* 15 (d2) */
};
/* Generate a GLSL parameter that does the input modifier computation and return the input register/mask to use */
{
out_str[0] = 0;
switch (src_modifier)
{
case WINED3DSPSM_DZ: /* Need to handle this in the instructions itself (texld & texcrd). */
case WINED3DSPSM_DW:
case WINED3DSPSM_NONE:
break;
case WINED3DSPSM_NEG:
break;
case WINED3DSPSM_NOT:
break;
case WINED3DSPSM_BIAS:
break;
case WINED3DSPSM_BIASNEG:
break;
case WINED3DSPSM_SIGN:
break;
case WINED3DSPSM_SIGNNEG:
break;
case WINED3DSPSM_COMP:
break;
case WINED3DSPSM_X2:
break;
case WINED3DSPSM_X2NEG:
break;
case WINED3DSPSM_ABS:
break;
case WINED3DSPSM_ABSNEG:
break;
default:
}
}
/** Writes the GLSL variable name that corresponds to the register that the
* DX opcode parameter is trying to access */
{
/* oPos, oFog and oPts in D3D */
{
case WINED3DSPR_TEMP:
break;
case WINED3DSPR_INPUT:
/* vertex shaders */
{
break;
}
{
{
else
}
else
break;
}
/* pixel shaders >= 3.0 */
{
{
/* Removing a + 0 would be an obvious optimization, but
* OS X doesn't see the NOP operation there. */
if (idx)
{
{
"((%s + %u) > %u ? (%s + %u) > %u ? gl_SecondaryColor : gl_Color : %s_in[%s + %u])",
}
else
{
}
}
else
{
{
}
else
{
}
}
}
else
{
}
}
else
{
else
break;
}
break;
case WINED3DSPR_CONST:
{
/* Relative addressing */
{
else
}
else
{
else
}
}
break;
case WINED3DSPR_CONSTINT:
break;
case WINED3DSPR_CONSTBOOL:
break;
case WINED3DSPR_TEXTURE: /* case WINED3DSPR_ADDR: */
else
break;
case WINED3DSPR_LOOP:
break;
case WINED3DSPR_SAMPLER:
break;
case WINED3DSPR_COLOROUT:
WARN("Write to render target %u, only %d supported.\n",
break;
case WINED3DSPR_RASTOUT:
break;
case WINED3DSPR_DEPTHOUT:
break;
case WINED3DSPR_ATTROUT:
else
break;
case WINED3DSPR_TEXCRDOUT:
/* Vertex shaders >= 3.0: WINED3DSPR_OUTPUT */
break;
case WINED3DSPR_MISCTYPE:
{
/* vPos */
}
{
/* Note that gl_FrontFacing is a bool, while vFace is
}
else
{
}
break;
case WINED3DSPR_IMMCONST:
switch (reg->immconst_type)
{
case WINED3D_IMMCONST_SCALAR:
{
case WINED3D_DATA_FLOAT:
break;
case WINED3D_DATA_INT:
break;
case WINED3D_DATA_RESOURCE:
case WINED3D_DATA_SAMPLER:
case WINED3D_DATA_UINT:
break;
default:
break;
}
break;
case WINED3D_IMMCONST_VEC4:
{
case WINED3D_DATA_FLOAT:
break;
case WINED3D_DATA_INT:
break;
case WINED3D_DATA_RESOURCE:
case WINED3D_DATA_SAMPLER:
case WINED3D_DATA_UINT:
break;
default:
break;
}
break;
default:
}
break;
case WINED3DSPR_CONSTBUFFER:
else
break;
case WINED3DSPR_PRIMID:
break;
default:
break;
}
}
{
*str++ = '.';
*str = '\0';
}
/* Get the GLSL write mask for the destination register */
static DWORD shader_glsl_get_write_mask(const struct wined3d_shader_dst_param *param, char *write_mask)
{
{
*write_mask = '\0';
}
else
{
}
return mask;
}
unsigned int size = 0;
return size;
}
{
/* For registers of type WINED3DDECLTYPE_D3DCOLOR, data is stored as "bgra",
* but addressed as "rgba". To fix this we need to swap the register's x
* and z components. */
*str++ = '.';
/* swizzle bits fields: wwzzyyxx */
*str = '\0';
}
{
*swizzle_str = '\0';
else
}
/* From a given parameter token, generate the corresponding GLSL string.
* Also, return the actual register name and swizzle in case the
* caller needs this information as well. */
{
char swizzle_str[6];
swizzle_str[0] = '\0';
{
shader_glsl_gen_modifier(wined3d_src->modifiers, glsl_src->reg_name, swizzle_str, glsl_src->param_str);
}
else
{
char param_str[200];
{
case WINED3D_DATA_FLOAT:
break;
case WINED3D_DATA_INT:
break;
case WINED3D_DATA_RESOURCE:
case WINED3D_DATA_SAMPLER:
case WINED3D_DATA_UINT:
break;
default:
break;
}
}
}
/* From a given parameter token, generate the corresponding GLSL string.
* Also, return the actual register name and swizzle in case the
* caller needs this information as well. */
{
}
/* Append the destination part of the instruction to the buffer, return the effective write mask */
{
struct glsl_dst_param glsl_dst;
{
{
case WINED3D_DATA_FLOAT:
break;
case WINED3D_DATA_INT:
break;
case WINED3D_DATA_RESOURCE:
case WINED3D_DATA_SAMPLER:
case WINED3D_DATA_UINT:
break;
default:
break;
}
}
return mask;
}
/* Append the destination part of the instruction to the buffer, return the effective write mask */
static DWORD shader_glsl_append_dst(struct wined3d_shader_buffer *buffer, const struct wined3d_shader_instruction *ins)
{
}
/** Process GLSL instruction modifiers */
{
struct glsl_dst_param dst_param;
if (!modifiers) return;
if (modifiers & WINED3DSPDM_SATURATE)
{
/* _SAT means to clamp the value of the register to between 0 and 1 */
}
{
FIXME("_centroid modifier not handled\n");
}
{
/* MSDN says this modifier can be safely ignored, so that's what we'll do. */
}
}
{
switch (op)
{
case WINED3D_SHADER_REL_OP_GT: return ">";
case WINED3D_SHADER_REL_OP_EQ: return "==";
case WINED3D_SHADER_REL_OP_GE: return ">=";
case WINED3D_SHADER_REL_OP_LT: return "<";
case WINED3D_SHADER_REL_OP_NE: return "!=";
case WINED3D_SHADER_REL_OP_LE: return "<=";
default:
return "(\?\?)";
}
}
{
&& (((const struct shader_glsl_ctx_priv *)ctx->backend_data)->cur_ps_args->shadow & (1 << sampler_idx));
/* Note that there's no such thing as a projected cube texture. */
switch(sampler_type) {
case WINED3DSTT_1D:
if (shadow)
{
if (lod)
{
}
else if (grad)
{
else
{
FIXME("Unsupported 1D shadow grad function.\n");
}
}
else
{
}
}
else
{
if (lod)
{
}
else if (grad)
{
else
{
FIXME("Unsupported 1D grad function.\n");
}
}
else
{
}
}
break;
case WINED3DSTT_2D:
if (shadow)
{
if (texrect)
{
if (lod)
{
}
else if (grad)
{
else
{
FIXME("Unsupported RECT shadow grad function.\n");
}
}
else
{
}
}
else
{
if (lod)
{
}
else if (grad)
{
else
{
FIXME("Unsupported 2D shadow grad function.\n");
}
}
else
{
}
}
sample_function->coord_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
}
else
{
if (texrect)
{
if (lod)
{
}
else if (grad)
{
else
{
FIXME("Unsupported RECT grad function.\n");
}
}
else
{
}
}
else
{
if (lod)
{
}
else if (grad)
{
else
{
FIXME("Unsupported 2D grad function.\n");
}
}
else
{
}
}
}
break;
case WINED3DSTT_CUBE:
if (shadow)
{
FIXME("Unsupported Cube shadow function.\n");
sample_function->coord_mask = 0;
}
else
{
if (lod)
{
}
else if (grad)
{
else
{
FIXME("Unsupported Cube grad function.\n");
}
}
else
{
}
sample_function->coord_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
}
break;
case WINED3DSTT_VOLUME:
if (shadow)
{
FIXME("Unsupported 3D shadow function.\n");
sample_function->coord_mask = 0;
}
else
{
if (lod)
{
}
else if (grad)
{
else
{
FIXME("Unsupported 3D grad function.\n");
}
}
else
{
}
sample_function->coord_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
}
break;
default:
sample_function->coord_mask = 0;
break;
}
}
{
switch(channel_source)
{
case CHANNEL_SOURCE_ZERO:
break;
case CHANNEL_SOURCE_ONE:
break;
case CHANNEL_SOURCE_X:
break;
case CHANNEL_SOURCE_Y:
break;
case CHANNEL_SOURCE_Z:
break;
case CHANNEL_SOURCE_W:
break;
default:
break;
}
}
{
DWORD fixup_mask = 0;
char arguments[256];
char mask_str[6];
if (!(mask &= fixup_mask))
return;
if (is_complex_fixup(fixup))
{
return;
}
arguments[0] = '\0';
if (mask & WINED3DSP_WRITEMASK_0)
{
}
if (mask & WINED3DSP_WRITEMASK_1)
{
}
if (mask & WINED3DSP_WRITEMASK_2)
{
}
if (mask & WINED3DSP_WRITEMASK_3)
{
}
if (mask_size > 1)
else
}
static void shader_glsl_color_correction(const struct wined3d_shader_instruction *ins, struct color_fixup_desc fixup)
{
char reg_name[256];
}
static void PRINTF_ATTR(8, 9) shader_glsl_gen_sample_code(const struct wined3d_shader_instruction *ins,
{
char dst_swizzle[6];
struct color_fixup_desc fixup;
{
if(bias) {
FIXME("Biased sampling from NP2 textures is unsupported\n");
} else {
}
}
}
else
{
}
if(bias) {
} else {
if (np2_fixup) {
} else {
}
}
if(!is_identity_fixup(fixup)) {
}
}
/*****************************************************************************
* Begin processing individual instruction opcodes
****************************************************************************/
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
const char *op;
/* Determine the GLSL operator to use based on the opcode */
switch (ins->handler_idx)
{
default:
op = "<unhandled operator>";
break;
}
}
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
unsigned int mask_size;
const char *op;
if (mask_size > 1)
{
switch (ins->handler_idx)
{
default:
op = "<unhandled operator>";
break;
}
}
else
{
switch (ins->handler_idx)
{
default:
op = "<unhandled operator>";
break;
}
}
}
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
/* If we have ARB_gpu_shader5 or GLSL 4.0, we can use imulExtended(). If
* not, we can emulate it. */
FIXME("64-bit integer multiplies not implemented.\n");
{
}
}
{
{
{
char dst_mask[6];
}
else
{
}
}
{
}
}
/* Process the WINED3DSIO_MOV opcode using GLSL (dst = src) */
{
struct glsl_src_param src0_param;
/* In vs_1_1 WINED3DSIO_MOV can write to the address register. In later
* shader versions WINED3DSIO_MOVA is used for this. */
{
/* This is a simple floor() */
if (mask_size > 1) {
} else {
}
}
{
/* We need to *round* to the nearest int here. */
{
if (mask_size > 1)
else
}
else
{
if (mask_size > 1)
else
}
}
else
{
}
}
/* Process the dot product operators DP3 and DP4 in GLSL (dst = dot(src0, src1)) */
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
unsigned int dst_size = 0;
/* dp3 works on vec3, dp4 on vec4 */
{
} else {
}
if (dst_size > 1) {
shader_addline(buffer, "vec%d(dot(%s, %s)));\n", dst_size, src0_param.param_str, src1_param.param_str);
} else {
}
}
/* Note that this instruction has some restrictions. The destination write mask
* can't contain the w component, and the source swizzles have to be .xyzw */
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
char dst_mask[6];
shader_addline(ins->ctx->buffer, "cross(%s, %s)%s);\n", src0_param.param_str, src1_param.param_str, dst_mask);
}
{
}
/* Process the WINED3DSIO_POW instruction in GLSL (dst = |src0|^src1)
* Src0 and src1 are scalars. Note that D3D uses the absolute of src0, while
* GLSL uses the value as-is. */
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
unsigned int dst_size;
if (dst_size > 1)
{
}
else
{
}
}
/* Process the WINED3DSIO_LOG instruction in GLSL (dst = log2(|src0|))
* Src0 is a scalar. Note that D3D uses the absolute of src0, while
* GLSL uses the value as-is. */
{
struct glsl_src_param src0_param;
unsigned int dst_size;
if (dst_size > 1)
{
}
else
{
}
}
/* Map the opcode 1-to-1 to the GL code (arg->dst = instruction(src0, src1, ...) */
{
struct glsl_src_param src_param;
const char *instruction;
unsigned i;
/* Determine the GLSL function to use based on the opcode */
/* TODO: Possibly make this a table for faster lookups */
switch (ins->handler_idx)
{
default: instruction = "";
break;
}
{
{
}
}
}
{
struct glsl_src_param src_param;
unsigned int mask_size;
char dst_mask[6];
if (mask_size > 1)
{
}
else
{
}
}
/** Process the WINED3DSIO_EXPP instruction in GLSL:
* For shader model 1.x, do the following (and honor the writemask, so use a temporary variable):
* dst.x = 2^(floor(src))
* dst.y = src - floor(src)
* dst.z = 2^src (partial precision is allowed, but optional)
* dst.w = 1.0;
* For 2.0 shaders, just do this (honoring writemask and swizzle):
* dst = 2^src; (partial precision is allowed, but optional)
*/
{
struct glsl_src_param src_param;
{
char dst_mask[6];
shader_addline(ins->ctx->buffer, "tmp0.y = %s - floor(%s);\n", src_param.param_str, src_param.param_str);
} else {
unsigned int mask_size;
if (mask_size > 1) {
} else {
}
}
}
{
struct glsl_src_param src_param;
unsigned int mask_size;
if (mask_size > 1)
else
}
{
struct glsl_src_param src_param;
unsigned int mask_size;
if (mask_size > 1)
else
}
/** Process the RCP (reciprocal or inverse) opcode in GLSL (dst = 1 / src) */
{
struct glsl_src_param src_param;
unsigned int mask_size;
if (mask_size > 1)
{
}
else
{
}
}
{
struct glsl_src_param src_param;
unsigned int mask_size;
if (mask_size > 1)
{
}
else
{
}
}
/** Process signed comparison opcodes in GLSL. */
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
unsigned int mask_size;
if (mask_size > 1) {
const char *compare;
switch(ins->handler_idx)
{
default: compare = "";
}
} else {
switch(ins->handler_idx)
{
case WINED3DSIH_SLT:
/* Step(src0, src1) is not suitable here because if src0 == src1 SLT is supposed,
* to return 0.0 but step returns 1.0 because step is not < x
* An alternative is a bvec compare padded with an unused second component.
* step(src1 * -1.0, src0 * -1.0) is not an option because it suffers from the same
* issue. Playing with not() is not possible either because not() does not accept
* a scalar.
*/
break;
case WINED3DSIH_SGE:
/* Here we can use the step() function and safe a conditional */
break;
default:
}
}
}
{
const char *condition_prefix, *condition_suffix;
struct wined3d_shader_dst_param dst;
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
struct glsl_src_param src2_param;
DWORD cmp_channel = 0;
unsigned int i, j;
char mask_char[6];
switch (ins->handler_idx)
{
case WINED3DSIH_CMP:
condition_prefix = "";
condition_suffix = " >= 0.0";
break;
case WINED3DSIH_CND:
condition_prefix = "";
condition_suffix = " > 0.5";
break;
case WINED3DSIH_MOVC:
condition_prefix = "bool(";
condition_suffix = ")";
break;
default:
condition_prefix = "<unhandled prefix>";
condition_suffix = "<unhandled suffix>";
break;
}
{
return;
}
/* Splitting the instruction up in multiple lines imposes a problem:
* The first lines may overwrite source parameters of the following lines.
* Deal with that by using a temporary destination register if needed. */
/* Cycle through all source0 channels. */
for (i = 0; i < 4; ++i)
{
write_mask = 0;
/* Find the destination channels which use the current source0 channel. */
for (j = 0; j < 4; ++j)
{
{
write_mask |= WINED3DSP_WRITEMASK_0 << j;
cmp_channel = WINED3DSP_WRITEMASK_0 << j;
}
}
if (temp_destination)
{
continue;
}
continue;
}
if (temp_destination)
{
}
}
/** Process the CND opcode in GLSL (dst = (src0 > 0.5) ? src1 : src2) */
/* For ps 1.1-1.3, only a single component of src0 is used. For ps 1.4
* the compare is done per component of src0. */
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
struct glsl_src_param src2_param;
{
/* Fun: The D3DSI_COISSUE flag changes the semantic of the cnd instruction for < 1.4 shaders */
{
} else {
}
return;
}
}
/** GLSL code generation for WINED3DSIO_MAD: Multiply the first 2 opcodes, then add the last */
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
struct glsl_src_param src2_param;
}
/* Handles transforming all WINED3DSIO_M?x? opcodes for
Vertex shaders to GLSL codes */
{
int i;
int nComponents = 0;
struct wined3d_shader_dst_param tmp_dst = {{0}};
struct wined3d_shader_instruction tmp_ins;
/* Set constants for the temporary argument */
switch(ins->handler_idx)
{
case WINED3DSIH_M4x4:
nComponents = 4;
break;
case WINED3DSIH_M4x3:
nComponents = 3;
break;
case WINED3DSIH_M3x4:
nComponents = 4;
break;
case WINED3DSIH_M3x3:
nComponents = 3;
break;
case WINED3DSIH_M3x2:
nComponents = 2;
break;
default:
break;
}
for (i = 0; i < nComponents; ++i)
{
}
}
/**
The LRP instruction performs a component-wise linear interpolation
between the second and third operands using the first operand as the
blend factor. Equation: (dst = src2 + src0 * (src1 - src2))
This is equivalent to mix(src2, src1, src0);
*/
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
struct glsl_src_param src2_param;
}
/** Process the WINED3DSIO_LIT instruction in GLSL:
* dst.x = dst.w = 1.0
* dst.y = (src0.x > 0) ? src0.x
* dst.z = (src0.x > 0) ? ((src0.y > 0) ? pow(src0.y, src.w) : 0) : 0
* where src.w is clamped at +- 128
*/
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
struct glsl_src_param src3_param;
char dst_mask[6];
/* The sdk specifies the instruction like this
* dst.x = 1.0;
* if(src.x > 0.0) dst.y = src.x
* else dst.y = 0.0.
* if(src.x > 0.0 && src.y > 0.0) dst.z = pow(src.y, power);
* else dst.z = 0.0;
* dst.w = 1.0;
* (where power = src.w clamped between -128 and 128)
*
* Obviously that has quite a few conditionals in it which we don't like. So the first step is this:
* dst.x = 1.0 ... No further explanation needed
* dst.y = max(src.y, 0.0); ... If x < 0.0, use 0.0, otherwise x. Same as the conditional
* dst.z = x > 0.0 ? pow(max(y, 0.0), p) : 0; ... 0 ^ power is 0, and otherwise we use y anyway
* dst.w = 1.0. ... Nothing fancy.
*
* So we still have one conditional in there. So do this:
* dst.z = pow(max(0.0, src.y) * step(0.0, src.x), power);
*
* step(0.0, x) will return 1 if src.x > 0.0, and 0 otherwise. So if y is 0 we get pow(0.0 * 1.0, power),
* which sets dst.z to 0. If y > 0, but x = 0.0, we get pow(y * 0.0, power), which results in 0 too.
* if both x and y are > 0, we get pow(y * 1.0, power), as it is supposed to.
*
* Unfortunately pow(0.0 ^ 0.0) returns NaN on most GPUs, but lit with src.y = 0 and src.w = 0 returns
* a non-NaN value in dst.z. What we return doesn't matter, as long as it is not NaN. Return 0, which is
* what all Windows HW drivers and GL_ARB_vertex_program's LIT do.
*/
"vec4(1.0, max(%s, 0.0), %s == 0.0 ? 0.0 : "
"pow(max(0.0, %s) * step(0.0, %s), clamp(%s, -128.0, 128.0)), 1.0)%s);\n",
}
/** Process the WINED3DSIO_DST instruction in GLSL:
* dst.x = 1.0
* dst.y = src0.x * src0.y
* dst.z = src0.z
* dst.w = src1.w
*/
{
struct glsl_src_param src0y_param;
struct glsl_src_param src0z_param;
struct glsl_src_param src1y_param;
struct glsl_src_param src1w_param;
char dst_mask[6];
src0y_param.param_str, src1y_param.param_str, src0z_param.param_str, src1w_param.param_str, dst_mask);
}
/** Process the WINED3DSIO_SINCOS instruction in GLSL:
* VS 2.0 requires that specific cosine and sine constants be passed to this instruction so the hardware
* can handle it. But, these functions are built-in for GLSL, so we can just ignore the last 2 params.
*
* dst.x = cos(src0.?)
* dst.y = sin(src0.?)
* dst.z = dst.z
* dst.w = dst.w
*/
{
struct glsl_src_param src0_param;
{
switch (write_mask)
{
case WINED3DSP_WRITEMASK_0:
break;
case WINED3DSP_WRITEMASK_1:
break;
case (WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1):
break;
default:
ERR("Write mask should be .x, .y or .xy\n");
break;
}
return;
}
{
{
char dst_mask[6];
}
else
{
}
}
{
}
}
/* sgn in vs_2_0 has 2 extra parameters(registers for temporary storage) which we don't use
* here. But those extra parameters require a dedicated function for sgn, since map2gl would
* generate invalid code
*/
{
struct glsl_src_param src0_param;
}
/** Process the WINED3DSIO_LOOP instruction in GLSL:
* Start a for() loop where src1.y is the initial value of aL,
* increment aL by src1.z for a total of src1.x iterations.
* Need to use a temporary variable for this operation.
*/
/* FIXME: I don't think nested loops will work correctly this way. */
{
const struct wined3d_shader_lconst *constant;
struct glsl_src_param src1_param;
{
/* Try to hardcode the loop control parameters if possible. Direct3D 9
* class hardware doesn't support real varying indexing, but Microsoft
* designed this feature for Shader model 2.x+. If the loop control is
* known at compile time, the GLSL compiler can unroll the loop, and
* replace indirect addressing with direct addressing. */
{
{
{
break;
}
}
}
if (control_values)
{
if (loop_control.step > 0)
{
}
else if (loop_control.step < 0)
{
}
else
{
}
}
else
{
shader_addline(buffer, "for (tmpInt%u = 0, aL%u = %s.y; tmpInt%u < %s.x; tmpInt%u++, aL%u += %s.z)\n{\n",
}
}
else
{
}
}
{
{
}
{
}
}
{
const struct wined3d_shader_lconst *constant;
struct glsl_src_param src0_param;
/* Try to hardcode local values to help the GLSL compiler to unroll and optimize the loop */
{
{
{
break;
}
}
}
if (control_values)
{
}
else
{
}
}
{
struct glsl_src_param src0_param;
}
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
}
{
}
{
}
{
}
/* FIXME: According to MSDN the compare is done per component. */
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
}
{
struct glsl_src_param src_param;
}
{
}
{
}
{
struct glsl_src_param src1_param;
}
{
/* No-op. The closing } is written when a new function is started, and at the end of the shader. This
* function only suppresses the unhandled instruction warning
*/
}
/*********************************************
* Pixel Shader Specific Code begins here
********************************************/
{
struct glsl_sample_function sample_function;
DWORD sample_flags = 0;
/* 1.0-1.4: Use destination register as sampler source.
* 2.0+: Use provided sampler source. */
else
{
/* Projected cube textures don't make a lot of sense, the resulting coordinates stay the same. */
{
switch (flags & ~WINED3D_PSARGS_PROJECTED)
{
case WINED3D_TTFF_COUNT1:
FIXME("WINED3D_TTFF_PROJECTED with WINED3D_TTFF_COUNT1?\n");
break;
case WINED3D_TTFF_COUNT2:
break;
case WINED3D_TTFF_COUNT3:
break;
case WINED3D_TTFF_COUNT4:
case WINED3D_TTFF_DISABLE:
break;
}
}
}
{
if (src_mod == WINED3DSPSM_DZ) {
} else if (src_mod == WINED3DSPSM_DW) {
}
}
else
{
{
/* ps 2.0 texldp instruction always divides by the fourth component. */
}
}
/* 1.0-1.3: Use destination register as coordinate source.
1.4+: Use provided coordinate source register. */
{
char coord_mask[6];
}
else
{
struct glsl_src_param coord_param;
{
struct glsl_src_param bias;
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, NULL, bias.param_str,
} else {
}
}
}
{
struct glsl_sample_function sample_function;
{
FIXME("texldd used, but not supported by hardware. Falling back to regular tex\n");
return;
}
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, dx_param.param_str, dy_param.param_str, NULL,
}
{
struct glsl_sample_function sample_function;
{
/* Plain GLSL only supports Lod sampling functions in vertex shaders.
* However, the NVIDIA drivers allow them in fragment shaders as well,
* even without the appropriate extension. */
}
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, NULL, lod_param.param_str,
}
{
/* FIXME: Make this work for more than just 2D textures */
if (!(ins->ctx->reg_maps->shader_version.major == 1 && ins->ctx->reg_maps->shader_version.minor == 4))
{
char dst_mask[6];
}
else
{
char dst_swizzle[6];
if (src_mod == WINED3DSPSM_DZ)
{
struct glsl_src_param div_param;
if (mask_size > 1) {
shader_addline(buffer, "gl_TexCoord[%u]%s / vec%d(%s));\n", reg, dst_swizzle, mask_size, div_param.param_str);
} else {
}
}
else if (src_mod == WINED3DSPSM_DW)
{
struct glsl_src_param div_param;
if (mask_size > 1) {
shader_addline(buffer, "gl_TexCoord[%u]%s / vec%d(%s));\n", reg, dst_swizzle, mask_size, div_param.param_str);
} else {
}
} else {
}
}
}
/** Process the WINED3DSIO_TEXDP3TEX instruction in GLSL:
* Take a 3-component dot product of the TexCoord[dstreg] and src,
* then perform a 1D texture lookup from stage dstregnum, place into dst. */
{
struct glsl_sample_function sample_function;
struct glsl_src_param src0_param;
/* Do I have to take care about the projected bit? I don't think so, since the dp3 returns only one
* scalar, and projected sampling would require 4.
*
* It is a dependent read - not valid with conditional NP2 textures
*/
switch(mask_size)
{
case 1:
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
break;
case 2:
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
break;
case 3:
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
break;
default:
break;
}
}
/** Process the WINED3DSIO_TEXDP3 instruction in GLSL:
* Take a 3-component dot product of the TexCoord[dstreg] and src. */
{
struct glsl_src_param src0_param;
unsigned int mask_size;
if (mask_size > 1) {
shader_addline(ins->ctx->buffer, "vec%d(dot(T%u.xyz, %s)));\n", mask_size, dstreg, src0_param.param_str);
} else {
}
}
/** Process the WINED3DSIO_TEXDEPTH instruction in GLSL:
* Calculate the depth as dst.x / dst.y */
{
struct glsl_dst_param dst_param;
/* Tests show that texdepth never returns anything below 0.0, and that r5.y is clamped to 1.0.
* Negative input is accepted, -0.25 / -0.5 returns 0.5. GL should clamp gl_FragDepth to [0;1], but
* this doesn't always work, so clamp the results manually. Whether or not the x value is clamped at 1
* too is irrelevant, since if x = 0, any y value < 1.0 (and > 1.0 is not allowed) results in a result
* >= 1.0 or < 0.0
*/
}
/** Process the WINED3DSIO_TEXM3X2DEPTH instruction in GLSL:
* Last row of a 3x2 matrix multiply, use the result to calculate the depth:
* Calculate tmp0.y = TexCoord[dstreg] . src.xyz; (tmp0.x has already been calculated)
* depth = (tmp0.y == 0.0) ? 1.0 : tmp0.x / tmp0.y
*/
{
struct glsl_src_param src0_param;
shader_addline(ins->ctx->buffer, "gl_FragDepth = (tmp0.y == 0.0) ? 1.0 : clamp(tmp0.x / tmp0.y, 0.0, 1.0);\n");
}
/** Process the WINED3DSIO_TEXM3X2PAD instruction in GLSL
* Calculate the 1st of a 2-row matrix multiplication. */
{
struct glsl_src_param src0_param;
}
/** Process the WINED3DSIO_TEXM3X3PAD instruction in GLSL
* Calculate the 1st or 2nd row of a 3-row matrix multiplication. */
{
struct glsl_src_param src0_param;
shader_addline(buffer, "tmp0.%c = dot(T%u.xyz, %s);\n", 'x' + tex_mx->current_row, reg, src0_param.param_str);
}
{
struct glsl_sample_function sample_function;
struct glsl_src_param src0_param;
/* Sample the texture using the calculated coordinates */
shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, "tmp0.xy");
}
/** Process the WINED3DSIO_TEXM3X3TEX instruction in GLSL
* Perform the 3rd row of a 3x3 matrix multiply, then sample the texture using the calculated coordinates */
{
struct glsl_sample_function sample_function;
struct glsl_src_param src0_param;
/* Dependent read, not valid with conditional NP2 */
/* Sample the texture using the calculated coordinates */
shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, "tmp0.xyz");
tex_mx->current_row = 0;
}
/** Process the WINED3DSIO_TEXM3X3 instruction in GLSL
* Perform the 3rd row of a 3x3 matrix multiply */
{
struct glsl_src_param src0_param;
char dst_mask[6];
shader_addline(ins->ctx->buffer, "vec4(tmp0.xy, dot(T%u.xyz, %s), 1.0)%s);\n", reg, src0_param.param_str, dst_mask);
tex_mx->current_row = 0;
}
/* Process the WINED3DSIO_TEXM3X3SPEC instruction in GLSL
* Perform the final texture lookup based on the previous 2 3x3 matrix multiplies */
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
struct glsl_sample_function sample_function;
char coord_mask[6];
/* Perform the last matrix multiply operation */
/* Reflection calculation */
/* Dependent read, not valid with conditional NP2 */
/* Sample the texture */
tex_mx->current_row = 0;
}
/* Process the WINED3DSIO_TEXM3X3VSPEC instruction in GLSL
* Perform the final texture lookup based on the previous 2 3x3 matrix multiplies */
{
struct glsl_sample_function sample_function;
struct glsl_src_param src0_param;
char coord_mask[6];
/* Perform the last matrix multiply operation */
/* Construct the eye-ray vector from w coordinates */
shader_addline(buffer, "tmp1.xyz = normalize(vec3(gl_TexCoord[%u].w, gl_TexCoord[%u].w, gl_TexCoord[%u].w));\n",
/* Dependent read, not valid with conditional NP2 */
/* Sample the texture using the calculated coordinates */
tex_mx->current_row = 0;
}
/** Process the WINED3DSIO_TEXBEM instruction in GLSL.
* Apply a fake bump map transform.
* texbem is pshader <= 1.3 only, this saves a few version checks
*/
{
struct glsl_sample_function sample_function;
struct glsl_src_param coord_param;
char coord_mask[6];
/* Dependent read, not valid with conditional NP2 */
/* With projected textures, texbem only divides the static texture coord,
* not the displacement, so we can't let GL handle this. */
if (flags & WINED3D_PSARGS_PROJECTED)
{
char coord_div_mask[3];
switch (flags & ~WINED3D_PSARGS_PROJECTED)
{
case WINED3D_TTFF_COUNT1:
FIXME("WINED3D_TTFF_PROJECTED with WINED3D_TTFF_COUNT1?\n");
break;
case WINED3D_TTFF_COUNT2:
break;
case WINED3D_TTFF_COUNT3:
break;
case WINED3D_TTFF_COUNT4:
case WINED3D_TTFF_DISABLE:
break;
}
shader_addline(ins->ctx->buffer, "T%u%s /= T%u%s;\n", sampler_idx, coord_mask, sampler_idx, coord_div_mask);
}
shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &coord_param);
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
{
struct glsl_src_param luminance_param;
struct glsl_dst_param dst_param;
}
}
{
shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src0_param);
shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src1_param);
}
/** Process the WINED3DSIO_TEXREG2AR instruction in GLSL
* Sample 2D texture at dst using the alpha & red (wx) components of src as texture coordinates */
{
struct glsl_sample_function sample_function;
struct glsl_src_param src0_param;
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
}
/** Process the WINED3DSIO_TEXREG2GB instruction in GLSL
* Sample 2D texture at dst using the green & blue (yz) components of src as texture coordinates */
{
struct glsl_sample_function sample_function;
struct glsl_src_param src0_param;
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
}
/** Process the WINED3DSIO_TEXREG2RGB instruction in GLSL
* Sample texture at dst using the rgb (xyz) components of src as texture coordinates */
{
struct glsl_sample_function sample_function;
struct glsl_src_param src0_param;
/* Dependent read, not valid with conditional NP2 */
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
}
/** Process the WINED3DSIO_TEXKILL instruction in GLSL.
* If any of the first 3 components are < 0, discard this pixel */
{
struct glsl_dst_param dst_param;
/* The argument is a destination parameter, and no writemasks are allowed */
{
/* 2.0 shaders compare all 4 components in texkill */
shader_addline(ins->ctx->buffer, "if (any(lessThan(%s.xyzw, vec4(0.0)))) discard;\n", dst_param.reg_name);
} else {
/* 1.X shaders only compare the first 3 components, probably due to the nature of the texkill
* instruction as a tex* instruction, and phase, which kills all a / w components. Even if all
* 4 components are defined, only the first 3 are used
*/
shader_addline(ins->ctx->buffer, "if (any(lessThan(%s.xyz, vec3(0.0)))) discard;\n", dst_param.reg_name);
}
}
/** Process the WINED3DSIO_DP2ADD instruction in GLSL.
* dst = dot2(src0, src1) + src2 */
{
struct glsl_src_param src0_param;
struct glsl_src_param src1_param;
struct glsl_src_param src2_param;
unsigned int mask_size;
shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src0_param);
shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src1_param);
if (mask_size > 1) {
} else {
}
}
static void shader_glsl_input_pack(const struct wined3d_shader *shader, struct wined3d_shader_buffer *buffer,
const struct wined3d_shader_signature_element *input_signature,
const struct wined3d_shader_reg_maps *reg_maps,
{
unsigned int i;
{
const char *semantic_name;
char reg_mask[6];
/* Unused */
if (!(map & 1)) continue;
{
else
}
{
if (!semantic_idx)
else if (semantic_idx == 1)
else
}
else
{
}
}
}
/*********************************************
* Vertex Shader Specific Code begins here
********************************************/
static void add_glsl_program_entry(struct shader_glsl_priv *priv, struct glsl_shader_prog_link *entry)
{
struct glsl_program_key key;
{
ERR("Failed to insert program entry.\n");
}
}
{
struct wine_rb_entry *entry;
struct glsl_program_key key;
return entry ? WINE_RB_ENTRY_VALUE(entry, struct glsl_shader_prog_link, program_lookup_entry) : NULL;
}
#endif
/* Context activation is done by the caller. */
static void delete_glsl_program_entry(struct shader_glsl_priv *priv, const struct wined3d_gl_info *gl_info,
struct glsl_shader_prog_link *entry
, struct wined3d_context *context
#endif
)
{
struct glsl_program_key key;
{
}
#endif
}
const struct wined3d_shader_signature_element *input_signature,
const struct wined3d_shader_reg_maps *reg_maps_in,
const struct wined3d_shader_signature_element *output_signature,
const struct wined3d_shader_reg_maps *reg_maps_out)
{
unsigned int i, j;
const char *semantic_name_in;
char reg_mask[6];
char destination[50];
{
if (!(input_map & 1)) continue;
/* Declared, but not read register */
if (in_idx == ~0U) continue;
{
FIXME("More input varyings declared than supported, expect issues.\n");
continue;
}
else
{
if (!(output_map & 1)
continue;
}
}
for (i = 0; i < in_count + 2; ++i)
{
unsigned int size;
continue;
size = 0;
if (i == in_count)
else if (i == in_count + 1)
else
}
}
/* Context activation is done by the caller. */
const struct wined3d_gl_info *gl_info)
{
GLhandleARB ret = 0;
unsigned int i;
const char *semantic_name;
char reg_mask[6];
if (ps_major < 3)
{
{
if (!(map & 1)) continue;
{
if (!semantic_idx)
else if (semantic_idx == 1)
}
{
}
{
if (semantic_idx < 8)
{
if (!(write_mask & WINED3DSP_WRITEMASK_3))
}
}
{
}
{
}
}
}
else
{
/* This one is tricky: a 3.0 pixel shader reads from a 3.0 vertex shader */
/* First, sort out position and point size. Those are not passed to the pixel shader */
{
if (!(map & 1)) continue;
{
}
{
}
}
/* Then, fix the pixel shader input */
}
checkGLcall("glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB)");
return ret;
}
{
shader_addline(buffer, "bvec3 srgb_compare = lessThan(gl_FragData[0].xyz, vec3(srgb_const1.x));\n");
}
static void shader_glsl_generate_fog_code(struct wined3d_shader_buffer *buffer, enum wined3d_ffp_ps_fog_mode mode)
{
switch (mode)
{
case WINED3D_FFP_PS_FOG_OFF:
return;
/* Fog = (gl_Fog.end - gl_FogFragCoord) / (gl_Fog.end - gl_Fog.start) */
shader_addline(buffer, "float Fog = (gl_Fog.end - gl_FogFragCoord) / (gl_Fog.end - gl_Fog.start);\n");
break;
case WINED3D_FFP_PS_FOG_EXP:
/* Fog = e^-(gl_Fog.density * gl_FogFragCoord) */
break;
case WINED3D_FFP_PS_FOG_EXP2:
/* Fog = e^-((gl_Fog.density * gl_FogFragCoord)^2) */
shader_addline(buffer, "float Fog = exp(-gl_Fog.density * gl_Fog.density * gl_FogFragCoord * gl_FogFragCoord);\n");
break;
default:
return;
}
shader_addline(buffer, "gl_FragData[0].xyz = mix(gl_Fog.color.xyz, gl_FragData[0].xyz, clamp(Fog, 0.0, 1.0));\n");
}
/* Context activation is done by the caller. */
{
struct shader_glsl_ctx_priv priv_ctx;
/* Create the hw GLSL shader object and assign it as the shader->prgId */
/* The spec says that it doesn't have to be explicitly enabled, but the
* nvidia drivers write a warning if we don't do so. */
/* Base Declarations */
/* Pack 3.0 inputs */
/* Base Shader Body */
/* Pixel shaders < 2.0 place the resulting color in R0 implicitly */
{
/* Some older cards like GeforceFX ones don't support multiple buffers, so also not gl_FragData */
}
if (args->srgb_correction)
/* SM < 3 does not replace the fog stage. */
/* Store the shader object */
return shader_obj;
}
/* Context activation is done by the caller. */
const struct vs_compile_args *args)
{
struct shader_glsl_ctx_priv priv_ctx;
/* Create the hw GLSL shader program and assign it as the shader->prgId */
/* Base Declarations */
/* Base Shader Body */
/* Unpack outputs */
/* The D3DRS_FOGTABLEMODE render state defines if the shader-generated fog coord is used
* or if the fragment depth is used. If the fragment depth is used(FOGTABLEMODE != NONE),
* the fog frag coord is thrown away. If the fog frag coord is used, but not written by
* the shader, it is set to 0.0(fully fogged, since start = 1.0, end = 0.0)
*/
/* We always store the clipplanes without y inversion */
if (args->clip_enabled)
/* Write the final position.
*
* OpenGL coordinates specify the center of the pixel while d3d coords specify
* the corner. The offsets are stored in z and w in posFixup. posFixup.y contains
* 1.0 or -1.0 to turn the rendering upside down for offscreen rendering. PosFixup.x
* contains 1.0 to allow a mad.
*/
/* Z coord [0;1]->[-1;1] mapping, see comment in transform_projection in state.c
*
* Basically we want (in homogeneous coordinates) z = z * 2 - 1. However, shaders are run
* before the homogeneous divide, so we have to take the w into account: z = ((z / w) * 2 - 1) * w,
* which is the same as z = z * 2 - w.
*/
return shader_obj;
}
/* Context activation is done by the caller. */
{
struct shader_glsl_ctx_priv priv_ctx;
return shader_id;
}
{
struct glsl_shader_private *shader_data;
struct ps_np2fixup_info *np2fixup;
UINT i;
if (!shader->backend_data)
{
if (!shader->backend_data)
{
ERR("Failed to allocate backend data.\n");
return 0;
}
}
/* Usually we have very few GL shaders for each d3d shader(just 1 or maybe 2),
* so a linear search is more performant than a hashmap or a binary search
* (cache coherency etc)
*/
for (i = 0; i < shader_data->num_gl_shaders; ++i)
{
{
return gl_shaders[i].prgId;
}
}
if (shader_data->num_gl_shaders)
{
new_size * sizeof(*gl_shaders));
}
else
{
new_size = 1;
}
if(!new_array) {
ERR("Out of memory\n");
return 0;
}
}
return ret;
}
static inline BOOL vs_args_equal(const struct vs_compile_args *stored, const struct vs_compile_args *new,
}
const struct vs_compile_args *args)
{
UINT i;
struct glsl_shader_private *shader_data;
if (!shader->backend_data)
{
if (!shader->backend_data)
{
ERR("Failed to allocate backend data.\n");
return 0;
}
}
/* Usually we have very few GL shaders for each d3d shader(just 1 or maybe 2),
* so a linear search is more performant than a hashmap or a binary search
* (cache coherency etc)
*/
for (i = 0; i < shader_data->num_gl_shaders; ++i)
{
return gl_shaders[i].prgId;
}
if (shader_data->num_gl_shaders)
{
new_size * sizeof(*gl_shaders));
}
else
{
new_size = 1;
}
if(!new_array) {
ERR("Out of memory\n");
return 0;
}
}
return ret;
}
{
struct glsl_gs_compiled_shader *gl_shaders;
struct glsl_shader_private *shader_data;
if (!shader->backend_data)
{
{
ERR("Failed to allocate backend data.\n");
return 0;
}
}
if (shader_data->num_gl_shaders)
return gl_shaders[0].id;
{
ERR("Failed to allocate GL shader array.\n");
return 0;
}
return ret;
}
static const char *shader_glsl_ffp_mcs(enum wined3d_material_color_source mcs, const char *material)
{
switch (mcs)
{
case WINED3D_MCS_MATERIAL:
return material;
case WINED3D_MCS_COLOR1:
return "gl_Color";
case WINED3D_MCS_COLOR2:
return "gl_SecondaryColor";
default:
return "<invalid>";
}
}
{
enum wined3d_light_type light_type;
unsigned int i;
{
return;
}
for (i = 0; i < MAX_ACTIVE_LIGHTS; ++i)
{
light_type = (settings->light_type >> WINED3D_FFP_LIGHT_TYPE_SHIFT(i)) & WINED3D_FFP_LIGHT_TYPE_MASK;
switch (light_type)
{
case WINED3D_LIGHT_POINT:
" gl_LightSource[%u].linearAttenuation, gl_LightSource[%u].quadraticAttenuation));\n", i, i, i);
break;
" * gl_LightSource[%u].diffuse.xyz) / att;\n", i);
if (settings->localviewer)
else
" * gl_LightSource[%u].specular) / att;\n", i);
break;
case WINED3D_LIGHT_SPOT:
" / dot(dst.xyz, vec3(gl_LightSource[%u].constantAttenuation,"
" gl_LightSource[%u].linearAttenuation, gl_LightSource[%u].quadraticAttenuation));\n",
i, i, i, i);
break;
" * gl_LightSource[%u].diffuse.xyz) * att;\n", i);
if (settings->localviewer)
else
" * gl_LightSource[%u].specular) * att;\n", i);
break;
break;
shader_addline(buffer, "diffuse += max(0.0, dot(dir, normal)) * gl_LightSource[%u].diffuse.xyz;\n", i);
" * gl_LightSource[%u].specular;\n", i);
break;
default:
if (light_type)
continue;
}
}
}
/* Context activation is done by the caller. */
{
unsigned int i;
else
for (i = 0; i < MAX_TEXTURES; ++i)
{
{
case WINED3DTSS_TCI_PASSTHRU:
i, i, i);
break;
break;
break;
" * vec4(reflect(normalize(ec_pos.xyz), normal), 1.0);\n", i, i);
break;
case WINED3DTSS_TCI_SPHEREMAP:
" * vec4(r.x / m + 0.5, r.y / m + 0.5, 0.0, 1.0);\n", i, i);
break;
default:
break;
}
}
{
case WINED3D_FFP_VS_FOG_OFF:
break;
break;
case WINED3D_FFP_VS_FOG_RANGE:
break;
case WINED3D_FFP_VS_FOG_DEPTH:
break;
default:
break;
}
if (settings->point_size)
{
" + gl_Point.distanceLinearAttenuation * length(ec_pos.xyz)"
" + gl_Point.distanceQuadraticAttenuation * dot(ec_pos.xyz, ec_pos.xyz));\n");
shader_addline(buffer, "gl_PointSize = clamp(gl_PointSize, gl_Point.sizeMin, gl_Point.sizeMax);\n");
}
return shader_obj;
}
{
const char *ret;
if (arg == ARG_UNUSED)
return "<unused arg>";
switch (arg & WINED3DTA_SELECTMASK)
{
case WINED3DTA_DIFFUSE:
ret = "gl_Color";
break;
case WINED3DTA_CURRENT:
if (!stage)
ret = "gl_Color";
else
ret = "ret";
break;
case WINED3DTA_TEXTURE:
switch (stage)
{
case 0: ret = "tex0"; break;
default:
ret = "<invalid texture>";
break;
}
break;
case WINED3DTA_TFACTOR:
ret = "tex_factor";
break;
case WINED3DTA_SPECULAR:
ret = "gl_SecondaryColor";
break;
case WINED3DTA_TEMP:
ret = "temp_reg";
break;
case WINED3DTA_CONSTANT:
FIXME("Per-stage constants not implemented.\n");
switch (stage)
{
case 0: ret = "const0"; break;
default:
ret = "<invalid constant>";
break;
}
break;
default:
return "<unhandled arg>";
}
if (arg & WINED3DTA_COMPLEMENT)
{
if (argnum == 0)
ret = "arg0";
else if (argnum == 1)
ret = "arg1";
else if (argnum == 2)
ret = "arg2";
}
if (arg & WINED3DTA_ALPHAREPLICATE)
{
if (argnum == 0)
ret = "arg0";
else if (argnum == 1)
ret = "arg1";
else if (argnum == 2)
ret = "arg2";
}
return ret;
}
static void shader_glsl_ffp_fragment_op(struct wined3d_shader_buffer *buffer, unsigned int stage, BOOL color,
{
dstmask = "";
else if (color)
dstmask = ".xyz";
else
dstmask = ".w";
dstreg = "temp_reg";
else
dstreg = "ret";
switch (op)
{
case WINED3D_TOP_DISABLE:
if (!stage)
break;
case WINED3D_TOP_SELECT_ARG1:
break;
case WINED3D_TOP_SELECT_ARG2:
break;
case WINED3D_TOP_MODULATE:
break;
case WINED3D_TOP_MODULATE_4X:
break;
case WINED3D_TOP_MODULATE_2X:
break;
case WINED3D_TOP_ADD:
break;
case WINED3D_TOP_ADD_SIGNED:
break;
break;
case WINED3D_TOP_SUBTRACT:
break;
case WINED3D_TOP_ADD_SMOOTH:
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
case WINED3D_TOP_BUMPENVMAP:
/* These are handled in the first pass, nothing to do. */
break;
case WINED3D_TOP_DOTPRODUCT3:
break;
case WINED3D_TOP_MULTIPLY_ADD:
break;
case WINED3D_TOP_LERP:
/* MSDN isn't quite right here. */
break;
default:
break;
}
}
/* Context activation is done by the caller. */
{
const char *final_combiner_src = "ret";
unsigned int stage;
/* Find out which textures are read */
{
break;
tfactor_used = TRUE;
tempreg_used = TRUE;
tempreg_used = TRUE;
{
/* fall through */
case WINED3D_TOP_BUMPENVMAP:
/* fall through */
break;
tfactor_used = TRUE;
break;
default:
break;
}
continue;
tfactor_used = TRUE;
tempreg_used = TRUE;
}
{
continue;
{
case tex_1d:
break;
case tex_2d:
break;
case tex_3d:
break;
case tex_cube:
break;
case tex_rect:
break;
default:
break;
}
continue;
continue;
}
if (tfactor_used)
if (settings->sRGB_write)
{
srgb_cmp);
}
/* Generate texture sampling instructions) */
{
const char *texture_function, *coord_mask;
char tex_reg_name[8];
continue;
{
}
{
}
else
{
}
else
{
case tex_1d:
if (proj)
{
texture_function = "texture1DProj";
coord_mask = "xw";
}
else
{
texture_function = "texture1D";
coord_mask = "x";
}
break;
case tex_2d:
if (proj)
{
texture_function = "texture2DProj";
coord_mask = "xyw";
}
else
{
texture_function = "texture2D";
coord_mask = "xy";
}
break;
case tex_3d:
if (proj)
{
texture_function = "texture3DProj";
coord_mask = "xyzw";
}
else
{
texture_function = "texture3D";
coord_mask = "xyz";
}
break;
case tex_cube:
texture_function = "textureCube";
coord_mask = "xyz";
break;
case tex_rect:
if (proj)
{
texture_function = "texture2DRectProj";
coord_mask = "xyw";
}
else
{
texture_function = "texture2DRect";
coord_mask = "xy";
}
break;
default:
texture_function = "";
coord_mask = "xyzw";
break;
}
if (stage > 0
{
/* With projective textures, texbem only divides the static
* texture coord, not the displacement, so multiply the
* displacement with the dividing parameter before passing it to
* TXP. */
{
{
}
else
{
}
}
else
{
}
if (clamp)
else
shader_addline(buffer, "tex%u *= clamp(tex%u.z * bumpenv_lum_scale%u + bumpenv_lum_offset%u, 0.0, 1.0);\n",
}
{
if (clamp)
else
}
else
{
if (clamp)
else
}
}
/* Generate the main shader */
{
{
if (!stage)
final_combiner_src = "gl_Color";
break;
}
else
{
if (!stage)
}
else if (op_equal)
{
}
else
{
}
}
shader_addline(buffer, "gl_FragData[0] = gl_SecondaryColor * specular_enable + %s;\n", final_combiner_src);
if (settings->sRGB_write)
return shader_obj;
}
static struct glsl_ffp_vertex_shader *shader_glsl_find_ffp_vertex_shader(struct shader_glsl_priv *priv,
{
struct glsl_ffp_vertex_shader *shader;
const struct wine_rb_entry *entry;
return NULL;
ERR("Failed to insert ffp vertex shader.\n");
return shader;
}
static struct glsl_ffp_fragment_shader *shader_glsl_find_ffp_fragment_shader(struct shader_glsl_priv *priv,
{
struct glsl_ffp_fragment_shader *glsl_desc;
const struct ffp_frag_desc *desc;
return NULL;
return glsl_desc;
}
{
unsigned int i;
char name[32];
{
}
for (i = 0; i < MAX_CONST_I; ++i)
{
}
}
{
unsigned int i;
char name[32];
{
}
for (i = 0; i < MAX_CONST_I; ++i)
{
}
for (i = 0; i < MAX_TEXTURES; ++i)
{
}
}
/* Context activation is done by the caller. */
static void set_glsl_shader_program(const struct wined3d_context *context, const struct wined3d_state *state,
struct shader_glsl_priv *priv)
{
GLhandleARB programId = 0;
unsigned int i;
struct ps_compile_args ps_compile_args;
struct vs_compile_args vs_compile_args;
{
else
gs_id = 0;
}
{
struct glsl_ffp_vertex_shader *ffp_shader;
struct wined3d_ffp_vs_settings settings;
gs_id = 0;
}
else
{
vs_id = 0;
gs_id = 0;
}
{
}
{
struct glsl_ffp_fragment_shader *ffp_shader;
struct ffp_frag_settings settings;
}
else
{
ps_id = 0;
}
{
return;
}
/* If we get to this point, then no matching program exists, so we create one */
/* Create the entry */
entry->constant_version = 0;
/* Add the hash table entry */
/* Set the current program */
/* Attach GLSL vshader */
if (vs_id)
{
checkGLcall("glAttachObjectARB");
}
if (vshader)
{
char tmp_name[10];
reorder_shader_id = generate_param_reorder_function(&priv->shader_buffer, vshader, pshader, gl_info);
checkGLcall("glAttachObjectARB");
/* Flag the reorder function for deletion, then it will be freed automatically when the program
* is destroyed
*/
/* Bind vertex attributes to a corresponding index number to match
* the same index numbers as ARB_vertex_programs (makes loading
* vertex attributes simpler). With this method, we can use the
* exact same code to load the attributes later for both ARB and
* GLSL shaders.
*
* We have to do this here because we need to know the Program ID
* in order to make the bindings work, and it has to be done prior
* to linking the GLSL program. */
{
if (!(map & 1)) continue;
}
checkGLcall("glBindAttribLocationARB");
}
if (gshader)
{
checkGLcall("glAttachObjectARB");
TRACE("input type %s, output type %s, vertices out %u.\n",
checkGLcall("glProgramParameteriARB");
}
/* Attach GLSL pshader */
if (ps_id)
{
checkGLcall("glAttachObjectARB");
}
/* Link the program */
checkGLcall("Find glsl program uniform locations");
{
}
else
{
}
/* Set the shader to allow uniform loading on it */
checkGLcall("glUseProgramObjectARB(programId)");
/* Load the vertex and pixel samplers now. The function that finds the mappings makes sure
* that it stays the same for each vertexshader-pixelshader pair(=linked glsl program). If
* a pshader with fixed function pipeline is used there are no vertex samplers, and if a
* vertex shader with fixed function pixel processing is used we make sure that the card
* supports enough samplers to allow the max number of vertex samplers with all possible
* fixed function fragment processing setups. So once the program is linked these samplers
* won't change.
*/
}
/* Context activation is done by the caller. */
static GLhandleARB create_glsl_blt_shader(const struct wined3d_gl_info *gl_info, enum tex_types tex_type, BOOL masked)
{
const char *blt_pshader;
static const char *blt_vshader =
"#version 120\n"
"void main(void)\n"
"{\n"
" gl_Position = gl_Vertex;\n"
" gl_FrontColor = vec4(1.0);\n"
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
"}\n";
static const char * const blt_pshaders_full[tex_type_count] =
{
/* tex_1d */
NULL,
/* tex_2d */
"#version 120\n"
"uniform sampler2D sampler;\n"
"void main(void)\n"
"{\n"
" gl_FragDepth = texture2D(sampler, gl_TexCoord[0].xy).x;\n"
"}\n",
/* tex_3d */
NULL,
/* tex_cube */
"#version 120\n"
"uniform samplerCube sampler;\n"
"void main(void)\n"
"{\n"
" gl_FragDepth = textureCube(sampler, gl_TexCoord[0].xyz).x;\n"
"}\n",
/* tex_rect */
"#version 120\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect sampler;\n"
"void main(void)\n"
"{\n"
" gl_FragDepth = texture2DRect(sampler, gl_TexCoord[0].xy).x;\n"
"}\n",
};
static const char * const blt_pshaders_masked[tex_type_count] =
{
/* tex_1d */
NULL,
/* tex_2d */
"#version 120\n"
"uniform sampler2D sampler;\n"
"uniform vec4 mask;\n"
"void main(void)\n"
"{\n"
" if (all(lessThan(gl_FragCoord.xy, mask.zw))) discard;\n"
" gl_FragDepth = texture2D(sampler, gl_TexCoord[0].xy).x;\n"
"}\n",
/* tex_3d */
NULL,
/* tex_cube */
"#version 120\n"
"uniform samplerCube sampler;\n"
"uniform vec4 mask;\n"
"void main(void)\n"
"{\n"
" if (all(lessThan(gl_FragCoord.xy, mask.zw))) discard;\n"
" gl_FragDepth = textureCube(sampler, gl_TexCoord[0].xyz).x;\n"
"}\n",
/* tex_rect */
"#version 120\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect sampler;\n"
"uniform vec4 mask;\n"
"void main(void)\n"
"{\n"
" if (all(lessThan(gl_FragCoord.xy, mask.zw))) discard;\n"
" gl_FragDepth = texture2DRect(sampler, gl_TexCoord[0].xy).x;\n"
"}\n",
};
if (!blt_pshader)
{
return 0;
}
/* Once linked we can mark the shaders for deletion. They will be deleted once the program
* is destroyed
*/
return program_id;
}
/* Context activation is done by the caller. */
const struct wined3d_state *state)
{
GLhandleARB program_id = 0;
old_vertex_color_clamp = priv->glsl_program ? priv->glsl_program->vs.vertex_color_clamp : GL_FIXED_ONLY_ARB;
current_vertex_color_clamp = priv->glsl_program ? priv->glsl_program->vs.vertex_color_clamp : GL_FIXED_ONLY_ARB;
{
{
checkGLcall("glClampColorARB");
}
else
{
FIXME("vertex color clamp needs to be changed, but extension not supported.\n");
}
}
checkGLcall("glUseProgramObjectARB");
/* In case that NP2 texcoord fixup data is found for the selected program, trigger a reload of the
* constants. This has to be done because it can't be guaranteed that sampler() (from state.c) is
* called between selecting the shader and using it, which results in wrong fixup for some frames. */
{
}
}
/* Context activation is done by the caller. */
{
checkGLcall("glUseProgramObjectARB");
{
checkGLcall("glClampColorARB");
}
}
/* Context activation is done by the caller. */
{
blt_program = masked ? &priv->depth_blt_program_masked[tex_type] : &priv->depth_blt_program_full[tex_type];
if (!*blt_program)
{
}
else
{
}
if (masked)
{
}
}
/* Context activation is done by the caller. */
static void shader_glsl_deselect_depth_blt(void *shader_priv, const struct wined3d_gl_info *gl_info)
{
checkGLcall("glUseProgramObjectARB");
}
{
const struct wined3d_gl_info *gl_info;
const struct list *linked_programs;
struct wined3d_context *context;
{
return;
}
TRACE("Deleting linked programs.\n");
if (linked_programs->next)
{
UINT i;
{
{
{
, context
#endif
);
}
for (i = 0; i < shader_data->num_gl_shaders; ++i)
{
checkGLcall("glDeleteObjectARB");
}
break;
}
{
{
, context
#endif
);
}
for (i = 0; i < shader_data->num_gl_shaders; ++i)
{
checkGLcall("glDeleteObjectARB");
}
break;
}
{
{
, context
#endif
);
}
for (i = 0; i < shader_data->num_gl_shaders; ++i)
{
checkGLcall("glDeleteObjectARB");
}
break;
}
default:
break;
}
}
}
{
const struct glsl_program_key *k = key;
const struct glsl_shader_prog_link, program_lookup_entry);
return 0;
}
{
SIZE_T size = (constant_count + 1) * sizeof(*heap->entries) + constant_count * sizeof(*heap->positions);
if (!mem)
{
ERR("Failed to allocate memory\n");
return FALSE;
}
return TRUE;
}
{
}
static const struct wine_rb_functions wined3d_glsl_program_rb_functions =
{
};
static HRESULT shader_glsl_alloc(struct wined3d_device *device, const struct wined3d_vertex_pipe_ops *vertex_pipe,
const struct fragment_pipeline *fragment_pipe)
{
struct shader_glsl_priv *priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct shader_glsl_priv));
struct fragment_caps fragment_caps;
void *vertex_priv, *fragment_priv;
{
ERR("Failed to initialize vertex pipe.\n");
return E_FAIL;
}
{
ERR("Failed to initialize fragment pipe.\n");
return E_FAIL;
}
{
ERR("Failed to initialize shader buffer.\n");
goto fail;
}
{
ERR("Failed to allocate memory.\n");
goto fail;
}
{
ERR("Failed to initialize vertex shader constant heap\n");
goto fail;
}
{
ERR("Failed to initialize pixel shader constant heap\n");
goto fail;
}
{
ERR("Failed to initialize rbtree.\n");
goto fail;
}
return WINED3D_OK;
fail:
return E_OUTOFMEMORY;
}
/* Context activation is done by the caller. */
{
int i;
for (i = 0; i < tex_type_count; ++i)
{
if (priv->depth_blt_program_full[i])
{
}
if (priv->depth_blt_program_masked[i])
{
}
}
}
static void shader_glsl_context_destroyed(void *shader_priv, const struct wined3d_context *context) {}
{
shader_model = 4;
/* ARB_shader_texture_lod or EXT_gpu_shader4 is required for the SM3
* texldd and texldl instructions. */
shader_model = 3;
else
shader_model = 2;
/* FIXME: The following line is card dependent. -8.0 to 8.0 is the
* Direct3D minimum requirement.
*
* Both GL_ARB_fragment_program and GLSL require a "maximum representable magnitude"
* of colors to be 2^10, and 2^32 for other floats. Should we use 1024 here?
*
* The problem is that the refrast clamps temporary results in the shader to
* [-MaxValue;+MaxValue]. If the card's max value is bigger than the one we advertize here,
* then applications may miss the clamping behavior. On the other hand, if it is smaller,
* the shader will generate incorrect results too. Unfortunately, GL deliberately doesn't
* offer a way to query this.
*/
/* Ideally we'd only set caps like sRGB writes here if supported by both
* the shader backend and the fragment pipe, but we can get called before
* shader_glsl_alloc(). */
}
{
{
TRACE("Checking support for fixup:\n");
}
/* We support everything except YUV conversions. */
if (!is_complex_fixup(fixup))
{
TRACE("[OK]\n");
return TRUE;
}
TRACE("[FAILED]\n");
return FALSE;
}
{
/* WINED3DSIH_ABS */ shader_glsl_map2gl,
/* WINED3DSIH_ADD */ shader_glsl_binop,
/* WINED3DSIH_AND */ shader_glsl_binop,
/* WINED3DSIH_BEM */ shader_glsl_bem,
/* WINED3DSIH_BREAK */ shader_glsl_break,
/* WINED3DSIH_BREAKC */ shader_glsl_breakc,
/* WINED3DSIH_BREAKP */ shader_glsl_breakp,
/* WINED3DSIH_CALL */ shader_glsl_call,
/* WINED3DSIH_CALLNZ */ shader_glsl_callnz,
/* WINED3DSIH_CMP */ shader_glsl_conditional_move,
/* WINED3DSIH_CND */ shader_glsl_cnd,
/* WINED3DSIH_CRS */ shader_glsl_cross,
/* WINED3DSIH_CUT */ shader_glsl_cut,
/* WINED3DSIH_DCL */ shader_glsl_nop,
/* WINED3DSIH_DCL_CONSTANT_BUFFER */ shader_glsl_nop,
/* WINED3DSIH_DCL_INPUT_PRIMITIVE */ shader_glsl_nop,
/* WINED3DSIH_DCL_OUTPUT_TOPOLOGY */ shader_glsl_nop,
/* WINED3DSIH_DCL_VERTICES_OUT */ shader_glsl_nop,
/* WINED3DSIH_DEF */ shader_glsl_nop,
/* WINED3DSIH_DEFB */ shader_glsl_nop,
/* WINED3DSIH_DEFI */ shader_glsl_nop,
/* WINED3DSIH_DIV */ shader_glsl_binop,
/* WINED3DSIH_DP2ADD */ shader_glsl_dp2add,
/* WINED3DSIH_DP3 */ shader_glsl_dot,
/* WINED3DSIH_DP4 */ shader_glsl_dot,
/* WINED3DSIH_DST */ shader_glsl_dst,
/* WINED3DSIH_DSX */ shader_glsl_map2gl,
/* WINED3DSIH_DSY */ shader_glsl_map2gl,
/* WINED3DSIH_ELSE */ shader_glsl_else,
/* WINED3DSIH_EMIT */ shader_glsl_emit,
/* WINED3DSIH_ENDIF */ shader_glsl_end,
/* WINED3DSIH_ENDLOOP */ shader_glsl_end,
/* WINED3DSIH_ENDREP */ shader_glsl_end,
/* WINED3DSIH_EQ */ shader_glsl_relop,
/* WINED3DSIH_EXP */ shader_glsl_map2gl,
/* WINED3DSIH_EXPP */ shader_glsl_expp,
/* WINED3DSIH_FRC */ shader_glsl_map2gl,
/* WINED3DSIH_FTOI */ shader_glsl_to_int,
/* WINED3DSIH_GE */ shader_glsl_relop,
/* WINED3DSIH_IADD */ shader_glsl_binop,
/* WINED3DSIH_IEQ */ NULL,
/* WINED3DSIH_IF */ shader_glsl_if,
/* WINED3DSIH_IFC */ shader_glsl_ifc,
/* WINED3DSIH_IGE */ shader_glsl_relop,
/* WINED3DSIH_IMUL */ shader_glsl_imul,
/* WINED3DSIH_ITOF */ shader_glsl_to_float,
/* WINED3DSIH_LABEL */ shader_glsl_label,
/* WINED3DSIH_LD */ NULL,
/* WINED3DSIH_LIT */ shader_glsl_lit,
/* WINED3DSIH_LOG */ shader_glsl_log,
/* WINED3DSIH_LOGP */ shader_glsl_log,
/* WINED3DSIH_LOOP */ shader_glsl_loop,
/* WINED3DSIH_LRP */ shader_glsl_lrp,
/* WINED3DSIH_LT */ shader_glsl_relop,
/* WINED3DSIH_M3x2 */ shader_glsl_mnxn,
/* WINED3DSIH_M3x3 */ shader_glsl_mnxn,
/* WINED3DSIH_M3x4 */ shader_glsl_mnxn,
/* WINED3DSIH_M4x3 */ shader_glsl_mnxn,
/* WINED3DSIH_M4x4 */ shader_glsl_mnxn,
/* WINED3DSIH_MAD */ shader_glsl_mad,
/* WINED3DSIH_MAX */ shader_glsl_map2gl,
/* WINED3DSIH_MIN */ shader_glsl_map2gl,
/* WINED3DSIH_MOV */ shader_glsl_mov,
/* WINED3DSIH_MOVA */ shader_glsl_mov,
/* WINED3DSIH_MOVC */ shader_glsl_conditional_move,
/* WINED3DSIH_MUL */ shader_glsl_binop,
/* WINED3DSIH_NOP */ shader_glsl_nop,
/* WINED3DSIH_NRM */ shader_glsl_nrm,
/* WINED3DSIH_PHASE */ shader_glsl_nop,
/* WINED3DSIH_POW */ shader_glsl_pow,
/* WINED3DSIH_RCP */ shader_glsl_rcp,
/* WINED3DSIH_REP */ shader_glsl_rep,
/* WINED3DSIH_RET */ shader_glsl_ret,
/* WINED3DSIH_ROUND_NI */ shader_glsl_map2gl,
/* WINED3DSIH_RSQ */ shader_glsl_rsq,
/* WINED3DSIH_SAMPLE */ NULL,
/* WINED3DSIH_SAMPLE_GRAD */ NULL,
/* WINED3DSIH_SAMPLE_LOD */ NULL,
/* WINED3DSIH_SETP */ NULL,
/* WINED3DSIH_SGE */ shader_glsl_compare,
/* WINED3DSIH_SGN */ shader_glsl_sgn,
/* WINED3DSIH_SINCOS */ shader_glsl_sincos,
/* WINED3DSIH_SLT */ shader_glsl_compare,
/* WINED3DSIH_SQRT */ NULL,
/* WINED3DSIH_SUB */ shader_glsl_binop,
/* WINED3DSIH_TEX */ shader_glsl_tex,
/* WINED3DSIH_TEXBEM */ shader_glsl_texbem,
/* WINED3DSIH_TEXBEML */ shader_glsl_texbem,
/* WINED3DSIH_TEXCOORD */ shader_glsl_texcoord,
/* WINED3DSIH_TEXDEPTH */ shader_glsl_texdepth,
/* WINED3DSIH_TEXDP3 */ shader_glsl_texdp3,
/* WINED3DSIH_TEXDP3TEX */ shader_glsl_texdp3tex,
/* WINED3DSIH_TEXKILL */ shader_glsl_texkill,
/* WINED3DSIH_TEXLDD */ shader_glsl_texldd,
/* WINED3DSIH_TEXLDL */ shader_glsl_texldl,
/* WINED3DSIH_TEXM3x2DEPTH */ shader_glsl_texm3x2depth,
/* WINED3DSIH_TEXM3x2PAD */ shader_glsl_texm3x2pad,
/* WINED3DSIH_TEXM3x2TEX */ shader_glsl_texm3x2tex,
/* WINED3DSIH_TEXM3x3 */ shader_glsl_texm3x3,
/* WINED3DSIH_TEXM3x3DIFF */ NULL,
/* WINED3DSIH_TEXM3x3PAD */ shader_glsl_texm3x3pad,
/* WINED3DSIH_TEXM3x3SPEC */ shader_glsl_texm3x3spec,
/* WINED3DSIH_TEXM3x3TEX */ shader_glsl_texm3x3tex,
/* WINED3DSIH_TEXM3x3VSPEC */ shader_glsl_texm3x3vspec,
/* WINED3DSIH_TEXREG2AR */ shader_glsl_texreg2ar,
/* WINED3DSIH_TEXREG2GB */ shader_glsl_texreg2gb,
/* WINED3DSIH_TEXREG2RGB */ shader_glsl_texreg2rgb,
/* WINED3DSIH_UDIV */ shader_glsl_udiv,
/* WINED3DSIH_USHR */ shader_glsl_binop,
/* WINED3DSIH_UTOF */ shader_glsl_to_float,
/* WINED3DSIH_XOR */ shader_glsl_binop,
};
/* Select handler */
/* Unhandled opcode */
if (!hw_fct)
{
return;
}
}
{
return priv->ffp_proj_control;
}
const struct wined3d_shader_backend_ops glsl_shader_backend =
{
};
{
if (enable)
else
checkGLcall("GL_VERTEX_PROGRAM_POINT_SIZE_ARB");
}
static void glsl_vertex_pipe_vp_get_caps(const struct wined3d_gl_info *gl_info, struct wined3d_vertex_caps *caps)
{
}
static void *glsl_vertex_pipe_vp_alloc(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv)
{
struct shader_glsl_priv *priv;
if (shader_backend == &glsl_shader_backend)
{
priv = shader_priv;
{
ERR("Failed to initialize rbtree.\n");
return NULL;
}
return priv;
}
FIXME("GLSL vertex pipe without GLSL shader backend not implemented.\n");
return NULL;
}
{
{
, NULL
#endif
);
}
}
/* Context activation is done by the caller. */
{
struct glsl_ffp_destroy_ctx ctx;
}
{
}
static const struct StateEntryTemplate glsl_vertex_pipe_vp_states[] =
{
{STATE_RENDER(WINED3D_RS_SPECULARENABLE), {STATE_RENDER(WINED3D_RS_SPECULARENABLE), state_specularenable }, WINED3D_GL_EXT_NONE },
/* Clip planes */
/* Lights */
/* Viewport */
/* Transform states */
{STATE_TRANSFORM(WINED3D_TS_VIEW), {STATE_TRANSFORM(WINED3D_TS_VIEW), transform_view }, WINED3D_GL_EXT_NONE },
{STATE_TRANSFORM(WINED3D_TS_PROJECTION), {STATE_TRANSFORM(WINED3D_TS_PROJECTION), transform_projection }, WINED3D_GL_EXT_NONE },
{STATE_TRANSFORM(WINED3D_TS_TEXTURE0), {STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TRANSFORM(WINED3D_TS_TEXTURE1), {STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TRANSFORM(WINED3D_TS_TEXTURE2), {STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TRANSFORM(WINED3D_TS_TEXTURE3), {STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TRANSFORM(WINED3D_TS_TEXTURE4), {STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TRANSFORM(WINED3D_TS_TEXTURE5), {STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TRANSFORM(WINED3D_TS_TEXTURE6), {STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TRANSFORM(WINED3D_TS_TEXTURE7), {STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)), {STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)), transform_world }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture }, WINED3D_GL_EXT_NONE },
/* Fog */
{STATE_RENDER(WINED3D_RS_FOGENABLE), {STATE_RENDER(WINED3D_RS_FOGENABLE), glsl_vertex_pipe_shader}, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_FOGTABLEMODE), {STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), {STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_RANGEFOGENABLE), {STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_CLIPPING), {STATE_RENDER(WINED3D_RS_CLIPPING), state_clipping }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE), {STATE_RENDER(WINED3D_RS_CLIPPING), NULL }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_AMBIENT), {STATE_RENDER(WINED3D_RS_AMBIENT), state_ambient }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_POINTSIZE), {STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), {STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_arb }, ARB_POINT_PARAMETERS },
{STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), {STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_ext }, EXT_POINT_PARAMETERS },
{STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), {STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), state_psizemin_w }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), {STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), state_pointsprite }, ARB_POINT_SPRITE },
{STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), {STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE), state_pointsprite_w }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), {STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), state_pscale }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_POINTSCALE_A), {STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_POINTSCALE_B), {STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_POINTSCALE_C), {STATE_RENDER(WINED3D_RS_POINTSCALEENABLE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), {STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, ARB_POINT_PARAMETERS },
{STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), {STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, EXT_POINT_PARAMETERS },
{STATE_RENDER(WINED3D_RS_POINTSIZE_MAX), {STATE_RENDER(WINED3D_RS_POINTSIZE_MIN), NULL }, WINED3D_GL_EXT_NONE },
/* Samplers for NP2 texture matrix adjustions. They are not needed if
* GL_ARB_texture_non_power_of_two is supported, so register a NULL state
* handler in that case to get the vertex part of sampler() skipped (VTF
* is handled in the misc states). Otherwise, register
* sampler_texmatrix(), which takes care of updating the texture matrix. */
};
/* TODO:
* - This currently depends on GL fixed function functions to set things
* like light parameters. Ideally we'd use regular uniforms for that.
* - In part because of the previous point, much of this is modelled after
* GL fixed function, and has much of the same limitations. For example,
* D3D spot lights are slightly different from GL spot lights.
* - We can now implement drawing transformed vertices using the GLSL pipe,
* instead of using the immediate mode fallback.
* - Similarly, we don't need the fallback for certain combinations of
* material sources anymore.
* - Implement vertex blending and vertex tweening.
* - Handle WINED3D_TSS_TEXCOORD_INDEX in the shader, instead of duplicating
* attribute arrays in load_tex_coords().
* - Per-vertex point sizes. */
const struct wined3d_vertex_pipe_ops glsl_vertex_pipe =
{
};
{
/* Nothing to do. */
}
static void glsl_fragment_pipe_get_caps(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
{
}
static void *glsl_fragment_pipe_alloc(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv)
{
struct shader_glsl_priv *priv;
if (shader_backend == &glsl_shader_backend)
{
priv = shader_priv;
{
ERR("Failed to initialize rbtree.\n");
return NULL;
}
return priv;
}
FIXME("GLSL fragment pipe without GLSL shader backend not implemented.\n");
return NULL;
}
{
{
, context
#endif
);
}
}
/* Context activation is done by the caller. */
{
struct glsl_ffp_destroy_ctx ctx;
}
{
}
{
enum fogsource new_source;
return;
{
if (use_vshader)
else if (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE || context->last_was_rhw)
else
}
else
{
}
{
}
}
{
}
{
}
static const struct StateEntryTemplate glsl_fragment_pipe_state_template[] =
{
{STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), {STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT01), {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT10), {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT11), {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT01), {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT10), {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT11), {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT01), {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT10), {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT11), {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT01), {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT10), {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT11), {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT01), {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT10), {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT11), {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT01), {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT10), {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT11), {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT01), {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT10), {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT11), {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT01), {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT10), {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT11), {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_FOGENABLE), {STATE_RENDER(WINED3D_RS_FOGENABLE), glsl_fragment_pipe_fog }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_FOGTABLEMODE), {STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), {STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_FOGSTART), {STATE_RENDER(WINED3D_RS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_FOGEND), {STATE_RENDER(WINED3D_RS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE), {STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE), state_srgbwrite }, ARB_FRAMEBUFFER_SRGB},
{STATE_RENDER(WINED3D_RS_FOGCOLOR), {STATE_RENDER(WINED3D_RS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_FOGDENSITY), {STATE_RENDER(WINED3D_RS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(0,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), glsl_fragment_pipe_tex_transform }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(1,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), glsl_fragment_pipe_tex_transform }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(2,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), glsl_fragment_pipe_tex_transform }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(3,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), glsl_fragment_pipe_tex_transform }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(4,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), glsl_fragment_pipe_tex_transform }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(5,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), glsl_fragment_pipe_tex_transform }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(6,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), glsl_fragment_pipe_tex_transform }, WINED3D_GL_EXT_NONE },
{STATE_TEXTURESTAGE(7,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), glsl_fragment_pipe_tex_transform }, WINED3D_GL_EXT_NONE },
{STATE_RENDER(WINED3D_RS_SPECULARENABLE), {STATE_RENDER(WINED3D_RS_SPECULARENABLE), glsl_fragment_pipe_invalidate_constants}, WINED3D_GL_EXT_NONE },
{0 /* Terminate */, {0, 0 }, WINED3D_GL_EXT_NONE },
};
const struct fragment_pipeline glsl_fragment_pipe =
{
};