Commit 2ca19030 by Nicolas Capens

Derive VertexRoutine from Function<>.

Bug 22652760 Change-Id: I48e9e1f3ff677429eff1aea2f80b1e384a537a14 Reviewed-on: https://swiftshader-review.googlesource.com/4557Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 060a2d3f
...@@ -73,7 +73,7 @@ namespace sw ...@@ -73,7 +73,7 @@ namespace sw
P = 0; P = 0;
PB = 0; PB = 0;
PBV = 0; PBV = 0;
for(int i = 0; i < 12; i++) for(int i = 0; i < 12; i++)
{ {
PBVM[i] = 0; PBVM[i] = 0;
...@@ -271,7 +271,7 @@ namespace sw ...@@ -271,7 +271,7 @@ namespace sw
{ {
if(light < 8) if(light < 8)
{ {
ff.attenuationConstant[light] = replicate(constant); ff.attenuationConstant[light] = replicate(constant);
ff.attenuationLinear[light] = replicate(linear); ff.attenuationLinear[light] = replicate(linear);
ff.attenuationQuadratic[light] = replicate(quadratic); ff.attenuationQuadratic[light] = replicate(quadratic);
} }
...@@ -707,7 +707,7 @@ namespace sw ...@@ -707,7 +707,7 @@ namespace sw
{ {
PB = P * B; PB = P * B;
PBV = PB * V; PBV = PB * V;
for(int i = 0; i < activeMatrices; i++) for(int i = 0; i < activeMatrices; i++)
{ {
PBVM[i] = PBV * M[i]; PBVM[i] = PBV * M[i];
...@@ -723,7 +723,7 @@ namespace sw ...@@ -723,7 +723,7 @@ namespace sw
{ {
PB = P * B; PB = P * B;
PBV = PB * V; PBV = PB * V;
for(int i = 0; i < activeMatrices; i++) for(int i = 0; i < activeMatrices; i++)
{ {
PBVM[i] = PBV * M[i]; PBVM[i] = PBV * M[i];
...@@ -737,7 +737,7 @@ namespace sw ...@@ -737,7 +737,7 @@ namespace sw
if(updateViewMatrix) if(updateViewMatrix)
{ {
PBV = PB * V; PBV = PB * V;
for(int i = 0; i < activeMatrices; i++) for(int i = 0; i < activeMatrices; i++)
{ {
PBVM[i] = PBV * M[i]; PBVM[i] = PBV * M[i];
...@@ -808,7 +808,7 @@ namespace sw ...@@ -808,7 +808,7 @@ namespace sw
state.shaderContainsTexldl = context->vertexShader ? context->vertexShader->containsTexldl() : false; state.shaderContainsTexldl = context->vertexShader ? context->vertexShader->containsTexldl() : false;
state.positionRegister = context->vertexShader ? context->vertexShader->positionRegister : Pos; state.positionRegister = context->vertexShader ? context->vertexShader->positionRegister : Pos;
state.pointSizeRegister = context->vertexShader ? context->vertexShader->pointSizeRegister : Pts; state.pointSizeRegister = context->vertexShader ? context->vertexShader->pointSizeRegister : Pts;
state.vertexBlendMatrixCount = context->vertexBlendMatrixCountActive(); state.vertexBlendMatrixCount = context->vertexBlendMatrixCountActive();
state.indexedVertexBlendEnable = context->indexedVertexBlendActive(); state.indexedVertexBlendEnable = context->indexedVertexBlendActive();
state.vertexNormalActive = context->vertexNormalActive(); state.vertexNormalActive = context->vertexNormalActive();
...@@ -888,7 +888,7 @@ namespace sw ...@@ -888,7 +888,7 @@ namespace sw
{ {
state.output[D0].write = 0xF; state.output[D0].write = 0xF;
} }
if(context->specularActive()) if(context->specularActive())
{ {
state.output[D1].write = 0xF; state.output[D1].write = 0xF;
...@@ -968,7 +968,7 @@ namespace sw ...@@ -968,7 +968,7 @@ namespace sw
} }
generator->generate(); generator->generate();
routine = generator->getRoutine(); routine = (*generator)(L"VertexRoutine_%0.8X", state.shaderID);
delete generator; delete generator;
routineCache->add(state, routine); routineCache->add(state, routine);
......
...@@ -23,9 +23,8 @@ namespace sw ...@@ -23,9 +23,8 @@ namespace sw
extern bool halfIntegerCoordinates; // Pixel centers are not at integer coordinates extern bool halfIntegerCoordinates; // Pixel centers are not at integer coordinates
extern bool symmetricNormalizedDepth; // [-1, 1] instead of [0, 1] extern bool symmetricNormalizedDepth; // [-1, 1] instead of [0, 1]
VertexRoutine::VertexRoutine(const VertexProcessor::State &state, const VertexShader *shader) : state(state), shader(shader) VertexRoutine::VertexRoutine(const VertexProcessor::State &state, const VertexShader *shader) : r(shader), state(state), shader(shader)
{ {
routine = 0;
} }
VertexRoutine::~VertexRoutine() VertexRoutine::~VertexRoutine()
...@@ -34,67 +33,56 @@ namespace sw ...@@ -34,67 +33,56 @@ namespace sw
void VertexRoutine::generate() void VertexRoutine::generate()
{ {
Function<Void(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)> function; Pointer<Byte> vertex(Arg<0>());
{ Pointer<Byte> batch(Arg<1>());
Pointer<Byte> vertex(function.Arg<0>()); Pointer<Byte> task(Arg<2>());
Pointer<Byte> batch(function.Arg<1>()); Pointer<Byte> data(Arg<3>());
Pointer<Byte> task(function.Arg<2>());
Pointer<Byte> data(function.Arg<3>());
const bool texldl = state.shaderContainsTexldl;
Pointer<Byte> cache = task + OFFSET(VertexTask,vertexCache); const bool texldl = state.shaderContainsTexldl;
Pointer<Byte> vertexCache = cache + OFFSET(VertexCache,vertex);
Pointer<Byte> tagCache = cache + OFFSET(VertexCache,tag);
UInt vertexCount = *Pointer<UInt>(task + OFFSET(VertexTask,vertexCount)); Pointer<Byte> cache = task + OFFSET(VertexTask,vertexCache);
Pointer<Byte> vertexCache = cache + OFFSET(VertexCache,vertex);
Pointer<Byte> tagCache = cache + OFFSET(VertexCache,tag);
Registers r(shader); UInt vertexCount = *Pointer<UInt>(task + OFFSET(VertexTask,vertexCount));
r.data = data;
r.constants = *Pointer<Pointer<Byte> >(data + OFFSET(DrawData,constants));
if(shader && shader->instanceIdDeclared)
{
r.instanceID = *Pointer<Int>(data + OFFSET(DrawData, instanceID));
}
Do
{
UInt index = *Pointer<UInt>(batch);
UInt tagIndex = index & 0x0000003C;
UInt indexQ = !texldl ? UInt(index & 0xFFFFFFFC) : index; // FIXME: TEXLDL hack to have independent LODs, hurts performance.
If(*Pointer<UInt>(tagCache + tagIndex) != indexQ) r.data = data;
{ r.constants = *Pointer<Pointer<Byte> >(data + OFFSET(DrawData,constants));
*Pointer<UInt>(tagCache + tagIndex) = indexQ; if(shader && shader->instanceIdDeclared)
{
r.instanceID = *Pointer<Int>(data + OFFSET(DrawData, instanceID));
}
readInput(r, indexQ); Do
pipeline(r); {
postTransform(r); UInt index = *Pointer<UInt>(batch);
computeClipFlags(r); UInt tagIndex = index & 0x0000003C;
UInt indexQ = !texldl ? UInt(index & 0xFFFFFFFC) : index; // FIXME: TEXLDL hack to have independent LODs, hurts performance.
Pointer<Byte> cacheLine0 = vertexCache + tagIndex * UInt((int)sizeof(Vertex)); If(*Pointer<UInt>(tagCache + tagIndex) != indexQ)
writeCache(cacheLine0, r); {
} *Pointer<UInt>(tagCache + tagIndex) = indexQ;
UInt cacheIndex = index & 0x0000003F; readInput(r, indexQ);
Pointer<Byte> cacheLine = vertexCache + cacheIndex * UInt((int)sizeof(Vertex)); pipeline(r);
writeVertex(vertex, cacheLine); postTransform(r);
computeClipFlags(r);
vertex += sizeof(Vertex); Pointer<Byte> cacheLine0 = vertexCache + tagIndex * UInt((int)sizeof(Vertex));
batch += sizeof(unsigned int); writeCache(cacheLine0, r);
vertexCount--;
} }
Until(vertexCount == 0)
Return(); UInt cacheIndex = index & 0x0000003F;
} Pointer<Byte> cacheLine = vertexCache + cacheIndex * UInt((int)sizeof(Vertex));
writeVertex(vertex, cacheLine);
routine = function(L"VertexRoutine_%0.8X", state.shaderID); vertex += sizeof(Vertex);
} batch += sizeof(unsigned int);
vertexCount--;
}
Until(vertexCount == 0)
Routine *VertexRoutine::getRoutine() Return();
{
return routine;
} }
void VertexRoutine::readInput(Registers &r, UInt &index) void VertexRoutine::readInput(Registers &r, UInt &index)
...@@ -242,7 +230,7 @@ namespace sw ...@@ -242,7 +230,7 @@ namespace sw
v.y = Float4(*Pointer<Short4>(source1)); v.y = Float4(*Pointer<Short4>(source1));
v.z = Float4(*Pointer<Short4>(source2)); v.z = Float4(*Pointer<Short4>(source2));
v.w = Float4(*Pointer<Short4>(source3)); v.w = Float4(*Pointer<Short4>(source3));
transpose4xN(v.x, v.y, v.z, v.w, stream.count); transpose4xN(v.x, v.y, v.z, v.w, stream.count);
if(stream.normalized) if(stream.normalized)
...@@ -251,7 +239,7 @@ namespace sw ...@@ -251,7 +239,7 @@ namespace sw
if(stream.count >= 2) v.y *= *Pointer<Float4>(r.constants + OFFSET(Constants,unscaleShort)); if(stream.count >= 2) v.y *= *Pointer<Float4>(r.constants + OFFSET(Constants,unscaleShort));
if(stream.count >= 3) v.z *= *Pointer<Float4>(r.constants + OFFSET(Constants,unscaleShort)); if(stream.count >= 3) v.z *= *Pointer<Float4>(r.constants + OFFSET(Constants,unscaleShort));
if(stream.count >= 4) v.w *= *Pointer<Float4>(r.constants + OFFSET(Constants,unscaleShort)); if(stream.count >= 4) v.w *= *Pointer<Float4>(r.constants + OFFSET(Constants,unscaleShort));
} }
} }
break; break;
case STREAMTYPE_USHORT: case STREAMTYPE_USHORT:
...@@ -260,7 +248,7 @@ namespace sw ...@@ -260,7 +248,7 @@ namespace sw
v.y = Float4(*Pointer<UShort4>(source1)); v.y = Float4(*Pointer<UShort4>(source1));
v.z = Float4(*Pointer<UShort4>(source2)); v.z = Float4(*Pointer<UShort4>(source2));
v.w = Float4(*Pointer<UShort4>(source3)); v.w = Float4(*Pointer<UShort4>(source3));
transpose4xN(v.x, v.y, v.z, v.w, stream.count); transpose4xN(v.x, v.y, v.z, v.w, stream.count);
if(stream.normalized) if(stream.normalized)
...@@ -277,7 +265,7 @@ namespace sw ...@@ -277,7 +265,7 @@ namespace sw
// FIXME: Vectorize // FIXME: Vectorize
{ {
Int x, y, z; Int x, y, z;
x = y = z = *Pointer<Int>(source0); x = y = z = *Pointer<Int>(source0);
v.x.x = Float(x & 0x000003FF); v.x.x = Float(x & 0x000003FF);
...@@ -287,7 +275,7 @@ namespace sw ...@@ -287,7 +275,7 @@ namespace sw
{ {
Int x, y, z; Int x, y, z;
x = y = z = *Pointer<Int>(source1); x = y = z = *Pointer<Int>(source1);
v.y.x = Float(x & 0x000003FF); v.y.x = Float(x & 0x000003FF);
...@@ -297,7 +285,7 @@ namespace sw ...@@ -297,7 +285,7 @@ namespace sw
{ {
Int x, y, z; Int x, y, z;
x = y = z = *Pointer<Int>(source2); x = y = z = *Pointer<Int>(source2);
v.z.x = Float(x & 0x000003FF); v.z.x = Float(x & 0x000003FF);
...@@ -307,7 +295,7 @@ namespace sw ...@@ -307,7 +295,7 @@ namespace sw
{ {
Int x, y, z; Int x, y, z;
x = y = z = *Pointer<Int>(source3); x = y = z = *Pointer<Int>(source3);
v.w.x = Float(x & 0x000003FF); v.w.x = Float(x & 0x000003FF);
...@@ -326,7 +314,7 @@ namespace sw ...@@ -326,7 +314,7 @@ namespace sw
// FIXME: Vectorize // FIXME: Vectorize
{ {
Int x, y, z; Int x, y, z;
x = y = z = *Pointer<Int>(source0); x = y = z = *Pointer<Int>(source0);
v.x.x = Float((x << 22) & 0xFFC00000); v.x.x = Float((x << 22) & 0xFFC00000);
...@@ -336,7 +324,7 @@ namespace sw ...@@ -336,7 +324,7 @@ namespace sw
{ {
Int x, y, z; Int x, y, z;
x = y = z = *Pointer<Int>(source1); x = y = z = *Pointer<Int>(source1);
v.y.x = Float((x << 22) & 0xFFC00000); v.y.x = Float((x << 22) & 0xFFC00000);
...@@ -346,7 +334,7 @@ namespace sw ...@@ -346,7 +334,7 @@ namespace sw
{ {
Int x, y, z; Int x, y, z;
x = y = z = *Pointer<Int>(source2); x = y = z = *Pointer<Int>(source2);
v.z.x = Float((x << 22) & 0xFFC00000); v.z.x = Float((x << 22) & 0xFFC00000);
...@@ -356,7 +344,7 @@ namespace sw ...@@ -356,7 +344,7 @@ namespace sw
{ {
Int x, y, z; Int x, y, z;
x = y = z = *Pointer<Int>(source3); x = y = z = *Pointer<Int>(source3);
v.w.x = Float((x << 22) & 0xFFC00000); v.w.x = Float((x << 22) & 0xFFC00000);
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
namespace sw namespace sw
{ {
class VertexRoutine class VertexRoutine : public Function<Void(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)>
{ {
protected: protected:
struct Registers struct Registers
...@@ -31,7 +31,7 @@ namespace sw ...@@ -31,7 +31,7 @@ namespace sw
{ {
loopDepth = -1; loopDepth = -1;
enableStack[0] = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); enableStack[0] = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
if(shader && shader->containsBreakInstruction()) if(shader && shader->containsBreakInstruction())
{ {
enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
...@@ -71,31 +71,30 @@ namespace sw ...@@ -71,31 +71,30 @@ namespace sw
Int instanceID; Int instanceID;
}; };
Registers r;
public: public:
VertexRoutine(const VertexProcessor::State &state, const VertexShader *shader); VertexRoutine(const VertexProcessor::State &state, const VertexShader *shader);
virtual ~VertexRoutine(); virtual ~VertexRoutine();
void generate(); void generate();
Routine *getRoutine();
protected: protected:
const VertexProcessor::State &state; const VertexProcessor::State &state;
const VertexShader *const shader; const VertexShader *const shader;
private: private:
virtual void pipeline(Registers &r) = 0; virtual void pipeline(Registers &r) = 0;
typedef VertexProcessor::State::Input Stream; typedef VertexProcessor::State::Input Stream;
Vector4f readStream(Registers &r, Pointer<Byte> &buffer, UInt &stride, const Stream &stream, const UInt &index); Vector4f readStream(Registers &r, Pointer<Byte> &buffer, UInt &stride, const Stream &stream, const UInt &index);
void readInput(Registers &r, UInt &index); void readInput(Registers &r, UInt &index);
void computeClipFlags(Registers &r); void computeClipFlags(Registers &r);
void postTransform(Registers &r); void postTransform(Registers &r);
void writeCache(Pointer<Byte> &cacheLine, Registers &r); void writeCache(Pointer<Byte> &cacheLine, Registers &r);
void writeVertex(Pointer<Byte> &vertex, Pointer<Byte> &cacheLine); void writeVertex(Pointer<Byte> &vertex, Pointer<Byte> &cacheLine);
Routine *routine;
}; };
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment