{
for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
- if(usage == shader->input[i].usage &&
- index == shader->input[i].index)
+ const sw::Shader::Semantic& input = shader->getInput(i);
+ if((usage == input.usage) && (index == input.index))
{
renderer->setInputStream(i, attribute);
{
for(int i = 0; i < MAX_VERTEX_OUTPUTS; i++)
{
- if((usage == shader->output[i][0].usage || (usage == D3DDECLUSAGE_POSITIONT && shader->output[i][0].usage == D3DDECLUSAGE_POSITION)) &&
- index == shader->output[i][0].index)
+ const sw::Shader::Semantic& output = shader->getOutput(i, 0);
+ if(((usage == output.usage) || (usage == D3DDECLUSAGE_POSITIONT && output.usage == D3DDECLUSAGE_POSITION)) &&
+ (index == output.index))
{
renderer->setInputStream(i, attribute);
case EvqConstReadOnly: return temporaryRegister(operand);
case EvqPosition: return varyingRegister(operand);
case EvqPointSize: return varyingRegister(operand);
- case EvqInstanceID: vertexShader->instanceIdDeclared = true; return 0;
- case EvqFragCoord: pixelShader->vPosDeclared = true; return 0;
- case EvqFrontFacing: pixelShader->vFaceDeclared = true; return 1;
+ case EvqInstanceID: vertexShader->declareInstanceId(); return 0;
+ case EvqFragCoord: pixelShader->declareVPos(); return 0;
+ case EvqFrontFacing: pixelShader->declareVFace(); return 1;
case EvqPointCoord: return varyingRegister(operand);
case EvqFragColor: return 0;
case EvqFragData: return fragmentOutputRegister(operand);
if(varying->getQualifier() == EvqPointCoord)
{
ASSERT(varying->isRegister());
- if(componentCount >= 1) pixelShader->semantic[var][0] = sw::Shader::Semantic(sw::Shader::USAGE_TEXCOORD, var);
- if(componentCount >= 2) pixelShader->semantic[var][1] = sw::Shader::Semantic(sw::Shader::USAGE_TEXCOORD, var);
- if(componentCount >= 3) pixelShader->semantic[var][2] = sw::Shader::Semantic(sw::Shader::USAGE_TEXCOORD, var);
- if(componentCount >= 4) pixelShader->semantic[var][3] = sw::Shader::Semantic(sw::Shader::USAGE_TEXCOORD, var);
+ pixelShader->setInput(var, componentCount, sw::Shader::Semantic(sw::Shader::USAGE_TEXCOORD, var));
}
else
{
{
bool flat = hasFlatQualifier(varying);
- if(componentCount >= 1) pixelShader->semantic[var + i][0] = sw::Shader::Semantic(sw::Shader::USAGE_COLOR, var + i, flat);
- if(componentCount >= 2) pixelShader->semantic[var + i][1] = sw::Shader::Semantic(sw::Shader::USAGE_COLOR, var + i, flat);
- if(componentCount >= 3) pixelShader->semantic[var + i][2] = sw::Shader::Semantic(sw::Shader::USAGE_COLOR, var + i, flat);
- if(componentCount >= 4) pixelShader->semantic[var + i][3] = sw::Shader::Semantic(sw::Shader::USAGE_COLOR, var + i, flat);
+ pixelShader->setInput(var + i, componentCount, sw::Shader::Semantic(sw::Shader::USAGE_COLOR, var + i, flat));
}
}
}
if(varying->getQualifier() == EvqPosition)
{
ASSERT(varying->isRegister());
- vertexShader->output[var][0] = sw::Shader::Semantic(sw::Shader::USAGE_POSITION, 0);
- vertexShader->output[var][1] = sw::Shader::Semantic(sw::Shader::USAGE_POSITION, 0);
- vertexShader->output[var][2] = sw::Shader::Semantic(sw::Shader::USAGE_POSITION, 0);
- vertexShader->output[var][3] = sw::Shader::Semantic(sw::Shader::USAGE_POSITION, 0);
- vertexShader->positionRegister = var;
+ vertexShader->setPositionRegister(var);
}
else if(varying->getQualifier() == EvqPointSize)
{
ASSERT(varying->isRegister());
- vertexShader->output[var][0] = sw::Shader::Semantic(sw::Shader::USAGE_PSIZE, 0);
- vertexShader->output[var][1] = sw::Shader::Semantic(sw::Shader::USAGE_PSIZE, 0);
- vertexShader->output[var][2] = sw::Shader::Semantic(sw::Shader::USAGE_PSIZE, 0);
- vertexShader->output[var][3] = sw::Shader::Semantic(sw::Shader::USAGE_PSIZE, 0);
- vertexShader->pointSizeRegister = var;
+ vertexShader->setPointSizeRegister(var);
}
else
{
{
for(int i = 0; i < registerCount; i++)
{
- vertexShader->input[index + i] = sw::Shader::Semantic(sw::Shader::USAGE_TEXCOORD, index + i);
+ vertexShader->setInput(index + i, sw::Shader::Semantic(sw::Shader::USAGE_TEXCOORD, index + i));
}
}
for(int i = 0; i < registers; i++)
{
- if(components >= 1) vertexBinary->output[out + i][0] = sw::Shader::Semantic(sw::Shader::USAGE_COLOR, in + i);
- if(components >= 2) vertexBinary->output[out + i][1] = sw::Shader::Semantic(sw::Shader::USAGE_COLOR, in + i);
- if(components >= 3) vertexBinary->output[out + i][2] = sw::Shader::Semantic(sw::Shader::USAGE_COLOR, in + i);
- if(components >= 4) vertexBinary->output[out + i][3] = sw::Shader::Semantic(sw::Shader::USAGE_COLOR, in + i);
+ vertexBinary->setOutput(out + i, components, sw::Shader::Semantic(sw::Shader::USAGE_COLOR, in + i));
}
}
else // Vertex varying is declared but not written to
{
for(int i = 0; i < registers; i++)
{
- if(components >= 1) pixelBinary->semantic[in + i][0] = sw::Shader::Semantic();
- if(components >= 2) pixelBinary->semantic[in + i][1] = sw::Shader::Semantic();
- if(components >= 3) pixelBinary->semantic[in + i][2] = sw::Shader::Semantic();
- if(components >= 4) pixelBinary->semantic[in + i][3] = sw::Shader::Semantic();
+ pixelBinary->setInput(in + i, components, sw::Shader::Semantic());
}
}
for(int i = 0; i < registers; i++)
{
- bool flat = pixelBinary->semantic[in + i][0].flat;
-
- if(components >= 1) vertexBinary->output[out + i][0] = sw::Shader::Semantic(sw::Shader::USAGE_COLOR, in + i, flat);
- if(components >= 2) vertexBinary->output[out + i][1] = sw::Shader::Semantic(sw::Shader::USAGE_COLOR, in + i, flat);
- if(components >= 3) vertexBinary->output[out + i][2] = sw::Shader::Semantic(sw::Shader::USAGE_COLOR, in + i, flat);
- if(components >= 4) vertexBinary->output[out + i][3] = sw::Shader::Semantic(sw::Shader::USAGE_COLOR, in + i, flat);
+ vertexBinary->setOutput(out + i, components, sw::Shader::Semantic(sw::Shader::USAGE_COLOR, in + i, pixelBinary->getInput(in + i, 0).flat));
}
}
else // Vertex varying is declared but not written to
{
for(int i = 0; i < registers; i++)
{
- if(components >= 1) pixelBinary->semantic[in + i][0] = sw::Shader::Semantic();
- if(components >= 2) pixelBinary->semantic[in + i][1] = sw::Shader::Semantic();
- if(components >= 3) pixelBinary->semantic[in + i][2] = sw::Shader::Semantic();
- if(components >= 4) pixelBinary->semantic[in + i][3] = sw::Shader::Semantic();
+ pixelBinary->setInput(in + i, components, sw::Shader::Semantic());
}
}
{
if(!preTransformed)
{
- if(vertexShader->output[T0 + coordinate][component].usage == Shader::USAGE_TEXCOORD)
+ if(vertexShader->getOutput(T0 + coordinate, component).usage == Shader::USAGE_TEXCOORD)
{
hasTexture = true;
}
if(vertexShader)
{
- vertexDiffuse = vertexShader->output[C0][component].active();
+ vertexDiffuse = vertexShader->getOutput(C0, component).active();
}
else if(!preTransformed)
{
}
else
{
- vertexSpecular = vertexShader->output[C1][component].active();
+ vertexSpecular = vertexShader->getOutput(C1, component).active();
}
// Pixel processor requires specular component
{
for(int component = 0; component < 4; component++)
{
- const Shader::Semantic &semantic = context->pixelShader->semantic[interpolant][component];
+ const Shader::Semantic &semantic = context->pixelShader->getInput(interpolant, component);
if(semantic.active())
{
{
for(int component = 0; component < 4; component++)
{
- state.interpolant[interpolant].centroid = context->pixelShader->semantic[interpolant][0].centroid;
+ state.interpolant[interpolant].centroid = context->pixelShader->getInput(interpolant, 0).centroid;
}
}
}
bool QuadRasterizer::interpolateZ() const
{
- return state.depthTestActive || state.pixelFogActive() || (shader && shader->vPosDeclared && fullPixelPositionRegister);
+ return state.depthTestActive || state.pixelFogActive() || (shader && shader->isVPosDeclared() && fullPixelPositionRegister);
}
bool QuadRasterizer::interpolateW() const
{
- return state.perspective || (shader && shader->vPosDeclared && fullPixelPositionRegister);
+ return state.perspective || (shader && shader->isVPosDeclared() && fullPixelPositionRegister);
}
}
draw->vsDirtyConstB = 0;
}
- if(context->vertexShader->instanceIdDeclared)
+ if(context->vertexShader->isInstanceIdDeclared())
{
data->instanceID = context->instanceID;
}
{
State state;
- bool vPosZW = (context->pixelShader && context->pixelShader->vPosDeclared && fullPixelPositionRegister);
+ bool vPosZW = (context->pixelShader && context->pixelShader->isVPosDeclared() && fullPixelPositionRegister);
state.isDrawPoint = context->isDrawPoint(true);
state.isDrawLine = context->isDrawLine(true);
state.cullMode = context->cullMode;
state.twoSidedStencil = context->stencilActive() && context->twoSidedStencil;
state.slopeDepthBias = slopeDepthBias != 0.0f;
- state.vFace = context->pixelShader && context->pixelShader->vFaceDeclared;
+ state.vFace = context->pixelShader && context->pixelShader->isVFaceDeclared();
state.positionRegister = Pos;
state.pointSizeRegister = Unused;
if(context->vertexShader)
{
- state.positionRegister = context->vertexShader->positionRegister;
- state.pointSizeRegister = context->vertexShader->pointSizeRegister;
+ state.positionRegister = context->vertexShader->getPositionRegister();
+ state.pointSizeRegister = context->vertexShader->getPointSizeRegister();
}
else if(context->pointSizeActive())
{
for(int component = 0; component < 4; component++)
{
int project = context->isProjectionComponent(interpolant - 2, component) ? 1 : 0;
- const Shader::Semantic& semantic = context->pixelShader->semantic[interpolant][component - project];
+ const Shader::Semantic& semantic = context->pixelShader->getInput(interpolant, component - project);
if(semantic.active())
{
int input = interpolant;
for(int i = 0; i < MAX_VERTEX_OUTPUTS; i++)
{
- if(semantic == context->vertexShader->output[i][component - project])
+ if(semantic == context->vertexShader->getOutput(i, component - project))
{
input = i;
break;
{
for(int component = 0; component < 4; component++)
{
- const Shader::Semantic& semantic = context->pixelShader->semantic[interpolant][component];
+ const Shader::Semantic& semantic = context->pixelShader->getInput(interpolant, component);
switch(semantic.usage)
{
state.fixedFunction = !context->vertexShader && context->pixelShaderVersion() < 0x0300;
state.textureSampling = context->vertexShader ? context->vertexShader->containsTextureSampling() : false;
- state.positionRegister = context->vertexShader ? context->vertexShader->positionRegister : Pos;
- state.pointSizeRegister = context->vertexShader ? context->vertexShader->pointSizeRegister : Pts;
+ state.positionRegister = context->vertexShader ? context->vertexShader->getPositionRegister() : Pos;
+ state.pointSizeRegister = context->vertexShader ? context->vertexShader->getPointSizeRegister() : Pts;
state.vertexBlendMatrixCount = context->vertexBlendMatrixCountActive();
state.indexedVertexBlendEnable = context->indexedVertexBlendActive();
{
for(int i = 0; i < MAX_VERTEX_OUTPUTS; i++)
{
- state.output[i].xWrite = context->vertexShader->output[i][0].active();
- state.output[i].yWrite = context->vertexShader->output[i][1].active();
- state.output[i].zWrite = context->vertexShader->output[i][2].active();
- state.output[i].wWrite = context->vertexShader->output[i][3].active();
+ state.output[i].xWrite = context->vertexShader->getOutput(i, 0).active();
+ state.output[i].yWrite = context->vertexShader->getOutput(i, 1).active();
+ state.output[i].zWrite = context->vertexShader->getOutput(i, 2).active();
+ state.output[i].wWrite = context->vertexShader->getOutput(i, 3).active();
}
}
else if(!context->preTransformed || context->pixelShaderVersion() < 0x0300)
{
if(shader->getVersion() >= 0x0300)
{
- if(shader->vPosDeclared)
+ if(shader->isVPosDeclared())
{
if(!halfIntegerCoordinates)
{
}
}
- if(shader->vFaceDeclared)
+ if(shader->isVFaceDeclared())
{
Float4 area = *Pointer<Float>(primitive + OFFSET(Primitive, area));
Float4 face = booleanFaceRegister ? Float4(As<Float4>(CmpNLT(area, Float4(0.0f)))) : area;
append(new sw::Shader::Instruction(*ps->getInstruction(i)));
}
- memcpy(semantic, ps->semantic, sizeof(semantic));
+ memcpy(input, ps->input, sizeof(input));
vPosDeclared = ps->vPosDeclared;
vFaceDeclared = ps->vFaceDeclared;
usedSamplers = ps->usedSamplers;
bool PixelShader::usesDiffuse(int component) const
{
- return semantic[0][component].active();
+ return input[0][component].active();
}
bool PixelShader::usesSpecular(int component) const
{
- return semantic[1][component].active();
+ return input[1][component].active();
}
bool PixelShader::usesTexture(int coordinate, int component) const
{
- return semantic[2 + coordinate][component].active();
+ return input[2 + coordinate][component].active();
+ }
+
+ void PixelShader::setInput(int inputIdx, int nbComponents, const sw::Shader::Semantic& semantic)
+ {
+ for(int i = 0; i < nbComponents; ++i)
+ {
+ input[inputIdx][i] = semantic;
+ }
+ }
+
+ const sw::Shader::Semantic& PixelShader::getInput(int inputIdx, int component) const
+ {
+ return input[inputIdx][component];
}
void PixelShader::analyze()
if(version < 0x0300)
{
// Set default mapping; disable unused interpolants below
- semantic[0][0] = Semantic(Shader::USAGE_COLOR, 0);
- semantic[0][1] = Semantic(Shader::USAGE_COLOR, 0);
- semantic[0][2] = Semantic(Shader::USAGE_COLOR, 0);
- semantic[0][3] = Semantic(Shader::USAGE_COLOR, 0);
+ input[0][0] = Semantic(Shader::USAGE_COLOR, 0);
+ input[0][1] = Semantic(Shader::USAGE_COLOR, 0);
+ input[0][2] = Semantic(Shader::USAGE_COLOR, 0);
+ input[0][3] = Semantic(Shader::USAGE_COLOR, 0);
- semantic[1][0] = Semantic(Shader::USAGE_COLOR, 1);
- semantic[1][1] = Semantic(Shader::USAGE_COLOR, 1);
- semantic[1][2] = Semantic(Shader::USAGE_COLOR, 1);
- semantic[1][3] = Semantic(Shader::USAGE_COLOR, 1);
+ input[1][0] = Semantic(Shader::USAGE_COLOR, 1);
+ input[1][1] = Semantic(Shader::USAGE_COLOR, 1);
+ input[1][2] = Semantic(Shader::USAGE_COLOR, 1);
+ input[1][3] = Semantic(Shader::USAGE_COLOR, 1);
for(int i = 0; i < 8; i++)
{
- semantic[2 + i][0] = Semantic(Shader::USAGE_TEXCOORD, i);
- semantic[2 + i][1] = Semantic(Shader::USAGE_TEXCOORD, i);
- semantic[2 + i][2] = Semantic(Shader::USAGE_TEXCOORD, i);
- semantic[2 + i][3] = Semantic(Shader::USAGE_TEXCOORD, i);
+ input[2 + i][0] = Semantic(Shader::USAGE_TEXCOORD, i);
+ input[2 + i][1] = Semantic(Shader::USAGE_TEXCOORD, i);
+ input[2 + i][2] = Semantic(Shader::USAGE_TEXCOORD, i);
+ input[2 + i][3] = Semantic(Shader::USAGE_TEXCOORD, i);
}
Shader::SamplerType samplerType[16];
{
if(!interpolant[index][component])
{
- semantic[index][component] = Semantic();
+ input[index][component] = Semantic();
}
}
}
unsigned char mask = instruction[i]->dst.mask;
unsigned char reg = instruction[i]->dst.index;
- if(mask & 0x01) semantic[reg][0] = Semantic(usage, index);
- if(mask & 0x02) semantic[reg][1] = Semantic(usage, index);
- if(mask & 0x04) semantic[reg][2] = Semantic(usage, index);
- if(mask & 0x08) semantic[reg][3] = Semantic(usage, index);
+ if(mask & 0x01) input[reg][0] = Semantic(usage, index);
+ if(mask & 0x02) input[reg][1] = Semantic(usage, index);
+ if(mask & 0x04) input[reg][2] = Semantic(usage, index);
+ if(mask & 0x08) input[reg][3] = Semantic(usage, index);
}
else if(instruction[i]->dst.type == Shader::PARAMETER_MISCTYPE)
{
switch(instruction[i]->dst.type)
{
case Shader::PARAMETER_INPUT:
- semantic[reg][0].centroid = centroid;
+ input[reg][0].centroid = centroid;
break;
case Shader::PARAMETER_TEXTURE:
- semantic[2 + reg][0].centroid = centroid;
+ input[2 + reg][0].centroid = centroid;
break;
default:
break;
bool usesSpecular(int component) const;
bool usesTexture(int coordinate, int component) const;
- virtual void analyze();
+ void setInput(int inputIdx, int nbComponents, const Semantic& semantic);
+ const Semantic& getInput(int inputIdx, int component) const;
- Semantic semantic[MAX_FRAGMENT_INPUTS][4]; // FIXME: Private
-
- bool vPosDeclared;
- bool vFaceDeclared;
+ void declareVPos() { vPosDeclared = true; }
+ void declareVFace() { vFaceDeclared = true; }
+ bool isVPosDeclared() const { return vPosDeclared; }
+ bool isVFaceDeclared() const { return vFaceDeclared; }
private:
+ void analyze();
void analyzeZOverride();
void analyzeKill();
void analyzeInterpolants();
+ Semantic input[MAX_FRAGMENT_INPUTS][4];
+
+ bool vPosDeclared;
+ bool vFaceDeclared;
bool zOverride;
bool kill;
bool centroid;
};
void optimize();
- virtual void analyze() = 0;
// FIXME: Private
unsigned int dirtyConstantsF;
enableContinue = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
}
- if(shader->instanceIdDeclared)
+ if(shader->isInstanceIdDeclared())
{
instanceID = *Pointer<Int>(data + OFFSET(DrawData,instanceID));
}
{
for(int i = 0; i < MAX_VERTEX_OUTPUTS; i++)
{
- unsigned char usage = shader->output[i][0].usage;
+ unsigned char usage = shader->getOutput(i, 0).usage;
switch(usage)
{
positionRegister = Pos;
pointSizeRegister = Unused;
instanceIdDeclared = false;
+ textureSampling = false;
for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
positionRegister = Pos;
pointSizeRegister = Unused;
instanceIdDeclared = false;
+ textureSampling = false;
for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
return textureSampling;
}
+ void VertexShader::setInput(int inputIdx, const sw::Shader::Semantic& semantic)
+ {
+ input[inputIdx] = semantic;
+ }
+
+ void VertexShader::setOutput(int outputIdx, int nbComponents, const sw::Shader::Semantic& semantic)
+ {
+ for(int i = 0; i < nbComponents; ++i)
+ {
+ output[outputIdx][i] = semantic;
+ }
+ }
+
+ void VertexShader::setPositionRegister(int posReg)
+ {
+ setOutput(posReg, 4, sw::Shader::Semantic(sw::Shader::USAGE_POSITION, 0));
+ positionRegister = posReg;
+ }
+
+ void VertexShader::setPointSizeRegister(int ptSizeReg)
+ {
+ setOutput(ptSizeReg, 4, sw::Shader::Semantic(sw::Shader::USAGE_PSIZE, 0));
+ pointSizeRegister = ptSizeReg;
+ }
+
+ const sw::Shader::Semantic& VertexShader::getInput(int inputIdx) const
+ {
+ return input[inputIdx];
+ }
+
+ const sw::Shader::Semantic& VertexShader::getOutput(int outputIdx, int component) const
+ {
+ return output[outputIdx][component];
+ }
+
void VertexShader::analyze()
{
analyzeInput();
static int validate(const unsigned long *const token); // Returns number of instructions if valid
bool containsTextureSampling() const;
- virtual void analyze();
-
- int positionRegister; // FIXME: Private
- int pointSizeRegister; // FIXME: Private
-
- bool instanceIdDeclared;
-
- Semantic input[MAX_VERTEX_INPUTS]; // FIXME: Private
- Semantic output[MAX_VERTEX_OUTPUTS][4]; // FIXME: Private
+ void setInput(int inputIdx, const Semantic& semantic);
+ void setOutput(int outputIdx, int nbComponents, const Semantic& semantic);
+ void setPositionRegister(int posReg);
+ void setPointSizeRegister(int ptSizeReg);
+ void declareInstanceId() { instanceIdDeclared = true; }
+
+ const Semantic& getInput(int inputIdx) const;
+ const Semantic& getOutput(int outputIdx, int component) const;
+ int getPositionRegister() const { return positionRegister; }
+ int getPointSizeRegister() const { return pointSizeRegister; }
+ bool isInstanceIdDeclared() const { return instanceIdDeclared; }
private:
+ void analyze();
void analyzeInput();
void analyzeOutput();
void analyzeTextureSampling();
+ Semantic input[MAX_VERTEX_INPUTS];
+ Semantic output[MAX_VERTEX_OUTPUTS][4];
+
+ int positionRegister;
+ int pointSizeRegister;
+
+ bool instanceIdDeclared;
bool textureSampling;
};
}