Several speed optimizations

This commit is contained in:
Michaël Lemaire 2013-12-11 12:46:39 +01:00 committed by Michael Lemaire
parent a59d8f2cc6
commit be5c67e4aa
13 changed files with 88 additions and 71 deletions

View file

@ -47,11 +47,11 @@ run:build
LD_LIBRARY_PATH=$(LIBRARY_PATH) ${RUNNER} ${BUILDPATH}/interface/desktop/paysages-gui
profile:build
LD_LIBRARY_PATH=${LIBRARY_PATH} perf record -g fp ${BUILDPATH}/interface/desktop/paysages-gui
LD_LIBRARY_PATH=${LIBRARY_PATH} perf record -g fp ${BUILDPATH}/interface/desktop/paysages-gui $(ARGS)
perf report -g
profile_cli:build
LD_LIBRARY_PATH=${LIBRARY_PATH} perf record -g fp ${BUILDPATH}/interface/commandline/paysages-cli
LD_LIBRARY_PATH=${LIBRARY_PATH} perf record -g fp ${BUILDPATH}/interface/commandline/paysages-cli $(ARGS)
perf report -g
package:build

View file

@ -83,19 +83,24 @@ Vector3 Matrix4::multPoint(const Vector3 &v) const
Vector3 Matrix4::transform(const Vector3 &v) const
{
Vector3 result;
double w;
result.x = a * v.x + b * v.y + c * v.z + d;
result.y = e * v.x + f * v.y + g * v.z + h;
result.z = i * v.x + j * v.y + k * v.z + l;
w = m * v.x + n * v.y + o * v.z + p;
double w = m * v.x + n * v.y + o * v.z + p;
if (w != 0.0)
{
result.x /= w;
result.y /= w;
result.z /= w;
w = 1.0 / w;
return Vector3(
(a * v.x + b * v.y + c * v.z + d) * w,
(e * v.x + f * v.y + g * v.z + h) * w,
(i * v.x + j * v.y + k * v.z + l) * w
);
}
else
{
return Vector3(
a * v.x + b * v.y + c * v.z + d,
e * v.x + f * v.y + g * v.z + h,
i * v.x + j * v.y + k * v.z + l
);
}
return result;
}
Matrix4 Matrix4::transposed() const

View file

@ -14,8 +14,7 @@ METHSPEC Vector3::Vector3(double x, double y, double z):
{
}
METHSPEC Vector3::Vector3():
x(0.0), y(0.0), z(0.0)
METHSPEC Vector3::Vector3()
{
}

View file

@ -24,7 +24,7 @@
static DialogRender* _current_dialog;
static void _renderStart(int width, int height, Color background)
static void _renderStart(int width, int height, const Color &background)
{
_current_dialog->pixbuf_lock->lock();
delete _current_dialog->pixbuf;
@ -35,7 +35,7 @@ static void _renderStart(int width, int height, Color background)
_current_dialog->tellRenderSize(width, height);
}
static void _renderDraw(int x, int y, Color col)
static void _renderDraw(int x, int y, const Color &col)
{
_current_dialog->pixbuf->setPixel(x, _current_dialog->pixbuf->height() - 1 - y, colorToQColor(col).rgb());
}

View file

@ -36,8 +36,16 @@ typedef struct
{
int x;
int y;
Vector3 pixel;
Vector3 location;
struct {
double x;
double y;
double z;
} pixel;
struct {
double x;
double y;
double z;
} location;
int callback;
} ScanPoint;
@ -68,8 +76,8 @@ typedef struct
RenderArea* area;
} RenderChunk;
static void _callbackStart(int, int, Color) {}
static void _callbackDraw(int, int, Color) {}
static void _callbackStart(int, int, const Color&) {}
static void _callbackDraw(int, int, const Color&) {}
static void _callbackUpdate(double) {}
RenderArea::RenderArea(SoftwareRenderer* renderer)
@ -297,7 +305,7 @@ static inline unsigned int _pushCallback(RenderArea* area, FragmentCallback call
}
}
void RenderArea::pushFragment(int x, int y, double z, int edge, Vector3 location, int callback)
void RenderArea::pushFragment(int x, int y, double z, int edge, const Vector3 &location, int callback)
{
RenderFragment* pixel_data;
@ -332,8 +340,10 @@ static void _scanGetDiff(ScanPoint* v1, ScanPoint* v2, ScanPoint* result)
static void _scanInterpolate(CameraDefinition* camera, ScanPoint* v1, ScanPoint* diff, double value, ScanPoint* result)
{
double v1depth = camera->getRealDepth(v1->pixel);
double v2depth = camera->getRealDepth(v1->pixel.add(diff->pixel));
Vector3 vec1(v1->pixel.x, v1->pixel.y, v1->pixel.z);
Vector3 vecdiff(diff->pixel.x, diff->pixel.y, diff->pixel.z);
double v1depth = camera->getRealDepth(vec1);
double v2depth = camera->getRealDepth(vec1.add(vecdiff));
double factor = ((1.0 - value) / v1depth + value / v2depth);
result->pixel.x = v1->pixel.x + diff->pixel.x * value;
@ -507,13 +517,14 @@ static void _renderScanLines(RenderArea* area, RenderScanlines* scanlines)
current.y = cury;
_scanInterpolate(area->renderer->render_camera, &down, &diff, fy / dy, &current);
area->pushFragment(current.x, current.y, current.pixel.z, (cury == starty || cury == endy), current.location, current.callback);
Vector3 veclocation = Vector3(current.location.x, current.location.y, current.location.z);
area->pushFragment(current.x, current.y, current.pixel.z, (cury == starty || cury == endy), veclocation, current.callback);
}
}
}
}
void RenderArea::pushTriangle(Vector3 pixel1, Vector3 pixel2, Vector3 pixel3, Vector3 location1, Vector3 location2, Vector3 location3, f_RenderFragmentCallback callback, void* callback_data)
void RenderArea::pushTriangle(const Vector3 &pixel1, const Vector3 &pixel2, const Vector3 &pixel3, const Vector3 &location1, const Vector3 &location2, const Vector3 &location3, f_RenderFragmentCallback callback, void* callback_data)
{
FragmentCallback fragment_callback = {callback, callback_data};
ScanPoint point1, point2, point3;
@ -532,15 +543,27 @@ void RenderArea::pushTriangle(Vector3 pixel1, Vector3 pixel2, Vector3 pixel3, Ve
lock->release();
/* Prepare vertices */
point1.pixel = pixel1;
point1.location = location1;
point1.pixel.x = pixel1.x;
point1.pixel.y = pixel1.y;
point1.pixel.z = pixel1.z;
point1.location.x = location1.x;
point1.location.y = location1.y;
point1.location.z = location1.z;
point2.pixel = pixel2;
point2.location = location2;
point2.pixel.x = pixel2.x;
point2.pixel.y = pixel2.y;
point2.pixel.z = pixel2.z;
point2.location.x = location2.x;
point2.location.y = location2.y;
point2.location.z = location2.z;
point2.callback = point1.callback;
point3.pixel = pixel3;
point3.location = location3;
point3.pixel.x = pixel3.x;
point3.pixel.y = pixel3.y;
point3.pixel.z = pixel3.z;
point3.location.x = location3.x;
point3.location.y = location3.y;
point3.location.z = location3.z;
point3.callback = point1.callback;
/* Prepare scanlines */

View file

@ -22,9 +22,9 @@ public:
int quality;
} RenderParams;
typedef Color (*f_RenderFragmentCallback)(SoftwareRenderer* renderer, Vector3 location, void* data);
typedef void (*RenderCallbackStart)(int width, int height, Color background);
typedef void (*RenderCallbackDraw)(int x, int y, Color col);
typedef Color (*f_RenderFragmentCallback)(SoftwareRenderer* renderer, const Vector3 &location, void* data);
typedef void (*RenderCallbackStart)(int width, int height, const Color &background);
typedef void (*RenderCallbackDraw)(int x, int y, const Color &col);
typedef void (*RenderCallbackUpdate)(double progress);
public:
@ -37,7 +37,7 @@ public:
void clear();
void update();
void pushTriangle(Vector3 pixel1, Vector3 pixel2, Vector3 pixel3, Vector3 location1, Vector3 location2, Vector3 location3, f_RenderFragmentCallback callback, void* callback_data);
void pushTriangle(const Vector3 &pixel1, const Vector3 &pixel2, const Vector3 &pixel3, const Vector3 &location1, const Vector3 &location2, const Vector3 &location3, f_RenderFragmentCallback callback, void* callback_data);
Color getPixel(int x, int y);
@ -47,7 +47,7 @@ public:
void setAllDirty();
void processDirtyPixels();
void pushFragment(int x, int y, double z, int edge, Vector3 location, int callback);
void pushFragment(int x, int y, double z, int edge, const Vector3 &location, int callback);
public:
ColorProfile* hdr_mapping;

View file

@ -14,7 +14,7 @@ SkyRasterizer::SkyRasterizer(SoftwareRenderer* renderer):
{
}
static Color _postProcessFragment(SoftwareRenderer* renderer, Vector3 location, void*)
static Color _postProcessFragment(SoftwareRenderer* renderer, const Vector3 &location, void*)
{
Vector3 camera_location, direction;
Color result;

View file

@ -221,17 +221,17 @@ int SoftwareRenderer::addRenderProgress(double)
return not render_interrupt;
}
Vector3 SoftwareRenderer::getCameraLocation(Vector3)
Vector3 SoftwareRenderer::getCameraLocation(const Vector3 &)
{
return render_camera->getLocation();
}
Vector3 SoftwareRenderer::getCameraDirection(Vector3)
Vector3 SoftwareRenderer::getCameraDirection(const Vector3 &)
{
return render_camera->getDirectionNormalized();
}
double SoftwareRenderer::getPrecision(Vector3 location)
double SoftwareRenderer::getPrecision(const Vector3 &location)
{
Vector3 projected;
@ -242,17 +242,17 @@ double SoftwareRenderer::getPrecision(Vector3 location)
return render_camera->unproject(projected).sub(location).getNorm(); // / (double)render_quality;
}
Vector3 SoftwareRenderer::projectPoint(Vector3 point)
Vector3 SoftwareRenderer::projectPoint(const Vector3 &point)
{
return render_camera->project(point);
}
Vector3 SoftwareRenderer::unprojectPoint(Vector3 point)
Vector3 SoftwareRenderer::unprojectPoint(const Vector3 &point)
{
return render_camera->unproject(point);
}
void SoftwareRenderer::pushTriangle(Vector3 v1, Vector3 v2, Vector3 v3, RenderArea::f_RenderFragmentCallback callback, void* callback_data)
void SoftwareRenderer::pushTriangle(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, RenderArea::f_RenderFragmentCallback callback, void* callback_data)
{
Vector3 p1, p2, p3;
@ -263,13 +263,13 @@ void SoftwareRenderer::pushTriangle(Vector3 v1, Vector3 v2, Vector3 v3, RenderAr
render_area->pushTriangle(p1, p2, p3, v1, v2, v3, callback, callback_data);
}
void SoftwareRenderer::pushQuad(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, RenderArea::f_RenderFragmentCallback callback, void* callback_data)
void SoftwareRenderer::pushQuad(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &v4, RenderArea::f_RenderFragmentCallback callback, void* callback_data)
{
pushTriangle(v2, v3, v1, callback, callback_data);
pushTriangle(v4, v1, v3, callback, callback_data);
}
void SoftwareRenderer::pushDisplacedTriangle(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 ov1, Vector3 ov2, Vector3 ov3, RenderArea::f_RenderFragmentCallback callback, void* callback_data)
void SoftwareRenderer::pushDisplacedTriangle(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &ov1, const Vector3 &ov2, const Vector3 &ov3, RenderArea::f_RenderFragmentCallback callback, void* callback_data)
{
Vector3 p1, p2, p3;
@ -280,7 +280,7 @@ void SoftwareRenderer::pushDisplacedTriangle(Vector3 v1, Vector3 v2, Vector3 v3,
render_area->pushTriangle(p1, p2, p3, ov1, ov2, ov3, callback, callback_data);
}
void SoftwareRenderer::pushDisplacedQuad(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, Vector3 ov1, Vector3 ov2, Vector3 ov3, Vector3 ov4, RenderArea::f_RenderFragmentCallback callback, void* callback_data)
void SoftwareRenderer::pushDisplacedQuad(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &v4, const Vector3 &ov1, const Vector3 &ov2, const Vector3 &ov3, const Vector3 &ov4, RenderArea::f_RenderFragmentCallback callback, void* callback_data)
{
pushDisplacedTriangle(v2, v3, v1, ov2, ov3, ov1, callback, callback_data);
pushDisplacedTriangle(v4, v1, v3, ov4, ov1, ov3, callback, callback_data);

View file

@ -33,16 +33,16 @@ public:
void* customData[10];
virtual Vector3 getCameraLocation(Vector3 target);
virtual Vector3 getCameraDirection(Vector3 target);
virtual double getPrecision(Vector3 location);
virtual Vector3 projectPoint(Vector3 point);
virtual Vector3 unprojectPoint(Vector3 point);
virtual Vector3 getCameraLocation(const Vector3 &target);
virtual Vector3 getCameraDirection(const Vector3 &target);
virtual double getPrecision(const Vector3 &location);
virtual Vector3 projectPoint(const Vector3 &point);
virtual Vector3 unprojectPoint(const Vector3 &point);
virtual int addRenderProgress(double progress);
virtual void pushTriangle(Vector3 v1, Vector3 v2, Vector3 v3, RenderArea::f_RenderFragmentCallback callback, void* callback_data);
virtual void pushQuad(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, RenderArea::f_RenderFragmentCallback callback, void* callback_data);
virtual void pushDisplacedTriangle(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 ov1, Vector3 ov2, Vector3 ov3, RenderArea::f_RenderFragmentCallback callback, void* callback_data);
virtual void pushDisplacedQuad(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, Vector3 ov1, Vector3 ov2, Vector3 ov3, Vector3 ov4, RenderArea::f_RenderFragmentCallback callback, void* callback_data);
virtual void pushTriangle(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, RenderArea::f_RenderFragmentCallback callback, void* callback_data);
virtual void pushQuad(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &v4, RenderArea::f_RenderFragmentCallback callback, void* callback_data);
virtual void pushDisplacedTriangle(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &ov1, const Vector3 &ov2, const Vector3 &ov3, RenderArea::f_RenderFragmentCallback callback, void* callback_data);
virtual void pushDisplacedQuad(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &v4, const Vector3 &ov1, const Vector3 &ov2, const Vector3 &ov3, const Vector3 &ov4, RenderArea::f_RenderFragmentCallback callback, void* callback_data);
/*!
* \brief Set the scenery to render.

View file

@ -16,22 +16,12 @@ TerrainRasterizer::TerrainRasterizer(SoftwareRenderer* renderer):
static inline Vector3 _getPoint(SoftwareRenderer* renderer, double x, double z)
{
Vector3 result;
result.x = x;
result.y = renderer->getTerrainRenderer()->getHeight(x, z, 1);
result.z = z;
return result;
return Vector3(x, renderer->getTerrainRenderer()->getHeight(x, z, 1), z);
}
static Color _postProcessFragment(SoftwareRenderer* renderer, Vector3 point, void*)
static Color _postProcessFragment(SoftwareRenderer* renderer, const Vector3 &point, void*)
{
double precision;
point = _getPoint(renderer, point.x, point.z);
precision = renderer->getPrecision(point);
double precision = renderer->getPrecision(_getPoint(renderer, point.x, point.z));
return renderer->getTerrainRenderer()->getFinalColor(point, precision);
}

View file

@ -9,7 +9,7 @@ WaterRasterizer::WaterRasterizer(SoftwareRenderer* renderer):
{
}
static Color _postProcessFragment(SoftwareRenderer* renderer, Vector3 location, void*)
static Color _postProcessFragment(SoftwareRenderer* renderer, const Vector3 &location, void*)
{
return renderer->getWaterRenderer()->getResult(location.x, location.z).final;
}

View file

@ -11,7 +11,7 @@
#define OUTPUT_WIDTH 400
#define OUTPUT_HEIGHT 300
static Color _postProcessFragment(SoftwareRenderer* renderer, Vector3 location, void*)
static Color _postProcessFragment(SoftwareRenderer* renderer, const Vector3 &location, void*)
{
return renderer->getAtmosphereRenderer()->applyAerialPerspective(location, COLOR_BLACK).final;
}

View file

@ -6,7 +6,7 @@
#include "ColorProfile.h"
#include "System.h"
static Color _postProcessFragment(SoftwareRenderer*, Vector3 location, void*)
static Color _postProcessFragment(SoftwareRenderer*, const Vector3 &location, void*)
{
/* Checker-board */
double x = fmod(location.x, 0.2);