Blender V4.3
eevee_gbuffer.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 "DRW_render.hh"
14#include "GPU_capabilities.hh"
15
16#include "eevee_material.hh"
18
19namespace blender::eevee {
20
21class Instance;
22
127struct GBuffer {
128 /* TODO(fclem): Use texture from pool once they support texture array and layer views. */
129 Texture header_tx = {"GBufferHeader"};
130 Texture closure_tx = {"GBufferClosure"};
131 Texture normal_tx = {"GBufferNormal"};
132 /* References to the GBuffer layer range [1..max]. */
133 GPUTexture *closure_img_tx = nullptr;
134 GPUTexture *normal_img_tx = nullptr;
135
136 void acquire(int2 extent, int data_count, int normal_count)
137 {
138 /* Always allocating enough layers so that the image view is always valid. */
139 data_count = max_ii(3, data_count);
140 normal_count = max_ii(2, normal_count);
141
144 header_tx.ensure_2d(GPU_R32UI, extent, usage);
145 closure_tx.ensure_2d_array(GPU_RGB10_A2, extent, data_count, usage);
146 normal_tx.ensure_2d_array(GPU_RG16, extent, normal_count, usage);
147 /* Ensure layer view for frame-buffer attachment. */
150 /* Ensure layer view for image store. */
151 closure_img_tx = closure_tx.layer_range_view(2, data_count - 2);
152 normal_img_tx = normal_tx.layer_range_view(1, normal_count - 1);
153 }
154
155 /* Bind the GBuffer frame-buffer correctly using the correct workarounds. */
156 void bind(Framebuffer &gbuffer_fb)
157 {
158 /* Workaround a Metal bug that is only showing up on ATI/Intel GPUs. */
161 {
163 GPU_framebuffer_bind(gbuffer_fb);
164 return;
165 }
166
168 /* Clearing custom load-store frame-buffers is invalid,
169 * clear the stencil as a regular frame-buffer first. */
170 GPU_framebuffer_bind(gbuffer_fb);
171 GPU_framebuffer_clear_stencil(gbuffer_fb, 0x0u);
172 }
174 gbuffer_fb,
175 {
178 {GPU_LOADACTION_CLEAR, GPU_STOREACTION_STORE, {0}}, /* GBuf Header */
181 {GPU_LOADACTION_DONT_CARE, GPU_STOREACTION_STORE}, /* GBuf Closure 2*/
182 });
183 }
184
185 void release()
186 {
187 /* TODO(fclem): Use texture from pool once they support texture array. */
188 // header_tx.release();
189 // closure_tx.release();
190 // normal_tx.release();
191
192 closure_img_tx = nullptr;
193 normal_img_tx = nullptr;
194 }
195
196 template<typename PassType> void bind_resources(PassType &pass)
197 {
198 pass.bind_texture("gbuf_header_tx", &header_tx);
199 pass.bind_texture("gbuf_closure_tx", &closure_tx);
200 pass.bind_texture("gbuf_normal_tx", &normal_tx);
201 }
202};
203
204} // namespace blender::eevee
MINLINE int max_ii(int a, int b)
bool GPU_stencil_export_support()
@ GPU_LOADACTION_LOAD
@ GPU_LOADACTION_DONT_CARE
@ GPU_LOADACTION_CLEAR
@ GPU_STOREACTION_STORE
void GPU_framebuffer_clear_stencil(GPUFrameBuffer *fb, uint clear_stencil)
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
#define GPU_framebuffer_bind_ex(_fb,...)
@ GPU_DRIVER_ANY
@ GPU_OS_MAC
@ GPU_DEVICE_ATI
@ GPU_DEVICE_INTEL_UHD
@ GPU_DEVICE_INTEL
bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver)
eGPUTextureUsage
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_SHADER_WRITE
@ GPU_TEXTURE_USAGE_ATTACHMENT
@ GPU_RGB10_A2
void clear(float4 values)
bool ensure_2d_array(eGPUTextureFormat format, int2 extent, int layers, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
bool ensure_layer_views(bool cube_as_array=false)
bool ensure_2d(eGPUTextureFormat format, int2 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
GPUTexture * layer_range_view(int layer_start, int layer_len, bool cube_as_array=false)
out_radiance out_gbuf_normal out_gbuf_closure2 GPU_RG16
SHADOW_TILEMAP_RES tiles_buf[] statistics_buf render_view_buf[SHADOW_VIEW_MAX] GPU_R32UI
PassType
VecBase< uint32_t, 4 > uint4
void bind_resources(PassType &pass)
void acquire(int2 extent, int data_count, int normal_count)
void bind(Framebuffer &gbuffer_fb)