Blender V4.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
11#pragma once
12
13#include "DNA_scene_types.h"
14
15#include "DRW_render.hh"
16
18
19namespace blender::eevee {
20
21class Instance;
22
23/* -------------------------------------------------------------------- */
36 /* Persistent history buffers. */
37 Texture radiance_history_tx = {"radiance_tx"};
38 Texture variance_history_tx = {"variance_tx"};
39 /* Map of tiles that were processed inside the history buffer. */
40 Texture tilemask_history_tx = {"tilemask_tx"};
44 bool valid_history = false;
49 TextureFromPool denoised_spatial_tx = {"denoised_spatial_tx"};
50 TextureFromPool denoised_temporal_tx = {"denoised_temporal_tx"};
51 TextureFromPool denoised_bilateral_tx = {"denoised_bilateral_tx"};
52 };
57
62 Texture radiance_feedback_tx = {"radiance_feedback_tx"};
68
69 GPUTexture *feedback_ensure(bool is_dummy, int2 extent)
70 {
72 if (radiance_feedback_tx.ensure_2d(GPU_RGBA16F, is_dummy ? int2(1) : extent, usage_rw)) {
74 }
76 }
77};
78
85 private:
87 TextureFromPool *result_ = nullptr;
89 GPUTexture *tx_ = nullptr;
91 Texture *history_ = nullptr;
92
93 public:
95 RayTraceResultTexture(TextureFromPool &result) : result_(result.ptr()), tx_(result){};
97 : result_(result.ptr()), tx_(result), history_(history.ptr()){};
98
99 operator GPUTexture *() const
100 {
101 BLI_assert(tx_ != nullptr);
102 return tx_;
103 }
104
105 GPUTexture **operator&()
106 {
107 return &tx_;
108 }
109
110 void release()
111 {
112 if (history_) {
113 /* Swap after last use. */
114 TextureFromPool::swap(*result_, *history_);
115 }
116 /* NOTE: This releases the previous history. */
117 result_->release();
118 }
119};
120
123
124 void release()
125 {
126 for (int i = 0; i < 3; i++) {
127 closures[i].release();
128 }
129 }
130};
131
134/* -------------------------------------------------------------------- */
139 private:
140 Instance &inst_;
141
142 draw::PassSimple tile_classify_ps_ = {"TileClassify"};
143 draw::PassSimple tile_compact_ps_ = {"TileCompact"};
144 draw::PassSimple generate_ps_ = {"RayGenerate"};
145 draw::PassSimple trace_planar_ps_ = {"Trace.Planar"};
146 draw::PassSimple trace_screen_ps_ = {"Trace.Screen"};
147 draw::PassSimple trace_fallback_ps_ = {"Trace.Fallback"};
148 draw::PassSimple denoise_spatial_ps_ = {"DenoiseSpatial"};
149 draw::PassSimple denoise_temporal_ps_ = {"DenoiseTemporal"};
150 draw::PassSimple denoise_bilateral_ps_ = {"DenoiseBilateral"};
151 draw::PassSimple horizon_schedule_ps_ = {"HorizonScan.Schedule"};
152 draw::PassSimple horizon_setup_ps_ = {"HorizonScan.Setup"};
153 draw::PassSimple horizon_scan_ps_ = {"HorizonScan.Trace"};
154 draw::PassSimple horizon_denoise_ps_ = {"HorizonScan.Denoise"};
155 draw::PassSimple horizon_resolve_ps_ = {"HorizonScan.Resolve"};
156
158 int3 tile_classify_dispatch_size_ = int3(1);
160 int3 tile_compact_dispatch_size_ = int3(1);
161 int3 horizon_schedule_dispatch_size_ = int3(1);
163 int3 tracing_dispatch_size_ = int3(1);
164 int3 horizon_tracing_dispatch_size_ = int3(1);
167 Texture tile_raytrace_denoise_tx_ = {"tile_raytrace_denoise_tx_"};
168 Texture tile_raytrace_tracing_tx_ = {"tile_raytrace_tracing_tx_"};
169 Texture tile_horizon_denoise_tx_ = {"tile_horizon_denoise_tx_"};
170 Texture tile_horizon_tracing_tx_ = {"tile_horizon_tracing_tx_"};
172 DispatchIndirectBuf raytrace_tracing_dispatch_buf_ = {"raytrace_tracing_dispatch_buf_"};
174 DispatchIndirectBuf raytrace_denoise_dispatch_buf_ = {"raytrace_denoise_dispatch_buf_"};
176 DispatchIndirectBuf horizon_tracing_dispatch_buf_ = {"horizon_tracing_dispatch_buf_"};
178 DispatchIndirectBuf horizon_denoise_dispatch_buf_ = {"horizon_denoise_dispatch_buf_"};
180 GPUTexture *horizon_scan_output_tx_[3] = {nullptr};
182 RayTraceTileBuf raytrace_tracing_tiles_buf_ = {"raytrace_tracing_tiles_buf_"};
183 RayTraceTileBuf raytrace_denoise_tiles_buf_ = {"raytrace_denoise_tiles_buf_"};
184 RayTraceTileBuf horizon_tracing_tiles_buf_ = {"horizon_tracing_tiles_buf_"};
185 RayTraceTileBuf horizon_denoise_tiles_buf_ = {"horizon_denoise_tiles_buf_"};
187 TextureFromPool ray_data_tx_ = {"ray_data_tx"};
189 TextureFromPool ray_time_tx_ = {"ray_data_tx"};
191 TextureFromPool ray_radiance_tx_ = {"ray_radiance_tx"};
193 TextureFromPool horizon_radiance_tx_[4] = {{"horizon_radiance_tx_"}};
194 TextureFromPool horizon_radiance_denoised_tx_[4] = {{"horizon_radiance_denoised_tx_"}};
196 TextureFromPool downsampled_in_radiance_tx_ = {"downsampled_in_radiance_tx_"};
198 TextureFromPool downsampled_in_normal_tx_ = {"downsampled_in_normal_tx_"};
200 GPUTexture *denoised_spatial_tx_ = nullptr;
201 GPUTexture *denoised_temporal_tx_ = nullptr;
202 GPUTexture *denoised_bilateral_tx_ = nullptr;
204 TextureFromPool hit_depth_tx_ = {"hit_depth_tx_"};
206 TextureFromPool hit_variance_tx_ = {"hit_variance_tx_"};
208 TextureFromPool denoise_variance_tx_ = {"denoise_variance_tx_"};
210 GPUTexture *radiance_history_tx_ = nullptr;
211 GPUTexture *variance_history_tx_ = nullptr;
212 GPUTexture *tilemask_history_tx_ = nullptr;
214 GPUTexture *screen_radiance_front_tx_ = nullptr;
215 GPUTexture *screen_radiance_back_tx_ = nullptr;
216
217 Texture radiance_dummy_black_tx_ = {"radiance_dummy_black_tx"};
219 TextureFromPool dummy_result_tx_ = {"dummy_result_tx"};
221 GPUTexture *renderbuf_depth_view_ = nullptr;
222
224 RaytraceEEVEE ray_tracing_options_;
225 int fast_gi_ray_count_ = 0;
226 int fast_gi_step_count_ = 0;
227 bool fast_gi_ao_only_ = 0;
228
230
231 RayTraceData &data_;
232
233 public:
234 RayTraceModule(Instance &inst, RayTraceData &data) : inst_(inst), data_(data){};
235
236 void init();
237
238 void sync();
239
256 RayTraceResult render(RayTraceBuffer &rt_buffer,
257 GPUTexture *screen_radiance_back_tx,
258 eClosureBits active_closures,
259 /* TODO(fclem): Maybe wrap these two in some other class. */
260 View &main_view,
261 View &render_view);
262
267
272
273 void debug_pass_sync();
274 void debug_draw(View &view, GPUFrameBuffer *view_fb);
275
276 private:
277 RayTraceResultTexture trace(int closure_index,
278 bool active_layer,
280 RayTraceBuffer &rt_buffer,
281 /* TODO(fclem): Maybe wrap these two in some other class. */
282 View &main_view,
283 View &render_view);
284};
285
288} // namespace blender::eevee
#define BLI_assert(a)
Definition BLI_assert.h:50
RaytraceEEVEE_Method
@ RAYTRACE_EEVEE_METHOD_PROBE
eGPUTextureUsage
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_SHADER_WRITE
static void swap(TextureFromPool &a, Texture &b)
void clear(float4 values)
bool ensure_2d(eGPUTextureFormat format, int2 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
A running instance of the engine.
RayTraceResult alloc_only(RayTraceBuffer &rt_buffer)
void debug_draw(View &view, GPUFrameBuffer *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
VecBase< float, 4 > float4
VecBase< int32_t, 3 > int3
GPUTexture * feedback_ensure(bool is_dummy, int2 extent)
RayTraceResultTexture closures[3]
PointerRNA * ptr
Definition wm_files.cc:4126