Blender V5.0
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_map.hh"
17#include "BLI_mutex.hh"
18
19#include "DRW_render.hh"
20#include "GPU_material.hh"
21#include "GPU_shader.hh"
22
24
25namespace blender::eevee {
26
28
29/* Keep alphabetical order and clean prefix. */
32
42
52
56
60
78
82
87
94
100
102
107
117
119
125
146
149
158
160
166
168};
169
201
202
206 private:
207 std::array<StaticShader, MAX_SHADER_TYPE> shaders_;
208
209 Mutex mutex_;
210
211 class SpecializationsKey {
212 private:
213 uint64_t hash_value_;
214
215 public:
216 SpecializationsKey(int render_buffers_shadow_id,
217 int shadow_ray_count,
218 int shadow_ray_step_count,
219 bool use_split_indirect,
220 bool use_lightprobe_eval)
221 {
222 BLI_assert(render_buffers_shadow_id >= -1);
223 BLI_assert(shadow_ray_count >= 1 && shadow_ray_count <= 4);
224 BLI_assert(shadow_ray_step_count >= 1 && shadow_ray_step_count <= 16);
225 BLI_assert(uint64_t(use_split_indirect) >= 0 && uint64_t(use_split_indirect) <= 1);
226 hash_value_ = render_buffers_shadow_id + 1;
227 hash_value_ = (hash_value_ << 2) | (shadow_ray_count - 1);
228 hash_value_ = (hash_value_ << 4) | (shadow_ray_step_count - 1);
229 hash_value_ = (hash_value_ << 1) | uint64_t(use_split_indirect);
230 hash_value_ = (hash_value_ << 1) | uint64_t(use_lightprobe_eval);
231 }
232
233 uint64_t hash() const
234 {
235 return hash_value_;
236 }
237
238 bool operator==(const SpecializationsKey &k) const
239 {
240 return hash_value_ == k.hash_value_;
241 }
242 };
243
245
246 static gpu::StaticShaderCache<ShaderModule> &get_static_cache()
247 {
249 static gpu::StaticShaderCache<ShaderModule> static_cache;
250 return static_cache;
251 }
252
253 public:
254 ShaderModule();
256
257 /* Trigger async compilation for the given shaders groups. */
259 {
260 return static_shaders_load(request_bits, false);
261 }
262 /* Wait for async compilation to finish for the given shaders groups.
263 * If shaders are not scheduled to async compile, this will do blocking compilation. */
265 {
266 return static_shaders_load(request_bits, true);
267 }
268
269 bool request_specializations(bool block_until_ready,
270 int render_buffers_shadow_id,
271 int shadow_ray_count,
272 int shadow_ray_step_count,
273 bool use_split_indirect,
274 bool use_lightprobe_eval);
275
276 gpu::Shader *static_shader_get(eShaderType shader_type);
277 GPUMaterial *material_shader_get(::Material *blender_mat,
278 bNodeTree *nodetree,
279 eMaterialPipeline pipeline_type,
280 eMaterialGeometry geometry_type,
281 bool deferred_compilation,
282 ::Material *default_mat);
283 GPUMaterial *world_shader_get(::World *blender_world,
284 bNodeTree *nodetree,
285 eMaterialPipeline pipeline_type,
286 bool deferred_compilation);
287
288 void material_create_info_amend(GPUMaterial *mat, GPUCodegenOutput *codegen);
289
291 static ShaderModule *module_get();
292 static void module_free();
293
294 private:
295 const char *static_shader_create_info_name_get(eShaderType shader_type);
296 ShaderGroups static_shaders_load(ShaderGroups request_bits, bool block_until_ready);
297};
298
299} // namespace blender::eevee
#define BLI_assert(a)
Definition BLI_assert.h:46
#define ENUM_OPERATORS(_type, _max)
bool operator==(const AssetWeakReference &a, const AssetWeakReference &b)
unsigned long long int uint64_t
ShaderGroups static_shaders_wait_ready(ShaderGroups request_bits)
ShaderGroups static_shaders_load_async(ShaderGroups request_bits)
@ SHADOW_TILEMAP_TAG_USAGE_SURFELS
@ SHADOW_TILEMAP_TAG_USAGE_OPAQUE
@ SHADOW_TILEMAP_TAG_USAGE_TRANSPARENT
@ FILM_PASS_CONVERT_CRYPTOMATTE
@ SHADOW_TILEMAP_TAG_USAGE_VOLUME
gpu::StaticShader StaticShader
std::mutex Mutex
Definition BLI_mutex.hh:47
#define hash
Definition noise_c.cc:154