Blender V5.0
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. */
40 Texture radiance_history_tx = {"radiance_tx"};
41 Texture variance_history_tx = {"variance_tx"};
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 {
75 if (radiance_feedback_tx.ensure_2d(
76 gpu::TextureFormat::SFLOAT_16_16_16_16, is_dummy ? int2(1) : extent, usage_rw))
77 {
78 radiance_feedback_tx.clear(float4(0.0f));
79 }
81 }
82};
83
90 private:
92 TextureFromPool *result_ = nullptr;
94 gpu::Texture *tx_ = nullptr;
96 Texture *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. */
119 TextureFromPool::swap(*result_, *history_);
120 }
121 /* NOTE: This releases the previous history. */
122 result_->release();
123 }
124};
125
128
129 void release()
130 {
131 for (int i = 0; i < 3; i++) {
132 closures[i].release();
133 }
134 }
135};
136
138
139/* -------------------------------------------------------------------- */
142
144 private:
145 Instance &inst_;
146
147 draw::PassSimple tile_classify_ps_ = {"TileClassify"};
148 draw::PassSimple tile_compact_ps_ = {"TileCompact"};
149 draw::PassSimple generate_ps_ = {"RayGenerate"};
150 draw::PassSimple trace_planar_ps_ = {"Trace.Planar"};
151 draw::PassSimple trace_screen_ps_ = {"Trace.Screen"};
152 draw::PassSimple trace_fallback_ps_ = {"Trace.Fallback"};
153 draw::PassSimple denoise_spatial_ps_ = {"DenoiseSpatial"};
154 draw::PassSimple denoise_temporal_ps_ = {"DenoiseTemporal"};
155 draw::PassSimple denoise_bilateral_ps_ = {"DenoiseBilateral"};
156 draw::PassSimple horizon_schedule_ps_ = {"HorizonScan.Schedule"};
157 draw::PassSimple horizon_setup_ps_ = {"HorizonScan.Setup"};
158 draw::PassSimple horizon_scan_ps_ = {"HorizonScan.Trace"};
159 draw::PassSimple horizon_denoise_ps_ = {"HorizonScan.Denoise"};
160 draw::PassSimple horizon_resolve_ps_ = {"HorizonScan.Resolve"};
161
163 int3 tile_classify_dispatch_size_ = int3(1);
165 int3 tile_compact_dispatch_size_ = int3(1);
166 int3 horizon_schedule_dispatch_size_ = int3(1);
168 int3 tracing_dispatch_size_ = int3(1);
169 int3 horizon_tracing_dispatch_size_ = int3(1);
172 Texture tile_raytrace_denoise_tx_ = {"tile_raytrace_denoise_tx_"};
173 Texture tile_raytrace_tracing_tx_ = {"tile_raytrace_tracing_tx_"};
174 Texture tile_horizon_denoise_tx_ = {"tile_horizon_denoise_tx_"};
175 Texture tile_horizon_tracing_tx_ = {"tile_horizon_tracing_tx_"};
177 DispatchIndirectBuf raytrace_tracing_dispatch_buf_ = {"raytrace_tracing_dispatch_buf_"};
179 DispatchIndirectBuf raytrace_denoise_dispatch_buf_ = {"raytrace_denoise_dispatch_buf_"};
181 DispatchIndirectBuf horizon_tracing_dispatch_buf_ = {"horizon_tracing_dispatch_buf_"};
183 DispatchIndirectBuf horizon_denoise_dispatch_buf_ = {"horizon_denoise_dispatch_buf_"};
185 gpu::Texture *horizon_scan_output_tx_[3] = {nullptr};
187 RayTraceTileBuf raytrace_tracing_tiles_buf_ = {"raytrace_tracing_tiles_buf_"};
188 RayTraceTileBuf raytrace_denoise_tiles_buf_ = {"raytrace_denoise_tiles_buf_"};
189 RayTraceTileBuf horizon_tracing_tiles_buf_ = {"horizon_tracing_tiles_buf_"};
190 RayTraceTileBuf horizon_denoise_tiles_buf_ = {"horizon_denoise_tiles_buf_"};
192 TextureFromPool ray_data_tx_ = {"ray_data_tx"};
194 TextureFromPool ray_time_tx_ = {"ray_data_tx"};
196 TextureFromPool ray_radiance_tx_ = {"ray_radiance_tx"};
198 TextureFromPool horizon_radiance_tx_[4] = {{"horizon_radiance_tx_"}};
199 TextureFromPool horizon_radiance_denoised_tx_[4] = {{"horizon_radiance_denoised_tx_"}};
201 TextureFromPool downsampled_in_radiance_tx_ = {"downsampled_in_radiance_tx_"};
203 TextureFromPool downsampled_in_normal_tx_ = {"downsampled_in_normal_tx_"};
205 gpu::Texture *denoised_spatial_tx_ = nullptr;
206 gpu::Texture *denoised_temporal_tx_ = nullptr;
207 gpu::Texture *denoised_bilateral_tx_ = nullptr;
209 TextureFromPool hit_depth_tx_ = {"hit_depth_tx_"};
211 TextureFromPool hit_variance_tx_ = {"hit_variance_tx_"};
213 TextureFromPool denoise_variance_tx_ = {"denoise_variance_tx_"};
215 gpu::Texture *radiance_history_tx_ = nullptr;
216 gpu::Texture *variance_history_tx_ = nullptr;
217 gpu::Texture *tilemask_history_tx_ = nullptr;
219 gpu::Texture *screen_radiance_front_tx_ = nullptr;
220 gpu::Texture *screen_radiance_back_tx_ = nullptr;
221
222 Texture radiance_dummy_black_tx_ = {"radiance_dummy_black_tx"};
224 TextureFromPool dummy_result_tx_ = {"dummy_result_tx"};
226 gpu::Texture *renderbuf_depth_view_ = nullptr;
227
229 RaytraceEEVEE ray_tracing_options_;
230 int fast_gi_ray_count_ = 0;
231 int fast_gi_step_count_ = 0;
232 bool fast_gi_ao_only_ = false;
233
234 bool use_raytracing_ = false;
235
237
238 RayTraceData &data_;
239
240 public:
241 RayTraceModule(Instance &inst, RayTraceData &data) : inst_(inst), data_(data) {};
242
243 void init();
244
245 void sync();
246
264 gpu::Texture *screen_radiance_back_tx,
265 eClosureBits active_closures,
266 /* TODO(fclem): Maybe wrap these two in some other class. */
267 View &main_view,
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
293 private:
294 RayTraceResultTexture trace(int closure_index,
295 bool active_layer,
297 RayTraceBuffer &rt_buffer,
298 /* TODO(fclem): Maybe wrap these two in some other class. */
299 View &main_view,
300 View &render_view);
301};
302
304
305} // namespace blender::eevee
#define BLI_assert(a)
Definition BLI_assert.h:46
RaytraceEEVEE_Method
@ RAYTRACE_EEVEE_METHOD_PROBE
static AppView * view
eGPUTextureUsage
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_SHADER_WRITE
BMesh const char void * data
static void swap(TextureFromPool &a, Texture &b)
A running instance of the engine.
RayTraceResult alloc_only(RayTraceBuffer &rt_buffer)
void debug_draw(View &view, gpu::FrameBuffer *view_fb)
RayTraceModule(Instance &inst, RayTraceData &data)
RayTraceResult alloc_dummy(RayTraceBuffer &rt_buffer)
RayTraceResultTexture(TextureFromPool &result)
RayTraceResultTexture(TextureFromPool &result, Texture &history)
CCL_NAMESPACE_BEGIN struct Options options
detail::Pass< command::DrawCommandBuf > PassSimple
draw::StorageBuffer< DispatchCommand > DispatchIndirectBuf
Definition draw_pass.hh:70
draw::StorageArrayBuffer< uint, 1024, true > RayTraceTileBuf
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3
gpu::Texture * feedback_ensure(bool is_dummy, int2 extent)
RayTraceResultTexture closures[3]
i
Definition text_draw.cc:230
PointerRNA * ptr
Definition wm_files.cc:4238