Blender V5.3
eevee_shader.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11
12#pragma once
13
14#include <array>
15
16#include "BLI_enum_flags.hh"
17#include "BLI_map.hh"
18#include "BLI_mutex.hh"
19
20#include "DRW_render.hh"
21#include "GPU_material.hh"
22#include "GPU_shader.hh"
23
25
26namespace blender::eevee {
27
29
30/* Keep alphabetical order and clean prefix. */
33
44
55
59
63
81
85
90
98
104
107
112
122
124
130
150
153
162
164
166
172
174};
175
207
208
212 private:
213 std::array<StaticShader, MAX_SHADER_TYPE> shaders_;
214
215 Mutex mutex_;
216
217 class SpecializationsKey {
218 private:
219 uint64_t hash_value_;
220
221 public:
222 SpecializationsKey(int render_buffers_shadow_id,
223 int shadow_ray_count,
224 int shadow_ray_step_count,
225 bool use_split_indirect,
226 bool use_lightprobe_eval)
227 {
228 BLI_assert(render_buffers_shadow_id >= -1);
229 BLI_assert(shadow_ray_count >= 1 && shadow_ray_count <= 4);
230 BLI_assert(shadow_ray_step_count >= 1 && shadow_ray_step_count <= 16);
231 BLI_assert(uint64_t(use_split_indirect) >= 0 && uint64_t(use_split_indirect) <= 1);
232 hash_value_ = render_buffers_shadow_id + 1;
233 hash_value_ = (hash_value_ << 2) | (shadow_ray_count - 1);
234 hash_value_ = (hash_value_ << 4) | (shadow_ray_step_count - 1);
235 hash_value_ = (hash_value_ << 1) | uint64_t(use_split_indirect);
236 hash_value_ = (hash_value_ << 1) | uint64_t(use_lightprobe_eval);
237 }
238
239 uint64_t hash() const
240 {
241 return hash_value_;
242 }
243
244 bool operator==(const SpecializationsKey &k) const
245 {
246 return hash_value_ == k.hash_value_;
247 }
248 };
249
251
252 static gpu::StaticShaderCache<ShaderModule> &get_static_cache()
253 {
255 static gpu::StaticShaderCache<ShaderModule> static_cache;
256 return static_cache;
257 }
258
259 public:
260 ShaderModule();
262
263 /* Trigger async compilation for the given shaders groups. */
265 {
266 return static_shaders_load(request_bits, false);
267 }
268 /* Wait for async compilation to finish for the given shaders groups.
269 * If shaders are not scheduled to async compile, this will do blocking compilation. */
271 {
272 return static_shaders_load(request_bits, true);
273 }
274
275 bool request_specializations(bool block_until_ready,
276 int render_buffers_shadow_id,
277 int shadow_ray_count,
278 int shadow_ray_step_count,
279 bool use_split_indirect,
280 bool use_lightprobe_eval);
281
282 gpu::Shader *static_shader_get(eShaderType shader_type);
283 GPUMaterial *material_shader_get(blender::Material *blender_mat,
284 bNodeTree *nodetree,
285 eMaterialPipeline pipeline_type,
286 eMaterialGeometry geometry_type,
287 bool deferred_compilation,
288 blender::Material *default_mat);
289 GPUMaterial *world_shader_get(blender::World *blender_world,
290 bNodeTree *nodetree,
291 eMaterialPipeline pipeline_type,
292 bool deferred_compilation);
293
294 void material_create_info_amend(GPUMaterial *mat, GPUCodegenOutput *codegen);
295
297 static ShaderModule *module_get();
298 static void module_free();
299
300 private:
301 const char *static_shader_create_info_name_get(eShaderType shader_type);
302 ShaderGroups static_shaders_load(ShaderGroups request_bits, bool block_until_ready);
303 void material_create_info_pipelines_amend(eMaterialGeometry geometry_type,
304 eMaterialPipeline pipeline_type,
306};
307
308} // namespace blender::eevee
ShaderGroups static_shaders_wait_ready(ShaderGroups request_bits)
ShaderGroups static_shaders_load_async(ShaderGroups request_bits)
ENUM_OPERATORS(Layer::Flags)
@ DEFERRED_TILE_CLASSIFY_FALLBACK
@ SHADOW_TILEMAP_TAG_USAGE_SURFELS
@ SHADOW_TILEMAP_TAG_USAGE_OPAQUE
@ SHADOW_TILEMAP_TAG_USAGE_TRANSPARENT
@ FILM_PASS_CONVERT_CRYPTOMATTE
@ SHADOW_TILEMAP_TAG_USAGE_VOLUME
@ SHADOW_TILEMAP_TAG_UPDATE_PROPAGATE
gpu::StaticShader StaticShader
bool operator==(const CameraData &a, const CameraData &b)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
unsigned int uint32_t
Definition BKE_text.h:81
std::mutex Mutex
Definition BLI_mutex.hh:51
#define hash
Definition noise_c.cc:156
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...