wined3d: Keep pshader and vshader constants in GLSL separate.

GLSL uniforms have as scope the entire program.
To prevent conflicts, name pshader and vshader constants differently.
Based on a patch by Jason Green.
This commit is contained in:
Ivan Gyurdiev 2006-06-12 03:00:03 -04:00 committed by Alexandre Julliard
parent 0d08316523
commit 14a52e5c09
3 changed files with 27 additions and 12 deletions

View File

@ -725,7 +725,10 @@ void shader_generate_glsl_declarations(
char pshader = shader_is_pshader_version(This->baseShader.hex_version);
/* Declare the constants (aka uniforms) */
shader_addline(buffer, "uniform vec4 C[%u];\n", This->baseShader.limits.constant_float);
if (pshader)
shader_addline(buffer, "uniform vec4 PC[%u];\n", This->baseShader.limits.constant_float);
else
shader_addline(buffer, "uniform vec4 VC[%u];\n", This->baseShader.limits.constant_float);
/* Declare texture samplers */
for (i = 0; i < This->baseShader.limits.sampler; i++) {

View File

@ -1723,7 +1723,8 @@ void drawPrimLoadPSamplersGLSL(
void drawPrimLoadConstantsGLSL_F(IWineD3DDevice* iface,
unsigned max_constants,
float* constants,
BOOL* constants_set) {
BOOL* constants_set,
char is_pshader) {
IWineD3DDeviceImpl* This = (IWineD3DDeviceImpl *)iface;
GLhandleARB programId = This->stateBlock->shaderPrgId;
@ -1738,12 +1739,15 @@ void drawPrimLoadConstantsGLSL_F(IWineD3DDevice* iface,
for (i=0; i<max_constants; ++i) {
if (NULL == constants_set || constants_set[i]) {
const char* prefix = is_pshader? "PC":"VC";
TRACE_(d3d_shader)("Loading constants %i: %f, %f, %f, %f\n",
i, constants[i*4], constants[i*4+1], constants[i*4+2], constants[i*4+3]);
/* TODO: Benchmark and see if it would be beneficial to store the
* locations of the constants to avoid looking up each time */
snprintf(tmp_name, sizeof(tmp_name), "C[%i]", i);
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 */
@ -1798,13 +1802,13 @@ void drawPrimLoadConstants(IWineD3DDevice *iface,
if (NULL != vertexDeclaration && NULL != vertexDeclaration->constants) {
/* Load DirectX 8 float constants/uniforms for vertex shader */
drawPrimLoadConstantsGLSL_F(iface, WINED3D_VSHADER_MAX_CONSTANTS,
vertexDeclaration->constants, NULL);
vertexDeclaration->constants, NULL, 0);
}
/* Load DirectX 9 float constants/uniforms for vertex shader */
drawPrimLoadConstantsGLSL_F(iface, WINED3D_VSHADER_MAX_CONSTANTS,
This->stateBlock->vertexShaderConstantF,
This->stateBlock->set.vertexShaderConstantsF);
This->stateBlock->set.vertexShaderConstantsF, 0);
/* TODO: Load boolean & integer constants for vertex shader */
}
@ -1816,7 +1820,7 @@ void drawPrimLoadConstants(IWineD3DDevice *iface,
/* Load DirectX 9 float constants/uniforms for pixel shader */
drawPrimLoadConstantsGLSL_F(iface, WINED3D_PSHADER_MAX_CONSTANTS,
This->stateBlock->pixelShaderConstantF,
This->stateBlock->set.pixelShaderConstantsF);
This->stateBlock->set.pixelShaderConstantsF, 1);
/* TODO: Load boolean & integer constants for pixel shader */
}

View File

@ -205,6 +205,9 @@ static void shader_glsl_get_register_name(
}
break;
case D3DSPR_CONST:
{
const char* prefix = pshader? "PC":"VC";
if (arg->reg_maps->constantsF[reg]) {
/* Use a local constant declared by "dcl" */
@ -214,7 +217,7 @@ static void shader_glsl_get_register_name(
* local constant. */
FIXME("Relative addressing not yet supported on named constants\n");
} else {
sprintf(tmpStr, "C%lu", reg);
sprintf(tmpStr, "%s%lu", prefix, reg);
}
} else {
/* Use a global constant declared in Set____ShaderConstantF() */
@ -224,16 +227,17 @@ static void shader_glsl_get_register_name(
if (D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 2) {
char relStr[100], relReg[50], relMask[6];
shader_glsl_add_param(arg, addr_token, 0, TRUE, relReg, relMask, relStr);
sprintf(tmpStr, "C[%s + %lu]", relStr, reg);
sprintf(tmpStr, "%s[%s + %lu]", prefix, relStr, reg);
} else {
sprintf(tmpStr, "C[A0.x + %lu]", reg);
sprintf(tmpStr, "%s[A0.x + %lu]", prefix, reg);
}
} else {
/* Just a normal global constant - no relative addressing */
sprintf(tmpStr, "C[%lu]", reg);
sprintf(tmpStr, "%s[%lu]", prefix, reg);
}
}
break;
break;
}
case D3DSPR_TEXTURE: /* case D3DSPR_ADDR: */
if (pshader) {
sprintf(tmpStr, "T%lu", reg);
@ -710,8 +714,12 @@ void shader_glsl_def(SHADER_OPCODE_ARG* arg) {
DWORD reg = arg->dst & D3DSP_REGNUM_MASK;
IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) arg->shader;
char pshader = shader_is_pshader_version(This->baseShader.hex_version);
const char* prefix = pshader? "PC":"VC";
shader_addline(arg->buffer,
"const vec4 C%lu = { %f, %f, %f, %f };\n", reg,
"const vec4 %s%lu = { %f, %f, %f, %f };\n", prefix, reg,
*((const float *)(arg->src + 0)),
*((const float *)(arg->src + 1)),
*((const float *)(arg->src + 2)),