Blender V5.0
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++ :
34 data.value_len++;
35 }
36 return -1;
37 };
38
39 data.normal_id = pass_index_get(EEVEE_RENDER_PASS_NORMAL, EEVEE_RENDER_PASS_AO);
40 data.position_id = pass_index_get(EEVEE_RENDER_PASS_POSITION);
41 data.diffuse_light_id = pass_index_get(EEVEE_RENDER_PASS_DIFFUSE_LIGHT);
42 data.diffuse_color_id = pass_index_get(EEVEE_RENDER_PASS_DIFFUSE_COLOR);
43 data.specular_light_id = pass_index_get(EEVEE_RENDER_PASS_SPECULAR_LIGHT);
44 data.specular_color_id = pass_index_get(EEVEE_RENDER_PASS_SPECULAR_COLOR);
45 data.volume_light_id = pass_index_get(EEVEE_RENDER_PASS_VOLUME_LIGHT);
46 data.emission_id = pass_index_get(EEVEE_RENDER_PASS_EMIT);
47 data.environment_id = pass_index_get(EEVEE_RENDER_PASS_ENVIRONMENT);
48 data.shadow_id = pass_index_get(EEVEE_RENDER_PASS_SHADOW);
49 data.ambient_occlusion_id = pass_index_get(EEVEE_RENDER_PASS_AO);
50 data.transparent_id = pass_index_get(EEVEE_RENDER_PASS_TRANSPARENT);
51
52 data.aovs = inst_.film.aovs_info;
53}
54
56{
57 const eViewLayerEEVEEPassType enabled_passes = inst_.film.enabled_passes_get();
58
59 extent_ = extent;
60
61 auto pass_extent = [&](eViewLayerEEVEEPassType pass_bit) -> int2 {
62 /* Use dummy texture for disabled passes. Allows correct bindings. */
63 return (enabled_passes & pass_bit) ? extent : int2(1);
64 };
65
67
68 /* Depth and combined are always needed. */
69 depth_tx.ensure_2d(gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8, extent, usage);
70 /* TODO(fclem): depth_tx should ideally be a texture from pool but we need stencil_view
71 * which is currently unsupported by pool textures. */
72 // depth_tx.acquire(extent, gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8);
73 combined_tx.acquire(extent, color_format);
74
75 eGPUTextureUsage usage_attachment_read_write = GPU_TEXTURE_USAGE_ATTACHMENT |
78
79 /* TODO(fclem): Make vector pass allocation optional if no TAA or motion blur is needed. */
80 vector_tx.acquire(extent, vector_tx_format(), usage_attachment_read_write);
81
82 const bool do_motion_vectors_swizzle = vector_tx_format() == gpu::TextureFormat::SFLOAT_16_16;
83 if (do_motion_vectors_swizzle) {
84 /* Change texture swizzling to avoid complexity in shaders. */
86 }
87
88 int color_len = data.color_len + data.aovs.color_len;
89 int value_len = data.value_len + data.aovs.value_len;
90
91 rp_color_tx.ensure_2d_array(color_format,
92 (color_len > 0) ? extent : int2(1),
93 math::max(1, color_len),
94 usage_attachment_read_write);
95 rp_value_tx.ensure_2d_array(float_format,
96 (value_len > 0) ? extent : int2(1),
97 math::max(1, value_len),
98 usage_attachment_read_write);
99
100 const gpu::TextureFormat cryptomatte_format = gpu::TextureFormat::SFLOAT_32_32_32_32;
104 cryptomatte_format,
106}
107
109{
110 /* TODO(fclem): depth_tx should ideally be a texture from pool but we need stencil_view
111 * which is currently unsupported by pool textures. */
112 // depth_tx.release();
113 combined_tx.release();
114
115 const bool do_motion_vectors_swizzle = vector_tx_format() == gpu::TextureFormat::SFLOAT_16_16;
116 if (do_motion_vectors_swizzle) {
117 /* Reset swizzle since this texture might be reused in other places. */
119 }
120 vector_tx.release();
121
122 cryptomatte_tx.release();
123}
124
126{
127 const eViewLayerEEVEEPassType enabled_passes = inst_.film.enabled_passes_get();
128 bool do_full_vector_render_pass = ((enabled_passes & EEVEE_RENDER_PASS_VECTOR) ||
129 inst_.motion_blur.postfx_enabled()) &&
130 !inst_.is_viewport();
131
132 /* Only RG16F (`motion.prev`) for the viewport. */
133 return do_full_vector_render_pass ? gpu::TextureFormat::SFLOAT_16_16_16_16 :
134 gpu::TextureFormat::SFLOAT_16_16;
135}
136
137} // namespace blender::eevee
eViewLayerEEVEEPassType
@ EEVEE_RENDER_PASS_CRYPTOMATTE_MATERIAL
@ EEVEE_RENDER_PASS_AO
@ EEVEE_RENDER_PASS_NORMAL
@ EEVEE_RENDER_PASS_CRYPTOMATTE_OBJECT
@ EEVEE_RENDER_PASS_DIFFUSE_LIGHT
@ EEVEE_RENDER_PASS_VOLUME_LIGHT
@ EEVEE_RENDER_PASS_DIFFUSE_COLOR
@ EEVEE_RENDER_PASS_CRYPTOMATTE_ASSET
@ EEVEE_RENDER_PASS_ENVIRONMENT
@ EEVEE_RENDER_PASS_SPECULAR_LIGHT
@ EEVEE_RENDER_PASS_VECTOR
@ EEVEE_RENDER_PASS_SPECULAR_COLOR
@ EEVEE_RENDER_PASS_EMIT
@ EEVEE_RENDER_PASS_TRANSPARENT
@ EEVEE_RENDER_PASS_SHADOW
@ EEVEE_RENDER_PASS_POSITION
void GPU_texture_swizzle_set(blender::gpu::Texture *texture, const char swizzle[4])
eGPUTextureUsage
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_SHADER_WRITE
@ GPU_TEXTURE_USAGE_ATTACHMENT
static ePassStorageType pass_storage_type(eViewLayerEEVEEPassType pass_type)
static constexpr gpu::TextureFormat float_format
static constexpr gpu::TextureFormat color_format
static eViewLayerEEVEEPassType enabled_passes(const ViewLayer *view_layer)
T max(const T &a, const T &b)
VecBase< int32_t, 2 > int2