Permalink
Browse files

Experimental amd gpu workaround.

  • Loading branch information...
Shyotl committed Aug 23, 2016
1 parent 8e7574b commit 583ea76c85049a38946d071e82ca3847c57463ed
Showing with 51 additions and 63 deletions.
  1. +49 −62 indra/newview/pipeline.cpp
  2. +2 −1 indra/newview/pipeline.h
View
@@ -775,6 +775,7 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
mSampleBuffer.release();
mScreen.release();
mFinalScreen.release();
mDeferredDownsampledDepth.release();
@@ -806,6 +807,7 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
}
if (!mScreen.allocate(resX, resY, screenFormat, FALSE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE)) return false;
if (!mFinalScreen.allocate(resX, resY, GL_RGBA, FALSE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE)) return false;
if (samples > 0)
{
if (!mFXAABuffer.allocate(resX, resY, GL_RGBA, FALSE, FALSE, LLTexUnit::TT_TEXTURE, FALSE)) return false;
@@ -887,6 +889,7 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
}
mFXAABuffer.release();
mScreen.release();
mFinalScreen.release();
mDeferredScreen.release(); //make sure to release any render targets that share a depth buffer with mDeferredScreen first
mDeferredDepth.release();
mDeferredDownsampledDepth.release();
@@ -909,6 +912,8 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
if (LLPipeline::sRenderDeferred)
{ //share depth buffer between deferred targets
mDeferredScreen.shareDepthBuffer(mScreen);
mDeferredScreen.shareDepthBuffer(mFinalScreen);
//mDeferredScreen.shareDepthBuffer(mDeferredLight);
/*for (U32 i = 0; i < 3; i++)
{ //share stencil buffer with screen space lightmap to stencil out sky
if (mDeferredLight[i].getTexture(0))
@@ -1008,6 +1013,7 @@ void LLPipeline::releaseLUTBuffers()
void LLPipeline::releaseScreenBuffers()
{
mScreen.release();
mFinalScreen.release();
mFXAABuffer.release();
mPhysicsDisplay.release();
mDeferredScreen.release();
@@ -6994,14 +7000,14 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b
gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA);
mScreen.bindTexture(0, 0);
mFinalScreen.bindTexture(0, 0);
gGL.color4f(1,1,1,1);
gPipeline.enableLightsFullbright(LLColor4(1,1,1,1));
drawFullScreenRect(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0);
gGL.getTexUnit(0)->unbind(mScreen.getUsage());
gGL.getTexUnit(0)->unbind(mFinalScreen.getUsage());
mGlow[1].flush();
}
@@ -7188,13 +7194,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b
mDeferredLight.bindTarget();
shader = &gDeferredCoFProgram;
bindDeferredShader(*shader);
S32 channel = shader->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mScreen.getUsage());
if (channel > -1)
{
mScreen.bindTexture(0, channel);
}
bindDeferredShader(*shader, &mFinalScreen);
shader->uniform1f(LLShaderMgr::DOF_FOCAL_DISTANCE, -subject_distance/1000.f);
shader->uniform1f(LLShaderMgr::DOF_BLUR_CONSTANT, blur_constant);
@@ -7213,32 +7213,27 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b
U32 dof_height = (U32) (mScreen.getHeight()*CameraDoFResScale);
{ //perform DoF sampling at half-res (preserve alpha channel)
mScreen.bindTarget();
mFinalScreen.bindTarget();
glViewport(0,0, dof_width, dof_height);
gGL.setColorMask(true, false);
shader = &gDeferredPostProgram;
bindDeferredShader(*shader);
S32 channel = shader->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mDeferredLight.getUsage());
if (channel > -1)
{
mDeferredLight.bindTexture(0, channel);
}
bindDeferredShader(*shader, &mDeferredLight);
shader->uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
shader->uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
drawFullScreenRect(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0);
unbindDeferredShader(*shader);
mScreen.flush();
mFinalScreen.flush();
gGL.setColorMask(true, true);
}
{ //combine result based on alpha
if (multisample)
{
mDeferredLight.bindTarget();
mScreen.bindTarget();
glViewport(0, 0, mDeferredScreen.getWidth(), mDeferredScreen.getHeight());
}
else
@@ -7251,12 +7246,11 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b
}
shader = &gDeferredDoFCombineProgram;
bindDeferredShader(*shader);
bindDeferredShader(*shader, &mFinalScreen);
S32 channel = shader->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mScreen.getUsage());
if (channel > -1)
{
mScreen.bindTexture(0, channel);
gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
}
@@ -7283,7 +7277,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b
if (multisample)
{
mDeferredLight.flush();
mScreen.flush();
}
}
}
@@ -7295,12 +7289,11 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b
}
LLGLSLShader* shader = &gDeferredPostNoDoFProgram;
bindDeferredShader(*shader);
bindDeferredShader(*shader, &mFinalScreen);
S32 channel = shader->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mScreen.getUsage());
if (channel > -1)
{
mScreen.bindTexture(0, channel);
gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
}
@@ -7331,26 +7324,29 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b
//bake out texture2D with RGBL for FXAA shader
mFXAABuffer.bindTarget();
S32 width = mScreen.getWidth();
S32 height = mScreen.getHeight();
LLRenderTarget& render_target = dof_enabled ? mScreen : mDeferredLight;
S32 width = render_target.getWidth();
S32 height = render_target.getHeight();
glViewport(0, 0, width, height);
LLGLSLShader* shader = &gGlowCombineFXAAProgram;
shader->bind();
shader->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, width, height);
bindDeferredShader(*shader, &render_target);
S32 channel = shader->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mDeferredLight.getUsage());
S32 channel = shader->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, render_target.getUsage());
if (channel > -1)
{
mDeferredLight.bindTexture(0, channel);
gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
}
drawFullScreenRect(LLVertexBuffer::MAP_VERTEX);
shader->disableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mDeferredLight.getUsage());
shader->unbind();
if (channel > -1)
{
gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
}
unbindDeferredShader(*shader);
mFXAABuffer.flush();
@@ -7479,7 +7475,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b
static LLFastTimer::DeclareTimer FTM_BIND_DEFERRED("Bind Deferred");
void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, U32 noise_map)
void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* diffuse_source, LLRenderTarget* light_source)
{
LLFastTimer t(FTM_BIND_DEFERRED);
@@ -7501,17 +7497,15 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, U32 n
static const LLCachedControl<F32> RenderEdgeNormCutoff("RenderEdgeNormCutoff",.25f);
static const LLCachedControl<F32> RenderSSAOResolutionScale("SHRenderSSAOResolutionScale",.5f);
if (noise_map == 0xFFFFFFFF)
{
noise_map = mNoiseMap;
}
diffuse_source = diffuse_source ? diffuse_source : &mDeferredScreen;
light_source = light_source ? light_source : &mDeferredLight;
shader.bind();
S32 channel = 0;
channel = shader.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mDeferredScreen.getUsage());
channel = shader.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, diffuse_source->getUsage());
if (channel > -1)
{
mDeferredScreen.bindTexture(0,channel);
diffuse_source->bindTexture(0, channel);
gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
}
@@ -7565,7 +7559,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, U32 n
channel = shader.enableTexture(LLShaderMgr::DEFERRED_NOISE);
if (channel > -1)
{
gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE, noise_map);
gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseMap);
gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
}
@@ -7577,17 +7571,10 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, U32 n
stop_glerror();
channel = shader.enableTexture(LLShaderMgr::DEFERRED_LIGHT, mDeferredLight.getUsage());
channel = shader.enableTexture(LLShaderMgr::DEFERRED_LIGHT, light_source->getUsage());
if (channel > -1)
{
if (light_index > 0)
{
mScreen.bindTexture(0, channel);
}
else
{
mDeferredLight.bindTexture(0, channel);
}
light_source->bindTexture(0, channel);
gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
}
@@ -7787,7 +7774,7 @@ void LLPipeline::renderDeferredLighting()
{
mDeferredDownsampledDepth.bindTarget();
mDeferredDownsampledDepth.clear(GL_DEPTH_BUFFER_BIT);
bindDeferredShader(gDeferredDownsampleDepthNearestProgram, 0);
bindDeferredShader(gDeferredDownsampleDepthNearestProgram);
gDeferredDownsampleDepthNearestProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, mDeferredDownsampledDepth.getWidth()/ssao_scale, mDeferredDownsampledDepth.getHeight()/ssao_scale);
{
LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
@@ -7803,7 +7790,7 @@ void LLPipeline::renderDeferredLighting()
glClearColor(1,1,1,1);
mScreen.clear(GL_COLOR_BUFFER_BIT);
glClearColor(0,0,0,0);
bindDeferredShader(gDeferredSSAOProgram, 0);
bindDeferredShader(gDeferredSSAOProgram);
if(ssao_scale < 1.f)
{
glViewport(0,0,mDeferredDownsampledDepth.getWidth(),mDeferredDownsampledDepth.getHeight());
@@ -7823,7 +7810,7 @@ void LLPipeline::renderDeferredLighting()
mDeferredLight.bindTarget();
{ //paint shadow/SSAO light map (direct lighting lightmap)
LLFastTimer ftm(FTM_SUN_SHADOW);
bindDeferredShader(gDeferredSunProgram, 0);
bindDeferredShader(gDeferredSunProgram);
glClearColor(1,1,1,1);
mDeferredLight.clear(GL_COLOR_BUFFER_BIT);
glClearColor(0,0,0,0);
@@ -7898,7 +7885,7 @@ void LLPipeline::renderDeferredLighting()
mScreen.flush();
unbindDeferredShader(gDeferredBlurLightProgram);
bindDeferredShader(gDeferredBlurLightProgram, 1);
bindDeferredShader(gDeferredBlurLightProgram, &mScreen, &mScreen);
mDeferredLight.bindTarget();
gDeferredBlurLightProgram.uniform2f(sDelta, 0.f, 1.f);
@@ -8239,7 +8226,7 @@ void LLPipeline::renderDeferredLighting()
{
LLGLDepthTest depth(GL_FALSE, GL_FALSE);
mScreen.bindTarget();
mFinalScreen.bindTarget();
// Apply gamma correction to the frame here.
gDeferredPostGammaCorrectProgram.bind();
S32 channel = 0;
@@ -8256,15 +8243,15 @@ void LLPipeline::renderDeferredLighting()
gGL.getTexUnit(channel)->unbind(mScreen.getUsage());
gDeferredPostGammaCorrectProgram.unbind();
mScreen.flush();
mFinalScreen.flush();
}
gGL.matrixMode(LLRender::MM_PROJECTION);
gGL.popMatrix();
gGL.matrixMode(LLRender::MM_MODELVIEW);
gGL.popMatrix();
mScreen.bindTarget();
mFinalScreen.bindTarget();
{ //render non-deferred geometry (alpha, fullbright, glow)
LLGLDisable blend(GL_BLEND);
@@ -8313,7 +8300,7 @@ void LLPipeline::renderDeferredLighting()
}
}
mScreen.flush();
mFinalScreen.flush();
}
@@ -8387,7 +8374,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target)
{
mDeferredDownsampledDepth.bindTarget();
mDeferredDownsampledDepth.clear(GL_DEPTH_BUFFER_BIT);
bindDeferredShader(gDeferredDownsampleDepthNearestProgram, 0);
bindDeferredShader(gDeferredDownsampleDepthNearestProgram);
gDeferredDownsampleDepthNearestProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, mDeferredDownsampledDepth.getWidth()/ssao_scale, mDeferredDownsampledDepth.getHeight()/ssao_scale);
{
LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
@@ -8403,7 +8390,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target)
glClearColor(1,1,1,1);
mScreen.clear(GL_COLOR_BUFFER_BIT);
glClearColor(0,0,0,0);
bindDeferredShader(gDeferredSSAOProgram, 0);
bindDeferredShader(gDeferredSSAOProgram);
if(ssao_scale < 1.f)
{
glViewport(0,0,mDeferredDownsampledDepth.getWidth(),mDeferredDownsampledDepth.getHeight());
@@ -8777,7 +8764,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target)
gGL.setColorMask(true, true);
}
/*mScreen.flush();
mScreen.flush();
//gamma correct lighting
gGL.matrixMode(LLRender::MM_PROJECTION);
@@ -8794,7 +8781,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target)
LLVector2 tc2((F32) mScreen.getWidth()*2,
(F32) mScreen.getHeight()*2);
mScreen.bindTarget();
mFinalScreen.bindTarget();
// Apply gamma correction to the frame here.
gDeferredPostGammaCorrectProgram.bind();
//mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
@@ -8826,15 +8813,15 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target)
gGL.getTexUnit(channel)->unbind(mScreen.getUsage());
gDeferredPostGammaCorrectProgram.unbind();
mScreen.flush();
mFinalScreen.flush();
}
gGL.matrixMode(LLRender::MM_PROJECTION);
gGL.popMatrix();
gGL.matrixMode(LLRender::MM_MODELVIEW);
gGL.popMatrix();
mScreen.bindTarget();*/
mFinalScreen.bindTarget();
{ //render non-deferred geometry (alpha, fullbright, glow)
LLGLDisable blend(GL_BLEND);
View
@@ -286,7 +286,7 @@ class LLPipeline
void renderGeomDeferred(LLCamera& camera);
void renderGeomPostDeferred(LLCamera& camera, bool do_occlusion=true);
void renderGeomShadow(LLCamera& camera);
void bindDeferredShader(LLGLSLShader& shader, U32 light_index = 0, U32 noise_map = 0xFFFFFFFF);
void bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* diffuse_source = NULL, LLRenderTarget* light_source = NULL);
void setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep);
void unbindDeferredShader(LLGLSLShader& shader);
@@ -586,6 +586,7 @@ class LLPipeline
public:
//screen texture
LLRenderTarget mScreen;
LLRenderTarget mFinalScreen;
LLRenderTarget mDeferredScreen;
private:
LLRenderTarget mFXAABuffer;

0 comments on commit 583ea76

Please sign in to comment.