Commit 62edf14b by Antonio Maiorano

Modify SetupRoutine to implement FunctionT

Bug: b/143479561 Change-Id: I555db2de99dfc5a139fbdf61c8ac4447e58ffd02 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/37709Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com>
parent e60921e4
......@@ -269,7 +269,6 @@ namespace sw
draw->vertexRoutine = vertexRoutine;
draw->setupRoutine = setupRoutine;
draw->pixelRoutine = pixelRoutine;
draw->setupPointer = (SetupProcessor::RoutinePointer)setupRoutine->getEntry();
draw->setupPrimitives = setupPrimitives;
draw->setupState = setupState;
......@@ -432,7 +431,7 @@ namespace sw
}
vertexRoutine = {};
setupRoutine.reset();
setupRoutine = {};
pixelRoutine = {};
}
......@@ -614,7 +613,6 @@ namespace sw
int DrawCall::setupSolidTriangles(Triangle *triangles, Primitive *primitives, const DrawCall *drawCall, int count)
{
auto &state = drawCall->setupState;
auto setupRoutine = drawCall->setupPointer;
int ms = state.multiSample;
const DrawData *data = drawCall->data;
......@@ -640,7 +638,7 @@ namespace sw
}
}
if(setupRoutine(primitives, triangles, &polygon, data))
if(drawCall->setupRoutine(primitives, triangles, &polygon, data))
{
primitives += ms;
visible++;
......@@ -788,7 +786,6 @@ namespace sw
bool DrawCall::setupLine(Primitive &primitive, Triangle &triangle, const DrawCall &draw)
{
const SetupProcessor::RoutinePointer &setupRoutine = draw.setupPointer;
const DrawData &data = *draw.data;
float lineWidth = data.lineWidth;
......@@ -876,7 +873,7 @@ namespace sw
}
}
return setupRoutine(&primitive, &triangle, &polygon, &data);
return draw.setupRoutine(&primitive, &triangle, &polygon, &data);
}
}
else // Diamond test convention
......@@ -982,7 +979,7 @@ namespace sw
}
}
return setupRoutine(&primitive, &triangle, &polygon, &data);
return draw.setupRoutine(&primitive, &triangle, &polygon, &data);
}
}
......@@ -991,7 +988,6 @@ namespace sw
bool DrawCall::setupPoint(Primitive &primitive, Triangle &triangle, const DrawCall &draw)
{
const SetupProcessor::RoutinePointer &setupRoutine = draw.setupPointer;
const DrawData &data = *draw.data;
Vertex &v = triangle.v0;
......@@ -1048,7 +1044,7 @@ namespace sw
triangle.v1.projected.x += iround(subPixF * 0.5f * pSize);
triangle.v2.projected.y -= iround(subPixF * 0.5f * pSize) * (data.HxF[0] > 0.0f ? 1 : -1); // Both Direct3D and OpenGL expect (0, 0) in the top-left corner
return setupRoutine(&primitive, &triangle, &polygon, &data);
return draw.setupRoutine(&primitive, &triangle, &polygon, &data);
}
return false;
......
......@@ -155,11 +155,9 @@ namespace sw
VkLineRasterizationModeEXT lineRasterizationMode;
VertexProcessor::RoutineType vertexRoutine;
std::shared_ptr<Routine> setupRoutine;
SetupProcessor::RoutineType setupRoutine;
PixelProcessor::RoutineType pixelRoutine;
SetupProcessor::RoutinePointer setupPointer;
SetupFunction setupPrimitives;
SetupProcessor::State setupState;
......@@ -236,7 +234,7 @@ namespace sw
PixelProcessor::State pixelState;
VertexProcessor::RoutineType vertexRoutine;
std::shared_ptr<Routine> setupRoutine;
SetupProcessor::RoutineType setupRoutine;
PixelProcessor::RoutineType pixelRoutine;
vk::Device* device;
......
......@@ -94,7 +94,7 @@ namespace sw
return state;
}
std::shared_ptr<Routine> SetupProcessor::routine(const State &state)
SetupProcessor::RoutineType SetupProcessor::routine(const State &state)
{
auto routine = routineCache->query(state);
......@@ -114,6 +114,6 @@ namespace sw
void SetupProcessor::setRoutineCacheSize(int cacheSize)
{
delete routineCache;
routineCache = new RoutineCache<State>(clamp(cacheSize, 1, 65536));
routineCache = new RoutineCacheType(clamp(cacheSize, 1, 65536));
}
}
......@@ -30,6 +30,8 @@ namespace sw
struct DrawCall;
struct DrawData;
using SetupFunction = FunctionT<int(Primitive* primitive, const Triangle* triangle, const Polygon* polygon, const DrawData* draw)>;
class SetupProcessor
{
public:
......@@ -60,7 +62,7 @@ namespace sw
uint32_t hash;
};
typedef bool (*RoutinePointer)(Primitive *primitive, const Triangle *triangle, const Polygon *polygon, const DrawData *draw);
using RoutineType = SetupFunction::RoutineType;
SetupProcessor();
......@@ -68,12 +70,13 @@ namespace sw
protected:
State update(const sw::Context* context) const;
std::shared_ptr<Routine> routine(const State &state);
RoutineType routine(const State &state);
void setRoutineCacheSize(int cacheSize);
private:
RoutineCache<State> *routineCache;
using RoutineCacheType = RoutineCacheT<State, SetupFunction::CFunctionType>;
RoutineCacheType *routineCache;
};
}
......
......@@ -25,7 +25,6 @@ namespace sw
{
SetupRoutine::SetupRoutine(const SetupProcessor::State &state) : state(state)
{
routine = 0;
}
SetupRoutine::~SetupRoutine()
......@@ -34,7 +33,7 @@ namespace sw
void SetupRoutine::generate()
{
Function<Int(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)> function;
SetupFunction function;
{
Pointer<Byte> primitive(function.Arg<0>());
Pointer<Byte> tri(function.Arg<1>());
......@@ -610,7 +609,7 @@ namespace sw
#endif
}
std::shared_ptr<Routine> SetupRoutine::getRoutine()
SetupFunction::RoutineType SetupRoutine::getRoutine()
{
return routine;
}
......
......@@ -30,7 +30,7 @@ namespace sw
virtual ~SetupRoutine();
void generate();
std::shared_ptr<Routine> getRoutine();
SetupFunction::RoutineType getRoutine();
private:
void setupGradient(Pointer<Byte> &primitive, Pointer<Byte> &triangle, Float4 &w012, Float4 (&m)[3], Pointer<Byte> &v0, Pointer<Byte> &v1, Pointer<Byte> &v2, int attribute, int planeEquation, bool flatShading, bool perspective, int component);
......@@ -40,7 +40,7 @@ namespace sw
const SetupProcessor::State &state;
std::shared_ptr<Routine> routine;
SetupFunction::RoutineType 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