glsl_shader.c revision 4b9d6701570cb98fd36e209314239d104ec584d3
/*
* GLSL pixel and vertex shader implementation
*
* Copyright 2006 Jason Green
* Copyright 2006-2007 Henri Verbeet
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
* Copyright 2009 Henri Verbeet for CodeWeavers
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Oracle elects to use only
* the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
* a choice of LGPL license versions is made available with the language indicating
* that LGPLv2 or any later version may be used, or where a choice of which version
* of the LGPL is applied is otherwise unspecified.
*/
/*
* 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 GLINFO_LOCATION (*gl_info)
#define WINED3D_GLSL_SAMPLE_PROJECTED 0x1
#define WINED3D_GLSL_SAMPLE_RECT 0x2
#define WINED3D_GLSL_SAMPLE_LOD 0x4
#define WINED3D_GLSL_SAMPLE_GRAD 0x8
typedef struct {
char reg_name[150];
char mask_str[6];
typedef struct {
char reg_name[150];
char param_str[200];
typedef struct {
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;
};
/* Struct to maintain data about a linked GLSL program */
struct glsl_shader_prog_link {
struct wine_rb_entry program_lookup_entry;
struct list vshader_entry;
struct list pshader_entry;
struct vs_compile_args vs_args;
struct ps_compile_args ps_args;
#ifdef VBOX_WITH_WDDM
#else
const struct ps_np2fixup_info *np2Fixup_info;
#endif
};
#ifdef VBOX_WITH_WDDM
#define WINEFIXUPINFO_NOINDEX (~0UL)
#define WINEFIXUPINFO_GET(_p) get_fixup_info((const IWineD3DPixelShaderImpl*)(_p)->pshader, (_p)->inp2Fixup_info)
#else
#endif
typedef struct {
struct ps_compile_args ps_args;
struct vs_compile_args vs_args;
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_pshader_private
{
struct glsl_ps_compiled_shader *gl_shaders;
};
struct glsl_vs_compiled_shader
{
struct vs_compile_args args;
};
struct glsl_vshader_private
{
struct glsl_vs_compiled_shader *gl_shaders;
};
{
switch (type)
{
#define WINED3D_TO_STR(u) case u: return #u
default:
}
}
/* 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;
}
/** Prints the GLSL info log which will contain error messages if they exist */
/* GL locking is done by the caller */
{
int infologLength = 0;
char *infoLog;
unsigned int i;
static const char * const spam[] =
{
"Vertex shader was successfully compiled to run on hardware.\n", /* fglrx */
"Fragment shader was successfully compiled to run on hardware.\n", /* fglrx, with \n */
"Fragment shader was successfully compiled to run on hardware.", /* fglrx, no \n */
"Fragment shader(s) linked, vertex shader(s) linked. \n ", /* fglrx, with \n */
"Fragment shader(s) linked, vertex shader(s) linked.", /* fglrx, no \n */
"Vertex shader(s) linked, no fragment shader(s) defined. \n ", /* fglrx, with \n */
"Vertex shader(s) linked, no fragment shader(s) defined.", /* fglrx, no \n */
"Fragment shader(s) linked, no vertex shader(s) defined. \n ", /* fglrx, with \n */
"Fragment shader(s) linked, no vertex shader(s) defined.", /* fglrx, no \n */
};
&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)
{
/* Fglrx doesn't terminate the string properly, but it tells us the proper length.
* So use HEAP_ZERO_MEMORY to avoid uninitialized bytes
*/
break;
}
}
if (is_spam)
{
}
else
{
}
}
}
/* GL locking 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)
{
return;
}
source_size = tmp;
}
FIXME("\n");
FIXME("\n");
}
}
/* GL locking is done by the caller. */
{
if (tmp == GL_PROGRAM_OBJECT_ARB)
{
if (!tmp)
{
}
}
}
/**
* Loads (pixel shader) samplers
*/
/* GL locking is done by the caller */
{
int i;
char sampler_name[20];
for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i) {
if (name_loc != -1) {
{
checkGLcall("glUniform1iARB");
} else {
}
}
}
}
/* GL locking is done by the caller */
{
char sampler_name[20];
int i;
for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i) {
if (name_loc != -1) {
{
checkGLcall("glUniform1iARB");
} else {
}
}
}
}
/* GL locking 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()");
}
/* GL locking 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;
}
/* GL locking 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()");
}
/* Loads floating point constants (aka uniforms) into the currently set GLSL program. */
/* GL locking is done by the caller */
static void shader_glsl_load_constantsF(IWineD3DBaseShaderImpl *This, const struct wined3d_gl_info *gl_info,
{
const local_constant *lconst;
/* 1.X pshaders have the constants clamped to [-1;1] implicitly. */
else
{
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 */
{
/* We found this uniform name in the program - go ahead and send the data */
}
checkGLcall("glUniform4fvARB()");
}
/* Loads integer constants (aka uniforms) into the currently set GLSL program. */
/* GL locking is done by the caller */
static void shader_glsl_load_constantsI(IWineD3DBaseShaderImpl *This, 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) {
/* We found this uniform name in the program - go ahead and send the data */
checkGLcall("glUniform4ivARB");
}
}
/* Loads boolean constants (aka uniforms) into the currently set GLSL program. */
/* GL locking is done by the caller */
static void shader_glsl_load_constantsB(IWineD3DBaseShaderImpl *This, const struct wined3d_gl_info *gl_info,
{
unsigned int i;
char tmp_name[8];
const char *prefix;
{
prefix = "VB";
break;
prefix = "GB";
break;
prefix = "PB";
break;
default:
FIXME("Unknown shader type %#x.\n",
prefix = "UB";
break;
}
/* 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 */
if (tmp_loc != -1)
{
/* We found this uniform name in the program - go ahead and send the data */
checkGLcall("glUniform1ivARB");
}
}
/* Load immediate constants */
while (ptr) {
if (tmp_loc != -1) {
/* We found this uniform name in the program - go ahead and send the data */
checkGLcall("glUniform1ivARB");
}
}
}
{
WINE_RB_ENTRY_VALUE(entry, struct glsl_shader_prog_link, program_lookup_entry)->constant_version = 0;
}
#ifdef VBOX_WITH_WDDM
static const struct ps_np2fixup_info * get_fixup_info(const IWineD3DPixelShaderImpl *shader, UINT inp2fixup_info)
{
if (inp2fixup_info == WINEFIXUPINFO_NOINDEX)
return NULL;
{
ERR("no backend data\n");
return NULL;
}
{
ERR("invalid index\n");
return NULL;
}
}
#endif
/**
* Loads the texture dimensions for NP2 fixup into the currently set GLSL program.
*/
/* GL locking is done by the caller (state handler) */
static void shader_glsl_load_np2fixup_constants(
char usePixelShader,
char useVertexShader) {
const struct glsl_shader_prog_link* prog = ((struct shader_glsl_priv *)(deviceImpl->shader_priv))->glsl_program;
if (!prog) {
/* No GLSL program set - nothing to do. */
return;
}
if (!usePixelShader) {
/* NP2 texcoord fixup is (currently) only done for pixelshaders. */
return;
}
UINT i;
const IWineD3DBaseTextureImpl* const tex = (const IWineD3DBaseTextureImpl*) stateBlock->textures[i];
if (!tex) {
FIXME("Nonexistent texture is flagged for NP2 texcoord fixup\n");
continue;
}
if (idx % 2) {
} else {
}
}
GL_EXTCALL(glUniform4fvARB(prog->np2Fixup_location, np2Fixup_info->num_consts, np2fixup_constants));
}
}
/**
* Loads the app-supplied constants into the currently set GLSL program.
*/
/* GL locking is done by the caller (state handler) */
char usePixelShader, char useVertexShader)
{
#ifdef VBOX_WITH_WDDM
#else
#endif
int i;
if (!prog) {
/* No GLSL program set - nothing to do. */
return;
}
if (useVertexShader) {
shader_glsl_load_constantsI(vshader, gl_info, prog->vuniformI_locations, stateBlock->vertexShaderConstantI,
/* Upload the position fixup params */
checkGLcall("glUniform4fvARB");
}
if (usePixelShader) {
shader_glsl_load_constantsI(pshader, gl_info, prog->puniformI_locations, stateBlock->pixelShaderConstantI,
/* 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;
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 */
}
}
}
{
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(IWineD3DDevice *iface, UINT start, UINT count)
{
UINT i;
{
else
}
}
{
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 local_constant *lconst;
/* There are some minor differences between pixel and vertex shaders */
/* 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
*/
if (pshader)
{
/* No indirect addressing here. */
}
else
{
/* 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 */
}
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.
*/
if(!pshader) {
/* Predeclaration; This function is added at link time based on the pixel shader.
* VS 3.0 shaders have an array OUT[] the shader writes to, earlier versions don't have
* that. We know the input to the reorder function at vertex shader compile time, so
* we can deal with that. The reorder function for a 1.x and 2.x vertex shader can just
* read gl_FrontColor. The output depends on the pixel shader. The reorder function for a
* 1.x and 2.x pshader or for fixed function will write gl_FrontColor, and for a 3.0 shader
* it will write to the varying array. Here we depend on the shader optimizer on sorting that
* out. The nvidia driver only does that if the parameter is inout instead of out, hence the
* inout.
*/
{
} else {
}
} else {
{
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");
context->render_offscreen ? 0.0f : ((IWineD3DSurfaceImpl *)device->render_targets[0])->currentDesc.Height,
}
}
}
/* Declare texture samplers */
if (reg_maps->sampler_type[i])
{
switch (reg_maps->sampler_type[i])
{
case WINED3DSTT_1D:
break;
case WINED3DSTT_2D:
IWineD3DBaseTexture_GetTextureDimensions(device->stateBlock->textures[i]) == GL_TEXTURE_RECTANGLE_ARB) {
} else {
}
break;
case WINED3DSTT_CUBE:
break;
case WINED3DSTT_VOLUME:
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 input register varyings. Only pixel shader, vertex shaders have that declared in the
* helper function shader that is linked in at link time
*/
{
{
shader_addline(buffer, "varying vec4 IN[%u];\n", vec4_varyings(reg_maps->shader_version.major, gl_info));
} 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.
*/
}
}
/* Declare output register temporaries */
}
/* Declare temporary variables */
{
}
/* Declare attributes */
{
{
}
}
/* Declare loop registers aLx */
for (i = 0; i < reg_maps->loop_depth; i++) {
}
/* Temporary variables for matrix operations */
/* Local constants use a different name so they can be loaded once at shader link time
* They can't be hardcoded into the shader text via LC = {x, y, z, w}; because the
* float -> string conversion can cause precision loss.
*/
}
}
/* Start the main program */
/* DirectX apps expect integer values, while OpenGL drivers add approximately 0.5. This causes
* off-by-one problems as spotted by the vPos d3d9 visual test. Unfortunately the 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 substract 0.5.
*
* To deal with that just floor() the position. This will eliminate the fraction on all cards.
*
* TODO: Test how that behaves with multisampling once we can enable multisampling in winex11.
*
* An advantage of floor is that it works even if the driver doesn't add 1/2. 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.
*/
shader_addline(buffer, "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 */
static void shader_glsl_gen_modifier(DWORD src_modifier, const char *in_reg, const char *in_regswizzle, char *out_str)
{
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 */
static const char * const hwrastout_reg_names[] = { "gl_Position", "gl_FogFragCoord", "gl_PointSize" };
{
case WINED3DSPR_TEMP:
break;
case WINED3DSPR_INPUT:
/* vertex shaders */
if (!pshader)
{
break;
}
/* pixel shaders >= 3.0 */
{
{
/* Removing a + 0 would be an obvious optimization, but macos doesn't see the NOP
* operation there */
if (idx)
{
{
"((%s + %u) > %d ? (%s + %u) > %d ? gl_SecondaryColor : gl_Color : IN[%s + %u])",
}
else
{
}
}
else
{
{
}
else
{
}
}
}
else
{
}
}
else
{
break;
}
break;
case WINED3DSPR_CONST:
{
/* Relative addressing */
{
}
else
{
else
}
}
break;
case WINED3DSPR_CONSTINT:
break;
case WINED3DSPR_CONSTBOOL:
break;
case WINED3DSPR_TEXTURE: /* case WINED3DSPR_ADDR: */
break;
case WINED3DSPR_LOOP:
break;
case WINED3DSPR_SAMPLER:
break;
case WINED3DSPR_COLOROUT:
break;
case WINED3DSPR_RASTOUT:
break;
case WINED3DSPR_DEPTHOUT:
break;
case WINED3DSPR_ATTROUT:
break;
case WINED3DSPR_TEXCRDOUT:
/* Vertex shaders >= 3.0: WINED3DSPR_OUTPUT */
if (This->baseShader.reg_maps.shader_version.major >= 3) sprintf(register_name, "OUT[%u]", reg->idx);
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_FLOAT:
break;
case WINED3D_IMMCONST_FLOAT4:
break;
default:
}
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);
}
/* 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 */
{
if (mask) shader_addline(buffer, "%s%s = %s(", glsl_dst.reg_name, glsl_dst.mask_str, shift_glsl_tab[dst->shift]);
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 */
{
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 COMPARISON_GT: return ">";
case COMPARISON_EQ: return "==";
case COMPARISON_GE: return ">=";
case COMPARISON_LT: return "<";
case COMPARISON_NE: return "!=";
case COMPARISON_LE: return "<=";
default:
return "(\?\?)";
}
}
{
/* Note that there's no such thing as a projected cube texture. */
switch(sampler_type) {
case WINED3DSTT_1D:
if(lod) {
}
else if (grad)
{
else
{
FIXME("Unsupported 1D grad function.\n");
}
}
else
{
}
break;
case WINED3DSTT_2D:
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(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(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;
}
}
static void shader_glsl_color_correction(const struct wined3d_shader_instruction *ins, struct color_fixup_desc fixup)
{
struct wined3d_shader_dst_param dst;
char arguments[256];
mask = 0;
if (!mask) return; /* Nothing to do */
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
{
shader_addline(ins->ctx->buffer, "%s%s = %s;\n", dst_param.reg_name, dst_param.mask_str, arguments);
}
}
static void PRINTF_ATTR(8, 9) shader_glsl_gen_sample_code(const struct wined3d_shader_instruction *ins,
const char *bias, const char *coord_reg_fmt, ...)
{
const char *sampler_base;
char dst_swizzle[6];
struct color_fixup_desc fixup;
{
sampler_base = "Psampler";
if(bias) {
FIXME("Biased sampling from NP2 textures is unsupported\n");
} else {
}
}
{
{
{
{
}
else
{
}
}
else
{
DebugBreak();
FIXME("Unexpected coord_mask with t_mirror\n");
}
}
}
} else {
sampler_base = "Vsampler";
}
if (tmirror_tmp_reg)
{
}
else
{
}
if(bias) {
} else {
if (np2_fixup) {
} else {
}
}
if(!is_identity_fixup(fixup)) {
}
}
/*****************************************************************************
* Begin processing individual instruction opcodes
****************************************************************************/
/* Generate GLSL arithmetic functions (dst = src1 + src2) */
{
char op;
/* Determine the GLSL operator to use based on the opcode */
switch (ins->handler_idx)
{
default:
op = ' ';
break;
}
}
/* Process the WINED3DSIO_MOV opcode using GLSL (dst = src) */
{
/* 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)) */
{
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 */
{
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. */
{
unsigned int dst_size;
if (dst_size > 1) {
shader_addline(buffer, "vec%d(pow(abs(%s), %s)));\n", dst_size, src0_param.param_str, src1_param.param_str);
} 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. */
{
unsigned int dst_size;
if (dst_size > 1)
{
}
else
{
}
}
/* Map the opcode 1-to-1 to the GL code (arg->dst = instruction(src0, src1, ...) */
{
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;
}
{
{
}
}
}
{
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)
*/
{
{
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 {
}
}
}
/** Process the RCP (reciprocal or inverse) opcode in GLSL (dst = 1 / src) */
{
unsigned int mask_size;
if (mask_size > 1)
{
}
else
{
}
}
{
unsigned int mask_size;
if (mask_size > 1)
{
}
else
{
}
}
/** Process signed comparison opcodes in GLSL. */
{
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:
}
}
}
/** Process CMP instruction in GLSL (dst = src0 >= 0.0 ? src1 : src2), per channel */
{
unsigned int i, j;
char mask_char[6];
{
} else {
/* 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;
}
}
/* Splitting the cmp 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
*/
{
if (!write_mask) continue;
} else {
if (!write_mask) 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 wined3d_shader_dst_param dst;
unsigned int i, j;
{
/* Fun: The D3DSI_COISSUE flag changes the semantic of the cnd instruction for < 1.4 shaders */
{
} else {
}
return;
}
/* 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 (!write_mask) continue;
}
}
/** GLSL code generation for WINED3DSIO_MAD: Multiply the first 2 opcodes, then add the last */
{
}
/* 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);
*/
{
}
/** 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
*/
{
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;
*
* 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
*/
"vec4(1.0, max(%s, 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
*/
{
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
*/
{
switch (write_mask) {
case WINED3DSP_WRITEMASK_0:
break;
case WINED3DSP_WRITEMASK_1:
break;
case (WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1):
shader_addline(ins->ctx->buffer, "vec2(cos(%s), sin(%s)));\n", src0_param.param_str, src0_param.param_str);
break;
default:
ERR("Write mask should be .x, .y or .xy\n");
break;
}
}
/* 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
*/
{
}
/** 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 local_constant *constant;
/* 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 {
"for (tmpInt%u = 0, aL%u = %s.y; tmpInt%u < %s.x; tmpInt%u++, aL%u += %s.z) {\n",
}
}
{
{
}
{
}
}
{
const local_constant *constant;
/* Try to hardcode local values to help the GLSL compiler to unroll and optimize the loop */
{
{
{
break;
}
}
}
if(control_values) {
} else {
}
}
{
}
{
}
{
}
{
}
/* FIXME: According to MSDN the compare is done per component. */
{
}
{
}
{
}
{
shader_addline(ins->ctx->buffer, "if (%s) subroutine%u();\n", src1_param.param_str, ins->src[0].reg.idx);
}
{
/* 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
********************************************/
{
DWORD sample_flags = 0;
/* 1.0-1.4: Use destination register as sampler source.
* 2.0+: Use provided sampler source. */
{
/* Projected cube textures don't make a lot of sense, the resulting coordinates stay the same. */
switch (flags & ~WINED3DTTFF_PROJECTED) {
case WINED3DTTFF_COUNT4:
}
}
}
{
if (src_mod == WINED3DSPSM_DZ) {
} else if (src_mod == WINED3DSPSM_DW) {
}
} else {
{
/* ps 2.0 texldp instruction always divides by the fourth component. */
}
}
IWineD3DBaseTexture_GetTextureDimensions(deviceImpl->stateBlock->textures[sampler_idx]) == GL_TEXTURE_RECTANGLE_ARB) {
}
/* 1.0-1.3: Use destination register as coordinate source.
1.4+: Use provided coordinate source register. */
{
char coord_mask[6];
} else {
{
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, NULL, bias.param_str,
} else {
}
}
}
{
{
FIXME("texldd used, but not supported by hardware. Falling back to regular tex\n");
return shader_glsl_tex(ins);
}
IWineD3DBaseTexture_GetTextureDimensions(deviceImpl->stateBlock->textures[sampler_idx]) == GL_TEXTURE_RECTANGLE_ARB) {
}
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, dx_param.param_str, dy_param.param_str, NULL,
}
{
IWineD3DBaseTexture_GetTextureDimensions(deviceImpl->stateBlock->textures[sampler_idx]) == GL_TEXTURE_RECTANGLE_ARB) {
}
{
/* The GLSL spec claims the Lod sampling functions are only supported in vertex shaders.
* However, they seem to work just fine in fragment shaders as well. */
}
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) {
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) {
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. */
{
/* 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. */
{
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 */
{
/* 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
*/
{
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. */
{
}
/** Process the WINED3DSIO_TEXM3X3PAD instruction in GLSL
* Calculate the 1st or 2nd row of a 3-row matrix multiplication. */
{
shader_addline(buffer, "tmp0.%c = dot(T%u.xyz, %s);\n", 'x' + current_state->current_row, reg, src0_param.param_str);
}
{
/* 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 */
{
/* 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");
current_state->current_row = 0;
}
/** Process the WINED3DSIO_TEXM3X3 instruction in GLSL
* Perform the 3rd row of a 3x3 matrix multiply */
{
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);
current_state->current_row = 0;
}
/* Process the WINED3DSIO_TEXM3X3SPEC instruction in GLSL
* Perform the final texture lookup based on the previous 2 3x3 matrix multiplies */
{
/* Perform the last matrix multiply operation */
/* Reflection calculation */
/* Dependent read, not valid with conditional NP2 */
/* Sample the texture */
shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, "tmp0.xyz");
current_state->current_row = 0;
}
/* Process the WINED3DSIO_TEXM3X3VSPEC instruction in GLSL
* Perform the final texture lookup based on the previous 2 3x3 matrix multiplies */
{
/* 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 */
shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, "tmp0.xyz");
current_state->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
*/
{
char coord_mask[6];
/* Dependent read, not valid with conditional NP2 */
/* with projective textures, texbem only divides the static texture coord, not the displacement,
* so we can't let the GL handle this.
*/
if (flags & WINED3DTTFF_PROJECTED) {
char coord_div_mask[3];
switch (flags & ~WINED3DTTFF_PROJECTED) {
case WINED3DTTFF_COUNT4:
}
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,
{
}
}
{
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 */
{
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 */
{
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 */
{
/* 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 */
{
/* 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 */
{
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(IWineD3DPixelShader *iface, struct wined3d_shader_buffer *buffer,
const struct wined3d_shader_signature_element *input_signature, const struct 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 == 0)
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) {
{
ERR("Failed to insert program entry.\n");
}
}
struct ps_compile_args *ps_args) {
struct wine_rb_entry *entry;
return entry ? WINE_RB_ENTRY_VALUE(entry, struct glsl_shader_prog_link, program_lookup_entry) : NULL;
}
/* GL locking 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)
{
}
static void handle_ps3_input(struct wined3d_shader_buffer *buffer, const struct wined3d_gl_info *gl_info, const DWORD *map,
const struct wined3d_shader_signature_element *input_signature, const struct shader_reg_maps *reg_maps_in,
const struct wined3d_shader_signature_element *output_signature, const struct shader_reg_maps *reg_maps_out)
{
unsigned int i, j;
const char *semantic_name_in, *semantic_name_out;
char destination[50];
if (!output_signature)
{
/* Save gl_FrontColor & gl_FrontSecondaryColor before overwriting them. */
}
{
if (!(input_map & 1)) continue;
FIXME("More input varyings declared than supported, expect issues\n");
continue;
}
else if (map[i] == ~0U)
{
/* Declared, but not read register */
continue;
}
} else {
}
if (!output_signature)
{
{
if (semantic_idx_in == 0)
else if (semantic_idx_in == 1)
else
}
{
if (semantic_idx_in < 8)
{
}
else
{
}
}
{
}
else
{
}
} else {
{
if (!(output_map & 1)) continue;
if (semantic_idx_in == semantic_idx_out
{
}
}
if(!found) {
}
}
}
/* This is solely to make the compiler / linker happy and avoid warning about undefined
* varyings. It shouldn't result in any real code executed on the GPU, since all read
* input varyings are assigned above, if the optimizer works properly.
*/
for(i = 0; i < in_count + 2; i++) {
{
unsigned int size = 0;
if(!(set[i] & WINED3DSP_WRITEMASK_0)) {
size++;
}
if(!(set[i] & WINED3DSP_WRITEMASK_1)) {
size++;
}
if(!(set[i] & WINED3DSP_WRITEMASK_2)) {
size++;
}
if(!(set[i] & WINED3DSP_WRITEMASK_3)) {
size++;
}
if (i == in_count) {
} else if (i == in_count + 1) {
} else {
}
if (size == 1) {
} else {
}
}
}
}
/* GL locking is done by the caller */
IWineD3DVertexShader *vertexshader, IWineD3DPixelShader *pixelshader, const struct wined3d_gl_info *gl_info)
{
GLhandleARB ret = 0;
unsigned int i;
const char *semantic_name;
char reg_mask[6];
const struct wined3d_shader_signature_element *output_signature;
/* That one is easy: The vertex shader writes to the builtin varyings, the pixel shader reads from them.
* Take care about the texcoord .w fixup though if we're using the fixed function fragment pipeline
*/
{
}
}
} else {
}
/* The vertex shader writes to its own varyings, the pixel shader needs them in the builtin ones */
{
if (!(map & 1)) continue;
{
if (semantic_idx == 0)
else if (semantic_idx == 1)
}
{
}
{
if (semantic_idx < 8)
{
if (!(write_mask & WINED3DSP_WRITEMASK_3))
}
}
{
}
{
}
}
/* 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 */
/* The vertex shader wrote to the builtin varyings. There is no need to figure out position and
* point size, but we depend on the optimizers kindness to find out that the pixel shader doesn't
* read gl_TexCoord and gl_ColorX, otherwise we'll run out of varyings
*/
} else {
}
checkGLcall("glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB)");
checkGLcall("glShaderSourceARB(ret, 1, &buffer->buffer, NULL)");
checkGLcall("glCompileShaderARB(ret)");
return ret;
}
/* GL locking is done by the caller */
static void hardcode_local_constants(IWineD3DBaseShaderImpl *shader, const struct wined3d_gl_info *gl_info,
{
const local_constant *lconst;
const float *value;
char glsl_name[8];
}
checkGLcall("Hardcoding local constants");
}
/* GL locking 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 */
shader_generate_glsl_declarations(context, buffer, (IWineD3DBaseShader *)This, reg_maps, &priv_ctx);
/* 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)
{
shader_addline(buffer, "bvec3 srgb_compare = lessThan(gl_FragData[0].xyz, vec3(srgb_const1.x));\n");
}
/* Pixel shader < 3.0 do not replace the fog stage.
* This implements linear fog computation and blending.
* TODO: non linear fog
* NOTE: gl_Fog.start and gl_Fog.end don't hold fog start s and end e but
* -1/(e-s) and e/(e-s) respectively.
*/
{
case FOG_OFF: break;
case FOG_LINEAR:
break;
case FOG_EXP:
/* Fog = e^(-gl_Fog.density * gl_FogFragCoord) */
break;
case 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;
}
}
/* Store the shader object */
return shader_obj;
}
/* GL locking 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 */
shader_generate_glsl_declarations(context, buffer, (IWineD3DBaseShader *)This, reg_maps, &priv_ctx);
/* Base Shader Body */
/* Unpack 3.0 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)
*/
}
/* 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.
*/
if(args->clip_enabled) {
}
/* 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;
}
const struct ps_compile_args *args,
#ifdef VBOX_WITH_WDDM
#else
const struct ps_np2fixup_info **np2fixup_info
#endif
)
{
UINT i;
struct glsl_ps_compiled_shader *new_array;
struct glsl_pshader_private *shader_data;
{
shader->baseShader.backend_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_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++) {
#ifdef VBOX_WITH_WDDM
*inp2fixup_info = i;
#else
#endif
}
}
}
if (shader_data->num_gl_shaders)
{
} else {
new_size = 1;
}
if(!new_array) {
ERR("Out of memory\n");
return 0;
}
}
memset(&shader_data->gl_shaders[shader_data->num_gl_shaders].np2fixup, 0, sizeof(struct ps_np2fixup_info));
#ifdef VBOX_WITH_WDDM
#else
#endif
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_vs_compiled_shader *new_array;
struct glsl_vshader_private *shader_data;
{
shader->baseShader.backend_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_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++) {
}
}
if (shader_data->num_gl_shaders)
{
} else {
new_size = 1;
}
if(!new_array) {
ERR("Out of memory\n");
return 0;
}
}
return ret;
}
/** Sets the GLSL program ID for the given pixel and vertex shader combination.
* It sets the programId on the current StateBlock (because it should be called
* inside of the DrawPrimitive() part of the render loop).
*
* If a program for the given combination does not exist, create one, and store
* the program in the hash table. If it creates a program, it will link the
* given objects, too.
*/
/* GL locking is done by the caller */
{
GLhandleARB programId = 0;
unsigned int i;
char glsl_name[8];
struct ps_compile_args ps_compile_args;
struct vs_compile_args vs_compile_args;
if (vshader) find_vs_compile_args((IWineD3DVertexShaderImpl *)vshader, device->stateBlock, &vs_compile_args);
if (pshader) find_ps_compile_args((IWineD3DPixelShaderImpl *)pshader, device->stateBlock, &ps_compile_args);
if (entry) {
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 (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
*/
checkGLcall("glAttachObjectARB");
/* 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");
list_add_head(&((IWineD3DBaseShaderImpl *)vshader)->baseShader.linked_programs, &entry->vshader_entry);
}
/* Attach GLSL pshader */
if (pshader)
{
#ifdef VBOX_WITH_WDDM
#else
#endif
);
checkGLcall("glAttachObjectARB");
list_add_head(&((IWineD3DBaseShaderImpl *)pshader)->baseShader.linked_programs, &entry->pshader_entry);
}
/* Link the program */
{
}
for (i = 0; i < MAX_CONST_I; ++i)
{
}
{
}
for (i = 0; i < MAX_CONST_I; ++i)
{
}
if(pshader) {
char name[32];
for(i = 0; i < MAX_TEXTURES; i++) {
}
if (ps_compile_args.np2_fixup) {
if (WINEFIXUPINFO_ISVALID(entry)) {
} else {
FIXME("NP2 texcoord fixup needed for this pixelshader, but no fixup uniform found.\n");
}
}
}
checkGLcall("Find glsl program uniform locations");
if (pshader
{
} 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.
*/
/* If the local constants do not have to be loaded with the environment constants,
* load them now to have them hardcoded in the GLSL program. This saves some CPU cycles
* later
*/
{
}
{
}
}
/* GL locking is done by the caller */
static GLhandleARB create_glsl_blt_shader(const struct wined3d_gl_info *gl_info, enum tex_types tex_type)
{
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 *blt_pshaders[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",
};
if (!blt_pshaders[tex_type])
{
}
/* Once linked we can mark the shaders for deletion. They will be deleted once the program
* is destroyed
*/
return program_id;
}
/* GL locking is done by the caller */
{
#ifdef VBOX_WITH_WDDM
#else
#endif
GLhandleARB program_id = 0;
old_vertex_color_clamp = priv->glsl_program ? priv->glsl_program->vertex_color_clamp : GL_FIXED_ONLY_ARB;
current_vertex_color_clamp = priv->glsl_program ? priv->glsl_program->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. */
{
}
}
/* GL locking is done by the caller */
if (!*blt_program) {
} else {
}
}
/* GL locking is done by the caller */
checkGLcall("glUseProgramObjectARB");
}
const struct list *linked_programs;
const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
/* Note: Do not use QueryInterface here to find out which shader type this is because this code
* can be called from IWineD3DBaseShader::Release
*/
if(pshader) {
struct glsl_pshader_private *shader_data;
{
return;
}
{
ENTER_GL();
LEAVE_GL();
}
} else {
struct glsl_vshader_private *shader_data;
{
return;
}
{
ENTER_GL();
LEAVE_GL();
}
}
TRACE("Deleting linked programs\n");
if (linked_programs->next) {
ENTER_GL();
if(pshader) {
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs, struct glsl_shader_prog_link, pshader_entry) {
}
} else {
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs, struct glsl_shader_prog_link, vshader_entry) {
}
}
LEAVE_GL();
}
if(pshader) {
UINT i;
ENTER_GL();
for(i = 0; i < shader_data->num_gl_shaders; i++) {
checkGLcall("glDeleteObjectARB");
}
LEAVE_GL();
}
else
{
UINT i;
ENTER_GL();
for(i = 0; i < shader_data->num_gl_shaders; i++) {
checkGLcall("glDeleteObjectARB");
}
LEAVE_GL();
}
}
{
const glsl_program_key_t *k = key;
const struct glsl_shader_prog_link, program_lookup_entry);
int cmp;
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 =
{
};
struct shader_glsl_priv *priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct shader_glsl_priv));
{
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;
ENTER_GL();
for (i = 0; i < tex_type_count; ++i)
{
if (priv->depth_blt_program[i])
{
}
}
LEAVE_GL();
}
/* TODO: GL_EXT_bindable_uniform can be used to share constants across shaders */
return FALSE;
}
{
* models with GLSL support only support 2.0. In case of nvidia we can detect VS 2.0 support based
* on the version of NV_vertex_program.
* For Ati cards there's no way using glsl (it abstracts the lowlevel info away) and also not
* using ARB_vertex_program. It is safe to assume that when a card supports pixel shader 2.0 it
* supports vertex shader 2.0 too and the way around. We can detect ps2.0 using the maximum number
* of native instructions, so use that here. For more info see the pixel shader versioning code below.
*/
else
TRACE_(d3d_caps)("Hardware vertex shader version %d.%d enabled (GLSL)\n", (pCaps->VertexShaderVersion >> 8) & 0xff, pCaps->VertexShaderVersion & 0xff);
/* Older DX9-class videocards (GeforceFX / Radeon >9500/X*00) only support pixel shader 2.0/2.0a/2.0b.
* In OpenGL the extensions related to GLSL abstract lowlevel GL info away which is needed
* to distinguish between 2.0 and 3.0 (and 2.0a/2.0b). In case of Nvidia we use their fragment
* program extensions. On other hardware including ATI GL_ARB_fragment_program offers the info
* in max native instructions. Intel and others also offer the info in this extension but they
* don't support GLSL (at least on Windows).
*
* PS2.0 requires at least 96 instructions, 2.0a/2.0b go up to 512. Assume that if the number
* of instructions is 512 or less we have to do with ps2.0 hardware.
* NOTE: ps3.0 hardware requires 512 or more instructions but ati and nvidia offer 'enough' (1024 vs 4096) on their most basic ps3.0 hardware.
*/
else
/* 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.
*/
TRACE_(d3d_caps)("Hardware pixel shader version %d.%d enabled (GLSL)\n", (pCaps->PixelShaderVersion >> 8) & 0xff, pCaps->PixelShaderVersion & 0xff);
}
{
{
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_arith,
/* WINED3DSIH_BEM */ shader_glsl_bem,
/* WINED3DSIH_BREAK */ shader_glsl_break,
/* WINED3DSIH_BREAKC */ shader_glsl_breakc,
/* WINED3DSIH_BREAKP */ NULL,
/* WINED3DSIH_CALL */ shader_glsl_call,
/* WINED3DSIH_CALLNZ */ shader_glsl_callnz,
/* WINED3DSIH_CMP */ shader_glsl_cmp,
/* WINED3DSIH_CND */ shader_glsl_cnd,
/* WINED3DSIH_CRS */ shader_glsl_cross,
/* WINED3DSIH_CUT */ NULL,
/* WINED3DSIH_DCL */ NULL,
/* WINED3DSIH_DEF */ NULL,
/* WINED3DSIH_DEFB */ NULL,
/* WINED3DSIH_DEFI */ NULL,
/* 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 */ NULL,
/* WINED3DSIH_ENDIF */ shader_glsl_end,
/* WINED3DSIH_ENDLOOP */ shader_glsl_end,
/* WINED3DSIH_ENDREP */ shader_glsl_end,
/* WINED3DSIH_EXP */ shader_glsl_map2gl,
/* WINED3DSIH_EXPP */ shader_glsl_expp,
/* WINED3DSIH_FRC */ shader_glsl_map2gl,
/* WINED3DSIH_IADD */ NULL,
/* WINED3DSIH_IF */ shader_glsl_if,
/* WINED3DSIH_IFC */ shader_glsl_ifc,
/* WINED3DSIH_IGE */ NULL,
/* WINED3DSIH_LABEL */ shader_glsl_label,
/* 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 */ NULL,
/* 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_MUL */ shader_glsl_arith,
/* WINED3DSIH_NOP */ NULL,
/* WINED3DSIH_NRM */ shader_glsl_nrm,
/* WINED3DSIH_PHASE */ NULL,
/* WINED3DSIH_POW */ shader_glsl_pow,
/* WINED3DSIH_RCP */ shader_glsl_rcp,
/* WINED3DSIH_REP */ shader_glsl_rep,
/* WINED3DSIH_RET */ shader_glsl_ret,
/* WINED3DSIH_RSQ */ shader_glsl_rsq,
/* WINED3DSIH_SETP */ NULL,
/* WINED3DSIH_SGE */ shader_glsl_compare,
/* WINED3DSIH_SGN */ shader_glsl_sgn,
/* WINED3DSIH_SINCOS */ shader_glsl_sincos,
/* WINED3DSIH_SLT */ shader_glsl_compare,
/* WINED3DSIH_SUB */ shader_glsl_arith,
/* 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,
};
/* Select handler */
/* Unhandled opcode */
if (!hw_fct)
{
return;
}
}
const shader_backend_t glsl_shader_backend = {
};