Blender V5.3
eevee_hizbuffer.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12
13#pragma once
14
15#include "DRW_render.hh"
16
17#include "DRW_gpu_wrapper.hh"
18
19#include "draw_pass.hh"
20#include "eevee_defines.hh"
22
23namespace blender::eevee {
24
25using namespace draw;
26
27class Instance;
28
29/* -------------------------------------------------------------------- */
32
33class HiZBuffer {
34 private:
35 Instance &inst_;
36
40 std::array<gpu::Texture *, HIZ_MIP_COUNT> hiz_mip_ref_;
41
43 draw::Texture dummy_empty_hiz_tx_ = {"dummy_empty_hiz_tx_"};
44
49 draw::StorageBuffer<uint4, true> atomic_tile_counter_ = {"atomic_tile_counter"};
51 PassSimple hiz_update_ps_ = {"HizUpdate"};
53 PassSimple hiz_update_layer_ps_ = {"HizUpdate.Layer"};
54 int layer_id_ = -1;
56 PassSimple debug_draw_ps_ = {"HizUpdate.Debug"};
58 bool is_dirty_ = true;
60 gpu::Texture *src_tx_ = nullptr;
61 gpu::Texture **src_tx_ptr_ = nullptr;
62
63 HiZData &data_;
64
65 public:
66 HiZBuffer(Instance &inst, HiZData &data) : inst_(inst), data_(data)
67 {
68 atomic_tile_counter_.clear_to_zero();
69 float value = 1.0f;
70 dummy_empty_hiz_tx_.ensure_2d(
71 gpu::TextureFormat::SFLOAT_32, int2(1), GPU_TEXTURE_USAGE_SHADER_READ, &value);
72 };
73
74 void sync();
75
82 {
83 src_tx_ptr_ = texture;
84 layer_id_ = layer;
85 swap_layer();
86 /* Both layer becomes undefined. Replace by dummy texture. */
87 back.ref_tx_ = dummy_empty_hiz_tx_;
88 front.ref_tx_ = dummy_empty_hiz_tx_;
89 }
90
98 {
99 hiz_tx_.swap();
100 back.ref_tx_ = front.ref_tx_;
101 front.ref_tx_ = hiz_tx_.current();
102 set_dirty();
103 }
104
109 {
110 is_dirty_ = true;
111 }
112
118 void update();
119
120 void debug_draw(View &view, gpu::FrameBuffer *view_fb);
121
122 /* Back is Previous layer depth (ex: For refraction). Front for current layer depth. */
123 struct {
125 gpu::Texture *ref_tx_ = nullptr;
126
127 template<typename PassType> void bind_resources(PassType &pass)
128 {
129 pass.bind_texture(HIZ_TEX_SLOT, &ref_tx_);
130 }
132};
133
135
136} // namespace blender::eevee
void debug_draw(View &view, gpu::FrameBuffer *view_fb)
HiZBuffer(Instance &inst, HiZData &data)
struct blender::eevee::HiZBuffer::@342214352322061324133130050175232001060230260232 back
void set_source(gpu::Texture **texture, int layer=-1)
struct blender::eevee::HiZBuffer::@342214352322061324133130050175232001060230260232 front
A running instance of the engine.
#define HIZ_TEX_SLOT
#define layer
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
PassType
detail::Pass< command::DrawCommandBuf > PassSimple
VecBase< int32_t, 2 > int2
@ GPU_TEXTURE_USAGE_SHADER_READ
BMesh const char void * data