Repository: google/filament
File: filament/src/PostProcessManager.cpp (C++)

Code before:
            +DescriptorSetBindingPoints::PER_RENDERABLE , {});
}

UTILS_NOINLINE
void PostProcessManager::commitAndRenderFullScreenQuad(DriverApi& driver,
        FrameGraphResources::RenderPassInfo const& out, FMaterialInstance const* mi,
        PostProcessVariant const variant) const noexcept {
    mi->commit(driver);
    mi->use(driver);
    FMaterial const* const ma = mi->getMaterial();
    PipelineState const pipeline = getPipelineState(ma, variant);

    driver.bindDescriptorSet(mDummyPerRenderableDsh, +DescriptorSetBindingPoints::PER_RENDERABLE,
            { { 0, 0 }, driver });

    assert_invariant(
            ((out.params.readOnlyDepthStencil & RenderPassParams::READONLY_DEPTH)
             && !pipeline.rasterState.depthWrite)
            || !(out.params.readOnlyDepthStencil & RenderPassParams::READONLY_DEPTH));

    driver.beginRenderPass(out.target, out.params);
    driver.draw(pipeline, mFullScreenQuadRph, 0, 3, 1);
    driver.endRenderPass();

    driver.bindDescriptorSet({},
            +DescriptorSetBindingPoints::PER_RENDERABLE , {});
}

// ------------------------------------------------------------------------------------------------

PostProcessManager::StructurePassOutput PostProcessManager::structure(FrameGraph& fg,
        RenderPassBuilder const& passBuilder, uint8_t const structureRenderFlags,
        uint32_t width, uint32_t height,
        StructurePassConfig const& config) noexcept {

    const float scale = config.scale;

    // structure pass -- automatically culled if not used, currently used by:
    //    - ssao
    //    - contact shadows
    // It consists of a mipmapped depth pass, tuned for SSAO
    struct StructurePassData {
        FrameGraphId<FrameGraphTexture> depth;
        FrameGraphId<FrameGraphTexture> picking;
    };

    // sanitize a bit the user provided scaling factor
    width  = std::max(32u, uint32_t(std::ceil(float(width) * scale)));
    height = std::max(32u, uint32_t(std::ceil(float(height) * scale)));

    // We limit the lowest lod size to 32 pixels (which is where the -5 comes from)

Review comment (suggestion):
These can be replaced by:
`DescriptorSet::unbind(driver, DescriptorSetBindingPoints::PER_RENDERABLE);`


Code after:
}

UTILS_NOINLINE
void PostProcessManager::commitAndRenderFullScreenQuad(DriverApi& driver,
        FrameGraphResources::RenderPassInfo const& out, FMaterialInstance const* mi,
        PostProcessVariant const variant) const noexcept {
    mi->commit(driver);
    mi->use(driver);
    FMaterial const* const ma = mi->getMaterial();
    PipelineState const pipeline = getPipelineState(ma, variant);

    assert_invariant(
            ((out.params.readOnlyDepthStencil & RenderPassParams::READONLY_DEPTH)
             && !pipeline.rasterState.depthWrite)
            || !(out.params.readOnlyDepthStencil & RenderPassParams::READONLY_DEPTH));

    driver.beginRenderPass(out.target, out.params);
    driver.draw(pipeline, mFullScreenQuadRph, 0, 3, 1);
    driver.endRenderPass();
    DescriptorSet::unbind(driver, DescriptorSetBindingPoints::PER_MATERIAL);
}

// ------------------------------------------------------------------------------------------------

PostProcessManager::StructurePassOutput PostProcessManager::structure(FrameGraph& fg,
        RenderPassBuilder const& passBuilder, uint8_t const structureRenderFlags,
        uint32_t width, uint32_t height,
        StructurePassConfig const& config) noexcept {

    const float scale = config.scale;

    // structure pass -- automatically culled if not used, currently used by:
    //    - ssao
    //    - contact shadows
    // It consists of a mipmapped depth pass, tuned for SSAO
    struct StructurePassData {
        FrameGraphId<FrameGraphTexture> depth;
        FrameGraphId<FrameGraphTexture> picking;
    };

    // sanitize a bit the user provided scaling factor
    width  = std::max(32u, uint32_t(std::ceil(float(width) * scale)));
    height = std::max(32u, uint32_t(std::ceil(float(height) * scale)));

    // We limit the lowest lod size to 32 pixels (which is where the -5 comes from)
    const size_t levelCount = std::min(8, FTexture::maxLevelCount(width, height) - 5);
    assert_invariant(levelCount >= 1);

    // generate depth pass at the requested resolution
    auto const& structurePass = fg.addPass<StructurePassData>("Structure Pass",
            [&](FrameGraph::Builder& builder, auto& data) {