Shader cleanup A couple of class members from PixelShader and VertexShader were still public. Fixed that in this cleanup. Change-Id: I2dfaac7fd4cecdc791f1ef7236148e74c4b5b486 Reviewed-on: https://swiftshader-review.googlesource.com/5850 Tested-by: Alexis Hétu <sugoi@google.com> Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/Shader/PixelProgram.cpp b/src/Shader/PixelProgram.cpp index 5c04196..1f50547 100644 --- a/src/Shader/PixelProgram.cpp +++ b/src/Shader/PixelProgram.cpp
@@ -28,7 +28,7 @@ { if(shader->getVersion() >= 0x0300) { - if(shader->vPosDeclared) + if(shader->isVPosDeclared()) { if(!halfIntegerCoordinates) { @@ -48,7 +48,7 @@ } } - 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;
diff --git a/src/Shader/PixelShader.cpp b/src/Shader/PixelShader.cpp index 806b6e8..0b78c14 100644 --- a/src/Shader/PixelShader.cpp +++ b/src/Shader/PixelShader.cpp
@@ -34,7 +34,7 @@ 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; @@ -125,17 +125,30 @@ 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() @@ -188,22 +201,22 @@ 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]; @@ -660,7 +673,7 @@ { if(!interpolant[index][component]) { - semantic[index][component] = Semantic(); + input[index][component] = Semantic(); } } } @@ -678,10 +691,10 @@ 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) { @@ -713,10 +726,10 @@ 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;
diff --git a/src/Shader/PixelShader.hpp b/src/Shader/PixelShader.hpp index 2fbde6b..a06aaaa 100644 --- a/src/Shader/PixelShader.hpp +++ b/src/Shader/PixelShader.hpp
@@ -36,18 +36,24 @@ 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;
diff --git a/src/Shader/Shader.hpp b/src/Shader/Shader.hpp index 3cd08a3..ae8b90f 100644 --- a/src/Shader/Shader.hpp +++ b/src/Shader/Shader.hpp
@@ -593,7 +593,6 @@ }; void optimize(); - virtual void analyze() = 0; // FIXME: Private unsigned int dirtyConstantsF;
diff --git a/src/Shader/VertexProgram.cpp b/src/Shader/VertexProgram.cpp index 5fda7e7..20caa49 100644 --- a/src/Shader/VertexProgram.cpp +++ b/src/Shader/VertexProgram.cpp
@@ -50,7 +50,7 @@ enableContinue = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); } - if(shader->instanceIdDeclared) + if(shader->isInstanceIdDeclared()) { instanceID = *Pointer<Int>(data + OFFSET(DrawData,instanceID)); } @@ -596,7 +596,7 @@ { 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) {
diff --git a/src/Shader/VertexShader.cpp b/src/Shader/VertexShader.cpp index 733c113..dd62b4b 100644 --- a/src/Shader/VertexShader.cpp +++ b/src/Shader/VertexShader.cpp
@@ -27,6 +27,7 @@ positionRegister = Pos; pointSizeRegister = Unused; instanceIdDeclared = false; + textureSampling = false; for(int i = 0; i < MAX_VERTEX_INPUTS; i++) { @@ -59,6 +60,7 @@ positionRegister = Pos; pointSizeRegister = Unused; instanceIdDeclared = false; + textureSampling = false; for(int i = 0; i < MAX_VERTEX_INPUTS; i++) { @@ -149,6 +151,41 @@ 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();
diff --git a/src/Shader/VertexShader.hpp b/src/Shader/VertexShader.hpp index 0fdd09c..4eb6786 100644 --- a/src/Shader/VertexShader.hpp +++ b/src/Shader/VertexShader.hpp
@@ -31,21 +31,31 @@ static int validate(const unsigned long *const token); // Returns number of instructions if valid bool containsTextureSampling() const; - virtual void analyze(); + 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; } - 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 + 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; }; }