2006-06-09 09:33:01 +02:00
|
|
|
/*
|
|
|
|
* GLSL pixel and vertex shader implementation
|
|
|
|
*
|
|
|
|
* Copyright 2006 Jason Green
|
2007-01-15 19:30:20 +01:00
|
|
|
* Copyright 2006-2007 Henri Verbeet
|
2006-06-09 09:33:01 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2007-01-15 19:30:12 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
|
2007-01-17 21:41:46 +01:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d_constants);
|
2006-06-09 09:33:01 +02:00
|
|
|
|
|
|
|
#define GLINFO_LOCATION (*gl_info)
|
|
|
|
|
2007-01-15 19:36:58 +01:00
|
|
|
typedef struct {
|
|
|
|
char reg_name[50];
|
|
|
|
char mask_str[6];
|
|
|
|
} glsl_dst_param_t;
|
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
typedef struct {
|
|
|
|
char reg_name[50];
|
|
|
|
char param_str[100];
|
|
|
|
} glsl_src_param_t;
|
|
|
|
|
2007-01-15 19:33:38 +01:00
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
DWORD coord_mask;
|
|
|
|
} glsl_sample_function_t;
|
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
/** Prints the GLSL info log which will contain error messages if they exist */
|
|
|
|
void print_glsl_info_log(WineD3D_GL_Info *gl_info, GLhandleARB obj) {
|
|
|
|
|
|
|
|
int infologLength = 0;
|
|
|
|
char *infoLog;
|
|
|
|
|
|
|
|
GL_EXTCALL(glGetObjectParameterivARB(obj,
|
|
|
|
GL_OBJECT_INFO_LOG_LENGTH_ARB,
|
|
|
|
&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)
|
|
|
|
{
|
|
|
|
infoLog = (char *)HeapAlloc(GetProcessHeap(), 0, infologLength);
|
|
|
|
GL_EXTCALL(glGetInfoLogARB(obj, infologLength, NULL, infoLog));
|
2006-06-12 08:56:13 +02:00
|
|
|
FIXME("Error received from GLSL shader #%u: %s\n", obj, debugstr_a(infoLog));
|
2006-06-09 09:33:01 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, infoLog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-16 22:07:00 +02:00
|
|
|
/**
|
|
|
|
* Loads (pixel shader) samplers
|
|
|
|
*/
|
|
|
|
void shader_glsl_load_psamplers(
|
|
|
|
WineD3D_GL_Info *gl_info,
|
|
|
|
IWineD3DStateBlock* iface) {
|
|
|
|
|
|
|
|
IWineD3DStateBlockImpl* stateBlock = (IWineD3DStateBlockImpl*) iface;
|
2006-08-19 17:23:20 +02:00
|
|
|
GLhandleARB programId = stateBlock->glsl_program->programId;
|
2006-06-16 22:07:00 +02:00
|
|
|
GLhandleARB name_loc;
|
|
|
|
int i;
|
|
|
|
char sampler_name[20];
|
|
|
|
|
2006-06-21 00:32:52 +02:00
|
|
|
for (i=0; i< GL_LIMITS(samplers); ++i) {
|
2006-06-16 22:07:00 +02:00
|
|
|
if (stateBlock->textures[i] != NULL) {
|
2006-06-16 22:07:31 +02:00
|
|
|
snprintf(sampler_name, sizeof(sampler_name), "Psampler%d", i);
|
2006-06-16 22:07:00 +02:00
|
|
|
name_loc = GL_EXTCALL(glGetUniformLocationARB(programId, sampler_name));
|
|
|
|
if (name_loc != -1) {
|
2006-12-28 03:13:57 +01:00
|
|
|
TRACE("Loading %s for texture %d\n", sampler_name, i);
|
2006-06-16 22:07:00 +02:00
|
|
|
GL_EXTCALL(glUniform1iARB(name_loc, i));
|
|
|
|
checkGLcall("glUniform1iARB");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads floating point constants (aka uniforms) into the currently set GLSL program.
|
2006-08-19 17:24:02 +02:00
|
|
|
* When constant_list == NULL, it will load all the constants.
|
2006-06-16 22:07:00 +02:00
|
|
|
*/
|
2006-08-19 17:24:02 +02:00
|
|
|
static void shader_glsl_load_constantsF(IWineD3DBaseShaderImpl* This, WineD3D_GL_Info *gl_info,
|
2006-08-19 17:23:20 +02:00
|
|
|
unsigned int max_constants, float* constants, GLhandleARB *constant_locations,
|
2006-08-19 17:24:02 +02:00
|
|
|
struct list *constant_list) {
|
|
|
|
local_constant* lconst;
|
2006-06-16 22:07:00 +02:00
|
|
|
GLhandleARB tmp_loc;
|
|
|
|
int i;
|
|
|
|
|
2006-08-19 17:24:02 +02:00
|
|
|
if (!constant_list) {
|
|
|
|
if (TRACE_ON(d3d_shader)) {
|
|
|
|
for (i = 0; i < max_constants; ++i) {
|
|
|
|
tmp_loc = constant_locations[i];
|
|
|
|
if (tmp_loc != -1) {
|
2007-01-17 21:41:46 +01:00
|
|
|
TRACE_(d3d_constants)("Loading constants %i: %f, %f, %f, %f\n", i,
|
2006-08-19 17:24:02 +02:00
|
|
|
constants[i * 4 + 0], constants[i * 4 + 1],
|
|
|
|
constants[i * 4 + 2], constants[i * 4 + 3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < max_constants; ++i) {
|
2006-08-19 17:23:20 +02:00
|
|
|
tmp_loc = constant_locations[i];
|
2006-06-16 22:07:00 +02:00
|
|
|
if (tmp_loc != -1) {
|
|
|
|
/* We found this uniform name in the program - go ahead and send the data */
|
2006-08-19 17:24:02 +02:00
|
|
|
GL_EXTCALL(glUniform4fvARB(tmp_loc, 1, constants + (i * 4)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkGLcall("glUniform4fvARB()");
|
|
|
|
} else {
|
|
|
|
constant_entry *constant;
|
|
|
|
if (TRACE_ON(d3d_shader)) {
|
|
|
|
LIST_FOR_EACH_ENTRY(constant, constant_list, constant_entry, entry) {
|
|
|
|
i = constant->idx;
|
|
|
|
tmp_loc = constant_locations[i];
|
|
|
|
if (tmp_loc != -1) {
|
2007-01-17 21:41:46 +01:00
|
|
|
TRACE_(d3d_constants)("Loading constants %i: %f, %f, %f, %f\n", i,
|
2006-08-19 17:24:02 +02:00
|
|
|
constants[i * 4 + 0], constants[i * 4 + 1],
|
|
|
|
constants[i * 4 + 2], constants[i * 4 + 3]);
|
|
|
|
}
|
2006-06-16 22:07:00 +02:00
|
|
|
}
|
|
|
|
}
|
2006-08-19 17:24:02 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(constant, constant_list, constant_entry, entry) {
|
|
|
|
i = constant->idx;
|
|
|
|
tmp_loc = constant_locations[i];
|
|
|
|
if (tmp_loc != -1) {
|
|
|
|
/* We found this uniform name in the program - go ahead and send the data */
|
|
|
|
GL_EXTCALL(glUniform4fvARB(tmp_loc, 1, constants + (i * 4)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkGLcall("glUniform4fvARB()");
|
2006-06-16 22:07:00 +02:00
|
|
|
}
|
2006-07-10 06:51:03 +02:00
|
|
|
|
|
|
|
/* Load immediate constants */
|
2006-08-19 17:24:02 +02:00
|
|
|
if (TRACE_ON(d3d_shader)) {
|
|
|
|
LIST_FOR_EACH_ENTRY(lconst, &This->baseShader.constantsF, local_constant, entry) {
|
|
|
|
tmp_loc = constant_locations[lconst->idx];
|
|
|
|
if (tmp_loc != -1) {
|
|
|
|
GLfloat* values = (GLfloat*)lconst->value;
|
2007-01-17 21:41:46 +01:00
|
|
|
TRACE_(d3d_constants)("Loading local constants %i: %f, %f, %f, %f\n", lconst->idx,
|
2006-08-19 17:24:02 +02:00
|
|
|
values[0], values[1], values[2], values[3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LIST_FOR_EACH_ENTRY(lconst, &This->baseShader.constantsF, local_constant, entry) {
|
|
|
|
tmp_loc = constant_locations[lconst->idx];
|
2006-07-10 06:51:03 +02:00
|
|
|
if (tmp_loc != -1) {
|
|
|
|
/* We found this uniform name in the program - go ahead and send the data */
|
2006-08-19 17:24:02 +02:00
|
|
|
GL_EXTCALL(glUniform4fvARB(tmp_loc, 1, (GLfloat*)lconst->value));
|
2006-07-10 06:51:03 +02:00
|
|
|
}
|
|
|
|
}
|
2006-08-19 17:24:02 +02:00
|
|
|
checkGLcall("glUniform4fvARB()");
|
2006-06-16 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2006-06-16 22:08:34 +02:00
|
|
|
/**
|
|
|
|
* Loads integer constants (aka uniforms) into the currently set GLSL program.
|
|
|
|
* When @constants_set == NULL, it will load all the constants.
|
|
|
|
*/
|
|
|
|
void shader_glsl_load_constantsI(
|
2006-07-10 06:51:03 +02:00
|
|
|
IWineD3DBaseShaderImpl* This,
|
2006-06-16 22:08:34 +02:00
|
|
|
WineD3D_GL_Info *gl_info,
|
|
|
|
GLhandleARB programId,
|
|
|
|
unsigned max_constants,
|
|
|
|
int* constants,
|
2006-07-10 06:51:03 +02:00
|
|
|
BOOL* constants_set) {
|
2006-06-16 22:08:34 +02:00
|
|
|
|
|
|
|
GLhandleARB tmp_loc;
|
|
|
|
int i;
|
2006-08-13 11:18:12 +02:00
|
|
|
char tmp_name[8];
|
2006-07-10 06:51:03 +02:00
|
|
|
char is_pshader = shader_is_pshader_version(This->baseShader.hex_version);
|
2006-06-16 22:08:34 +02:00
|
|
|
const char* prefix = is_pshader? "PI":"VI";
|
2006-07-10 06:51:03 +02:00
|
|
|
struct list* ptr;
|
2006-06-16 22:08:34 +02:00
|
|
|
|
|
|
|
for (i=0; i<max_constants; ++i) {
|
|
|
|
if (NULL == constants_set || constants_set[i]) {
|
|
|
|
|
2007-01-17 21:41:46 +01:00
|
|
|
TRACE_(d3d_constants)("Loading constants %i: %i, %i, %i, %i\n",
|
2006-06-16 22:08:34 +02:00
|
|
|
i, constants[i*4], constants[i*4+1], constants[i*4+2], constants[i*4+3]);
|
|
|
|
|
|
|
|
/* TODO: Benchmark and see if it would be beneficial to store the
|
|
|
|
* locations of the constants to avoid looking up each time */
|
|
|
|
snprintf(tmp_name, sizeof(tmp_name), "%s[%i]", prefix, i);
|
|
|
|
tmp_loc = GL_EXTCALL(glGetUniformLocationARB(programId, tmp_name));
|
|
|
|
if (tmp_loc != -1) {
|
|
|
|
/* We found this uniform name in the program - go ahead and send the data */
|
|
|
|
GL_EXTCALL(glUniform4ivARB(tmp_loc, 1, &constants[i*4]));
|
|
|
|
checkGLcall("glUniform4ivARB");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-10 06:51:03 +02:00
|
|
|
|
|
|
|
/* Load immediate constants */
|
|
|
|
ptr = list_head(&This->baseShader.constantsI);
|
|
|
|
while (ptr) {
|
|
|
|
local_constant* lconst = LIST_ENTRY(ptr, struct local_constant, entry);
|
|
|
|
unsigned int idx = lconst->idx;
|
|
|
|
GLint* values = (GLint*) lconst->value;
|
|
|
|
|
2007-01-17 21:41:46 +01:00
|
|
|
TRACE_(d3d_constants)("Loading local constants %i: %i, %i, %i, %i\n", idx,
|
2006-07-10 06:51:03 +02:00
|
|
|
values[0], values[1], values[2], values[3]);
|
|
|
|
|
|
|
|
snprintf(tmp_name, sizeof(tmp_name), "%s[%i]", prefix, idx);
|
|
|
|
tmp_loc = GL_EXTCALL(glGetUniformLocationARB(programId, tmp_name));
|
|
|
|
if (tmp_loc != -1) {
|
|
|
|
/* We found this uniform name in the program - go ahead and send the data */
|
|
|
|
GL_EXTCALL(glUniform4ivARB(tmp_loc, 1, values));
|
|
|
|
checkGLcall("glUniform4ivARB");
|
|
|
|
}
|
|
|
|
ptr = list_next(&This->baseShader.constantsI, ptr);
|
|
|
|
}
|
2006-06-16 22:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads boolean constants (aka uniforms) into the currently set GLSL program.
|
|
|
|
* When @constants_set == NULL, it will load all the constants.
|
|
|
|
*/
|
|
|
|
void shader_glsl_load_constantsB(
|
2006-07-10 06:51:03 +02:00
|
|
|
IWineD3DBaseShaderImpl* This,
|
2006-06-16 22:08:34 +02:00
|
|
|
WineD3D_GL_Info *gl_info,
|
|
|
|
GLhandleARB programId,
|
|
|
|
unsigned max_constants,
|
|
|
|
BOOL* constants,
|
2006-07-10 06:51:03 +02:00
|
|
|
BOOL* constants_set) {
|
2006-06-16 22:08:34 +02:00
|
|
|
|
|
|
|
GLhandleARB tmp_loc;
|
|
|
|
int i;
|
2006-08-13 11:18:12 +02:00
|
|
|
char tmp_name[8];
|
2006-07-10 06:51:03 +02:00
|
|
|
char is_pshader = shader_is_pshader_version(This->baseShader.hex_version);
|
2006-06-16 22:08:34 +02:00
|
|
|
const char* prefix = is_pshader? "PB":"VB";
|
2006-07-10 06:51:03 +02:00
|
|
|
struct list* ptr;
|
2006-06-16 22:08:34 +02:00
|
|
|
|
|
|
|
for (i=0; i<max_constants; ++i) {
|
|
|
|
if (NULL == constants_set || constants_set[i]) {
|
|
|
|
|
2007-01-17 21:41:46 +01:00
|
|
|
TRACE_(d3d_constants)("Loading constants %i: %i;\n", i, constants[i*4]);
|
2006-06-16 22:08:34 +02:00
|
|
|
|
|
|
|
/* TODO: Benchmark and see if it would be beneficial to store the
|
|
|
|
* locations of the constants to avoid looking up each time */
|
|
|
|
snprintf(tmp_name, sizeof(tmp_name), "%s[%i]", prefix, i);
|
|
|
|
tmp_loc = GL_EXTCALL(glGetUniformLocationARB(programId, tmp_name));
|
|
|
|
if (tmp_loc != -1) {
|
|
|
|
/* We found this uniform name in the program - go ahead and send the data */
|
|
|
|
GL_EXTCALL(glUniform1ivARB(tmp_loc, 1, &constants[i*4]));
|
|
|
|
checkGLcall("glUniform1ivARB");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-10 06:51:03 +02:00
|
|
|
|
|
|
|
/* Load immediate constants */
|
|
|
|
ptr = list_head(&This->baseShader.constantsB);
|
|
|
|
while (ptr) {
|
|
|
|
local_constant* lconst = LIST_ENTRY(ptr, struct local_constant, entry);
|
|
|
|
unsigned int idx = lconst->idx;
|
|
|
|
GLint* values = (GLint*) lconst->value;
|
|
|
|
|
2007-01-17 21:41:46 +01:00
|
|
|
TRACE_(d3d_constants)("Loading local constants %i: %i\n", idx, values[0]);
|
2006-07-10 06:51:03 +02:00
|
|
|
|
|
|
|
snprintf(tmp_name, sizeof(tmp_name), "%s[%i]", prefix, idx);
|
|
|
|
tmp_loc = GL_EXTCALL(glGetUniformLocationARB(programId, tmp_name));
|
|
|
|
if (tmp_loc != -1) {
|
|
|
|
/* We found this uniform name in the program - go ahead and send the data */
|
|
|
|
GL_EXTCALL(glUniform1ivARB(tmp_loc, 1, values));
|
|
|
|
checkGLcall("glUniform1ivARB");
|
|
|
|
}
|
|
|
|
ptr = list_next(&This->baseShader.constantsB, ptr);
|
|
|
|
}
|
2006-06-16 22:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-06-16 22:07:00 +02:00
|
|
|
/**
|
|
|
|
* Loads the app-supplied constants into the currently set GLSL program.
|
|
|
|
*/
|
|
|
|
void shader_glsl_load_constants(
|
2006-09-27 13:15:58 +02:00
|
|
|
IWineD3DDevice* device,
|
2006-06-16 22:07:00 +02:00
|
|
|
char usePixelShader,
|
|
|
|
char useVertexShader) {
|
2006-09-27 13:15:58 +02:00
|
|
|
|
|
|
|
IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) device;
|
|
|
|
IWineD3DStateBlockImpl* stateBlock = deviceImpl->stateBlock;
|
|
|
|
WineD3D_GL_Info *gl_info = &((IWineD3DImpl*) deviceImpl->wineD3D)->gl_info;
|
|
|
|
|
2006-08-19 17:23:20 +02:00
|
|
|
GLhandleARB *constant_locations;
|
2006-08-19 17:24:02 +02:00
|
|
|
struct list *constant_list;
|
2006-08-19 17:23:20 +02:00
|
|
|
GLhandleARB programId;
|
2006-06-16 22:07:00 +02:00
|
|
|
|
2006-08-19 17:23:20 +02:00
|
|
|
if (!stateBlock->glsl_program) {
|
2006-06-16 22:07:00 +02:00
|
|
|
/* No GLSL program set - nothing to do. */
|
|
|
|
return;
|
|
|
|
}
|
2006-08-19 17:23:20 +02:00
|
|
|
programId = stateBlock->glsl_program->programId;
|
2006-06-16 22:07:00 +02:00
|
|
|
|
|
|
|
if (useVertexShader) {
|
2006-07-10 06:51:03 +02:00
|
|
|
IWineD3DBaseShaderImpl* vshader = (IWineD3DBaseShaderImpl*) stateBlock->vertexShader;
|
|
|
|
IWineD3DVertexShaderImpl* vshader_impl = (IWineD3DVertexShaderImpl*) vshader;
|
2006-09-23 19:09:06 +02:00
|
|
|
GLint pos;
|
2006-07-10 06:51:03 +02:00
|
|
|
|
2006-06-16 22:07:00 +02:00
|
|
|
IWineD3DVertexDeclarationImpl* vertexDeclaration =
|
2006-07-10 06:51:03 +02:00
|
|
|
(IWineD3DVertexDeclarationImpl*) vshader_impl->vertexDeclaration;
|
2006-06-16 22:07:00 +02:00
|
|
|
|
2006-08-19 17:23:20 +02:00
|
|
|
constant_locations = stateBlock->glsl_program->vuniformF_locations;
|
2006-08-19 17:24:02 +02:00
|
|
|
constant_list = &stateBlock->set_vconstantsF;
|
2006-08-19 17:23:20 +02:00
|
|
|
|
2006-06-16 22:07:00 +02:00
|
|
|
if (NULL != vertexDeclaration && NULL != vertexDeclaration->constants) {
|
|
|
|
/* Load DirectX 8 float constants/uniforms for vertex shader */
|
2006-08-19 17:23:20 +02:00
|
|
|
shader_glsl_load_constantsF(vshader, gl_info, GL_LIMITS(vshader_constantsF),
|
|
|
|
vertexDeclaration->constants, constant_locations, NULL);
|
2006-06-16 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Load DirectX 9 float constants/uniforms for vertex shader */
|
2006-08-19 17:23:20 +02:00
|
|
|
shader_glsl_load_constantsF(vshader, gl_info, GL_LIMITS(vshader_constantsF),
|
2006-08-19 17:24:02 +02:00
|
|
|
stateBlock->vertexShaderConstantF, constant_locations, constant_list);
|
2006-06-16 22:07:00 +02:00
|
|
|
|
2006-06-16 22:08:34 +02:00
|
|
|
/* Load DirectX 9 integer constants/uniforms for vertex shader */
|
2006-07-10 06:51:03 +02:00
|
|
|
shader_glsl_load_constantsI(vshader, gl_info, programId, MAX_CONST_I,
|
2006-06-16 22:08:34 +02:00
|
|
|
stateBlock->vertexShaderConstantI,
|
2006-07-10 06:51:03 +02:00
|
|
|
stateBlock->set.vertexShaderConstantsI);
|
2006-06-16 22:08:34 +02:00
|
|
|
|
|
|
|
/* Load DirectX 9 boolean constants/uniforms for vertex shader */
|
2006-07-10 06:51:03 +02:00
|
|
|
shader_glsl_load_constantsB(vshader, gl_info, programId, MAX_CONST_B,
|
2006-06-16 22:08:34 +02:00
|
|
|
stateBlock->vertexShaderConstantB,
|
2006-07-10 06:51:03 +02:00
|
|
|
stateBlock->set.vertexShaderConstantsB);
|
2006-09-23 19:09:06 +02:00
|
|
|
|
|
|
|
/* Upload the position fixup params */
|
|
|
|
pos = GL_EXTCALL(glGetUniformLocationARB(programId, "posFixup"));
|
|
|
|
checkGLcall("glGetUniformLocationARB");
|
2006-09-27 13:14:46 +02:00
|
|
|
GL_EXTCALL(glUniform4fvARB(pos, 1, &deviceImpl->posFixup[0]));
|
2006-09-23 19:09:06 +02:00
|
|
|
checkGLcall("glUniform4fvARB");
|
2006-06-16 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (usePixelShader) {
|
|
|
|
|
2006-07-10 06:51:03 +02:00
|
|
|
IWineD3DBaseShaderImpl* pshader = (IWineD3DBaseShaderImpl*) stateBlock->pixelShader;
|
|
|
|
|
2006-08-19 17:23:20 +02:00
|
|
|
constant_locations = stateBlock->glsl_program->puniformF_locations;
|
2006-08-19 17:24:02 +02:00
|
|
|
constant_list = &stateBlock->set_pconstantsF;
|
2006-08-19 17:23:20 +02:00
|
|
|
|
2006-06-16 22:07:00 +02:00
|
|
|
/* Load pixel shader samplers */
|
2006-09-27 13:15:58 +02:00
|
|
|
shader_glsl_load_psamplers(gl_info, (IWineD3DStateBlock*) stateBlock);
|
2006-06-16 22:07:00 +02:00
|
|
|
|
|
|
|
/* Load DirectX 9 float constants/uniforms for pixel shader */
|
2006-08-19 17:23:20 +02:00
|
|
|
shader_glsl_load_constantsF(pshader, gl_info, GL_LIMITS(pshader_constantsF),
|
2006-08-19 17:24:02 +02:00
|
|
|
stateBlock->pixelShaderConstantF, constant_locations, constant_list);
|
2006-06-16 22:07:00 +02:00
|
|
|
|
2006-06-16 22:08:34 +02:00
|
|
|
/* Load DirectX 9 integer constants/uniforms for pixel shader */
|
2006-07-10 06:51:03 +02:00
|
|
|
shader_glsl_load_constantsI(pshader, gl_info, programId, MAX_CONST_I,
|
2006-06-16 22:08:34 +02:00
|
|
|
stateBlock->pixelShaderConstantI,
|
2006-07-10 06:51:03 +02:00
|
|
|
stateBlock->set.pixelShaderConstantsI);
|
2006-06-16 22:08:34 +02:00
|
|
|
|
|
|
|
/* Load DirectX 9 boolean constants/uniforms for pixel shader */
|
2006-07-10 06:51:03 +02:00
|
|
|
shader_glsl_load_constantsB(pshader, gl_info, programId, MAX_CONST_B,
|
2006-06-16 22:08:34 +02:00
|
|
|
stateBlock->pixelShaderConstantB,
|
2006-07-10 06:51:03 +02:00
|
|
|
stateBlock->set.pixelShaderConstantsB);
|
2006-06-16 22:07:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-16 22:07:31 +02:00
|
|
|
/** Generate the variable & register declarations for the GLSL output target */
|
|
|
|
void shader_generate_glsl_declarations(
|
|
|
|
IWineD3DBaseShader *iface,
|
|
|
|
shader_reg_maps* reg_maps,
|
2006-07-19 06:06:07 +02:00
|
|
|
SHADER_BUFFER* buffer,
|
|
|
|
WineD3D_GL_Info* gl_info) {
|
2006-06-16 22:07:31 +02:00
|
|
|
|
|
|
|
IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* There are some minor differences between pixel and vertex shaders */
|
|
|
|
char pshader = shader_is_pshader_version(This->baseShader.hex_version);
|
|
|
|
char prefix = pshader ? 'P' : 'V';
|
|
|
|
|
2006-07-10 12:35:15 +02:00
|
|
|
/* Prototype the subroutines */
|
|
|
|
for (i = 0; i < This->baseShader.limits.label; i++) {
|
|
|
|
if (reg_maps->labels[i])
|
|
|
|
shader_addline(buffer, "void subroutine%lu();\n", i);
|
|
|
|
}
|
|
|
|
|
2006-06-16 22:07:31 +02:00
|
|
|
/* Declare the constants (aka uniforms) */
|
2006-07-19 06:06:07 +02:00
|
|
|
if (This->baseShader.limits.constant_float > 0) {
|
|
|
|
unsigned max_constantsF = min(This->baseShader.limits.constant_float,
|
|
|
|
(pshader ? GL_LIMITS(pshader_constantsF) : GL_LIMITS(vshader_constantsF)));
|
|
|
|
shader_addline(buffer, "uniform vec4 %cC[%u];\n", prefix, max_constantsF);
|
|
|
|
}
|
2006-06-16 22:07:31 +02:00
|
|
|
|
|
|
|
if (This->baseShader.limits.constant_int > 0)
|
|
|
|
shader_addline(buffer, "uniform ivec4 %cI[%u];\n", prefix, This->baseShader.limits.constant_int);
|
|
|
|
|
|
|
|
if (This->baseShader.limits.constant_bool > 0)
|
|
|
|
shader_addline(buffer, "uniform bool %cB[%u];\n", prefix, This->baseShader.limits.constant_bool);
|
|
|
|
|
2006-09-23 19:09:06 +02:00
|
|
|
if(!pshader)
|
|
|
|
shader_addline(buffer, "uniform vec4 posFixup;\n");
|
|
|
|
|
2006-06-16 22:07:31 +02:00
|
|
|
/* Declare texture samplers */
|
|
|
|
for (i = 0; i < This->baseShader.limits.sampler; i++) {
|
|
|
|
if (reg_maps->samplers[i]) {
|
|
|
|
|
2006-07-28 21:34:39 +02:00
|
|
|
DWORD stype = reg_maps->samplers[i] & WINED3DSP_TEXTURETYPE_MASK;
|
2006-06-16 22:07:31 +02:00
|
|
|
switch (stype) {
|
|
|
|
|
2006-07-28 21:34:39 +02:00
|
|
|
case WINED3DSTT_1D:
|
|
|
|
shader_addline(buffer, "uniform sampler1D %csampler%lu;\n", prefix, i);
|
|
|
|
break;
|
|
|
|
case WINED3DSTT_2D:
|
2006-06-16 22:07:31 +02:00
|
|
|
shader_addline(buffer, "uniform sampler2D %csampler%lu;\n", prefix, i);
|
|
|
|
break;
|
2006-07-28 21:34:39 +02:00
|
|
|
case WINED3DSTT_CUBE:
|
2006-06-16 22:07:31 +02:00
|
|
|
shader_addline(buffer, "uniform samplerCube %csampler%lu;\n", prefix, i);
|
|
|
|
break;
|
2006-07-28 21:34:39 +02:00
|
|
|
case WINED3DSTT_VOLUME:
|
2006-06-16 22:07:31 +02:00
|
|
|
shader_addline(buffer, "uniform sampler3D %csampler%lu;\n", prefix, i);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
shader_addline(buffer, "uniform unsupported_sampler %csampler%lu;\n", prefix, i);
|
2006-10-01 05:20:10 +02:00
|
|
|
FIXME("Unrecognized sampler type: %#x\n", stype);
|
2006-06-16 22:07:31 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Declare address variables */
|
|
|
|
for (i = 0; i < This->baseShader.limits.address; i++) {
|
|
|
|
if (reg_maps->address[i])
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "ivec4 A%d;\n", i);
|
2006-06-16 22:07:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Declare texture coordinate temporaries and initialize them */
|
|
|
|
for (i = 0; i < This->baseShader.limits.texcoord; i++) {
|
|
|
|
if (reg_maps->texcoord[i])
|
|
|
|
shader_addline(buffer, "vec4 T%lu = gl_TexCoord[%lu];\n", i, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Declare input register temporaries */
|
|
|
|
for (i=0; i < This->baseShader.limits.packed_input; i++) {
|
|
|
|
if (reg_maps->packed_input[i])
|
|
|
|
shader_addline(buffer, "vec4 IN%lu;\n", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Declare output register temporaries */
|
|
|
|
for (i = 0; i < This->baseShader.limits.packed_output; i++) {
|
|
|
|
if (reg_maps->packed_output[i])
|
|
|
|
shader_addline(buffer, "vec4 OUT%lu;\n", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Declare temporary variables */
|
|
|
|
for(i = 0; i < This->baseShader.limits.temporary; i++) {
|
|
|
|
if (reg_maps->temporary[i])
|
|
|
|
shader_addline(buffer, "vec4 R%lu;\n", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Declare attributes */
|
|
|
|
for (i = 0; i < This->baseShader.limits.attributes; i++) {
|
|
|
|
if (reg_maps->attributes[i])
|
|
|
|
shader_addline(buffer, "attribute vec4 attrib%i;\n", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Declare loop register aL */
|
2006-06-17 05:01:20 +02:00
|
|
|
if (reg_maps->loop) {
|
2006-06-16 22:07:31 +02:00
|
|
|
shader_addline(buffer, "int aL;\n");
|
2006-06-17 05:01:20 +02:00
|
|
|
shader_addline(buffer, "int tmpInt;\n");
|
|
|
|
}
|
2006-06-16 22:07:31 +02:00
|
|
|
|
|
|
|
/* Temporary variables for matrix operations */
|
|
|
|
shader_addline(buffer, "vec4 tmp0;\n");
|
|
|
|
shader_addline(buffer, "vec4 tmp1;\n");
|
|
|
|
|
|
|
|
/* Start the main program */
|
|
|
|
shader_addline(buffer, "void main() {\n");
|
|
|
|
}
|
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* Functions to generate GLSL strings from DirectX Shader bytecode begin here.
|
|
|
|
*
|
|
|
|
* For more information, see http://wiki.winehq.org/DirectX-Shaders
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Prototypes */
|
2007-01-15 19:30:20 +01:00
|
|
|
static void shader_glsl_add_src_param(SHADER_OPCODE_ARG* arg, const DWORD param,
|
2007-01-15 19:37:04 +01:00
|
|
|
const DWORD addr_token, DWORD mask, glsl_src_param_t *src_param);
|
2007-01-15 19:31:06 +01:00
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
/** Used for opcode modifiers - They multiply the result by the specified amount */
|
2006-12-14 15:47:59 +01:00
|
|
|
static const char * const shift_glsl_tab[] = {
|
2006-06-09 09:33:01 +02:00
|
|
|
"", /* 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 */
|
2006-06-10 13:22:27 +02:00
|
|
|
static void shader_glsl_gen_modifier (
|
2006-06-09 09:33:01 +02:00
|
|
|
const DWORD instr,
|
|
|
|
const char *in_reg,
|
|
|
|
const char *in_regswizzle,
|
|
|
|
char *out_str) {
|
|
|
|
|
|
|
|
out_str[0] = 0;
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
if (instr == WINED3DSIO_TEXKILL)
|
2006-06-27 08:00:02 +02:00
|
|
|
return;
|
|
|
|
|
2006-10-10 01:47:42 +02:00
|
|
|
switch (instr & WINED3DSP_SRCMOD_MASK) {
|
2007-01-15 19:36:40 +01:00
|
|
|
case WINED3DSPSM_DZ: /* Need to handle this in the instructions itself (texld & texcrd). */
|
|
|
|
case WINED3DSPSM_DW:
|
2006-10-10 01:47:42 +02:00
|
|
|
case WINED3DSPSM_NONE:
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(out_str, "%s%s", in_reg, in_regswizzle);
|
|
|
|
break;
|
2006-10-10 01:47:42 +02:00
|
|
|
case WINED3DSPSM_NEG:
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(out_str, "-%s%s", in_reg, in_regswizzle);
|
|
|
|
break;
|
2006-10-10 01:47:42 +02:00
|
|
|
case WINED3DSPSM_NOT:
|
2006-07-10 12:35:15 +02:00
|
|
|
sprintf(out_str, "!%s%s", in_reg, in_regswizzle);
|
|
|
|
break;
|
2006-10-10 01:47:42 +02:00
|
|
|
case WINED3DSPSM_BIAS:
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(out_str, "(%s%s - vec4(0.5)%s)", in_reg, in_regswizzle, in_regswizzle);
|
|
|
|
break;
|
2006-10-10 01:47:42 +02:00
|
|
|
case WINED3DSPSM_BIASNEG:
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(out_str, "-(%s%s - vec4(0.5)%s)", in_reg, in_regswizzle, in_regswizzle);
|
|
|
|
break;
|
2006-10-10 01:47:42 +02:00
|
|
|
case WINED3DSPSM_SIGN:
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(out_str, "(2.0 * (%s%s - 0.5))", in_reg, in_regswizzle);
|
|
|
|
break;
|
2006-10-10 01:47:42 +02:00
|
|
|
case WINED3DSPSM_SIGNNEG:
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(out_str, "-(2.0 * (%s%s - 0.5))", in_reg, in_regswizzle);
|
|
|
|
break;
|
2006-10-10 01:47:42 +02:00
|
|
|
case WINED3DSPSM_COMP:
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(out_str, "(1.0 - %s%s)", in_reg, in_regswizzle);
|
|
|
|
break;
|
2006-10-10 01:47:42 +02:00
|
|
|
case WINED3DSPSM_X2:
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(out_str, "(2.0 * %s%s)", in_reg, in_regswizzle);
|
|
|
|
break;
|
2006-10-10 01:47:42 +02:00
|
|
|
case WINED3DSPSM_X2NEG:
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(out_str, "-(2.0 * %s%s)", in_reg, in_regswizzle);
|
|
|
|
break;
|
2006-10-10 01:47:42 +02:00
|
|
|
case WINED3DSPSM_ABS:
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(out_str, "abs(%s%s)", in_reg, in_regswizzle);
|
|
|
|
break;
|
2006-10-10 01:47:42 +02:00
|
|
|
case WINED3DSPSM_ABSNEG:
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(out_str, "-abs(%s%s)", in_reg, in_regswizzle);
|
|
|
|
break;
|
|
|
|
default:
|
2006-10-10 01:47:42 +02:00
|
|
|
FIXME("Unhandled modifier %u\n", (instr & WINED3DSP_SRCMOD_MASK));
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(out_str, "%s%s", in_reg, in_regswizzle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Writes the GLSL variable name that corresponds to the register that the
|
|
|
|
* DX opcode parameter is trying to access */
|
2006-06-10 13:22:27 +02:00
|
|
|
static void shader_glsl_get_register_name(
|
2006-06-09 09:33:01 +02:00
|
|
|
const DWORD param,
|
|
|
|
const DWORD addr_token,
|
|
|
|
char* regstr,
|
|
|
|
BOOL* is_color,
|
|
|
|
SHADER_OPCODE_ARG* arg) {
|
|
|
|
|
|
|
|
/* oPos, oFog and oPts in D3D */
|
2006-12-14 15:47:59 +01:00
|
|
|
static const char * const hwrastout_reg_names[] = { "gl_Position", "gl_FogFragCoord", "gl_PointSize" };
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD reg = param & WINED3DSP_REGNUM_MASK;
|
2006-06-09 09:33:01 +02:00
|
|
|
DWORD regtype = shader_get_regtype(param);
|
|
|
|
IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) arg->shader;
|
2006-09-27 13:14:46 +02:00
|
|
|
IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
|
|
|
|
WineD3D_GL_Info* gl_info = &((IWineD3DImpl*)deviceImpl->wineD3D)->gl_info;
|
|
|
|
|
2006-06-12 08:56:13 +02:00
|
|
|
char pshader = shader_is_pshader_version(This->baseShader.hex_version);
|
2006-06-09 09:33:01 +02:00
|
|
|
char tmpStr[50];
|
2006-06-12 08:53:32 +02:00
|
|
|
|
|
|
|
*is_color = FALSE;
|
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
switch (regtype) {
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_TEMP:
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "R%u", reg);
|
2006-06-09 09:33:01 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_INPUT:
|
2006-06-09 09:33:01 +02:00
|
|
|
if (pshader) {
|
2006-06-12 08:57:07 +02:00
|
|
|
/* Pixel shaders >= 3.0 */
|
2006-10-13 05:36:41 +02:00
|
|
|
if (WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 3)
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "IN%u", reg);
|
2006-06-12 08:57:07 +02:00
|
|
|
else {
|
|
|
|
if (reg==0)
|
|
|
|
strcpy(tmpStr, "gl_Color");
|
|
|
|
else
|
|
|
|
strcpy(tmpStr, "gl_SecondaryColor");
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
} else {
|
2006-07-07 08:27:38 +02:00
|
|
|
if (vshader_input_is_color((IWineD3DVertexShader*) This, reg))
|
|
|
|
*is_color = TRUE;
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "attrib%u", reg);
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_CONST:
|
2006-06-12 09:00:03 +02:00
|
|
|
{
|
|
|
|
const char* prefix = pshader? "PC":"VC";
|
|
|
|
|
2006-07-10 06:51:03 +02:00
|
|
|
/* Relative addressing */
|
2006-10-13 05:35:03 +02:00
|
|
|
if (param & WINED3DSHADER_ADDRMODE_RELATIVE) {
|
2006-07-10 06:51:03 +02:00
|
|
|
|
|
|
|
/* Relative addressing on shaders 2.0+ have a relative address token,
|
|
|
|
* prior to that, it was hard-coded as "A0.x" because there's only 1 register */
|
2006-10-13 05:36:41 +02:00
|
|
|
if (WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 2) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t rel_param;
|
|
|
|
shader_glsl_add_src_param(arg, addr_token, 0, WINED3DSP_WRITEMASK_0, &rel_param);
|
|
|
|
sprintf(tmpStr, "%s[%s + %u]", prefix, rel_param.param_str, reg);
|
2006-07-10 06:51:03 +02:00
|
|
|
} else
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "%s[A0.x + %u]", prefix, reg);
|
2006-07-10 06:51:03 +02:00
|
|
|
|
|
|
|
} else
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "%s[%u]", prefix, reg);
|
2006-07-10 06:51:03 +02:00
|
|
|
|
2006-06-12 09:00:03 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_CONSTINT:
|
2006-07-10 06:51:03 +02:00
|
|
|
if (pshader)
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "PI[%u]", reg);
|
2006-07-10 06:51:03 +02:00
|
|
|
else
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "VI[%u]", reg);
|
2006-06-16 22:07:31 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_CONSTBOOL:
|
2006-07-10 06:51:03 +02:00
|
|
|
if (pshader)
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "PB[%u]", reg);
|
2006-07-10 06:51:03 +02:00
|
|
|
else
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "VB[%u]", reg);
|
2006-06-16 22:07:31 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_TEXTURE: /* case WINED3DSPR_ADDR: */
|
2006-06-09 09:33:01 +02:00
|
|
|
if (pshader) {
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "T%u", reg);
|
2006-06-09 09:33:01 +02:00
|
|
|
} else {
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "A%u", reg);
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_LOOP:
|
2006-06-14 04:32:14 +02:00
|
|
|
sprintf(tmpStr, "aL");
|
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_SAMPLER:
|
2006-06-12 08:59:16 +02:00
|
|
|
if (pshader)
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "Psampler%u", reg);
|
2006-06-12 08:59:16 +02:00
|
|
|
else
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "Vsampler%u", reg);
|
2006-06-09 09:33:01 +02:00
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_COLOROUT:
|
2006-12-19 19:25:42 +01:00
|
|
|
if (reg >= GL_LIMITS(buffers)) {
|
|
|
|
WARN("Write to render target %u, only %d supported\n", reg, 4);
|
|
|
|
}
|
2006-08-09 22:54:14 +02:00
|
|
|
if (GL_SUPPORT(ARB_DRAW_BUFFERS)) {
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "gl_FragData[%u]", reg);
|
2006-08-09 22:54:14 +02:00
|
|
|
} else { /* On older cards with GLSL support like the GeforceFX there's only one buffer. */
|
2006-12-19 19:25:42 +01:00
|
|
|
sprintf(tmpStr, "gl_FragColor");
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_RASTOUT:
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(tmpStr, "%s", hwrastout_reg_names[reg]);
|
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_DEPTHOUT:
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(tmpStr, "gl_FragDepth");
|
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_ATTROUT:
|
2006-06-09 09:33:01 +02:00
|
|
|
if (reg == 0) {
|
|
|
|
sprintf(tmpStr, "gl_FrontColor");
|
|
|
|
} else {
|
|
|
|
sprintf(tmpStr, "gl_FrontSecondaryColor");
|
|
|
|
}
|
|
|
|
break;
|
2006-10-10 01:45:55 +02:00
|
|
|
case WINED3DSPR_TEXCRDOUT:
|
|
|
|
/* Vertex shaders >= 3.0: WINED3DSPR_OUTPUT */
|
2006-10-13 05:36:41 +02:00
|
|
|
if (WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 3)
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "OUT%u", reg);
|
2006-06-12 08:57:07 +02:00
|
|
|
else
|
2006-10-01 05:20:10 +02:00
|
|
|
sprintf(tmpStr, "gl_TexCoord[%u]", reg);
|
2006-06-09 09:33:01 +02:00
|
|
|
break;
|
|
|
|
default:
|
2006-10-01 05:20:10 +02:00
|
|
|
FIXME("Unhandled register name Type(%d)\n", regtype);
|
2006-06-09 09:33:01 +02:00
|
|
|
sprintf(tmpStr, "unrecognized_register");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcat(regstr, tmpStr);
|
|
|
|
}
|
|
|
|
|
2006-12-29 15:31:26 +01:00
|
|
|
/* Get the GLSL write mask for the destination register */
|
2007-01-15 19:30:28 +01:00
|
|
|
static DWORD shader_glsl_get_write_mask(const DWORD param, char *write_mask) {
|
2006-12-29 15:31:26 +01:00
|
|
|
char *ptr = write_mask;
|
2007-01-15 19:30:28 +01:00
|
|
|
DWORD mask = param & WINED3DSP_WRITEMASK_ALL;
|
2007-01-18 23:41:51 +01:00
|
|
|
DWORD reg_type = shader_get_regtype(param);
|
2006-12-29 15:31:26 +01:00
|
|
|
|
2007-01-18 23:41:51 +01:00
|
|
|
/* gl_FogFragCoord, gl_PointSize and gl_FragDepth are floats, fixup the write mask. */
|
|
|
|
if (((reg_type == WINED3DSPR_RASTOUT) && ((param & WINED3DSP_REGNUM_MASK) != 0))
|
|
|
|
|| reg_type == WINED3DSPR_DEPTHOUT) {
|
2007-01-15 19:30:35 +01:00
|
|
|
mask = WINED3DSP_WRITEMASK_0;
|
|
|
|
} else {
|
2007-01-15 19:36:52 +01:00
|
|
|
*ptr++ = '.';
|
|
|
|
if (param & WINED3DSP_WRITEMASK_0) *ptr++ = 'x';
|
|
|
|
if (param & WINED3DSP_WRITEMASK_1) *ptr++ = 'y';
|
|
|
|
if (param & WINED3DSP_WRITEMASK_2) *ptr++ = 'z';
|
|
|
|
if (param & WINED3DSP_WRITEMASK_3) *ptr++ = 'w';
|
2007-01-02 13:21:47 +01:00
|
|
|
}
|
|
|
|
|
2006-12-29 15:31:26 +01:00
|
|
|
*ptr = '\0';
|
2007-01-15 19:30:28 +01:00
|
|
|
|
|
|
|
return mask;
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
2007-01-15 19:31:49 +01:00
|
|
|
static size_t shader_glsl_get_write_mask_size(DWORD write_mask) {
|
|
|
|
size_t size = 0;
|
|
|
|
|
|
|
|
if (write_mask & WINED3DSP_WRITEMASK_0) ++size;
|
|
|
|
if (write_mask & WINED3DSP_WRITEMASK_1) ++size;
|
|
|
|
if (write_mask & WINED3DSP_WRITEMASK_2) ++size;
|
|
|
|
if (write_mask & WINED3DSP_WRITEMASK_3) ++size;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:31:06 +01:00
|
|
|
static void shader_glsl_get_swizzle(const DWORD param, BOOL fixup, DWORD mask, char *swizzle_str) {
|
2006-12-29 15:31:43 +01:00
|
|
|
/* 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. */
|
2007-01-15 19:36:46 +01:00
|
|
|
DWORD swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
|
2006-12-29 15:31:43 +01:00
|
|
|
const char *swizzle_chars = fixup ? "zyxw" : "xyzw";
|
|
|
|
char *ptr = swizzle_str;
|
|
|
|
|
2007-01-15 19:36:40 +01:00
|
|
|
*ptr++ = '.';
|
2007-01-15 19:36:46 +01:00
|
|
|
/* swizzle bits fields: wwzzyyxx */
|
|
|
|
if (mask & WINED3DSP_WRITEMASK_0) *ptr++ = swizzle_chars[swizzle & 0x03];
|
|
|
|
if (mask & WINED3DSP_WRITEMASK_1) *ptr++ = swizzle_chars[(swizzle >> 2) & 0x03];
|
|
|
|
if (mask & WINED3DSP_WRITEMASK_2) *ptr++ = swizzle_chars[(swizzle >> 4) & 0x03];
|
|
|
|
if (mask & WINED3DSP_WRITEMASK_3) *ptr++ = swizzle_chars[(swizzle >> 6) & 0x03];
|
2007-01-02 13:21:47 +01:00
|
|
|
|
2006-12-29 15:31:43 +01:00
|
|
|
*ptr = '\0';
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
2007-01-15 19:30:20 +01:00
|
|
|
/* From a given parameter token, generate the corresponding GLSL string.
|
|
|
|
* Also, return the actual register name and swizzle in case the
|
2006-06-09 09:33:01 +02:00
|
|
|
* caller needs this information as well. */
|
2007-01-15 19:30:20 +01:00
|
|
|
static void shader_glsl_add_src_param(SHADER_OPCODE_ARG* arg, const DWORD param,
|
2007-01-15 19:37:04 +01:00
|
|
|
const DWORD addr_token, DWORD mask, glsl_src_param_t *src_param) {
|
2007-01-15 19:30:20 +01:00
|
|
|
BOOL is_color = FALSE;
|
2007-01-15 19:37:04 +01:00
|
|
|
char swizzle_str[6];
|
|
|
|
|
|
|
|
src_param->reg_name[0] = '\0';
|
|
|
|
src_param->param_str[0] = '\0';
|
|
|
|
swizzle_str[0] = '\0';
|
2007-01-15 19:30:20 +01:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_get_register_name(param, addr_token, src_param->reg_name, &is_color, arg);
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_get_swizzle(param, is_color, mask, swizzle_str);
|
|
|
|
shader_glsl_gen_modifier(param, src_param->reg_name, swizzle_str, src_param->param_str);
|
2007-01-15 19:30:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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. */
|
2007-01-15 19:30:28 +01:00
|
|
|
static DWORD shader_glsl_add_dst_param(SHADER_OPCODE_ARG* arg, const DWORD param,
|
2007-01-15 19:36:58 +01:00
|
|
|
const DWORD addr_token, glsl_dst_param_t *dst_param) {
|
2006-06-09 09:33:01 +02:00
|
|
|
BOOL is_color = FALSE;
|
|
|
|
|
2007-01-15 19:36:58 +01:00
|
|
|
dst_param->mask_str[0] = '\0';
|
|
|
|
dst_param->reg_name[0] = '\0';
|
2007-01-15 19:30:20 +01:00
|
|
|
|
2007-01-15 19:36:58 +01:00
|
|
|
shader_glsl_get_register_name(param, addr_token, dst_param->reg_name, &is_color, arg);
|
|
|
|
return shader_glsl_get_write_mask(param, dst_param->mask_str);
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
2007-01-15 19:30:59 +01:00
|
|
|
/* Append the destination part of the instruction to the buffer, return the effective write mask */
|
|
|
|
static DWORD shader_glsl_append_dst(SHADER_BUFFER *buffer, SHADER_OPCODE_ARG *arg) {
|
2007-01-15 19:36:58 +01:00
|
|
|
glsl_dst_param_t dst_param;
|
2007-01-15 19:30:59 +01:00
|
|
|
DWORD mask;
|
|
|
|
int shift;
|
|
|
|
|
|
|
|
shift = (arg->dst & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT;
|
2007-01-15 19:36:58 +01:00
|
|
|
mask = shader_glsl_add_dst_param(arg, arg->dst, arg->dst_addr, &dst_param);
|
|
|
|
shader_addline(buffer, "%s%s = %s(", dst_param.reg_name, dst_param.mask_str, shift_glsl_tab[shift]);
|
2007-01-15 19:30:59 +01:00
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
/** Process GLSL instruction modifiers */
|
|
|
|
void shader_glsl_add_instruction_modifiers(SHADER_OPCODE_ARG* arg) {
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
|
2006-10-10 01:48:12 +02:00
|
|
|
DWORD mask = arg->dst & WINED3DSP_DSTMOD_MASK;
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
|
|
|
|
if (arg->opcode->dst_token && mask != 0) {
|
2007-01-15 19:36:58 +01:00
|
|
|
glsl_dst_param_t dst_param;
|
|
|
|
|
|
|
|
shader_glsl_add_dst_param(arg, arg->dst, 0, &dst_param);
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2006-10-10 01:48:12 +02:00
|
|
|
if (mask & WINED3DSPDM_SATURATE) {
|
2006-06-09 09:33:01 +02:00
|
|
|
/* _SAT means to clamp the value of the register to between 0 and 1 */
|
2007-01-15 19:36:58 +01:00
|
|
|
shader_addline(arg->buffer, "%s%s = clamp(%s%s, 0.0, 1.0);\n", dst_param.reg_name,
|
|
|
|
dst_param.mask_str, dst_param.reg_name, dst_param.mask_str);
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
2006-10-10 01:48:12 +02:00
|
|
|
if (mask & WINED3DSPDM_MSAMPCENTROID) {
|
2006-06-09 09:33:01 +02:00
|
|
|
FIXME("_centroid modifier not handled\n");
|
|
|
|
}
|
2006-10-10 01:48:12 +02:00
|
|
|
if (mask & WINED3DSPDM_PARTIALPRECISION) {
|
2006-06-09 09:33:01 +02:00
|
|
|
/* MSDN says this modifier can be safely ignored, so that's what we'll do. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
static inline const char* shader_get_comp_op(
|
|
|
|
const DWORD opcode) {
|
|
|
|
|
|
|
|
DWORD op = (opcode & INST_CONTROLS_MASK) >> INST_CONTROLS_SHIFT;
|
|
|
|
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:
|
2006-10-01 05:20:10 +02:00
|
|
|
FIXME("Unrecognized comparison value: %u\n", op);
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
return "(\?\?)";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:33:38 +01:00
|
|
|
static void shader_glsl_get_sample_function(DWORD sampler_type, BOOL projected, glsl_sample_function_t *sample_function) {
|
|
|
|
/* Note that there's no such thing as a projected cube texture. */
|
|
|
|
switch(sampler_type) {
|
|
|
|
case WINED3DSTT_1D:
|
|
|
|
sample_function->name = projected ? "texture1DProj" : "texture1D";
|
|
|
|
sample_function->coord_mask = WINED3DSP_WRITEMASK_0;
|
|
|
|
break;
|
|
|
|
case WINED3DSTT_2D:
|
|
|
|
sample_function->name = projected ? "texture2DProj" : "texture2D";
|
|
|
|
sample_function->coord_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1;
|
|
|
|
break;
|
|
|
|
case WINED3DSTT_CUBE:
|
|
|
|
sample_function->name = "textureCube";
|
|
|
|
sample_function->coord_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
|
|
|
break;
|
|
|
|
case WINED3DSTT_VOLUME:
|
|
|
|
sample_function->name = projected ? "texture3DProj" : "texture3D";
|
|
|
|
sample_function->coord_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sample_function->name = "";
|
|
|
|
FIXME("Unrecognized sampler type: %#x;\n", sampler_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-27 20:50:47 +01:00
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* Begin processing individual instruction opcodes
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2006-06-15 17:38:04 +02:00
|
|
|
/* Generate GLSL arithmetic functions (dst = src1 + src2) */
|
2006-06-09 09:33:01 +02:00
|
|
|
void shader_glsl_arith(SHADER_OPCODE_ARG* arg) {
|
|
|
|
CONST SHADER_OPCODE* curOpcode = arg->opcode;
|
|
|
|
SHADER_BUFFER* buffer = arg->buffer;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
glsl_src_param_t src1_param;
|
2007-01-15 19:31:31 +01:00
|
|
|
DWORD write_mask;
|
|
|
|
char op;
|
2006-06-09 09:33:01 +02:00
|
|
|
|
|
|
|
/* Determine the GLSL operator to use based on the opcode */
|
|
|
|
switch (curOpcode->opcode) {
|
2007-01-15 19:31:31 +01:00
|
|
|
case WINED3DSIO_MUL: op = '*'; break;
|
|
|
|
case WINED3DSIO_ADD: op = '+'; break;
|
|
|
|
case WINED3DSIO_SUB: op = '-'; break;
|
2006-06-09 09:33:01 +02:00
|
|
|
default:
|
2007-01-15 19:31:31 +01:00
|
|
|
op = ' ';
|
2006-06-09 09:33:01 +02:00
|
|
|
FIXME("Opcode %s not yet handled in GLSL\n", curOpcode->name);
|
|
|
|
break;
|
|
|
|
}
|
2007-01-15 19:31:31 +01:00
|
|
|
|
|
|
|
write_mask = shader_glsl_append_dst(buffer, arg);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], write_mask, &src0_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], write_mask, &src1_param);
|
|
|
|
shader_addline(buffer, "%s %c %s);\n", src0_param.param_str, op, src1_param.param_str);
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/* Process the WINED3DSIO_MOV opcode using GLSL (dst = src) */
|
2006-06-09 09:33:01 +02:00
|
|
|
void shader_glsl_mov(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:32:27 +01:00
|
|
|
IWineD3DBaseShaderImpl* shader = (IWineD3DBaseShaderImpl*) arg->shader;
|
2006-06-09 09:33:01 +02:00
|
|
|
SHADER_BUFFER* buffer = arg->buffer;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
2007-01-15 19:32:27 +01:00
|
|
|
DWORD write_mask;
|
|
|
|
|
|
|
|
write_mask = shader_glsl_append_dst(buffer, arg);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], write_mask, &src0_param);
|
2007-01-15 19:32:27 +01:00
|
|
|
|
|
|
|
/* In vs_1_1 WINED3DSIO_MOV can write to the adress register. In later
|
|
|
|
* shader versions WINED3DSIO_MOVA is used for this. */
|
|
|
|
if ((WINED3DSHADER_VERSION_MAJOR(shader->baseShader.hex_version) == 1 &&
|
|
|
|
!shader_is_pshader_version(shader->baseShader.hex_version) &&
|
|
|
|
shader_get_regtype(arg->dst) == WINED3DSPR_ADDR) ||
|
|
|
|
arg->opcode->opcode == WINED3DSIO_MOVA) {
|
|
|
|
/* We need to *round* to the nearest int here. */
|
|
|
|
size_t mask_size = shader_glsl_get_write_mask_size(write_mask);
|
|
|
|
if (mask_size > 1) {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(buffer, "ivec%d(floor(%s + vec%d(0.5))));\n", mask_size, src0_param.param_str, mask_size);
|
2007-01-15 19:32:27 +01:00
|
|
|
} else {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(buffer, "int(floor(%s + 0.5)));\n", src0_param.param_str);
|
2007-01-15 19:32:27 +01:00
|
|
|
}
|
|
|
|
} else {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(buffer, "%s);\n", src0_param.param_str);
|
2007-01-15 19:32:27 +01:00
|
|
|
}
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process the dot product operators DP3 and DP4 in GLSL (dst = dot(src0, src1)) */
|
|
|
|
void shader_glsl_dot(SHADER_OPCODE_ARG* arg) {
|
|
|
|
CONST SHADER_OPCODE* curOpcode = arg->opcode;
|
|
|
|
SHADER_BUFFER* buffer = arg->buffer;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
glsl_src_param_t src1_param;
|
2007-01-15 19:32:13 +01:00
|
|
|
DWORD dst_write_mask, src_write_mask;
|
|
|
|
size_t dst_size = 0;
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:32:13 +01:00
|
|
|
dst_write_mask = shader_glsl_append_dst(buffer, arg);
|
|
|
|
dst_size = shader_glsl_get_write_mask_size(dst_write_mask);
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:32:13 +01:00
|
|
|
/* dp3 works on vec3, dp4 on vec4 */
|
|
|
|
if (curOpcode->opcode == WINED3DSIO_DP4) {
|
|
|
|
src_write_mask = WINED3DSP_WRITEMASK_ALL;
|
|
|
|
} else {
|
|
|
|
src_write_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_write_mask, &src0_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], src_write_mask, &src1_param);
|
2007-01-15 19:32:13 +01:00
|
|
|
|
|
|
|
if (dst_size > 1) {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(buffer, "vec%d(dot(%s, %s)));\n", dst_size, src0_param.param_str, src1_param.param_str);
|
2007-01-15 19:32:13 +01:00
|
|
|
} else {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(buffer, "dot(%s, %s));\n", src0_param.param_str, src1_param.param_str);
|
2007-01-15 19:32:13 +01:00
|
|
|
}
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
2007-01-15 19:31:56 +01:00
|
|
|
/* 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 */
|
|
|
|
void shader_glsl_cross(SHADER_OPCODE_ARG *arg) {
|
|
|
|
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
glsl_src_param_t src1_param;
|
2007-01-15 19:31:56 +01:00
|
|
|
char dst_mask[6];
|
|
|
|
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_mask);
|
|
|
|
shader_glsl_append_dst(arg->buffer, arg);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], src_mask, &src1_param);
|
|
|
|
shader_addline(arg->buffer, "cross(%s, %s).%s);\n", src0_param.param_str, src1_param.param_str, dst_mask);
|
2007-01-15 19:31:56 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
/* Map the opcode 1-to-1 to the GL code (arg->dst = instruction(src0, src1, ...) */
|
|
|
|
void shader_glsl_map2gl(SHADER_OPCODE_ARG* arg) {
|
|
|
|
CONST SHADER_OPCODE* curOpcode = arg->opcode;
|
|
|
|
SHADER_BUFFER* buffer = arg->buffer;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src_param;
|
2007-01-15 19:32:07 +01:00
|
|
|
const char *instruction;
|
|
|
|
char arguments[256];
|
|
|
|
DWORD write_mask;
|
2006-06-09 09:33:01 +02:00
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
/* Determine the GLSL function to use based on the opcode */
|
|
|
|
/* TODO: Possibly make this a table for faster lookups */
|
|
|
|
switch (curOpcode->opcode) {
|
2007-01-15 19:32:07 +01:00
|
|
|
case WINED3DSIO_MIN: instruction = "min"; break;
|
|
|
|
case WINED3DSIO_MAX: instruction = "max"; break;
|
|
|
|
case WINED3DSIO_RSQ: instruction = "inversesqrt"; break;
|
|
|
|
case WINED3DSIO_ABS: instruction = "abs"; break;
|
|
|
|
case WINED3DSIO_FRC: instruction = "fract"; break;
|
|
|
|
case WINED3DSIO_POW: instruction = "pow"; break;
|
|
|
|
case WINED3DSIO_NRM: instruction = "normalize"; break;
|
|
|
|
case WINED3DSIO_LOGP:
|
|
|
|
case WINED3DSIO_LOG: instruction = "log2"; break;
|
|
|
|
case WINED3DSIO_EXP: instruction = "exp2"; break;
|
|
|
|
case WINED3DSIO_SGN: instruction = "sign"; break;
|
|
|
|
default: instruction = "";
|
2006-06-09 09:33:01 +02:00
|
|
|
FIXME("Opcode %s not yet handled in GLSL\n", curOpcode->name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:32:07 +01:00
|
|
|
write_mask = shader_glsl_append_dst(buffer, arg);
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:32:07 +01:00
|
|
|
arguments[0] = '\0';
|
2006-06-09 09:33:01 +02:00
|
|
|
if (curOpcode->num_params > 0) {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], write_mask, &src_param);
|
|
|
|
strcat(arguments, src_param.param_str);
|
2006-06-09 09:33:01 +02:00
|
|
|
for (i = 2; i < curOpcode->num_params; ++i) {
|
2007-01-15 19:32:07 +01:00
|
|
|
strcat(arguments, ", ");
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[i-1], arg->src_addr[i-1], write_mask, &src_param);
|
|
|
|
strcat(arguments, src_param.param_str);
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:32:07 +01:00
|
|
|
shader_addline(buffer, "%s(%s));\n", instruction, arguments);
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_EXPP instruction in GLSL:
|
2006-07-28 10:14:14 +02:00
|
|
|
* 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)
|
|
|
|
*/
|
|
|
|
void shader_glsl_expp(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:33:01 +01:00
|
|
|
IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)arg->shader;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src_param;
|
2006-07-28 10:14:14 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src_param);
|
2006-07-28 10:14:14 +02:00
|
|
|
|
2007-01-15 19:33:01 +01:00
|
|
|
if (shader->baseShader.hex_version < WINED3DPS_VERSION(2,0)) {
|
|
|
|
char dst_mask[6];
|
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "tmp0.x = exp2(floor(%s));\n", src_param.param_str);
|
|
|
|
shader_addline(arg->buffer, "tmp0.y = %s - floor(%s);\n", src_param.param_str, src_param.param_str);
|
|
|
|
shader_addline(arg->buffer, "tmp0.z = exp2(%s);\n", src_param.param_str);
|
2006-07-28 10:14:14 +02:00
|
|
|
shader_addline(arg->buffer, "tmp0.w = 1.0;\n");
|
2007-01-15 19:33:01 +01:00
|
|
|
|
|
|
|
shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_mask);
|
|
|
|
shader_addline(arg->buffer, "tmp0%s);\n", dst_mask);
|
2006-07-28 10:14:14 +02:00
|
|
|
} else {
|
2007-01-15 19:33:01 +01:00
|
|
|
DWORD write_mask;
|
|
|
|
size_t mask_size;
|
|
|
|
|
|
|
|
write_mask = shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
mask_size = shader_glsl_get_write_mask_size(write_mask);
|
|
|
|
|
|
|
|
if (mask_size > 1) {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "vec%d(exp2(%s)));\n", mask_size, src_param.param_str);
|
2007-01-15 19:33:01 +01:00
|
|
|
} else {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "exp2(%s));\n", src_param.param_str);
|
2007-01-15 19:33:01 +01:00
|
|
|
}
|
2006-07-28 10:14:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
/** Process the RCP (reciprocal or inverse) opcode in GLSL (dst = 1 / src) */
|
|
|
|
void shader_glsl_rcp(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src_param;
|
2007-01-15 19:33:06 +01:00
|
|
|
DWORD write_mask;
|
|
|
|
size_t mask_size;
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:33:06 +01:00
|
|
|
write_mask = shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
mask_size = shader_glsl_get_write_mask_size(write_mask);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src_param);
|
2007-01-15 19:33:06 +01:00
|
|
|
|
|
|
|
if (mask_size > 1) {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "vec%d(1.0 / %s));\n", mask_size, src_param.param_str);
|
2007-01-15 19:33:06 +01:00
|
|
|
} else {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "1.0 / %s);\n", src_param.param_str);
|
2007-01-15 19:33:06 +01:00
|
|
|
}
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Process signed comparison opcodes in GLSL. */
|
|
|
|
void shader_glsl_compare(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
glsl_src_param_t src1_param;
|
2007-01-15 19:31:49 +01:00
|
|
|
DWORD write_mask;
|
|
|
|
size_t mask_size;
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:31:49 +01:00
|
|
|
write_mask = shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
mask_size = shader_glsl_get_write_mask_size(write_mask);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], write_mask, &src0_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], write_mask, &src1_param);
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:31:49 +01:00
|
|
|
if (mask_size > 1) {
|
|
|
|
const char *compare;
|
|
|
|
|
|
|
|
switch(arg->opcode->opcode) {
|
|
|
|
case WINED3DSIO_SLT: compare = "lessThan"; break;
|
|
|
|
case WINED3DSIO_SGE: compare = "greaterThanEqual"; break;
|
|
|
|
default: compare = "";
|
|
|
|
FIXME("Can't handle opcode %s\n", arg->opcode->name);
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "vec%d(%s(%s, %s)));\n", mask_size, compare,
|
|
|
|
src0_param.param_str, src1_param.param_str);
|
2006-06-09 09:33:01 +02:00
|
|
|
} else {
|
2007-01-15 19:31:49 +01:00
|
|
|
const char *compare;
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:31:49 +01:00
|
|
|
switch(arg->opcode->opcode) {
|
|
|
|
case WINED3DSIO_SLT: compare = "<"; break;
|
|
|
|
case WINED3DSIO_SGE: compare = ">="; break;
|
|
|
|
default: compare = "";
|
2006-06-09 09:33:01 +02:00
|
|
|
FIXME("Can't handle opcode %s\n", arg->opcode->name);
|
|
|
|
}
|
2007-01-15 19:31:49 +01:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "(%s %s %s) ? 1.0 : 0.0);\n",
|
|
|
|
src0_param.param_str, compare, src1_param.param_str);
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:32:48 +01:00
|
|
|
/** Process CMP instruction in GLSL (dst = src0 >= 0.0 ? src1 : src2), per channel */
|
2006-06-09 09:33:01 +02:00
|
|
|
void shader_glsl_cmp(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
glsl_src_param_t src1_param;
|
|
|
|
glsl_src_param_t src2_param;
|
2007-01-15 19:32:48 +01:00
|
|
|
DWORD write_mask;
|
|
|
|
size_t mask_size;
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:32:48 +01:00
|
|
|
write_mask = shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
mask_size = shader_glsl_get_write_mask_size(write_mask);
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], write_mask, &src0_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], write_mask, &src1_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[2], arg->src_addr[2], write_mask, &src2_param);
|
2007-01-15 19:32:48 +01:00
|
|
|
|
|
|
|
if (mask_size > 1) {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "mix(%s, %s, vec%d(lessThan(%s, vec%d(0.0)))));\n",
|
|
|
|
src1_param.param_str, src2_param.param_str, mask_size, src0_param.param_str, mask_size);
|
2007-01-15 19:32:48 +01:00
|
|
|
} else {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "%s >= 0.0 ? %s : %s);\n",
|
|
|
|
src0_param.param_str, src1_param.param_str, src2_param.param_str);
|
2007-01-15 19:32:48 +01:00
|
|
|
}
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Process the CND opcode in GLSL (dst = (src0 < 0.5) ? src1 : src2) */
|
2007-01-15 19:32:54 +01:00
|
|
|
/* 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. */
|
2006-06-09 09:33:01 +02:00
|
|
|
void shader_glsl_cnd(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:32:54 +01:00
|
|
|
IWineD3DBaseShaderImpl* shader = (IWineD3DBaseShaderImpl*) arg->shader;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
glsl_src_param_t src1_param;
|
|
|
|
glsl_src_param_t src2_param;
|
2007-01-15 19:32:54 +01:00
|
|
|
DWORD write_mask;
|
|
|
|
size_t mask_size;
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:32:54 +01:00
|
|
|
write_mask = shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
|
|
|
|
if (shader->baseShader.hex_version < WINED3DPS_VERSION(1, 4)) {
|
|
|
|
mask_size = 1;
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param);
|
2007-01-15 19:32:54 +01:00
|
|
|
} else {
|
|
|
|
mask_size = shader_glsl_get_write_mask_size(write_mask);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], write_mask, &src0_param);
|
2007-01-15 19:32:54 +01:00
|
|
|
}
|
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], write_mask, &src1_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[2], arg->src_addr[2], write_mask, &src2_param);
|
2007-01-15 19:32:54 +01:00
|
|
|
|
|
|
|
if (mask_size > 1) {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "mix(%s, %s, vec%d(lessThan(%s, vec%d(0.5)))));\n",
|
|
|
|
src2_param.param_str, src1_param.param_str, mask_size, src0_param.param_str, mask_size);
|
2007-01-15 19:32:54 +01:00
|
|
|
} else {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "%s < 0.5 ? %s : %s);\n",
|
|
|
|
src0_param.param_str, src1_param.param_str, src2_param.param_str);
|
2007-01-15 19:32:54 +01:00
|
|
|
}
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** GLSL code generation for WINED3DSIO_MAD: Multiply the first 2 opcodes, then add the last */
|
2006-06-09 09:33:01 +02:00
|
|
|
void shader_glsl_mad(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
glsl_src_param_t src1_param;
|
|
|
|
glsl_src_param_t src2_param;
|
2007-01-15 19:31:37 +01:00
|
|
|
DWORD write_mask;
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:31:37 +01:00
|
|
|
write_mask = shader_glsl_append_dst(arg->buffer, arg);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], write_mask, &src0_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], write_mask, &src1_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[2], arg->src_addr[2], write_mask, &src2_param);
|
|
|
|
shader_addline(arg->buffer, "(%s * %s) + %s);\n",
|
|
|
|
src0_param.param_str, src1_param.param_str, src2_param.param_str);
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Handles transforming all WINED3DSIO_M?x? opcodes for
|
2006-06-09 09:33:01 +02:00
|
|
|
Vertex shaders to GLSL codes */
|
|
|
|
void shader_glsl_mnxn(SHADER_OPCODE_ARG* arg) {
|
|
|
|
int i;
|
|
|
|
int nComponents = 0;
|
|
|
|
SHADER_OPCODE_ARG tmpArg;
|
|
|
|
|
|
|
|
memset(&tmpArg, 0, sizeof(SHADER_OPCODE_ARG));
|
|
|
|
|
|
|
|
/* Set constants for the temporary argument */
|
|
|
|
tmpArg.shader = arg->shader;
|
|
|
|
tmpArg.buffer = arg->buffer;
|
|
|
|
tmpArg.src[0] = arg->src[0];
|
|
|
|
tmpArg.src_addr[0] = arg->src_addr[0];
|
2006-07-06 04:35:56 +02:00
|
|
|
tmpArg.src_addr[1] = arg->src_addr[1];
|
2006-06-09 09:33:01 +02:00
|
|
|
tmpArg.reg_maps = arg->reg_maps;
|
|
|
|
|
|
|
|
switch(arg->opcode->opcode) {
|
2006-10-10 01:45:12 +02:00
|
|
|
case WINED3DSIO_M4x4:
|
2006-06-09 09:33:01 +02:00
|
|
|
nComponents = 4;
|
2006-10-30 20:27:01 +01:00
|
|
|
tmpArg.opcode = shader_get_opcode(arg->shader, WINED3DSIO_DP4);
|
2006-06-09 09:33:01 +02:00
|
|
|
break;
|
2006-10-10 01:45:12 +02:00
|
|
|
case WINED3DSIO_M4x3:
|
2006-06-09 09:33:01 +02:00
|
|
|
nComponents = 3;
|
2006-10-30 20:27:01 +01:00
|
|
|
tmpArg.opcode = shader_get_opcode(arg->shader, WINED3DSIO_DP4);
|
2006-06-09 09:33:01 +02:00
|
|
|
break;
|
2006-10-10 01:45:12 +02:00
|
|
|
case WINED3DSIO_M3x4:
|
2006-06-09 09:33:01 +02:00
|
|
|
nComponents = 4;
|
2006-10-30 20:27:01 +01:00
|
|
|
tmpArg.opcode = shader_get_opcode(arg->shader, WINED3DSIO_DP3);
|
2006-06-09 09:33:01 +02:00
|
|
|
break;
|
2006-10-10 01:45:12 +02:00
|
|
|
case WINED3DSIO_M3x3:
|
2006-06-09 09:33:01 +02:00
|
|
|
nComponents = 3;
|
2006-10-30 20:27:01 +01:00
|
|
|
tmpArg.opcode = shader_get_opcode(arg->shader, WINED3DSIO_DP3);
|
2006-06-09 09:33:01 +02:00
|
|
|
break;
|
2006-10-10 01:45:12 +02:00
|
|
|
case WINED3DSIO_M3x2:
|
2006-06-09 09:33:01 +02:00
|
|
|
nComponents = 2;
|
2006-10-30 20:27:01 +01:00
|
|
|
tmpArg.opcode = shader_get_opcode(arg->shader, WINED3DSIO_DP3);
|
2006-06-09 09:33:01 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nComponents; i++) {
|
2006-10-10 01:48:12 +02:00
|
|
|
tmpArg.dst = ((arg->dst) & ~WINED3DSP_WRITEMASK_ALL)|(WINED3DSP_WRITEMASK_0<<i);
|
2006-06-09 09:33:01 +02:00
|
|
|
tmpArg.src[1] = arg->src[1]+i;
|
|
|
|
shader_glsl_dot(&tmpArg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
The LRP instruction performs a component-wise linear interpolation
|
|
|
|
between the second and third operands using the first operand as the
|
2007-01-15 19:32:40 +01:00
|
|
|
blend factor. Equation: (dst = src2 + src0 * (src1 - src2))
|
|
|
|
This is equivalent to mix(src2, src1, src0);
|
2006-06-09 09:33:01 +02:00
|
|
|
*/
|
|
|
|
void shader_glsl_lrp(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
glsl_src_param_t src1_param;
|
|
|
|
glsl_src_param_t src2_param;
|
2007-01-15 19:32:40 +01:00
|
|
|
DWORD write_mask;
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:32:40 +01:00
|
|
|
write_mask = shader_glsl_append_dst(arg->buffer, arg);
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], write_mask, &src0_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], write_mask, &src1_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[2], arg->src_addr[2], write_mask, &src2_param);
|
2007-01-15 19:32:40 +01:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "mix(%s, %s, %s));\n",
|
|
|
|
src2_param.param_str, src1_param.param_str, src0_param.param_str);
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_LIT instruction in GLSL:
|
2006-06-14 04:32:14 +02:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
void shader_glsl_lit(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
glsl_src_param_t src1_param;
|
|
|
|
glsl_src_param_t src3_param;
|
2007-01-15 19:32:33 +01:00
|
|
|
char dst_mask[6];
|
2006-06-14 04:32:14 +02:00
|
|
|
|
2007-01-15 19:32:33 +01:00
|
|
|
shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_mask);
|
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_1, &src1_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_3, &src3_param);
|
2006-06-14 04:32:14 +02:00
|
|
|
|
2007-01-15 19:32:33 +01:00
|
|
|
shader_addline(arg->buffer, "vec4(1.0, (%s > 0.0 ? %s : 0.0), (%s > 0.0 ? ((%s > 0.0) ? pow(%s, clamp(%s, -128.0, 128.0)) : 0.0) : 0.0), 1.0)%s);\n",
|
2007-01-15 19:37:04 +01:00
|
|
|
src0_param.param_str, src0_param.param_str, src0_param.param_str, src1_param.param_str, src1_param.param_str, src3_param.param_str, dst_mask);
|
2006-06-14 04:32:14 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_DST instruction in GLSL:
|
2006-06-14 04:32:14 +02:00
|
|
|
* dst.x = 1.0
|
|
|
|
* dst.y = src0.x * src0.y
|
|
|
|
* dst.z = src0.z
|
|
|
|
* dst.w = src1.w
|
|
|
|
*/
|
|
|
|
void shader_glsl_dst(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0y_param;
|
|
|
|
glsl_src_param_t src0z_param;
|
|
|
|
glsl_src_param_t src1y_param;
|
|
|
|
glsl_src_param_t src1w_param;
|
|
|
|
char dst_mask[6];
|
2006-06-14 04:32:14 +02:00
|
|
|
|
2007-01-15 19:33:15 +01:00
|
|
|
shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_mask);
|
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_1, &src0y_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_2, &src0z_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_1, &src1y_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_3, &src1w_param);
|
2006-06-14 04:32:14 +02:00
|
|
|
|
2007-01-15 19:33:15 +01:00
|
|
|
shader_addline(arg->buffer, "vec4(1.0, %s * %s, %s, %s))%s;\n",
|
2007-01-15 19:37:04 +01:00
|
|
|
src0y_param.param_str, src1y_param.param_str, src0z_param.param_str, src1w_param.param_str, dst_mask);
|
2006-06-14 04:32:14 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_SINCOS instruction in GLSL:
|
2006-06-14 04:32:14 +02:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
void shader_glsl_sincos(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
2007-01-15 19:31:25 +01:00
|
|
|
DWORD write_mask;
|
2006-06-14 04:32:14 +02:00
|
|
|
|
2007-01-15 19:31:25 +01:00
|
|
|
write_mask = shader_glsl_append_dst(arg->buffer, arg);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param);
|
2007-01-15 19:31:25 +01:00
|
|
|
|
|
|
|
switch (write_mask) {
|
|
|
|
case WINED3DSP_WRITEMASK_0:
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "cos(%s));\n", src0_param.param_str);
|
2007-01-15 19:31:25 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DSP_WRITEMASK_1:
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "sin(%s));\n", src0_param.param_str);
|
2007-01-15 19:31:25 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case (WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1):
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "vec2(cos(%s), sin(%s)));\n", src0_param.param_str, src0_param.param_str);
|
2007-01-15 19:31:25 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("Write mask should be .x, .y or .xy\n");
|
|
|
|
break;
|
|
|
|
}
|
2006-06-14 04:32:14 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_LOOP instruction in GLSL:
|
2007-01-15 19:36:11 +01:00
|
|
|
* 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.
|
2006-06-17 05:01:20 +02:00
|
|
|
* Need to use a temporary variable for this operation.
|
2006-06-14 04:32:14 +02:00
|
|
|
*/
|
2007-01-15 19:36:11 +01:00
|
|
|
/* FIXME: I don't think nested loops will work correctly this way. */
|
2006-06-14 04:32:14 +02:00
|
|
|
void shader_glsl_loop(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src1_param;
|
|
|
|
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_ALL, &src1_param);
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
|
|
|
|
shader_addline(arg->buffer, "for (tmpInt = 0, aL = %s.y; tmpInt < %s.x; tmpInt++, aL += %s.z) {\n",
|
2007-01-15 19:37:04 +01:00
|
|
|
src1_param.reg_name, src1_param.reg_name, src1_param.reg_name);
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void shader_glsl_end(SHADER_OPCODE_ARG* arg) {
|
|
|
|
shader_addline(arg->buffer, "}\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void shader_glsl_rep(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param);
|
|
|
|
shader_addline(arg->buffer, "for (tmpInt = 0; tmpInt < %s; tmpInt++) {\n", src0_param.param_str);
|
2006-06-14 04:32:14 +02:00
|
|
|
}
|
|
|
|
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
void shader_glsl_if(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
2006-06-14 04:32:14 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param);
|
|
|
|
shader_addline(arg->buffer, "if (%s) {\n", src0_param.param_str);
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void shader_glsl_ifc(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
glsl_src_param_t src1_param;
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_0, &src1_param);
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
|
|
|
|
shader_addline(arg->buffer, "if (%s %s %s) {\n",
|
2007-01-15 19:37:04 +01:00
|
|
|
src0_param.param_str, shader_get_comp_op(arg->opcode_token), src1_param.param_str);
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void shader_glsl_else(SHADER_OPCODE_ARG* arg) {
|
|
|
|
shader_addline(arg->buffer, "} else {\n");
|
2006-06-14 04:32:14 +02:00
|
|
|
}
|
|
|
|
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
void shader_glsl_break(SHADER_OPCODE_ARG* arg) {
|
|
|
|
shader_addline(arg->buffer, "break;\n");
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:36:29 +01:00
|
|
|
/* FIXME: According to MSDN the compare is done per component. */
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
void shader_glsl_breakc(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
glsl_src_param_t src1_param;
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_0, &src1_param);
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
|
|
|
|
shader_addline(arg->buffer, "if (%s %s %s) break;\n",
|
2007-01-15 19:37:04 +01:00
|
|
|
src0_param.param_str, shader_get_comp_op(arg->opcode_token), src1_param.param_str);
|
wined3d: More flow control instructions
- Implement if, else, endif, rep, endrep, break
- Implement ifc, breakc, using undocumented comparison bits in the instruction token
- Fix bug in main loop processing of codes with no dst token
- Fix bug in GLSL output modifier processing of codes with no dst token
- Fix bug in loop implementation (src1 contains the integer data, src0 is aL)
- Add versioning for all the instructions above, and remove
GLSL_REQUIRED thing, which is useless and should be removed from all
opcodes in general.
2006-07-10 11:11:35 +02:00
|
|
|
}
|
2006-06-14 04:32:14 +02:00
|
|
|
|
2006-07-10 12:35:15 +02:00
|
|
|
void shader_glsl_label(SHADER_OPCODE_ARG* arg) {
|
|
|
|
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD snum = (arg->src[0]) & WINED3DSP_REGNUM_MASK;
|
2006-07-10 12:35:15 +02:00
|
|
|
shader_addline(arg->buffer, "}\n");
|
|
|
|
shader_addline(arg->buffer, "void subroutine%lu () {\n", snum);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shader_glsl_call(SHADER_OPCODE_ARG* arg) {
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD snum = (arg->src[0]) & WINED3DSP_REGNUM_MASK;
|
2006-07-10 12:35:15 +02:00
|
|
|
shader_addline(arg->buffer, "subroutine%lu();\n", snum);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shader_glsl_callnz(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src1_param;
|
2006-07-10 12:35:15 +02:00
|
|
|
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD snum = (arg->src[0]) & WINED3DSP_REGNUM_MASK;
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_0, &src1_param);
|
|
|
|
shader_addline(arg->buffer, "if (%s) subroutine%lu();\n", src1_param.param_str, snum);
|
2006-07-10 12:35:15 +02:00
|
|
|
}
|
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
/*********************************************
|
|
|
|
* Pixel Shader Specific Code begins here
|
|
|
|
********************************************/
|
|
|
|
void pshader_glsl_tex(SHADER_OPCODE_ARG* arg) {
|
|
|
|
IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
|
2006-06-12 08:54:30 +02:00
|
|
|
DWORD hex_version = This->baseShader.hex_version;
|
2007-01-15 19:36:40 +01:00
|
|
|
char dst_swizzle[6];
|
|
|
|
glsl_sample_function_t sample_function;
|
|
|
|
DWORD sampler_type;
|
|
|
|
DWORD sampler_idx;
|
|
|
|
BOOL projected;
|
|
|
|
DWORD mask = 0;
|
2006-06-09 09:33:01 +02:00
|
|
|
|
|
|
|
/* All versions have a destination register */
|
2007-01-15 19:36:40 +01:00
|
|
|
shader_glsl_append_dst(arg->buffer, arg);
|
2006-06-12 08:59:16 +02:00
|
|
|
|
2006-11-27 20:50:47 +01:00
|
|
|
/* 1.0-1.4: Use destination register as sampler source.
|
|
|
|
* 2.0+: Use provided sampler source. */
|
2007-01-15 19:36:40 +01:00
|
|
|
if (hex_version < WINED3DPS_VERSION(1,4)) {
|
|
|
|
IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
|
|
|
|
DWORD flags;
|
|
|
|
|
|
|
|
sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
|
|
|
|
flags = deviceImpl->stateBlock->textureState[sampler_idx][WINED3DTSS_TEXTURETRANSFORMFLAGS];
|
|
|
|
|
|
|
|
if (flags & WINED3DTTFF_PROJECTED) {
|
|
|
|
projected = TRUE;
|
|
|
|
switch (flags & ~WINED3DTTFF_PROJECTED) {
|
|
|
|
case WINED3DTTFF_COUNT1: FIXME("WINED3DTTFF_PROJECTED with WINED3DTTFF_COUNT1?\n"); break;
|
|
|
|
case WINED3DTTFF_COUNT2: mask = WINED3DSP_WRITEMASK_1; break;
|
|
|
|
case WINED3DTTFF_COUNT3: mask = WINED3DSP_WRITEMASK_2; break;
|
|
|
|
case WINED3DTTFF_COUNT4:
|
|
|
|
case WINED3DTTFF_DISABLE: mask = WINED3DSP_WRITEMASK_3; break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
projected = FALSE;
|
|
|
|
}
|
|
|
|
} else if (hex_version < WINED3DPS_VERSION(2,0)) {
|
|
|
|
DWORD src_mod = arg->src[0] & WINED3DSP_SRCMOD_MASK;
|
|
|
|
sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
|
|
|
|
|
|
|
|
if (src_mod == WINED3DSPSM_DZ) {
|
|
|
|
projected = TRUE;
|
|
|
|
mask = WINED3DSP_WRITEMASK_2;
|
|
|
|
} else if (src_mod == WINED3DSPSM_DW) {
|
|
|
|
projected = TRUE;
|
|
|
|
mask = WINED3DSP_WRITEMASK_3;
|
|
|
|
} else {
|
|
|
|
projected = FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sampler_idx = arg->src[1] & WINED3DSP_REGNUM_MASK;
|
|
|
|
/* TODO: Handle D3DSI_TEXLD_PROJECTED... */
|
|
|
|
projected = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK;
|
|
|
|
shader_glsl_get_sample_function(sampler_type, projected, &sample_function);
|
|
|
|
mask |= sample_function.coord_mask;
|
|
|
|
|
2006-10-13 05:36:41 +02:00
|
|
|
if (hex_version < WINED3DPS_VERSION(2,0)) {
|
2007-01-15 19:36:40 +01:00
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_swizzle);
|
2006-08-24 23:57:46 +02:00
|
|
|
} else {
|
2007-01-15 19:36:40 +01:00
|
|
|
shader_glsl_get_swizzle(arg->src[1], FALSE, arg->dst, dst_swizzle);
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
2006-11-27 20:50:47 +01:00
|
|
|
|
2007-01-15 19:36:40 +01:00
|
|
|
/* 1.0-1.3: Use destination register as coordinate source.
|
|
|
|
1.4+: Use provided coordinate source register. */
|
|
|
|
if (hex_version < WINED3DPS_VERSION(1,4)) {
|
2007-01-15 19:37:04 +01:00
|
|
|
char coord_mask[6];
|
2007-01-15 19:36:40 +01:00
|
|
|
shader_glsl_get_write_mask(mask, coord_mask);
|
|
|
|
shader_addline(arg->buffer, "%s(Psampler%u, T%u%s)%s);\n",
|
|
|
|
sample_function.name, sampler_idx, sampler_idx, coord_mask, dst_swizzle);
|
|
|
|
} else {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t coord_param;
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], mask, &coord_param);
|
2007-01-15 19:36:40 +01:00
|
|
|
shader_addline(arg->buffer, "%s(Psampler%u, %s)%s);\n",
|
2007-01-15 19:37:04 +01:00
|
|
|
sample_function.name, sampler_idx, coord_param.param_str, dst_swizzle);
|
2007-01-15 19:36:40 +01:00
|
|
|
}
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void pshader_glsl_texcoord(SHADER_OPCODE_ARG* arg) {
|
|
|
|
|
|
|
|
/* FIXME: Make this work for more than just 2D textures */
|
|
|
|
|
|
|
|
IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
|
|
|
|
SHADER_BUFFER* buffer = arg->buffer;
|
2006-06-12 08:54:30 +02:00
|
|
|
DWORD hex_version = This->baseShader.hex_version;
|
2007-01-15 19:36:40 +01:00
|
|
|
DWORD write_mask;
|
|
|
|
char dst_mask[6];
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:36:40 +01:00
|
|
|
write_mask = shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
shader_glsl_get_write_mask(write_mask, dst_mask);
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2006-10-13 05:36:41 +02:00
|
|
|
if (hex_version != WINED3DPS_VERSION(1,4)) {
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK;
|
2007-01-15 19:36:40 +01:00
|
|
|
shader_addline(buffer, "clamp(gl_TexCoord[%u], 0.0, 1.0)%s);\n", reg, dst_mask);
|
2006-06-09 09:33:01 +02:00
|
|
|
} else {
|
2007-01-15 19:36:40 +01:00
|
|
|
DWORD reg = arg->src[0] & WINED3DSP_REGNUM_MASK;
|
|
|
|
DWORD src_mod = arg->src[0] & WINED3DSP_SRCMOD_MASK;
|
|
|
|
char dst_swizzle[6];
|
|
|
|
|
|
|
|
shader_glsl_get_swizzle(arg->src[0], FALSE, write_mask, dst_swizzle);
|
|
|
|
|
|
|
|
if (src_mod == WINED3DSPSM_DZ) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t div_param;
|
2007-01-15 19:36:40 +01:00
|
|
|
size_t mask_size = shader_glsl_get_write_mask_size(write_mask);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_2, &div_param);
|
2007-01-15 19:36:40 +01:00
|
|
|
|
|
|
|
if (mask_size > 1) {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(buffer, "gl_TexCoord[%u]%s / vec%d(%s));\n", reg, dst_swizzle, mask_size, div_param.param_str);
|
2007-01-15 19:36:40 +01:00
|
|
|
} else {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(buffer, "gl_TexCoord[%u]%s / %s);\n", reg, dst_swizzle, div_param.param_str);
|
2007-01-15 19:36:40 +01:00
|
|
|
}
|
|
|
|
} else if (src_mod == WINED3DSPSM_DW) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t div_param;
|
2007-01-15 19:36:40 +01:00
|
|
|
size_t mask_size = shader_glsl_get_write_mask_size(write_mask);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_3, &div_param);
|
2007-01-15 19:36:40 +01:00
|
|
|
|
|
|
|
if (mask_size > 1) {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(buffer, "gl_TexCoord[%u]%s / vec%d(%s));\n", reg, dst_swizzle, mask_size, div_param.param_str);
|
2007-01-15 19:36:40 +01:00
|
|
|
} else {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(buffer, "gl_TexCoord[%u]%s / %s);\n", reg, dst_swizzle, div_param.param_str);
|
2007-01-15 19:36:40 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
shader_addline(buffer, "gl_TexCoord[%u]%s);\n", reg, dst_swizzle);
|
|
|
|
}
|
|
|
|
}
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXDP3TEX instruction in GLSL:
|
2006-07-28 10:14:14 +02:00
|
|
|
* Take a 3-component dot product of the TexCoord[dstreg] and src,
|
|
|
|
* then perform a 1D texture lookup from stage dstregnum, place into dst. */
|
|
|
|
void pshader_glsl_texdp3tex(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
2007-01-15 19:34:18 +01:00
|
|
|
char dst_mask[6];
|
|
|
|
DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
|
|
|
|
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
2006-07-28 10:14:14 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param);
|
2006-07-28 10:14:14 +02:00
|
|
|
|
2007-01-15 19:34:18 +01:00
|
|
|
shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_mask);
|
|
|
|
shader_addline(arg->buffer, "texture1D(Psampler%u, dot(gl_TexCoord[%u].xyz, %s))%s);\n",
|
2007-01-15 19:37:04 +01:00
|
|
|
sampler_idx, sampler_idx, src0_param.param_str, dst_mask);
|
2006-07-28 10:14:14 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXDP3 instruction in GLSL:
|
2006-07-28 10:14:14 +02:00
|
|
|
* Take a 3-component dot product of the TexCoord[dstreg] and src. */
|
|
|
|
void pshader_glsl_texdp3(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD dstreg = arg->dst & WINED3DSP_REGNUM_MASK;
|
2007-01-15 19:34:25 +01:00
|
|
|
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
|
|
|
DWORD dst_mask;
|
|
|
|
size_t mask_size;
|
2006-07-28 10:14:14 +02:00
|
|
|
|
2007-01-15 19:34:25 +01:00
|
|
|
dst_mask = shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
mask_size = shader_glsl_get_write_mask_size(dst_mask);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param);
|
2006-07-28 10:14:14 +02:00
|
|
|
|
2007-01-15 19:34:25 +01:00
|
|
|
if (mask_size > 1) {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "vec%d(dot(T%u.xyz, %s)));\n", mask_size, dstreg, src0_param.param_str);
|
2007-01-15 19:34:25 +01:00
|
|
|
} else {
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "dot(T%u.xyz, %s));\n", dstreg, src0_param.param_str);
|
2007-01-15 19:34:25 +01:00
|
|
|
}
|
2006-07-28 10:14:14 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXDEPTH instruction in GLSL:
|
2006-07-28 10:14:14 +02:00
|
|
|
* Calculate the depth as dst.x / dst.y */
|
|
|
|
void pshader_glsl_texdepth(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:36:58 +01:00
|
|
|
glsl_dst_param_t dst_param;
|
|
|
|
|
|
|
|
shader_glsl_add_dst_param(arg, arg->dst, 0, &dst_param);
|
2006-07-28 10:14:14 +02:00
|
|
|
|
2007-01-15 19:36:58 +01:00
|
|
|
shader_addline(arg->buffer, "gl_FragDepth = %s.x / %s.y;\n", dst_param.reg_name, dst_param.reg_name);
|
2006-07-28 10:14:14 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXM3X2DEPTH instruction in GLSL:
|
2006-07-28 10:14:14 +02:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
void pshader_glsl_texm3x2depth(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:34:33 +01:00
|
|
|
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD dstreg = arg->dst & WINED3DSP_REGNUM_MASK;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
2006-07-28 10:14:14 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param);
|
2006-07-28 10:14:14 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "tmp0.y = dot(T%u.xyz, %s);\n", dstreg, src0_param.param_str);
|
2007-01-15 19:34:33 +01:00
|
|
|
shader_addline(arg->buffer, "gl_FragDepth = (tmp0.y == 0.0) ? 1.0 : clamp(tmp0.x / tmp0.y, 0.0, 1.0);\n");
|
2006-07-28 10:14:14 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXM3X2PAD instruction in GLSL
|
2006-07-28 10:14:14 +02:00
|
|
|
* Calculate the 1st of a 2-row matrix multiplication. */
|
2006-06-09 09:33:01 +02:00
|
|
|
void pshader_glsl_texm3x2pad(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:34:58 +01:00
|
|
|
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK;
|
2006-06-27 08:00:02 +02:00
|
|
|
SHADER_BUFFER* buffer = arg->buffer;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
2006-06-27 08:00:02 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param);
|
|
|
|
shader_addline(buffer, "tmp0.x = dot(T%u.xyz, %s);\n", reg, src0_param.param_str);
|
2006-06-27 08:00:02 +02:00
|
|
|
}
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXM3X3PAD instruction in GLSL
|
2006-06-27 08:00:02 +02:00
|
|
|
* Calculate the 1st or 2nd row of a 3-row matrix multiplication. */
|
|
|
|
void pshader_glsl_texm3x3pad(SHADER_OPCODE_ARG* arg) {
|
|
|
|
|
|
|
|
IWineD3DPixelShaderImpl* shader = (IWineD3DPixelShaderImpl*) arg->shader;
|
2007-01-15 19:35:06 +01:00
|
|
|
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK;
|
2006-06-09 09:33:01 +02:00
|
|
|
SHADER_BUFFER* buffer = arg->buffer;
|
2006-06-27 08:00:02 +02:00
|
|
|
SHADER_PARSE_STATE* current_state = &shader->baseShader.parse_state;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param);
|
|
|
|
shader_addline(buffer, "tmp0.%c = dot(T%u.xyz, %s);\n", 'x' + current_state->current_row, reg, src0_param.param_str);
|
2006-06-27 08:00:02 +02:00
|
|
|
current_state->texcoord_w[current_state->current_row++] = reg;
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void pshader_glsl_texm3x2tex(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:35:14 +01:00
|
|
|
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK;
|
2006-06-09 09:33:01 +02:00
|
|
|
SHADER_BUFFER* buffer = arg->buffer;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
2007-01-15 19:35:14 +01:00
|
|
|
char dst_mask[6];
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param);
|
|
|
|
shader_addline(buffer, "tmp0.y = dot(T%u.xyz, %s);\n", reg, src0_param.param_str);
|
2007-01-15 19:35:14 +01:00
|
|
|
|
|
|
|
shader_glsl_append_dst(buffer, arg);
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_mask);
|
2006-11-27 20:51:01 +01:00
|
|
|
|
|
|
|
/* Sample the texture using the calculated coordinates */
|
2007-01-15 19:35:14 +01:00
|
|
|
shader_addline(buffer, "texture2D(Psampler%u, tmp0.xy)%s);\n", reg, dst_mask);
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
2006-06-12 08:57:07 +02:00
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXM3X3TEX instruction in GLSL
|
2006-11-27 20:50:51 +01:00
|
|
|
* Perform the 3rd row of a 3x3 matrix multiply, then sample the texture using the calculated coordinates */
|
2006-07-25 04:52:38 +02:00
|
|
|
void pshader_glsl_texm3x3tex(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:35:22 +01:00
|
|
|
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
2007-01-15 19:35:22 +01:00
|
|
|
char dst_mask[6];
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK;
|
2006-07-25 04:52:38 +02:00
|
|
|
IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
|
|
|
|
SHADER_PARSE_STATE* current_state = &This->baseShader.parse_state;
|
2007-01-15 19:35:22 +01:00
|
|
|
DWORD sampler_type = arg->reg_maps->samplers[reg] & WINED3DSP_TEXTURETYPE_MASK;
|
|
|
|
glsl_sample_function_t sample_function;
|
2006-07-25 04:52:38 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param);
|
|
|
|
shader_addline(arg->buffer, "tmp0.z = dot(T%u.xyz, %s);\n", reg, src0_param.param_str);
|
2007-01-15 19:35:22 +01:00
|
|
|
|
|
|
|
shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_mask);
|
|
|
|
shader_glsl_get_sample_function(sampler_type, FALSE, &sample_function);
|
2006-11-27 20:50:51 +01:00
|
|
|
|
|
|
|
/* Sample the texture using the calculated coordinates */
|
2007-01-15 19:35:22 +01:00
|
|
|
shader_addline(arg->buffer, "%s(Psampler%u, tmp0.xyz)%s);\n", sample_function.name, reg, dst_mask);
|
|
|
|
|
2006-07-25 04:52:38 +02:00
|
|
|
current_state->current_row = 0;
|
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXM3X3 instruction in GLSL
|
2006-07-28 10:14:14 +02:00
|
|
|
* Perform the 3rd row of a 3x3 matrix multiply */
|
|
|
|
void pshader_glsl_texm3x3(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:35:28 +01:00
|
|
|
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
2007-01-15 19:35:28 +01:00
|
|
|
char dst_mask[6];
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK;
|
2006-07-28 10:14:14 +02:00
|
|
|
IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
|
|
|
|
SHADER_PARSE_STATE* current_state = &This->baseShader.parse_state;
|
2007-01-15 19:35:28 +01:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param);
|
2007-01-15 19:35:28 +01:00
|
|
|
|
|
|
|
shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_mask);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "vec4(tmp.xy, dot(T%u.xyz, %s), 1.0)%s);\n", reg, src0_param.param_str, dst_mask);
|
2007-01-15 19:35:28 +01:00
|
|
|
|
2006-07-28 10:14:14 +02:00
|
|
|
current_state->current_row = 0;
|
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXM3X3SPEC instruction in GLSL
|
2006-07-25 04:52:38 +02:00
|
|
|
* Peform the final texture lookup based on the previous 2 3x3 matrix multiplies */
|
|
|
|
void pshader_glsl_texm3x3spec(SHADER_OPCODE_ARG* arg) {
|
|
|
|
|
|
|
|
IWineD3DPixelShaderImpl* shader = (IWineD3DPixelShaderImpl*) arg->shader;
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
glsl_src_param_t src1_param;
|
2007-01-15 19:35:36 +01:00
|
|
|
char dst_mask[6];
|
2006-07-25 04:52:38 +02:00
|
|
|
SHADER_BUFFER* buffer = arg->buffer;
|
|
|
|
SHADER_PARSE_STATE* current_state = &shader->baseShader.parse_state;
|
2006-07-28 21:34:39 +02:00
|
|
|
DWORD stype = arg->reg_maps->samplers[reg] & WINED3DSP_TEXTURETYPE_MASK;
|
2007-01-15 19:35:36 +01:00
|
|
|
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
|
|
|
glsl_sample_function_t sample_function;
|
2006-07-25 04:52:38 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], src_mask, &src1_param);
|
2006-07-25 04:52:38 +02:00
|
|
|
|
|
|
|
/* Perform the last matrix multiply operation */
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(buffer, "tmp0.z = dot(T%u.xyz, %s);\n", reg, src0_param.param_str);
|
2007-01-15 19:35:36 +01:00
|
|
|
|
|
|
|
/* Calculate reflection vector, 2*(tmp0.src1)*tmp0-src1
|
2007-01-17 21:41:40 +01:00
|
|
|
* This is equivalent to reflect(-src1, tmp0); */
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(buffer, "tmp0.xyz = reflect(-(%s), tmp0.xyz);\n", src1_param.param_str);
|
2006-07-25 04:52:38 +02:00
|
|
|
|
2007-01-15 19:35:36 +01:00
|
|
|
shader_glsl_append_dst(buffer, arg);
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_mask);
|
|
|
|
shader_glsl_get_sample_function(stype, FALSE, &sample_function);
|
2006-07-25 04:52:38 +02:00
|
|
|
|
|
|
|
/* Sample the texture */
|
2007-01-15 19:35:36 +01:00
|
|
|
shader_addline(buffer, "%s(Psampler%u, tmp0.xyz)%s);\n", sample_function.name, reg, dst_mask);
|
|
|
|
|
2006-07-25 04:52:38 +02:00
|
|
|
current_state->current_row = 0;
|
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXM3X3VSPEC instruction in GLSL
|
2006-06-27 08:00:02 +02:00
|
|
|
* Peform the final texture lookup based on the previous 2 3x3 matrix multiplies */
|
|
|
|
void pshader_glsl_texm3x3vspec(SHADER_OPCODE_ARG* arg) {
|
|
|
|
|
|
|
|
IWineD3DPixelShaderImpl* shader = (IWineD3DPixelShaderImpl*) arg->shader;
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK;
|
2006-06-27 08:00:02 +02:00
|
|
|
SHADER_BUFFER* buffer = arg->buffer;
|
|
|
|
SHADER_PARSE_STATE* current_state = &shader->baseShader.parse_state;
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
char dst_mask[6];
|
2007-01-15 19:35:48 +01:00
|
|
|
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
|
|
|
DWORD sampler_type = arg->reg_maps->samplers[reg] & WINED3DSP_TEXTURETYPE_MASK;
|
|
|
|
glsl_sample_function_t sample_function;
|
2006-06-27 08:00:02 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param);
|
2006-06-27 08:00:02 +02:00
|
|
|
|
|
|
|
/* Perform the last matrix multiply operation */
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(buffer, "tmp0.z = dot(vec3(T%u), vec3(%s));\n", reg, src0_param.param_str);
|
2006-06-27 08:00:02 +02:00
|
|
|
|
|
|
|
/* Construct the eye-ray vector from w coordinates */
|
2007-01-15 19:35:48 +01:00
|
|
|
shader_addline(buffer, "tmp1.xyz = normalize(vec3(gl_TexCoord[%u].w, gl_TexCoord[%u].w, gl_TexCoord[%u].w));\n",
|
|
|
|
current_state->texcoord_w[0], current_state->texcoord_w[1], reg);
|
2006-06-27 08:00:02 +02:00
|
|
|
|
2007-01-15 19:35:48 +01:00
|
|
|
/* Calculate reflection vector (Assume normal is normalized): RF = 2*(tmp0.tmp1)*tmp0-tmp1
|
2007-01-17 21:41:40 +01:00
|
|
|
* This is equivalent to reflect(-tmp1, tmp0); */
|
2007-01-15 19:35:48 +01:00
|
|
|
shader_addline(buffer, "tmp0.xyz = reflect(-tmp1.xyz, tmp0.xyz);\n");
|
|
|
|
|
|
|
|
shader_glsl_append_dst(buffer, arg);
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_mask);
|
|
|
|
shader_glsl_get_sample_function(sampler_type, FALSE, &sample_function);
|
2006-06-27 08:00:02 +02:00
|
|
|
|
2006-11-27 20:51:01 +01:00
|
|
|
/* Sample the texture using the calculated coordinates */
|
2007-01-15 19:35:48 +01:00
|
|
|
shader_addline(buffer, "%s(Psampler%u, tmp0.xyz)%s);\n", sample_function.name, reg, dst_mask);
|
|
|
|
|
2006-06-27 08:00:02 +02:00
|
|
|
current_state->current_row = 0;
|
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXBEM instruction in GLSL.
|
2006-06-27 08:00:02 +02:00
|
|
|
* Apply a fake bump map transform.
|
|
|
|
* FIXME: Should apply the BUMPMAPENV matrix. For now, just sample the texture */
|
|
|
|
void pshader_glsl_texbem(SHADER_OPCODE_ARG* arg) {
|
|
|
|
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD reg1 = arg->dst & WINED3DSP_REGNUM_MASK;
|
|
|
|
DWORD reg2 = arg->src[0] & WINED3DSP_REGNUM_MASK;
|
2006-06-27 08:00:02 +02:00
|
|
|
|
|
|
|
FIXME("Not applying the BUMPMAPENV matrix for pixel shader instruction texbem.\n");
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(arg->buffer, "T%u = texture2D(Psampler%u, gl_TexCoord[%u].xy + T%u.xy);\n",
|
2006-06-27 08:00:02 +02:00
|
|
|
reg1, reg1, reg1, reg2);
|
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXREG2AR instruction in GLSL
|
2006-07-25 04:52:38 +02:00
|
|
|
* Sample 2D texture at dst using the alpha & red (wx) components of src as texture coordinates */
|
|
|
|
void pshader_glsl_texreg2ar(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
2007-01-15 19:33:24 +01:00
|
|
|
DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
|
|
|
|
char dst_mask[6];
|
2006-07-25 04:52:38 +02:00
|
|
|
|
2007-01-15 19:33:24 +01:00
|
|
|
shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_mask);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_ALL, &src0_param);
|
2006-07-25 04:52:38 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "texture2D(Psampler%u, %s.wx)%s);\n", sampler_idx, src0_param.reg_name, dst_mask);
|
2006-07-25 04:52:38 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXREG2GB instruction in GLSL
|
2006-07-25 04:52:38 +02:00
|
|
|
* Sample 2D texture at dst using the green & blue (yz) components of src as texture coordinates */
|
|
|
|
void pshader_glsl_texreg2gb(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
2007-01-15 19:33:32 +01:00
|
|
|
DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
|
|
|
|
char dst_mask[6];
|
2006-07-25 04:52:38 +02:00
|
|
|
|
2007-01-15 19:33:32 +01:00
|
|
|
shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_mask);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_ALL, &src0_param);
|
2006-07-25 04:52:38 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "texture2D(Psampler%u, %s.yz)%s);\n", sampler_idx, src0_param.reg_name, dst_mask);
|
2006-07-25 04:52:38 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXREG2RGB instruction in GLSL
|
2006-07-25 04:52:38 +02:00
|
|
|
* Sample texture at dst using the rgb (xyz) components of src as texture coordinates */
|
|
|
|
void pshader_glsl_texreg2rgb(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
2007-01-15 19:33:44 +01:00
|
|
|
char dst_mask[6];
|
|
|
|
DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
|
|
|
|
DWORD sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK;
|
|
|
|
glsl_sample_function_t sample_function;
|
2006-07-25 04:52:38 +02:00
|
|
|
|
2007-01-15 19:33:44 +01:00
|
|
|
shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_mask);
|
|
|
|
shader_glsl_get_sample_function(sampler_type, FALSE, &sample_function);
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], sample_function.coord_mask, &src0_param);
|
2006-07-25 04:52:38 +02:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "%s(Psampler%u, %s)%s);\n", sample_function.name, sampler_idx, src0_param.param_str, dst_mask);
|
2006-07-25 04:52:38 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_TEXKILL instruction in GLSL.
|
2006-06-27 08:00:02 +02:00
|
|
|
* If any of the first 3 components are < 0, discard this pixel */
|
|
|
|
void pshader_glsl_texkill(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:36:58 +01:00
|
|
|
glsl_dst_param_t dst_param;
|
2006-06-27 08:00:02 +02:00
|
|
|
|
2007-01-15 19:36:58 +01:00
|
|
|
shader_glsl_add_dst_param(arg, arg->dst, 0, &dst_param);
|
|
|
|
shader_addline(arg->buffer, "if (any(lessThan(%s.xyz, vec3(0.0)))) discard;\n", dst_param.reg_name);
|
2006-06-27 08:00:02 +02:00
|
|
|
}
|
|
|
|
|
2006-10-10 01:45:12 +02:00
|
|
|
/** Process the WINED3DSIO_DP2ADD instruction in GLSL.
|
2006-06-27 08:00:02 +02:00
|
|
|
* dst = dot2(src0, src1) + src2 */
|
|
|
|
void pshader_glsl_dp2add(SHADER_OPCODE_ARG* arg) {
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
glsl_src_param_t src1_param;
|
|
|
|
glsl_src_param_t src2_param;
|
2007-01-15 19:32:20 +01:00
|
|
|
DWORD write_mask;
|
|
|
|
size_t mask_size;
|
2006-06-27 08:00:02 +02:00
|
|
|
|
2007-01-15 19:32:20 +01:00
|
|
|
write_mask = shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
mask_size = shader_glsl_get_write_mask_size(write_mask);
|
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src0_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src1_param);
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[2], arg->src_addr[2], WINED3DSP_WRITEMASK_0, &src2_param);
|
2007-01-15 19:32:20 +01:00
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
shader_addline(arg->buffer, "dot(%s, %s) + %s);\n", src0_param.param_str, src1_param.param_str, src2_param.param_str);
|
2006-06-27 08:00:02 +02:00
|
|
|
}
|
|
|
|
|
2006-06-12 08:57:07 +02:00
|
|
|
void pshader_glsl_input_pack(
|
|
|
|
SHADER_BUFFER* buffer,
|
2006-07-07 08:27:38 +02:00
|
|
|
semantic* semantics_in) {
|
2006-06-12 08:57:07 +02:00
|
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
2006-07-07 08:27:38 +02:00
|
|
|
for (i = 0; i < MAX_REG_INPUT; i++) {
|
2006-06-12 08:57:07 +02:00
|
|
|
|
2006-07-07 08:27:38 +02:00
|
|
|
DWORD usage_token = semantics_in[i].usage;
|
|
|
|
DWORD register_token = semantics_in[i].reg;
|
|
|
|
DWORD usage, usage_idx;
|
2006-06-12 08:57:07 +02:00
|
|
|
char reg_mask[6];
|
|
|
|
|
|
|
|
/* Uninitialized */
|
2006-07-07 08:27:38 +02:00
|
|
|
if (!usage_token) continue;
|
2006-10-10 01:46:35 +02:00
|
|
|
usage = (usage_token & WINED3DSP_DCL_USAGE_MASK) >> WINED3DSP_DCL_USAGE_SHIFT;
|
|
|
|
usage_idx = (usage_token & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
|
2006-12-29 15:31:26 +01:00
|
|
|
shader_glsl_get_write_mask(register_token, reg_mask);
|
2006-07-07 08:27:38 +02:00
|
|
|
|
|
|
|
switch(usage) {
|
|
|
|
|
|
|
|
case D3DDECLUSAGE_COLOR:
|
|
|
|
if (usage_idx == 0)
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "IN%u%s = vec4(gl_Color)%s;\n",
|
2006-07-07 08:27:38 +02:00
|
|
|
i, reg_mask, reg_mask);
|
2006-07-07 19:01:27 +02:00
|
|
|
else if (usage_idx == 1)
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "IN%u%s = vec4(gl_SecondaryColor)%s;\n",
|
2006-07-07 08:27:38 +02:00
|
|
|
i, reg_mask, reg_mask);
|
|
|
|
else
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "IN%u%s = vec4(unsupported_color_input)%s;\n",
|
2006-07-07 08:27:38 +02:00
|
|
|
i, reg_mask, reg_mask);
|
2006-06-12 08:57:07 +02:00
|
|
|
break;
|
|
|
|
|
2006-07-07 08:27:38 +02:00
|
|
|
case D3DDECLUSAGE_TEXCOORD:
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "IN%u%s = vec4(gl_TexCoord[%u])%s;\n",
|
2006-07-07 08:27:38 +02:00
|
|
|
i, reg_mask, usage_idx, reg_mask );
|
2006-06-12 08:57:07 +02:00
|
|
|
break;
|
|
|
|
|
2006-07-07 08:27:38 +02:00
|
|
|
case D3DDECLUSAGE_FOG:
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "IN%u%s = vec4(gl_FogFragCoord)%s;\n",
|
2006-07-07 08:27:38 +02:00
|
|
|
i, reg_mask, reg_mask);
|
2006-06-12 08:57:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "IN%u%s = vec4(unsupported_input)%s;\n",
|
2006-07-07 08:27:38 +02:00
|
|
|
i, reg_mask, reg_mask);
|
2006-06-12 08:57:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************
|
|
|
|
* Vertex Shader Specific Code begins here
|
|
|
|
********************************************/
|
|
|
|
|
|
|
|
void vshader_glsl_output_unpack(
|
|
|
|
SHADER_BUFFER* buffer,
|
2006-07-07 08:27:38 +02:00
|
|
|
semantic* semantics_out) {
|
2006-06-12 08:57:07 +02:00
|
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
2006-07-07 08:27:38 +02:00
|
|
|
for (i = 0; i < MAX_REG_OUTPUT; i++) {
|
2006-06-12 08:57:07 +02:00
|
|
|
|
2006-07-07 08:27:38 +02:00
|
|
|
DWORD usage_token = semantics_out[i].usage;
|
|
|
|
DWORD register_token = semantics_out[i].reg;
|
|
|
|
DWORD usage, usage_idx;
|
2006-06-12 08:57:07 +02:00
|
|
|
char reg_mask[6];
|
|
|
|
|
|
|
|
/* Uninitialized */
|
2006-07-07 08:27:38 +02:00
|
|
|
if (!usage_token) continue;
|
2006-06-12 08:57:07 +02:00
|
|
|
|
2006-10-10 01:46:35 +02:00
|
|
|
usage = (usage_token & WINED3DSP_DCL_USAGE_MASK) >> WINED3DSP_DCL_USAGE_SHIFT;
|
|
|
|
usage_idx = (usage_token & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
|
2006-12-29 15:31:26 +01:00
|
|
|
shader_glsl_get_write_mask(register_token, reg_mask);
|
2006-06-12 08:57:07 +02:00
|
|
|
|
2006-07-07 08:27:38 +02:00
|
|
|
switch(usage) {
|
2006-06-12 08:57:07 +02:00
|
|
|
|
2006-07-07 08:27:38 +02:00
|
|
|
case D3DDECLUSAGE_COLOR:
|
|
|
|
if (usage_idx == 0)
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "gl_FrontColor%s = OUT%u%s;\n", reg_mask, i, reg_mask);
|
2006-07-07 08:27:38 +02:00
|
|
|
else if (usage_idx == 1)
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "gl_FrontSecondaryColor%s = OUT%u%s;\n", reg_mask, i, reg_mask);
|
2006-07-07 08:27:38 +02:00
|
|
|
else
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "unsupported_color_output%s = OUT%u%s;\n", reg_mask, i, reg_mask);
|
2006-06-12 08:57:07 +02:00
|
|
|
break;
|
|
|
|
|
2006-07-07 08:27:38 +02:00
|
|
|
case D3DDECLUSAGE_POSITION:
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "gl_Position%s = OUT%u%s;\n", reg_mask, i, reg_mask);
|
2006-06-12 08:57:07 +02:00
|
|
|
break;
|
2006-07-07 08:27:38 +02:00
|
|
|
|
|
|
|
case D3DDECLUSAGE_TEXCOORD:
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "gl_TexCoord[%u]%s = OUT%u%s;\n",
|
2006-07-07 08:27:38 +02:00
|
|
|
usage_idx, reg_mask, i, reg_mask);
|
2006-06-12 08:57:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DSHADERDECLUSAGE_PSIZE:
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "gl_PointSize = OUT%u.x;\n", i);
|
2006-06-12 08:57:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DSHADERDECLUSAGE_FOG:
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "gl_FogFragCoord%s = OUT%u%s;\n", reg_mask, i, reg_mask);
|
2006-06-12 08:57:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-10-01 05:20:10 +02:00
|
|
|
shader_addline(buffer, "unsupported_output%s = OUT%u%s;\n", reg_mask, i, reg_mask);
|
2006-07-07 08:27:38 +02:00
|
|
|
}
|
|
|
|
}
|
2006-06-12 08:57:07 +02:00
|
|
|
}
|
2006-11-27 20:50:37 +01:00
|
|
|
|
2006-12-28 03:13:24 +01:00
|
|
|
/** Attach a GLSL pixel or vertex shader object to the shader program */
|
|
|
|
static void attach_glsl_shader(IWineD3DDevice *iface, IWineD3DBaseShader* shader) {
|
|
|
|
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
|
|
|
|
WineD3D_GL_Info *gl_info = &((IWineD3DImpl *)(This->wineD3D))->gl_info;
|
|
|
|
GLhandleARB shaderObj = ((IWineD3DBaseShaderImpl*)shader)->baseShader.prgId;
|
|
|
|
if (This->stateBlock->glsl_program && shaderObj != 0) {
|
|
|
|
TRACE("Attaching GLSL shader object %u to program %u\n", shaderObj, This->stateBlock->glsl_program->programId);
|
|
|
|
GL_EXTCALL(glAttachObjectARB(This->stateBlock->glsl_program->programId, shaderObj));
|
|
|
|
checkGLcall("glAttachObjectARB");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 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 list. If it creates a program, it will link the given
|
|
|
|
* objects, too.
|
|
|
|
*
|
|
|
|
* We keep the shader programs around on a list because linking
|
|
|
|
* shader objects together is an expensive operation. It's much
|
|
|
|
* faster to loop through a list of pre-compiled & linked programs
|
|
|
|
* each time that the application sets a new pixel or vertex shader
|
|
|
|
* than it is to re-link them together at that time.
|
|
|
|
*
|
|
|
|
* The list will be deleted in IWineD3DDevice::Release().
|
|
|
|
*/
|
|
|
|
static void set_glsl_shader_program(IWineD3DDevice *iface) {
|
|
|
|
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
|
|
|
|
WineD3D_GL_Info *gl_info = &((IWineD3DImpl *)(This->wineD3D))->gl_info;
|
|
|
|
IWineD3DPixelShader *pshader = This->stateBlock->pixelShader;
|
|
|
|
IWineD3DVertexShader *vshader = This->stateBlock->vertexShader;
|
|
|
|
struct glsl_shader_prog_link *curLink = NULL;
|
|
|
|
struct glsl_shader_prog_link *newLink = NULL;
|
|
|
|
struct list *ptr = NULL;
|
|
|
|
GLhandleARB programId = 0;
|
|
|
|
int i;
|
|
|
|
char glsl_name[8];
|
|
|
|
|
|
|
|
ptr = list_head( &This->glsl_shader_progs );
|
|
|
|
while (ptr) {
|
|
|
|
/* At least one program exists - see if it matches our ps/vs combination */
|
|
|
|
curLink = LIST_ENTRY( ptr, struct glsl_shader_prog_link, entry );
|
|
|
|
if (vshader == curLink->vertexShader && pshader == curLink->pixelShader) {
|
|
|
|
/* Existing Program found, use it */
|
|
|
|
TRACE("Found existing program (%u) for this vertex/pixel shader combination\n",
|
|
|
|
curLink->programId);
|
|
|
|
This->stateBlock->glsl_program = curLink;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* This isn't the entry we need - try the next one */
|
|
|
|
ptr = list_next( &This->glsl_shader_progs, ptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get to this point, then no matching program exists, so we create one */
|
|
|
|
programId = GL_EXTCALL(glCreateProgramObjectARB());
|
|
|
|
TRACE("Created new GLSL shader program %u\n", programId);
|
|
|
|
|
|
|
|
/* Allocate a new link for the list of programs */
|
|
|
|
newLink = HeapAlloc(GetProcessHeap(), 0, sizeof(struct glsl_shader_prog_link));
|
|
|
|
newLink->programId = programId;
|
|
|
|
This->stateBlock->glsl_program = newLink;
|
|
|
|
|
|
|
|
/* Attach GLSL vshader */
|
|
|
|
if (NULL != vshader && This->vs_selected_mode == SHADER_GLSL) {
|
|
|
|
int i;
|
|
|
|
int max_attribs = 16; /* TODO: Will this always be the case? It is at the moment... */
|
|
|
|
char tmp_name[10];
|
|
|
|
|
|
|
|
TRACE("Attaching vertex shader to GLSL program\n");
|
|
|
|
attach_glsl_shader(iface, (IWineD3DBaseShader*)vshader);
|
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
for (i = 0; i < max_attribs; ++i) {
|
|
|
|
snprintf(tmp_name, sizeof(tmp_name), "attrib%i", i);
|
|
|
|
GL_EXTCALL(glBindAttribLocationARB(programId, i, tmp_name));
|
|
|
|
}
|
|
|
|
checkGLcall("glBindAttribLocationARB");
|
|
|
|
newLink->vertexShader = vshader;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attach GLSL pshader */
|
|
|
|
if (NULL != pshader && This->ps_selected_mode == SHADER_GLSL) {
|
|
|
|
TRACE("Attaching pixel shader to GLSL program\n");
|
|
|
|
attach_glsl_shader(iface, (IWineD3DBaseShader*)pshader);
|
|
|
|
newLink->pixelShader = pshader;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Link the program */
|
|
|
|
TRACE("Linking GLSL shader program %u\n", programId);
|
|
|
|
GL_EXTCALL(glLinkProgramARB(programId));
|
|
|
|
print_glsl_info_log(&GLINFO_LOCATION, programId);
|
|
|
|
list_add_head( &This->glsl_shader_progs, &newLink->entry);
|
|
|
|
|
|
|
|
newLink->vuniformF_locations = HeapAlloc(GetProcessHeap(), 0, sizeof(GLhandleARB) * GL_LIMITS(vshader_constantsF));
|
|
|
|
for (i = 0; i < GL_LIMITS(vshader_constantsF); ++i) {
|
|
|
|
snprintf(glsl_name, sizeof(glsl_name), "VC[%i]", i);
|
|
|
|
newLink->vuniformF_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
|
|
|
|
}
|
|
|
|
newLink->puniformF_locations = HeapAlloc(GetProcessHeap(), 0, sizeof(GLhandleARB) * GL_LIMITS(pshader_constantsF));
|
|
|
|
for (i = 0; i < GL_LIMITS(pshader_constantsF); ++i) {
|
|
|
|
snprintf(glsl_name, sizeof(glsl_name), "PC[%i]", i);
|
|
|
|
newLink->puniformF_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-11-27 20:50:37 +01:00
|
|
|
static GLhandleARB create_glsl_blt_shader(WineD3D_GL_Info *gl_info) {
|
|
|
|
GLhandleARB program_id;
|
|
|
|
GLhandleARB vshader_id, pshader_id;
|
|
|
|
const char *blt_vshader[] = {
|
|
|
|
"void main(void)\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_Position = gl_Vertex;\n"
|
|
|
|
" gl_FrontColor = vec4(1.0);\n"
|
|
|
|
" gl_TexCoord[0].x = (gl_Vertex.x * 0.5) + 0.5;\n"
|
|
|
|
" gl_TexCoord[0].y = (-gl_Vertex.y * 0.5) + 0.5;\n"
|
|
|
|
"}\n"
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *blt_pshader[] = {
|
|
|
|
"uniform sampler2D sampler;\n"
|
|
|
|
"void main(void)\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_FragDepth = texture2D(sampler, gl_TexCoord[0].xy).x;\n"
|
|
|
|
"}\n"
|
|
|
|
};
|
|
|
|
|
|
|
|
vshader_id = GL_EXTCALL(glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB));
|
|
|
|
GL_EXTCALL(glShaderSourceARB(vshader_id, 1, blt_vshader, NULL));
|
|
|
|
GL_EXTCALL(glCompileShaderARB(vshader_id));
|
|
|
|
|
|
|
|
pshader_id = GL_EXTCALL(glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB));
|
|
|
|
GL_EXTCALL(glShaderSourceARB(pshader_id, 1, blt_pshader, NULL));
|
|
|
|
GL_EXTCALL(glCompileShaderARB(pshader_id));
|
|
|
|
|
|
|
|
program_id = GL_EXTCALL(glCreateProgramObjectARB());
|
|
|
|
GL_EXTCALL(glAttachObjectARB(program_id, vshader_id));
|
|
|
|
GL_EXTCALL(glAttachObjectARB(program_id, pshader_id));
|
|
|
|
GL_EXTCALL(glLinkProgramARB(program_id));
|
|
|
|
|
|
|
|
print_glsl_info_log(&GLINFO_LOCATION, program_id);
|
|
|
|
|
|
|
|
return program_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void shader_glsl_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {
|
|
|
|
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
|
|
|
|
WineD3D_GL_Info *gl_info = &((IWineD3DImpl *)(This->wineD3D))->gl_info;
|
|
|
|
GLhandleARB program_id = 0;
|
|
|
|
|
|
|
|
if (useVS || usePS) set_glsl_shader_program(iface);
|
|
|
|
else This->stateBlock->glsl_program = NULL;
|
|
|
|
|
|
|
|
program_id = This->stateBlock->glsl_program ? This->stateBlock->glsl_program->programId : 0;
|
|
|
|
if (program_id) TRACE("Using GLSL program %u\n", program_id);
|
|
|
|
GL_EXTCALL(glUseProgramObjectARB(program_id));
|
|
|
|
checkGLcall("glUseProgramObjectARB");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void shader_glsl_select_depth_blt(IWineD3DDevice *iface) {
|
|
|
|
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
|
|
|
|
WineD3D_GL_Info *gl_info = &((IWineD3DImpl *)(This->wineD3D))->gl_info;
|
|
|
|
static GLhandleARB program_id = 0;
|
|
|
|
static GLhandleARB loc = -1;
|
|
|
|
|
|
|
|
if (!program_id) {
|
|
|
|
program_id = create_glsl_blt_shader(gl_info);
|
|
|
|
loc = GL_EXTCALL(glGetUniformLocationARB(program_id, "sampler"));
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_EXTCALL(glUseProgramObjectARB(program_id));
|
|
|
|
GL_EXTCALL(glUniform1iARB(loc, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void shader_glsl_cleanup(BOOL usePS, BOOL useVS) {
|
|
|
|
/* Nothing to do */
|
|
|
|
}
|
|
|
|
|
|
|
|
const shader_backend_t glsl_shader_backend = {
|
|
|
|
&shader_glsl_select,
|
|
|
|
&shader_glsl_select_depth_blt,
|
|
|
|
&shader_glsl_load_constants,
|
|
|
|
&shader_glsl_cleanup
|
|
|
|
};
|