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 ...@@ -269,7 +269,6 @@ namespace sw
draw->vertexRoutine = vertexRoutine; draw->vertexRoutine = vertexRoutine;
draw->setupRoutine = setupRoutine; draw->setupRoutine = setupRoutine;
draw->pixelRoutine = pixelRoutine; draw->pixelRoutine = pixelRoutine;
draw->setupPointer = (SetupProcessor::RoutinePointer)setupRoutine->getEntry();
draw->setupPrimitives = setupPrimitives; draw->setupPrimitives = setupPrimitives;
draw->setupState = setupState; draw->setupState = setupState;
...@@ -432,7 +431,7 @@ namespace sw ...@@ -432,7 +431,7 @@ namespace sw
} }
vertexRoutine = {}; vertexRoutine = {};
setupRoutine.reset(); setupRoutine = {};
pixelRoutine = {}; pixelRoutine = {};
} }
...@@ -614,7 +613,6 @@ namespace sw ...@@ -614,7 +613,6 @@ namespace sw
int DrawCall::setupSolidTriangles(Triangle *triangles, Primitive *primitives, const DrawCall *drawCall, int count) int DrawCall::setupSolidTriangles(Triangle *triangles, Primitive *primitives, const DrawCall *drawCall, int count)
{ {
auto &state = drawCall->setupState; auto &state = drawCall->setupState;
auto setupRoutine = drawCall->setupPointer;
int ms = state.multiSample; int ms = state.multiSample;
const DrawData *data = drawCall->data; const DrawData *data = drawCall->data;
...@@ -640,7 +638,7 @@ namespace sw ...@@ -640,7 +638,7 @@ namespace sw
} }
} }
if(setupRoutine(primitives, triangles, &polygon, data)) if(drawCall->setupRoutine(primitives, triangles, &polygon, data))
{ {
primitives += ms; primitives += ms;
visible++; visible++;
...@@ -788,7 +786,6 @@ namespace sw ...@@ -788,7 +786,6 @@ namespace sw
bool DrawCall::setupLine(Primitive &primitive, Triangle &triangle, const DrawCall &draw) bool DrawCall::setupLine(Primitive &primitive, Triangle &triangle, const DrawCall &draw)
{ {
const SetupProcessor::RoutinePointer &setupRoutine = draw.setupPointer;
const DrawData &data = *draw.data; const DrawData &data = *draw.data;
float lineWidth = data.lineWidth; float lineWidth = data.lineWidth;
...@@ -876,7 +873,7 @@ namespace sw ...@@ -876,7 +873,7 @@ namespace sw
} }
} }
return setupRoutine(&primitive, &triangle, &polygon, &data); return draw.setupRoutine(&primitive, &triangle, &polygon, &data);
} }
} }
else // Diamond test convention else // Diamond test convention
...@@ -982,7 +979,7 @@ namespace sw ...@@ -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 ...@@ -991,7 +988,6 @@ namespace sw
bool DrawCall::setupPoint(Primitive &primitive, Triangle &triangle, const DrawCall &draw) bool DrawCall::setupPoint(Primitive &primitive, Triangle &triangle, const DrawCall &draw)
{ {
const SetupProcessor::RoutinePointer &setupRoutine = draw.setupPointer;
const DrawData &data = *draw.data; const DrawData &data = *draw.data;
Vertex &v = triangle.v0; Vertex &v = triangle.v0;
...@@ -1048,7 +1044,7 @@ namespace sw ...@@ -1048,7 +1044,7 @@ namespace sw
triangle.v1.projected.x += iround(subPixF * 0.5f * pSize); 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 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; return false;
......
...@@ -155,11 +155,9 @@ namespace sw ...@@ -155,11 +155,9 @@ namespace sw
VkLineRasterizationModeEXT lineRasterizationMode; VkLineRasterizationModeEXT lineRasterizationMode;
VertexProcessor::RoutineType vertexRoutine; VertexProcessor::RoutineType vertexRoutine;
std::shared_ptr<Routine> setupRoutine; SetupProcessor::RoutineType setupRoutine;
PixelProcessor::RoutineType pixelRoutine; PixelProcessor::RoutineType pixelRoutine;
SetupProcessor::RoutinePointer setupPointer;
SetupFunction setupPrimitives; SetupFunction setupPrimitives;
SetupProcessor::State setupState; SetupProcessor::State setupState;
...@@ -236,7 +234,7 @@ namespace sw ...@@ -236,7 +234,7 @@ namespace sw
PixelProcessor::State pixelState; PixelProcessor::State pixelState;
VertexProcessor::RoutineType vertexRoutine; VertexProcessor::RoutineType vertexRoutine;
std::shared_ptr<Routine> setupRoutine; SetupProcessor::RoutineType setupRoutine;
PixelProcessor::RoutineType pixelRoutine; PixelProcessor::RoutineType pixelRoutine;
vk::Device* device; vk::Device* device;
......
...@@ -94,7 +94,7 @@ namespace sw ...@@ -94,7 +94,7 @@ namespace sw
return state; return state;
} }
std::shared_ptr<Routine> SetupProcessor::routine(const State &state) SetupProcessor::RoutineType SetupProcessor::routine(const State &state)
{ {
auto routine = routineCache->query(state); auto routine = routineCache->query(state);
...@@ -114,6 +114,6 @@ namespace sw ...@@ -114,6 +114,6 @@ namespace sw
void SetupProcessor::setRoutineCacheSize(int cacheSize) void SetupProcessor::setRoutineCacheSize(int cacheSize)
{ {
delete routineCache; delete routineCache;
routineCache = new RoutineCache<State>(clamp(cacheSize, 1, 65536)); routineCache = new RoutineCacheType(clamp(cacheSize, 1, 65536));
} }
} }
...@@ -30,6 +30,8 @@ namespace sw ...@@ -30,6 +30,8 @@ namespace sw
struct DrawCall; struct DrawCall;
struct DrawData; struct DrawData;
using SetupFunction = FunctionT<int(Primitive* primitive, const Triangle* triangle, const Polygon* polygon, const DrawData* draw)>;
class SetupProcessor class SetupProcessor
{ {
public: public:
...@@ -60,7 +62,7 @@ namespace sw ...@@ -60,7 +62,7 @@ namespace sw
uint32_t hash; uint32_t hash;
}; };
typedef bool (*RoutinePointer)(Primitive *primitive, const Triangle *triangle, const Polygon *polygon, const DrawData *draw); using RoutineType = SetupFunction::RoutineType;
SetupProcessor(); SetupProcessor();
...@@ -68,12 +70,13 @@ namespace sw ...@@ -68,12 +70,13 @@ namespace sw
protected: protected:
State update(const sw::Context* context) const; State update(const sw::Context* context) const;
std::shared_ptr<Routine> routine(const State &state); RoutineType routine(const State &state);
void setRoutineCacheSize(int cacheSize); void setRoutineCacheSize(int cacheSize);
private: private:
RoutineCache<State> *routineCache; using RoutineCacheType = RoutineCacheT<State, SetupFunction::CFunctionType>;
RoutineCacheType *routineCache;
}; };
} }
......
...@@ -25,7 +25,6 @@ namespace sw ...@@ -25,7 +25,6 @@ namespace sw
{ {
SetupRoutine::SetupRoutine(const SetupProcessor::State &state) : state(state) SetupRoutine::SetupRoutine(const SetupProcessor::State &state) : state(state)
{ {
routine = 0;
} }
SetupRoutine::~SetupRoutine() SetupRoutine::~SetupRoutine()
...@@ -34,7 +33,7 @@ namespace sw ...@@ -34,7 +33,7 @@ namespace sw
void SetupRoutine::generate() void SetupRoutine::generate()
{ {
Function<Int(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)> function; SetupFunction function;
{ {
Pointer<Byte> primitive(function.Arg<0>()); Pointer<Byte> primitive(function.Arg<0>());
Pointer<Byte> tri(function.Arg<1>()); Pointer<Byte> tri(function.Arg<1>());
...@@ -610,7 +609,7 @@ namespace sw ...@@ -610,7 +609,7 @@ namespace sw
#endif #endif
} }
std::shared_ptr<Routine> SetupRoutine::getRoutine() SetupFunction::RoutineType SetupRoutine::getRoutine()
{ {
return routine; return routine;
} }
......
...@@ -30,7 +30,7 @@ namespace sw ...@@ -30,7 +30,7 @@ namespace sw
virtual ~SetupRoutine(); virtual ~SetupRoutine();
void generate(); void generate();
std::shared_ptr<Routine> getRoutine(); SetupFunction::RoutineType getRoutine();
private: 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); 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 ...@@ -40,7 +40,7 @@ namespace sw
const SetupProcessor::State &state; 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