This new implementation does all downsampling in a single compute shader dispatch, removing a lot of complexity from the previous recursive downsampling. This is heavilly inspired by the Single-Pass-Downsampler from GPUOpen: https://github.com/GPUOpen-Effects/FidelityFX-SPD However I do not implement all the optimization bits as they require vulkan (GL_KHR_shader_subgroup) and is not as versatile (it is only for HiZ). Timers inside renderdoc report ~0.4ms of saving on a 2048*1024 render for the whole downsampling. Note that the previous implementation only processed 6 mips where the new one processes 8 mips. ``` EEVEE ~1.0ms EEVEE-Next ~0.6ms ``` Padding has been bumped to be of 128px for processing 8 mips. A new debug option has been added (debug value 2) to validate the HiZ.
82 lines
1.9 KiB
C++
82 lines
1.9 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
* Copyright 2021 Blender Foundation.
|
|
*/
|
|
|
|
/** \file
|
|
* \ingroup eevee
|
|
*
|
|
* The Hierarchical-Z buffer is texture containing a copy of the depth buffer with mipmaps.
|
|
* Each mip contains the maximum depth of each 4 pixels on the upper level.
|
|
* The size of the texture is padded to avoid messing with the mipmap pixels alignments.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "DRW_render.h"
|
|
|
|
#include "eevee_shader_shared.hh"
|
|
|
|
namespace blender::eevee {
|
|
|
|
class Instance;
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
/** \name Hierarchical-Z buffer
|
|
* \{ */
|
|
|
|
class HiZBuffer {
|
|
private:
|
|
Instance &inst_;
|
|
|
|
/** The texture containing the hiz mip chain. */
|
|
Texture hiz_tx_ = {"hiz_tx_"};
|
|
/**
|
|
* Atomic counter counting the number of tile that have finished down-sampling.
|
|
* The last one will process the last few mip level.
|
|
*/
|
|
draw::StorageBuffer<uint4, true> atomic_tile_counter_ = {"atomic_tile_counter"};
|
|
/** Single pass recursive downsample. */
|
|
DRWPass *hiz_update_ps_ = nullptr;
|
|
/** Debug pass. */
|
|
DRWPass *debug_draw_ps_ = nullptr;
|
|
/** Dirty flag to check if the update is necessary. */
|
|
bool is_dirty_ = true;
|
|
|
|
HiZDataBuf data_;
|
|
|
|
public:
|
|
HiZBuffer(Instance &inst) : inst_(inst)
|
|
{
|
|
atomic_tile_counter_.clear_to_zero();
|
|
};
|
|
|
|
void sync();
|
|
|
|
/**
|
|
* Tag the buffer for update if needed.
|
|
*/
|
|
void set_dirty()
|
|
{
|
|
is_dirty_ = true;
|
|
}
|
|
|
|
/**
|
|
* Update the content of the HiZ buffer with the depth render target.
|
|
* Noop if the buffer has not been tagged as dirty.
|
|
* Should be called before each passes that needs to read the hiz buffer.
|
|
*/
|
|
void update();
|
|
|
|
void debug_draw(GPUFrameBuffer *view_fb);
|
|
|
|
void bind_resources(DRWShadingGroup *grp)
|
|
{
|
|
DRW_shgroup_uniform_texture_ref(grp, "hiz_tx", &hiz_tx_);
|
|
DRW_shgroup_uniform_block_ref(grp, "hiz_buf", &data_);
|
|
}
|
|
};
|
|
|
|
/** \} */
|
|
|
|
} // namespace blender::eevee
|