Blender V5.3
eevee_renderbuffers.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
14
15#include "GPU_texture.hh"
16
17#include "DRW_render.hh"
18
19#include "eevee_film.hh"
20#include "eevee_instance.hh"
21
22namespace blender::eevee {
23
25{
26 const eViewLayerEEVEEPassType enabled_passes = inst_.film.enabled_passes_get();
27
28 data.color_len = 0;
29 data.value_len = 0;
30
31 auto pass_index_get = [&](eViewLayerEEVEEPassType pass_type, int dependent_passes = 0) {
32 if (enabled_passes & (pass_type | dependent_passes)) {
33 return pass_storage_type(pass_type) == PASS_STORAGE_COLOR ? data.color_len++ :
35 }
36 return -1;
37 };
38
41 /* Custom lighting in the hybrid pipeline requires both passes, so the combine pass can
42 * reconstruct the radiance. */
52 data.emission_id = pass_index_get(EEVEE_RENDER_PASS_EMIT);
54 data.shadow_id = pass_index_get(EEVEE_RENDER_PASS_SHADOW);
57 data.denoising_depth_id = (enabled_passes & EEVEE_RENDER_PASS_DENOISING_DEPTH) ? 0 : -1;
62
63 data.aovs = inst_.film.aovs_info;
64}
65
66void RenderBuffers::acquire(int2 extent, gpu::TextureFormat raycast_depth_format)
67{
68 const eViewLayerEEVEEPassType enabled_passes = inst_.film.enabled_passes_get();
69
70 extent_ = extent;
71
72 auto pass_extent = [&](eViewLayerEEVEEPassType pass_bit) -> int2 {
73 /* Use dummy texture for disabled passes. Allows correct bindings. */
74 return (enabled_passes & pass_bit) ? extent : int2(1);
75 };
76
77 eGPUTextureUsage usage_attachment_read = GPU_TEXTURE_USAGE_SHADER_READ |
79
80 /* Depth and combined are always needed. */
81 depth_tx.acquire_2d(extent, depth_format, usage_attachment_read);
83
84 eGPUTextureUsage usage_attachment_read_write = GPU_TEXTURE_USAGE_ATTACHMENT |
87
88 /* TODO(fclem): Make vector pass allocation optional if no TAA or motion blur is needed. */
89 vector_tx.acquire_2d(extent, vector_tx_format(), usage_attachment_read_write);
90 if (inst_.pipelines.has_raycast) {
91 raycast_depth_tx.acquire_2d(extent, raycast_depth_format, GPU_TEXTURE_USAGE_SHADER_READ);
92 object_id_tx.acquire_2d(extent, object_id_format, usage_attachment_read);
93 prepass_normal_tx.acquire_2d(extent, prepass_normal_format, usage_attachment_read);
94 }
95 else {
96 /* Still acquire them, since the passes can't conditionally bind textures. */
100 }
101
102 const bool do_motion_vectors_swizzle = vector_tx_format() == gpu::TextureFormat::SFLOAT_16_16;
103 if (do_motion_vectors_swizzle) {
104 /* Change texture swizzling to avoid complexity in shaders. */
106 }
107
108 int color_len = data.color_len + data.aovs.color_len;
109 int value_len = data.value_len + data.aovs.value_len;
110
111 rp_color_tx.acquire_2d_array((color_len > 0) ? extent : int2(1),
112 math::max(1, color_len),
114 usage_attachment_read_write);
115 rp_value_tx.acquire_2d_array((value_len > 0) ? extent : int2(1),
116 math::max(1, value_len),
118 usage_attachment_read_write);
119
120 const gpu::TextureFormat cryptomatte_format = gpu::TextureFormat::SFLOAT_32_32_32_32;
124 cryptomatte_format,
126}
127
129{
132
133 const bool do_motion_vectors_swizzle = vector_tx_format() == gpu::TextureFormat::SFLOAT_16_16;
134 if (do_motion_vectors_swizzle) {
135 /* Reset swizzle since this texture might be reused in other places. */
137 }
142
144
147}
148
150{
151 const eViewLayerEEVEEPassType enabled_passes = inst_.film.enabled_passes_get();
152 bool do_full_vector_render_pass = ((enabled_passes & EEVEE_RENDER_PASS_VECTOR) ||
153 inst_.motion_blur.postfx_enabled()) &&
154 !inst_.is_viewport();
155
156 /* Only RG16F (`motion.prev`) for the viewport. */
157 return do_full_vector_render_pass ? gpu::TextureFormat::SFLOAT_16_16_16_16 :
158 gpu::TextureFormat::SFLOAT_16_16;
159}
160
161} // namespace blender::eevee
bool acquire_2d(int2 extent, gpu::TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, int mip_len=1)
bool acquire_2d_array(int2 extent, int layers, gpu::TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, int mip_len=1)
static ePassStorageType pass_storage_type(eViewLayerEEVEEPassType pass_type)
static constexpr gpu::TextureFormat prepass_normal_format
static constexpr gpu::TextureFormat depth_format
static constexpr gpu::TextureFormat float_format
static constexpr gpu::TextureFormat color_format
void acquire(int2 extent, gpu::TextureFormat raycast_depth_format=depth_format)
static constexpr gpu::TextureFormat object_id_format
T max(const T &a, const T &b)
VecBase< int32_t, 2 > int2
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_SHADER_WRITE
@ GPU_TEXTURE_USAGE_ATTACHMENT
void GPU_texture_swizzle_set(gpu::Texture *texture, const char swizzle[4])
@ EEVEE_RENDER_PASS_CRYPTOMATTE_ASSET
@ EEVEE_RENDER_PASS_SPECULAR_LIGHT
@ EEVEE_RENDER_PASS_DIFFUSE_COLOR
@ EEVEE_RENDER_PASS_DENOISING_NORMAL
@ EEVEE_RENDER_PASS_CRYPTOMATTE_MATERIAL
@ EEVEE_RENDER_PASS_ENVIRONMENT
@ EEVEE_RENDER_PASS_VECTOR
@ EEVEE_RENDER_PASS_EMIT
@ EEVEE_RENDER_PASS_AO
@ EEVEE_RENDER_PASS_DENOISING_ROUGHNESS
@ EEVEE_RENDER_PASS_DENOISING_DIFFUSE_ALBEDO
@ EEVEE_RENDER_PASS_CRYPTOMATTE_OBJECT
@ EEVEE_RENDER_PASS_VOLUME_LIGHT
@ EEVEE_RENDER_PASS_DENOISING_SPECULAR_ALBEDO
@ EEVEE_RENDER_PASS_TRANSPARENT
@ EEVEE_RENDER_PASS_NORMAL
@ EEVEE_RENDER_PASS_POSITION
@ EEVEE_RENDER_PASS_DIFFUSE_LIGHT
@ EEVEE_RENDER_PASS_SPECULAR_COLOR
@ EEVEE_RENDER_PASS_SHADOW
@ EEVEE_RENDER_PASS_DENOISING_DEPTH