From 79912f9d3f0807529183521f69f989f947c1cff1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 7 Oct 2011 03:12:11 -0500 Subject: SH-2031 Profile guided optimization of matrix ops - don't use F64 except where needed (should really factor out calls to gluProject) - get rid of sorting by texture in favor of sorting by matrix (no sort needed, geometry is already matrix sorted as a result of frustum cull tree traversal order) - unroll matrix sync inner loop and cache MVP and normal matrices --- indra/newview/llhudrender.cpp | 12 ++++++++- indra/newview/llselectmgr.cpp | 2 +- indra/newview/llviewercamera.cpp | 58 +++++++++++++++++++++++++++++----------- indra/newview/pipeline.cpp | 28 +++++-------------- indra/newview/pipeline.h | 2 +- 5 files changed, 61 insertions(+), 41 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llhudrender.cpp b/indra/newview/llhudrender.cpp index 607f7f7f4b..122711a86d 100644 --- a/indra/newview/llhudrender.cpp +++ b/indra/newview/llhudrender.cpp @@ -107,8 +107,18 @@ void hud_render_text(const LLWString &wstr, const LLVector3 &pos_agent, viewport[1] = world_view_rect.mBottom; viewport[2] = world_view_rect.getWidth(); viewport[3] = world_view_rect.getHeight(); + + F64 mdlv[16]; + F64 proj[16]; + + for (U32 i = 0; i < 16; i++) + { + mdlv[i] = (F64) gGLModelView[i]; + proj[i] = (F64) gGLProjection[i]; + } + gluProject(render_pos.mV[0], render_pos.mV[1], render_pos.mV[2], - gGLModelView, gGLProjection, (GLint*) viewport, + mdlv, proj, (GLint*) viewport, &winX, &winY, &winZ); //fonts all render orthographically, set up projection`` diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp index 3a50eeb1c9..2971ee710a 100644 --- a/indra/newview/llselectmgr.cpp +++ b/indra/newview/llselectmgr.cpp @@ -4838,7 +4838,7 @@ void LLSelectMgr::processForceObjectSelect(LLMessageSystem* msg, void**) LLSelectMgr::getInstance()->highlightObjectAndFamily(objects); } -extern LLGLdouble gGLModelView[16]; +extern F32 gGLModelView[16]; void LLSelectMgr::updateSilhouettes() { diff --git a/indra/newview/llviewercamera.cpp b/indra/newview/llviewercamera.cpp index c0ef4da1ff..a437a8b3b5 100644 --- a/indra/newview/llviewercamera.cpp +++ b/indra/newview/llviewercamera.cpp @@ -218,8 +218,15 @@ void LLViewerCamera::calcProjection(const F32 far_distance) const void LLViewerCamera::updateFrustumPlanes(LLCamera& camera, BOOL ortho, BOOL zflip, BOOL no_hacks) { GLint* viewport = (GLint*) gGLViewport; - GLdouble* model = gGLModelView; - GLdouble* proj = gGLProjection; + F64 model[16]; + F64 proj[16]; + + for (U32 i = 0; i < 16; i++) + { + model[i] = (F64) gGLModelView[i]; + proj[i] = (F64) gGLProjection[i]; + } + GLdouble objX,objY,objZ; LLVector3 frust[8]; @@ -420,7 +427,6 @@ void LLViewerCamera::setPerspective(BOOL for_selection, if (!for_selection && mZoomFactor == 1.f) { // Save GL matrices for access elsewhere in code, especially project_world_to_screen - //glGetDoublev(GL_MODELVIEW_MATRIX, gGLModelView); for (U32 i = 0; i < 16; i++) { gGLModelView[i] = modelview.m[i]; @@ -428,14 +434,6 @@ void LLViewerCamera::setPerspective(BOOL for_selection, } updateFrustumPlanes(*this); - - /*if (gSavedSettings.getBOOL("CameraOffset")) - { - gGL.matrixMode(LLRender::MM_PROJECTION); - gGL.translatef(0,0,-50); - gGL.rotatef(20.0,1,0,0); - gGL.matrixMode(LLRender::MM_MODELVIEW); - }*/ } @@ -443,11 +441,20 @@ void LLViewerCamera::setPerspective(BOOL for_selection, // screen coordinates to the agent's region. void LLViewerCamera::projectScreenToPosAgent(const S32 screen_x, const S32 screen_y, LLVector3* pos_agent) const { - GLdouble x, y, z; + + F64 mdlv[16]; + F64 proj[16]; + + for (U32 i = 0; i < 16; i++) + { + mdlv[i] = (F64) gGLModelView[i]; + proj[i] = (F64) gGLProjection[i]; + } + gluUnProject( GLdouble(screen_x), GLdouble(screen_y), 0.0, - gGLModelView, gGLProjection, (GLint*)gGLViewport, + mdlv, proj, (GLint*)gGLViewport, &x, &y, &z ); @@ -484,8 +491,17 @@ BOOL LLViewerCamera::projectPosAgentToScreen(const LLVector3 &pos_agent, LLCoord viewport[2] = world_view_rect.getWidth(); viewport[3] = world_view_rect.getHeight(); + F64 mdlv[16]; + F64 proj[16]; + + for (U32 i = 0; i < 16; i++) + { + mdlv[i] = (F64) gGLModelView[i]; + proj[i] = (F64) gGLProjection[i]; + } + if (GL_TRUE == gluProject(pos_agent.mV[VX], pos_agent.mV[VY], pos_agent.mV[VZ], - gGLModelView, gGLProjection, (GLint*)viewport, + mdlv, proj, (GLint*)viewport, &x, &y, &z)) { // convert screen coordinates to virtual UI coordinates @@ -587,9 +603,19 @@ BOOL LLViewerCamera::projectPosAgentToScreenEdge(const LLVector3 &pos_agent, viewport[2] = world_view_rect.getWidth(); viewport[3] = world_view_rect.getHeight(); GLdouble x, y, z; // object's window coords, GL-style + + F64 mdlv[16]; + F64 proj[16]; + + for (U32 i = 0; i < 16; i++) + { + mdlv[i] = (F64) gGLModelView[i]; + proj[i] = (F64) gGLProjection[i]; + } + if (GL_TRUE == gluProject(pos_agent.mV[VX], pos_agent.mV[VY], - pos_agent.mV[VZ], gGLModelView, - gGLProjection, (GLint*)viewport, + pos_agent.mV[VZ], mdlv, + proj, (GLint*)viewport, &x, &y, &z)) { x /= gViewerWindow->getDisplayScale().mV[VX]; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index d28bb1f64e..42873dbca8 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -201,13 +201,10 @@ U32 nhpo2(U32 v) return r; } -glh::matrix4f glh_copy_matrix(GLdouble* src) +glh::matrix4f glh_copy_matrix(F32* src) { glh::matrix4f ret; - for (U32 i = 0; i < 16; i++) - { - ret.m[i] = (F32) src[i]; - } + ret.set_value(src); return ret; } @@ -231,7 +228,7 @@ glh::matrix4f glh_get_last_projection() return glh_copy_matrix(gGLLastProjection); } -void glh_copy_matrix(const glh::matrix4f& src, GLdouble* dst) +void glh_copy_matrix(const glh::matrix4f& src, F32* dst) { for (U32 i = 0; i < 16; i++) { @@ -3171,19 +3168,6 @@ void LLPipeline::postSort(LLCamera& camera) if (!sShadowRender) { - //sort by texture or bump map - for (U32 i = 0; i < LLRenderPass::NUM_RENDER_TYPES; ++i) - { - if (i == LLRenderPass::PASS_BUMP) - { - std::sort(sCull->beginRenderMap(i), sCull->endRenderMap(i), LLDrawInfo::CompareBump()); - } - else - { - std::sort(sCull->beginRenderMap(i), sCull->endRenderMap(i), LLDrawInfo::CompareTexturePtrMatrix()); - } - } - std::sort(sCull->beginAlphaGroups(), sCull->endAlphaGroups(), LLSpatialGroup::CompareDepthGreater()); } llpushcallstacks ; @@ -3503,8 +3487,8 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate) assertInitialized(); - F64 saved_modelview[16]; - F64 saved_projection[16]; + F32 saved_modelview[16]; + F32 saved_projection[16]; //HACK: preserve/restore matrices around HUD render if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD)) @@ -6768,7 +6752,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, U32 n { cube_map->enable(channel); cube_map->bind(); - F64* m = gGLModelView; + F32* m = gGLModelView; F32 mat[] = { m[0], m[1], m[2], diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h index d24bab747b..86579261ca 100644 --- a/indra/newview/pipeline.h +++ b/indra/newview/pipeline.h @@ -72,7 +72,7 @@ BOOL compute_min_max(LLMatrix4& box, LLVector2& min, LLVector2& max); // Shouldn bool LLRayAABB(const LLVector3 ¢er, const LLVector3 &size, const LLVector3& origin, const LLVector3& dir, LLVector3 &coord, F32 epsilon = 0); BOOL setup_hud_matrices(); // use whole screen to render hud BOOL setup_hud_matrices(const LLRect& screen_region); // specify portion of screen (in pixels) to render hud attachments from (for picking) -glh::matrix4f glh_copy_matrix(GLdouble* src); +glh::matrix4f glh_copy_matrix(F32* src); glh::matrix4f glh_get_current_modelview(); void glh_set_current_modelview(const glh::matrix4f& mat); glh::matrix4f glh_get_current_projection(); -- cgit v1.2.3