Blender V4.5
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#include <string>
16
17#include "BLI_mutex.hh"
18#include "BLI_string_ref.hh"
19
20#include "DRW_render.hh"
21#include "GPU_material.hh"
22#include "GPU_shader.hh"
23
24#include "eevee_material.hh"
25#include "eevee_sync.hh"
26
27namespace blender::eevee {
28
30
31/* Keep alphabetical order and clean prefix. */
34
44
53
57
61
79
83
88
95
101
103
108
118
120
126
147
150
156
158
164
166};
167
172 private:
173 std::array<StaticShader, MAX_SHADER_TYPE> shaders_;
174
175 Mutex mutex_;
176
177 class SpecializationsKey {
178 private:
179 uint64_t hash_value_;
180
181 public:
182 SpecializationsKey(int render_buffers_shadow_id,
183 int shadow_ray_count,
184 int shadow_ray_step_count,
185 bool use_split_indirect,
186 bool use_lightprobe_eval)
187 {
188 BLI_assert(render_buffers_shadow_id >= -1);
189 BLI_assert(shadow_ray_count >= 1 && shadow_ray_count <= 4);
190 BLI_assert(shadow_ray_step_count >= 1 && shadow_ray_step_count <= 16);
191 BLI_assert(uint64_t(use_split_indirect) >= 0 && uint64_t(use_split_indirect) <= 1);
192 hash_value_ = render_buffers_shadow_id + 1;
193 hash_value_ = (hash_value_ << 2) | (shadow_ray_count - 1);
194 hash_value_ = (hash_value_ << 4) | (shadow_ray_step_count - 1);
195 hash_value_ = (hash_value_ << 1) | uint64_t(use_split_indirect);
196 hash_value_ = (hash_value_ << 1) | uint64_t(use_lightprobe_eval);
197 }
198
199 uint64_t hash() const
200 {
201 return hash_value_;
202 }
203
204 bool operator==(const SpecializationsKey &k) const
205 {
206 return hash_value_ == k.hash_value_;
207 }
208
209 bool operator<(const SpecializationsKey &k) const
210 {
211 return hash_value_ < k.hash_value_;
212 }
213 };
214
216
217 static gpu::StaticShaderCache<ShaderModule> &get_static_cache()
218 {
220 static gpu::StaticShaderCache<ShaderModule> static_cache;
221 return static_cache;
222 }
223
224 public:
225 ShaderModule();
227
228 /* Trigger async compilation for the given shaders groups. */
230 {
231 return static_shaders_load(request_bits, false);
232 }
233 /* Wait for async compilation to finish for the given shaders groups.
234 * If shaders are not scheduled to async compile, this will do blocking compilation. */
236 {
237 return static_shaders_load(request_bits, true);
238 }
239
240 bool request_specializations(bool block_until_ready,
241 int render_buffers_shadow_id,
242 int shadow_ray_count,
243 int shadow_ray_step_count,
244 bool use_split_indirect,
245 bool use_lightprobe_eval);
246
247 GPUShader *static_shader_get(eShaderType shader_type);
249 bNodeTree *nodetree,
250 eMaterialPipeline pipeline_type,
251 eMaterialGeometry geometry_type,
252 bool deferred_compilation,
253 ::Material *default_mat);
254 GPUMaterial *world_shader_get(::World *blender_world,
255 bNodeTree *nodetree,
256 eMaterialPipeline pipeline_type,
257 bool deferred_compilation);
258
260
262 static ShaderModule *module_get();
263 static void module_free();
264
265 private:
266 const char *static_shader_create_info_name_get(eShaderType shader_type);
267 ShaderGroups static_shaders_load(ShaderGroups request_bits, bool block_until_ready);
268};
269
270} // namespace blender::eevee
#define BLI_assert(a)
Definition BLI_assert.h:46
unsigned long long int uint64_t
ShaderGroups static_shaders_wait_ready(ShaderGroups request_bits)
bool request_specializations(bool block_until_ready, int render_buffers_shadow_id, int shadow_ray_count, int shadow_ray_step_count, bool use_split_indirect, bool use_lightprobe_eval)
ShaderGroups static_shaders_load_async(ShaderGroups request_bits)
void material_create_info_amend(GPUMaterial *mat, GPUCodegenOutput *codegen)
GPUMaterial * material_shader_get(::Material *blender_mat, bNodeTree *nodetree, eMaterialPipeline pipeline_type, eMaterialGeometry geometry_type, bool deferred_compilation, ::Material *default_mat)
static ShaderModule * module_get()
GPUMaterial * world_shader_get(::World *blender_world, bNodeTree *nodetree, eMaterialPipeline pipeline_type, bool deferred_compilation)
GPUShader * static_shader_get(eShaderType shader_type)
@ 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
bool operator==(const CameraData &a, const CameraData &b)
constexpr bool operator<(StringRef a, StringRef b)
std::mutex Mutex
Definition BLI_mutex.hh:47
#define hash
Definition noise_c.cc:154