History

Gathering the diffusion passes in the SUrfaceGEometryPAss job

samcake committed 10 years ago

Commit ff132fa1 parent 3638a3b7 files · +145 −65Browse files

Unified · Split

7 files
  1. interface/src/Application.cpp +2 −0
  2. libraries/render-utils/src/SurfaceGeometryPass.cpp +110 −33
  3. libraries/render-utils/src/SurfaceGeometryPass.h +21 −3
  4. libraries/render/src/render/BlurTask.cpp +5 −6
  5. libraries/render/src/render/BlurTask.h +3 −3
  6. scripts/developer/utilities/render/statsGPU.qml +0 −5
  7. scripts/developer/utilities/render/surfaceGeometryPass.qml +4 −15
interface/src/Application.cpp+2−0
@@ -305,6 +305,8 @@ public: · 304 unmodified lines
305305 // Don't actually crash in debug builds, in case this apparent deadlock is simply from
306306 // the developer actively debugging code
307307 #ifdef NDEBUG
308+
309+
308310 deadlockDetectionCrash();
309311 #endif
310312 }
libraries/render-utils/src/SurfaceGeometryPass.cpp+110−33
@@ -282,6 +282,10 @@ void SurfaceGeometryFramebuffer::updateLinearDepth(const gpu::TexturePointer& li · 281 unmodified lines
282282 void SurfaceGeometryFramebuffer::clear() {
283283 _curvatureFramebuffer.reset();
284284 _curvatureTexture.reset();
285+ _lowCurvatureFramebuffer.reset();
286+ _lowCurvatureTexture.reset();
287+ _blurringFramebuffer.reset();
288+ _blurringTexture.reset();
285289 }
286290
287291 gpu::TexturePointer SurfaceGeometryFramebuffer::getLinearDepthTexture() {
@@ -293,9 +297,17 @@ void SurfaceGeometryFramebuffer::allocate() { · 5 unmodified lines
293297 auto width = _frameSize.x;
294298 auto height = _frameSize.y;
295299
296− _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)));
300+ _curvatureTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT)));
297301 _curvatureFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
298302 _curvatureFramebuffer->setRenderBuffer(0, _curvatureTexture);
303+
304+ _lowCurvatureTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT)));
305+ _lowCurvatureFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
306+ _lowCurvatureFramebuffer->setRenderBuffer(0, _lowCurvatureTexture);
307+
308+ _blurringTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT)));
309+ _blurringFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
310+ _blurringFramebuffer->setRenderBuffer(0, _blurringTexture);
299311 }
300312
301313 gpu::FramebufferPointer SurfaceGeometryFramebuffer::getCurvatureFramebuffer() {
@@ -312,6 +324,34 @@ gpu::TexturePointer SurfaceGeometryFramebuffer::getCurvatureTexture() { · 10 unmodified lines
312324 return _curvatureTexture;
313325 }
314326
327+gpu::FramebufferPointer SurfaceGeometryFramebuffer::getLowCurvatureFramebuffer() {
328+ if (!_lowCurvatureFramebuffer) {
329+ allocate();
330+ }
331+ return _lowCurvatureFramebuffer;
332+}
333+
334+gpu::TexturePointer SurfaceGeometryFramebuffer::getLowCurvatureTexture() {
335+ if (!_lowCurvatureTexture) {
336+ allocate();
337+ }
338+ return _lowCurvatureTexture;
339+}
340+
341+gpu::FramebufferPointer SurfaceGeometryFramebuffer::getBlurringFramebuffer() {
342+ if (!_blurringFramebuffer) {
343+ allocate();
344+ }
345+ return _blurringFramebuffer;
346+}
347+
348+gpu::TexturePointer SurfaceGeometryFramebuffer::getBlurringTexture() {
349+ if (!_blurringTexture) {
350+ allocate();
351+ }
352+ return _blurringTexture;
353+}
354+
315355 void SurfaceGeometryFramebuffer::setResolutionLevel(int resolutionLevel) {
316356 if (resolutionLevel != getResolutionLevel()) {
317357 clear();
@@ -320,8 +360,7 @@ void SurfaceGeometryFramebuffer::setResolutionLevel(int resolutionLevel) { · 2 unmodified lines
320360 }
321361
322362 SurfaceGeometryPass::SurfaceGeometryPass() :
323− _firstBlurPass(false),
324− _secondBlurPass(true, _firstBlurPass.getParameters())
363+ _diffusePass(false)
325364 {
326365 Parameters parameters;
327366 _parametersBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Parameters), (const gpu::Byte*) &parameters));
@@ -345,6 +384,10 @@ void SurfaceGeometryPass::configure(const Config& config) { · 17 unmodified lines
345384 _surfaceGeometryFramebuffer = std::make_shared<SurfaceGeometryFramebuffer>();
346385 }
347386 _surfaceGeometryFramebuffer->setResolutionLevel(config.resolutionLevel);
387+
388+ _diffusePass.getParameters()->setFilterRadiusScale(config.diffuseFilterScale);
389+ _diffusePass.getParameters()->setDepthThreshold(config.diffuseDepthThreshold);
390+
348391 }
349392
350393
@@ -358,33 +401,52 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c · 7 unmodified lines
358401 const auto deferredFramebuffer = inputs.get1();
359402 const auto linearDepthFramebuffer = inputs.get2();
360403
361− auto linearDepthTexture = linearDepthFramebuffer->getHalfLinearDepthTexture();
404+
405+ auto linearDepthTexture = linearDepthFramebuffer->getLinearDepthTexture();
406+ auto normalTexture = deferredFramebuffer->getDeferredNormalTexture();
407+ auto sourceViewport = args->_viewport;
408+ auto curvatureViewport = sourceViewport;
409+
410+ if (_surfaceGeometryFramebuffer->getResolutionLevel() > 0) {
411+ linearDepthTexture = linearDepthFramebuffer->getHalfLinearDepthTexture();
412+ normalTexture = linearDepthFramebuffer->getHalfNormalTexture();
413+ curvatureViewport = curvatureViewport >> _surfaceGeometryFramebuffer->getResolutionLevel();
414+ }
362415
363416 if (!_surfaceGeometryFramebuffer) {
364417 _surfaceGeometryFramebuffer = std::make_shared<SurfaceGeometryFramebuffer>();
365418 }
366419 _surfaceGeometryFramebuffer->updateLinearDepth(linearDepthTexture);
367420
368− // auto normalTexture = deferredFramebuffer->getDeferredNormalTexture();
369− auto normalTexture = linearDepthFramebuffer->getHalfNormalTexture();
370−
371421 auto curvatureFramebuffer = _surfaceGeometryFramebuffer->getCurvatureFramebuffer();
422+ auto curvatureTexture = _surfaceGeometryFramebuffer->getCurvatureTexture();
372423 #ifdef USE_STENCIL_TEST
373− if (curvatureFBO->getDepthStencilBuffer() != deferredFramebuffer->getPrimaryDepthTexture()) {
374− curvatureFBO->setDepthStencilBuffer(deferredFramebuffer->getPrimaryDepthTexture(), deferredFramebuffer->getPrimaryDepthTexture()->getTexelFormat());
424+ if (curvatureFramebuffer->getDepthStencilBuffer() != deferredFramebuffer->getPrimaryDepthTexture()) {
425+ curvatureFramebuffer->setDepthStencilBuffer(deferredFramebuffer->getPrimaryDepthTexture(), deferredFramebuffer->getPrimaryDepthTexture()->getTexelFormat());
375426 }
376427 #endif
377− auto curvatureTexture = _surfaceGeometryFramebuffer->getCurvatureTexture();
428+
429+ auto lowCurvatureFramebuffer = _surfaceGeometryFramebuffer->getLowCurvatureFramebuffer();
430+ auto lowCurvatureTexture = _surfaceGeometryFramebuffer->getLowCurvatureTexture();
431+
432+ auto blurringFramebuffer = _surfaceGeometryFramebuffer->getBlurringFramebuffer();
433+ auto blurringTexture = _surfaceGeometryFramebuffer->getBlurringTexture();
378434
379435 outputs.edit0() = _surfaceGeometryFramebuffer;
380436 outputs.edit1() = curvatureFramebuffer;
437+ outputs.edit2() = curvatureFramebuffer;
438+ outputs.edit3() = lowCurvatureFramebuffer;
381439
382440 auto curvaturePipeline = getCurvaturePipeline();
441+ auto diffuseVPipeline = _diffusePass.getBlurVPipeline();
442+ auto diffuseHPipeline = _diffusePass.getBlurHPipeline();
383443
384− auto depthViewport = args->_viewport;
385− auto curvatureViewport = depthViewport >> 1;
386− // >> _surfaceGeometryFramebuffer->getResolutionLevel();
444+ glm::ivec2 textureSize(curvatureTexture->getDimensions());
445+ _diffusePass.getParameters()->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, curvatureViewport));
446+ _diffusePass.getParameters()->setDepthPerspective(args->getViewFrustum().getProjection()[1][1]);
447+ _diffusePass.getParameters()->setLinearDepthPosFar(args->getViewFrustum().getFarClip());
387448
449+
388450 gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
389451 _gpuTimer.begin(batch);
390452 batch.enableStereo(false);
@@ -393,43 +455,58 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c · 2 unmodified lines
393455 batch.setViewTransform(Transform());
394456
395457 batch.setViewportTransform(curvatureViewport);
396− batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(_surfaceGeometryFramebuffer->getCurvatureFrameSize(), curvatureViewport));
458+ batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(_surfaceGeometryFramebuffer->getSourceFrameSize(), curvatureViewport));
397459
460+ // Curvature pass
398461 batch.setUniformBuffer(SurfaceGeometryPass_FrameTransformSlot, frameTransform->getFrameTransformBuffer());
399462 batch.setUniformBuffer(SurfaceGeometryPass_ParamsSlot, _parametersBuffer);
400−
401− // Curvature pass
402463 batch.setFramebuffer(curvatureFramebuffer);
403−
404− // We can avoid the clear by drawing the same clear vallue from the makeCurvature shader. same performances or no worse
405−
464+ // We can avoid the clear by drawing the same clear vallue from the makeCurvature shader. same performances or no worse
406465 #ifdef USE_STENCIL_TEST
407466 // Except if stenciling out
408467 batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0));
409468 #endif
410−
411469 batch.setPipeline(curvaturePipeline);
412470 batch.setResourceTexture(SurfaceGeometryPass_DepthMapSlot, linearDepthTexture);
413471 batch.setResourceTexture(SurfaceGeometryPass_NormalMapSlot, normalTexture);
414472 batch.draw(gpu::TRIANGLE_STRIP, 4);
415473
416− batch.setResourceTexture(SurfaceGeometryPass_DepthMapSlot, nullptr);
417− batch.setResourceTexture(SurfaceGeometryPass_NormalMapSlot, nullptr);
474+ // Diffusion pass
475+ const int BlurTask_ParamsSlot = 0;
476+ const int BlurTask_SourceSlot = 0;
477+ const int BlurTask_DepthSlot = 1;
478+ batch.setUniformBuffer(BlurTask_ParamsSlot, _diffusePass.getParameters()->_parametersBuffer);
418479
419− _gpuTimer.end(batch);
420− });
480+ batch.setResourceTexture(BlurTask_DepthSlot, linearDepthTexture);
481+
482+ batch.setFramebuffer(blurringFramebuffer);
483+ batch.setPipeline(diffuseVPipeline);
484+ batch.setResourceTexture(BlurTask_SourceSlot, curvatureTexture);
485+ batch.draw(gpu::TRIANGLE_STRIP, 4);
421486
422− const auto diffuseCurvaturePassInputs = render::BlurGaussianDepthAware::Inputs(curvatureFramebuffer, linearDepthTexture);
423− gpu::FramebufferPointer midBlurredFramebuffer;
424− _firstBlurPass.run(sceneContext, renderContext, diffuseCurvaturePassInputs, midBlurredFramebuffer);
487+ batch.setFramebuffer(curvatureFramebuffer);
488+ batch.setPipeline(diffuseHPipeline);
489+ batch.setResourceTexture(BlurTask_SourceSlot, blurringTexture);
490+ batch.draw(gpu::TRIANGLE_STRIP, 4);
425491
426− gpu::FramebufferPointer lowBlurredFramebuffer;
427− _secondBlurPass.run(sceneContext, renderContext, diffuseCurvaturePassInputs, lowBlurredFramebuffer);
428−
429−
430− outputs.edit2() = midBlurredFramebuffer;
431− outputs.edit3() = lowBlurredFramebuffer;
492+ batch.setFramebuffer(blurringFramebuffer);
493+ batch.setPipeline(diffuseVPipeline);
494+ batch.setResourceTexture(BlurTask_SourceSlot, curvatureTexture);
495+ batch.draw(gpu::TRIANGLE_STRIP, 4);
432496
497+ batch.setFramebuffer(lowCurvatureFramebuffer);
498+ batch.setPipeline(diffuseHPipeline);
499+ batch.setResourceTexture(BlurTask_SourceSlot, blurringTexture);
500+ batch.draw(gpu::TRIANGLE_STRIP, 4);
501+
502+ batch.setResourceTexture(BlurTask_SourceSlot, nullptr);
503+ batch.setResourceTexture(BlurTask_DepthSlot, nullptr);
504+ batch.setUniformBuffer(BlurTask_ParamsSlot, nullptr);
505+
506+ _gpuTimer.end(batch);
507+ });
508+
509+
433510 auto config = std::static_pointer_cast<Config>(renderContext->jobConfig);
434511 config->gpuTime = _gpuTimer.getAverage();
435512 }
libraries/render-utils/src/SurfaceGeometryPass.h+21−3
@@ -112,12 +112,17 @@ public: · 111 unmodified lines
112112
113113 gpu::FramebufferPointer getCurvatureFramebuffer();
114114 gpu::TexturePointer getCurvatureTexture();
115+
116+ gpu::FramebufferPointer getLowCurvatureFramebuffer();
117+ gpu::TexturePointer getLowCurvatureTexture();
118+
119+ gpu::FramebufferPointer getBlurringFramebuffer();
120+ gpu::TexturePointer getBlurringTexture();
115121
116122 // Update the source framebuffer size which will drive the allocation of all the other resources.
117123 void updateLinearDepth(const gpu::TexturePointer& linearDepthBuffer);
118124 gpu::TexturePointer getLinearDepthTexture();
119125 const glm::ivec2& getSourceFrameSize() const { return _frameSize; }
120− glm::ivec2 getCurvatureFrameSize() const { return _frameSize >> _resolutionLevel; }
121126
122127 void setResolutionLevel(int level);
123128 int getResolutionLevel() const { return _resolutionLevel; }
@@ -131,6 +136,12 @@ protected: · 7 unmodified lines
131136 gpu::FramebufferPointer _curvatureFramebuffer;
132137 gpu::TexturePointer _curvatureTexture;
133138
139+ gpu::FramebufferPointer _blurringFramebuffer;
140+ gpu::TexturePointer _blurringTexture;
141+
142+ gpu::FramebufferPointer _lowCurvatureFramebuffer;
143+ gpu::TexturePointer _lowCurvatureTexture;
144+
134145 glm::ivec2 _frameSize;
135146 int _resolutionLevel{ 0 };
136147 };
@@ -143,6 +154,10 @@ class SurfaceGeometryPassConfig : public render::Job::Config { · 6 unmodified lines
143154 Q_PROPERTY(float basisScale MEMBER basisScale NOTIFY dirty)
144155 Q_PROPERTY(float curvatureScale MEMBER curvatureScale NOTIFY dirty)
145156 Q_PROPERTY(int resolutionLevel MEMBER resolutionLevel NOTIFY dirty)
157+
158+ Q_PROPERTY(float diffuseFilterScale MEMBER diffuseFilterScale NOTIFY dirty)
159+ Q_PROPERTY(float diffuseDepthThreshold MEMBER diffuseDepthThreshold NOTIFY dirty)
160+
146161 Q_PROPERTY(double gpuTime READ getGpuTime)
147162 public:
148163 SurfaceGeometryPassConfig() : render::Job::Config(true) {}
@@ -151,6 +166,8 @@ public: · 2 unmodified lines
151166 float basisScale{ 1.0f };
152167 float curvatureScale{ 10.0f };
153168 int resolutionLevel{ 0 };
169+ float diffuseFilterScale{ 0.2f };
170+ float diffuseDepthThreshold{ 1.0f };
154171
155172 double getGpuTime() { return gpuTime; }
156173
@@ -191,14 +208,15 @@ private: · 34 unmodified lines
191208 };
192209 gpu::BufferView _parametersBuffer;
193210
211+
194212 SurfaceGeometryFramebufferPointer _surfaceGeometryFramebuffer;
195213
196214 const gpu::PipelinePointer& getCurvaturePipeline();
197215
198216 gpu::PipelinePointer _curvaturePipeline;
217+
218+ render::BlurGaussianDepthAware _diffusePass;
199219
200− render::BlurGaussianDepthAware _firstBlurPass;
201− render::BlurGaussianDepthAware _secondBlurPass;
202220
203221 gpu::RangeTimer _gpuTimer;
204222 };
libraries/render/src/render/BlurTask.cpp+5−6
@@ -337,24 +337,23 @@ void BlurGaussianDepthAware::run(const SceneContextPointer& sceneContext, const · 336 unmodified lines
337337 auto blurHPipeline = getBlurHPipeline();
338338
339339 auto sourceViewport = args->_viewport;
340− auto blurViewport = sourceViewport >> 1;
341340
342− _parameters->setWidthHeight(blurViewport.z, blurViewport.w, args->_context->isStereo());
341+ _parameters->setWidthHeight(sourceViewport.z, sourceViewport.w, args->_context->isStereo());
343342 glm::ivec2 textureSize(blurringResources.sourceTexture->getDimensions());
344− _parameters->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, blurViewport));
343+ _parameters->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, sourceViewport));
345344 _parameters->setDepthPerspective(args->getViewFrustum().getProjection()[1][1]);
346345 _parameters->setLinearDepthPosFar(args->getViewFrustum().getFarClip());
347346
348347 gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
349348 batch.enableStereo(false);
350− batch.setViewportTransform(blurViewport);
349+ batch.setViewportTransform(sourceViewport);
351350
352351 batch.setUniformBuffer(BlurTask_ParamsSlot, _parameters->_parametersBuffer);
353352
354353 batch.setResourceTexture(BlurTask_DepthSlot, depthTexture);
355354
356355 batch.setFramebuffer(blurringResources.blurringFramebuffer);
357− // batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0));
356+ // batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0));
358357
359358 batch.setPipeline(blurVPipeline);
360359 batch.setResourceTexture(BlurTask_SourceSlot, blurringResources.sourceTexture);
@@ -362,7 +361,7 @@ void BlurGaussianDepthAware::run(const SceneContextPointer& sceneContext, const · 1 unmodified line
362361
363362 batch.setFramebuffer(blurringResources.finalFramebuffer);
364363 if (_inOutResources._generateOutputFramebuffer) {
365− // batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0));
364+ // batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0));
366365 }
367366
368367 batch.setPipeline(blurHPipeline);
libraries/render/src/render/BlurTask.h+3−3
@@ -144,6 +144,9 @@ public: · 143 unmodified lines
144144 void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Inputs& SourceAndDepth, gpu::FramebufferPointer& blurredFramebuffer);
145145
146146 const BlurParamsPointer& getParameters() const { return _parameters; }
147+
148+ gpu::PipelinePointer getBlurVPipeline();
149+ gpu::PipelinePointer getBlurHPipeline();
147150
148151 protected:
149152
@@ -152,9 +155,6 @@ protected: · 2 unmodified lines
152155 gpu::PipelinePointer _blurVPipeline;
153156 gpu::PipelinePointer _blurHPipeline;
154157
155− gpu::PipelinePointer getBlurVPipeline();
156− gpu::PipelinePointer getBlurHPipeline();
157−
158158 BlurInOutResource _inOutResources;
159159 };
160160
scripts/developer/utilities/render/statsGPU.qml+0−5
@@ -53,11 +53,6 @@ Item { · 52 unmodified lines
5353 prop: "gpuTime",
5454 label: "SurfaceGeometry",
5555 color: "#00FFFF"
56− },{
57− object: Render.getConfig("CurvatureRangeTimer"),
58− prop: "gpuTime",
59− label: "Curvature",
60− color: "#00FF00"
6156 },
6257 {
6358 object: Render.getConfig("RenderDeferred"),
scripts/developer/utilities/render/surfaceGeometryPass.qml+4−15
@@ -41,16 +41,11 @@ Column { · 40 unmodified lines
4141 min: 0.0
4242 }
4343 }
44− }
45−
46− Column{
47− CheckBox {
48− text: "Diffuse Curvature Mid"
49− checked: true
50− onCheckedChanged: { Render.getConfig("DiffuseCurvatureMid").enabled = checked }
51− }
44+
5245 Repeater {
53− 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"]
46+ model: [ "Diffusion Scale:SurfaceGeometry:diffuseFilterScale:2.0",
47+ "Diffusion Depth Threshold:SurfaceGeometry:diffuseDepthThreshold:1.0"
48+ ]
5449 ConfigSlider {
5550 label: qsTr(modelData.split(":")[0])
5651 integral: false
@@ -60,12 +55,6 @@ Column { · 3 unmodified lines
6055 min: 0.0
6156 }
6257 }
63−
64− CheckBox {
65− text: "Diffuse Curvature Low"
66− checked: true
67− onCheckedChanged: { Render.getConfig("DiffuseCurvatureLow").enabled = checked }
68− }
6958 }
7059 }
7160 }