Blender V5.3
eevee_raytrace.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
13#include "DNA_scene_types.h"
14
15#include "DRW_gpu_wrapper.hh"
16#include "DRW_render.hh"
17
19
20namespace blender::eevee {
21
22class Instance;
23
25
26/* -------------------------------------------------------------------- */
32
39 /* Persistent history buffers. */
42 /* Map of tiles that were processed inside the history buffer. */
43 Texture tilemask_history_tx = {"tilemask_tx"};
47 bool valid_history = false;
52 TextureFromPool denoised_spatial_tx = {"denoised_spatial_tx"};
53 TextureFromPool denoised_temporal_tx = {"denoised_temporal_tx"};
54 TextureFromPool denoised_bilateral_tx = {"denoised_bilateral_tx"};
55 };
56
60
65 Texture radiance_feedback_tx = {"radiance_feedback_tx"};
71
72 gpu::Texture *feedback_ensure(bool is_dummy, int2 extent)
73 {
76 gpu::TextureFormat::SFLOAT_16_16_16_16, is_dummy ? int2(1) : extent, usage_rw))
77 {
79 }
81 }
82};
83
90 private:
92 TextureFromPool *result_ = nullptr;
94 gpu::Texture *tx_ = nullptr;
96 TextureFromPool *history_ = nullptr;
97
98 public:
102 : result_(result.ptr()), tx_(result), history_(history.ptr()) {};
103
104 operator gpu::Texture *() const
105 {
106 BLI_assert(tx_ != nullptr);
107 return tx_;
108 }
109
111 {
112 return &tx_;
113 }
114
115 void release()
116 {
117 if (history_) {
118 /* Swap after last use, retain history until next cycle. */
119 TextureFromPool::swap(*result_, *history_);
120 history_->retain();
121 }
122 /* Release previous history. */
123 result_->release();
124 }
125};
126
129
130 void release()
131 {
132 for (int i = 0; i < 3; i++) {
133 closures[i].release();
134 }
135 }
136};
137
139
140/* -------------------------------------------------------------------- */
143
145 private:
146 Instance &inst_;
147
148 draw::PassSimple tile_classify_ps_ = {"TileClassify"};
149 draw::PassSimple tile_compact_ps_ = {"TileCompact"};
150 draw::PassSimple generate_ps_ = {"RayGenerate"};
151 draw::PassSimple trace_planar_ps_ = {"Trace.Planar"};
152 draw::PassSimple trace_screen_ps_ = {"Trace.Screen"};
153 draw::PassSimple trace_fallback_ps_ = {"Trace.Fallback"};
154 draw::PassSimple denoise_spatial_ps_ = {"DenoiseSpatial"};
155 draw::PassSimple denoise_temporal_ps_ = {"DenoiseTemporal"};
156 draw::PassSimple denoise_bilateral_ps_ = {"DenoiseBilateral"};
157 draw::PassSimple fast_gi_schedule_ps_ = {"FastGI.Schedule"};
158 draw::PassSimple fast_gi_setup_ps_ = {"FastGI.Setup"};
159 draw::PassSimple fast_gi_scan_ps_ = {"FastGI.Trace"};
160 draw::PassSimple fast_gi_denoise_ps_ = {"FastGI.Denoise"};
161 draw::PassSimple fast_gi_resolve_ps_ = {"FastGI.Resolve"};
162
164 int3 tile_classify_dispatch_size_ = int3(1);
166 int3 tile_compact_dispatch_size_ = int3(1);
167 int3 fast_gi_schedule_dispatch_size_ = int3(1);
169 int3 tracing_dispatch_size_ = int3(1);
170 int3 fast_gi_tracing_dispatch_size_ = int3(1);
175 Texture tile_raytrace_denoise_tx_ = {"tile_raytrace_denoise_tx_"};
176 Texture tile_raytrace_tracing_tx_ = {"tile_raytrace_tracing_tx_"};
177 Texture tile_fast_gi_denoise_tx_ = {"tile_fast_gi_denoise_tx_"};
178 Texture tile_fast_gi_tracing_tx_ = {"tile_fast_gi_tracing_tx_"};
180 DispatchIndirectBuf raytrace_tracing_dispatch_buf_ = {"raytrace_tracing_dispatch_buf_"};
182 DispatchIndirectBuf raytrace_denoise_dispatch_buf_ = {"raytrace_denoise_dispatch_buf_"};
184 DispatchIndirectBuf fast_gi_tracing_dispatch_buf_ = {"fast_gi_tracing_dispatch_buf_"};
186 DispatchIndirectBuf fast_gi_denoise_dispatch_buf_ = {"fast_gi_denoise_dispatch_buf_"};
188 gpu::Texture *fast_gi_scan_output_tx_[3] = {nullptr};
190 RayTraceTileBuf raytrace_tracing_tiles_buf_ = {"raytrace_tracing_tiles_buf_"};
191 RayTraceTileBuf raytrace_denoise_tiles_buf_ = {"raytrace_denoise_tiles_buf_"};
192 RayTraceTileBuf fast_gi_tracing_tiles_buf_ = {"fast_gi_tracing_tiles_buf_"};
193 RayTraceTileBuf fast_gi_denoise_tiles_buf_ = {"fast_gi_denoise_tiles_buf_"};
195 TextureFromPool ray_data_tx_ = {"ray_data_tx"};
197 TextureFromPool ray_time_tx_ = {"ray_data_tx"};
199 TextureFromPool ray_radiance_tx_ = {"ray_radiance_tx"};
201 TextureFromPool fast_gi_radiance_tx_[4] = {{"fast_gi_radiance_tx_"}};
202 TextureFromPool fast_gi_radiance_denoised_tx_[4] = {{"fast_gi_radiance_denoised_tx_"}};
204 Texture downsampled_in_radiance_tx_ = {"downsampled_in_radiance_tx_"};
206 Texture downsampled_in_normal_tx_ = {"downsampled_in_normal_tx_"};
208 gpu::Texture *downsampled_in_radiance_tx_ptr_[4] = {nullptr};
209 gpu::Texture *downsampled_in_normal_tx_ptr_[4] = {nullptr};
211 gpu::Texture *denoised_spatial_tx_ = nullptr;
212 gpu::Texture *denoised_temporal_tx_ = nullptr;
213 gpu::Texture *denoised_bilateral_tx_ = nullptr;
215 TextureFromPool hit_depth_tx_ = {"hit_depth_tx_"};
217 TextureFromPool hit_variance_tx_ = {"hit_variance_tx_"};
219 TextureFromPool denoise_variance_tx_ = {"denoise_variance_tx_"};
221 gpu::Texture *radiance_history_tx_ = nullptr;
222 gpu::Texture *variance_history_tx_ = nullptr;
223 gpu::Texture *tilemask_history_tx_ = nullptr;
225 gpu::Texture *screen_radiance_front_tx_ = nullptr;
226 gpu::Texture *screen_radiance_back_tx_ = nullptr;
227
228 Texture radiance_dummy_black_tx_ = {"radiance_dummy_black_tx"};
230 TextureFromPool dummy_result_tx_ = {"dummy_result_tx"};
232 gpu::Texture *renderbuf_depth_view_ = nullptr;
233
235 RaytraceEEVEE ray_tracing_options_;
236 int fast_gi_ray_count_ = 0;
237 int fast_gi_step_count_ = 0;
238 bool fast_gi_ao_only_ = false;
239
240 bool use_raytracing_ = false;
241
243
244 RayTraceData &data_;
245
246 public:
247 RayTraceModule(Instance &inst, RayTraceData &data) : inst_(inst), data_(data) {};
248
249 void init();
250
251 void sync();
252
266 gpu::Texture *screen_radiance_back_tx,
267 eClosureBits active_closures,
268 View &render_view);
269
274
279
280 void debug_pass_sync();
281 void debug_draw(View &view, gpu::FrameBuffer *view_fb);
282
283 bool use_raytracing() const
284 {
285 return use_raytracing_;
286 }
287
288 bool use_fast_gi() const
289 {
290 return use_raytracing() && ray_tracing_options_.trace_max_roughness < 1.0f;
291 }
292
298 void thickness_parameters_setup(const float4x4 &winmat, const int2 extent);
299
300 private:
301 RayTraceResultTexture trace(int closure_index,
302 bool active_layer,
304 RayTraceBuffer &rt_buffer,
305 View &render_view);
306};
307
309
310} // namespace blender::eevee
static void swap(TextureFromPool &a, TextureFromPool &b)
bool ensure_2d(gpu::TextureFormat format, int2 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
void clear(float4 values)
A running instance of the engine.
RayTraceResult alloc_only(RayTraceBuffer &rt_buffer)
void thickness_parameters_setup(const float4x4 &winmat, const int2 extent)
void debug_draw(View &view, gpu::FrameBuffer *view_fb)
RayTraceModule(Instance &inst, RayTraceData &data)
RayTraceResult alloc_dummy(RayTraceBuffer &rt_buffer)
RayTraceResultTexture(TextureFromPool &result, TextureFromPool &history)
RayTraceResultTexture(TextureFromPool &result)
CCL_NAMESPACE_BEGIN struct Options options
detail::Pass< command::DrawCommandBuf > PassSimple
draw::StorageBuffer< DispatchCommand > DispatchIndirectBuf
Definition draw_pass.hh:72
draw::StorageArrayBuffer< uint, 1024, true > RayTraceTileBuf
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_SHADER_WRITE
BMesh const char void * data
@ RAYTRACE_EEVEE_METHOD_PROBE
gpu::Texture * feedback_ensure(bool is_dummy, int2 extent)
RayTraceResultTexture closures[3]