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
|
2008-10-18 19:21:20 +02:00
|
|
|
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
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"
|
2008-12-19 19:21:56 +01:00
|
|
|
#include <limits.h>
|
2006-06-09 09:33:01 +02:00
|
|
|
#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);
|
2008-03-22 14:27:53 +01:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
|
2008-12-03 14:53:43 +01:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d);
|
2006-06-09 09:33:01 +02:00
|
|
|
|
|
|
|
#define GLINFO_LOCATION (*gl_info)
|
|
|
|
|
2007-01-15 19:36:58 +01:00
|
|
|
typedef struct {
|
2008-06-19 00:36:35 +02:00
|
|
|
char reg_name[150];
|
2007-01-15 19:36:58 +01:00
|
|
|
char mask_str[6];
|
|
|
|
} glsl_dst_param_t;
|
|
|
|
|
2007-01-15 19:37:04 +01:00
|
|
|
typedef struct {
|
2008-06-19 00:36:35 +02:00
|
|
|
char reg_name[150];
|
2007-01-15 19:37:04 +01:00
|
|
|
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;
|
|
|
|
|
2008-12-19 19:21:56 +01:00
|
|
|
enum heap_node_op
|
|
|
|
{
|
|
|
|
HEAP_NODE_TRAVERSE_LEFT,
|
|
|
|
HEAP_NODE_TRAVERSE_RIGHT,
|
|
|
|
HEAP_NODE_POP,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct constant_entry
|
|
|
|
{
|
|
|
|
unsigned int idx;
|
|
|
|
unsigned int version;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct constant_heap
|
|
|
|
{
|
|
|
|
struct constant_entry *entries;
|
|
|
|
unsigned int *positions;
|
|
|
|
unsigned int size;
|
|
|
|
};
|
|
|
|
|
2008-09-16 14:55:39 +02:00
|
|
|
/* GLSL shader private data */
|
|
|
|
struct shader_glsl_priv {
|
|
|
|
struct hash_table_t *glsl_program_lookup;
|
2008-12-19 19:21:56 +01:00
|
|
|
struct glsl_shader_prog_link *glsl_program;
|
|
|
|
struct constant_heap vconst_heap;
|
|
|
|
struct constant_heap pconst_heap;
|
|
|
|
unsigned char *stack;
|
2008-10-27 18:31:32 +01:00
|
|
|
GLhandleARB depth_blt_program[tex_type_count];
|
2008-12-19 19:21:56 +01:00
|
|
|
UINT next_constant_version;
|
2008-09-16 14:55:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Struct to maintain data about a linked GLSL program */
|
|
|
|
struct glsl_shader_prog_link {
|
2008-11-21 19:48:36 +01:00
|
|
|
struct list vshader_entry;
|
|
|
|
struct list pshader_entry;
|
|
|
|
GLhandleARB programId;
|
|
|
|
GLhandleARB *vuniformF_locations;
|
|
|
|
GLhandleARB *puniformF_locations;
|
|
|
|
GLhandleARB vuniformI_locations[MAX_CONST_I];
|
|
|
|
GLhandleARB puniformI_locations[MAX_CONST_I];
|
|
|
|
GLhandleARB posFixup_location;
|
|
|
|
GLhandleARB bumpenvmat_location[MAX_TEXTURES];
|
|
|
|
GLhandleARB luminancescale_location[MAX_TEXTURES];
|
|
|
|
GLhandleARB luminanceoffset_location[MAX_TEXTURES];
|
|
|
|
GLhandleARB ycorrection_location;
|
|
|
|
GLenum vertex_color_clamp;
|
2009-02-05 19:44:32 +01:00
|
|
|
IWineD3DVertexShader *vshader;
|
2008-11-21 19:48:36 +01:00
|
|
|
IWineD3DPixelShader *pshader;
|
2009-02-05 19:44:32 +01:00
|
|
|
struct vs_compile_args vs_args;
|
2008-11-21 19:48:36 +01:00
|
|
|
struct ps_compile_args ps_args;
|
2008-12-19 19:21:56 +01:00
|
|
|
UINT constant_version;
|
2008-09-16 14:55:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
2009-02-05 19:44:32 +01:00
|
|
|
IWineD3DVertexShader *vshader;
|
2008-11-21 19:48:36 +01:00
|
|
|
IWineD3DPixelShader *pshader;
|
|
|
|
struct ps_compile_args ps_args;
|
2009-02-05 19:44:32 +01:00
|
|
|
struct vs_compile_args vs_args;
|
2008-09-16 14:55:39 +02:00
|
|
|
} glsl_program_key_t;
|
|
|
|
|
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
/** Prints the GLSL info log which will contain error messages if they exist */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void print_glsl_info_log(const WineD3D_GL_Info *gl_info, GLhandleARB obj)
|
|
|
|
{
|
2006-06-09 09:33:01 +02:00
|
|
|
int infologLength = 0;
|
|
|
|
char *infoLog;
|
2008-12-01 13:02:08 +01:00
|
|
|
unsigned int i;
|
2007-12-15 11:43:51 +01:00
|
|
|
BOOL is_spam;
|
|
|
|
|
2008-12-10 10:04:40 +01:00
|
|
|
static const char * const spam[] =
|
|
|
|
{
|
2008-04-23 21:36:39 +02:00
|
|
|
"Vertex shader was successfully compiled to run on hardware.\n", /* fglrx */
|
|
|
|
"Fragment shader was successfully compiled to run on hardware.\n", /* fglrx */
|
|
|
|
"Fragment shader(s) linked, vertex shader(s) linked. \n ", /* fglrx, with \n */
|
|
|
|
"Fragment shader(s) linked, vertex shader(s) linked.", /* fglrx, no \n */
|
|
|
|
"Vertex shader(s) linked, no fragment shader(s) defined. \n ", /* fglrx, with \n */
|
|
|
|
"Vertex shader(s) linked, no fragment shader(s) defined.", /* fglrx, no \n */
|
2009-01-02 16:19:12 +01:00
|
|
|
"Fragment shader was successfully compiled to run on hardware.\n"
|
|
|
|
"WARNING: 0:2: extension 'GL_ARB_draw_buffers' is not supported",
|
2008-04-23 21:36:39 +02:00
|
|
|
"Fragment shader(s) linked, no vertex shader(s) defined.", /* fglrx, no \n */
|
2008-08-13 00:52:35 +02:00
|
|
|
"Fragment shader(s) linked, no vertex shader(s) defined. \n ", /* fglrx, with \n */
|
|
|
|
"WARNING: 0:2: extension 'GL_ARB_draw_buffers' is not supported\n" /* MacOS ati */
|
2007-12-15 11:43:51 +01:00
|
|
|
};
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2009-01-02 16:19:12 +01:00
|
|
|
if (!TRACE_ON(d3d_shader) && !FIXME_ON(d3d_shader)) return;
|
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
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)
|
|
|
|
{
|
2008-02-10 16:43:24 +01:00
|
|
|
/* Fglrx doesn't terminate the string properly, but it tells us the proper length.
|
|
|
|
* So use HEAP_ZERO_MEMORY to avoid uninitialized bytes
|
|
|
|
*/
|
|
|
|
infoLog = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, infologLength);
|
2006-06-09 09:33:01 +02:00
|
|
|
GL_EXTCALL(glGetInfoLogARB(obj, infologLength, NULL, infoLog));
|
2007-12-15 11:43:51 +01:00
|
|
|
is_spam = FALSE;
|
|
|
|
|
|
|
|
for(i = 0; i < sizeof(spam) / sizeof(spam[0]); i++) {
|
|
|
|
if(strcmp(infoLog, spam[i]) == 0) {
|
|
|
|
is_spam = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(is_spam) {
|
|
|
|
TRACE("Spam received from GLSL shader #%u: %s\n", obj, debugstr_a(infoLog));
|
|
|
|
} else {
|
|
|
|
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
|
|
|
|
*/
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_load_psamplers(const WineD3D_GL_Info *gl_info, IWineD3DStateBlock *iface, GLhandleARB programId)
|
|
|
|
{
|
2006-06-16 22:07:00 +02:00
|
|
|
IWineD3DStateBlockImpl* stateBlock = (IWineD3DStateBlockImpl*) iface;
|
|
|
|
GLhandleARB name_loc;
|
|
|
|
int i;
|
|
|
|
char sampler_name[20];
|
|
|
|
|
2007-07-01 23:41:57 +02:00
|
|
|
for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i) {
|
|
|
|
snprintf(sampler_name, sizeof(sampler_name), "Psampler%d", i);
|
|
|
|
name_loc = GL_EXTCALL(glGetUniformLocationARB(programId, sampler_name));
|
|
|
|
if (name_loc != -1) {
|
|
|
|
int mapped_unit = stateBlock->wineD3DDevice->texUnitMap[i];
|
|
|
|
if (mapped_unit != -1 && mapped_unit < GL_LIMITS(fragment_samplers)) {
|
2007-06-12 23:08:11 +02:00
|
|
|
TRACE("Loading %s for texture %d\n", sampler_name, mapped_unit);
|
|
|
|
GL_EXTCALL(glUniform1iARB(name_loc, mapped_unit));
|
|
|
|
checkGLcall("glUniform1iARB");
|
2007-07-01 23:41:57 +02:00
|
|
|
} else {
|
|
|
|
ERR("Trying to load sampler %s on unsupported unit %d\n", sampler_name, mapped_unit);
|
2007-06-12 23:08:11 +02:00
|
|
|
}
|
2006-06-16 22:07:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_load_vsamplers(const WineD3D_GL_Info *gl_info, IWineD3DStateBlock *iface, GLhandleARB programId)
|
|
|
|
{
|
2007-06-27 23:46:53 +02:00
|
|
|
IWineD3DStateBlockImpl* stateBlock = (IWineD3DStateBlockImpl*) iface;
|
|
|
|
GLhandleARB name_loc;
|
|
|
|
char sampler_name[20];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i) {
|
|
|
|
snprintf(sampler_name, sizeof(sampler_name), "Vsampler%d", i);
|
|
|
|
name_loc = GL_EXTCALL(glGetUniformLocationARB(programId, sampler_name));
|
|
|
|
if (name_loc != -1) {
|
|
|
|
int mapped_unit = stateBlock->wineD3DDevice->texUnitMap[MAX_FRAGMENT_SAMPLERS + i];
|
|
|
|
if (mapped_unit != -1 && mapped_unit < GL_LIMITS(combined_samplers)) {
|
|
|
|
TRACE("Loading %s for texture %d\n", sampler_name, mapped_unit);
|
|
|
|
GL_EXTCALL(glUniform1iARB(name_loc, mapped_unit));
|
|
|
|
checkGLcall("glUniform1iARB");
|
|
|
|
} else {
|
|
|
|
ERR("Trying to load sampler %s on unsupported unit %d\n", sampler_name, mapped_unit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-19 19:21:56 +01:00
|
|
|
static inline void walk_constant_heap(const WineD3D_GL_Info *gl_info, const float *constants,
|
|
|
|
const GLhandleARB *constant_locations, const struct constant_heap *heap, unsigned char *stack, DWORD version)
|
2008-11-25 14:36:09 +01:00
|
|
|
{
|
2008-12-19 19:21:56 +01:00
|
|
|
int stack_idx = 0;
|
|
|
|
unsigned int heap_idx = 1;
|
|
|
|
unsigned int idx;
|
|
|
|
|
|
|
|
if (heap->entries[heap_idx].version <= version) return;
|
|
|
|
|
|
|
|
idx = heap->entries[heap_idx].idx;
|
|
|
|
if (constant_locations[idx] != -1) GL_EXTCALL(glUniform4fvARB(constant_locations[idx], 1, &constants[idx * 4]));
|
|
|
|
stack[stack_idx] = HEAP_NODE_TRAVERSE_LEFT;
|
|
|
|
|
|
|
|
while (stack_idx >= 0)
|
|
|
|
{
|
|
|
|
/* Note that we fall through to the next case statement. */
|
|
|
|
switch(stack[stack_idx])
|
|
|
|
{
|
|
|
|
case HEAP_NODE_TRAVERSE_LEFT:
|
|
|
|
{
|
|
|
|
unsigned int left_idx = heap_idx << 1;
|
|
|
|
if (left_idx < heap->size && heap->entries[left_idx].version > version)
|
|
|
|
{
|
|
|
|
heap_idx = left_idx;
|
|
|
|
idx = heap->entries[heap_idx].idx;
|
|
|
|
if (constant_locations[idx] != -1)
|
|
|
|
GL_EXTCALL(glUniform4fvARB(constant_locations[idx], 1, &constants[idx * 4]));
|
|
|
|
|
|
|
|
stack[stack_idx++] = HEAP_NODE_TRAVERSE_RIGHT;
|
|
|
|
stack[stack_idx] = HEAP_NODE_TRAVERSE_LEFT;
|
|
|
|
break;
|
2007-02-27 20:51:58 +01:00
|
|
|
}
|
2006-08-19 17:24:02 +02:00
|
|
|
}
|
2008-12-19 19:21:56 +01:00
|
|
|
|
|
|
|
case HEAP_NODE_TRAVERSE_RIGHT:
|
|
|
|
{
|
|
|
|
unsigned int right_idx = (heap_idx << 1) + 1;
|
|
|
|
if (right_idx < heap->size && heap->entries[right_idx].version > version)
|
|
|
|
{
|
|
|
|
heap_idx = right_idx;
|
|
|
|
idx = heap->entries[heap_idx].idx;
|
|
|
|
if (constant_locations[idx] != -1)
|
|
|
|
GL_EXTCALL(glUniform4fvARB(constant_locations[idx], 1, &constants[idx * 4]));
|
|
|
|
|
|
|
|
stack[stack_idx++] = HEAP_NODE_POP;
|
|
|
|
stack[stack_idx] = HEAP_NODE_TRAVERSE_LEFT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case HEAP_NODE_POP:
|
|
|
|
{
|
|
|
|
heap_idx >>= 1;
|
|
|
|
--stack_idx;
|
|
|
|
break;
|
|
|
|
}
|
2006-08-19 17:24:02 +02:00
|
|
|
}
|
2006-06-16 22:07:00 +02:00
|
|
|
}
|
2008-12-19 19:21:56 +01:00
|
|
|
checkGLcall("walk_constant_heap()");
|
|
|
|
}
|
2007-09-13 13:34:29 +02:00
|
|
|
|
2008-12-19 19:21:56 +01:00
|
|
|
static inline void apply_clamped_constant(const WineD3D_GL_Info *gl_info, GLint location, const GLfloat *data)
|
|
|
|
{
|
|
|
|
GLfloat clamped_constant[4];
|
|
|
|
|
|
|
|
if (location == -1) return;
|
|
|
|
|
|
|
|
clamped_constant[0] = data[0] < -1.0f ? -1.0f : data[0] > 1.0 ? 1.0 : data[0];
|
|
|
|
clamped_constant[1] = data[1] < -1.0f ? -1.0f : data[1] > 1.0 ? 1.0 : data[1];
|
|
|
|
clamped_constant[2] = data[2] < -1.0f ? -1.0f : data[2] > 1.0 ? 1.0 : data[2];
|
|
|
|
clamped_constant[3] = data[3] < -1.0f ? -1.0f : data[3] > 1.0 ? 1.0 : data[3];
|
|
|
|
|
|
|
|
GL_EXTCALL(glUniform4fvARB(location, 1, clamped_constant));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void walk_constant_heap_clamped(const WineD3D_GL_Info *gl_info, const float *constants,
|
|
|
|
const GLhandleARB *constant_locations, const struct constant_heap *heap, unsigned char *stack, DWORD version)
|
|
|
|
{
|
|
|
|
int stack_idx = 0;
|
|
|
|
unsigned int heap_idx = 1;
|
|
|
|
unsigned int idx;
|
|
|
|
|
|
|
|
if (heap->entries[heap_idx].version <= version) return;
|
|
|
|
|
|
|
|
idx = heap->entries[heap_idx].idx;
|
|
|
|
apply_clamped_constant(gl_info, constant_locations[idx], &constants[idx * 4]);
|
|
|
|
stack[stack_idx] = HEAP_NODE_TRAVERSE_LEFT;
|
|
|
|
|
|
|
|
while (stack_idx >= 0)
|
2008-12-15 12:10:14 +01:00
|
|
|
{
|
2008-12-19 19:21:56 +01:00
|
|
|
/* Note that we fall through to the next case statement. */
|
|
|
|
switch(stack[stack_idx])
|
|
|
|
{
|
|
|
|
case HEAP_NODE_TRAVERSE_LEFT:
|
|
|
|
{
|
|
|
|
unsigned int left_idx = heap_idx << 1;
|
|
|
|
if (left_idx < heap->size && heap->entries[left_idx].version > version)
|
|
|
|
{
|
|
|
|
heap_idx = left_idx;
|
|
|
|
idx = heap->entries[heap_idx].idx;
|
|
|
|
apply_clamped_constant(gl_info, constant_locations[idx], &constants[idx * 4]);
|
|
|
|
|
|
|
|
stack[stack_idx++] = HEAP_NODE_TRAVERSE_RIGHT;
|
|
|
|
stack[stack_idx] = HEAP_NODE_TRAVERSE_LEFT;
|
|
|
|
break;
|
2007-09-13 13:34:29 +02:00
|
|
|
}
|
|
|
|
}
|
2008-12-19 19:21:56 +01:00
|
|
|
|
|
|
|
case HEAP_NODE_TRAVERSE_RIGHT:
|
|
|
|
{
|
|
|
|
unsigned int right_idx = (heap_idx << 1) + 1;
|
|
|
|
if (right_idx < heap->size && heap->entries[right_idx].version > version)
|
|
|
|
{
|
|
|
|
heap_idx = right_idx;
|
|
|
|
idx = heap->entries[heap_idx].idx;
|
|
|
|
apply_clamped_constant(gl_info, constant_locations[idx], &constants[idx * 4]);
|
|
|
|
|
|
|
|
stack[stack_idx++] = HEAP_NODE_POP;
|
|
|
|
stack[stack_idx] = HEAP_NODE_TRAVERSE_LEFT;
|
|
|
|
break;
|
2007-09-13 13:34:29 +02:00
|
|
|
}
|
2007-02-27 20:51:58 +01:00
|
|
|
}
|
2008-12-19 19:21:56 +01:00
|
|
|
|
|
|
|
case HEAP_NODE_POP:
|
|
|
|
{
|
|
|
|
heap_idx >>= 1;
|
|
|
|
--stack_idx;
|
|
|
|
break;
|
|
|
|
}
|
2007-02-13 23:12:40 +01:00
|
|
|
}
|
|
|
|
}
|
2008-12-19 19:21:56 +01:00
|
|
|
checkGLcall("walk_constant_heap_clamped()");
|
|
|
|
}
|
2006-07-10 06:51:03 +02:00
|
|
|
|
2008-12-19 19:21:56 +01:00
|
|
|
/* Loads floating point constants (aka uniforms) into the currently set GLSL program. */
|
|
|
|
static void shader_glsl_load_constantsF(IWineD3DBaseShaderImpl *This, const WineD3D_GL_Info *gl_info,
|
|
|
|
const float *constants, const GLhandleARB *constant_locations, const struct constant_heap *heap,
|
|
|
|
unsigned char *stack, UINT version)
|
|
|
|
{
|
|
|
|
const local_constant *lconst;
|
|
|
|
|
|
|
|
/* 1.X pshaders have the constants clamped to [-1;1] implicitly. */
|
|
|
|
if (WINED3DSHADER_VERSION_MAJOR(This->baseShader.reg_maps.shader_version) == 1
|
|
|
|
&& shader_is_pshader_version(This->baseShader.reg_maps.shader_version))
|
|
|
|
walk_constant_heap_clamped(gl_info, constants, constant_locations, heap, stack, version);
|
|
|
|
else
|
|
|
|
walk_constant_heap(gl_info, constants, constant_locations, heap, stack, version);
|
|
|
|
|
|
|
|
if (!This->baseShader.load_local_constsF)
|
|
|
|
{
|
2007-11-09 14:48:47 +01:00
|
|
|
TRACE("No need to load local float constants for this shader\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-13 13:34:29 +02:00
|
|
|
/* Immediate constants are clamped to [-1;1] at shader creation time if needed */
|
2008-12-19 19:21:56 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(lconst, &This->baseShader.constantsF, local_constant, entry)
|
|
|
|
{
|
|
|
|
GLhandleARB location = constant_locations[lconst->idx];
|
|
|
|
/* We found this uniform name in the program - go ahead and send the data */
|
|
|
|
if (location != -1) GL_EXTCALL(glUniform4fvARB(location, 1, (const 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
|
|
|
}
|
|
|
|
|
2008-12-02 18:41:33 +01:00
|
|
|
/* Loads integer constants (aka uniforms) into the currently set GLSL program. */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_load_constantsI(IWineD3DBaseShaderImpl *This, const WineD3D_GL_Info *gl_info,
|
2008-12-02 18:41:33 +01:00
|
|
|
const GLhandleARB locations[MAX_CONST_I], const int *constants, WORD constants_set)
|
2008-11-25 14:36:09 +01:00
|
|
|
{
|
2008-12-01 13:02:08 +01:00
|
|
|
unsigned int i;
|
2006-07-10 06:51:03 +02:00
|
|
|
struct list* ptr;
|
2006-06-16 22:08:34 +02:00
|
|
|
|
2008-12-02 18:41:33 +01:00
|
|
|
for (i = 0; constants_set; constants_set >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(constants_set & 1)) continue;
|
2006-06-16 22:08:34 +02:00
|
|
|
|
2008-12-02 18:41:33 +01:00
|
|
|
TRACE_(d3d_constants)("Loading constants %u: %i, %i, %i, %i\n",
|
|
|
|
i, constants[i*4], constants[i*4+1], constants[i*4+2], constants[i*4+3]);
|
2006-06-16 22:08:34 +02:00
|
|
|
|
2008-12-02 18:41:33 +01:00
|
|
|
/* We found this uniform name in the program - go ahead and send the data */
|
|
|
|
GL_EXTCALL(glUniform4ivARB(locations[i], 1, &constants[i*4]));
|
|
|
|
checkGLcall("glUniform4ivARB");
|
2006-06-16 22:08:34 +02:00
|
|
|
}
|
2006-07-10 06:51:03 +02:00
|
|
|
|
|
|
|
/* Load immediate constants */
|
|
|
|
ptr = list_head(&This->baseShader.constantsI);
|
|
|
|
while (ptr) {
|
2008-11-25 14:36:09 +01:00
|
|
|
const struct local_constant *lconst = LIST_ENTRY(ptr, const struct local_constant, entry);
|
2006-07-10 06:51:03 +02:00
|
|
|
unsigned int idx = lconst->idx;
|
2008-11-25 14:36:09 +01:00
|
|
|
const GLint *values = (const GLint *)lconst->value;
|
2006-07-10 06:51:03 +02:00
|
|
|
|
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]);
|
|
|
|
|
2007-11-06 23:36:10 +01:00
|
|
|
/* We found this uniform name in the program - go ahead and send the data */
|
|
|
|
GL_EXTCALL(glUniform4ivARB(locations[idx], 1, values));
|
|
|
|
checkGLcall("glUniform4ivARB");
|
2006-07-10 06:51:03 +02:00
|
|
|
ptr = list_next(&This->baseShader.constantsI, ptr);
|
|
|
|
}
|
2006-06-16 22:08:34 +02:00
|
|
|
}
|
|
|
|
|
2008-12-02 18:41:33 +01:00
|
|
|
/* Loads boolean constants (aka uniforms) into the currently set GLSL program. */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_load_constantsB(IWineD3DBaseShaderImpl *This, const WineD3D_GL_Info *gl_info,
|
2008-12-02 18:41:33 +01:00
|
|
|
GLhandleARB programId, const BOOL *constants, WORD constants_set)
|
2008-11-25 14:36:09 +01:00
|
|
|
{
|
2006-06-16 22:08:34 +02:00
|
|
|
GLhandleARB tmp_loc;
|
2008-12-01 13:02:08 +01:00
|
|
|
unsigned int i;
|
2006-08-13 11:18:12 +02:00
|
|
|
char tmp_name[8];
|
2008-12-15 12:10:14 +01:00
|
|
|
char is_pshader = shader_is_pshader_version(This->baseShader.reg_maps.shader_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
|
|
|
|
2008-12-02 18:41:33 +01:00
|
|
|
/* TODO: Benchmark and see if it would be beneficial to store the
|
|
|
|
* locations of the constants to avoid looking up each time */
|
|
|
|
for (i = 0; constants_set; constants_set >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(constants_set & 1)) continue;
|
2006-06-16 22:08:34 +02:00
|
|
|
|
2008-12-02 18:41:33 +01:00
|
|
|
TRACE_(d3d_constants)("Loading constants %i: %i;\n", i, constants[i]);
|
2006-06-16 22:08:34 +02:00
|
|
|
|
2008-12-02 18:41:33 +01: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]));
|
|
|
|
checkGLcall("glUniform1ivARB");
|
2006-06-16 22:08:34 +02:00
|
|
|
}
|
|
|
|
}
|
2006-07-10 06:51:03 +02:00
|
|
|
|
|
|
|
/* Load immediate constants */
|
|
|
|
ptr = list_head(&This->baseShader.constantsB);
|
|
|
|
while (ptr) {
|
2008-11-25 14:36:09 +01:00
|
|
|
const struct local_constant *lconst = LIST_ENTRY(ptr, const struct local_constant, entry);
|
2006-07-10 06:51:03 +02:00
|
|
|
unsigned int idx = lconst->idx;
|
2008-11-25 14:36:09 +01:00
|
|
|
const GLint *values = (const GLint *)lconst->value;
|
2006-07-10 06:51:03 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-12-19 19:21:56 +01:00
|
|
|
static void reset_program_constant_version(void *value, void *context)
|
|
|
|
{
|
2009-01-20 10:00:20 +01:00
|
|
|
struct glsl_shader_prog_link *entry = value;
|
2008-12-19 19:21:56 +01:00
|
|
|
entry->constant_version = 0;
|
|
|
|
}
|
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.
|
|
|
|
*/
|
2008-09-16 14:55:39 +02:00
|
|
|
static 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;
|
2009-02-03 09:36:07 +01:00
|
|
|
struct shader_glsl_priv *priv = deviceImpl->shader_priv;
|
2006-09-27 13:15:58 +02:00
|
|
|
IWineD3DStateBlockImpl* stateBlock = deviceImpl->stateBlock;
|
2008-11-25 14:36:09 +01:00
|
|
|
const WineD3D_GL_Info *gl_info = &deviceImpl->adapter->gl_info;
|
2006-09-27 13:15:58 +02:00
|
|
|
|
2006-08-19 17:23:20 +02:00
|
|
|
GLhandleARB programId;
|
2008-12-19 19:21:56 +01:00
|
|
|
struct glsl_shader_prog_link *prog = priv->glsl_program;
|
|
|
|
UINT constant_version;
|
2008-12-01 13:02:08 +01:00
|
|
|
int i;
|
2007-02-15 03:05:17 +01:00
|
|
|
|
2007-11-06 23:05:38 +01:00
|
|
|
if (!prog) {
|
2006-06-16 22:07:00 +02:00
|
|
|
/* No GLSL program set - nothing to do. */
|
|
|
|
return;
|
|
|
|
}
|
2007-11-06 23:05:38 +01:00
|
|
|
programId = prog->programId;
|
2008-12-19 19:21:56 +01:00
|
|
|
constant_version = prog->constant_version;
|
2006-06-16 22:07:00 +02:00
|
|
|
|
|
|
|
if (useVertexShader) {
|
2006-07-10 06:51:03 +02:00
|
|
|
IWineD3DBaseShaderImpl* vshader = (IWineD3DBaseShaderImpl*) stateBlock->vertexShader;
|
|
|
|
|
2006-06-16 22:07:00 +02:00
|
|
|
/* Load DirectX 9 float constants/uniforms for vertex shader */
|
2008-12-19 19:21:56 +01:00
|
|
|
shader_glsl_load_constantsF(vshader, gl_info, stateBlock->vertexShaderConstantF,
|
|
|
|
prog->vuniformF_locations, &priv->vconst_heap, priv->stack, constant_version);
|
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 */
|
2008-11-27 01:21:36 +01:00
|
|
|
if(vshader->baseShader.uses_int_consts) {
|
|
|
|
shader_glsl_load_constantsI(vshader, gl_info, prog->vuniformI_locations,
|
|
|
|
stateBlock->vertexShaderConstantI, stateBlock->changed.vertexShaderConstantsI);
|
|
|
|
}
|
2006-06-16 22:08:34 +02:00
|
|
|
|
|
|
|
/* Load DirectX 9 boolean constants/uniforms for vertex shader */
|
2008-11-27 01:21:36 +01:00
|
|
|
if(vshader->baseShader.uses_bool_consts) {
|
|
|
|
shader_glsl_load_constantsB(vshader, gl_info, programId,
|
|
|
|
stateBlock->vertexShaderConstantB, stateBlock->changed.vertexShaderConstantsB);
|
|
|
|
}
|
2006-09-23 19:09:06 +02:00
|
|
|
|
|
|
|
/* Upload the position fixup params */
|
2007-11-06 23:05:38 +01:00
|
|
|
GL_EXTCALL(glUniform4fvARB(prog->posFixup_location, 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-06-16 22:07:00 +02:00
|
|
|
/* Load DirectX 9 float constants/uniforms for pixel shader */
|
2008-12-19 19:21:56 +01:00
|
|
|
shader_glsl_load_constantsF(pshader, gl_info, stateBlock->pixelShaderConstantF,
|
|
|
|
prog->puniformF_locations, &priv->pconst_heap, priv->stack, constant_version);
|
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 */
|
2008-11-27 01:21:36 +01:00
|
|
|
if(pshader->baseShader.uses_int_consts) {
|
|
|
|
shader_glsl_load_constantsI(pshader, gl_info, prog->puniformI_locations,
|
|
|
|
stateBlock->pixelShaderConstantI, stateBlock->changed.pixelShaderConstantsI);
|
|
|
|
}
|
2007-02-15 03:05:17 +01:00
|
|
|
|
2006-06-16 22:08:34 +02:00
|
|
|
/* Load DirectX 9 boolean constants/uniforms for pixel shader */
|
2008-11-27 01:21:36 +01:00
|
|
|
if(pshader->baseShader.uses_bool_consts) {
|
|
|
|
shader_glsl_load_constantsB(pshader, gl_info, programId,
|
|
|
|
stateBlock->pixelShaderConstantB, stateBlock->changed.pixelShaderConstantsB);
|
|
|
|
}
|
2007-02-15 03:05:17 +01:00
|
|
|
|
|
|
|
/* Upload the environment bump map matrix if needed. The needsbumpmat member specifies the texture stage to load the matrix from.
|
|
|
|
* It can't be 0 for a valid texbem instruction.
|
|
|
|
*/
|
2008-03-05 03:18:55 +01:00
|
|
|
for(i = 0; i < ((IWineD3DPixelShaderImpl *) pshader)->numbumpenvmatconsts; i++) {
|
|
|
|
IWineD3DPixelShaderImpl *ps = (IWineD3DPixelShaderImpl *) pshader;
|
|
|
|
int stage = ps->luminanceconst[i].texunit;
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
const float *data = (const float *)&stateBlock->textureState[(int)ps->bumpenvmatconst[i].texunit][WINED3DTSS_BUMPENVMAT00];
|
2008-03-05 03:18:55 +01:00
|
|
|
GL_EXTCALL(glUniformMatrix2fvARB(prog->bumpenvmat_location[i], 1, 0, data));
|
2007-09-01 20:11:17 +02:00
|
|
|
checkGLcall("glUniformMatrix2fvARB");
|
|
|
|
|
|
|
|
/* texbeml needs the luminance scale and offset too. If texbeml is used, needsbumpmat
|
|
|
|
* is set too, so we can check that in the needsbumpmat check
|
|
|
|
*/
|
2008-03-05 03:18:55 +01:00
|
|
|
if(ps->baseShader.reg_maps.luminanceparams[stage]) {
|
2008-11-25 14:36:09 +01:00
|
|
|
const GLfloat *scale = (const GLfloat *)&stateBlock->textureState[stage][WINED3DTSS_BUMPENVLSCALE];
|
|
|
|
const GLfloat *offset = (const GLfloat *)&stateBlock->textureState[stage][WINED3DTSS_BUMPENVLOFFSET];
|
2007-09-01 20:11:17 +02:00
|
|
|
|
2008-03-05 03:18:55 +01:00
|
|
|
GL_EXTCALL(glUniform1fvARB(prog->luminancescale_location[i], 1, scale));
|
2007-09-01 20:11:17 +02:00
|
|
|
checkGLcall("glUniform1fvARB");
|
2008-03-05 03:18:55 +01:00
|
|
|
GL_EXTCALL(glUniform1fvARB(prog->luminanceoffset_location[i], 1, offset));
|
2007-09-01 20:11:17 +02:00
|
|
|
checkGLcall("glUniform1fvARB");
|
|
|
|
}
|
2008-03-05 03:18:55 +01:00
|
|
|
}
|
|
|
|
|
2007-09-14 13:11:00 +02:00
|
|
|
if(((IWineD3DPixelShaderImpl *) pshader)->vpos_uniform) {
|
|
|
|
float correction_params[4];
|
|
|
|
if(deviceImpl->render_offscreen) {
|
|
|
|
correction_params[0] = 0.0;
|
|
|
|
correction_params[1] = 1.0;
|
|
|
|
} else {
|
|
|
|
/* position is window relative, not viewport relative */
|
|
|
|
correction_params[0] = ((IWineD3DSurfaceImpl *) deviceImpl->render_targets[0])->currentDesc.Height;
|
|
|
|
correction_params[1] = -1.0;
|
|
|
|
}
|
2007-11-06 23:05:38 +01:00
|
|
|
GL_EXTCALL(glUniform4fvARB(prog->ycorrection_location, 1, correction_params));
|
2007-09-14 13:11:00 +02:00
|
|
|
}
|
2006-06-16 22:07:00 +02:00
|
|
|
}
|
2008-12-19 19:21:56 +01:00
|
|
|
|
|
|
|
if (priv->next_constant_version == UINT_MAX)
|
|
|
|
{
|
|
|
|
TRACE("Max constant version reached, resetting to 0.\n");
|
|
|
|
hash_table_for_each_entry(priv->glsl_program_lookup, reset_program_constant_version, NULL);
|
|
|
|
priv->next_constant_version = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prog->constant_version = priv->next_constant_version++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void update_heap_entry(struct constant_heap *heap, unsigned int idx,
|
|
|
|
unsigned int heap_idx, DWORD new_version)
|
|
|
|
{
|
|
|
|
struct constant_entry *entries = heap->entries;
|
|
|
|
unsigned int *positions = heap->positions;
|
|
|
|
unsigned int parent_idx;
|
|
|
|
|
|
|
|
while (heap_idx > 1)
|
|
|
|
{
|
|
|
|
parent_idx = heap_idx >> 1;
|
|
|
|
|
|
|
|
if (new_version <= entries[parent_idx].version) break;
|
|
|
|
|
|
|
|
entries[heap_idx] = entries[parent_idx];
|
|
|
|
positions[entries[parent_idx].idx] = heap_idx;
|
|
|
|
heap_idx = parent_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
entries[heap_idx].version = new_version;
|
|
|
|
entries[heap_idx].idx = idx;
|
|
|
|
positions[idx] = heap_idx;
|
2006-06-16 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2008-12-17 17:07:25 +01:00
|
|
|
static void shader_glsl_update_float_vertex_constants(IWineD3DDevice *iface, UINT start, UINT count)
|
|
|
|
{
|
|
|
|
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
|
2009-02-03 09:36:07 +01:00
|
|
|
struct shader_glsl_priv *priv = This->shader_priv;
|
2008-12-19 19:21:56 +01:00
|
|
|
struct constant_heap *heap = &priv->vconst_heap;
|
2008-12-17 17:07:25 +01:00
|
|
|
UINT i;
|
|
|
|
|
|
|
|
for (i = start; i < count + start; ++i)
|
|
|
|
{
|
|
|
|
if (!This->stateBlock->changed.vertexShaderConstantsF[i])
|
2008-12-19 19:21:56 +01:00
|
|
|
update_heap_entry(heap, i, heap->size++, priv->next_constant_version);
|
|
|
|
else
|
|
|
|
update_heap_entry(heap, i, heap->positions[i], priv->next_constant_version);
|
2008-12-17 17:07:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void shader_glsl_update_float_pixel_constants(IWineD3DDevice *iface, UINT start, UINT count)
|
|
|
|
{
|
|
|
|
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
|
2009-02-03 09:36:07 +01:00
|
|
|
struct shader_glsl_priv *priv = This->shader_priv;
|
2008-12-19 19:21:56 +01:00
|
|
|
struct constant_heap *heap = &priv->pconst_heap;
|
2008-12-17 17:07:25 +01:00
|
|
|
UINT i;
|
|
|
|
|
|
|
|
for (i = start; i < count + start; ++i)
|
|
|
|
{
|
|
|
|
if (!This->stateBlock->changed.pixelShaderConstantsF[i])
|
2008-12-19 19:21:56 +01:00
|
|
|
update_heap_entry(heap, i, heap->size++, priv->next_constant_version);
|
|
|
|
else
|
|
|
|
update_heap_entry(heap, i, heap->positions[i], priv->next_constant_version);
|
2008-12-17 17:07:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-16 22:07:31 +02:00
|
|
|
/** Generate the variable & register declarations for the GLSL output target */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_generate_glsl_declarations(IWineD3DBaseShader *iface, const shader_reg_maps *reg_maps,
|
2008-12-15 19:31:52 +01:00
|
|
|
SHADER_BUFFER *buffer, const WineD3D_GL_Info *gl_info,
|
|
|
|
const struct ps_compile_args *ps_args)
|
2008-11-25 14:36:09 +01:00
|
|
|
{
|
2006-06-16 22:07:31 +02:00
|
|
|
IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
|
2007-09-14 13:02:59 +02:00
|
|
|
IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device;
|
2008-12-15 12:10:14 +01:00
|
|
|
DWORD shader_version = reg_maps->shader_version;
|
2008-12-01 13:02:08 +01:00
|
|
|
unsigned int i, extra_constants_needed = 0;
|
2008-11-25 14:36:09 +01:00
|
|
|
const local_constant *lconst;
|
2006-06-16 22:07:31 +02:00
|
|
|
|
|
|
|
/* There are some minor differences between pixel and vertex shaders */
|
2008-12-15 12:10:14 +01:00
|
|
|
char pshader = shader_is_pshader_version(shader_version);
|
2006-06-16 22:07:31 +02:00
|
|
|
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])
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(buffer, "void subroutine%u();\n", i);
|
2006-07-10 12:35:15 +02:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2007-09-14 13:02:59 +02:00
|
|
|
if(!pshader) {
|
2006-09-23 19:09:06 +02:00
|
|
|
shader_addline(buffer, "uniform vec4 posFixup;\n");
|
2007-10-26 02:11:00 +02:00
|
|
|
/* Predeclaration; This function is added at link time based on the pixel shader.
|
|
|
|
* VS 3.0 shaders have an array OUT[] the shader writes to, earlier versions don't have
|
|
|
|
* that. We know the input to the reorder function at vertex shader compile time, so
|
|
|
|
* we can deal with that. The reorder function for a 1.x and 2.x vertex shader can just
|
|
|
|
* read gl_FrontColor. The output depends on the pixel shader. The reorder function for a
|
|
|
|
* 1.x and 2.x pshader or for fixed function will write gl_FrontColor, and for a 3.0 shader
|
|
|
|
* it will write to the varying array. Here we depend on the shader optimizer on sorting that
|
|
|
|
* out. The nvidia driver only does that if the parameter is inout instead of out, hence the
|
|
|
|
* inout.
|
|
|
|
*/
|
2008-12-15 12:10:14 +01:00
|
|
|
if (shader_version >= WINED3DVS_VERSION(3, 0))
|
|
|
|
{
|
2007-10-26 02:11:00 +02:00
|
|
|
shader_addline(buffer, "void order_ps_input(in vec4[%u]);\n", MAX_REG_OUTPUT);
|
|
|
|
} else {
|
|
|
|
shader_addline(buffer, "void order_ps_input();\n");
|
|
|
|
}
|
2007-09-14 13:02:59 +02:00
|
|
|
} else {
|
|
|
|
IWineD3DPixelShaderImpl *ps_impl = (IWineD3DPixelShaderImpl *) This;
|
|
|
|
|
2008-03-05 03:18:55 +01:00
|
|
|
ps_impl->numbumpenvmatconsts = 0;
|
|
|
|
for(i = 0; i < (sizeof(reg_maps->bumpmat) / sizeof(reg_maps->bumpmat[0])); i++) {
|
|
|
|
if(!reg_maps->bumpmat[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ps_impl->bumpenvmatconst[(int) ps_impl->numbumpenvmatconsts].texunit = i;
|
|
|
|
shader_addline(buffer, "uniform mat2 bumpenvmat%d;\n", i);
|
|
|
|
|
2007-09-14 13:02:59 +02:00
|
|
|
if(reg_maps->luminanceparams) {
|
2008-03-05 03:18:55 +01:00
|
|
|
ps_impl->luminanceconst[(int) ps_impl->numbumpenvmatconsts].texunit = i;
|
|
|
|
shader_addline(buffer, "uniform float luminancescale%d;\n", i);
|
|
|
|
shader_addline(buffer, "uniform float luminanceoffset%d;\n", i);
|
2007-09-14 13:02:59 +02:00
|
|
|
extra_constants_needed++;
|
2008-03-05 03:18:55 +01:00
|
|
|
} else {
|
|
|
|
ps_impl->luminanceconst[(int) ps_impl->numbumpenvmatconsts].texunit = -1;
|
2007-09-14 13:02:59 +02:00
|
|
|
}
|
2008-03-05 03:18:55 +01:00
|
|
|
|
2007-09-14 13:02:59 +02:00
|
|
|
extra_constants_needed++;
|
2008-03-05 03:18:55 +01:00
|
|
|
ps_impl->numbumpenvmatconsts++;
|
2007-09-14 13:02:59 +02:00
|
|
|
}
|
|
|
|
|
2008-12-15 19:31:52 +01:00
|
|
|
if(ps_args->srgb_correction) {
|
2008-11-24 11:55:50 +01:00
|
|
|
shader_addline(buffer, "const vec4 srgb_mul_low = vec4(%f, %f, %f, %f);\n",
|
|
|
|
srgb_mul_low, srgb_mul_low, srgb_mul_low, srgb_mul_low);
|
|
|
|
shader_addline(buffer, "const vec4 srgb_comparison = vec4(%f, %f, %f, %f);\n",
|
|
|
|
srgb_cmp, srgb_cmp, srgb_cmp, srgb_cmp);
|
2007-09-01 20:11:17 +02:00
|
|
|
}
|
2007-10-13 13:03:56 +02:00
|
|
|
if(reg_maps->vpos || reg_maps->usesdsy) {
|
2007-09-14 13:11:00 +02:00
|
|
|
if(This->baseShader.limits.constant_float + extra_constants_needed + 1 < GL_LIMITS(pshader_constantsF)) {
|
|
|
|
shader_addline(buffer, "uniform vec4 ycorrection;\n");
|
|
|
|
((IWineD3DPixelShaderImpl *) This)->vpos_uniform = 1;
|
|
|
|
extra_constants_needed++;
|
|
|
|
} else {
|
|
|
|
/* This happens because we do not have proper tracking of the constant registers that are
|
|
|
|
* actually used, only the max limit of the shader version
|
|
|
|
*/
|
|
|
|
FIXME("Cannot find a free uniform for vpos correction params\n");
|
2007-11-09 14:52:56 +01:00
|
|
|
shader_addline(buffer, "const vec4 ycorrection = vec4(%f, %f, 0.0, 0.0);\n",
|
2007-09-14 13:11:00 +02:00
|
|
|
device->render_offscreen ? 0.0 : ((IWineD3DSurfaceImpl *) device->render_targets[0])->currentDesc.Height,
|
|
|
|
device->render_offscreen ? 1.0 : -1.0);
|
|
|
|
}
|
|
|
|
shader_addline(buffer, "vec4 vpos;\n");
|
|
|
|
}
|
2007-09-01 20:11:17 +02:00
|
|
|
}
|
2006-09-23 19:09:06 +02:00
|
|
|
|
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:
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(buffer, "uniform sampler1D %csampler%u;\n", prefix, i);
|
2006-07-28 21:34:39 +02:00
|
|
|
break;
|
|
|
|
case WINED3DSTT_2D:
|
2007-11-27 22:25:07 +01:00
|
|
|
if(device->stateBlock->textures[i] &&
|
|
|
|
IWineD3DBaseTexture_GetTextureDimensions(device->stateBlock->textures[i]) == GL_TEXTURE_RECTANGLE_ARB) {
|
|
|
|
shader_addline(buffer, "uniform sampler2DRect %csampler%u;\n", prefix, i);
|
|
|
|
} else {
|
|
|
|
shader_addline(buffer, "uniform sampler2D %csampler%u;\n", prefix, i);
|
|
|
|
}
|
2006-06-16 22:07:31 +02:00
|
|
|
break;
|
2006-07-28 21:34:39 +02:00
|
|
|
case WINED3DSTT_CUBE:
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(buffer, "uniform samplerCube %csampler%u;\n", prefix, i);
|
2006-06-16 22:07:31 +02:00
|
|
|
break;
|
2006-07-28 21:34:39 +02:00
|
|
|
case WINED3DSTT_VOLUME:
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(buffer, "uniform sampler3D %csampler%u;\n", prefix, i);
|
2006-06-16 22:07:31 +02:00
|
|
|
break;
|
|
|
|
default:
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(buffer, "uniform unsupported_sampler %csampler%u;\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])
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(buffer, "vec4 T%u = gl_TexCoord[%u];\n", i, i);
|
2006-06-16 22:07:31 +02:00
|
|
|
}
|
|
|
|
|
2007-10-26 02:11:00 +02:00
|
|
|
/* Declare input register varyings. Only pixel shader, vertex shaders have that declared in the
|
|
|
|
* helper function shader that is linked in at link time
|
|
|
|
*/
|
2008-12-15 12:10:14 +01:00
|
|
|
if (pshader && shader_version >= WINED3DPS_VERSION(3, 0))
|
|
|
|
{
|
2008-12-30 14:56:49 +01:00
|
|
|
if (use_vs(device->stateBlock))
|
|
|
|
{
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(buffer, "varying vec4 IN[%u];\n", GL_LIMITS(glsl_varyings) / 4);
|
2007-10-26 02:11:00 +02:00
|
|
|
} else {
|
|
|
|
/* TODO: Write a replacement shader for the fixed function vertex pipeline, so this isn't needed.
|
|
|
|
* For fixed function vertex processing + 3.0 pixel shader we need a separate function in the
|
|
|
|
* pixel shader that reads the fixed function color into the packed input registers.
|
|
|
|
*/
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(buffer, "vec4 IN[%u];\n", GL_LIMITS(glsl_varyings) / 4);
|
2007-10-26 02:11:00 +02:00
|
|
|
}
|
2006-06-16 22:07:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Declare output register temporaries */
|
2007-10-26 02:11:00 +02:00
|
|
|
if(This->baseShader.limits.packed_output) {
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(buffer, "vec4 OUT[%u];\n", This->baseShader.limits.packed_output);
|
2006-06-16 22:07:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Declare temporary variables */
|
|
|
|
for(i = 0; i < This->baseShader.limits.temporary; i++) {
|
|
|
|
if (reg_maps->temporary[i])
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(buffer, "vec4 R%u;\n", i);
|
2006-06-16 22:07:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2008-04-23 07:13:32 +02:00
|
|
|
/* Declare loop registers aLx */
|
2007-09-14 13:21:52 +02:00
|
|
|
for (i = 0; i < reg_maps->loop_depth; i++) {
|
|
|
|
shader_addline(buffer, "int aL%u;\n", i);
|
|
|
|
shader_addline(buffer, "int tmpInt%u;\n", i);
|
2006-06-17 05:01:20 +02:00
|
|
|
}
|
2007-09-14 13:21:52 +02:00
|
|
|
|
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");
|
|
|
|
|
2008-06-02 21:44:06 +02:00
|
|
|
/* Local constants use a different name so they can be loaded once at shader link time
|
|
|
|
* They can't be hardcoded into the shader text via LC = {x, y, z, w}; because the
|
|
|
|
* float -> string conversion can cause precision loss.
|
|
|
|
*/
|
2007-11-09 14:48:47 +01:00
|
|
|
if(!This->baseShader.load_local_constsF) {
|
|
|
|
LIST_FOR_EACH_ENTRY(lconst, &This->baseShader.constantsF, local_constant, entry) {
|
2008-06-02 21:44:06 +02:00
|
|
|
shader_addline(buffer, "uniform vec4 %cLC%u;\n", prefix, lconst->idx);
|
2007-11-09 14:48:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-16 22:07:31 +02:00
|
|
|
/* Start the main program */
|
|
|
|
shader_addline(buffer, "void main() {\n");
|
2007-09-14 13:11:00 +02:00
|
|
|
if(pshader && reg_maps->vpos) {
|
2008-03-07 03:13:07 +01:00
|
|
|
/* DirectX apps expect integer values, while OpenGL drivers add approximately 0.5. This causes
|
|
|
|
* off-by-one problems as spotted by the vPos d3d9 visual test. Unfortunately the ATI cards do
|
|
|
|
* not add exactly 0.5, but rather something like 0.49999999 or 0.50000001, which still causes
|
|
|
|
* precision troubles when we just substract 0.5.
|
|
|
|
*
|
|
|
|
* To deal with that just floor() the position. This will eliminate the fraction on all cards.
|
|
|
|
*
|
|
|
|
* TODO: Test how that behaves with multisampling once we can enable multisampling in winex11.
|
|
|
|
*
|
|
|
|
* An advantage of floor is that it works even if the driver doesn't add 1/2. It is somewhat
|
|
|
|
* questionable if 1.5, 2.5, ... are the proper values to return in gl_FragCoord, even though
|
|
|
|
* coordinates specify the pixel centers instead of the pixel corners. This code will behave
|
|
|
|
* correctly on drivers that returns integer values.
|
|
|
|
*/
|
|
|
|
shader_addline(buffer, "vpos = floor(vec4(0, ycorrection[0], 0, 0) + gl_FragCoord * vec4(1, ycorrection[1], 1, 1));\n");
|
2007-09-14 13:11:00 +02:00
|
|
|
}
|
2006-06-16 22:07:31 +02:00
|
|
|
}
|
|
|
|
|
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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_add_src_param(const 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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_get_register_name(const DWORD param, const DWORD addr_token,
|
|
|
|
char *regstr, BOOL *is_color, const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2006-06-09 09:33:01 +02:00
|
|
|
/* 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;
|
2008-11-25 14:36:09 +01:00
|
|
|
const WineD3D_GL_Info* gl_info = &deviceImpl->adapter->gl_info;
|
2008-12-15 12:10:14 +01:00
|
|
|
DWORD shader_version = This->baseShader.reg_maps.shader_version;
|
|
|
|
char pshader = shader_is_pshader_version(shader_version);
|
2008-06-19 00:36:35 +02:00
|
|
|
char tmpStr[150];
|
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 */
|
2008-12-15 12:10:14 +01:00
|
|
|
if (WINED3DSHADER_VERSION_MAJOR(shader_version) >= 3)
|
|
|
|
{
|
2008-06-19 00:36:35 +02:00
|
|
|
DWORD in_count = GL_LIMITS(glsl_varyings) / 4;
|
|
|
|
|
2007-10-28 00:08:56 +02:00
|
|
|
if (param & WINED3DSHADER_ADDRMODE_RELATIVE) {
|
|
|
|
glsl_src_param_t rel_param;
|
|
|
|
shader_glsl_add_src_param(arg, addr_token, 0, WINED3DSP_WRITEMASK_0, &rel_param);
|
|
|
|
|
2007-11-02 01:50:20 +01:00
|
|
|
/* Removing a + 0 would be an obvious optimization, but macos doesn't see the NOP
|
|
|
|
* operation there
|
|
|
|
*/
|
|
|
|
if(((IWineD3DPixelShaderImpl *) This)->input_reg_map[reg]) {
|
2008-06-19 00:36:35 +02:00
|
|
|
if (((IWineD3DPixelShaderImpl *)This)->declared_in_count > in_count) {
|
|
|
|
sprintf(tmpStr, "((%s + %u) > %d ? (%s + %u) > %d ? gl_SecondaryColor : gl_Color : IN[%s + %u])",
|
|
|
|
rel_param.param_str, ((IWineD3DPixelShaderImpl *)This)->input_reg_map[reg], in_count - 1,
|
|
|
|
rel_param.param_str, ((IWineD3DPixelShaderImpl *)This)->input_reg_map[reg], in_count,
|
|
|
|
rel_param.param_str, ((IWineD3DPixelShaderImpl *)This)->input_reg_map[reg]);
|
|
|
|
} else {
|
|
|
|
sprintf(tmpStr, "IN[%s + %u]", rel_param.param_str, ((IWineD3DPixelShaderImpl *)This)->input_reg_map[reg]);
|
|
|
|
}
|
2007-11-02 01:50:20 +01:00
|
|
|
} else {
|
2008-06-19 00:36:35 +02:00
|
|
|
if (((IWineD3DPixelShaderImpl *)This)->declared_in_count > in_count) {
|
|
|
|
sprintf(tmpStr, "((%s) > %d ? (%s) > %d ? gl_SecondaryColor : gl_Color : IN[%s])",
|
|
|
|
rel_param.param_str, in_count - 1,
|
|
|
|
rel_param.param_str, in_count,
|
|
|
|
rel_param.param_str);
|
|
|
|
} else {
|
|
|
|
sprintf(tmpStr, "IN[%s]", rel_param.param_str);
|
|
|
|
}
|
2007-11-02 01:50:20 +01:00
|
|
|
}
|
2007-10-28 00:08:56 +02:00
|
|
|
} else {
|
2008-06-19 00:36:35 +02:00
|
|
|
DWORD idx = ((IWineD3DPixelShaderImpl *) This)->input_reg_map[reg];
|
|
|
|
if (idx == in_count) {
|
|
|
|
sprintf(tmpStr, "gl_Color");
|
|
|
|
} else if (idx == in_count + 1) {
|
|
|
|
sprintf(tmpStr, "gl_SecondaryColor");
|
|
|
|
} else {
|
|
|
|
sprintf(tmpStr, "IN[%u]", idx);
|
|
|
|
}
|
2007-10-28 00:08:56 +02:00
|
|
|
}
|
|
|
|
} else {
|
2006-06-12 08:57:07 +02:00
|
|
|
if (reg==0)
|
|
|
|
strcpy(tmpStr, "gl_Color");
|
|
|
|
else
|
|
|
|
strcpy(tmpStr, "gl_SecondaryColor");
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
} else {
|
2009-02-05 19:44:32 +01:00
|
|
|
if (((IWineD3DVertexShaderImpl *)This)->cur_args->swizzle_map & (1 << 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
|
|
|
{
|
2008-06-02 21:12:27 +02:00
|
|
|
const char prefix = pshader? 'P':'V';
|
2006-06-12 09:00:03 +02:00
|
|
|
|
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 */
|
2008-12-15 12:10:14 +01:00
|
|
|
if (WINED3DSHADER_VERSION_MAJOR(shader_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);
|
2007-11-02 01:50:20 +01:00
|
|
|
if(reg) {
|
2008-06-02 21:12:27 +02:00
|
|
|
sprintf(tmpStr, "%cC[%s + %u]", prefix, rel_param.param_str, reg);
|
2007-11-02 01:50:20 +01:00
|
|
|
} else {
|
2008-06-02 21:12:27 +02:00
|
|
|
sprintf(tmpStr, "%cC[%s]", prefix, rel_param.param_str);
|
2007-11-02 01:50:20 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(reg) {
|
2008-06-02 21:12:27 +02:00
|
|
|
sprintf(tmpStr, "%cC[A0.x + %u]", prefix, reg);
|
2007-11-02 01:50:20 +01:00
|
|
|
} else {
|
2008-06-02 21:12:27 +02:00
|
|
|
sprintf(tmpStr, "%cC[A0.x]", prefix);
|
2007-11-02 01:50:20 +01:00
|
|
|
}
|
|
|
|
}
|
2006-07-10 06:51:03 +02:00
|
|
|
|
2007-11-09 14:48:47 +01:00
|
|
|
} else {
|
2008-02-14 14:15:49 +01:00
|
|
|
if(shader_constant_is_local(This, reg)) {
|
2008-06-02 21:12:27 +02:00
|
|
|
sprintf(tmpStr, "%cLC%u", prefix, reg);
|
2007-11-09 14:48:47 +01:00
|
|
|
} else {
|
2008-06-02 21:12:27 +02:00
|
|
|
sprintf(tmpStr, "%cC[%u]", prefix, reg);
|
2007-11-09 14:48:47 +01:00
|
|
|
}
|
|
|
|
}
|
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:
|
2007-09-14 13:21:52 +02:00
|
|
|
sprintf(tmpStr, "aL%u", This->baseShader.cur_loop_regno - 1);
|
2006-06-14 04:32:14 +02:00
|
|
|
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 */
|
2008-12-15 12:10:14 +01:00
|
|
|
if (WINED3DSHADER_VERSION_MAJOR(shader_version) >= 3) sprintf(tmpStr, "OUT[%u]", reg);
|
|
|
|
else sprintf(tmpStr, "gl_TexCoord[%u]", reg);
|
2006-06-09 09:33:01 +02:00
|
|
|
break;
|
2007-05-03 21:01:09 +02:00
|
|
|
case WINED3DSPR_MISCTYPE:
|
|
|
|
if (reg == 0) {
|
|
|
|
/* vPos */
|
2007-09-14 13:11:00 +02:00
|
|
|
sprintf(tmpStr, "vpos");
|
2007-10-04 08:24:03 +02:00
|
|
|
} else if (reg == 1){
|
|
|
|
/* Note that gl_FrontFacing is a bool, while vFace is
|
|
|
|
* a float for which the sign determines front/back
|
|
|
|
*/
|
|
|
|
sprintf(tmpStr, "(gl_FrontFacing ? 1.0 : -1.0)");
|
2007-05-03 21:01:09 +02:00
|
|
|
} else {
|
|
|
|
FIXME("Unhandled misctype register %d\n", reg);
|
|
|
|
sprintf(tmpStr, "unrecognized_register");
|
|
|
|
}
|
|
|
|
break;
|
2006-06-09 09:33:01 +02:00
|
|
|
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;
|
2006-12-29 15:31:26 +01:00
|
|
|
|
2007-04-12 23:55:31 +02:00
|
|
|
if (shader_is_scalar(param)) {
|
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
|
|
|
}
|
|
|
|
|
2008-01-07 17:17:27 +01:00
|
|
|
static unsigned int shader_glsl_get_write_mask_size(DWORD write_mask) {
|
|
|
|
unsigned int size = 0;
|
2007-01-15 19:31:49 +01:00
|
|
|
|
|
|
|
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-04-12 23:55:31 +02:00
|
|
|
if (!shader_is_scalar(param)) {
|
|
|
|
*ptr++ = '.';
|
|
|
|
/* 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. */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_add_src_param(const SHADER_OPCODE_ARG *arg, const DWORD param,
|
|
|
|
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. */
|
2008-11-25 14:36:09 +01:00
|
|
|
static DWORD shader_glsl_add_dst_param(const SHADER_OPCODE_ARG* arg, const DWORD param,
|
|
|
|
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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static DWORD shader_glsl_append_dst_ext(SHADER_BUFFER *buffer, const SHADER_OPCODE_ARG *arg, const DWORD param)
|
|
|
|
{
|
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;
|
|
|
|
|
2007-03-29 19:57:41 +02:00
|
|
|
mask = shader_glsl_add_dst_param(arg, param, arg->dst_addr, &dst_param);
|
|
|
|
|
|
|
|
if(mask) {
|
|
|
|
shift = (param & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-03-29 19:57:41 +02:00
|
|
|
/* Append the destination part of the instruction to the buffer, return the effective write mask */
|
2008-11-25 14:36:09 +01:00
|
|
|
static DWORD shader_glsl_append_dst(SHADER_BUFFER *buffer, const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2007-03-29 19:57:41 +02:00
|
|
|
return shader_glsl_append_dst_ext(buffer, arg, arg->dst);
|
|
|
|
}
|
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
/** Process GLSL instruction modifiers */
|
2008-11-25 14:36:09 +01:00
|
|
|
void shader_glsl_add_instruction_modifiers(const SHADER_OPCODE_ARG* arg)
|
|
|
|
{
|
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-11-27 22:25:07 +01:00
|
|
|
static void shader_glsl_get_sample_function(DWORD sampler_type, BOOL projected, BOOL texrect, glsl_sample_function_t *sample_function) {
|
2007-01-15 19:33:38 +01:00
|
|
|
/* 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:
|
2007-11-27 22:25:07 +01:00
|
|
|
if(texrect) {
|
|
|
|
sample_function->name = projected ? "texture2DRectProj" : "texture2DRect";
|
|
|
|
} else {
|
|
|
|
sample_function->name = projected ? "texture2DProj" : "texture2D";
|
|
|
|
}
|
2007-01-15 19:33:38 +01:00
|
|
|
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 = "";
|
2008-10-08 17:34:51 +02:00
|
|
|
sample_function->coord_mask = 0;
|
2007-01-15 19:33:38 +01:00
|
|
|
FIXME("Unrecognized sampler type: %#x;\n", sampler_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-03 14:53:43 +01:00
|
|
|
static void shader_glsl_append_fixup_arg(char *arguments, const char *reg_name,
|
|
|
|
BOOL sign_fixup, enum fixup_channel_source channel_source)
|
2008-11-25 14:36:09 +01:00
|
|
|
{
|
2008-12-03 14:53:43 +01:00
|
|
|
switch(channel_source)
|
|
|
|
{
|
|
|
|
case CHANNEL_SOURCE_ZERO:
|
|
|
|
strcat(arguments, "0.0");
|
2007-09-21 23:53:57 +02:00
|
|
|
break;
|
|
|
|
|
2008-12-03 14:53:43 +01:00
|
|
|
case CHANNEL_SOURCE_ONE:
|
|
|
|
strcat(arguments, "1.0");
|
2007-09-21 23:53:57 +02:00
|
|
|
break;
|
|
|
|
|
2008-12-03 14:53:43 +01:00
|
|
|
case CHANNEL_SOURCE_X:
|
|
|
|
strcat(arguments, reg_name);
|
|
|
|
strcat(arguments, ".x");
|
2007-09-21 23:47:40 +02:00
|
|
|
break;
|
2007-09-21 23:34:09 +02:00
|
|
|
|
2008-12-03 14:53:43 +01:00
|
|
|
case CHANNEL_SOURCE_Y:
|
|
|
|
strcat(arguments, reg_name);
|
|
|
|
strcat(arguments, ".y");
|
2007-09-21 23:34:09 +02:00
|
|
|
break;
|
|
|
|
|
2008-12-03 14:53:43 +01:00
|
|
|
case CHANNEL_SOURCE_Z:
|
|
|
|
strcat(arguments, reg_name);
|
|
|
|
strcat(arguments, ".z");
|
2007-09-21 23:34:09 +02:00
|
|
|
break;
|
|
|
|
|
2008-12-03 14:53:43 +01:00
|
|
|
case CHANNEL_SOURCE_W:
|
|
|
|
strcat(arguments, reg_name);
|
|
|
|
strcat(arguments, ".w");
|
2007-09-21 23:34:09 +02:00
|
|
|
break;
|
|
|
|
|
2008-12-03 14:53:43 +01:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled channel source %#x\n", channel_source);
|
|
|
|
strcat(arguments, "undefined");
|
2007-09-21 23:34:09 +02:00
|
|
|
break;
|
2008-12-03 14:53:43 +01:00
|
|
|
}
|
2007-09-21 23:34:09 +02:00
|
|
|
|
2008-12-03 14:53:43 +01:00
|
|
|
if (sign_fixup) strcat(arguments, " * 2.0 - 1.0");
|
|
|
|
}
|
2008-07-23 17:33:10 +02:00
|
|
|
|
2008-12-03 14:53:43 +01:00
|
|
|
static void shader_glsl_color_correction(const struct SHADER_OPCODE_ARG *arg, struct color_fixup_desc fixup)
|
|
|
|
{
|
|
|
|
unsigned int mask_size, remaining;
|
|
|
|
glsl_dst_param_t dst_param;
|
|
|
|
char arguments[256];
|
|
|
|
DWORD mask;
|
|
|
|
BOOL dummy;
|
|
|
|
|
|
|
|
mask = 0;
|
|
|
|
if (fixup.x_sign_fixup || fixup.x_source != CHANNEL_SOURCE_X) mask |= WINED3DSP_WRITEMASK_0;
|
|
|
|
if (fixup.y_sign_fixup || fixup.y_source != CHANNEL_SOURCE_Y) mask |= WINED3DSP_WRITEMASK_1;
|
|
|
|
if (fixup.z_sign_fixup || fixup.z_source != CHANNEL_SOURCE_Z) mask |= WINED3DSP_WRITEMASK_2;
|
|
|
|
if (fixup.w_sign_fixup || fixup.w_source != CHANNEL_SOURCE_W) mask |= WINED3DSP_WRITEMASK_3;
|
|
|
|
mask &= arg->dst;
|
|
|
|
|
|
|
|
if (!mask) return; /* Nothing to do */
|
|
|
|
|
|
|
|
if (is_yuv_fixup(fixup))
|
|
|
|
{
|
|
|
|
enum yuv_fixup yuv_fixup = get_yuv_fixup(fixup);
|
|
|
|
FIXME("YUV fixup (%#x) not supported\n", yuv_fixup);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask_size = shader_glsl_get_write_mask_size(mask);
|
|
|
|
|
|
|
|
dst_param.mask_str[0] = '\0';
|
|
|
|
shader_glsl_get_write_mask(mask, dst_param.mask_str);
|
|
|
|
|
|
|
|
dst_param.reg_name[0] = '\0';
|
|
|
|
shader_glsl_get_register_name(arg->dst, arg->dst_addr, dst_param.reg_name, &dummy, arg);
|
|
|
|
|
|
|
|
arguments[0] = '\0';
|
|
|
|
remaining = mask_size;
|
|
|
|
if (mask & WINED3DSP_WRITEMASK_0)
|
|
|
|
{
|
|
|
|
shader_glsl_append_fixup_arg(arguments, dst_param.reg_name, fixup.x_sign_fixup, fixup.x_source);
|
|
|
|
if (--remaining) strcat(arguments, ", ");
|
|
|
|
}
|
|
|
|
if (mask & WINED3DSP_WRITEMASK_1)
|
|
|
|
{
|
|
|
|
shader_glsl_append_fixup_arg(arguments, dst_param.reg_name, fixup.y_sign_fixup, fixup.y_source);
|
|
|
|
if (--remaining) strcat(arguments, ", ");
|
|
|
|
}
|
|
|
|
if (mask & WINED3DSP_WRITEMASK_2)
|
|
|
|
{
|
|
|
|
shader_glsl_append_fixup_arg(arguments, dst_param.reg_name, fixup.z_sign_fixup, fixup.z_source);
|
|
|
|
if (--remaining) strcat(arguments, ", ");
|
|
|
|
}
|
|
|
|
if (mask & WINED3DSP_WRITEMASK_3)
|
|
|
|
{
|
|
|
|
shader_glsl_append_fixup_arg(arguments, dst_param.reg_name, fixup.w_sign_fixup, fixup.w_source);
|
|
|
|
if (--remaining) strcat(arguments, ", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mask_size > 1)
|
|
|
|
{
|
|
|
|
shader_addline(arg->buffer, "%s%s = vec%u(%s);\n",
|
|
|
|
dst_param.reg_name, dst_param.mask_str, mask_size, arguments);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shader_addline(arg->buffer, "%s%s = %s;\n", dst_param.reg_name, dst_param.mask_str, arguments);
|
2007-09-21 23:34:09 +02:00
|
|
|
}
|
|
|
|
}
|
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) */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_arith(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2006-06-09 09:33:01 +02:00
|
|
|
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) */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_mov(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
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
|
|
|
|
2007-02-14 16:22:07 +01:00
|
|
|
/* In vs_1_1 WINED3DSIO_MOV can write to the address register. In later
|
2007-01-15 19:32:27 +01:00
|
|
|
* shader versions WINED3DSIO_MOVA is used for this. */
|
2008-12-15 12:10:14 +01:00
|
|
|
if ((WINED3DSHADER_VERSION_MAJOR(arg->reg_maps->shader_version) == 1
|
|
|
|
&& !shader_is_pshader_version(arg->reg_maps->shader_version)
|
|
|
|
&& shader_get_regtype(arg->dst) == WINED3DSPR_ADDR))
|
|
|
|
{
|
2007-11-30 16:20:22 +01:00
|
|
|
/* This is a simple floor() */
|
2008-01-07 17:17:27 +01:00
|
|
|
unsigned int mask_size = shader_glsl_get_write_mask_size(write_mask);
|
2007-11-30 16:20:22 +01:00
|
|
|
if (mask_size > 1) {
|
|
|
|
shader_addline(buffer, "ivec%d(floor(%s)));\n", mask_size, src0_param.param_str);
|
|
|
|
} else {
|
|
|
|
shader_addline(buffer, "int(floor(%s)));\n", src0_param.param_str);
|
|
|
|
}
|
|
|
|
} else if(arg->opcode->opcode == WINED3DSIO_MOVA) {
|
2007-01-15 19:32:27 +01:00
|
|
|
/* We need to *round* to the nearest int here. */
|
2008-01-07 17:17:27 +01:00
|
|
|
unsigned int mask_size = shader_glsl_get_write_mask_size(write_mask);
|
2007-01-15 19:32:27 +01:00
|
|
|
if (mask_size > 1) {
|
2007-02-11 08:04:55 +01:00
|
|
|
shader_addline(buffer, "ivec%d(floor(abs(%s) + vec%d(0.5)) * sign(%s)));\n", mask_size, src0_param.param_str, mask_size, src0_param.param_str);
|
2007-01-15 19:32:27 +01:00
|
|
|
} else {
|
2007-02-11 08:04:55 +01:00
|
|
|
shader_addline(buffer, "int(floor(abs(%s) + 0.5) * sign(%s)));\n", src0_param.param_str, 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)) */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_dot(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2006-06-09 09:33:01 +02:00
|
|
|
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;
|
2008-01-07 17:17:27 +01:00
|
|
|
unsigned int 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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_cross(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2007-01-15 19:31:56 +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;
|
|
|
|
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);
|
2007-09-13 12:41:18 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-05-11 12:12:40 +02:00
|
|
|
/* Process the WINED3DSIO_POW instruction in GLSL (dst = |src0|^src1)
|
|
|
|
* Src0 and src1 are scalars. Note that D3D uses the absolute of src0, while
|
|
|
|
* GLSL uses the value as-is. */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_pow(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2007-05-11 12:12:40 +02:00
|
|
|
SHADER_BUFFER *buffer = arg->buffer;
|
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
glsl_src_param_t src1_param;
|
|
|
|
DWORD dst_write_mask;
|
2008-01-07 17:17:27 +01:00
|
|
|
unsigned int dst_size;
|
2007-05-11 12:12:40 +02:00
|
|
|
|
|
|
|
dst_write_mask = shader_glsl_append_dst(buffer, arg);
|
|
|
|
dst_size = shader_glsl_get_write_mask_size(dst_write_mask);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (dst_size > 1) {
|
|
|
|
shader_addline(buffer, "vec%d(pow(abs(%s), %s)));\n", dst_size, src0_param.param_str, src1_param.param_str);
|
|
|
|
} else {
|
|
|
|
shader_addline(buffer, "pow(abs(%s), %s));\n", src0_param.param_str, src1_param.param_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-09 21:24:53 +02:00
|
|
|
/* Process the WINED3DSIO_LOG instruction in GLSL (dst = log2(|src0|))
|
|
|
|
* Src0 is a scalar. Note that D3D uses the absolute of src0, while
|
|
|
|
* GLSL uses the value as-is. */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_log(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2007-09-09 21:24:53 +02:00
|
|
|
SHADER_BUFFER *buffer = arg->buffer;
|
|
|
|
glsl_src_param_t src0_param;
|
|
|
|
DWORD dst_write_mask;
|
2008-01-07 17:17:27 +01:00
|
|
|
unsigned int dst_size;
|
2007-09-09 21:24:53 +02:00
|
|
|
|
|
|
|
dst_write_mask = shader_glsl_append_dst(buffer, arg);
|
|
|
|
dst_size = shader_glsl_get_write_mask_size(dst_write_mask);
|
|
|
|
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param);
|
|
|
|
|
|
|
|
if (dst_size > 1) {
|
|
|
|
shader_addline(buffer, "vec%d(log2(abs(%s))));\n", dst_size, src0_param.param_str);
|
|
|
|
} else {
|
|
|
|
shader_addline(buffer, "log2(abs(%s)));\n", src0_param.param_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
/* Map the opcode 1-to-1 to the GL code (arg->dst = instruction(src0, src1, ...) */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_map2gl(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2006-06-09 09:33:01 +02:00
|
|
|
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_ABS: instruction = "abs"; break;
|
|
|
|
case WINED3DSIO_FRC: instruction = "fract"; break;
|
|
|
|
case WINED3DSIO_NRM: instruction = "normalize"; break;
|
|
|
|
case WINED3DSIO_EXP: instruction = "exp2"; break;
|
|
|
|
case WINED3DSIO_SGN: instruction = "sign"; break;
|
2007-07-03 00:22:18 +02:00
|
|
|
case WINED3DSIO_DSX: instruction = "dFdx"; break;
|
2007-10-13 13:03:56 +02:00
|
|
|
case WINED3DSIO_DSY: instruction = "ycorrection.y * dFdy"; break;
|
2007-01-15 19:32:07 +01:00
|
|
|
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)
|
|
|
|
*/
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_expp(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
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
|
|
|
|
2008-12-15 12:10:14 +01:00
|
|
|
if (arg->reg_maps->shader_version < WINED3DPS_VERSION(2,0))
|
|
|
|
{
|
2007-01-15 19:33:01 +01:00
|
|
|
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;
|
2008-01-07 17:17:27 +01:00
|
|
|
unsigned int mask_size;
|
2007-01-15 19:33:01 +01:00
|
|
|
|
|
|
|
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) */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_rcp(const 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;
|
2008-01-07 17:17:27 +01:00
|
|
|
unsigned int 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-07-02 22:40:06 +02:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_3, &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
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_rsq(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2007-07-02 22:40:06 +02:00
|
|
|
SHADER_BUFFER* buffer = arg->buffer;
|
|
|
|
glsl_src_param_t src_param;
|
|
|
|
DWORD write_mask;
|
2008-01-07 17:17:27 +01:00
|
|
|
unsigned int mask_size;
|
2007-07-02 22:40:06 +02:00
|
|
|
|
|
|
|
write_mask = shader_glsl_append_dst(buffer, arg);
|
|
|
|
mask_size = shader_glsl_get_write_mask_size(write_mask);
|
|
|
|
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_3, &src_param);
|
|
|
|
|
|
|
|
if (mask_size > 1) {
|
|
|
|
shader_addline(buffer, "vec%d(inversesqrt(%s)));\n", mask_size, src_param.param_str);
|
|
|
|
} else {
|
|
|
|
shader_addline(buffer, "inversesqrt(%s));\n", src_param.param_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
/** Process signed comparison opcodes in GLSL. */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_compare(const 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;
|
2008-01-07 17:17:27 +01:00
|
|
|
unsigned int 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
|
|
|
switch(arg->opcode->opcode) {
|
2007-11-05 23:13:00 +01:00
|
|
|
case WINED3DSIO_SLT:
|
2007-11-09 19:53:20 +01:00
|
|
|
/* Step(src0, src1) is not suitable here because if src0 == src1 SLT is supposed,
|
|
|
|
* to return 0.0 but step returns 1.0 because step is not < x
|
2007-12-07 01:03:54 +01:00
|
|
|
* An alternative is a bvec compare padded with an unused second component.
|
2007-11-09 19:53:20 +01:00
|
|
|
* step(src1 * -1.0, src0 * -1.0) is not an option because it suffers from the same
|
|
|
|
* issue. Playing with not() is not possible either because not() does not accept
|
|
|
|
* a scalar.
|
|
|
|
*/
|
|
|
|
shader_addline(arg->buffer, "(%s < %s) ? 1.0 : 0.0);\n", src0_param.param_str, src1_param.param_str);
|
2007-11-05 23:13:00 +01:00
|
|
|
break;
|
|
|
|
case WINED3DSIO_SGE:
|
2007-11-09 19:53:20 +01:00
|
|
|
/* Here we can use the step() function and safe a conditional */
|
2007-11-05 23:13:00 +01:00
|
|
|
shader_addline(arg->buffer, "step(%s, %s));\n", src1_param.param_str, src0_param.param_str);
|
|
|
|
break;
|
|
|
|
default:
|
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
|
|
|
|
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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_cmp(const 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-03-29 19:57:41 +02:00
|
|
|
DWORD write_mask, cmp_channel = 0;
|
|
|
|
unsigned int i, j;
|
2007-09-09 16:54:51 +02:00
|
|
|
char mask_char[6];
|
|
|
|
BOOL temp_destination = FALSE;
|
|
|
|
|
2008-02-11 12:04:57 +01:00
|
|
|
if(shader_is_scalar(arg->src[0])) {
|
|
|
|
write_mask = shader_glsl_append_dst(arg->buffer, arg);
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2008-02-11 12:04:57 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_ALL, &src0_param);
|
2007-03-29 19:57:41 +02: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);
|
2006-06-09 09:33:01 +02:00
|
|
|
|
2008-02-11 12:04:57 +01:00
|
|
|
shader_addline(arg->buffer, "%s >= 0.0 ? %s : %s);\n",
|
|
|
|
src0_param.param_str, src1_param.param_str, src2_param.param_str);
|
|
|
|
} else {
|
|
|
|
DWORD src0reg = arg->src[0] & WINED3DSP_REGNUM_MASK;
|
|
|
|
DWORD src1reg = arg->src[1] & WINED3DSP_REGNUM_MASK;
|
|
|
|
DWORD src2reg = arg->src[2] & WINED3DSP_REGNUM_MASK;
|
|
|
|
DWORD src0regtype = shader_get_regtype(arg->src[0]);
|
|
|
|
DWORD src1regtype = shader_get_regtype(arg->src[1]);
|
|
|
|
DWORD src2regtype = shader_get_regtype(arg->src[2]);
|
|
|
|
DWORD dstreg = arg->dst & WINED3DSP_REGNUM_MASK;
|
|
|
|
DWORD dstregtype = shader_get_regtype(arg->dst);
|
|
|
|
|
|
|
|
/* Cycle through all source0 channels */
|
|
|
|
for (i=0; i<4; i++) {
|
|
|
|
write_mask = 0;
|
|
|
|
/* Find the destination channels which use the current source0 channel */
|
|
|
|
for (j=0; j<4; j++) {
|
|
|
|
if ( ((arg->src[0] >> (WINED3DSP_SWIZZLE_SHIFT + 2*j)) & 0x3) == i ) {
|
|
|
|
write_mask |= WINED3DSP_WRITEMASK_0 << j;
|
|
|
|
cmp_channel = WINED3DSP_WRITEMASK_0 << j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Splitting the cmp instruction up in multiple lines imposes a problem:
|
|
|
|
* The first lines may overwrite source parameters of the following lines.
|
|
|
|
* Deal with that by using a temporary destination register if needed
|
|
|
|
*/
|
|
|
|
if((src0reg == dstreg && src0regtype == dstregtype) ||
|
|
|
|
(src1reg == dstreg && src1regtype == dstregtype) ||
|
|
|
|
(src2reg == dstreg && src2regtype == dstregtype)) {
|
|
|
|
|
|
|
|
write_mask = shader_glsl_get_write_mask(arg->dst & (~WINED3DSP_SWIZZLE_MASK | write_mask), mask_char);
|
|
|
|
if (!write_mask) continue;
|
|
|
|
shader_addline(arg->buffer, "tmp0%s = (", mask_char);
|
|
|
|
temp_destination = TRUE;
|
|
|
|
} else {
|
|
|
|
write_mask = shader_glsl_append_dst_ext(arg->buffer, arg, arg->dst & (~WINED3DSP_SWIZZLE_MASK | write_mask));
|
|
|
|
if (!write_mask) continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], cmp_channel, &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-09-09 16:54:51 +02:00
|
|
|
shader_addline(arg->buffer, "%s >= 0.0 ? %s : %s);\n",
|
2008-02-11 12:04:57 +01:00
|
|
|
src0_param.param_str, src1_param.param_str, src2_param.param_str);
|
|
|
|
}
|
2007-09-09 16:54:51 +02:00
|
|
|
|
2008-02-11 12:04:57 +01:00
|
|
|
if(temp_destination) {
|
|
|
|
shader_glsl_get_write_mask(arg->dst, mask_char);
|
|
|
|
shader_glsl_append_dst_ext(arg->buffer, arg, arg->dst);
|
|
|
|
shader_addline(arg->buffer, "tmp0%s);\n", mask_char);
|
|
|
|
}
|
2007-09-09 16:54:51 +02:00
|
|
|
}
|
|
|
|
|
2006-06-09 09:33:01 +02:00
|
|
|
}
|
|
|
|
|
2007-04-05 00:26:35 +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. */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_cnd(const 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-03-29 19:59:11 +02:00
|
|
|
DWORD write_mask, cmp_channel = 0;
|
|
|
|
unsigned int i, j;
|
2007-01-15 19:32:54 +01:00
|
|
|
|
2008-12-15 12:10:14 +01:00
|
|
|
if (arg->reg_maps->shader_version < WINED3DPS_VERSION(1, 4))
|
|
|
|
{
|
2007-03-29 19:59:11 +02: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-03-29 19:59:11 +02: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-09-13 14:48:57 +02:00
|
|
|
|
|
|
|
/* Fun: The D3DSI_COISSUE flag changes the semantic of the cnd instruction for < 1.4 shaders */
|
|
|
|
if(arg->opcode_token & WINED3DSI_COISSUE) {
|
|
|
|
shader_addline(arg->buffer, "%s /* COISSUE! */);\n", src1_param.param_str);
|
|
|
|
} else {
|
|
|
|
shader_addline(arg->buffer, "%s > 0.5 ? %s : %s);\n",
|
|
|
|
src0_param.param_str, src1_param.param_str, src2_param.param_str);
|
|
|
|
}
|
2007-03-29 19:59:11 +02:00
|
|
|
return;
|
2007-01-15 19:32:54 +01:00
|
|
|
}
|
2007-03-29 19:59:11 +02:00
|
|
|
/* Cycle through all source0 channels */
|
|
|
|
for (i=0; i<4; i++) {
|
|
|
|
write_mask = 0;
|
|
|
|
/* Find the destination channels which use the current source0 channel */
|
|
|
|
for (j=0; j<4; j++) {
|
|
|
|
if ( ((arg->src[0] >> (WINED3DSP_SWIZZLE_SHIFT + 2*j)) & 0x3) == i ) {
|
|
|
|
write_mask |= WINED3DSP_WRITEMASK_0 << j;
|
|
|
|
cmp_channel = WINED3DSP_WRITEMASK_0 << j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
write_mask = shader_glsl_append_dst_ext(arg->buffer, arg, arg->dst & (~WINED3DSP_SWIZZLE_MASK | write_mask));
|
|
|
|
if (!write_mask) continue;
|
2007-01-15 19:32:54 +01:00
|
|
|
|
2007-03-29 19:59:11 +02:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], cmp_channel, &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:54 +01:00
|
|
|
|
2007-04-05 00:26:35 +02:00
|
|
|
shader_addline(arg->buffer, "%s > 0.5 ? %s : %s);\n",
|
2007-01-15 19:37:04 +01:00
|
|
|
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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_mad(const 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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_mnxn(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2008-12-04 17:41:31 +01:00
|
|
|
IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)arg->shader;
|
|
|
|
const SHADER_OPCODE *opcode_table = shader->baseShader.shader_ins;
|
2008-12-15 12:10:14 +01:00
|
|
|
DWORD shader_version = arg->reg_maps->shader_version;
|
2006-06-09 09:33:01 +02:00
|
|
|
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;
|
2008-12-04 17:41:31 +01:00
|
|
|
tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, 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;
|
2008-12-04 17:41:31 +01:00
|
|
|
tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, 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;
|
2008-12-04 17:41:31 +01:00
|
|
|
tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, 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;
|
2008-12-04 17:41:31 +01:00
|
|
|
tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, 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;
|
2008-12-04 17:41:31 +01:00
|
|
|
tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, 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
|
|
|
*/
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_lrp(const 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
|
|
|
|
*/
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_lit(const 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-10-28 21:21:24 +01:00
|
|
|
/* The sdk specifies the instruction like this
|
|
|
|
* dst.x = 1.0;
|
|
|
|
* if(src.x > 0.0) dst.y = src.x
|
|
|
|
* else dst.y = 0.0.
|
|
|
|
* if(src.x > 0.0 && src.y > 0.0) dst.z = pow(src.y, power);
|
|
|
|
* else dst.z = 0.0;
|
|
|
|
* dst.w = 1.0;
|
|
|
|
*
|
|
|
|
* Obviously that has quite a few conditionals in it which we don't like. So the first step is this:
|
|
|
|
* dst.x = 1.0 ... No further explanation needed
|
|
|
|
* dst.y = max(src.y, 0.0); ... If x < 0.0, use 0.0, otherwise x. Same as the conditional
|
|
|
|
* dst.z = x > 0.0 ? pow(max(y, 0.0), p) : 0; ... 0 ^ power is 0, and otherwise we use y anyway
|
|
|
|
* dst.w = 1.0. ... Nothing fancy.
|
|
|
|
*
|
|
|
|
* So we still have one conditional in there. So do this:
|
|
|
|
* dst.z = pow(max(0.0, src.y) * step(0.0, src.x), power);
|
|
|
|
*
|
|
|
|
* step(0.0, x) will return 1 if src.x > 0.0, and 0 otherwise. So if y is 0 we get pow(0.0 * 1.0, power),
|
|
|
|
* which sets dst.z to 0. If y > 0, but x = 0.0, we get pow(y * 0.0, power), which results in 0 too.
|
|
|
|
* if both x and y are > 0, we get pow(y * 1.0, power), as it is supposed to
|
|
|
|
*/
|
|
|
|
shader_addline(arg->buffer, "vec4(1.0, max(%s, 0.0), pow(max(0.0, %s) * step(0.0, %s), clamp(%s, -128.0, 128.0)), 1.0)%s);\n",
|
|
|
|
src0_param.param_str, src1_param.param_str, src0_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
|
|
|
|
*/
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_dst(const 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
|
|
|
|
*/
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_sincos(const 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. */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_loop(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2007-01-15 19:37:04 +01:00
|
|
|
glsl_src_param_t src1_param;
|
2007-09-14 13:21:52 +02:00
|
|
|
IWineD3DBaseShaderImpl* shader = (IWineD3DBaseShaderImpl*) arg->shader;
|
2007-10-28 00:08:56 +02:00
|
|
|
DWORD regtype = shader_get_regtype(arg->src[1]);
|
|
|
|
DWORD reg = arg->src[1] & WINED3DSP_REGNUM_MASK;
|
|
|
|
const DWORD *control_values = NULL;
|
2008-11-25 14:36:09 +01:00
|
|
|
const local_constant *constant;
|
2007-01-15 19:37:04 +01:00
|
|
|
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_ALL, &src1_param);
|
2007-09-14 13:21:52 +02:00
|
|
|
|
2007-10-28 00:08:56 +02:00
|
|
|
/* Try to hardcode the loop control parameters if possible. Direct3D 9 class hardware doesn't support real
|
|
|
|
* varying indexing, but Microsoft designed this feature for Shader model 2.x+. If the loop control is
|
|
|
|
* known at compile time, the GLSL compiler can unroll the loop, and replace indirect addressing with direct
|
|
|
|
* addressing.
|
|
|
|
*/
|
|
|
|
if(regtype == WINED3DSPR_CONSTINT) {
|
|
|
|
LIST_FOR_EACH_ENTRY(constant, &shader->baseShader.constantsI, local_constant, entry) {
|
|
|
|
if(constant->idx == reg) {
|
|
|
|
control_values = constant->value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(control_values) {
|
|
|
|
if(control_values[2] > 0) {
|
|
|
|
shader_addline(arg->buffer, "for (aL%u = %d; aL%u < (%d * %d + %d); aL%u += %d) {\n",
|
|
|
|
shader->baseShader.cur_loop_depth, control_values[1],
|
|
|
|
shader->baseShader.cur_loop_depth, control_values[0], control_values[2], control_values[1],
|
|
|
|
shader->baseShader.cur_loop_depth, control_values[2]);
|
|
|
|
} else if(control_values[2] == 0) {
|
|
|
|
shader_addline(arg->buffer, "for (aL%u = %d, tmpInt%u = 0; tmpInt%u < %d; tmpInt%u++) {\n",
|
|
|
|
shader->baseShader.cur_loop_depth, control_values[1], shader->baseShader.cur_loop_depth,
|
|
|
|
shader->baseShader.cur_loop_depth, control_values[0],
|
|
|
|
shader->baseShader.cur_loop_depth);
|
|
|
|
} else {
|
|
|
|
shader_addline(arg->buffer, "for (aL%u = %d; aL%u > (%d * %d + %d); aL%u += %d) {\n",
|
|
|
|
shader->baseShader.cur_loop_depth, control_values[1],
|
|
|
|
shader->baseShader.cur_loop_depth, control_values[0], control_values[2], control_values[1],
|
|
|
|
shader->baseShader.cur_loop_depth, control_values[2]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
shader_addline(arg->buffer, "for (tmpInt%u = 0, aL%u = %s.y; tmpInt%u < %s.x; tmpInt%u++, aL%u += %s.z) {\n",
|
|
|
|
shader->baseShader.cur_loop_depth, shader->baseShader.cur_loop_regno,
|
|
|
|
src1_param.reg_name, shader->baseShader.cur_loop_depth, src1_param.reg_name,
|
|
|
|
shader->baseShader.cur_loop_depth, shader->baseShader.cur_loop_regno, src1_param.reg_name);
|
|
|
|
}
|
2007-09-14 13:21:52 +02:00
|
|
|
|
|
|
|
shader->baseShader.cur_loop_depth++;
|
|
|
|
shader->baseShader.cur_loop_regno++;
|
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
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_end(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2007-09-14 13:21:52 +02:00
|
|
|
IWineD3DBaseShaderImpl* shader = (IWineD3DBaseShaderImpl*) arg->shader;
|
|
|
|
|
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, "}\n");
|
2007-09-14 13:21:52 +02:00
|
|
|
|
|
|
|
if(arg->opcode->opcode == WINED3DSIO_ENDLOOP) {
|
|
|
|
shader->baseShader.cur_loop_depth--;
|
|
|
|
shader->baseShader.cur_loop_regno--;
|
|
|
|
}
|
|
|
|
if(arg->opcode->opcode == WINED3DSIO_ENDREP) {
|
|
|
|
shader->baseShader.cur_loop_depth--;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_rep(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2007-09-14 13:21:52 +02:00
|
|
|
IWineD3DBaseShaderImpl* shader = (IWineD3DBaseShaderImpl*) arg->shader;
|
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);
|
2007-09-14 13:21:52 +02:00
|
|
|
shader_addline(arg->buffer, "for (tmpInt%d = 0; tmpInt%d < %s; tmpInt%d++) {\n",
|
|
|
|
shader->baseShader.cur_loop_depth, shader->baseShader.cur_loop_depth,
|
|
|
|
src0_param.param_str, shader->baseShader.cur_loop_depth);
|
|
|
|
shader->baseShader.cur_loop_depth++;
|
2006-06-14 04:32:14 +02:00
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_if(const 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
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_ifc(const 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
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_else(const 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
|
|
|
shader_addline(arg->buffer, "} else {\n");
|
2006-06-14 04:32:14 +02:00
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_break(const 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
|
|
|
shader_addline(arg->buffer, "break;\n");
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:36:29 +01:00
|
|
|
/* FIXME: According to MSDN the compare is done per component. */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_breakc(const 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
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_label(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2006-07-10 12:35:15 +02:00
|
|
|
|
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");
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(arg->buffer, "void subroutine%u () {\n", snum);
|
2006-07-10 12:35:15 +02:00
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_call(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2006-10-10 01:47:12 +02:00
|
|
|
DWORD snum = (arg->src[0]) & WINED3DSP_REGNUM_MASK;
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(arg->buffer, "subroutine%u();\n", snum);
|
2006-07-10 12:35:15 +02:00
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_callnz(const 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);
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(arg->buffer, "if (%s) subroutine%u();\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
|
|
|
|
********************************************/
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_tex(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2006-06-09 09:33:01 +02:00
|
|
|
IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
|
2007-09-21 23:34:09 +02:00
|
|
|
IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
|
2008-12-15 12:10:14 +01:00
|
|
|
DWORD shader_version = arg->reg_maps->shader_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;
|
2007-11-27 22:25:07 +01:00
|
|
|
BOOL projected, texrect = FALSE;
|
2007-01-15 19:36:40 +01:00
|
|
|
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. */
|
2008-12-15 12:10:14 +01:00
|
|
|
if (shader_version < WINED3DPS_VERSION(2,0)) sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
|
|
|
|
else sampler_idx = arg->src[1] & WINED3DSP_REGNUM_MASK;
|
2008-10-28 21:25:06 +01:00
|
|
|
sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK;
|
2007-01-15 19:36:40 +01:00
|
|
|
|
2008-12-15 12:10:14 +01:00
|
|
|
if (shader_version < WINED3DPS_VERSION(1,4))
|
|
|
|
{
|
2008-10-28 21:25:06 +01:00
|
|
|
DWORD flags = deviceImpl->stateBlock->textureState[sampler_idx][WINED3DTSS_TEXTURETRANSFORMFLAGS];
|
|
|
|
|
|
|
|
/* Projected cube textures don't make a lot of sense, the resulting coordinates stay the same. */
|
|
|
|
if (flags & WINED3DTTFF_PROJECTED && sampler_type != WINED3DSTT_CUBE) {
|
2007-01-15 19:36:40 +01:00
|
|
|
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;
|
|
|
|
}
|
2008-12-15 12:10:14 +01:00
|
|
|
}
|
|
|
|
else if (shader_version < WINED3DPS_VERSION(2,0))
|
|
|
|
{
|
2007-01-15 19:36:40 +01:00
|
|
|
DWORD src_mod = arg->src[0] & WINED3DSP_SRCMOD_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 {
|
2007-03-29 18:44:57 +02:00
|
|
|
if(arg->opcode_token & WINED3DSI_TEXLD_PROJECT) {
|
|
|
|
/* ps 2.0 texldp instruction always divides by the fourth component. */
|
|
|
|
projected = TRUE;
|
|
|
|
mask = WINED3DSP_WRITEMASK_3;
|
|
|
|
} else {
|
|
|
|
projected = FALSE;
|
|
|
|
}
|
2007-01-15 19:36:40 +01:00
|
|
|
}
|
|
|
|
|
2007-11-27 22:25:07 +01:00
|
|
|
if(deviceImpl->stateBlock->textures[sampler_idx] &&
|
|
|
|
IWineD3DBaseTexture_GetTextureDimensions(deviceImpl->stateBlock->textures[sampler_idx]) == GL_TEXTURE_RECTANGLE_ARB) {
|
|
|
|
texrect = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
shader_glsl_get_sample_function(sampler_type, projected, texrect, &sample_function);
|
2007-01-15 19:36:40 +01:00
|
|
|
mask |= sample_function.coord_mask;
|
|
|
|
|
2008-12-15 12:10:14 +01:00
|
|
|
if (shader_version < WINED3DPS_VERSION(2,0)) shader_glsl_get_write_mask(arg->dst, dst_swizzle);
|
|
|
|
else shader_glsl_get_swizzle(arg->src[1], FALSE, arg->dst, dst_swizzle);
|
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. */
|
2008-12-15 12:10:14 +01:00
|
|
|
if (shader_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-08-30 22:59:14 +02:00
|
|
|
if(arg->opcode_token & WINED3DSI_TEXLD_BIAS) {
|
|
|
|
glsl_src_param_t bias;
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_3, &bias);
|
|
|
|
|
|
|
|
shader_addline(arg->buffer, "%s(Psampler%u, %s, %s)%s);\n",
|
|
|
|
sample_function.name, sampler_idx, coord_param.param_str,
|
|
|
|
bias.param_str, dst_swizzle);
|
|
|
|
} else {
|
|
|
|
shader_addline(arg->buffer, "%s(Psampler%u, %s)%s);\n",
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_texldl(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2007-06-27 23:46:53 +02:00
|
|
|
IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*)arg->shader;
|
2007-11-27 22:25:07 +01:00
|
|
|
IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
|
2007-06-27 23:46:53 +02:00
|
|
|
glsl_sample_function_t sample_function;
|
|
|
|
glsl_src_param_t coord_param, lod_param;
|
|
|
|
char dst_swizzle[6];
|
|
|
|
DWORD sampler_type;
|
|
|
|
DWORD sampler_idx;
|
2007-11-27 22:25:07 +01:00
|
|
|
BOOL texrect = FALSE;
|
2007-06-27 23:46:53 +02:00
|
|
|
|
|
|
|
shader_glsl_append_dst(arg->buffer, arg);
|
|
|
|
shader_glsl_get_swizzle(arg->src[1], FALSE, arg->dst, dst_swizzle);
|
|
|
|
|
|
|
|
sampler_idx = arg->src[1] & WINED3DSP_REGNUM_MASK;
|
|
|
|
sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK;
|
2007-11-27 22:25:07 +01:00
|
|
|
if(deviceImpl->stateBlock->textures[sampler_idx] &&
|
|
|
|
IWineD3DBaseTexture_GetTextureDimensions(deviceImpl->stateBlock->textures[sampler_idx]) == GL_TEXTURE_RECTANGLE_ARB) {
|
|
|
|
texrect = TRUE;
|
|
|
|
}
|
|
|
|
shader_glsl_get_sample_function(sampler_type, FALSE, texrect, &sample_function); shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], sample_function.coord_mask, &coord_param);
|
2007-06-27 23:46:53 +02:00
|
|
|
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_3, &lod_param);
|
|
|
|
|
2008-12-15 12:10:14 +01:00
|
|
|
if (shader_is_pshader_version(arg->reg_maps->shader_version))
|
|
|
|
{
|
2007-06-27 23:46:53 +02:00
|
|
|
/* The GLSL spec claims the Lod sampling functions are only supported in vertex shaders.
|
|
|
|
* However, they seem to work just fine in fragment shaders as well. */
|
|
|
|
WARN("Using %sLod in fragment shader.\n", sample_function.name);
|
|
|
|
shader_addline(arg->buffer, "%sLod(Psampler%u, %s, %s)%s);\n",
|
|
|
|
sample_function.name, sampler_idx, coord_param.param_str, lod_param.param_str, dst_swizzle);
|
|
|
|
} else {
|
|
|
|
shader_addline(arg->buffer, "%sLod(Vsampler%u, %s, %s)%s);\n",
|
|
|
|
sample_function.name, sampler_idx, coord_param.param_str, lod_param.param_str, dst_swizzle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texcoord(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2006-06-09 09:33:01 +02:00
|
|
|
/* FIXME: Make this work for more than just 2D textures */
|
|
|
|
SHADER_BUFFER* buffer = arg->buffer;
|
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
|
|
|
|
2008-12-15 12:10:14 +01:00
|
|
|
if (arg->reg_maps->shader_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;
|
2008-01-07 17:17:27 +01:00
|
|
|
unsigned int 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;
|
2008-01-07 17:17:27 +01:00
|
|
|
unsigned int 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. */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texdp3tex(const 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];
|
2007-09-13 12:25:29 +02:00
|
|
|
glsl_sample_function_t sample_function;
|
2007-01-15 19:34:18 +01:00
|
|
|
DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
|
|
|
|
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
|
2007-09-13 12:25:29 +02:00
|
|
|
DWORD sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK;
|
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);
|
2007-09-13 12:25:29 +02:00
|
|
|
|
|
|
|
/* Do I have to take care about the projected bit? I don't think so, since the dp3 returns only one
|
2007-11-27 22:25:07 +01:00
|
|
|
* scalar, and projected sampling would require 4.
|
|
|
|
*
|
|
|
|
* It is a dependent read - not valid with conditional NP2 textures
|
2007-09-13 12:25:29 +02:00
|
|
|
*/
|
2007-11-27 22:25:07 +01:00
|
|
|
shader_glsl_get_sample_function(sampler_type, FALSE, FALSE, &sample_function);
|
2007-09-13 12:25:29 +02:00
|
|
|
|
|
|
|
switch(count_bits(sample_function.coord_mask)) {
|
|
|
|
case 1:
|
|
|
|
shader_addline(arg->buffer, "%s(Psampler%u, dot(gl_TexCoord[%u].xyz, %s))%s);\n",
|
|
|
|
sample_function.name, sampler_idx, sampler_idx, src0_param.param_str, dst_mask);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
shader_addline(arg->buffer, "%s(Psampler%u, vec2(dot(gl_TexCoord[%u].xyz, %s), 0.0))%s);\n",
|
|
|
|
sample_function.name, sampler_idx, sampler_idx, src0_param.param_str, dst_mask);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
shader_addline(arg->buffer, "%s(Psampler%u, vec3(dot(gl_TexCoord[%u].xyz, %s), 0.0, 0.0))%s);\n",
|
|
|
|
sample_function.name, sampler_idx, sampler_idx, src0_param.param_str, dst_mask);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unexpected mask bitcount %d\n", count_bits(sample_function.coord_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. */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texdp3(const 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;
|
2008-01-07 17:17:27 +01:00
|
|
|
unsigned int 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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texdepth(const 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-08-31 17:00:16 +02:00
|
|
|
/* Tests show that texdepth never returns anything below 0.0, and that r5.y is clamped to 1.0.
|
|
|
|
* Negative input is accepted, -0.25 / -0.5 returns 0.5. GL should clamp gl_FragDepth to [0;1], but
|
2007-09-27 18:57:51 +02:00
|
|
|
* this doesn't always work, so clamp the results manually. Whether or not the x value is clamped at 1
|
|
|
|
* too is irrelevant, since if x = 0, any y value < 1.0 (and > 1.0 is not allowed) results in a result
|
2007-08-31 17:00:16 +02:00
|
|
|
* >= 1.0 or < 0.0
|
|
|
|
*/
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(arg->buffer, "gl_FragDepth = clamp((%s.x / min(%s.y, 1.0)), 0.0, 1.0);\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
|
|
|
|
*/
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texm3x2depth(const 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. */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texm3x2pad(const 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. */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texm3x3pad(const SHADER_OPCODE_ARG* arg)
|
|
|
|
{
|
2006-06-27 08:00:02 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texm3x2tex(const 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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texm3x3tex(const 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);
|
2007-11-27 22:25:07 +01:00
|
|
|
/* Dependent read, not valid with conditional NP2 */
|
|
|
|
shader_glsl_get_sample_function(sampler_type, FALSE, 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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texm3x3(const 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-08-28 11:54:44 +02:00
|
|
|
shader_addline(arg->buffer, "vec4(tmp0.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
|
2008-10-20 17:56:58 +02:00
|
|
|
* Perform the final texture lookup based on the previous 2 3x3 matrix multiplies */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texm3x3spec(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2006-07-25 04:52:38 +02:00
|
|
|
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-09-12 23:46:47 +02:00
|
|
|
/* Reflection calculation */
|
|
|
|
shader_addline(buffer, "tmp0.xyz = -reflect((%s), normalize(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);
|
2007-11-27 22:25:07 +01:00
|
|
|
/* Dependent read, not valid with conditional NP2 */
|
|
|
|
shader_glsl_get_sample_function(stype, FALSE, 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
|
2008-10-20 17:56:58 +02:00
|
|
|
* Perform the final texture lookup based on the previous 2 3x3 matrix multiplies */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texm3x3vspec(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2006-06-27 08:00:02 +02:00
|
|
|
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);
|
2007-09-12 23:46:47 +02:00
|
|
|
shader_addline(buffer, "tmp0.xyz = -reflect(tmp1.xyz, normalize(tmp0.xyz));\n");
|
2007-01-15 19:35:48 +01:00
|
|
|
|
|
|
|
shader_glsl_append_dst(buffer, arg);
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_mask);
|
2007-11-27 22:25:07 +01:00
|
|
|
/* Dependent read, not valid with conditional NP2 */
|
|
|
|
shader_glsl_get_sample_function(sampler_type, FALSE, 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.
|
2007-02-15 03:00:57 +01:00
|
|
|
* texbem is pshader <= 1.3 only, this saves a few version checks
|
|
|
|
*/
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texbem(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2007-02-15 03:00:57 +01:00
|
|
|
IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
|
|
|
|
IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
|
|
|
|
char dst_swizzle[6];
|
|
|
|
glsl_sample_function_t sample_function;
|
2007-03-22 17:42:03 +01:00
|
|
|
glsl_src_param_t coord_param;
|
2007-02-15 03:00:57 +01:00
|
|
|
DWORD sampler_type;
|
|
|
|
DWORD sampler_idx;
|
2007-03-22 17:42:41 +01:00
|
|
|
DWORD mask;
|
2007-02-15 03:00:57 +01:00
|
|
|
DWORD flags;
|
|
|
|
char coord_mask[6];
|
|
|
|
|
|
|
|
sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
|
|
|
|
flags = deviceImpl->stateBlock->textureState[sampler_idx][WINED3DTSS_TEXTURETRANSFORMFLAGS];
|
|
|
|
|
2007-03-22 17:42:41 +01:00
|
|
|
sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK;
|
2007-11-27 22:25:07 +01:00
|
|
|
/* Dependent read, not valid with conditional NP2 */
|
|
|
|
shader_glsl_get_sample_function(sampler_type, FALSE, FALSE, &sample_function);
|
2007-03-22 17:42:41 +01:00
|
|
|
mask = sample_function.coord_mask;
|
|
|
|
|
|
|
|
shader_glsl_get_write_mask(arg->dst, dst_swizzle);
|
|
|
|
|
|
|
|
shader_glsl_get_write_mask(mask, coord_mask);
|
|
|
|
|
|
|
|
/* with projective textures, texbem only divides the static texture coord, not the displacement,
|
|
|
|
* so we can't let the GL handle this.
|
|
|
|
*/
|
2007-02-15 03:00:57 +01:00
|
|
|
if (flags & WINED3DTTFF_PROJECTED) {
|
2007-03-22 17:42:41 +01:00
|
|
|
DWORD div_mask=0;
|
|
|
|
char coord_div_mask[3];
|
2007-02-15 03:00:57 +01:00
|
|
|
switch (flags & ~WINED3DTTFF_PROJECTED) {
|
|
|
|
case WINED3DTTFF_COUNT1: FIXME("WINED3DTTFF_PROJECTED with WINED3DTTFF_COUNT1?\n"); break;
|
2007-03-22 17:42:41 +01:00
|
|
|
case WINED3DTTFF_COUNT2: div_mask = WINED3DSP_WRITEMASK_1; break;
|
|
|
|
case WINED3DTTFF_COUNT3: div_mask = WINED3DSP_WRITEMASK_2; break;
|
2007-02-15 03:00:57 +01:00
|
|
|
case WINED3DTTFF_COUNT4:
|
2007-03-22 17:42:41 +01:00
|
|
|
case WINED3DTTFF_DISABLE: div_mask = WINED3DSP_WRITEMASK_3; break;
|
2007-02-15 03:00:57 +01:00
|
|
|
}
|
2007-03-22 17:42:41 +01:00
|
|
|
shader_glsl_get_write_mask(div_mask, coord_div_mask);
|
|
|
|
shader_addline(arg->buffer, "T%u%s /= T%u%s;\n", sampler_idx, coord_mask, sampler_idx, coord_div_mask);
|
2007-02-15 03:00:57 +01:00
|
|
|
}
|
|
|
|
|
2007-03-22 17:42:41 +01:00
|
|
|
shader_glsl_append_dst(arg->buffer, arg);
|
2007-03-22 17:42:03 +01:00
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0|WINED3DSP_WRITEMASK_1, &coord_param);
|
2007-09-01 20:11:17 +02:00
|
|
|
if(arg->opcode->opcode == WINED3DSIO_TEXBEML) {
|
|
|
|
glsl_src_param_t luminance_param;
|
|
|
|
shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_2, &luminance_param);
|
2008-03-05 03:18:55 +01:00
|
|
|
shader_addline(arg->buffer, "(%s(Psampler%u, T%u%s + vec4(bumpenvmat%d * %s, 0.0, 0.0)%s )*(%s * luminancescale%d + luminanceoffset%d))%s);\n",
|
|
|
|
sample_function.name, sampler_idx, sampler_idx, coord_mask, sampler_idx, coord_param.param_str, coord_mask,
|
|
|
|
luminance_param.param_str, sampler_idx, sampler_idx, dst_swizzle);
|
2007-09-01 20:11:17 +02:00
|
|
|
} else {
|
2008-03-05 03:18:55 +01:00
|
|
|
shader_addline(arg->buffer, "%s(Psampler%u, T%u%s + vec4(bumpenvmat%d * %s, 0.0, 0.0)%s )%s);\n",
|
|
|
|
sample_function.name, sampler_idx, sampler_idx, coord_mask, sampler_idx, coord_param.param_str, coord_mask, dst_swizzle);
|
2007-09-01 20:11:17 +02:00
|
|
|
}
|
2006-06-27 08:00:02 +02:00
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_bem(const SHADER_OPCODE_ARG *arg)
|
|
|
|
{
|
2007-03-26 23:34:32 +02:00
|
|
|
glsl_src_param_t src0_param, src1_param;
|
2008-03-05 03:18:55 +01:00
|
|
|
DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
|
2007-03-26 23:34:32 +02: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_append_dst(arg->buffer, arg);
|
2008-03-05 03:18:55 +01:00
|
|
|
shader_addline(arg->buffer, "%s + bumpenvmat%d * %s);\n",
|
|
|
|
src0_param.param_str, sampler_idx, src1_param.param_str);
|
2007-03-26 23:34:32 +02:00
|
|
|
}
|
|
|
|
|
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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texreg2ar(const 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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texreg2gb(const 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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texreg2rgb(const 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);
|
2007-11-27 22:25:07 +01:00
|
|
|
/* Dependent read, not valid with conditional NP2 */
|
|
|
|
shader_glsl_get_sample_function(sampler_type, FALSE, 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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_texkill(const 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-08-30 23:35:50 +02:00
|
|
|
/* The argument is a destination parameter, and no writemasks are allowed */
|
2007-01-15 19:36:58 +01:00
|
|
|
shader_glsl_add_dst_param(arg, arg->dst, 0, &dst_param);
|
2008-12-15 12:10:14 +01:00
|
|
|
if ((arg->reg_maps->shader_version >= WINED3DPS_VERSION(2,0)))
|
|
|
|
{
|
2007-08-30 23:35:50 +02:00
|
|
|
/* 2.0 shaders compare all 4 components in texkill */
|
|
|
|
shader_addline(arg->buffer, "if (any(lessThan(%s.xyzw, vec4(0.0)))) discard;\n", dst_param.reg_name);
|
|
|
|
} else {
|
2007-11-09 12:37:53 +01:00
|
|
|
/* 1.X shaders only compare the first 3 components, probably due to the nature of the texkill
|
2007-08-30 23:35:50 +02:00
|
|
|
* instruction as a tex* instruction, and phase, which kills all a / w components. Even if all
|
|
|
|
* 4 components are defined, only the first 3 are used
|
|
|
|
*/
|
|
|
|
shader_addline(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 */
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_dp2add(const 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;
|
2008-01-07 17:17:27 +01:00
|
|
|
unsigned int 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
|
|
|
|
2008-04-23 22:18:32 +02:00
|
|
|
if (mask_size > 1) {
|
|
|
|
shader_addline(arg->buffer, "vec%d(dot(%s, %s) + %s));\n", mask_size, src0_param.param_str, src1_param.param_str, src2_param.param_str);
|
|
|
|
} else {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void pshader_glsl_input_pack(SHADER_BUFFER* buffer, const struct semantic* semantics_in,
|
|
|
|
IWineD3DPixelShader *iface, enum vertexprocessing_mode vertexprocessing)
|
|
|
|
{
|
2006-06-12 08:57:07 +02:00
|
|
|
unsigned int i;
|
2007-10-26 02:11:00 +02:00
|
|
|
IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *) iface;
|
2006-06-12 08:57:07 +02:00
|
|
|
|
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) {
|
|
|
|
|
2007-10-26 02:11:00 +02:00
|
|
|
case WINED3DDECLUSAGE_TEXCOORD:
|
2008-11-24 11:55:50 +01:00
|
|
|
if(usage_idx < 8 && vertexprocessing == pretransformed) {
|
2007-10-26 02:11:00 +02:00
|
|
|
shader_addline(buffer, "IN[%u]%s = gl_TexCoord[%u]%s;\n",
|
2007-10-28 00:12:37 +02:00
|
|
|
This->input_reg_map[i], reg_mask, usage_idx, reg_mask);
|
2007-10-26 02:11:00 +02:00
|
|
|
} else {
|
|
|
|
shader_addline(buffer, "IN[%u]%s = vec4(0.0, 0.0, 0.0, 0.0)%s;\n",
|
2007-10-28 00:12:37 +02:00
|
|
|
This->input_reg_map[i], reg_mask, reg_mask);
|
2007-10-26 02:11:00 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-02-13 23:12:14 +01:00
|
|
|
case WINED3DDECLUSAGE_COLOR:
|
2006-07-07 08:27:38 +02:00
|
|
|
if (usage_idx == 0)
|
2007-10-18 14:45:32 +02:00
|
|
|
shader_addline(buffer, "IN[%u]%s = vec4(gl_Color)%s;\n",
|
2007-10-28 00:12:37 +02:00
|
|
|
This->input_reg_map[i], reg_mask, reg_mask);
|
2006-07-07 19:01:27 +02:00
|
|
|
else if (usage_idx == 1)
|
2007-10-18 14:45:32 +02:00
|
|
|
shader_addline(buffer, "IN[%u]%s = vec4(gl_SecondaryColor)%s;\n",
|
2007-10-28 00:12:37 +02:00
|
|
|
This->input_reg_map[i], reg_mask, reg_mask);
|
2006-07-07 08:27:38 +02:00
|
|
|
else
|
2007-10-26 02:11:00 +02:00
|
|
|
shader_addline(buffer, "IN[%u]%s = vec4(0.0, 0.0, 0.0, 0.0)%s;\n",
|
2007-10-28 00:12:37 +02:00
|
|
|
This->input_reg_map[i], reg_mask, reg_mask);
|
2006-06-12 08:57:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-10-26 02:11:00 +02:00
|
|
|
shader_addline(buffer, "IN[%u]%s = vec4(0.0, 0.0, 0.0, 0.0)%s;\n",
|
2007-10-28 00:12:37 +02:00
|
|
|
This->input_reg_map[i], reg_mask, reg_mask);
|
2006-06-12 08:57:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************
|
|
|
|
* Vertex Shader Specific Code begins here
|
|
|
|
********************************************/
|
|
|
|
|
2008-07-08 21:44:20 +02:00
|
|
|
static void add_glsl_program_entry(struct shader_glsl_priv *priv, struct glsl_shader_prog_link *entry) {
|
2007-02-27 20:51:53 +01:00
|
|
|
glsl_program_key_t *key;
|
|
|
|
|
|
|
|
key = HeapAlloc(GetProcessHeap(), 0, sizeof(glsl_program_key_t));
|
|
|
|
key->vshader = entry->vshader;
|
|
|
|
key->pshader = entry->pshader;
|
2009-02-05 19:44:32 +01:00
|
|
|
key->vs_args = entry->vs_args;
|
2008-11-21 19:48:36 +01:00
|
|
|
key->ps_args = entry->ps_args;
|
2007-02-27 20:51:53 +01:00
|
|
|
|
2008-07-08 21:44:20 +02:00
|
|
|
hash_table_put(priv->glsl_program_lookup, key, entry);
|
2007-02-27 20:51:53 +01:00
|
|
|
}
|
|
|
|
|
2008-07-08 21:44:20 +02:00
|
|
|
static struct glsl_shader_prog_link *get_glsl_program_entry(struct shader_glsl_priv *priv,
|
2009-02-05 19:44:32 +01:00
|
|
|
IWineD3DVertexShader *vshader, IWineD3DPixelShader *pshader, struct vs_compile_args *vs_args,
|
|
|
|
struct ps_compile_args *ps_args) {
|
2007-02-27 20:51:53 +01:00
|
|
|
glsl_program_key_t key;
|
|
|
|
|
|
|
|
key.vshader = vshader;
|
|
|
|
key.pshader = pshader;
|
2009-02-05 19:44:32 +01:00
|
|
|
key.vs_args = *vs_args;
|
2008-11-21 19:48:36 +01:00
|
|
|
key.ps_args = *ps_args;
|
2007-02-27 20:51:53 +01:00
|
|
|
|
2009-02-03 09:36:07 +01:00
|
|
|
return hash_table_get(priv->glsl_program_lookup, &key);
|
2007-02-27 20:51:53 +01:00
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void delete_glsl_program_entry(struct shader_glsl_priv *priv, const WineD3D_GL_Info *gl_info,
|
|
|
|
struct glsl_shader_prog_link *entry)
|
|
|
|
{
|
2007-02-27 20:51:53 +01:00
|
|
|
glsl_program_key_t *key;
|
|
|
|
|
|
|
|
key = HeapAlloc(GetProcessHeap(), 0, sizeof(glsl_program_key_t));
|
|
|
|
key->vshader = entry->vshader;
|
|
|
|
key->pshader = entry->pshader;
|
2009-02-05 19:44:32 +01:00
|
|
|
key->vs_args = entry->vs_args;
|
2008-11-21 19:48:36 +01:00
|
|
|
key->ps_args = entry->ps_args;
|
2008-07-08 21:44:20 +02:00
|
|
|
hash_table_remove(priv->glsl_program_lookup, key);
|
2007-02-27 20:51:53 +01:00
|
|
|
|
|
|
|
GL_EXTCALL(glDeleteObjectARB(entry->programId));
|
|
|
|
if (entry->vshader) list_remove(&entry->vshader_entry);
|
|
|
|
if (entry->pshader) list_remove(&entry->pshader_entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry->vuniformF_locations);
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry->puniformF_locations);
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
2006-12-28 03:13:24 +01:00
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void handle_ps3_input(SHADER_BUFFER *buffer, const struct semantic *semantics_in,
|
|
|
|
const struct semantic *semantics_out, const WineD3D_GL_Info *gl_info, const DWORD *map)
|
|
|
|
{
|
2007-10-26 02:11:00 +02:00
|
|
|
unsigned int i, j;
|
|
|
|
DWORD usage_token, usage_token_out;
|
|
|
|
DWORD register_token, register_token_out;
|
|
|
|
DWORD usage, usage_idx, usage_out, usage_idx_out;
|
|
|
|
DWORD *set;
|
2008-06-19 00:36:35 +02:00
|
|
|
DWORD in_idx;
|
|
|
|
DWORD in_count = GL_LIMITS(glsl_varyings) / 4;
|
2007-10-26 02:11:00 +02:00
|
|
|
char reg_mask[6], reg_mask_out[6];
|
2008-06-19 00:36:35 +02:00
|
|
|
char destination[50];
|
|
|
|
|
|
|
|
set = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*set) * (in_count + 2));
|
2007-10-26 02:11:00 +02:00
|
|
|
|
2008-06-19 00:36:35 +02:00
|
|
|
if (!semantics_out) {
|
|
|
|
/* Save gl_FrontColor & gl_FrontSecondaryColor before overwriting them. */
|
2008-06-26 14:08:59 +02:00
|
|
|
shader_addline(buffer, "vec4 front_color = gl_FrontColor;\n");
|
|
|
|
shader_addline(buffer, "vec4 front_secondary_color = gl_FrontSecondaryColor;\n");
|
2008-06-19 00:36:35 +02:00
|
|
|
}
|
2007-10-26 02:11:00 +02:00
|
|
|
|
2007-10-28 00:12:37 +02:00
|
|
|
for(i = 0; i < MAX_REG_INPUT; i++) {
|
2007-10-26 02:11:00 +02:00
|
|
|
usage_token = semantics_in[i].usage;
|
|
|
|
if (!usage_token) continue;
|
2008-06-19 00:36:35 +02:00
|
|
|
|
|
|
|
in_idx = map[i];
|
|
|
|
if (in_idx >= (in_count + 2)) {
|
2007-10-28 00:12:37 +02:00
|
|
|
FIXME("More input varyings declared than supported, expect issues\n");
|
|
|
|
continue;
|
2007-11-06 12:34:22 +01:00
|
|
|
} else if(map[i] == -1) {
|
|
|
|
/* Declared, but not read register */
|
|
|
|
continue;
|
2007-10-28 00:12:37 +02:00
|
|
|
}
|
2008-06-19 00:36:35 +02:00
|
|
|
|
|
|
|
if (in_idx == in_count) {
|
|
|
|
sprintf(destination, "gl_FrontColor");
|
|
|
|
} else if (in_idx == in_count + 1) {
|
|
|
|
sprintf(destination, "gl_FrontSecondaryColor");
|
|
|
|
} else {
|
|
|
|
sprintf(destination, "IN[%u]", in_idx);
|
|
|
|
}
|
|
|
|
|
2007-10-26 02:11:00 +02:00
|
|
|
register_token = semantics_in[i].reg;
|
|
|
|
|
|
|
|
usage = (usage_token & WINED3DSP_DCL_USAGE_MASK) >> WINED3DSP_DCL_USAGE_SHIFT;
|
|
|
|
usage_idx = (usage_token & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
|
2007-10-28 00:12:37 +02:00
|
|
|
set[map[i]] = shader_glsl_get_write_mask(register_token, reg_mask);
|
2007-10-26 02:11:00 +02:00
|
|
|
|
|
|
|
if(!semantics_out) {
|
|
|
|
switch(usage) {
|
|
|
|
case WINED3DDECLUSAGE_COLOR:
|
|
|
|
if (usage_idx == 0)
|
2008-06-19 00:36:35 +02:00
|
|
|
shader_addline(buffer, "%s%s = front_color%s;\n",
|
|
|
|
destination, reg_mask, reg_mask);
|
2007-10-26 02:11:00 +02:00
|
|
|
else if (usage_idx == 1)
|
2008-06-19 00:36:35 +02:00
|
|
|
shader_addline(buffer, "%s%s = front_secondary_color%s;\n",
|
|
|
|
destination, reg_mask, reg_mask);
|
2007-10-26 02:11:00 +02:00
|
|
|
else
|
2008-06-19 00:36:35 +02:00
|
|
|
shader_addline(buffer, "%s%s = vec4(0.0, 0.0, 0.0, 0.0)%s;\n",
|
|
|
|
destination, reg_mask, reg_mask);
|
2007-10-26 02:11:00 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_TEXCOORD:
|
|
|
|
if (usage_idx < 8) {
|
2008-06-19 00:36:35 +02:00
|
|
|
shader_addline(buffer, "%s%s = gl_TexCoord[%u]%s;\n",
|
|
|
|
destination, reg_mask, usage_idx, reg_mask);
|
2007-10-26 02:11:00 +02:00
|
|
|
} else {
|
2008-06-19 00:36:35 +02:00
|
|
|
shader_addline(buffer, "%s%s = vec4(0.0, 0.0, 0.0, 0.0)%s;\n",
|
|
|
|
destination, reg_mask, reg_mask);
|
2007-10-26 02:11:00 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_FOG:
|
2008-06-19 00:36:35 +02:00
|
|
|
shader_addline(buffer, "%s%s = vec4(gl_FogFragCoord, 0.0, 0.0, 0.0)%s;\n",
|
|
|
|
destination, reg_mask, reg_mask);
|
2007-10-26 02:11:00 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-06-19 00:36:35 +02:00
|
|
|
shader_addline(buffer, "%s%s = vec4(0.0, 0.0, 0.0, 0.0)%s;\n",
|
|
|
|
destination, reg_mask, reg_mask);
|
2007-10-26 02:11:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
BOOL found = FALSE;
|
|
|
|
for(j = 0; j < MAX_REG_OUTPUT; j++) {
|
|
|
|
usage_token_out = semantics_out[j].usage;
|
|
|
|
if (!usage_token_out) continue;
|
|
|
|
register_token_out = semantics_out[j].reg;
|
|
|
|
|
|
|
|
usage_out = (usage_token_out & WINED3DSP_DCL_USAGE_MASK) >> WINED3DSP_DCL_USAGE_SHIFT;
|
|
|
|
usage_idx_out = (usage_token_out & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
|
|
|
|
shader_glsl_get_write_mask(register_token_out, reg_mask_out);
|
|
|
|
|
|
|
|
if(usage == usage_out &&
|
|
|
|
usage_idx == usage_idx_out) {
|
2008-06-19 00:36:35 +02:00
|
|
|
shader_addline(buffer, "%s%s = OUT[%u]%s;\n",
|
|
|
|
destination, reg_mask, j, reg_mask);
|
2007-10-26 02:11:00 +02:00
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!found) {
|
2008-06-19 00:36:35 +02:00
|
|
|
shader_addline(buffer, "%s%s = vec4(0.0, 0.0, 0.0, 0.0)%s;\n",
|
|
|
|
destination, reg_mask, reg_mask);
|
2007-10-26 02:11:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is solely to make the compiler / linker happy and avoid warning about undefined
|
|
|
|
* varyings. It shouldn't result in any real code executed on the GPU, since all read
|
|
|
|
* input varyings are assigned above, if the optimizer works properly.
|
|
|
|
*/
|
2008-06-19 00:36:35 +02:00
|
|
|
for(i = 0; i < in_count + 2; i++) {
|
2007-10-26 02:11:00 +02:00
|
|
|
if(set[i] != WINED3DSP_WRITEMASK_ALL) {
|
|
|
|
unsigned int size = 0;
|
|
|
|
memset(reg_mask, 0, sizeof(reg_mask));
|
|
|
|
if(!(set[i] & WINED3DSP_WRITEMASK_0)) {
|
|
|
|
reg_mask[size] = 'x';
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
if(!(set[i] & WINED3DSP_WRITEMASK_1)) {
|
|
|
|
reg_mask[size] = 'y';
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
if(!(set[i] & WINED3DSP_WRITEMASK_2)) {
|
|
|
|
reg_mask[size] = 'z';
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
if(!(set[i] & WINED3DSP_WRITEMASK_3)) {
|
|
|
|
reg_mask[size] = 'w';
|
|
|
|
size++;
|
|
|
|
}
|
2008-06-19 00:36:35 +02:00
|
|
|
|
|
|
|
if (i == in_count) {
|
|
|
|
sprintf(destination, "gl_FrontColor");
|
|
|
|
} else if (i == in_count + 1) {
|
|
|
|
sprintf(destination, "gl_FrontSecondaryColor");
|
|
|
|
} else {
|
|
|
|
sprintf(destination, "IN[%u]", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size == 1) {
|
|
|
|
shader_addline(buffer, "%s.%s = 0.0;\n", destination, reg_mask);
|
|
|
|
} else {
|
|
|
|
shader_addline(buffer, "%s.%s = vec%u(0.0);\n", destination, reg_mask, size);
|
2007-10-26 02:11:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, set);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GLhandleARB generate_param_reorder_function(IWineD3DVertexShader *vertexshader,
|
2008-11-25 14:36:09 +01:00
|
|
|
IWineD3DPixelShader *pixelshader, const WineD3D_GL_Info *gl_info)
|
|
|
|
{
|
2007-10-26 02:11:00 +02:00
|
|
|
GLhandleARB ret = 0;
|
|
|
|
IWineD3DVertexShaderImpl *vs = (IWineD3DVertexShaderImpl *) vertexshader;
|
|
|
|
IWineD3DPixelShaderImpl *ps = (IWineD3DPixelShaderImpl *) pixelshader;
|
2008-08-23 22:41:51 +02:00
|
|
|
IWineD3DDeviceImpl *device;
|
2008-12-15 12:10:14 +01:00
|
|
|
DWORD vs_major = WINED3DSHADER_VERSION_MAJOR(vs->baseShader.reg_maps.shader_version);
|
|
|
|
DWORD ps_major = ps ? WINED3DSHADER_VERSION_MAJOR(ps->baseShader.reg_maps.shader_version) : 0;
|
2007-10-26 02:11:00 +02:00
|
|
|
unsigned int i;
|
|
|
|
SHADER_BUFFER buffer;
|
|
|
|
DWORD usage_token;
|
|
|
|
DWORD register_token;
|
2007-12-06 22:10:11 +01:00
|
|
|
DWORD usage, usage_idx, writemask;
|
2007-10-26 02:11:00 +02:00
|
|
|
char reg_mask[6];
|
2008-11-25 14:36:09 +01:00
|
|
|
const struct semantic *semantics_out, *semantics_in;
|
2007-10-26 02:11:00 +02:00
|
|
|
|
2008-12-09 09:52:38 +01:00
|
|
|
shader_buffer_init(&buffer);
|
2007-10-26 02:11:00 +02:00
|
|
|
|
2008-06-30 23:03:47 +02:00
|
|
|
shader_addline(&buffer, "#version 120\n");
|
|
|
|
|
2007-10-26 02:11:00 +02:00
|
|
|
if(vs_major < 3 && ps_major < 3) {
|
2007-12-06 22:10:11 +01:00
|
|
|
/* That one is easy: The vertex shader writes to the builtin varyings, the pixel shader reads from them.
|
|
|
|
* Take care about the texcoord .w fixup though if we're using the fixed function fragment pipeline
|
|
|
|
*/
|
2008-08-23 22:41:51 +02:00
|
|
|
device = (IWineD3DDeviceImpl *) vs->baseShader.device;
|
|
|
|
if((GLINFO_LOCATION).set_texcoord_w && ps_major == 0 && vs_major > 0 &&
|
|
|
|
!device->frag_pipe->ffp_proj_control) {
|
2007-12-06 22:10:11 +01:00
|
|
|
shader_addline(&buffer, "void order_ps_input() {\n");
|
|
|
|
for(i = 0; i < min(8, MAX_REG_TEXCRD); i++) {
|
|
|
|
if(vs->baseShader.reg_maps.texcoord_mask[i] != 0 &&
|
|
|
|
vs->baseShader.reg_maps.texcoord_mask[i] != WINED3DSP_WRITEMASK_ALL) {
|
|
|
|
shader_addline(&buffer, "gl_TexCoord[%u].w = 1.0;\n", i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
shader_addline(&buffer, "}\n");
|
|
|
|
} else {
|
|
|
|
shader_addline(&buffer, "void order_ps_input() { /* do nothing */ }\n");
|
|
|
|
}
|
2007-10-26 02:11:00 +02:00
|
|
|
} else if(ps_major < 3 && vs_major >= 3) {
|
|
|
|
/* The vertex shader writes to its own varyings, the pixel shader needs them in the builtin ones */
|
|
|
|
semantics_out = vs->semantics_out;
|
|
|
|
|
|
|
|
shader_addline(&buffer, "void order_ps_input(in vec4 OUT[%u]) {\n", MAX_REG_OUTPUT);
|
|
|
|
for(i = 0; i < MAX_REG_OUTPUT; i++) {
|
|
|
|
usage_token = semantics_out[i].usage;
|
|
|
|
if (!usage_token) continue;
|
|
|
|
register_token = semantics_out[i].reg;
|
|
|
|
|
|
|
|
usage = (usage_token & WINED3DSP_DCL_USAGE_MASK) >> WINED3DSP_DCL_USAGE_SHIFT;
|
|
|
|
usage_idx = (usage_token & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
|
2007-12-06 22:10:11 +01:00
|
|
|
writemask = shader_glsl_get_write_mask(register_token, reg_mask);
|
2007-10-26 02:11:00 +02:00
|
|
|
|
|
|
|
switch(usage) {
|
|
|
|
case WINED3DDECLUSAGE_COLOR:
|
|
|
|
if (usage_idx == 0)
|
|
|
|
shader_addline(&buffer, "gl_FrontColor%s = OUT[%u]%s;\n", reg_mask, i, reg_mask);
|
|
|
|
else if (usage_idx == 1)
|
|
|
|
shader_addline(&buffer, "gl_FrontSecondaryColor%s = OUT[%u]%s;\n", reg_mask, i, reg_mask);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_POSITION:
|
|
|
|
shader_addline(&buffer, "gl_Position%s = OUT[%u]%s;\n", reg_mask, i, reg_mask);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_TEXCOORD:
|
|
|
|
if (usage_idx < 8) {
|
2007-12-06 22:10:11 +01:00
|
|
|
if(!(GLINFO_LOCATION).set_texcoord_w || ps_major > 0) writemask |= WINED3DSP_WRITEMASK_3;
|
|
|
|
|
2007-10-26 02:11:00 +02:00
|
|
|
shader_addline(&buffer, "gl_TexCoord[%u]%s = OUT[%u]%s;\n",
|
2007-12-06 22:10:11 +01:00
|
|
|
usage_idx, reg_mask, i, reg_mask);
|
|
|
|
if(!(writemask & WINED3DSP_WRITEMASK_3)) {
|
|
|
|
shader_addline(&buffer, "gl_TexCoord[%u].w = 1.0;\n", usage_idx);
|
|
|
|
}
|
2007-10-26 02:11:00 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_PSIZE:
|
|
|
|
shader_addline(&buffer, "gl_PointSize = OUT[%u].x;\n", i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_FOG:
|
|
|
|
shader_addline(&buffer, "gl_FogFragCoord = OUT[%u].%c;\n", i, reg_mask[1]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
shader_addline(&buffer, "}\n");
|
|
|
|
|
|
|
|
} else if(ps_major >= 3 && vs_major >= 3) {
|
|
|
|
semantics_out = vs->semantics_out;
|
|
|
|
semantics_in = ps->semantics_in;
|
|
|
|
|
|
|
|
/* This one is tricky: a 3.0 pixel shader reads from a 3.0 vertex shader */
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(&buffer, "varying vec4 IN[%u];\n", GL_LIMITS(glsl_varyings) / 4);
|
2007-10-26 02:11:00 +02:00
|
|
|
shader_addline(&buffer, "void order_ps_input(in vec4 OUT[%u]) {\n", MAX_REG_OUTPUT);
|
|
|
|
|
|
|
|
/* First, sort out position and point size. Those are not passed to the pixel shader */
|
|
|
|
for(i = 0; i < MAX_REG_OUTPUT; i++) {
|
|
|
|
usage_token = semantics_out[i].usage;
|
|
|
|
if (!usage_token) continue;
|
|
|
|
register_token = semantics_out[i].reg;
|
|
|
|
|
|
|
|
usage = (usage_token & WINED3DSP_DCL_USAGE_MASK) >> WINED3DSP_DCL_USAGE_SHIFT;
|
|
|
|
usage_idx = (usage_token & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
|
|
|
|
shader_glsl_get_write_mask(register_token, reg_mask);
|
|
|
|
|
|
|
|
switch(usage) {
|
|
|
|
case WINED3DDECLUSAGE_POSITION:
|
|
|
|
shader_addline(&buffer, "gl_Position%s = OUT[%u]%s;\n", reg_mask, i, reg_mask);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DDECLUSAGE_PSIZE:
|
|
|
|
shader_addline(&buffer, "gl_PointSize = OUT[%u].x;\n", i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then, fix the pixel shader input */
|
2007-10-28 00:12:37 +02:00
|
|
|
handle_ps3_input(&buffer, semantics_in, semantics_out, gl_info, ps->input_reg_map);
|
2007-10-26 02:11:00 +02:00
|
|
|
|
|
|
|
shader_addline(&buffer, "}\n");
|
|
|
|
} else if(ps_major >= 3 && vs_major < 3) {
|
|
|
|
semantics_in = ps->semantics_in;
|
|
|
|
|
2007-11-28 12:55:11 +01:00
|
|
|
shader_addline(&buffer, "varying vec4 IN[%u];\n", GL_LIMITS(glsl_varyings) / 4);
|
2007-10-26 02:11:00 +02:00
|
|
|
shader_addline(&buffer, "void order_ps_input() {\n");
|
|
|
|
/* The vertex shader wrote to the builtin varyings. There is no need to figure out position and
|
|
|
|
* point size, but we depend on the optimizers kindness to find out that the pixel shader doesn't
|
|
|
|
* read gl_TexCoord and gl_ColorX, otherwise we'll run out of varyings
|
|
|
|
*/
|
2007-10-28 00:12:37 +02:00
|
|
|
handle_ps3_input(&buffer, semantics_in, NULL, gl_info, ps->input_reg_map);
|
2007-10-26 02:11:00 +02:00
|
|
|
shader_addline(&buffer, "}\n");
|
|
|
|
} else {
|
|
|
|
ERR("Unexpected vertex and pixel shader version condition: vs: %d, ps: %d\n", vs_major, ps_major);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GL_EXTCALL(glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB));
|
|
|
|
checkGLcall("glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB)");
|
|
|
|
GL_EXTCALL(glShaderSourceARB(ret, 1, (const char**)&buffer.buffer, NULL));
|
2009-02-03 09:36:07 +01:00
|
|
|
checkGLcall("glShaderSourceARB(ret, 1, &buffer.buffer, NULL)");
|
2007-10-26 02:11:00 +02:00
|
|
|
GL_EXTCALL(glCompileShaderARB(ret));
|
|
|
|
checkGLcall("glCompileShaderARB(ret)");
|
|
|
|
|
2008-12-09 09:52:38 +01:00
|
|
|
shader_buffer_free(&buffer);
|
2007-10-26 02:11:00 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void hardcode_local_constants(IWineD3DBaseShaderImpl *shader, const WineD3D_GL_Info *gl_info,
|
|
|
|
GLhandleARB programId, char prefix)
|
|
|
|
{
|
|
|
|
const local_constant *lconst;
|
2008-06-02 21:44:06 +02:00
|
|
|
GLuint tmp_loc;
|
2008-11-25 14:36:09 +01:00
|
|
|
const float *value;
|
2008-06-02 21:44:06 +02:00
|
|
|
char glsl_name[8];
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(lconst, &shader->baseShader.constantsF, local_constant, entry) {
|
2008-11-25 14:36:09 +01:00
|
|
|
value = (const float *)lconst->value;
|
2008-06-02 21:44:06 +02:00
|
|
|
snprintf(glsl_name, sizeof(glsl_name), "%cLC%u", prefix, lconst->idx);
|
|
|
|
tmp_loc = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
|
|
|
|
GL_EXTCALL(glUniform4fvARB(tmp_loc, 1, value));
|
|
|
|
}
|
|
|
|
checkGLcall("Hardcoding local constants\n");
|
|
|
|
}
|
|
|
|
|
2006-12-28 03:13:24 +01:00
|
|
|
/** 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
|
2007-02-27 20:51:53 +01:00
|
|
|
* the program in the hash table. If it creates a program, it will link the
|
|
|
|
* given objects, too.
|
2006-12-28 03:13:24 +01:00
|
|
|
*/
|
2007-03-12 23:22:00 +01:00
|
|
|
static void set_glsl_shader_program(IWineD3DDevice *iface, BOOL use_ps, BOOL use_vs) {
|
2006-12-28 03:13:24 +01:00
|
|
|
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
|
2009-02-03 09:36:07 +01:00
|
|
|
struct shader_glsl_priv *priv = This->shader_priv;
|
2008-11-25 14:36:09 +01:00
|
|
|
const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
|
2006-12-28 03:13:24 +01:00
|
|
|
IWineD3DPixelShader *pshader = This->stateBlock->pixelShader;
|
|
|
|
IWineD3DVertexShader *vshader = This->stateBlock->vertexShader;
|
2007-02-27 20:51:53 +01:00
|
|
|
struct glsl_shader_prog_link *entry = NULL;
|
2006-12-28 03:13:24 +01:00
|
|
|
GLhandleARB programId = 0;
|
2007-10-26 02:11:00 +02:00
|
|
|
GLhandleARB reorder_shader_id = 0;
|
2006-12-28 03:13:24 +01:00
|
|
|
int i;
|
|
|
|
char glsl_name[8];
|
2008-11-24 11:52:12 +01:00
|
|
|
GLhandleARB vshader_id, pshader_id;
|
2009-02-05 19:44:32 +01:00
|
|
|
struct ps_compile_args ps_compile_args;
|
|
|
|
struct vs_compile_args vs_compile_args;
|
2006-12-28 03:13:24 +01:00
|
|
|
|
2008-11-24 11:52:12 +01:00
|
|
|
if(use_vs) {
|
2009-02-05 19:44:32 +01:00
|
|
|
find_vs_compile_args((IWineD3DVertexShaderImpl*)This->stateBlock->vertexShader, This->stateBlock, &vs_compile_args);
|
2008-11-24 11:52:12 +01:00
|
|
|
} else {
|
2009-02-05 19:44:32 +01:00
|
|
|
/* FIXME: Do we really have to spend CPU cycles to generate a few zeroed bytes? */
|
|
|
|
memset(&vs_compile_args, 0, sizeof(vs_compile_args));
|
2008-11-24 11:52:12 +01:00
|
|
|
}
|
|
|
|
if(use_ps) {
|
2009-02-05 19:44:32 +01:00
|
|
|
find_ps_compile_args((IWineD3DPixelShaderImpl*)This->stateBlock->pixelShader, This->stateBlock, &ps_compile_args);
|
2008-11-24 11:52:12 +01:00
|
|
|
} else {
|
2008-11-21 19:48:36 +01:00
|
|
|
/* FIXME: Do we really have to spend CPU cycles to generate a few zeroed bytes? */
|
2009-02-05 19:44:32 +01:00
|
|
|
memset(&ps_compile_args, 0, sizeof(ps_compile_args));
|
2008-11-24 11:52:12 +01:00
|
|
|
}
|
2009-02-05 19:44:32 +01:00
|
|
|
entry = get_glsl_program_entry(priv, vshader, pshader, &vs_compile_args, &ps_compile_args);
|
2007-02-27 20:51:53 +01:00
|
|
|
if (entry) {
|
2008-07-07 21:02:57 +02:00
|
|
|
priv->glsl_program = entry;
|
2007-02-27 20:51:53 +01:00
|
|
|
return;
|
2006-12-28 03:13:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2007-02-27 20:51:53 +01:00
|
|
|
/* Create the entry */
|
|
|
|
entry = HeapAlloc(GetProcessHeap(), 0, sizeof(struct glsl_shader_prog_link));
|
|
|
|
entry->programId = programId;
|
2009-02-05 19:44:32 +01:00
|
|
|
entry->vshader = vshader;
|
2008-11-21 19:48:36 +01:00
|
|
|
entry->pshader = pshader;
|
2009-02-05 19:44:32 +01:00
|
|
|
entry->vs_args = vs_compile_args;
|
|
|
|
entry->ps_args = ps_compile_args;
|
2008-12-19 19:21:56 +01:00
|
|
|
entry->constant_version = 0;
|
2007-02-27 20:51:53 +01:00
|
|
|
/* Add the hash table entry */
|
2008-07-08 21:44:20 +02:00
|
|
|
add_glsl_program_entry(priv, entry);
|
2007-02-27 20:51:53 +01:00
|
|
|
|
|
|
|
/* Set the current program */
|
2008-07-07 21:02:57 +02:00
|
|
|
priv->glsl_program = entry;
|
2006-12-28 03:13:24 +01:00
|
|
|
|
2009-02-05 19:44:32 +01:00
|
|
|
if(use_vs) {
|
|
|
|
vshader_id = find_gl_vshader((IWineD3DVertexShaderImpl *) vshader, &vs_compile_args);
|
|
|
|
} else {
|
|
|
|
vshader_id = 0;
|
|
|
|
}
|
|
|
|
|
2006-12-28 03:13:24 +01:00
|
|
|
/* Attach GLSL vshader */
|
2007-02-27 20:51:53 +01:00
|
|
|
if (vshader_id) {
|
2006-12-28 03:13:24 +01:00
|
|
|
int max_attribs = 16; /* TODO: Will this always be the case? It is at the moment... */
|
|
|
|
char tmp_name[10];
|
|
|
|
|
2007-11-22 22:18:53 +01:00
|
|
|
reorder_shader_id = generate_param_reorder_function(vshader, pshader, gl_info);
|
|
|
|
TRACE("Attaching GLSL shader object %u to program %u\n", reorder_shader_id, programId);
|
|
|
|
GL_EXTCALL(glAttachObjectARB(programId, reorder_shader_id));
|
|
|
|
checkGLcall("glAttachObjectARB");
|
|
|
|
/* Flag the reorder function for deletion, then it will be freed automatically when the program
|
|
|
|
* is destroyed
|
|
|
|
*/
|
|
|
|
GL_EXTCALL(glDeleteObjectARB(reorder_shader_id));
|
|
|
|
|
2007-02-27 20:51:53 +01:00
|
|
|
TRACE("Attaching GLSL shader object %u to program %u\n", vshader_id, programId);
|
|
|
|
GL_EXTCALL(glAttachObjectARB(programId, vshader_id));
|
|
|
|
checkGLcall("glAttachObjectARB");
|
2006-12-28 03:13:24 +01:00
|
|
|
|
|
|
|
/* 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) {
|
2007-10-22 14:08:23 +02:00
|
|
|
if (((IWineD3DBaseShaderImpl*)vshader)->baseShader.reg_maps.attributes[i]) {
|
|
|
|
snprintf(tmp_name, sizeof(tmp_name), "attrib%i", i);
|
|
|
|
GL_EXTCALL(glBindAttribLocationARB(programId, i, tmp_name));
|
|
|
|
}
|
2006-12-28 03:13:24 +01:00
|
|
|
}
|
|
|
|
checkGLcall("glBindAttribLocationARB");
|
2007-02-27 20:51:53 +01:00
|
|
|
|
|
|
|
list_add_head(&((IWineD3DBaseShaderImpl *)vshader)->baseShader.linked_programs, &entry->vshader_entry);
|
2006-12-28 03:13:24 +01:00
|
|
|
}
|
|
|
|
|
2008-11-21 19:48:36 +01:00
|
|
|
if(use_ps) {
|
2009-02-05 19:44:32 +01:00
|
|
|
pshader_id = find_gl_pshader((IWineD3DPixelShaderImpl *) pshader, &ps_compile_args);
|
2008-11-21 19:48:36 +01:00
|
|
|
} else {
|
|
|
|
pshader_id = 0;
|
|
|
|
}
|
|
|
|
|
2006-12-28 03:13:24 +01:00
|
|
|
/* Attach GLSL pshader */
|
2007-02-27 20:51:53 +01:00
|
|
|
if (pshader_id) {
|
|
|
|
TRACE("Attaching GLSL shader object %u to program %u\n", pshader_id, programId);
|
|
|
|
GL_EXTCALL(glAttachObjectARB(programId, pshader_id));
|
|
|
|
checkGLcall("glAttachObjectARB");
|
|
|
|
|
|
|
|
list_add_head(&((IWineD3DBaseShaderImpl *)pshader)->baseShader.linked_programs, &entry->pshader_entry);
|
2006-12-28 03:13:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Link the program */
|
|
|
|
TRACE("Linking GLSL shader program %u\n", programId);
|
|
|
|
GL_EXTCALL(glLinkProgramARB(programId));
|
|
|
|
print_glsl_info_log(&GLINFO_LOCATION, programId);
|
|
|
|
|
2007-02-27 20:51:53 +01:00
|
|
|
entry->vuniformF_locations = HeapAlloc(GetProcessHeap(), 0, sizeof(GLhandleARB) * GL_LIMITS(vshader_constantsF));
|
2006-12-28 03:13:24 +01:00
|
|
|
for (i = 0; i < GL_LIMITS(vshader_constantsF); ++i) {
|
|
|
|
snprintf(glsl_name, sizeof(glsl_name), "VC[%i]", i);
|
2007-02-27 20:51:53 +01:00
|
|
|
entry->vuniformF_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
|
2006-12-28 03:13:24 +01:00
|
|
|
}
|
2007-11-06 23:36:10 +01:00
|
|
|
for (i = 0; i < MAX_CONST_I; ++i) {
|
|
|
|
snprintf(glsl_name, sizeof(glsl_name), "VI[%i]", i);
|
|
|
|
entry->vuniformI_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
|
|
|
|
}
|
2007-02-27 20:51:53 +01:00
|
|
|
entry->puniformF_locations = HeapAlloc(GetProcessHeap(), 0, sizeof(GLhandleARB) * GL_LIMITS(pshader_constantsF));
|
2006-12-28 03:13:24 +01:00
|
|
|
for (i = 0; i < GL_LIMITS(pshader_constantsF); ++i) {
|
|
|
|
snprintf(glsl_name, sizeof(glsl_name), "PC[%i]", i);
|
2007-02-27 20:51:53 +01:00
|
|
|
entry->puniformF_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
|
2006-12-28 03:13:24 +01:00
|
|
|
}
|
2007-11-06 23:36:10 +01:00
|
|
|
for (i = 0; i < MAX_CONST_I; ++i) {
|
|
|
|
snprintf(glsl_name, sizeof(glsl_name), "PI[%i]", i);
|
|
|
|
entry->puniformI_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
|
|
|
|
}
|
2007-11-06 23:05:38 +01:00
|
|
|
|
2008-03-05 03:18:55 +01:00
|
|
|
if(pshader) {
|
|
|
|
for(i = 0; i < ((IWineD3DPixelShaderImpl*)pshader)->numbumpenvmatconsts; i++) {
|
|
|
|
char name[32];
|
|
|
|
sprintf(name, "bumpenvmat%d", ((IWineD3DPixelShaderImpl*)pshader)->bumpenvmatconst[i].texunit);
|
|
|
|
entry->bumpenvmat_location[i] = GL_EXTCALL(glGetUniformLocationARB(programId, name));
|
|
|
|
sprintf(name, "luminancescale%d", ((IWineD3DPixelShaderImpl*)pshader)->luminanceconst[i].texunit);
|
|
|
|
entry->luminancescale_location[i] = GL_EXTCALL(glGetUniformLocationARB(programId, name));
|
|
|
|
sprintf(name, "luminanceoffset%d", ((IWineD3DPixelShaderImpl*)pshader)->luminanceconst[i].texunit);
|
|
|
|
entry->luminanceoffset_location[i] = GL_EXTCALL(glGetUniformLocationARB(programId, name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-06 23:05:38 +01:00
|
|
|
entry->posFixup_location = GL_EXTCALL(glGetUniformLocationARB(programId, "posFixup"));
|
|
|
|
entry->ycorrection_location = GL_EXTCALL(glGetUniformLocationARB(programId, "ycorrection"));
|
2007-11-06 23:36:10 +01:00
|
|
|
checkGLcall("Find glsl program uniform locations");
|
2007-11-07 23:03:15 +01:00
|
|
|
|
2008-12-15 12:10:14 +01:00
|
|
|
if (pshader
|
|
|
|
&& WINED3DSHADER_VERSION_MAJOR(((IWineD3DPixelShaderImpl *)pshader)->baseShader.reg_maps.shader_version) >= 3
|
|
|
|
&& ((IWineD3DPixelShaderImpl *)pshader)->declared_in_count > GL_LIMITS(glsl_varyings) / 4)
|
|
|
|
{
|
2008-06-19 00:36:35 +02:00
|
|
|
TRACE("Shader %d needs vertex color clamping disabled\n", programId);
|
|
|
|
entry->vertex_color_clamp = GL_FALSE;
|
|
|
|
} else {
|
|
|
|
entry->vertex_color_clamp = GL_FIXED_ONLY_ARB;
|
|
|
|
}
|
|
|
|
|
2007-11-07 23:03:15 +01:00
|
|
|
/* Set the shader to allow uniform loading on it */
|
|
|
|
GL_EXTCALL(glUseProgramObjectARB(programId));
|
|
|
|
checkGLcall("glUseProgramObjectARB(programId)");
|
|
|
|
|
|
|
|
/* Load the vertex and pixel samplers now. The function that finds the mappings makes sure
|
|
|
|
* that it stays the same for each vertexshader-pixelshader pair(=linked glsl program). If
|
|
|
|
* a pshader with fixed function pipeline is used there are no vertex samplers, and if a
|
|
|
|
* vertex shader with fixed function pixel processing is used we make sure that the card
|
|
|
|
* supports enough samplers to allow the max number of vertex samplers with all possible
|
|
|
|
* fixed function fragment processing setups. So once the program is linked these samplers
|
|
|
|
* won't change.
|
|
|
|
*/
|
|
|
|
if(vshader_id) {
|
|
|
|
/* Load vertex shader samplers */
|
|
|
|
shader_glsl_load_vsamplers(gl_info, (IWineD3DStateBlock*)This->stateBlock, programId);
|
|
|
|
}
|
|
|
|
if(pshader_id) {
|
|
|
|
/* Load pixel shader samplers */
|
|
|
|
shader_glsl_load_psamplers(gl_info, (IWineD3DStateBlock*)This->stateBlock, programId);
|
|
|
|
}
|
2008-06-02 21:44:06 +02:00
|
|
|
|
|
|
|
/* If the local constants do not have to be loaded with the environment constants,
|
|
|
|
* load them now to have them hardcoded in the GLSL program. This saves some CPU cycles
|
|
|
|
* later
|
|
|
|
*/
|
|
|
|
if(pshader && !((IWineD3DPixelShaderImpl*)pshader)->baseShader.load_local_constsF) {
|
|
|
|
hardcode_local_constants((IWineD3DBaseShaderImpl *) pshader, gl_info, programId, 'P');
|
|
|
|
}
|
|
|
|
if(vshader && !((IWineD3DVertexShaderImpl*)vshader)->baseShader.load_local_constsF) {
|
|
|
|
hardcode_local_constants((IWineD3DBaseShaderImpl *) vshader, gl_info, programId, 'V');
|
|
|
|
}
|
2006-12-28 03:13:24 +01:00
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static GLhandleARB create_glsl_blt_shader(const WineD3D_GL_Info *gl_info, enum tex_types tex_type)
|
|
|
|
{
|
2006-11-27 20:50:37 +01:00
|
|
|
GLhandleARB program_id;
|
|
|
|
GLhandleARB vshader_id, pshader_id;
|
2008-12-10 10:04:40 +01:00
|
|
|
static const char *blt_vshader[] =
|
|
|
|
{
|
2008-06-30 23:03:47 +02:00
|
|
|
"#version 120\n"
|
2006-11-27 20:50:37 +01:00
|
|
|
"void main(void)\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_Position = gl_Vertex;\n"
|
|
|
|
" gl_FrontColor = vec4(1.0);\n"
|
2008-10-27 18:31:31 +01:00
|
|
|
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
|
2006-11-27 20:50:37 +01:00
|
|
|
"}\n"
|
|
|
|
};
|
|
|
|
|
2008-12-10 10:04:40 +01:00
|
|
|
static const char *blt_pshaders[tex_type_count] =
|
|
|
|
{
|
2008-10-27 18:31:32 +01:00
|
|
|
/* tex_1d */
|
|
|
|
NULL,
|
|
|
|
/* tex_2d */
|
2008-06-30 23:03:47 +02:00
|
|
|
"#version 120\n"
|
2006-11-27 20:50:37 +01:00
|
|
|
"uniform sampler2D sampler;\n"
|
|
|
|
"void main(void)\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_FragDepth = texture2D(sampler, gl_TexCoord[0].xy).x;\n"
|
2008-10-27 18:31:32 +01:00
|
|
|
"}\n",
|
|
|
|
/* tex_3d */
|
|
|
|
NULL,
|
|
|
|
/* tex_cube */
|
|
|
|
"#version 120\n"
|
|
|
|
"uniform samplerCube sampler;\n"
|
|
|
|
"void main(void)\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_FragDepth = textureCube(sampler, gl_TexCoord[0].xyz).x;\n"
|
|
|
|
"}\n",
|
|
|
|
/* tex_rect */
|
|
|
|
"#version 120\n"
|
|
|
|
"#extension GL_ARB_texture_rectangle : enable\n"
|
|
|
|
"uniform sampler2DRect sampler;\n"
|
|
|
|
"void main(void)\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_FragDepth = texture2DRect(sampler, gl_TexCoord[0].xy).x;\n"
|
|
|
|
"}\n",
|
2006-11-27 20:50:37 +01:00
|
|
|
};
|
|
|
|
|
2008-10-27 18:31:32 +01:00
|
|
|
if (!blt_pshaders[tex_type])
|
|
|
|
{
|
|
|
|
FIXME("tex_type %#x not supported\n", tex_type);
|
|
|
|
tex_type = tex_2d;
|
|
|
|
}
|
|
|
|
|
2006-11-27 20:50:37 +01:00
|
|
|
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));
|
2008-10-27 18:31:32 +01:00
|
|
|
GL_EXTCALL(glShaderSourceARB(pshader_id, 1, &blt_pshaders[tex_type], NULL));
|
2006-11-27 20:50:37 +01:00
|
|
|
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);
|
|
|
|
|
2008-02-24 11:23:53 +01:00
|
|
|
/* Once linked we can mark the shaders for deletion. They will be deleted once the program
|
|
|
|
* is destroyed
|
|
|
|
*/
|
|
|
|
GL_EXTCALL(glDeleteObjectARB(vshader_id));
|
|
|
|
GL_EXTCALL(glDeleteObjectARB(pshader_id));
|
2006-11-27 20:50:37 +01:00
|
|
|
return program_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void shader_glsl_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {
|
|
|
|
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
|
2009-02-03 09:36:07 +01:00
|
|
|
struct shader_glsl_priv *priv = This->shader_priv;
|
2008-11-25 14:36:09 +01:00
|
|
|
const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
|
2006-11-27 20:50:37 +01:00
|
|
|
GLhandleARB program_id = 0;
|
2008-06-19 00:36:35 +02:00
|
|
|
GLenum old_vertex_color_clamp, current_vertex_color_clamp;
|
|
|
|
|
2008-07-07 21:02:57 +02:00
|
|
|
old_vertex_color_clamp = priv->glsl_program ? priv->glsl_program->vertex_color_clamp : GL_FIXED_ONLY_ARB;
|
2006-11-27 20:50:37 +01:00
|
|
|
|
2007-03-12 23:22:00 +01:00
|
|
|
if (useVS || usePS) set_glsl_shader_program(iface, usePS, useVS);
|
2008-07-07 21:02:57 +02:00
|
|
|
else priv->glsl_program = NULL;
|
2006-11-27 20:50:37 +01:00
|
|
|
|
2008-07-07 21:02:57 +02:00
|
|
|
current_vertex_color_clamp = priv->glsl_program ? priv->glsl_program->vertex_color_clamp : GL_FIXED_ONLY_ARB;
|
2008-06-19 00:36:35 +02:00
|
|
|
|
|
|
|
if (old_vertex_color_clamp != current_vertex_color_clamp) {
|
|
|
|
if (GL_SUPPORT(ARB_COLOR_BUFFER_FLOAT)) {
|
|
|
|
GL_EXTCALL(glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, current_vertex_color_clamp));
|
|
|
|
checkGLcall("glClampColorARB");
|
|
|
|
} else {
|
|
|
|
FIXME("vertex color clamp needs to be changed, but extension not supported.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-07 21:02:57 +02:00
|
|
|
program_id = priv->glsl_program ? priv->glsl_program->programId : 0;
|
2006-11-27 20:50:37 +01:00
|
|
|
if (program_id) TRACE("Using GLSL program %u\n", program_id);
|
|
|
|
GL_EXTCALL(glUseProgramObjectARB(program_id));
|
|
|
|
checkGLcall("glUseProgramObjectARB");
|
|
|
|
}
|
|
|
|
|
2008-10-27 18:31:31 +01:00
|
|
|
static void shader_glsl_select_depth_blt(IWineD3DDevice *iface, enum tex_types tex_type) {
|
2006-11-27 20:50:37 +01:00
|
|
|
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
|
2008-11-25 14:36:09 +01:00
|
|
|
const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
|
2009-02-03 09:36:07 +01:00
|
|
|
struct shader_glsl_priv *priv = This->shader_priv;
|
2008-10-27 18:31:32 +01:00
|
|
|
GLhandleARB *blt_program = &priv->depth_blt_program[tex_type];
|
2006-11-27 20:50:37 +01:00
|
|
|
|
2008-10-27 18:31:32 +01:00
|
|
|
if (!*blt_program) {
|
2008-10-20 00:15:13 +02:00
|
|
|
GLhandleARB loc;
|
2008-10-27 18:31:32 +01:00
|
|
|
*blt_program = create_glsl_blt_shader(gl_info, tex_type);
|
|
|
|
loc = GL_EXTCALL(glGetUniformLocationARB(*blt_program, "sampler"));
|
|
|
|
GL_EXTCALL(glUseProgramObjectARB(*blt_program));
|
2008-10-20 00:15:13 +02:00
|
|
|
GL_EXTCALL(glUniform1iARB(loc, 0));
|
|
|
|
} else {
|
2008-10-27 18:31:32 +01:00
|
|
|
GL_EXTCALL(glUseProgramObjectARB(*blt_program));
|
2006-11-27 20:50:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-10 17:57:35 +02:00
|
|
|
static void shader_glsl_deselect_depth_blt(IWineD3DDevice *iface) {
|
|
|
|
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
|
2008-11-25 14:36:09 +01:00
|
|
|
const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
|
2009-02-03 09:36:07 +01:00
|
|
|
struct shader_glsl_priv *priv = This->shader_priv;
|
2008-07-10 17:57:35 +02:00
|
|
|
GLhandleARB program_id;
|
|
|
|
|
|
|
|
program_id = priv->glsl_program ? priv->glsl_program->programId : 0;
|
|
|
|
if (program_id) TRACE("Using GLSL program %u\n", program_id);
|
|
|
|
|
|
|
|
GL_EXTCALL(glUseProgramObjectARB(program_id));
|
|
|
|
checkGLcall("glUseProgramObjectARB");
|
|
|
|
}
|
|
|
|
|
2007-11-20 17:40:54 +01:00
|
|
|
static void shader_glsl_destroy(IWineD3DBaseShader *iface) {
|
2008-11-25 14:36:09 +01:00
|
|
|
const struct list *linked_programs;
|
2007-11-20 17:40:54 +01:00
|
|
|
IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *) iface;
|
2008-07-08 21:44:20 +02:00
|
|
|
IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)This->baseShader.device;
|
2009-02-03 09:36:07 +01:00
|
|
|
struct shader_glsl_priv *priv = device->shader_priv;
|
2008-11-25 14:36:09 +01:00
|
|
|
const WineD3D_GL_Info *gl_info = &device->adapter->gl_info;
|
2008-11-24 11:55:50 +01:00
|
|
|
IWineD3DPixelShaderImpl *ps = NULL;
|
|
|
|
IWineD3DVertexShaderImpl *vs = NULL;
|
2007-11-20 17:40:54 +01:00
|
|
|
|
|
|
|
/* Note: Do not use QueryInterface here to find out which shader type this is because this code
|
|
|
|
* can be called from IWineD3DBaseShader::Release
|
|
|
|
*/
|
2008-12-15 12:10:14 +01:00
|
|
|
char pshader = shader_is_pshader_version(This->baseShader.reg_maps.shader_version);
|
2007-11-20 17:40:54 +01:00
|
|
|
|
2008-11-20 13:27:42 +01:00
|
|
|
if(pshader) {
|
2008-11-24 11:55:50 +01:00
|
|
|
ps = (IWineD3DPixelShaderImpl *) This;
|
|
|
|
if(ps->num_gl_shaders == 0) return;
|
2008-11-20 13:27:42 +01:00
|
|
|
} else {
|
2008-11-24 11:55:50 +01:00
|
|
|
vs = (IWineD3DVertexShaderImpl *) This;
|
2009-02-05 19:44:32 +01:00
|
|
|
if(vs->num_gl_shaders == 0) return;
|
2008-11-20 13:27:42 +01:00
|
|
|
}
|
2008-11-24 11:55:50 +01:00
|
|
|
|
2007-11-20 17:40:54 +01:00
|
|
|
linked_programs = &This->baseShader.linked_programs;
|
|
|
|
|
|
|
|
TRACE("Deleting linked programs\n");
|
|
|
|
if (linked_programs->next) {
|
|
|
|
struct glsl_shader_prog_link *entry, *entry2;
|
|
|
|
|
|
|
|
if(pshader) {
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs, struct glsl_shader_prog_link, pshader_entry) {
|
2008-07-08 21:44:20 +02:00
|
|
|
delete_glsl_program_entry(priv, gl_info, entry);
|
2007-11-20 17:40:54 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs, struct glsl_shader_prog_link, vshader_entry) {
|
2008-07-08 21:44:20 +02:00
|
|
|
delete_glsl_program_entry(priv, gl_info, entry);
|
2007-11-20 17:40:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-24 11:55:50 +01:00
|
|
|
if(pshader) {
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
for(i = 0; i < ps->num_gl_shaders; i++) {
|
|
|
|
TRACE("deleting pshader %u\n", ps->gl_shaders[i].prgId);
|
|
|
|
GL_EXTCALL(glDeleteObjectARB(ps->gl_shaders[i].prgId));
|
|
|
|
checkGLcall("glDeleteObjectARB");
|
|
|
|
}
|
|
|
|
LEAVE_GL();
|
|
|
|
HeapFree(GetProcessHeap(), 0, ps->gl_shaders);
|
|
|
|
ps->gl_shaders = NULL;
|
|
|
|
ps->num_gl_shaders = 0;
|
2009-01-19 18:39:36 +01:00
|
|
|
ps->shader_array_size = 0;
|
2008-11-24 11:55:50 +01:00
|
|
|
} else {
|
2009-02-05 19:44:32 +01:00
|
|
|
UINT i;
|
|
|
|
|
2008-11-24 11:55:50 +01:00
|
|
|
ENTER_GL();
|
2009-02-05 19:44:32 +01:00
|
|
|
for(i = 0; i < vs->num_gl_shaders; i++) {
|
|
|
|
TRACE("deleting vshader %u\n", vs->gl_shaders[i].prgId);
|
|
|
|
GL_EXTCALL(glDeleteObjectARB(vs->gl_shaders[i].prgId));
|
|
|
|
checkGLcall("glDeleteObjectARB");
|
|
|
|
}
|
2008-11-24 11:55:50 +01:00
|
|
|
LEAVE_GL();
|
2009-02-05 19:44:32 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, vs->gl_shaders);
|
|
|
|
vs->gl_shaders = NULL;
|
|
|
|
vs->num_gl_shaders = 0;
|
|
|
|
vs->shader_array_size = 0;
|
2008-11-24 11:55:50 +01:00
|
|
|
}
|
2007-11-20 17:40:54 +01:00
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:08 +01:00
|
|
|
static unsigned int glsl_program_key_hash(const void *key)
|
|
|
|
{
|
2009-01-20 10:00:20 +01:00
|
|
|
const glsl_program_key_t *k = key;
|
2008-03-18 19:37:53 +01:00
|
|
|
|
2009-02-05 19:44:32 +01:00
|
|
|
unsigned int hash = ((DWORD_PTR) k->vshader) | ((DWORD_PTR) k->pshader) << 16;
|
2008-03-18 19:37:53 +01:00
|
|
|
hash += ~(hash << 15);
|
|
|
|
hash ^= (hash >> 10);
|
|
|
|
hash += (hash << 3);
|
|
|
|
hash ^= (hash >> 6);
|
|
|
|
hash += ~(hash << 11);
|
|
|
|
hash ^= (hash >> 16);
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:08 +01:00
|
|
|
static BOOL glsl_program_key_compare(const void *keya, const void *keyb)
|
|
|
|
{
|
2009-01-20 10:00:20 +01:00
|
|
|
const glsl_program_key_t *ka = keya;
|
|
|
|
const glsl_program_key_t *kb = keyb;
|
2008-03-18 19:37:53 +01:00
|
|
|
|
2008-11-21 19:48:36 +01:00
|
|
|
return ka->vshader == kb->vshader && ka->pshader == kb->pshader &&
|
2009-02-05 19:44:32 +01:00
|
|
|
(memcmp(&ka->ps_args, &kb->ps_args, sizeof(kb->ps_args)) == 0) &&
|
|
|
|
(memcmp(&ka->vs_args, &kb->vs_args, sizeof(kb->vs_args)) == 0);
|
2008-03-18 19:37:53 +01:00
|
|
|
}
|
|
|
|
|
2008-12-19 19:21:56 +01:00
|
|
|
static BOOL constant_heap_init(struct constant_heap *heap, unsigned int constant_count)
|
|
|
|
{
|
|
|
|
SIZE_T size = (constant_count + 1) * sizeof(*heap->entries) + constant_count * sizeof(*heap->positions);
|
|
|
|
void *mem = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
|
|
|
|
if (!mem)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate memory\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
heap->entries = mem;
|
|
|
|
heap->entries[1].version = 0;
|
|
|
|
heap->positions = (unsigned int *)(heap->entries + constant_count + 1);
|
|
|
|
heap->size = 1;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void constant_heap_free(struct constant_heap *heap)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, heap->entries);
|
|
|
|
}
|
|
|
|
|
2008-02-24 11:23:53 +01:00
|
|
|
static HRESULT shader_glsl_alloc(IWineD3DDevice *iface) {
|
|
|
|
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
|
2008-12-19 19:21:56 +01:00
|
|
|
const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
|
2008-07-08 21:44:20 +02:00
|
|
|
struct shader_glsl_priv *priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct shader_glsl_priv));
|
2008-12-19 19:21:56 +01:00
|
|
|
SIZE_T stack_size = wined3d_log2i(max(GL_LIMITS(vshader_constantsF), GL_LIMITS(pshader_constantsF))) + 1;
|
|
|
|
|
|
|
|
priv->stack = HeapAlloc(GetProcessHeap(), 0, stack_size * sizeof(*priv->stack));
|
|
|
|
if (!priv->stack)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate memory.\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, priv);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!constant_heap_init(&priv->vconst_heap, GL_LIMITS(vshader_constantsF)))
|
|
|
|
{
|
|
|
|
ERR("Failed to initialize vertex shader constant heap\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, priv->stack);
|
|
|
|
HeapFree(GetProcessHeap(), 0, priv);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!constant_heap_init(&priv->pconst_heap, GL_LIMITS(pshader_constantsF)))
|
|
|
|
{
|
|
|
|
ERR("Failed to initialize pixel shader constant heap\n");
|
|
|
|
constant_heap_free(&priv->vconst_heap);
|
|
|
|
HeapFree(GetProcessHeap(), 0, priv->stack);
|
|
|
|
HeapFree(GetProcessHeap(), 0, priv);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2008-07-08 21:44:20 +02:00
|
|
|
priv->glsl_program_lookup = hash_table_create(glsl_program_key_hash, glsl_program_key_compare);
|
2008-12-19 19:21:56 +01:00
|
|
|
priv->next_constant_version = 1;
|
|
|
|
|
2008-07-08 21:44:20 +02:00
|
|
|
This->shader_priv = priv;
|
2008-02-24 11:23:53 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void shader_glsl_free(IWineD3DDevice *iface) {
|
|
|
|
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
|
2008-11-25 14:36:09 +01:00
|
|
|
const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
|
2009-02-03 09:36:07 +01:00
|
|
|
struct shader_glsl_priv *priv = This->shader_priv;
|
2008-10-27 18:31:32 +01:00
|
|
|
int i;
|
2008-07-09 17:59:39 +02:00
|
|
|
|
2008-10-27 18:31:32 +01:00
|
|
|
for (i = 0; i < tex_type_count; ++i)
|
|
|
|
{
|
|
|
|
if (priv->depth_blt_program[i])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDeleteObjectARB(priv->depth_blt_program[i]));
|
|
|
|
}
|
2008-07-09 17:59:39 +02:00
|
|
|
}
|
|
|
|
|
2008-07-29 17:51:52 +02:00
|
|
|
hash_table_destroy(priv->glsl_program_lookup, NULL, NULL);
|
2008-12-19 19:21:56 +01:00
|
|
|
constant_heap_free(&priv->pconst_heap);
|
|
|
|
constant_heap_free(&priv->vconst_heap);
|
2008-07-09 17:59:39 +02:00
|
|
|
|
2008-02-24 11:23:53 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->shader_priv);
|
2008-03-18 19:31:24 +01:00
|
|
|
This->shader_priv = NULL;
|
2008-02-24 11:23:53 +01:00
|
|
|
}
|
|
|
|
|
2008-03-04 02:30:23 +01:00
|
|
|
static BOOL shader_glsl_dirty_const(IWineD3DDevice *iface) {
|
2008-03-18 15:21:13 +01:00
|
|
|
/* TODO: GL_EXT_bindable_uniform can be used to share constants across shaders */
|
2008-03-04 02:30:23 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-12-14 15:40:07 +01:00
|
|
|
static GLuint shader_glsl_generate_pshader(IWineD3DPixelShader *iface, SHADER_BUFFER *buffer, const struct ps_compile_args *args) {
|
2008-03-18 19:19:16 +01:00
|
|
|
IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
|
2008-11-25 14:36:09 +01:00
|
|
|
const struct shader_reg_maps *reg_maps = &This->baseShader.reg_maps;
|
2008-03-18 19:19:16 +01:00
|
|
|
CONST DWORD *function = This->baseShader.function;
|
|
|
|
const char *fragcolor;
|
2008-11-25 14:36:09 +01:00
|
|
|
const WineD3D_GL_Info *gl_info = &((IWineD3DDeviceImpl *)This->baseShader.device)->adapter->gl_info;
|
2008-03-18 19:19:16 +01:00
|
|
|
|
2008-11-20 13:27:42 +01:00
|
|
|
/* Create the hw GLSL shader object and assign it as the shader->prgId */
|
2008-03-18 19:19:16 +01:00
|
|
|
GLhandleARB shader_obj = GL_EXTCALL(glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB));
|
|
|
|
|
2008-06-30 23:03:47 +02:00
|
|
|
shader_addline(buffer, "#version 120\n");
|
|
|
|
|
2008-03-18 19:19:16 +01:00
|
|
|
if (GL_SUPPORT(ARB_DRAW_BUFFERS)) {
|
|
|
|
shader_addline(buffer, "#extension GL_ARB_draw_buffers : enable\n");
|
|
|
|
}
|
|
|
|
if (GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
|
|
|
|
/* The spec says that it doesn't have to be explicitly enabled, but the nvidia
|
|
|
|
* drivers write a warning if we don't do so
|
|
|
|
*/
|
|
|
|
shader_addline(buffer, "#extension GL_ARB_texture_rectangle : enable\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Base Declarations */
|
2008-12-15 19:31:52 +01:00
|
|
|
shader_generate_glsl_declarations( (IWineD3DBaseShader*) This, reg_maps, buffer, &GLINFO_LOCATION, args);
|
2008-03-18 19:19:16 +01:00
|
|
|
|
|
|
|
/* Pack 3.0 inputs */
|
2008-12-15 19:31:52 +01:00
|
|
|
if (reg_maps->shader_version >= WINED3DPS_VERSION(3,0) && args->vp_mode != vertexshader) {
|
|
|
|
pshader_glsl_input_pack(buffer, This->semantics_in, iface, args->vp_mode);
|
2008-03-18 19:19:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Base Shader Body */
|
|
|
|
shader_generate_main( (IWineD3DBaseShader*) This, buffer, reg_maps, function);
|
|
|
|
|
|
|
|
/* Pixel shaders < 2.0 place the resulting color in R0 implicitly */
|
2008-12-15 12:10:14 +01:00
|
|
|
if (reg_maps->shader_version < WINED3DPS_VERSION(2,0))
|
|
|
|
{
|
2008-03-18 19:19:16 +01:00
|
|
|
/* Some older cards like GeforceFX ones don't support multiple buffers, so also not gl_FragData */
|
|
|
|
if(GL_SUPPORT(ARB_DRAW_BUFFERS))
|
|
|
|
shader_addline(buffer, "gl_FragData[0] = R0;\n");
|
|
|
|
else
|
|
|
|
shader_addline(buffer, "gl_FragColor = R0;\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(GL_SUPPORT(ARB_DRAW_BUFFERS)) {
|
|
|
|
fragcolor = "gl_FragData[0]";
|
|
|
|
} else {
|
|
|
|
fragcolor = "gl_FragColor";
|
|
|
|
}
|
2008-12-14 15:42:04 +01:00
|
|
|
if(args->srgb_correction) {
|
2008-03-18 19:19:16 +01:00
|
|
|
shader_addline(buffer, "tmp0.xyz = pow(%s.xyz, vec3(%f, %f, %f)) * vec3(%f, %f, %f) - vec3(%f, %f, %f);\n",
|
|
|
|
fragcolor, srgb_pow, srgb_pow, srgb_pow, srgb_mul_high, srgb_mul_high, srgb_mul_high,
|
|
|
|
srgb_sub_high, srgb_sub_high, srgb_sub_high);
|
|
|
|
shader_addline(buffer, "tmp1.xyz = %s.xyz * srgb_mul_low.xyz;\n", fragcolor);
|
|
|
|
shader_addline(buffer, "%s.x = %s.x < srgb_comparison.x ? tmp1.x : tmp0.x;\n", fragcolor, fragcolor);
|
|
|
|
shader_addline(buffer, "%s.y = %s.y < srgb_comparison.y ? tmp1.y : tmp0.y;\n", fragcolor, fragcolor);
|
|
|
|
shader_addline(buffer, "%s.z = %s.z < srgb_comparison.z ? tmp1.z : tmp0.z;\n", fragcolor, fragcolor);
|
|
|
|
shader_addline(buffer, "%s = clamp(%s, 0.0, 1.0);\n", fragcolor, fragcolor);
|
|
|
|
}
|
|
|
|
/* Pixel shader < 3.0 do not replace the fog stage.
|
|
|
|
* This implements linear fog computation and blending.
|
|
|
|
* TODO: non linear fog
|
|
|
|
* NOTE: gl_Fog.start and gl_Fog.end don't hold fog start s and end e but
|
|
|
|
* -1/(e-s) and e/(e-s) respectively.
|
|
|
|
*/
|
2008-12-15 19:35:40 +01:00
|
|
|
if(reg_maps->shader_version < WINED3DPS_VERSION(3,0)) {
|
|
|
|
switch(args->fog) {
|
|
|
|
case FOG_OFF: break;
|
|
|
|
case FOG_LINEAR:
|
2008-12-14 17:00:21 +01:00
|
|
|
shader_addline(buffer, "float fogstart = -1.0 / (gl_Fog.end - gl_Fog.start);\n");
|
|
|
|
shader_addline(buffer, "float fogend = gl_Fog.end * -fogstart;\n");
|
|
|
|
shader_addline(buffer, "float Fog = clamp(gl_FogFragCoord * fogstart + fogend, 0.0, 1.0);\n");
|
2008-12-15 19:35:40 +01:00
|
|
|
shader_addline(buffer, "%s.xyz = mix(gl_Fog.color.xyz, %s.xyz, Fog);\n", fragcolor, fragcolor);
|
|
|
|
break;
|
|
|
|
case FOG_EXP:
|
2009-01-02 01:59:13 +01:00
|
|
|
/* Fog = e^(-gl_Fog.density * gl_FogFragCoord) */
|
|
|
|
shader_addline(buffer, "float Fog = exp(-gl_Fog.density * gl_FogFragCoord);\n");
|
2009-02-12 12:30:13 +01:00
|
|
|
shader_addline(buffer, "Fog = clamp(Fog, 0.0, 1.0);\n");
|
2009-01-02 01:59:13 +01:00
|
|
|
shader_addline(buffer, "%s.xyz = mix(gl_Fog.color.xyz, %s.xyz, Fog);\n", fragcolor, fragcolor);
|
2008-12-15 19:35:40 +01:00
|
|
|
break;
|
|
|
|
case FOG_EXP2:
|
2009-01-02 01:59:13 +01:00
|
|
|
/* Fog = e^(-(gl_Fog.density * gl_FogFragCoord)^2) */
|
|
|
|
shader_addline(buffer, "float Fog = exp(-gl_Fog.density * gl_Fog.density * gl_FogFragCoord * gl_FogFragCoord);\n");
|
2009-02-12 12:30:13 +01:00
|
|
|
shader_addline(buffer, "Fog = clamp(Fog, 0.0, 1.0);\n");
|
2009-01-02 01:59:13 +01:00
|
|
|
shader_addline(buffer, "%s.xyz = mix(gl_Fog.color.xyz, %s.xyz, Fog);\n", fragcolor, fragcolor);
|
2008-12-15 19:35:40 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-03-18 19:19:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
shader_addline(buffer, "}\n");
|
|
|
|
|
|
|
|
TRACE("Compiling shader object %u\n", shader_obj);
|
|
|
|
GL_EXTCALL(glShaderSourceARB(shader_obj, 1, (const char**)&buffer->buffer, NULL));
|
|
|
|
GL_EXTCALL(glCompileShaderARB(shader_obj));
|
|
|
|
print_glsl_info_log(&GLINFO_LOCATION, shader_obj);
|
|
|
|
|
|
|
|
/* Store the shader object */
|
2008-11-24 11:55:50 +01:00
|
|
|
return shader_obj;
|
2008-03-18 19:19:16 +01:00
|
|
|
}
|
|
|
|
|
2009-02-05 19:44:32 +01:00
|
|
|
static GLuint shader_glsl_generate_vshader(IWineD3DVertexShader *iface, SHADER_BUFFER *buffer, const struct vs_compile_args *args) {
|
2008-03-18 19:19:16 +01:00
|
|
|
IWineD3DVertexShaderImpl *This = (IWineD3DVertexShaderImpl *)iface;
|
2008-11-25 14:36:09 +01:00
|
|
|
const struct shader_reg_maps *reg_maps = &This->baseShader.reg_maps;
|
2008-03-18 19:19:16 +01:00
|
|
|
CONST DWORD *function = This->baseShader.function;
|
2008-11-25 14:36:09 +01:00
|
|
|
const WineD3D_GL_Info *gl_info = &((IWineD3DDeviceImpl *)This->baseShader.device)->adapter->gl_info;
|
2008-03-18 19:19:16 +01:00
|
|
|
|
2008-11-20 13:27:42 +01:00
|
|
|
/* Create the hw GLSL shader program and assign it as the shader->prgId */
|
2008-03-18 19:19:16 +01:00
|
|
|
GLhandleARB shader_obj = GL_EXTCALL(glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB));
|
|
|
|
|
2008-06-30 23:03:47 +02:00
|
|
|
shader_addline(buffer, "#version 120\n");
|
|
|
|
|
2008-03-18 19:19:16 +01:00
|
|
|
/* Base Declarations */
|
2008-12-15 19:31:52 +01:00
|
|
|
shader_generate_glsl_declarations( (IWineD3DBaseShader*) This, reg_maps, buffer, &GLINFO_LOCATION, NULL);
|
2008-03-18 19:19:16 +01:00
|
|
|
|
|
|
|
/* Base Shader Body */
|
|
|
|
shader_generate_main( (IWineD3DBaseShader*) This, buffer, reg_maps, function);
|
|
|
|
|
|
|
|
/* Unpack 3.0 outputs */
|
2008-12-15 12:10:14 +01:00
|
|
|
if (reg_maps->shader_version >= WINED3DVS_VERSION(3,0)) shader_addline(buffer, "order_ps_input(OUT);\n");
|
|
|
|
else shader_addline(buffer, "order_ps_input();\n");
|
2008-03-18 19:19:16 +01:00
|
|
|
|
2009-01-10 02:29:39 +01:00
|
|
|
/* The D3DRS_FOGTABLEMODE render state defines if the shader-generated fog coord is used
|
|
|
|
* or if the fragment depth is used. If the fragment depth is used(FOGTABLEMODE != NONE),
|
|
|
|
* the fog frag coord is thrown away. If the fog frag coord is used, but not written by
|
|
|
|
* the shader, it is set to 0.0(fully fogged, since start = 1.0, end = 0.0)
|
|
|
|
*/
|
|
|
|
if(args->fog_src == VS_FOG_Z) {
|
2008-03-18 19:19:16 +01:00
|
|
|
shader_addline(buffer, "gl_FogFragCoord = gl_Position.z;\n");
|
2009-01-10 02:29:39 +01:00
|
|
|
} else if (!reg_maps->fog) {
|
|
|
|
shader_addline(buffer, "gl_FogFragCoord = 0.0;\n");
|
|
|
|
}
|
2008-03-18 19:19:16 +01:00
|
|
|
|
|
|
|
/* Write the final position.
|
|
|
|
*
|
|
|
|
* OpenGL coordinates specify the center of the pixel while d3d coords specify
|
|
|
|
* the corner. The offsets are stored in z and w in posFixup. posFixup.y contains
|
|
|
|
* 1.0 or -1.0 to turn the rendering upside down for offscreen rendering. PosFixup.x
|
|
|
|
* contains 1.0 to allow a mad.
|
|
|
|
*/
|
|
|
|
shader_addline(buffer, "gl_Position.y = gl_Position.y * posFixup.y;\n");
|
|
|
|
shader_addline(buffer, "gl_Position.xy += posFixup.zw * gl_Position.ww;\n");
|
|
|
|
|
|
|
|
/* Z coord [0;1]->[-1;1] mapping, see comment in transform_projection in state.c
|
|
|
|
*
|
|
|
|
* Basically we want (in homogeneous coordinates) z = z * 2 - 1. However, shaders are run
|
|
|
|
* before the homogeneous divide, so we have to take the w into account: z = ((z / w) * 2 - 1) * w,
|
2008-09-10 11:08:40 +02:00
|
|
|
* which is the same as z = z * 2 - w.
|
2008-03-18 19:19:16 +01:00
|
|
|
*/
|
|
|
|
shader_addline(buffer, "gl_Position.z = gl_Position.z * 2.0 - gl_Position.w;\n");
|
|
|
|
|
|
|
|
shader_addline(buffer, "}\n");
|
|
|
|
|
|
|
|
TRACE("Compiling shader object %u\n", shader_obj);
|
|
|
|
GL_EXTCALL(glShaderSourceARB(shader_obj, 1, (const char**)&buffer->buffer, NULL));
|
|
|
|
GL_EXTCALL(glCompileShaderARB(shader_obj));
|
|
|
|
print_glsl_info_log(&GLINFO_LOCATION, shader_obj);
|
|
|
|
|
2009-02-05 19:44:32 +01:00
|
|
|
return shader_obj;
|
2008-03-18 19:19:16 +01:00
|
|
|
}
|
|
|
|
|
2008-11-25 14:36:09 +01:00
|
|
|
static void shader_glsl_get_caps(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct shader_caps *pCaps)
|
|
|
|
{
|
2008-03-22 14:27:53 +01:00
|
|
|
/* Nvidia Geforce6/7 or Ati R4xx/R5xx cards with GLSL support, support VS 3.0 but older Nvidia/Ati
|
|
|
|
* models with GLSL support only support 2.0. In case of nvidia we can detect VS 2.0 support using
|
|
|
|
* vs_nv_version which is based on NV_vertex_program.
|
|
|
|
* For Ati cards there's no way using glsl (it abstracts the lowlevel info away) and also not
|
|
|
|
* using ARB_vertex_program. It is safe to assume that when a card supports pixel shader 2.0 it
|
|
|
|
* supports vertex shader 2.0 too and the way around. We can detect ps2.0 using the maximum number
|
|
|
|
* of native instructions, so use that here. For more info see the pixel shader versioning code below.
|
|
|
|
*/
|
|
|
|
if((GLINFO_LOCATION.vs_nv_version == VS_VERSION_20) || (GLINFO_LOCATION.ps_arb_max_instructions <= 512))
|
|
|
|
pCaps->VertexShaderVersion = WINED3DVS_VERSION(2,0);
|
|
|
|
else
|
|
|
|
pCaps->VertexShaderVersion = WINED3DVS_VERSION(3,0);
|
|
|
|
TRACE_(d3d_caps)("Hardware vertex shader version %d.%d enabled (GLSL)\n", (pCaps->VertexShaderVersion >> 8) & 0xff, pCaps->VertexShaderVersion & 0xff);
|
|
|
|
pCaps->MaxVertexShaderConst = GL_LIMITS(vshader_constantsF);
|
|
|
|
|
|
|
|
/* Older DX9-class videocards (GeforceFX / Radeon >9500/X*00) only support pixel shader 2.0/2.0a/2.0b.
|
|
|
|
* In OpenGL the extensions related to GLSL abstract lowlevel GL info away which is needed
|
|
|
|
* to distinguish between 2.0 and 3.0 (and 2.0a/2.0b). In case of Nvidia we use their fragment
|
|
|
|
* program extensions. On other hardware including ATI GL_ARB_fragment_program offers the info
|
|
|
|
* in max native instructions. Intel and others also offer the info in this extension but they
|
|
|
|
* don't support GLSL (at least on Windows).
|
|
|
|
*
|
|
|
|
* PS2.0 requires at least 96 instructions, 2.0a/2.0b go up to 512. Assume that if the number
|
|
|
|
* of instructions is 512 or less we have to do with ps2.0 hardware.
|
|
|
|
* NOTE: ps3.0 hardware requires 512 or more instructions but ati and nvidia offer 'enough' (1024 vs 4096) on their most basic ps3.0 hardware.
|
|
|
|
*/
|
|
|
|
if((GLINFO_LOCATION.ps_nv_version == PS_VERSION_20) || (GLINFO_LOCATION.ps_arb_max_instructions <= 512))
|
|
|
|
pCaps->PixelShaderVersion = WINED3DPS_VERSION(2,0);
|
|
|
|
else
|
|
|
|
pCaps->PixelShaderVersion = WINED3DPS_VERSION(3,0);
|
|
|
|
|
|
|
|
/* FIXME: The following line is card dependent. -8.0 to 8.0 is the
|
|
|
|
* Direct3D minimum requirement.
|
|
|
|
*
|
|
|
|
* Both GL_ARB_fragment_program and GLSL require a "maximum representable magnitude"
|
|
|
|
* of colors to be 2^10, and 2^32 for other floats. Should we use 1024 here?
|
|
|
|
*
|
|
|
|
* The problem is that the refrast clamps temporary results in the shader to
|
|
|
|
* [-MaxValue;+MaxValue]. If the card's max value is bigger than the one we advertize here,
|
|
|
|
* then applications may miss the clamping behavior. On the other hand, if it is smaller,
|
|
|
|
* the shader will generate incorrect results too. Unfortunately, GL deliberately doesn't
|
|
|
|
* offer a way to query this.
|
|
|
|
*/
|
|
|
|
pCaps->PixelShader1xMaxValue = 8.0;
|
|
|
|
TRACE_(d3d_caps)("Hardware pixel shader version %d.%d enabled (GLSL)\n", (pCaps->PixelShaderVersion >> 8) & 0xff, pCaps->PixelShaderVersion & 0xff);
|
2008-03-18 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2008-12-03 14:53:43 +01:00
|
|
|
static BOOL shader_glsl_color_fixup_supported(struct color_fixup_desc fixup)
|
|
|
|
{
|
|
|
|
if (TRACE_ON(d3d_shader) && TRACE_ON(d3d))
|
|
|
|
{
|
|
|
|
TRACE("Checking support for fixup:\n");
|
|
|
|
dump_color_fixup_desc(fixup);
|
2008-08-07 21:51:35 +02:00
|
|
|
}
|
2008-12-03 14:53:43 +01:00
|
|
|
|
|
|
|
/* We support everything except YUV conversions. */
|
|
|
|
if (!is_yuv_fixup(fixup))
|
|
|
|
{
|
|
|
|
TRACE("[OK]\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("[FAILED]\n");
|
|
|
|
return FALSE;
|
2008-08-07 21:51:35 +02:00
|
|
|
}
|
|
|
|
|
2008-09-23 17:39:34 +02:00
|
|
|
static const SHADER_HANDLER shader_glsl_instruction_handler_table[WINED3DSIH_TABLE_SIZE] =
|
|
|
|
{
|
|
|
|
/* WINED3DSIH_ABS */ shader_glsl_map2gl,
|
|
|
|
/* WINED3DSIH_ADD */ shader_glsl_arith,
|
|
|
|
/* WINED3DSIH_BEM */ pshader_glsl_bem,
|
|
|
|
/* WINED3DSIH_BREAK */ shader_glsl_break,
|
|
|
|
/* WINED3DSIH_BREAKC */ shader_glsl_breakc,
|
|
|
|
/* WINED3DSIH_BREAKP */ NULL,
|
|
|
|
/* WINED3DSIH_CALL */ shader_glsl_call,
|
|
|
|
/* WINED3DSIH_CALLNZ */ shader_glsl_callnz,
|
|
|
|
/* WINED3DSIH_CMP */ shader_glsl_cmp,
|
|
|
|
/* WINED3DSIH_CND */ shader_glsl_cnd,
|
|
|
|
/* WINED3DSIH_CRS */ shader_glsl_cross,
|
|
|
|
/* WINED3DSIH_DCL */ NULL,
|
|
|
|
/* WINED3DSIH_DEF */ NULL,
|
|
|
|
/* WINED3DSIH_DEFB */ NULL,
|
|
|
|
/* WINED3DSIH_DEFI */ NULL,
|
|
|
|
/* WINED3DSIH_DP2ADD */ pshader_glsl_dp2add,
|
|
|
|
/* WINED3DSIH_DP3 */ shader_glsl_dot,
|
|
|
|
/* WINED3DSIH_DP4 */ shader_glsl_dot,
|
|
|
|
/* WINED3DSIH_DST */ shader_glsl_dst,
|
|
|
|
/* WINED3DSIH_DSX */ shader_glsl_map2gl,
|
|
|
|
/* WINED3DSIH_DSY */ shader_glsl_map2gl,
|
|
|
|
/* WINED3DSIH_ELSE */ shader_glsl_else,
|
|
|
|
/* WINED3DSIH_ENDIF */ shader_glsl_end,
|
|
|
|
/* WINED3DSIH_ENDLOOP */ shader_glsl_end,
|
|
|
|
/* WINED3DSIH_ENDREP */ shader_glsl_end,
|
|
|
|
/* WINED3DSIH_EXP */ shader_glsl_map2gl,
|
|
|
|
/* WINED3DSIH_EXPP */ shader_glsl_expp,
|
|
|
|
/* WINED3DSIH_FRC */ shader_glsl_map2gl,
|
|
|
|
/* WINED3DSIH_IF */ shader_glsl_if,
|
|
|
|
/* WINED3DSIH_IFC */ shader_glsl_ifc,
|
|
|
|
/* WINED3DSIH_LABEL */ shader_glsl_label,
|
|
|
|
/* WINED3DSIH_LIT */ shader_glsl_lit,
|
|
|
|
/* WINED3DSIH_LOG */ shader_glsl_log,
|
|
|
|
/* WINED3DSIH_LOGP */ shader_glsl_log,
|
|
|
|
/* WINED3DSIH_LOOP */ shader_glsl_loop,
|
|
|
|
/* WINED3DSIH_LRP */ shader_glsl_lrp,
|
|
|
|
/* WINED3DSIH_M3x2 */ shader_glsl_mnxn,
|
|
|
|
/* WINED3DSIH_M3x3 */ shader_glsl_mnxn,
|
|
|
|
/* WINED3DSIH_M3x4 */ shader_glsl_mnxn,
|
|
|
|
/* WINED3DSIH_M4x3 */ shader_glsl_mnxn,
|
|
|
|
/* WINED3DSIH_M4x4 */ shader_glsl_mnxn,
|
|
|
|
/* WINED3DSIH_MAD */ shader_glsl_mad,
|
|
|
|
/* WINED3DSIH_MAX */ shader_glsl_map2gl,
|
|
|
|
/* WINED3DSIH_MIN */ shader_glsl_map2gl,
|
|
|
|
/* WINED3DSIH_MOV */ shader_glsl_mov,
|
|
|
|
/* WINED3DSIH_MOVA */ shader_glsl_mov,
|
|
|
|
/* WINED3DSIH_MUL */ shader_glsl_arith,
|
|
|
|
/* WINED3DSIH_NOP */ NULL,
|
|
|
|
/* WINED3DSIH_NRM */ shader_glsl_map2gl,
|
|
|
|
/* WINED3DSIH_PHASE */ NULL,
|
|
|
|
/* WINED3DSIH_POW */ shader_glsl_pow,
|
|
|
|
/* WINED3DSIH_RCP */ shader_glsl_rcp,
|
|
|
|
/* WINED3DSIH_REP */ shader_glsl_rep,
|
|
|
|
/* WINED3DSIH_RET */ NULL,
|
|
|
|
/* WINED3DSIH_RSQ */ shader_glsl_rsq,
|
|
|
|
/* WINED3DSIH_SETP */ NULL,
|
|
|
|
/* WINED3DSIH_SGE */ shader_glsl_compare,
|
|
|
|
/* WINED3DSIH_SGN */ shader_glsl_map2gl,
|
|
|
|
/* WINED3DSIH_SINCOS */ shader_glsl_sincos,
|
|
|
|
/* WINED3DSIH_SLT */ shader_glsl_compare,
|
|
|
|
/* WINED3DSIH_SUB */ shader_glsl_arith,
|
|
|
|
/* WINED3DSIH_TEX */ pshader_glsl_tex,
|
|
|
|
/* WINED3DSIH_TEXBEM */ pshader_glsl_texbem,
|
|
|
|
/* WINED3DSIH_TEXBEML */ pshader_glsl_texbem,
|
|
|
|
/* WINED3DSIH_TEXCOORD */ pshader_glsl_texcoord,
|
|
|
|
/* WINED3DSIH_TEXDEPTH */ pshader_glsl_texdepth,
|
|
|
|
/* WINED3DSIH_TEXDP3 */ pshader_glsl_texdp3,
|
|
|
|
/* WINED3DSIH_TEXDP3TEX */ pshader_glsl_texdp3tex,
|
|
|
|
/* WINED3DSIH_TEXKILL */ pshader_glsl_texkill,
|
|
|
|
/* WINED3DSIH_TEXLDD */ NULL,
|
|
|
|
/* WINED3DSIH_TEXLDL */ shader_glsl_texldl,
|
|
|
|
/* WINED3DSIH_TEXM3x2DEPTH */ pshader_glsl_texm3x2depth,
|
|
|
|
/* WINED3DSIH_TEXM3x2PAD */ pshader_glsl_texm3x2pad,
|
|
|
|
/* WINED3DSIH_TEXM3x2TEX */ pshader_glsl_texm3x2tex,
|
|
|
|
/* WINED3DSIH_TEXM3x3 */ pshader_glsl_texm3x3,
|
|
|
|
/* WINED3DSIH_TEXM3x3DIFF */ NULL,
|
|
|
|
/* WINED3DSIH_TEXM3x3PAD */ pshader_glsl_texm3x3pad,
|
|
|
|
/* WINED3DSIH_TEXM3x3SPEC */ pshader_glsl_texm3x3spec,
|
|
|
|
/* WINED3DSIH_TEXM3x3TEX */ pshader_glsl_texm3x3tex,
|
|
|
|
/* WINED3DSIH_TEXM3x3VSPEC */ pshader_glsl_texm3x3vspec,
|
|
|
|
/* WINED3DSIH_TEXREG2AR */ pshader_glsl_texreg2ar,
|
|
|
|
/* WINED3DSIH_TEXREG2GB */ pshader_glsl_texreg2gb,
|
|
|
|
/* WINED3DSIH_TEXREG2RGB */ pshader_glsl_texreg2rgb,
|
|
|
|
};
|
|
|
|
|
2006-11-27 20:50:37 +01:00
|
|
|
const shader_backend_t glsl_shader_backend = {
|
2008-09-23 17:39:34 +02:00
|
|
|
shader_glsl_instruction_handler_table,
|
2008-07-06 14:00:52 +02:00
|
|
|
shader_glsl_select,
|
|
|
|
shader_glsl_select_depth_blt,
|
2008-07-10 17:57:35 +02:00
|
|
|
shader_glsl_deselect_depth_blt,
|
2008-12-17 17:07:25 +01:00
|
|
|
shader_glsl_update_float_vertex_constants,
|
|
|
|
shader_glsl_update_float_pixel_constants,
|
2008-07-06 14:00:52 +02:00
|
|
|
shader_glsl_load_constants,
|
|
|
|
shader_glsl_color_correction,
|
|
|
|
shader_glsl_destroy,
|
|
|
|
shader_glsl_alloc,
|
|
|
|
shader_glsl_free,
|
|
|
|
shader_glsl_dirty_const,
|
|
|
|
shader_glsl_generate_pshader,
|
|
|
|
shader_glsl_generate_vshader,
|
|
|
|
shader_glsl_get_caps,
|
2008-12-03 14:53:43 +01:00
|
|
|
shader_glsl_color_fixup_supported,
|
2006-11-27 20:50:37 +01:00
|
|
|
};
|