summaryrefslogtreecommitdiff
path: root/indra/newview/llglsandbox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llglsandbox.cpp')
-rwxr-xr-x[-rw-r--r--]indra/newview/llglsandbox.cpp196
1 files changed, 190 insertions, 6 deletions
diff --git a/indra/newview/llglsandbox.cpp b/indra/newview/llglsandbox.cpp
index 1208c9378e..c80dec0e75 100644..100755
--- a/indra/newview/llglsandbox.cpp
+++ b/indra/newview/llglsandbox.cpp
@@ -62,6 +62,7 @@
#include "llresmgr.h"
#include "pipeline.h"
#include "llspatialpartition.h"
+#include "llviewershadermgr.h"
// Height of the yellow selection highlight posts for land
const F32 PARCEL_POST_HEIGHT = 0.666f;
@@ -79,10 +80,10 @@ void LLToolSelectRect::handleRectangleSelection(S32 x, S32 y, MASK mask)
S32 top = llmax(y, mDragStartY);
S32 bottom =llmin(y, mDragStartY);
- left = llround((F32) left * LLUI::sGLScaleFactor.mV[VX]);
- right = llround((F32) right * LLUI::sGLScaleFactor.mV[VX]);
- top = llround((F32) top * LLUI::sGLScaleFactor.mV[VY]);
- bottom = llround((F32) bottom * LLUI::sGLScaleFactor.mV[VY]);
+ left = ll_round((F32) left * LLUI::getScaleFactor().mV[VX]);
+ right = ll_round((F32) right * LLUI::getScaleFactor().mV[VX]);
+ top = ll_round((F32) top * LLUI::getScaleFactor().mV[VY]);
+ bottom = ll_round((F32) bottom * LLUI::getScaleFactor().mV[VY]);
F32 old_far_plane = LLViewerCamera::getInstance()->getFar();
F32 old_near_plane = LLViewerCamera::getInstance()->getNear();
@@ -623,7 +624,8 @@ void LLViewerParcelMgr::renderCollisionSegments(U8* segments, BOOL use_pass, LLV
LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
LLGLDisable cull(GL_CULL_FACE);
- if (mCollisionBanned == BA_BANNED)
+ if (mCollisionBanned == BA_BANNED ||
+ regionp->getRegionFlag(REGION_FLAGS_BLOCK_FLYOVER))
{
collision_height = BAN_HEIGHT;
}
@@ -767,7 +769,6 @@ void draw_line_cube(F32 width, const LLVector3& center)
gGL.vertex3f(center.mV[VX] + width ,center.mV[VY] - width,center.mV[VZ] - width);
}
-
void LLViewerObjectList::renderObjectBeacons()
{
if (mDebugBeacons.empty())
@@ -878,3 +879,186 @@ void LLViewerObjectList::renderObjectBeacons()
}
+F32 gpu_benchmark()
+{
+ if (!gGLManager.mHasShaderObjects || !gGLManager.mHasTimerQuery)
+ { // don't bother benchmarking the fixed function
+ // or venerable drivers which don't support accurate timing anyway
+ // and are likely to be correctly identified by the GPU table already.
+ return -1.f;
+ }
+
+ if (gBenchmarkProgram.mProgramObject == 0)
+ {
+ LLViewerShaderMgr::instance()->initAttribsAndUniforms();
+
+ gBenchmarkProgram.mName = "Benchmark Shader";
+ gBenchmarkProgram.mFeatures.attachNothing = true;
+ gBenchmarkProgram.mShaderFiles.clear();
+ gBenchmarkProgram.mShaderFiles.push_back(std::make_pair("interface/benchmarkV.glsl", GL_VERTEX_SHADER_ARB));
+ gBenchmarkProgram.mShaderFiles.push_back(std::make_pair("interface/benchmarkF.glsl", GL_FRAGMENT_SHADER_ARB));
+ gBenchmarkProgram.mShaderLevel = 1;
+ if (!gBenchmarkProgram.createShader(NULL, NULL))
+ {
+ return -1.f;
+ }
+ }
+
+ LLGLDisable blend(GL_BLEND);
+
+ //measure memory bandwidth by:
+ // - allocating a batch of textures and render targets
+ // - rendering those textures to those render targets
+ // - recording time taken
+ // - taking the median time for a given number of samples
+
+ //resolution of textures/render targets
+ const U32 res = 1024;
+
+ //number of textures
+ const U32 count = 32;
+
+ //number of samples to take
+ const S32 samples = 64;
+
+ if (gGLManager.mHasTimerQuery)
+ {
+ LLGLSLShader::initProfile();
+ }
+
+ LLRenderTarget dest[count];
+ U32 source[count];
+ LLImageGL::generateTextures(count, source);
+ std::vector<F32> results;
+
+ //build a random texture
+ U8* pixels = new U8[res*res*4];
+
+ for (U32 i = 0; i < res*res*4; ++i)
+ {
+ pixels[i] = (U8) ll_rand(255);
+ }
+
+
+ gGL.setColorMask(true, true);
+ LLGLDepthTest depth(GL_FALSE);
+
+ for (U32 i = 0; i < count; ++i)
+ { //allocate render targets and textures
+ dest[i].allocate(res,res,GL_RGBA,false, false, LLTexUnit::TT_TEXTURE, true);
+ dest[i].bindTarget();
+ dest[i].clear();
+ dest[i].flush();
+
+ gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, source[i]);
+ LLImageGL::setManualImage(GL_TEXTURE_2D, 0, GL_RGBA, res,res,GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+ }
+
+ delete [] pixels;
+
+ //make a dummy triangle to draw with
+ LLPointer<LLVertexBuffer> buff = new LLVertexBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0, GL_STATIC_DRAW_ARB);
+ buff->allocateBuffer(3, 0, true);
+
+ LLStrider<LLVector3> v;
+ LLStrider<LLVector2> tc;
+
+ buff->getVertexStrider(v);
+
+ v[0].set(-1,1,0);
+ v[1].set(-1,-3,0);
+ v[2].set(3,1,0);
+
+ buff->flush();
+
+ gBenchmarkProgram.bind();
+
+ bool busted_finish = false;
+
+ buff->setBuffer(LLVertexBuffer::MAP_VERTEX);
+ glFinish();
+
+ for (S32 c = -1; c < samples; ++c)
+ {
+ LLTimer timer;
+ timer.start();
+
+ for (U32 i = 0; i < count; ++i)
+ {
+ dest[i].bindTarget();
+ gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, source[i]);
+ buff->drawArrays(LLRender::TRIANGLES, 0, 3);
+ dest[i].flush();
+ }
+
+ //wait for current batch of copies to finish
+ if (busted_finish)
+ {
+ //read a pixel off the last target since some drivers seem to ignore glFinish
+ dest[count-1].bindTarget();
+ U32 pixel = 0;
+ glReadPixels(0,0,1,1,GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
+ dest[count-1].flush();
+ }
+ else
+ {
+ glFinish();
+ }
+
+ F32 time = timer.getElapsedTimeF32();
+
+ if (c >= 0) // <-- ignore the first sample as it tends to be artificially slow
+ {
+ //store result in gigabytes per second
+ F32 gb = (F32) ((F64) (res*res*8*count))/(1000000000);
+
+ F32 gbps = gb/time;
+
+ if (!gGLManager.mHasTimerQuery && !busted_finish && gbps > 128.f)
+ { //unrealistically high bandwidth for a card without timer queries, glFinish is probably ignored
+ busted_finish = true;
+ LL_WARNS() << "GPU Benchmark detected GL driver with broken glFinish implementation." << LL_ENDL;
+ }
+ else
+ {
+ results.push_back(gbps);
+ }
+ }
+ }
+
+ gBenchmarkProgram.unbind();
+
+ if (gGLManager.mHasTimerQuery)
+ {
+ LLGLSLShader::finishProfile(false);
+ }
+
+ LLImageGL::deleteTextures(count, source);
+
+ std::sort(results.begin(), results.end());
+
+ F32 gbps = results[results.size()/2];
+
+ LL_INFOS() << "Memory bandwidth is " << llformat("%.3f", gbps) << "GB/sec according to CPU timers" << LL_ENDL;
+
+#if LL_DARWIN
+ if (gbps > 512.f)
+ {
+ LL_WARNS() << "Memory bandwidth is improbably high and likely incorrect; discarding result." << LL_ENDL;
+ //OSX is probably lying, discard result
+ gbps = -1.f;
+ }
+#endif
+
+ F32 ms = gBenchmarkProgram.mTimeElapsed/1000000.f;
+ F32 seconds = ms/1000.f;
+
+ F64 samples_drawn = res*res*count*samples;
+ F32 samples_sec = (samples_drawn/1000000000.0)/seconds;
+ gbps = samples_sec*8;
+
+ LL_INFOS() << "Memory bandwidth is " << llformat("%.3f", gbps) << "GB/sec according to ARB_timer_query" << LL_ENDL;
+
+ return gbps;
+}
+