Blender V4.5
eevee_shadow_info.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
5#ifdef GPU_SHADER
6# pragma once
7# include "gpu_glsl_cpp_stubs.hh"
8
10# include "draw_view_info.hh"
11# include "eevee_common_info.hh"
12# include "eevee_shader_shared.hh"
14
15# define SPHERE_PROBE
16#endif
17
18#include "draw_defines.hh"
19#include "eevee_defines.hh"
20
22
23/* -------------------------------------------------------------------- */
26
27GPU_SHADER_CREATE_INFO(eevee_shadow_clipmap_clear)
30STORAGE_BUF(0, write, ShadowTileMapClip, tilemaps_clip_buf[])
31PUSH_CONSTANT(int, tilemaps_clip_buf_len)
32ADDITIONAL_INFO(eevee_shared)
33COMPUTE_SOURCE("eevee_shadow_clipmap_clear_comp.glsl")
35
36GPU_SHADER_CREATE_INFO(eevee_shadow_tilemap_bounds)
39STORAGE_BUF(LIGHT_BUF_SLOT, read_write, LightData, light_buf[])
40STORAGE_BUF(LIGHT_CULL_BUF_SLOT, read, LightCullingData, light_cull_buf)
41STORAGE_BUF(4, read, uint, casters_id_buf[])
42STORAGE_BUF(5, read_write, ShadowTileMapData, tilemaps_buf[])
43STORAGE_BUF(6, read, ObjectBounds, bounds_buf[])
44STORAGE_BUF(7, read_write, ShadowTileMapClip, tilemaps_clip_buf[])
45PUSH_CONSTANT(int, resource_len)
46TYPEDEF_SOURCE("draw_shader_shared.hh")
47ADDITIONAL_INFO(eevee_shared)
48COMPUTE_SOURCE("eevee_shadow_tilemap_bounds_comp.glsl")
50
51GPU_SHADER_CREATE_INFO(eevee_shadow_tilemap_init)
54STORAGE_BUF(0, read_write, ShadowTileMapData, tilemaps_buf[])
55STORAGE_BUF(1, read_write, uint, tiles_buf[])
56STORAGE_BUF(2, read_write, ShadowTileMapClip, tilemaps_clip_buf[])
57STORAGE_BUF(4, read_write, uint2, pages_cached_buf[])
58ADDITIONAL_INFO(eevee_shared)
59COMPUTE_SOURCE("eevee_shadow_tilemap_init_comp.glsl")
61
62GPU_SHADER_CREATE_INFO(eevee_shadow_tag_update)
64LOCAL_GROUP_SIZE(1, 1, 1)
65STORAGE_BUF(0, read_write, ShadowTileMapData, tilemaps_buf[])
66STORAGE_BUF(1, read_write, uint, tiles_buf[])
67STORAGE_BUF(5, read, ObjectBounds, bounds_buf[])
68STORAGE_BUF(6, read, uint, resource_ids_buf[])
69ADDITIONAL_INFO(eevee_shared)
70ADDITIONAL_INFO(draw_view)
71ADDITIONAL_INFO(draw_view_culling)
72COMPUTE_SOURCE("eevee_shadow_tag_update_comp.glsl")
74
75GPU_SHADER_CREATE_INFO(eevee_shadow_tag_usage_opaque)
78STORAGE_BUF(5, read_write, ShadowTileMapData, tilemaps_buf[])
79STORAGE_BUF(6, read_write, uint, tiles_buf[])
80PUSH_CONSTANT(int2, input_depth_extent)
81ADDITIONAL_INFO(eevee_shared)
82ADDITIONAL_INFO(draw_view)
83ADDITIONAL_INFO(draw_view_culling)
84ADDITIONAL_INFO(eevee_hiz_data)
85ADDITIONAL_INFO(eevee_light_data)
86COMPUTE_SOURCE("eevee_shadow_tag_usage_comp.glsl")
88
89GPU_SHADER_CREATE_INFO(eevee_shadow_tag_usage_surfels)
92STORAGE_BUF(6, read_write, ShadowTileMapData, tilemaps_buf[])
93STORAGE_BUF(7, read_write, uint, tiles_buf[])
94PUSH_CONSTANT(int, directional_level)
95ADDITIONAL_INFO(eevee_shared)
96ADDITIONAL_INFO(draw_view)
97ADDITIONAL_INFO(draw_view_culling)
98ADDITIONAL_INFO(eevee_light_data)
99ADDITIONAL_INFO(eevee_global_ubo)
100ADDITIONAL_INFO(eevee_surfel_common)
101COMPUTE_SOURCE("eevee_shadow_tag_usage_surfels_comp.glsl")
103
104GPU_SHADER_NAMED_INTERFACE_INFO(eevee_shadow_tag_transparent_iface, interp)
106SMOOTH(float3, vP)
108GPU_SHADER_NAMED_INTERFACE_INFO(eevee_shadow_tag_transparent_flat_iface, interp_flat)
109FLAT(float3, ls_aabb_min)
110FLAT(float3, ls_aabb_max)
112
113GPU_SHADER_CREATE_INFO(eevee_shadow_tag_usage_transparent)
116STORAGE_BUF(4, read, ObjectBounds, bounds_buf[])
117STORAGE_BUF(5, read_write, ShadowTileMapData, tilemaps_buf[])
118STORAGE_BUF(6, read_write, uint, tiles_buf[])
119PUSH_CONSTANT(int2, fb_resolution)
120PUSH_CONSTANT(int, fb_lod)
121VERTEX_OUT(eevee_shadow_tag_transparent_iface)
122VERTEX_OUT(eevee_shadow_tag_transparent_flat_iface)
123ADDITIONAL_INFO(eevee_shared)
124ADDITIONAL_INFO(draw_resource_id_varying)
125ADDITIONAL_INFO(draw_view)
126ADDITIONAL_INFO(draw_view_culling)
127ADDITIONAL_INFO(draw_modelmat)
128ADDITIONAL_INFO(eevee_hiz_data)
129ADDITIONAL_INFO(eevee_light_data)
130VERTEX_SOURCE("eevee_shadow_tag_usage_vert.glsl")
131FRAGMENT_SOURCE("eevee_shadow_tag_usage_frag.glsl")
133
134GPU_SHADER_CREATE_INFO(eevee_shadow_tag_usage_volume)
137STORAGE_BUF(4, read_write, ShadowTileMapData, tilemaps_buf[])
138STORAGE_BUF(5, read_write, uint, tiles_buf[])
139ADDITIONAL_INFO(eevee_volume_properties_data)
140ADDITIONAL_INFO(eevee_shared)
141ADDITIONAL_INFO(draw_view)
142ADDITIONAL_INFO(draw_view_culling)
143ADDITIONAL_INFO(eevee_hiz_data)
144ADDITIONAL_INFO(eevee_light_data)
145ADDITIONAL_INFO(eevee_sampling_data)
146COMPUTE_SOURCE("eevee_shadow_tag_usage_volume_comp.glsl")
148
149GPU_SHADER_CREATE_INFO(eevee_shadow_page_mask)
152PUSH_CONSTANT(int, max_view_per_tilemap)
153STORAGE_BUF(0, read_write, ShadowTileMapData, tilemaps_buf[])
154STORAGE_BUF(1, read_write, uint, tiles_buf[])
155ADDITIONAL_INFO(eevee_shared)
156COMPUTE_SOURCE("eevee_shadow_page_mask_comp.glsl")
158
159GPU_SHADER_CREATE_INFO(eevee_shadow_page_free)
162STORAGE_BUF(0, read_write, ShadowTileMapData, tilemaps_buf[])
163STORAGE_BUF(1, read_write, uint, tiles_buf[])
164STORAGE_BUF(2, read_write, ShadowPagesInfoData, pages_infos_buf)
165STORAGE_BUF(3, read_write, uint, pages_free_buf[])
166STORAGE_BUF(4, read_write, uint2, pages_cached_buf[])
167ADDITIONAL_INFO(eevee_shared)
168COMPUTE_SOURCE("eevee_shadow_page_free_comp.glsl")
170
171GPU_SHADER_CREATE_INFO(eevee_shadow_page_defrag)
174TYPEDEF_SOURCE("draw_shader_shared.hh")
175STORAGE_BUF(1, read_write, uint, tiles_buf[])
176STORAGE_BUF(2, read_write, ShadowPagesInfoData, pages_infos_buf)
177STORAGE_BUF(3, read_write, uint, pages_free_buf[])
178STORAGE_BUF(4, read_write, uint2, pages_cached_buf[])
179STORAGE_BUF(5, write, DispatchCommand, clear_dispatch_buf)
180STORAGE_BUF(6, write, DrawCommand, tile_draw_buf)
181STORAGE_BUF(7, read_write, ShadowStatistics, statistics_buf)
182ADDITIONAL_INFO(eevee_shared)
183COMPUTE_SOURCE("eevee_shadow_page_defrag_comp.glsl")
185
186GPU_SHADER_CREATE_INFO(eevee_shadow_page_allocate)
189TYPEDEF_SOURCE("draw_shader_shared.hh")
190STORAGE_BUF(0, read_write, ShadowTileMapData, tilemaps_buf[])
191STORAGE_BUF(1, read_write, uint, tiles_buf[])
192STORAGE_BUF(2, read_write, ShadowPagesInfoData, pages_infos_buf)
193STORAGE_BUF(3, read_write, uint, pages_free_buf[])
194STORAGE_BUF(4, read_write, uint2, pages_cached_buf[])
195STORAGE_BUF(6, read_write, ShadowStatistics, statistics_buf)
196ADDITIONAL_INFO(eevee_shared)
197COMPUTE_SOURCE("eevee_shadow_page_allocate_comp.glsl")
199
200GPU_SHADER_CREATE_INFO(eevee_shadow_tilemap_finalize)
202TYPEDEF_SOURCE("draw_shader_shared.hh")
204STORAGE_BUF(0, read, ShadowTileMapData, tilemaps_buf[])
205STORAGE_BUF(1, read, uint, tiles_buf[])
206STORAGE_BUF(2, read_write, ShadowPagesInfoData, pages_infos_buf)
207STORAGE_BUF(3, read_write, ShadowStatistics, statistics_buf)
208STORAGE_BUF(4, write, ViewMatrices, view_infos_buf[SHADOW_VIEW_MAX])
209STORAGE_BUF(5, write, ShadowRenderView, render_view_buf[SHADOW_VIEW_MAX])
210STORAGE_BUF(6, read, ShadowTileMapClip, tilemaps_clip_buf[])
211IMAGE(0, GPU_R32UI, write, uimage2D, tilemaps_img)
212ADDITIONAL_INFO(eevee_shared)
213COMPUTE_SOURCE("eevee_shadow_tilemap_finalize_comp.glsl")
215
216GPU_SHADER_CREATE_INFO(eevee_shadow_tilemap_rendermap)
218TYPEDEF_SOURCE("draw_shader_shared.hh")
220STORAGE_BUF(0, read_write, ShadowStatistics, statistics_buf)
221STORAGE_BUF(1, read, ShadowRenderView, render_view_buf[SHADOW_VIEW_MAX])
222STORAGE_BUF(2, read_write, uint, tiles_buf[])
223STORAGE_BUF(3, read_write, DispatchCommand, clear_dispatch_buf)
224STORAGE_BUF(4, read_write, DrawCommand, tile_draw_buf)
225STORAGE_BUF(5, write, uint, dst_coord_buf[SHADOW_RENDER_MAP_SIZE])
226STORAGE_BUF(6, write, uint, src_coord_buf[SHADOW_RENDER_MAP_SIZE])
227STORAGE_BUF(7, write, uint, render_map_buf[SHADOW_RENDER_MAP_SIZE])
228ADDITIONAL_INFO(eevee_shared)
229COMPUTE_SOURCE("eevee_shadow_tilemap_rendermap_comp.glsl")
231
232GPU_SHADER_CREATE_INFO(eevee_shadow_tilemap_amend)
235IMAGE(0, GPU_R32UI, read_write, uimage2D, tilemaps_img)
236STORAGE_BUF(LIGHT_CULL_BUF_SLOT, read, LightCullingData, light_cull_buf)
237STORAGE_BUF(LIGHT_BUF_SLOT, read_write, LightData, light_buf[])
238/* The call bind_resources(lights) also uses LIGHT_ZBIN_BUF_SLOT and LIGHT_TILE_BUF_SLOT. */
239STORAGE_BUF(4, read, ShadowTileMapData, tilemaps_buf[])
240ADDITIONAL_INFO(eevee_shared)
241ADDITIONAL_INFO(draw_view)
242COMPUTE_SOURCE("eevee_shadow_tilemap_amend_comp.glsl")
244
245/* AtomicMin clear implementation. */
246GPU_SHADER_CREATE_INFO(eevee_shadow_page_clear)
249STORAGE_BUF(2, read, ShadowPagesInfoData, pages_infos_buf)
250STORAGE_BUF(6, read, uint, dst_coord_buf[SHADOW_RENDER_MAP_SIZE])
251ADDITIONAL_INFO(eevee_shared)
252COMPUTE_SOURCE("eevee_shadow_page_clear_comp.glsl")
253IMAGE(SHADOW_ATLAS_IMG_SLOT, GPU_R32UI, read_write, uimage2DArrayAtomic, shadow_atlas_img)
255
256/* TBDR clear implementation. */
257GPU_SHADER_CREATE_INFO(eevee_shadow_page_tile_clear)
259DEFINE("PASS_CLEAR")
260ADDITIONAL_INFO(eevee_shared)
261BUILTINS(BuiltinBits::VIEWPORT_INDEX | BuiltinBits::LAYER)
262STORAGE_BUF(8, read, uint, src_coord_buf[SHADOW_RENDER_MAP_SIZE])
263VERTEX_SOURCE("eevee_shadow_page_tile_vert.glsl")
264FRAGMENT_SOURCE("eevee_shadow_page_tile_frag.glsl")
265FRAGMENT_OUT_ROG(0, float, out_tile_depth, SHADOW_ROG_ID)
267
268/* Interface for passing precalculated values in accumulation vertex to frag. */
269GPU_SHADER_NAMED_INTERFACE_INFO(eevee_shadow_page_tile_store_noperspective_iface,
270 interp_noperspective)
271NO_PERSPECTIVE(float2, out_texel_xy)
272GPU_SHADER_NAMED_INTERFACE_END(interp_noperspective)
273GPU_SHADER_NAMED_INTERFACE_INFO(eevee_shadow_page_tile_store_flat_iface, interp_flat)
274#ifdef APPLE
275/* Metal supports ushort which saves a bit of performance here. */
276FLAT(ushort, out_page_z)
277#else
278FLAT(uint, out_page_z)
279#endif
281
282/* 2nd tile pass to store shadow depths in atlas. */
283GPU_SHADER_CREATE_INFO(eevee_shadow_page_tile_store)
285DEFINE("PASS_DEPTH_STORE")
286ADDITIONAL_INFO(eevee_shared)
287BUILTINS(BuiltinBits::VIEWPORT_INDEX | BuiltinBits::LAYER)
288STORAGE_BUF(7, read, uint, dst_coord_buf[SHADOW_RENDER_MAP_SIZE])
289STORAGE_BUF(8, read, uint, src_coord_buf[SHADOW_RENDER_MAP_SIZE])
290SUBPASS_IN(0, float, Float2DArray, in_tile_depth, SHADOW_ROG_ID)
291IMAGE(SHADOW_ATLAS_IMG_SLOT, GPU_R32UI, read_write, uimage2DArray, shadow_atlas_img)
292VERTEX_OUT(eevee_shadow_page_tile_store_noperspective_iface)
293VERTEX_OUT(eevee_shadow_page_tile_store_flat_iface)
294VERTEX_SOURCE("eevee_shadow_page_tile_vert.glsl")
295FRAGMENT_SOURCE("eevee_shadow_page_tile_frag.glsl")
297
298/* Custom visibility check pass. */
299GPU_SHADER_CREATE_INFO(eevee_shadow_view_visibility)
301TYPEDEF_SOURCE("eevee_defines.hh")
302TYPEDEF_SOURCE("eevee_shader_shared.hh")
304DEFINE_VALUE("DRW_VIEW_LEN", STRINGIFY(DRW_VIEW_MAX))
305STORAGE_BUF(0, read, ObjectBounds, bounds_buf[])
306STORAGE_BUF(1, read_write, uint, visibility_buf[])
307STORAGE_BUF(2, read, ShadowRenderView, render_view_buf[SHADOW_VIEW_MAX])
308PUSH_CONSTANT(int, resource_len)
309PUSH_CONSTANT(int, view_len)
310PUSH_CONSTANT(int, visibility_word_per_draw)
311COMPUTE_SOURCE("eevee_shadow_visibility_comp.glsl")
312ADDITIONAL_INFO(draw_view)
313ADDITIONAL_INFO(draw_view_culling)
314ADDITIONAL_INFO(draw_object_infos)
316
318
319/* -------------------------------------------------------------------- */
322
323GPU_SHADER_CREATE_INFO(eevee_shadow_debug)
325ADDITIONAL_INFO(eevee_shared)
326STORAGE_BUF(5, read, ShadowTileMapData, tilemaps_buf[])
327STORAGE_BUF(6, read, uint, tiles_buf[])
328FRAGMENT_OUT_DUAL(0, float4, out_color_add, SRC_0)
329FRAGMENT_OUT_DUAL(0, float4, out_color_mul, SRC_1)
330PUSH_CONSTANT(int, debug_mode)
331PUSH_CONSTANT(int, debug_tilemap_index)
333FRAGMENT_SOURCE("eevee_shadow_debug_frag.glsl")
334ADDITIONAL_INFO(gpu_fullscreen)
335ADDITIONAL_INFO(draw_view)
336ADDITIONAL_INFO(eevee_hiz_data)
337ADDITIONAL_INFO(eevee_light_data)
338ADDITIONAL_INFO(eevee_shadow_data)
340
unsigned int uint
unsigned short ushort
#define STRINGIFY(x)
@ GPU_R32UI
#define DRW_VISIBILITY_GROUP_SIZE
#define DRW_VIEW_MAX
#define SURFEL_GROUP_SIZE
#define SHADOW_TILEMAP_RES
#define LIGHT_BUF_SLOT
#define SHADOW_PAGE_CLEAR_GROUP_SIZE
#define SHADOW_CLIPMAP_GROUP_SIZE
#define SHADOW_TILEMAP_LOD0_LEN
#define SHADOW_VIEW_MAX
#define SHADOW_DEPTH_SCAN_GROUP_SIZE
#define VOLUME_GROUP_SIZE
#define SHADOW_BOUNDS_GROUP_SIZE
#define SHADOW_ATLAS_IMG_SLOT
#define LIGHT_CULL_BUF_SLOT
#define SHADOW_RENDER_MAP_SIZE
#define SHADOW_ROG_ID
uint pos
ImageBase< uint, 2, true, true > uimage2DArrayAtomic
ImageBase< uint, 2 > uimage2D
ImageBase< uint, 2, true > uimage2DArray
VecBase< float, 4 > float4
#define TYPEDEF_SOURCE(filename)
#define VERTEX_OUT(stage_interface)
#define FRAGMENT_OUT_DUAL(slot, type, name, blend)
#define SMOOTH(type, name)
#define FRAGMENT_SOURCE(filename)
#define ADDITIONAL_INFO(info_name)
#define PUSH_CONSTANT(type, name)
#define DEFINE(name)
#define GPU_SHADER_NAMED_INTERFACE_INFO(_interface, _inst_name)
#define FLAT(type, name)
#define GPU_SHADER_NAMED_INTERFACE_END(_inst_name)
#define NO_PERSPECTIVE(type, name)
#define BUILTINS(builtin)
#define STORAGE_BUF(slot, qualifiers, type_name, name)
#define GPU_SHADER_CREATE_INFO(_info)
#define SUBPASS_IN(slot, type, img_type, name, rog)
#define VERTEX_SOURCE(filename)
#define LOCAL_GROUP_SIZE(...)
#define VERTEX_IN(slot, type, name)
#define IMAGE(slot, format, qualifiers, type, name)
#define GPU_SHADER_CREATE_END()
#define COMPUTE_SOURCE(filename)
#define DO_STATIC_COMPILATION()
#define DEPTH_WRITE(value)
#define DEFINE_VALUE(name, value)
#define FRAGMENT_OUT_ROG(slot, type, name, rog)
ccl_device_inline float interp(const float a, const float b, const float t)
Definition math_base.h:502
read