Investigate why the disable depth Bclamp doesn't work

This commit is contained in:
samcake 2016-08-31 19:14:35 -07:00
parent 885dfd3cf7
commit 354cbbc927
16 changed files with 115 additions and 47 deletions

View file

@ -25,7 +25,10 @@ void GLBackend::do_beginQuery(const Batch& batch, size_t paramOffset) {
auto query = batch._queries.get(batch._params[paramOffset]._uint);
GLQuery* glquery = syncGPUObject(*query);
if (glquery) {
glGetInteger64v(GL_TIMESTAMP, (GLint64*)&glquery->_batchElapsedTime);
PROFILE_RANGE_BEGIN(glquery->_profileRangeId, query->getName().c_str(), 0xFFFF7F00);
//glGetInteger64v(GL_TIMESTAMP, (GLint64*)&glquery->_batchElapsedTime);
glquery->_batchElapsedTime = usecTimestampNow() * 1000;
if (timeElapsed) {
glBeginQuery(GL_TIME_ELAPSED, glquery->_endqo);
} else {
@ -45,9 +48,13 @@ void GLBackend::do_endQuery(const Batch& batch, size_t paramOffset) {
glQueryCounter(glquery->_endqo, GL_TIMESTAMP);
}
GLint64 now;
glGetInteger64v(GL_TIMESTAMP, &now);
//glGetInteger64v(GL_TIMESTAMP, &now);
now = usecTimestampNow() * 1000;
glquery->_batchElapsedTime = now - glquery->_batchElapsedTime;
PROFILE_RANGE_END(glquery->_profileRangeId);
(void)CHECK_GL_ERROR();
}
}

View file

@ -49,6 +49,7 @@ public:
const GLuint _beginqo = { 0 };
GLuint64 _result { (GLuint64)-1 };
GLuint64 _batchElapsedTime { (GLuint64) 0 };
uint64_t _profileRangeId { 0 };
protected:
GLQuery(const std::weak_ptr<GLBackend>& backend, const Query& query, GLuint endId, GLuint beginId) : Parent(backend, query, endId), _beginqo(beginId) {}

View file

@ -15,8 +15,9 @@
using namespace gpu;
Query::Query(const Handler& returnHandler) :
_returnHandler(returnHandler)
Query::Query(const Handler& returnHandler, const std::string& name) :
_returnHandler(returnHandler),
_name(name)
{
}
@ -41,14 +42,15 @@ void Query::triggerReturnHandler(uint64_t queryResult, uint64_t batchElapsedTime
}
RangeTimer::RangeTimer() {
RangeTimer::RangeTimer(const std::string& name) :
_name(name) {
for (int i = 0; i < QUERY_QUEUE_SIZE; i++) {
_timerQueries.push_back(std::make_shared<gpu::Query>([&, i] (const Query& query) {
_tailIndex ++;
_movingAverageGPU.addSample(query.getGPUElapsedTime());
_movingAverageBatch.addSample(query.getBatchElapsedTime());
}));
}, _name));
}
}

View file

@ -15,6 +15,7 @@
#include <memory>
#include <functional>
#include <vector>
#include <string>
#include <SimpleMovingAverage.h>
#include "Format.h"
@ -27,18 +28,21 @@ namespace gpu {
public:
using Handler = std::function<void(const Query&)>;
Query(const Handler& returnHandler);
Query(const Handler& returnHandler, const std::string& name = "gpu::query");
~Query();
double getGPUElapsedTime() const;
double getBatchElapsedTime() const;
const std::string& getName() const { return _name; }
// Only for gpu::Context
const GPUObjectPointer gpuObject {};
void triggerReturnHandler(uint64_t queryResult, uint64_t batchElapsedTime);
protected:
Handler _returnHandler;
std::string _name;
uint64_t _queryResult { 0 };
uint64_t _usecBatchElapsedTime { 0 };
};
@ -52,7 +56,7 @@ namespace gpu {
// The result is always a late average of the time spent for that same task a few cycles ago.
class RangeTimer {
public:
RangeTimer();
RangeTimer(const std::string& name);
void begin(gpu::Batch& batch);
void end(gpu::Batch& batch);
@ -63,6 +67,7 @@ namespace gpu {
static const int QUERY_QUEUE_SIZE { 4 };
std::string _name;
gpu::Queries _timerQueries;
int _headIndex = -1;
int _tailIndex = -1;

View file

@ -351,6 +351,10 @@ void AmbientOcclusionEffect::run(const render::SceneContextPointer& sceneContext
auto sourceViewport = args->_viewport;
auto occlusionViewport = sourceViewport;
if (!_gpuTimer) {
_gpuTimer = std::make_shared < gpu::RangeTimer>(__FUNCTION__);
}
if (!_framebuffer) {
_framebuffer = std::make_shared<AmbientOcclusionFramebuffer>();
}
@ -384,7 +388,7 @@ void AmbientOcclusionEffect::run(const render::SceneContextPointer& sceneContext
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
batch.enableStereo(false);
_gpuTimer.begin(batch);
_gpuTimer->begin(batch);
batch.setViewportTransform(occlusionViewport);
batch.setProjectionTransform(glm::mat4());
@ -428,12 +432,12 @@ void AmbientOcclusionEffect::run(const render::SceneContextPointer& sceneContext
batch.setResourceTexture(AmbientOcclusionEffect_LinearDepthMapSlot, nullptr);
batch.setResourceTexture(AmbientOcclusionEffect_OcclusionMapSlot, nullptr);
_gpuTimer.end(batch);
_gpuTimer->end(batch);
});
// Update the timer
auto config = std::static_pointer_cast<Config>(renderContext->jobConfig);
config->setGPUBatchRunTime(_gpuTimer.getGPUAverage(), _gpuTimer.getBatchAverage());
config->setGPUBatchRunTime(_gpuTimer->getGPUAverage(), _gpuTimer->getBatchAverage());
}

View file

@ -12,6 +12,7 @@
#ifndef hifi_AmbientOcclusionEffect_h
#define hifi_AmbientOcclusionEffect_h
#include <string>
#include <DependencyManager.h>
#include "render/DrawTask.h"
@ -188,7 +189,7 @@ private:
AmbientOcclusionFramebufferPointer _framebuffer;
gpu::RangeTimer _gpuTimer;
gpu::RangeTimerPointer _gpuTimer;
friend class DebugAmbientOcclusion;
};

View file

@ -219,8 +219,9 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo
if (lightVolume) {
state->setCullMode(gpu::State::CULL_BACK);
state->setDepthTest(true, false, gpu::LESS_EQUAL);
state->setDepthTest(true, true, gpu::LESS_EQUAL);
state->setDepthClampEnable(true);
// TODO: We should use DepthClamp and avoid changing geometry for inside /outside cases
// additive blending
state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
@ -598,11 +599,11 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext,
// TODO: We shouldn;t have to do that test and use a different volume geometry for when inside the vlight volume,
// we should be able to draw thre same geometry use DepthClamp but for unknown reason it's s not working...
if (glm::distance(eyePoint, glm::vec3(light->getPosition())) < expandedRadius + nearRadius) {
/* if (glm::distance(eyePoint, glm::vec3(light->getPosition())) < expandedRadius + nearRadius) {
sphereParam.w = 0.0f;
batch._glUniform4fv(deferredLightingEffect->_pointLightLocations->sphereParam, 1, reinterpret_cast< const float* >(&sphereParam));
batch.draw(gpu::TRIANGLE_STRIP, 4);
} else {
} else*/ {
sphereParam.w = 1.0f;
batch._glUniform4fv(deferredLightingEffect->_pointLightLocations->sphereParam, 1, reinterpret_cast< const float* >(&sphereParam));
@ -647,12 +648,12 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext,
// TODO: We shouldn;t have to do that test and use a different volume geometry for when inside the vlight volume,
// we should be able to draw thre same geometry use DepthClamp but for unknown reason it's s not working...
const float OVER_CONSERVATIVE_SCALE = 1.1f;
if ((eyeHalfPlaneDistance > -nearRadius) &&
/* if ((eyeHalfPlaneDistance > -nearRadius) &&
(glm::distance(eyePoint, glm::vec3(light->getPosition())) < (expandedRadius * OVER_CONSERVATIVE_SCALE) + nearRadius)) {
coneParam.w = 0.0f;
batch._glUniform4fv(deferredLightingEffect->_spotLightLocations->coneParam, 1, reinterpret_cast< const float* >(&coneParam));
batch.draw(gpu::TRIANGLE_STRIP, 4);
} else {
} else*/ {
coneParam.w = 1.0f;
batch._glUniform4fv(deferredLightingEffect->_spotLightLocations->coneParam, 1, reinterpret_cast< const float* >(&coneParam));
@ -720,8 +721,12 @@ void RenderDeferred::run(const SceneContextPointer& sceneContext, const RenderCo
auto subsurfaceScatteringResource = inputs.get5();
auto args = renderContext->args;
if (!_gpuTimer) {
_gpuTimer = std::make_shared < gpu::RangeTimer>(__FUNCTION__);
}
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
_gpuTimer.begin(batch);
_gpuTimer->begin(batch);
});
setupJob.run(sceneContext, renderContext, deferredTransform, deferredFramebuffer, lightingModel, surfaceGeometryFramebuffer, ssaoFramebuffer, subsurfaceScatteringResource);
@ -731,9 +736,9 @@ void RenderDeferred::run(const SceneContextPointer& sceneContext, const RenderCo
cleanupJob.run(sceneContext, renderContext);
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
_gpuTimer.end(batch);
_gpuTimer->end(batch);
});
auto config = std::static_pointer_cast<Config>(renderContext->jobConfig);
config->setGPUBatchRunTime(_gpuTimer.getGPUAverage(), _gpuTimer.getBatchAverage());
config->setGPUBatchRunTime(_gpuTimer->getGPUAverage(), _gpuTimer->getBatchAverage());
}

View file

@ -183,7 +183,7 @@ public:
RenderDeferredCleanup cleanupJob;
protected:
gpu::RangeTimer _gpuTimer;
gpu::RangeTimerPointer _gpuTimer;
};
#endif // hifi_DeferredLightingEffect_h

View file

@ -101,7 +101,7 @@ RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) {
const auto primaryFramebuffer = addJob<PreparePrimaryFramebuffer>("PreparePrimaryBuffer");
// const auto fullFrameRangeTimer = addJob<BeginGPURangeTimer>("BeginRangeTimer");
const auto opaqueRangeTimer = addJob<BeginGPURangeTimer>("BeginOpaqueRangeTimer");
const auto opaqueRangeTimer = addJob<BeginGPURangeTimer>("BeginOpaqueRangeTimer", "DrawOpaques");
const auto prepareDeferredInputs = PrepareDeferred::Inputs(primaryFramebuffer, lightingModel).hasVarying();
const auto prepareDeferredOutputs = addJob<PrepareDeferred>("PrepareDeferred", prepareDeferredInputs);
@ -146,8 +146,8 @@ RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) {
addJob<DrawLight>("DrawLight", lights);
const auto deferredLightingInputs = RenderDeferred::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel,
surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, scatteringResource).hasVarying();
surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, scatteringResource).hasVarying();
// DeferredBuffer is complete, now let's shade it into the LightingBuffer
addJob<RenderDeferred>("RenderDeferred", deferredLightingInputs);
@ -159,7 +159,7 @@ RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) {
const auto transparentsInputs = DrawDeferred::Inputs(transparents, lightingModel).hasVarying();
addJob<DrawDeferred>("DrawTransparentDeferred", transparentsInputs, shapePlumber);
const auto toneAndPostRangeTimer = addJob<BeginGPURangeTimer>("BeginToneAndPostRangeTimer");
const auto toneAndPostRangeTimer = addJob<BeginGPURangeTimer>("BeginToneAndPostRangeTimer", "PostToneOverlaysAntialiasing");
// Lighting Buffer ready for tone mapping
const auto toneMappingInputs = render::Varying(ToneMappingDeferred::Inputs(lightingFramebuffer, primaryFramebuffer));
@ -174,9 +174,9 @@ RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) {
// Debugging stages
{
// Debugging Deferred buffer job
const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer));
addJob<DebugDeferredBuffer>("DebugDeferredBuffer", debugFramebuffers);
// Debugging Deferred buffer job
const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer));
addJob<DebugDeferredBuffer>("DebugDeferredBuffer", debugFramebuffers);
addJob<DebugSubsurfaceScattering>("DebugScattering", deferredLightingInputs);

View file

@ -21,7 +21,7 @@ class BeginGPURangeTimer {
public:
using JobModel = render::Job::ModelO<BeginGPURangeTimer, gpu::RangeTimerPointer>;
BeginGPURangeTimer() : _gpuTimer(std::make_shared<gpu::RangeTimer>()) {}
BeginGPURangeTimer(const std::string& name) : _gpuTimer(std::make_shared<gpu::RangeTimer>(name)) {}
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, gpu::RangeTimerPointer& timer);
@ -146,7 +146,7 @@ public:
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const Inputs& inputs);
protected:
gpu::RangeTimer _gpuTimer;
gpu::RangeTimerPointer _gpuTimer;
};
class DrawOverlay3DConfig : public render::Job::Config {
@ -205,7 +205,7 @@ public:
using JobModel = Model<RenderDeferredTask, Config>;
protected:
gpu::RangeTimer _gpuTimer;
gpu::RangeTimerPointer _gpuTimer;
};
#endif // hifi_RenderDeferredTask_h

View file

@ -61,9 +61,9 @@ void LinearDepthFramebuffer::updatePrimaryDepth(const gpu::TexturePointer& depth
void LinearDepthFramebuffer::clear() {
_linearDepthFramebuffer.reset();
_linearDepthTexture.reset();
_downsampleFramebuffer.reset();
_halfLinearDepthTexture.reset();
_halfNormalTexture.reset();
_downsampleFramebuffer.reset();
_halfLinearDepthTexture.reset();
_halfNormalTexture.reset();
}
void LinearDepthFramebuffer::allocate() {
@ -142,6 +142,10 @@ void LinearDepthPass::run(const render::SceneContextPointer& sceneContext, const
const auto frameTransform = inputs.get0();
const auto deferredFramebuffer = inputs.get1();
if (!_gpuTimer) {
_gpuTimer = std::make_shared < gpu::RangeTimer>(__FUNCTION__);
}
if (!_linearDepthFramebuffer) {
_linearDepthFramebuffer = std::make_shared<LinearDepthFramebuffer>();
}
@ -171,7 +175,7 @@ void LinearDepthPass::run(const render::SceneContextPointer& sceneContext, const
float clearLinearDepth = args->getViewFrustum().getFarClip() * 2.0f;
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
_gpuTimer.begin(batch);
_gpuTimer->begin(batch);
batch.enableStereo(false);
batch.setViewportTransform(depthViewport);
@ -197,11 +201,11 @@ void LinearDepthPass::run(const render::SceneContextPointer& sceneContext, const
batch.setPipeline(downsamplePipeline);
batch.draw(gpu::TRIANGLE_STRIP, 4);
_gpuTimer.end(batch);
_gpuTimer->end(batch);
});
auto config = std::static_pointer_cast<Config>(renderContext->jobConfig);
config->setGPUBatchRunTime(_gpuTimer.getGPUAverage(), _gpuTimer.getBatchAverage());
config->setGPUBatchRunTime(_gpuTimer->getGPUAverage(), _gpuTimer->getBatchAverage());
}
@ -406,6 +410,10 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c
RenderArgs* args = renderContext->args;
if (!_gpuTimer) {
_gpuTimer = std::make_shared < gpu::RangeTimer>(__FUNCTION__);
}
const auto frameTransform = inputs.get0();
const auto deferredFramebuffer = inputs.get1();
const auto linearDepthFramebuffer = inputs.get2();
@ -458,7 +466,7 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
_gpuTimer.begin(batch);
_gpuTimer->begin(batch);
batch.enableStereo(false);
batch.setProjectionTransform(glm::mat4());
@ -519,12 +527,12 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c
batch.setResourceTexture(BlurTask_DepthSlot, nullptr);
batch.setUniformBuffer(BlurTask_ParamsSlot, nullptr);
_gpuTimer.end(batch);
_gpuTimer->end(batch);
});
auto config = std::static_pointer_cast<Config>(renderContext->jobConfig);
config->setGPUBatchRunTime(_gpuTimer.getGPUAverage(), _gpuTimer.getBatchAverage());
config->setGPUBatchRunTime(_gpuTimer->getGPUAverage(), _gpuTimer->getBatchAverage());
}

View file

@ -87,7 +87,7 @@ private:
const gpu::PipelinePointer& getDownsamplePipeline();
gpu::PipelinePointer _downsamplePipeline;
gpu::RangeTimer _gpuTimer;
gpu::RangeTimerPointer _gpuTimer;
};
@ -202,7 +202,7 @@ private:
render::BlurGaussianDepthAware _diffusePass;
gpu::RangeTimer _gpuTimer;
gpu::RangeTimerPointer _gpuTimer;
};
#endif // hifi_SurfaceGeometryPass_h

View file

@ -31,14 +31,14 @@ in vec4 _texCoord0;
out vec4 _fragColor;
void main(void) {
_fragColor = vec4(1.0, 0.0, 0.0, 1.0);//
return;
DeferredFrameTransform deferredTransform = getDeferredFrameTransform();
// Grab the fragment data from the uv
vec2 texCoord = _texCoord0.st / _texCoord0.q;
texCoord *= texcoordFrameTransform.zw;
texCoord += texcoordFrameTransform.xy;
DeferredFragment frag = unpackDeferredFragment(deferredTransform, texCoord);
if (frag.mode == FRAG_MODE_UNLIT) {
@ -66,6 +66,11 @@ void main(void) {
discard;
}
// Frag to eye vec
vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0);
vec3 fragEyeDir = normalize(fragEyeVector.xyz);

View file

@ -21,8 +21,26 @@ bool nsightActive() {
return nsightLaunched;
}
uint64_t ProfileRange::beginRange(const char* name, uint32_t argbColor) {
nvtxEventAttributes_t eventAttrib = { 0 };
eventAttrib.version = NVTX_VERSION;
eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
eventAttrib.colorType = NVTX_COLOR_ARGB;
eventAttrib.color = argbColor;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
return nvtxRangeStartEx(&eventAttrib);
// return nvtxRangePushEx(&eventAttrib);
}
void ProfileRange::endRange(uint64_t rangeId) {
nvtxRangeEnd(rangeId);
// nvtxRangePop();
}
ProfileRange::ProfileRange(const char *name) {
//_rangeId = nvtxRangeStart(name);
// _rangeId = nvtxRangeStart(name);
_rangeId = nvtxRangePush(name);
}
@ -42,7 +60,7 @@ ProfileRange::ProfileRange(const char *name, uint32_t argbColor, uint64_t payloa
}
ProfileRange::~ProfileRange() {
// nvtxRangeEnd(_rangeId);
// nvtxRangeEnd(_rangeId);
nvtxRangePop();
}

View file

@ -19,15 +19,27 @@ public:
ProfileRange(const char *name);
ProfileRange(const char *name, uint32_t argbColor, uint64_t payload);
~ProfileRange();
static uint64_t beginRange(const char* name, uint32_t argbColor);
static void endRange(uint64_t rangeId);
private:
uint64_t _rangeId{ 0 };
};
#define PROFILE_RANGE(name) ProfileRange profileRangeThis(name);
#define PROFILE_RANGE_EX(name, argbColor, payload) ProfileRange profileRangeThis(name, argbColor, (uint64_t)payload);
#define PROFILE_RANGE_BEGIN(rangeId, name, argbColor) rangeId = ProfileRange::beginRange(name, argbColor)
#define PROFILE_RANGE_END(rangeId) ProfileRange::endRange(rangeId)
#else
#define PROFILE_RANGE(name)
#define PROFILE_RANGE_EX(name, argbColor, payload)
#define PROFILE_RANGE_BEGIN(rangeId, name, argbColor)
#define PROFILE_RANGE_END(rangeId)
#endif
#endif

View file

@ -526,7 +526,7 @@ public:
_octree->init();
// Prevent web entities from rendering
REGISTER_ENTITY_TYPE_WITH_FACTORY(Web, WebEntityItem::factory);
REGISTER_ENTITY_TYPE_WITH_FACTORY(Light, LightEntityItem::factory);
// REGISTER_ENTITY_TYPE_WITH_FACTORY(Light, LightEntityItem::factory);
DependencyManager::set<ParentFinder>(_octree->getTree());
getEntities()->setViewFrustum(_viewFrustum);