blob: 1d84349ba431a0fa041467dce071575b926fa197 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/* 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_;
/** Max mip to downsample to. We ensure the hiz has enough padding to never
* have to compensate the mipmap alignments. */
constexpr static int mip_count_ = HIZ_MIP_COUNT;
/* Kernel size is bigger than the local group size because we simply copy the level 0. */
constexpr static int kernel_size_ = HIZ_GROUP_SIZE << 1;
/** Aggregate of all views extent. The hiz is large enough to fit any view and is shared. */
int2 extent_;
/** The texture containing the hiz mip chain. */
Texture hiz_tx_ = {"hiz_tx_"};
/** Update dispatch size from the given depth buffer size. */
int3 dispatch_size_;
/** Single pass recursive downsample. */
DRWPass *hiz_update_ps_;
/** References only. */
GPUTexture *input_depth_tx_ = nullptr;
/** Dirty flag to check if the update is necessary. */
bool is_dirty_ = true;
public:
HiZBuffer(Instance &inst) : inst_(inst){};
void begin_sync();
void view_sync(int2 extent);
void end_sync();
void update(GPUTexture *depth_src);
GPUTexture **texture_ref_get(void)
{
return &hiz_tx_;
}
void set_dirty()
{
is_dirty_ = true;
}
private:
static void recursive_downsample(void *thunk, int lvl);
};
/** \} */
/* -------------------------------------------------------------------- */
/** \name Hierarchical-Z buffer Module
* \{ */
class HiZBufferModule {
friend HiZBuffer;
private:
Instance &inst_;
HiZDataBuf data_;
public:
HiZBufferModule(Instance &inst) : inst_(inst){};
const GPUUniformBuf *ubo_get(void) const
{
return data_;
}
};
/** \} */
} // namespace blender::eevee
|