Gathering the diffusion passes in the SUrfaceGEometryPAss job

This commit is contained in:
samcake 2016-07-19 02:11:22 -07:00
parent 3638a3b9c3
commit ff132fa712
7 changed files with 146 additions and 66 deletions

View file

@ -305,6 +305,8 @@ public:
// Don't actually crash in debug builds, in case this apparent deadlock is simply from
// the developer actively debugging code
#ifdef NDEBUG
deadlockDetectionCrash();
#endif
}

View file

@ -282,6 +282,10 @@ void SurfaceGeometryFramebuffer::updateLinearDepth(const gpu::TexturePointer& li
void SurfaceGeometryFramebuffer::clear() {
_curvatureFramebuffer.reset();
_curvatureTexture.reset();
_lowCurvatureFramebuffer.reset();
_lowCurvatureTexture.reset();
_blurringFramebuffer.reset();
_blurringTexture.reset();
}
gpu::TexturePointer SurfaceGeometryFramebuffer::getLinearDepthTexture() {
@ -293,9 +297,17 @@ void SurfaceGeometryFramebuffer::allocate() {
auto width = _frameSize.x;
auto height = _frameSize.y;
_curvatureTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width >> getResolutionLevel(), height >> getResolutionLevel(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT)));
_curvatureTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT)));
_curvatureFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
_curvatureFramebuffer->setRenderBuffer(0, _curvatureTexture);
_lowCurvatureTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT)));
_lowCurvatureFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
_lowCurvatureFramebuffer->setRenderBuffer(0, _lowCurvatureTexture);
_blurringTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT)));
_blurringFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
_blurringFramebuffer->setRenderBuffer(0, _blurringTexture);
}
gpu::FramebufferPointer SurfaceGeometryFramebuffer::getCurvatureFramebuffer() {
@ -312,6 +324,34 @@ gpu::TexturePointer SurfaceGeometryFramebuffer::getCurvatureTexture() {
return _curvatureTexture;
}
gpu::FramebufferPointer SurfaceGeometryFramebuffer::getLowCurvatureFramebuffer() {
if (!_lowCurvatureFramebuffer) {
allocate();
}
return _lowCurvatureFramebuffer;
}
gpu::TexturePointer SurfaceGeometryFramebuffer::getLowCurvatureTexture() {
if (!_lowCurvatureTexture) {
allocate();
}
return _lowCurvatureTexture;
}
gpu::FramebufferPointer SurfaceGeometryFramebuffer::getBlurringFramebuffer() {
if (!_blurringFramebuffer) {
allocate();
}
return _blurringFramebuffer;
}
gpu::TexturePointer SurfaceGeometryFramebuffer::getBlurringTexture() {
if (!_blurringTexture) {
allocate();
}
return _blurringTexture;
}
void SurfaceGeometryFramebuffer::setResolutionLevel(int resolutionLevel) {
if (resolutionLevel != getResolutionLevel()) {
clear();
@ -320,8 +360,7 @@ void SurfaceGeometryFramebuffer::setResolutionLevel(int resolutionLevel) {
}
SurfaceGeometryPass::SurfaceGeometryPass() :
_firstBlurPass(false),
_secondBlurPass(true, _firstBlurPass.getParameters())
_diffusePass(false)
{
Parameters parameters;
_parametersBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Parameters), (const gpu::Byte*) &parameters));
@ -345,6 +384,10 @@ void SurfaceGeometryPass::configure(const Config& config) {
_surfaceGeometryFramebuffer = std::make_shared<SurfaceGeometryFramebuffer>();
}
_surfaceGeometryFramebuffer->setResolutionLevel(config.resolutionLevel);
_diffusePass.getParameters()->setFilterRadiusScale(config.diffuseFilterScale);
_diffusePass.getParameters()->setDepthThreshold(config.diffuseDepthThreshold);
}
@ -358,33 +401,52 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c
const auto deferredFramebuffer = inputs.get1();
const auto linearDepthFramebuffer = inputs.get2();
auto linearDepthTexture = linearDepthFramebuffer->getHalfLinearDepthTexture();
auto linearDepthTexture = linearDepthFramebuffer->getLinearDepthTexture();
auto normalTexture = deferredFramebuffer->getDeferredNormalTexture();
auto sourceViewport = args->_viewport;
auto curvatureViewport = sourceViewport;
if (_surfaceGeometryFramebuffer->getResolutionLevel() > 0) {
linearDepthTexture = linearDepthFramebuffer->getHalfLinearDepthTexture();
normalTexture = linearDepthFramebuffer->getHalfNormalTexture();
curvatureViewport = curvatureViewport >> _surfaceGeometryFramebuffer->getResolutionLevel();
}
if (!_surfaceGeometryFramebuffer) {
_surfaceGeometryFramebuffer = std::make_shared<SurfaceGeometryFramebuffer>();
}
_surfaceGeometryFramebuffer->updateLinearDepth(linearDepthTexture);
// auto normalTexture = deferredFramebuffer->getDeferredNormalTexture();
auto normalTexture = linearDepthFramebuffer->getHalfNormalTexture();
auto curvatureFramebuffer = _surfaceGeometryFramebuffer->getCurvatureFramebuffer();
auto curvatureTexture = _surfaceGeometryFramebuffer->getCurvatureTexture();
#ifdef USE_STENCIL_TEST
if (curvatureFBO->getDepthStencilBuffer() != deferredFramebuffer->getPrimaryDepthTexture()) {
curvatureFBO->setDepthStencilBuffer(deferredFramebuffer->getPrimaryDepthTexture(), deferredFramebuffer->getPrimaryDepthTexture()->getTexelFormat());
if (curvatureFramebuffer->getDepthStencilBuffer() != deferredFramebuffer->getPrimaryDepthTexture()) {
curvatureFramebuffer->setDepthStencilBuffer(deferredFramebuffer->getPrimaryDepthTexture(), deferredFramebuffer->getPrimaryDepthTexture()->getTexelFormat());
}
#endif
auto curvatureTexture = _surfaceGeometryFramebuffer->getCurvatureTexture();
auto lowCurvatureFramebuffer = _surfaceGeometryFramebuffer->getLowCurvatureFramebuffer();
auto lowCurvatureTexture = _surfaceGeometryFramebuffer->getLowCurvatureTexture();
auto blurringFramebuffer = _surfaceGeometryFramebuffer->getBlurringFramebuffer();
auto blurringTexture = _surfaceGeometryFramebuffer->getBlurringTexture();
outputs.edit0() = _surfaceGeometryFramebuffer;
outputs.edit1() = curvatureFramebuffer;
outputs.edit2() = curvatureFramebuffer;
outputs.edit3() = lowCurvatureFramebuffer;
auto curvaturePipeline = getCurvaturePipeline();
auto diffuseVPipeline = _diffusePass.getBlurVPipeline();
auto diffuseHPipeline = _diffusePass.getBlurHPipeline();
auto depthViewport = args->_viewport;
auto curvatureViewport = depthViewport >> 1;
// >> _surfaceGeometryFramebuffer->getResolutionLevel();
glm::ivec2 textureSize(curvatureTexture->getDimensions());
_diffusePass.getParameters()->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, curvatureViewport));
_diffusePass.getParameters()->setDepthPerspective(args->getViewFrustum().getProjection()[1][1]);
_diffusePass.getParameters()->setLinearDepthPosFar(args->getViewFrustum().getFarClip());
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
_gpuTimer.begin(batch);
batch.enableStereo(false);
@ -393,43 +455,58 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c
batch.setViewTransform(Transform());
batch.setViewportTransform(curvatureViewport);
batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(_surfaceGeometryFramebuffer->getCurvatureFrameSize(), curvatureViewport));
batch.setUniformBuffer(SurfaceGeometryPass_FrameTransformSlot, frameTransform->getFrameTransformBuffer());
batch.setUniformBuffer(SurfaceGeometryPass_ParamsSlot, _parametersBuffer);
batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(_surfaceGeometryFramebuffer->getSourceFrameSize(), curvatureViewport));
// Curvature pass
batch.setUniformBuffer(SurfaceGeometryPass_FrameTransformSlot, frameTransform->getFrameTransformBuffer());
batch.setUniformBuffer(SurfaceGeometryPass_ParamsSlot, _parametersBuffer);
batch.setFramebuffer(curvatureFramebuffer);
// We can avoid the clear by drawing the same clear vallue from the makeCurvature shader. same performances or no worse
// We can avoid the clear by drawing the same clear vallue from the makeCurvature shader. same performances or no worse
#ifdef USE_STENCIL_TEST
// Except if stenciling out
batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0));
#endif
batch.setPipeline(curvaturePipeline);
batch.setResourceTexture(SurfaceGeometryPass_DepthMapSlot, linearDepthTexture);
batch.setResourceTexture(SurfaceGeometryPass_NormalMapSlot, normalTexture);
batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.setResourceTexture(SurfaceGeometryPass_DepthMapSlot, nullptr);
batch.setResourceTexture(SurfaceGeometryPass_NormalMapSlot, nullptr);
// Diffusion pass
const int BlurTask_ParamsSlot = 0;
const int BlurTask_SourceSlot = 0;
const int BlurTask_DepthSlot = 1;
batch.setUniformBuffer(BlurTask_ParamsSlot, _diffusePass.getParameters()->_parametersBuffer);
batch.setResourceTexture(BlurTask_DepthSlot, linearDepthTexture);
batch.setFramebuffer(blurringFramebuffer);
batch.setPipeline(diffuseVPipeline);
batch.setResourceTexture(BlurTask_SourceSlot, curvatureTexture);
batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.setFramebuffer(curvatureFramebuffer);
batch.setPipeline(diffuseHPipeline);
batch.setResourceTexture(BlurTask_SourceSlot, blurringTexture);
batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.setFramebuffer(blurringFramebuffer);
batch.setPipeline(diffuseVPipeline);
batch.setResourceTexture(BlurTask_SourceSlot, curvatureTexture);
batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.setFramebuffer(lowCurvatureFramebuffer);
batch.setPipeline(diffuseHPipeline);
batch.setResourceTexture(BlurTask_SourceSlot, blurringTexture);
batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.setResourceTexture(BlurTask_SourceSlot, nullptr);
batch.setResourceTexture(BlurTask_DepthSlot, nullptr);
batch.setUniformBuffer(BlurTask_ParamsSlot, nullptr);
_gpuTimer.end(batch);
});
const auto diffuseCurvaturePassInputs = render::BlurGaussianDepthAware::Inputs(curvatureFramebuffer, linearDepthTexture);
gpu::FramebufferPointer midBlurredFramebuffer;
_firstBlurPass.run(sceneContext, renderContext, diffuseCurvaturePassInputs, midBlurredFramebuffer);
gpu::FramebufferPointer lowBlurredFramebuffer;
_secondBlurPass.run(sceneContext, renderContext, diffuseCurvaturePassInputs, lowBlurredFramebuffer);
outputs.edit2() = midBlurredFramebuffer;
outputs.edit3() = lowBlurredFramebuffer;
auto config = std::static_pointer_cast<Config>(renderContext->jobConfig);
config->gpuTime = _gpuTimer.getAverage();
}

View file

@ -112,12 +112,17 @@ public:
gpu::FramebufferPointer getCurvatureFramebuffer();
gpu::TexturePointer getCurvatureTexture();
gpu::FramebufferPointer getLowCurvatureFramebuffer();
gpu::TexturePointer getLowCurvatureTexture();
gpu::FramebufferPointer getBlurringFramebuffer();
gpu::TexturePointer getBlurringTexture();
// Update the source framebuffer size which will drive the allocation of all the other resources.
void updateLinearDepth(const gpu::TexturePointer& linearDepthBuffer);
gpu::TexturePointer getLinearDepthTexture();
const glm::ivec2& getSourceFrameSize() const { return _frameSize; }
glm::ivec2 getCurvatureFrameSize() const { return _frameSize >> _resolutionLevel; }
void setResolutionLevel(int level);
int getResolutionLevel() const { return _resolutionLevel; }
@ -131,6 +136,12 @@ protected:
gpu::FramebufferPointer _curvatureFramebuffer;
gpu::TexturePointer _curvatureTexture;
gpu::FramebufferPointer _blurringFramebuffer;
gpu::TexturePointer _blurringTexture;
gpu::FramebufferPointer _lowCurvatureFramebuffer;
gpu::TexturePointer _lowCurvatureTexture;
glm::ivec2 _frameSize;
int _resolutionLevel{ 0 };
};
@ -143,6 +154,10 @@ class SurfaceGeometryPassConfig : public render::Job::Config {
Q_PROPERTY(float basisScale MEMBER basisScale NOTIFY dirty)
Q_PROPERTY(float curvatureScale MEMBER curvatureScale NOTIFY dirty)
Q_PROPERTY(int resolutionLevel MEMBER resolutionLevel NOTIFY dirty)
Q_PROPERTY(float diffuseFilterScale MEMBER diffuseFilterScale NOTIFY dirty)
Q_PROPERTY(float diffuseDepthThreshold MEMBER diffuseDepthThreshold NOTIFY dirty)
Q_PROPERTY(double gpuTime READ getGpuTime)
public:
SurfaceGeometryPassConfig() : render::Job::Config(true) {}
@ -151,6 +166,8 @@ public:
float basisScale{ 1.0f };
float curvatureScale{ 10.0f };
int resolutionLevel{ 0 };
float diffuseFilterScale{ 0.2f };
float diffuseDepthThreshold{ 1.0f };
double getGpuTime() { return gpuTime; }
@ -191,14 +208,15 @@ private:
};
gpu::BufferView _parametersBuffer;
SurfaceGeometryFramebufferPointer _surfaceGeometryFramebuffer;
const gpu::PipelinePointer& getCurvaturePipeline();
gpu::PipelinePointer _curvaturePipeline;
render::BlurGaussianDepthAware _diffusePass;
render::BlurGaussianDepthAware _firstBlurPass;
render::BlurGaussianDepthAware _secondBlurPass;
gpu::RangeTimer _gpuTimer;
};

View file

@ -337,24 +337,23 @@ void BlurGaussianDepthAware::run(const SceneContextPointer& sceneContext, const
auto blurHPipeline = getBlurHPipeline();
auto sourceViewport = args->_viewport;
auto blurViewport = sourceViewport >> 1;
_parameters->setWidthHeight(blurViewport.z, blurViewport.w, args->_context->isStereo());
_parameters->setWidthHeight(sourceViewport.z, sourceViewport.w, args->_context->isStereo());
glm::ivec2 textureSize(blurringResources.sourceTexture->getDimensions());
_parameters->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, blurViewport));
_parameters->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, sourceViewport));
_parameters->setDepthPerspective(args->getViewFrustum().getProjection()[1][1]);
_parameters->setLinearDepthPosFar(args->getViewFrustum().getFarClip());
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
batch.enableStereo(false);
batch.setViewportTransform(blurViewport);
batch.setViewportTransform(sourceViewport);
batch.setUniformBuffer(BlurTask_ParamsSlot, _parameters->_parametersBuffer);
batch.setResourceTexture(BlurTask_DepthSlot, depthTexture);
batch.setFramebuffer(blurringResources.blurringFramebuffer);
// batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0));
// batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0));
batch.setPipeline(blurVPipeline);
batch.setResourceTexture(BlurTask_SourceSlot, blurringResources.sourceTexture);
@ -362,7 +361,7 @@ void BlurGaussianDepthAware::run(const SceneContextPointer& sceneContext, const
batch.setFramebuffer(blurringResources.finalFramebuffer);
if (_inOutResources._generateOutputFramebuffer) {
// batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0));
// batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0));
}
batch.setPipeline(blurHPipeline);

View file

@ -144,6 +144,9 @@ public:
void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Inputs& SourceAndDepth, gpu::FramebufferPointer& blurredFramebuffer);
const BlurParamsPointer& getParameters() const { return _parameters; }
gpu::PipelinePointer getBlurVPipeline();
gpu::PipelinePointer getBlurHPipeline();
protected:
@ -152,9 +155,6 @@ protected:
gpu::PipelinePointer _blurVPipeline;
gpu::PipelinePointer _blurHPipeline;
gpu::PipelinePointer getBlurVPipeline();
gpu::PipelinePointer getBlurHPipeline();
BlurInOutResource _inOutResources;
};

View file

@ -53,11 +53,6 @@ Item {
prop: "gpuTime",
label: "SurfaceGeometry",
color: "#00FFFF"
},{
object: Render.getConfig("CurvatureRangeTimer"),
prop: "gpuTime",
label: "Curvature",
color: "#00FF00"
},
{
object: Render.getConfig("RenderDeferred"),

View file

@ -41,16 +41,11 @@ Column {
min: 0.0
}
}
}
Column{
CheckBox {
text: "Diffuse Curvature Mid"
checked: true
onCheckedChanged: { Render.getConfig("DiffuseCurvatureMid").enabled = checked }
}
Repeater {
model: [ "Blur Scale:DiffuseCurvatureMid:filterScale:2.0", "Blur Depth Threshold:DiffuseCurvatureMid:depthThreshold:1.0", "Blur Scale2:DiffuseCurvatureLow:filterScale:2.0", "Blur Depth Threshold 2:DiffuseCurvatureLow:depthThreshold:1.0"]
model: [ "Diffusion Scale:SurfaceGeometry:diffuseFilterScale:2.0",
"Diffusion Depth Threshold:SurfaceGeometry:diffuseDepthThreshold:1.0"
]
ConfigSlider {
label: qsTr(modelData.split(":")[0])
integral: false
@ -60,12 +55,6 @@ Column {
min: 0.0
}
}
CheckBox {
text: "Diffuse Curvature Low"
checked: true
onCheckedChanged: { Render.getConfig("DiffuseCurvatureLow").enabled = checked }
}
}
}
}