Blender V5.3
eevee_shader.cc
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#include "GPU_capabilities.hh"
13
14#include "BKE_material.hh"
15#include "BKE_node_runtime.hh"
16
17#include "DNA_world_types.h"
18
20
21#include "eevee_shader.hh"
22
23#include "eevee_shadow.hh"
24
25#include "BLI_assert.hh"
26#include "BLI_math_bits.hh"
27#include <fmt/format.h>
28
29namespace blender::eevee {
30
31/* -------------------------------------------------------------------- */
35
37{
38 return &get_static_cache().get();
39}
40
42{
43 get_static_cache().release();
44}
45
47{
48 for (auto i : IndexRange(MAX_SHADER_TYPE)) {
49 const char *name = static_shader_create_info_name_get(eShaderType(i));
50#ifndef NDEBUG
51 if (name == nullptr) {
52 std::cerr << "EEVEE: Missing case for eShaderType(" << i
53 << ") in static_shader_create_info_name_get().";
54 BLI_assert(0);
55 }
56 const GPUShaderCreateInfo *create_info = GPU_shader_create_info_get(name);
57 BLI_assert_msg(create_info != nullptr, "EEVEE: Missing create info for static shader.");
58#endif
59 shaders_[i] = StaticShader(name);
60 }
61}
62
64{
65 /* Cancel compilation to avoid asserts on exit at ShaderCompiler destructor. */
66
67 /* Specializations first, to avoid releasing the base shader while the specialization compilation
68 * is still in flight. */
69 for (Vector<AsyncSpecializationHandle> &handles : specialization_handles_.values()) {
70 for (AsyncSpecializationHandle &handle : handles) {
71 if (handle) {
73 }
74 }
75 }
76}
77
79
80/* -------------------------------------------------------------------- */
84
85ShaderGroups ShaderModule::static_shaders_load(const ShaderGroups request_bits,
86 bool block_until_ready)
87{
88 std::lock_guard lock(mutex_);
89
91 auto request = [&](ShaderGroups bit, Span<eShaderType> shader_types) {
92 if (request_bits & bit) {
93 bool all_loaded = true;
94 for (eShaderType shader : shader_types) {
95 if (shaders_[shader].is_ready()) {
96 /* Noop. */
97 }
98 else if (block_until_ready) {
99 shaders_[shader].get();
100 }
101 else {
102 shaders_[shader].ensure_compile_async();
103 all_loaded = false;
104 }
105 }
106 if (all_loaded) {
107 ready |= bit;
108 }
109 }
110 };
111
112#define AS_SPAN(arr) Span<eShaderType>(arr, ARRAY_SIZE(arr))
113 {
114 /* These are the slowest shaders by far. Submitting them first make sure they overlap with
115 * other shaders compilation. */
116 const eShaderType shader_list[] = {
123 request(DEFERRED_LIGHTING_SHADERS, AS_SPAN(shader_list));
124 }
125 {
126 const eShaderType shader_list[] = {AMBIENT_OCCLUSION_PASS};
127 request(AMBIENT_OCCLUSION_SHADERS, AS_SPAN(shader_list));
128 }
129 {
130 const eShaderType shader_list[] = {RENDERPASS_CLEAR,
131 FILM_COPY,
132 FILM_COMP,
135 FILM_FRAG,
141 request(FILM_SHADERS, AS_SPAN(shader_list));
142 }
143 {
144 const eShaderType shader_list[] = {DEFERRED_CAPTURE_EVAL};
145 request(DEFERRED_CAPTURE_SHADERS, AS_SPAN(shader_list));
146 }
147 {
148 const eShaderType shader_list[] = {DEFERRED_PLANAR_EVAL};
149 request(DEFERRED_PLANAR_SHADERS, AS_SPAN(shader_list));
150 }
151 {
152 const eShaderType shader_list[] = {DOF_BOKEH_LUT,
164 DOF_SETUP,
169 request(DEPTH_OF_FIELD_SHADERS, AS_SPAN(shader_list));
170 }
171 {
172 const eShaderType shader_list[] = {HIZ_UPDATE, HIZ_UPDATE_LAYER};
173 request(HIZ_SHADERS, AS_SPAN(shader_list));
174 }
175 {
176 const eShaderType shader_list[] = {
178 request(FAST_GI_SHADERS, AS_SPAN(shader_list));
179 }
180 {
181 const eShaderType shader_list[] = {LIGHT_CULLING_DEBUG,
188 request(LIGHT_CULLING_SHADERS, AS_SPAN(shader_list));
189 }
190 {
191 const eShaderType shader_list[] = {
193 request(IRRADIANCE_BAKE_SHADERS, AS_SPAN(shader_list));
194 }
195 {
196 const eShaderType shader_list[] = {MOTION_BLUR_GATHER,
200 request(MOTION_BLUR_SHADERS, AS_SPAN(shader_list));
201 }
202 {
203 const eShaderType shader_list[] = {RAY_DENOISE_BILATERAL,
212 request(RAYTRACING_SHADERS, AS_SPAN(shader_list));
213 }
214 {
215 const eShaderType shader_list[] = {SPHERE_PROBE_CONVOLVE,
220 request(SPHERE_PROBE_SHADERS, AS_SPAN(shader_list));
221 }
222 {
224 request(VOLUME_PROBE_SHADERS, AS_SPAN(shader_list));
225 }
226 {
227 const eShaderType shader_list[] = {SHADOW_CLIPMAP_CLEAR,
242 request(SHADOW_SHADERS, AS_SPAN(shader_list));
243 }
244 {
245 const eShaderType shader_list[] = {SUBSURFACE_CONVOLVE, SUBSURFACE_SETUP};
246 request(SUBSURFACE_SHADERS, AS_SPAN(shader_list));
247 }
248 {
249 const eShaderType shader_list[] = {SURFEL_CLUSTER_BUILD,
254 SURFEL_RAY};
255 request(SURFEL_SHADERS, AS_SPAN(shader_list));
256 }
257 {
258 const eShaderType shader_list[] = {VERTEX_COPY};
259 request(VERTEX_COPY_SHADERS, AS_SPAN(shader_list));
260 }
261 {
262 const eShaderType shader_list[] = {SHADOW_TILEMAP_TAG_USAGE_VOLUME,
268 request(VOLUME_EVAL_SHADERS, AS_SPAN(shader_list));
269 }
270#undef AS_SPAN
271 return ready;
272}
273
274bool ShaderModule::request_specializations(bool block_until_ready,
275 int render_buffers_shadow_id,
276 int shadow_ray_count,
277 int shadow_ray_step_count,
278 bool use_split_indirect,
279 bool use_lightprobe_eval)
280{
281 std::lock_guard lock(mutex_);
282
283 Vector<AsyncSpecializationHandle> &handles = specialization_handles_.lookup_or_add_cb(
284 {render_buffers_shadow_id,
285 shadow_ray_count,
286 shadow_ray_step_count,
287 use_split_indirect,
288 use_lightprobe_eval},
289 [&]() {
291 for (int i : IndexRange(3)) {
293
294 ShaderSpecialization specialization;
295 specialization.shader = shader;
296 gpu::shader::SpecializationConstants &constants = specialization.constants;
298
299 auto set_value = [&](const char *name, auto value) {
300 constants.set_value(GPU_shader_get_constant(shader, name), value);
301 };
302
303 for (bool use_transmission : {false, true}) {
304 set_value("render_pass_shadow_id", render_buffers_shadow_id);
305 set_value("use_split_indirect", use_split_indirect);
306 set_value("use_lightprobe_eval", use_lightprobe_eval);
307 set_value("use_transmission", use_transmission);
308 set_value("shadow_ray_count", shadow_ray_count);
309 set_value("shadow_ray_step_count", shadow_ray_step_count);
310 }
311
312 handles.append(GPU_shader_async_specialization(specialization));
313 }
314
315 return handles;
316 });
317
318 bool is_ready = true;
319 for (AsyncSpecializationHandle &handle : handles) {
320 while (!GPU_shader_async_specialization_is_ready(handle) && block_until_ready) {
321 /* Block until ready. */
322 }
323 if (handle != 0) {
324 is_ready = false;
325 break;
326 }
327 }
328
329 return is_ready;
330}
331
332const char *ShaderModule::static_shader_create_info_name_get(eShaderType shader_type)
333{
334 switch (shader_type) {
336 return "eevee_ambient_occlusion_pass";
337 case FILM_COPY:
338 return "eevee_film_copy_frag";
339 case FILM_COMP:
340 return "eevee_film_comp";
342 return "eevee_film_comp_panoramic";
344 return "eevee_film_cryptomatte_post";
345 case FILM_FRAG:
346 return "eevee_film_frag";
348 return "eevee_film_pass_convert_combined";
350 return "eevee_film_pass_convert_depth";
352 return "eevee_film_pass_convert_value";
354 return "eevee_film_pass_convert_color";
356 return "eevee_film_pass_convert_cryptomatte";
357 case DEFERRED_COMBINE:
358 return "eevee_deferred_combine";
360 return "eevee_deferred_light_single";
362 return "eevee_deferred_light_double";
364 return "eevee_deferred_light_triple";
366 return "eevee_deferred_aov_clear";
368 return "eevee_deferred_sphere_eval";
370 return "eevee_deferred_planar_eval";
372 return "eevee_deferred_thickness_amend";
374 return "eevee_deferred_tile_classify";
376 return "eevee_deferred_tile_classify_fallback";
377 case HIZ_DEBUG:
378 return "eevee_hiz_debug";
379 case HIZ_UPDATE:
380 return "eevee_hiz_update";
381 case HIZ_UPDATE_LAYER:
382 return "eevee_hiz_update_layer";
383 case FAST_GI_DENOISE:
384 return "eevee_fast_gi_denoise";
385 case FAST_GI_RESOLVE:
386 return "eevee_fast_gi_resolve";
387 case FAST_GI_SCAN:
388 return "eevee_fast_gi_scan";
389 case FAST_GI_SETUP:
390 return "eevee_fast_gi_setup";
392 return "eevee_lookdev_copy_world";
393 case LOOKDEV_DISPLAY:
394 return "eevee_lookdev_display";
396 return "eevee_motion_blur_gather";
398 return "eevee_motion_blur_tiles_dilate";
400 return "eevee_motion_blur_tiles_flatten_rgba";
402 return "eevee_motion_blur_tiles_flatten_rg";
403 case DEBUG_SURFELS:
404 return "eevee_debug_surfels";
406 return "eevee_debug_irradiance_grid";
407 case DEBUG_GBUFFER:
408 return "eevee_debug_gbuffer";
410 return "eevee_display_lightprobe_volume";
412 return "eevee_display_lightprobe_sphere";
414 return "eevee_display_lightprobe_planar";
415 case DOF_BOKEH_LUT:
416 return "eevee_depth_of_field_bokeh_lut";
417 case DOF_DOWNSAMPLE:
418 return "eevee_depth_of_field_downsample";
419 case DOF_FILTER:
420 return "eevee_depth_of_field_filter";
422 return "eevee_depth_of_field_gather_foreground_lut";
424 return "eevee_depth_of_field_gather_foreground_no_lut";
426 return "eevee_depth_of_field_gather_background_lut";
428 return "eevee_depth_of_field_gather_background_no_lut";
430 return "eevee_depth_of_field_hole_fill";
431 case DOF_REDUCE:
432 return "eevee_depth_of_field_reduce";
433 case DOF_RESOLVE:
434 return "eevee_depth_of_field_resolve_no_lut";
435 case DOF_RESOLVE_LUT:
436 return "eevee_depth_of_field_resolve_lut";
437 case DOF_SETUP:
438 return "eevee_depth_of_field_setup";
439 case DOF_SCATTER:
440 return "eevee_depth_of_field_scatter";
441 case DOF_STABILIZE:
442 return "eevee_depth_of_field_stabilize";
444 return "eevee_depth_of_field_tiles_dilate_minabs";
446 return "eevee_depth_of_field_tiles_dilate_minmax";
448 return "eevee_depth_of_field_tiles_flatten";
450 return "eevee_light_culling_debug";
452 return "eevee_light_culling_cull";
454 return "eevee_light_culling_sort";
456 return "eevee_light_culling_tile";
458 return "eevee_light_culling_zbin";
460 return "eevee_light_shape_display";
462 return "eevee_light_shadow_setup";
464 return "eevee_raytracing_denoise_spatial";
466 return "eevee_raytracing_denoise_temporal";
468 return "eevee_raytracing_denoise_bilateral";
469 case RAY_GENERATE:
470 return "eevee_ray_generate";
472 return "eevee_ray_trace_fallback";
473 case RAY_TRACE_PLANAR:
474 return "eevee_ray_trace_planar";
475 case RAY_TRACE_SCREEN:
476 return "eevee_ray_trace_screen";
478 return "eevee_ray_tile_classify";
479 case RAY_TILE_COMPACT:
480 return "eevee_ray_tile_compact";
481 case RENDERPASS_CLEAR:
482 return "eevee_renderpass_clear";
484 return "eevee_lightprobe_volume_bounds";
486 return "eevee_lightprobe_volume_offset";
488 return "eevee_lightprobe_volume_ray";
490 return "eevee_lightprobe_volume_load";
492 return "eevee_lightprobe_volume_world";
494 return "eevee_lightprobe_sphere_convolve";
496 return "eevee_lightprobe_sphere_remap";
498 return "eevee_lightprobe_sphere_irradiance";
500 return "eevee_lightprobe_sphere_select";
502 return "eevee_lightprobe_sphere_sunlight";
504 return "eevee_shadow_tilemap_bounds_init";
505 case SHADOW_DEBUG:
506 return "eevee_shadow_debug";
508 return "eevee_shadow_page_allocate";
510 return "eevee_shadow_page_clear";
512 return "eevee_shadow_page_defrag";
513 case SHADOW_PAGE_FREE:
514 return "eevee_shadow_page_free";
515 case SHADOW_PAGE_MASK:
516 return "eevee_shadow_page_mask";
518 return "eevee_shadow_tilemap_amend";
520 return "eevee_shadow_tilemap_bounds";
522 return "eevee_shadow_tilemap_finalize";
524 return "eevee_shadow_tilemap_rendermap";
526 return "eevee_shadow_tilemap_init";
528 return "eevee_shadow_tag_update";
530 return "eevee_shadow_tag_update_propagate";
532 return "eevee_shadow_tag_usage_opaque";
534 return "eevee_shadow_tag_usage_surfels";
536 return "eevee_shadow_tag_usage_transparent";
538 return "eevee_shadow_tag_usage_volume";
540 return "eevee_shadow_view_visibility";
542 return "eevee_subsurface_convolve";
543 case SUBSURFACE_SETUP:
544 return "eevee_subsurface_setup";
546 return "eevee_surfel_cluster_build";
547 case SURFEL_LIGHT:
548 return "eevee_surfel_light";
550 return "eevee_surfel_list_build";
552 return "eevee_surfel_list_flatten";
554 return "eevee_surfel_list_prefix";
556 return "eevee_surfel_list_prepare";
557 case SURFEL_LIST_SORT:
558 return "eevee_surfel_list_sort";
559 case SURFEL_RAY:
560 return "eevee_surfel_ray";
562 return "eevee_forward_resolve";
563 case VERTEX_COPY:
564 return "eevee_vertex_copy";
566 return "eevee_volume_integration";
568 return "eevee_volume_occupancy_convert";
569 case VOLUME_RESOLVE:
570 return "eevee_volume_resolve";
571 case VOLUME_SCATTER:
572 return "eevee_volume_scatter";
574 return "eevee_volume_scatter_with_lights";
575 /* To avoid compiler warning about missing case. */
576 case MAX_SHADER_TYPE:
577 return "";
578 }
579 return "";
580}
581
583{
584 return shaders_[shader_type].get();
585}
586
588
589/* -------------------------------------------------------------------- */
593
594/* Helper class to get free sampler slots for materials. */
596 /* Assumes slots reserved from ShaderCreateInfos are always below 32. */
597 uint32_t available_samplers_ = ~uint32_t(0u);
598 /* But some backends may allow more samplers that we can use for material textures.
599 * These slots are just increased linearly. */
600 int total_requested_samplers_ = 0;
601 bool sampler_overflow_ = false;
602
603 uint32_t available_vertex_id_ = ~uint32_t(0u);
604 bool vertex_id_overflow_ = false;
605
606 Set<std::string> visited_infos;
607
608 void reserve_slots_recursive(const gpu::shader::ShaderCreateInfo &info,
610 const gpu::shader::ShaderCreateInfo::Conditions &info_conditions,
611 bool is_gpumat_info = true)
612 {
613 using namespace blender::gpu::shader;
614 /* The same info can be included with different conditions. */
615 if (!info_conditions.is_empty() && info_conditions.evaluate(constants) == false) {
616 return;
617 }
618
619 if (!visited_infos.add_overwrite(info.name_)) {
620 /* Avoid infinite recursion or visiting an info more than once. */
621 return;
622 }
623
624 auto is_used = [&](const ShaderCreateInfo::Resource &res) {
625 ShaderCreateInfo::Conditions conditions = res.conditions;
626 conditions.extend(info_conditions);
627 return conditions.evaluate(constants);
628 };
629
630 for (const ShaderCreateInfo::VertIn &vert_in : info.vertex_inputs_) {
631 available_vertex_id_ &= ~(uint32_t(1) << vert_in.index);
632 }
633 for (const ShaderCreateInfo::Resource &res : info.pass_resources_) {
634 if (res.bind_type == ShaderCreateInfo::Resource::SAMPLER && is_used(res)) {
636 }
637 }
638 for (const ShaderCreateInfo::Resource &res : info.geometry_resources_) {
639 if (res.bind_type == ShaderCreateInfo::Resource::SAMPLER && is_used(res)) {
641 }
642 }
643 if (!is_gpumat_info) {
644 /* Don't assign slots for material textures until all the internal engine slots are reserved,
645 * they may overlap with our internal slots. */
646 for (const ShaderCreateInfo::Resource &res : info.batch_resources_) {
647 if (res.bind_type == ShaderCreateInfo::Resource::SAMPLER && is_used(res)) {
649 }
650 }
651 }
652
653 for (const auto &additional_info : info.additional_infos_) {
654 const ShaderCreateInfo &other_info = *reinterpret_cast<const ShaderCreateInfo *>(
655 GPU_shader_create_info_get(additional_info.name.c_str()));
656
657 ShaderCreateInfo::Conditions conditions = additional_info.conditions;
658 /* Combine the condition on the current info onto its additional infos. */
659 conditions.extend(info_conditions);
660
662 reserve_slots_recursive(other_info, constants, conditions, false);
663 }
664 }
665
666 public:
668 {
669 /* NOTE: Passing info.compilation_constants_ directly assumes that *all* compilation constant
670 * that are set are set on the base info and not inside its additional infos. This is valid
671 * currently because we do not use the create info from any pipeline declaration and declare
672 * all constants inside this file. */
673 reserve_slots_recursive(info, info.compilation_constants_, {});
674 }
675
676 /* Must be called before #get_next_sampler, which relies on the count matching the used slots
677 * once all of them are taken. */
678 void reserve_sampler_slot(int slot)
679 {
680 available_samplers_ &= ~(uint32_t(1) << slot);
681 total_requested_samplers_ = count_bits_i(~available_samplers_);
682 }
683
684 bool sampler_overflow() const
685 {
686 return sampler_overflow_;
687 }
688
690 {
691 return total_requested_samplers_;
692 }
693
695 {
696 return vertex_id_overflow_;
697 }
698
700 {
701 int next_sampler = available_samplers_ == 0 ? total_requested_samplers_ :
702 bitscan_forward_clear_uint(&available_samplers_);
703 total_requested_samplers_++;
704 if (next_sampler >= GPU_max_textures()) {
705 /* Should result in compilation failure. */
706 sampler_overflow_ = true;
707 return -1;
708 }
709
710 return next_sampler;
711 }
712
714 {
715 uint32_t bit = uint32_t(1) << index;
716 if ((available_vertex_id_ & bit) == 0) {
717 /* Should result in compilation failure. */
718 vertex_id_overflow_ = true;
719 }
720 available_vertex_id_ &= ~bit;
721 }
722};
723
725 eMaterialPipeline pipeline_type,
726 eMaterialGeometry geometry_type,
727 const bool use_shader_to_rgba,
728 const bool use_lighting_nodes,
729 const bool use_ao_node,
730 const bool use_raycast,
731 const bool use_additional_data)
732{
733 using namespace blender::gpu::shader;
734 using gpu::shader::Type;
735
736 const bool is_hybrid = pipeline_type == MAT_PIPE_DEFERRED &&
737 (use_shader_to_rgba || use_lighting_nodes);
738
739 info.compilation_constant(Type::bool_t, "is_mesh", geometry_type == MAT_GEOM_MESH);
740 info.compilation_constant(Type::bool_t, "is_curves", geometry_type == MAT_GEOM_CURVES);
741 info.compilation_constant(Type::bool_t, "is_pointcloud", geometry_type == MAT_GEOM_POINTCLOUD);
742 info.compilation_constant(Type::bool_t, "is_gsplat", geometry_type == MAT_GEOM_GSPLAT);
743 info.compilation_constant(Type::bool_t, "is_world", geometry_type == MAT_GEOM_WORLD);
744
745 info.compilation_constant(Type::bool_t, "is_volume_object", geometry_type == MAT_GEOM_VOLUME);
746
748 Type::bool_t, "is_volume_pipe", pipeline_type == MAT_PIPE_VOLUME_MATERIAL);
749 info.compilation_constant(Type::bool_t, "is_shadow_pipe", pipeline_type == MAT_PIPE_SHADOW);
750 info.compilation_constant(Type::bool_t, "is_capture_pipe", pipeline_type == MAT_PIPE_CAPTURE);
751 if (pipeline_type == MAT_PIPE_SHADOW) {
752 info.compilation_constant(Type::bool_t, "use_multi_viewport", GPU_multi_viewport_support());
753 }
755 Type::bool_t, "is_occupancy_pipe", pipeline_type == MAT_PIPE_VOLUME_OCCUPANCY);
757 Type::bool_t, "use_clip_plane", pipeline_type == MAT_PIPE_PREPASS_PLANAR);
758 info.compilation_constant(Type::bool_t, "use_ambient_occlusion", use_ao_node);
760 "use_forward_lighting",
761 (pipeline_type == MAT_PIPE_FORWARD) ||
762 ((pipeline_type == MAT_PIPE_DEFERRED) && use_shader_to_rgba));
763 info.compilation_constant(Type::bool_t, "use_raycast", use_raycast);
764 info.compilation_constant(Type::bool_t, "use_additional_data", use_additional_data);
765
766 StringRefNull pipeline_info_name;
767 /* Pipeline Info. */
768 switch (geometry_type) {
769 case MAT_GEOM_WORLD:
770 switch (pipeline_type) {
772 pipeline_info_name = "eevee_surf_volume_infos_";
773 info.name_ += "_world_volume";
774 info.compilation_constant(Type::bool_t, "is_homogenous", false); /* TODO? */
775 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
776 * pipeline. */
777 info.fragment_source("eevee_surf_volume.bsl.hh");
778 info.fragment_function("eevee_surf_volume");
779 break;
780 default:
781 pipeline_info_name = "eevee_surf_world_infos_";
782 info.name_ += "_world";
783 info.define("closure_to_rgba", "closure_to_rgba_world");
784 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
785 * pipeline. */
786 info.fragment_source("eevee_surf_world.bsl.hh");
787 info.fragment_function("eevee_surf_world");
788 break;
789 }
790 break;
791 default:
792 switch (pipeline_type) {
795 pipeline_info_name = "eevee_surf_depthTtrue_infos_";
796 info.name_ += "_depth_velocity";
797 info.compilation_constant(Type::bool_t, "use_velocity", true);
798 info.define("closure_to_rgba", "closure_to_rgba_depth");
799 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
800 * pipeline. */
801 info.fragment_source("eevee_surf_depth.bsl.hh");
802 info.fragment_function("eevee_surf_depthTtrue");
803 break;
807 pipeline_info_name = "eevee_surf_depthTfalse_infos_";
808 info.name_ += "_depth";
809 info.compilation_constant(Type::bool_t, "use_velocity", false);
810 info.compilation_constant(Type::bool_t, "use_lighting_nodes", false);
811 info.define("closure_to_rgba", "closure_to_rgba_depth");
812 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
813 * pipeline. */
814 info.fragment_source("eevee_surf_depth.bsl.hh");
815 info.fragment_function("eevee_surf_depthTfalse");
816 break;
818 pipeline_info_name = "eevee_surf_depthTfalse_infos_";
819 info.name_ += "_depth_clip";
820 info.compilation_constant(Type::bool_t, "use_velocity", false);
821 info.compilation_constant(Type::bool_t, "use_lighting_nodes", false);
822 info.define("closure_to_rgba", "closure_to_rgba_depth");
823 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
824 * pipeline. */
825 info.fragment_source("eevee_surf_depth.bsl.hh");
826 info.fragment_function("eevee_surf_depthTfalse");
827 break;
828 case MAT_PIPE_SHADOW:
829 pipeline_info_name = "eevee_surf_shadow_infos_";
830 info.name_ += "_shadow";
831 info.compilation_constant(Type::bool_t, "use_velocity", false);
832 info.compilation_constant(Type::bool_t, "use_lighting_nodes", false);
833 info.define("DRW_VIEW_LEN", STRINGIFY(SHADOW_VIEW_MAX));
834 info.define("closure_to_rgba", "closure_to_rgba_shadow");
835 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
836 * pipeline. */
837 info.fragment_source("eevee_surf_shadow.bsl.hh");
838 info.fragment_function("eevee_surf_shadow");
839 break;
841 pipeline_info_name = "eevee_surf_occupancy_infos_";
842 info.name_ += "_occupancy";
843 info.compilation_constant(Type::bool_t, "use_velocity", false);
844 info.compilation_constant(Type::bool_t, "use_lighting_nodes", false);
845 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
846 * pipeline. */
847 info.fragment_source("eevee_surf_occupancy.bsl.hh");
848 info.fragment_function("eevee_surf_occupancy");
849 break;
851 pipeline_info_name = "eevee_surf_volume_infos_";
852 info.compilation_constant(Type::bool_t, "use_velocity", false);
853 info.compilation_constant(Type::bool_t, "use_lighting_nodes", false);
854 info.compilation_constant(Type::bool_t, "is_homogenous", false); /* TODO? */
855 info.name_ += "_volume";
856 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
857 * pipeline. */
858 info.fragment_source("eevee_surf_volume.bsl.hh");
859 info.fragment_function("eevee_surf_volume");
860 break;
861 case MAT_PIPE_CAPTURE:
862 pipeline_info_name = "eevee_surf_capture_infos_";
863 info.name_ += "_capture";
864 info.compilation_constant(Type::bool_t, "use_velocity", false);
865 info.compilation_constant(Type::bool_t, "use_lighting_nodes", false);
866 info.define("closure_to_rgba", "closure_to_rgba_capture");
867 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
868 * pipeline. */
869 info.fragment_source("eevee_surf_capture.bsl.hh");
870 info.fragment_function("eevee_surf_capture");
871 break;
873 if (is_hybrid) {
874 pipeline_info_name = "eevee_surf_hybrid_infos_";
875 if (use_shader_to_rgba) {
876 info.define("closure_to_rgba", "closure_to_rgba_hybrid");
877 }
878 info.name_ += "_deferred_hybrid";
879 info.compilation_constant(Type::bool_t, "use_velocity", false);
880 info.compilation_constant(Type::bool_t, "use_lighting_nodes", use_lighting_nodes);
881 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
882 * pipeline. */
883 info.fragment_source("eevee_surf_hybrid.bsl.hh");
884 info.fragment_function("eevee_surf_hybrid");
885 }
886 else {
887 pipeline_info_name = "eevee_surf_deferred_infos_";
888 info.name_ += "_deferred";
889 info.compilation_constant(Type::bool_t, "use_velocity", false);
890 info.compilation_constant(Type::bool_t, "use_lighting_nodes", false);
891 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
892 * pipeline. */
893 info.fragment_source("eevee_surf_deferred.bsl.hh");
894 info.fragment_function("eevee_surf_deferred");
895 }
896 break;
897 case MAT_PIPE_FORWARD:
898 pipeline_info_name = "eevee_surf_forward_infos_";
899 info.define("closure_to_rgba", "closure_to_rgba_forward");
900 info.compilation_constant(Type::bool_t, "use_velocity", false);
902 gpu::shader::Type::bool_t, "use_lighting_nodes", use_lighting_nodes);
903 info.name_ += "_forward";
904 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
905 * pipeline. */
906 info.fragment_source("eevee_surf_forward.bsl.hh");
907 info.fragment_function("eevee_surf_forward");
908 break;
909 default:
911 break;
912 }
913 break;
914 }
915
916 /* Geometry Info. */
917 StringRefNull geometry_info_name;
918 switch (geometry_type) {
919 case MAT_GEOM_WORLD:
920 geometry_info_name = "eevee_geom_world_infos_";
921 info.name_ += "_world";
922 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
923 * pipeline. */
924 info.vertex_source("eevee_geom_world.bsl.hh");
925 info.vertex_function("eevee_geom_world");
926 break;
927 case MAT_GEOM_CURVES:
928 geometry_info_name = "eevee_geom_curves_infos_";
929 info.name_ += "_curves";
930 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
931 * pipeline. */
932 info.vertex_source("eevee_geom_curves.bsl.hh");
933 info.vertex_function("eevee_geom_curves");
934 break;
935 case MAT_GEOM_GSPLAT:
936 geometry_info_name = "eevee_geom_gsplat_infos_";
937 info.name_ += "_gsplat";
938 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
939 * pipeline. */
940 info.vertex_source("eevee_geom_gsplat.bsl.hh");
941 info.vertex_function("eevee_geom_gsplat");
942 break;
943 case MAT_GEOM_MESH:
944 geometry_info_name = "eevee_geom_mesh_infos_";
945 info.name_ += "_mesh";
946 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
947 * pipeline. */
948 info.vertex_source("eevee_geom_mesh.bsl.hh");
949 info.vertex_function("eevee_geom_mesh");
950 break;
952 geometry_info_name = "eevee_geom_pointcloud_infos_";
953 info.name_ += "_pointcloud";
954 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
955 * pipeline. */
956 info.vertex_source("eevee_geom_pointcloud.bsl.hh");
957 info.vertex_function("eevee_geom_pointcloud");
958 break;
959 case MAT_GEOM_VOLUME:
960 geometry_info_name = "eevee_geom_volume_infos_";
961 info.name_ += "_volume";
962 /* Until every vertex shader are ported, we need to bridge the gap here by defining the
963 * pipeline. */
964 info.vertex_source("eevee_geom_volume.bsl.hh");
965 info.vertex_function("eevee_geom_volume");
966 break;
967 }
968
970 gpu::shader::Type::bool_t, "use_aov_output", pipeline_type == MAT_PIPE_DEFERRED);
971
972 if (!pipeline_info_name.is_empty()) {
973 info.additional_info(pipeline_info_name);
974 }
975 if (!geometry_info_name.is_empty()) {
976 info.additional_info(geometry_info_name);
977 }
978 SlotAllocator available_slots;
979 available_slots.reserve_slots(info);
980
981 if (ELEM(pipeline_type, MAT_PIPE_DEFERRED, MAT_PIPE_FORWARD) &&
982 !ELEM(geometry_type, MAT_GEOM_WORLD, MAT_GEOM_VOLUME))
983 {
984 /* While only needed for the AO node, we always bind the hiz globally for these pipelines.
985 * To ensure no user textures will reuse the slot binding, we add the info unconditionally. */
986 available_slots.reserve_sampler_slot(HIZ_TEX_SLOT);
987 }
988 if (is_hybrid) {
989 /* WORKAROUND(fclem): These resources are bound once per hybrid sub-pass rather than per
990 * material, so their slots must not be reused by material textures, even for materials that
991 * don't use them. */
994 }
995
996 /* Iterate over user samplers and request their slots. */
997 for (auto &resource : info.batch_resources_) {
999 /* Assign non overlapping slots for material textures. */
1000 resource.slot = available_slots.get_next_sampler();
1001 }
1002 }
1003 return available_slots;
1004}
1005
1007{
1008 using namespace blender::gpu::shader;
1009
1010 uint64_t shader_uuid = GPU_material_uuid_get(gpumat);
1011 const bool use_shader_to_rgba = GPU_material_flag_get(gpumat, GPU_MATFLAG_SHADER_TO_RGBA);
1012 const bool use_lighting_nodes = GPU_material_flag_get(gpumat, GPU_MATFLAG_LIGHTING);
1013
1014 eMaterialPipeline pipeline_type;
1015 eMaterialGeometry geometry_type;
1016 eMaterialDisplacement displacement_type;
1017 eMaterialThickness thickness_type;
1018 bool transparent_shadows;
1019 material_type_from_shader_uuid(shader_uuid,
1020 pipeline_type,
1021 geometry_type,
1022 displacement_type,
1023 thickness_type,
1024 transparent_shadows);
1025
1026 GPUCodegenOutput &codegen = *codegen_;
1027 ShaderCreateInfo &info = *reinterpret_cast<ShaderCreateInfo *>(codegen.create_info);
1028
1029 /* WORKAROUND: Add new ob attr buffer. */
1030 if (GPU_material_uniform_attributes(gpumat) != nullptr ||
1032 {
1033 /* Search and remove the old object attribute UBO which would creating bind point collision. */
1034 for (auto &resource_info : info.batch_resources_) {
1035 if (resource_info.bind_type == ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER &&
1036 resource_info.uniformbuf.name == GPU_ATTRIBUTE_UBO_BLOCK_NAME "[512]")
1037 {
1038 info.batch_resources_.remove_first_occurrence_and_reorder(resource_info);
1039 break;
1040 }
1041 }
1042 /* Remove references to the UBO. */
1043 info.define("UNI_ATTR(a)", "float4(0.0)");
1044 }
1045
1046 /* WORKAROUND: Remove nodetree decl from the codegen. It is already defined in BSL. */
1047 {
1048 for (auto &resource_info : info.batch_resources_) {
1049 if (resource_info.bind_type == ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER &&
1050 resource_info.uniformbuf.name == GPU_UBO_BLOCK_NAME)
1051 {
1052 info.batch_resources_.remove_first_occurrence_and_reorder(resource_info);
1053 break;
1054 }
1055 }
1056 }
1057
1058 bool use_ao_node = (GPU_material_flag_get(gpumat, GPU_MATFLAG_AO) &&
1059 ELEM(pipeline_type, MAT_PIPE_FORWARD, MAT_PIPE_DEFERRED) &&
1060 geometry_type_has_surface(geometry_type));
1061
1062 bool use_transparency = false;
1063 if (GPU_material_flag_get(gpumat, GPU_MATFLAG_TRANSPARENT) || geometry_type == MAT_GEOM_GSPLAT) {
1064 if (pipeline_type != MAT_PIPE_SHADOW || transparent_shadows) {
1065 use_transparency = true;
1066 }
1067 /* Transparent material do not have any velocity specific pipeline. */
1068 if (pipeline_type == MAT_PIPE_PREPASS_FORWARD_VELOCITY) {
1069 pipeline_type = MAT_PIPE_PREPASS_FORWARD;
1070 }
1071 }
1072 info.compilation_constant(gpu::shader::Type::bool_t, "use_transparency", use_transparency);
1073
1074 const bool use_raycast = (GPU_material_flag_get(gpumat, GPU_MATFLAG_RAYCAST) &&
1075 ELEM(pipeline_type, MAT_PIPE_DEFERRED, MAT_PIPE_FORWARD));
1076
1077 const bool use_additional_data = GPU_material_flag_get(gpumat, GPU_MATFLAG_REFRACT) ||
1080
1081 /* Copy vertex inputs. They can be transferred into other type of resources.
1082 * We add them back after we get the SlotAllocator. */
1083 auto vertex_inputs = info.vertex_inputs_;
1084 info.vertex_inputs_.clear();
1085
1086 using gpuType = gpu::shader::Type;
1088 gpuType::bool_t, "use_diffuse", GPU_material_flag_get(gpumat, GPU_MATFLAG_DIFFUSE));
1090 gpuType::bool_t, "use_refraction", GPU_material_flag_get(gpumat, GPU_MATFLAG_REFRACT));
1092 gpuType::bool_t, "use_translucent", GPU_material_flag_get(gpumat, GPU_MATFLAG_TRANSLUCENT));
1094 gpuType::bool_t, "use_reflection", GPU_material_flag_get(gpumat, GPU_MATFLAG_GLOSSY));
1096 gpuType::bool_t, "use_clearcoat", GPU_material_flag_get(gpumat, GPU_MATFLAG_COAT));
1098 gpuType::bool_t, "use_sss", GPU_material_flag_get(gpumat, GPU_MATFLAG_SUBSURFACE));
1099
1100 const eClosureBits closure_bits = shader_closure_bits_from_flag(gpumat);
1101
1102 int32_t closure_bin_count = to_gbuffer_bin_count(closure_bits);
1103 info.compilation_constant(gpu::shader::Type::int_t, "closure_bin_count", closure_bin_count);
1105 gpu::shader::Type::int_t, "closure_bin_len", max(1, closure_bin_count));
1106
1107 if (pipeline_type == MAT_PIPE_DEFERRED) {
1109 "gbuffer_has_reflection",
1112 "gbuffer_has_refraction",
1115 "gbuffer_has_subsurface",
1118 "gbuffer_has_translucent",
1120
1123 "gbuffer_reflection_colorless",
1127 "gbuffer_refraction_colorless",
1129
1131 gpu::shader::Type::int_t, "gbuffer_layer_max", max(1, closure_bin_count));
1132
1133 bool use_simple_layout = false;
1134 if (closure_bin_count == 2) {
1135 /* In a lot of cases, we can predict that we do not need the extra GBuffer layers. This
1136 * simplifies the shader code and improves compilation time (see #145347). */
1137 const bool colorless_reflection = !GPU_material_flag_get(
1139 const bool colorless_refraction = !GPU_material_flag_get(
1141 int closure_layer_count = 0;
1142 if (closure_bits & CLOSURE_DIFFUSE) {
1143 closure_layer_count += 1;
1144 }
1145 if (closure_bits & CLOSURE_SSS) {
1146 closure_layer_count += 2;
1147 }
1148 if (closure_bits & CLOSURE_REFLECTION) {
1149 closure_layer_count += colorless_reflection ? 1 : 2;
1150 }
1151 if (closure_bits & CLOSURE_REFRACTION) {
1152 closure_layer_count += colorless_refraction ? 1 : 2;
1153 }
1154 if (closure_bits & CLOSURE_TRANSLUCENT) {
1155 closure_layer_count += 1;
1156 }
1157 if (closure_bits & CLOSURE_CLEARCOAT) {
1158 closure_layer_count += colorless_reflection ? 1 : 2;
1159 }
1160
1161 if (closure_layer_count <= 2) {
1162 use_simple_layout = true;
1163 }
1164 }
1165
1167 gpu::shader::Type::bool_t, "gbuffer_simple_layout", use_simple_layout);
1168 }
1169
1170 int transmit_eval_count = 0;
1171 if ((pipeline_type == MAT_PIPE_FORWARD) || use_shader_to_rgba || use_lighting_nodes) {
1172 transmit_eval_count = (closure_bits &
1174 1 :
1175 0;
1177 gpu::shader::Type::int_t, "light_closure_eval_count_reflect", closure_bin_count);
1179 gpu::shader::Type::int_t, "light_closure_eval_count_transmit", transmit_eval_count);
1180 info.compilation_constant(gpu::shader::Type::bool_t, "shadow_random", true);
1181 }
1182
1183 /* Always need to be defined. */
1185 gpu::shader::Type::int_t, "light_closure_count_reflect", max(1, closure_bin_count));
1187 gpu::shader::Type::int_t, "light_closure_count_transmit", max(1, transmit_eval_count));
1188
1189 /* Enabling barycentric coordinate only works for triangle primitives. */
1190 bool use_barycentric = GPU_material_flag_get(gpumat, GPU_MATFLAG_BARYCENTRIC) &&
1191 geometry_type == MAT_GEOM_MESH;
1192 info.compilation_constant(gpu::shader::Type::bool_t, "use_barycentric", use_barycentric);
1193
1194 /* Allow to use Reverse-Z on OpenGL. Does nothing in other backend. */
1196
1197 /* IMPORTANT: All additional_info containing resources should go before
1198 * add_pipeline_create_info. This ensure all resource slot are correctly reserved inside the
1199 * SlotAllocator.
1200 * Similarly all compilation_constant setting needs to happen before this point. */
1201
1203 pipeline_type,
1204 geometry_type,
1205 use_shader_to_rgba,
1206 use_lighting_nodes,
1207 use_ao_node,
1208 use_raycast,
1209 use_additional_data);
1210
1211 std::stringstream global_vars;
1212 switch (geometry_type) {
1213 case MAT_GEOM_MESH:
1214 if (pipeline_type == MAT_PIPE_VOLUME_MATERIAL) {
1215 /* If mesh has a volume output, it can receive volume grid attributes from smoke
1216 * simulation modifier. But the vertex shader might still need access to the vertex
1217 * attribute for displacement. */
1218 /* TODO(fclem): Eventually, we could add support for loading both. For now, remove the
1219 * vertex inputs after conversion (avoid name collision). */
1220 for (auto &input : vertex_inputs) {
1221 info.sampler(slots.get_next_sampler(), ImageType::Float3D, input.name, Frequency::BATCH);
1222 }
1223 vertex_inputs.clear();
1224 /* Volume materials require these for loading the grid attributes from smoke sims. */
1225 info.additional_info("draw_volume_infos");
1226 }
1227 break;
1229 /* Fall through to the curves case. */
1231 case MAT_GEOM_GSPLAT:
1232 /* Fall through to the curves case. */
1234 case MAT_GEOM_CURVES:
1236 for (auto &input : vertex_inputs) {
1237 if (input.name == "orco") {
1239 global_vars << input.type << " " << input.name << ";\n";
1240 }
1241 else {
1242 info.sampler(
1243 slots.get_next_sampler(), ImageType::FloatBuffer, input.name, Frequency::BATCH);
1244 }
1245 }
1246 vertex_inputs.clear();
1247 break;
1248 case MAT_GEOM_WORLD:
1249 if (pipeline_type == MAT_PIPE_VOLUME_MATERIAL) {
1250 /* Even if world do not have grid attributes, we use dummy texture binds to pass correct
1251 * defaults. So we have to replace all attributes as samplers. */
1252 for (auto &input : vertex_inputs) {
1253 info.sampler(slots.get_next_sampler(), ImageType::Float3D, input.name, Frequency::BATCH);
1254 }
1255 vertex_inputs.clear();
1256 }
1261 for (auto &input : vertex_inputs) {
1262 global_vars << input.type << " " << input.name << ";\n";
1263 }
1264 vertex_inputs.clear();
1265 break;
1266 case MAT_GEOM_VOLUME:
1268 for (auto &input : vertex_inputs) {
1269 info.sampler(slots.get_next_sampler(), ImageType::Float3D, input.name, Frequency::BATCH);
1270 }
1271 vertex_inputs.clear();
1272 break;
1273 }
1274
1275 for (auto &vert_in : vertex_inputs) {
1276 slots.set_vertex_input(vert_in.index);
1277 info.vertex_in(vert_in.index, vert_in.type, vert_in.name);
1278 }
1279
1280 const bool support_volume_attributes = ELEM(geometry_type, MAT_GEOM_MESH, MAT_GEOM_VOLUME);
1281 const bool do_vertex_attrib_load = !ELEM(geometry_type, MAT_GEOM_WORLD, MAT_GEOM_VOLUME) &&
1282 (pipeline_type != MAT_PIPE_VOLUME_MATERIAL ||
1283 !support_volume_attributes);
1284
1285 if (!do_vertex_attrib_load && !info.vertex_out_interfaces_.is_empty()) {
1286 /* Codegen outputs only one interface. */
1287 const StageInterfaceInfo &iface = *info.vertex_out_interfaces_.first().iface;
1288 /* Globals the attrib_load() can write to when it is in the fragment shader. */
1289 global_vars << "struct " << iface.name << " {\n";
1290 for (const auto &inout : iface.inouts) {
1291 global_vars << " " << inout.type << " " << inout.name << ";\n";
1292 }
1293 global_vars << "};\n";
1294 global_vars << iface.name << " " << iface.instance_name << ";\n";
1295
1296 info.vertex_out_interfaces_.clear();
1297 }
1298
1299 const char *domain_type_frag = "";
1300 const char *domain_type_vert = "";
1301 switch (geometry_type) {
1302 case MAT_GEOM_MESH:
1303 domain_type_frag = (pipeline_type == MAT_PIPE_VOLUME_MATERIAL) ? "VolumePoint" :
1304 "MeshVertex";
1305 domain_type_vert = "MeshVertex";
1306 break;
1307 case MAT_GEOM_GSPLAT:
1308 /* Fall through to point-clouds, reuse their attribute domain. */
1311 domain_type_frag = (pipeline_type == MAT_PIPE_VOLUME_MATERIAL) ? "VolumePoint" :
1312 "PointCloudPoint";
1313 domain_type_vert = "PointCloudPoint";
1314 break;
1315 case MAT_GEOM_CURVES:
1316 domain_type_frag = (pipeline_type == MAT_PIPE_VOLUME_MATERIAL) ? "VolumePoint" :
1317 "CurvesPoint";
1318 domain_type_vert = "CurvesPoint";
1319 break;
1320 case MAT_GEOM_WORLD:
1321 domain_type_frag = (pipeline_type == MAT_PIPE_VOLUME_MATERIAL) ? "VolumePoint" :
1322 "WorldPoint";
1323 domain_type_vert = "WorldPoint";
1324 break;
1325 case MAT_GEOM_VOLUME:
1326 domain_type_frag = domain_type_vert = "VolumePoint";
1327 break;
1328 }
1329
1330 std::stringstream attr_load;
1331 attr_load << "{\n";
1332 attr_load << (!codegen.attr_load.empty() ? codegen.attr_load : "");
1333 attr_load << "}\n\n";
1334
1335 std::stringstream vert_gen, frag_gen;
1336
1337 if (do_vertex_attrib_load) {
1338 vert_gen << global_vars.str() << "void attrib_load(" << domain_type_vert << " domain)"
1339 << attr_load.str();
1340 frag_gen << "void attrib_load(" << domain_type_frag << " domain) {}\n"; /* Placeholder. */
1341 }
1342 else {
1343 vert_gen << "void attrib_load(" << domain_type_vert << " domain) {}\n"; /* Placeholder. */
1344 frag_gen << global_vars.str() << "void attrib_load(" << domain_type_frag << " domain)"
1345 << attr_load.str();
1346 }
1347
1348 /* Bit of a workaround. Make sure that the nodetree UBO is part of the eevee_node_tree
1349 * interface and not the interface with the shader name. */
1350 for (auto &res : info.batch_resources_) {
1351 res.info_name = "eevee_node_tree";
1352 }
1353 for (auto &res : info.pass_resources_) {
1354 res.info_name = "eevee_node_tree";
1355 }
1356 for (auto &res : info.geometry_resources_) {
1357 res.info_name = "eevee_node_tree";
1358 }
1359
1360 std::string generated_resource_header = info.typedef_source_generated;
1361 /* Insert resource declaration after types declaration. */
1362 generated_resource_header += "#ifdef CREATE_INFO_RES_PASS_eevee_node_tree\n";
1363 generated_resource_header += "CREATE_INFO_RES_PASS_eevee_node_tree\n";
1364 generated_resource_header += "#endif\n";
1365 generated_resource_header += "#ifdef CREATE_INFO_RES_BATCH_eevee_node_tree\n";
1366 generated_resource_header += "CREATE_INFO_RES_BATCH_eevee_node_tree\n";
1367 generated_resource_header += "#endif\n";
1368 generated_resource_header += "#ifdef CREATE_INFO_RES_GEOMETRY_eevee_node_tree\n";
1369 generated_resource_header += "CREATE_INFO_RES_GEOMETRY_eevee_node_tree\n";
1370 generated_resource_header += "#endif\n";
1371 generated_resource_header += "\n";
1372
1373 info.generated_sources.append({"eevee_nodetree_type.bsl.hh", {}, generated_resource_header});
1374 info.generated_sources.append({"gpu_shader_material_interface.bsl.hh", {}, ""});
1375
1376 {
1377 const bool use_vertex_displacement = !codegen.displacement.empty() &&
1378 (displacement_type != MAT_DISPLACEMENT_BUMP) &&
1379 !ELEM(geometry_type, MAT_GEOM_WORLD, MAT_GEOM_VOLUME);
1380
1381 Vector<StringRefNull> dependencies = {};
1382 /* Needed for KernelGlobals and ShadingData. */
1383 dependencies.append("eevee_nodetree_lib.bsl.hh");
1384
1385 if (use_vertex_displacement) {
1386 for (const auto &graph : codegen.material_functions) {
1387 vert_gen << graph.serialized;
1388 dependencies.extend(graph.dependencies);
1389 }
1390 }
1391
1392 vert_gen << "#line 1 \"" __FILE__ "\"\n";
1393 vert_gen << "#line " STRINGIFY(__LINE__) "\n";
1394 vert_gen << "float3 nodetree_displacement(KernelGlobals kg, _ref(ShadingData, sd))\n";
1395 vert_gen << "{\n";
1396 vert_gen << ((use_vertex_displacement) ? codegen.displacement.serialized :
1397 "return float3(0);\n");
1398 vert_gen << "}\n\n";
1399
1400 if (use_vertex_displacement) {
1401 dependencies.append("eevee_geom_types_lib.bsl.hh");
1402 dependencies.extend(codegen.displacement.dependencies);
1403 }
1404
1405 info.generated_sources.append(
1406 {"eevee_nodetree_vert_lib.bsl.hh", dependencies, vert_gen.str()});
1407 }
1408
1409 if (pipeline_type != MAT_PIPE_VOLUME_OCCUPANCY) {
1410 Vector<StringRefNull> dependencies;
1411 dependencies.append("eevee_nodetree_type.bsl.hh");
1412 dependencies.append("eevee_geom_types_lib.bsl.hh");
1413 dependencies.append("eevee_nodetree_lib.bsl.hh");
1414
1415 for (const auto &graph : codegen.material_functions) {
1416 frag_gen << graph.serialized;
1417 dependencies.extend(graph.dependencies);
1418 }
1419
1420 if (!codegen.displacement.empty()) {
1421 /* Bump displacement. Needed to recompute normals after displacement. */
1422 info.define("MAT_DISPLACEMENT_BUMP");
1423
1424 frag_gen << "#line 1 \"" __FILE__ "\"\n";
1425 frag_gen << "#line " STRINGIFY(__LINE__) "\n";
1426 frag_gen << "float3 nodetree_displacement(KernelGlobals kg, _ref(ShadingData, sd))\n";
1427 frag_gen << "{\n";
1428 frag_gen << codegen.displacement.serialized;
1429 dependencies.extend(codegen.displacement.dependencies);
1430 frag_gen << "}\n\n";
1431 }
1432
1433 /* Improve error logging. */
1434 frag_gen << "#line 1 \"" __FILE__ "\"\n";
1435 frag_gen << "#line " STRINGIFY(__LINE__) "\n";
1436
1437 frag_gen << "Closure nodetree_surface(KernelGlobals kg, _ref(ShadingData, sd), float "
1438 "closure_rand)\n";
1439 frag_gen << "{\n";
1440 frag_gen << " closure_weights_reset(kg, sd, closure_rand);\n";
1441 frag_gen << codegen.surface.serialized_or_default("return Closure(0);\n");
1442 dependencies.extend(codegen.surface.dependencies);
1443 frag_gen << "}\n\n";
1444
1445 frag_gen << "float nodetree_thickness(KernelGlobals kg, _ref(ShadingData, sd))\n";
1446 frag_gen << "{\n";
1447 if (codegen.thickness.empty()) {
1448 /* Check presence of closure needing thickness to not add mandatory dependency on obinfos. */
1451 {
1452 frag_gen << "return 0.0;\n";
1453 }
1454 else {
1455 /* TODO(fclem): Should use `to_scale` but the gpu_shader_math_matrix_lib.glsl isn't
1456 * included everywhere yet. */
1457 frag_gen << "ObjectMatrices obj = _object_matrices_get(kg, sd);\n";
1458 frag_gen << "float3 ob_scale;\n";
1459 frag_gen << "ob_scale.x = length(obj.model[0].xyz);\n";
1460 frag_gen << "ob_scale.y = length(obj.model[1].xyz);\n";
1461 frag_gen << "ob_scale.z = length(obj.model[2].xyz);\n";
1462 frag_gen << "ObjectInfos infos = _object_infos_get(kg, sd);\n";
1463 frag_gen << "float3 ls_dimensions = safe_rcp(abs(infos.orco_mul.xyz));\n";
1464 frag_gen << "float3 ws_dimensions = ob_scale * ls_dimensions;\n";
1465 /* Choose the minimum axis so that cuboids are better represented. */
1466 frag_gen << "return reduce_min(ws_dimensions);\n";
1467 }
1468 }
1469 else {
1470 frag_gen << codegen.thickness.serialized;
1471 dependencies.extend(codegen.thickness.dependencies);
1472 }
1473 frag_gen << "}\n\n";
1474
1475 frag_gen << "Closure nodetree_volume(KernelGlobals kg, _ref(ShadingData, sd))\n";
1476 frag_gen << "{\n";
1477 frag_gen << " closure_weights_reset(kg, sd, 0.0);\n";
1478 frag_gen << codegen.volume.serialized_or_default("return Closure(0);\n");
1479 dependencies.extend(codegen.volume.dependencies);
1480 frag_gen << "}\n\n";
1481
1482 info.generated_sources.append(
1483 {"eevee_nodetree_frag_lib.bsl.hh", dependencies, frag_gen.str()});
1484 }
1485
1486 const char *material_name = (info.name_.c_str() + 2);
1487 /* Make shaders that have as too many attributes fail compilation and have correct error
1488 * report instead of raising an error. */
1489 if (slots.vertex_id_overflow()) {
1490 std::cerr << "Error: EEVEE: Material " << material_name << " uses too many attributes."
1491 << std::endl;
1492 /* Avoid assert in ShaderCreateInfo::finalize. */
1493 info.vertex_inputs_.clear();
1494 }
1495 /* Make shaders that have as too many samplers fail compilation and have correct error
1496 * report instead of raising an error. */
1497 if (slots.sampler_overflow()) {
1498 /* We ran out of binding slots. */
1499 std::cerr << fmt::format("Error: EEVEE: Material {} uses too many samplers. ({}/{})",
1500 material_name,
1503 << std::endl;
1504 /* Avoid assert in ShaderCreateInfo::finalize. */
1505 info.batch_resources_.clear();
1506 }
1507
1508 material_create_info_pipelines_amend(geometry_type, pipeline_type, info);
1509}
1510
1515
1516/* WATCH: This can be called from another thread! Needs to not touch the shader module in any
1517 * thread unsafe manner. */
1518static void codegen_callback(void *void_thunk, GPUMaterial *mat, GPUCodegenOutput *codegen)
1519{
1520 CallbackThunk *thunk = static_cast<CallbackThunk *>(void_thunk);
1521 thunk->shader_module->material_create_info_amend(mat, codegen);
1522}
1523
1524static GPUPass *pass_replacement_cb(void *void_thunk, GPUMaterial *mat)
1525{
1526 using namespace blender::gpu::shader;
1527
1528 CallbackThunk *thunk = static_cast<CallbackThunk *>(void_thunk);
1529
1530 const blender::Material *blender_mat = GPU_material_get_material(mat);
1531
1532 uint64_t shader_uuid = GPU_material_uuid_get(mat);
1533
1534 eMaterialPipeline pipeline_type;
1535 eMaterialGeometry geometry_type;
1536 eMaterialDisplacement displacement_type;
1537 eMaterialThickness thickness_type;
1538 bool transparent_shadows;
1539 material_type_from_shader_uuid(shader_uuid,
1540 pipeline_type,
1541 geometry_type,
1542 displacement_type,
1543 thickness_type,
1544 transparent_shadows);
1545
1546 bool is_shadow_pass = pipeline_type == eMaterialPipeline::MAT_PIPE_SHADOW;
1547 bool is_prepass = ELEM(pipeline_type,
1554
1555 bool has_vertex_displacement = GPU_material_has_displacement_output(mat) &&
1557 bool has_transparency = GPU_material_flag_get(mat, GPU_MATFLAG_TRANSPARENT) ||
1558 geometry_type == MAT_GEOM_GSPLAT;
1559 bool has_shadow_transparency = has_transparency && transparent_shadows;
1560 bool has_raytraced_transmission = blender_mat && (blender_mat->blend_flag & MA_BL_SS_REFRACTION);
1561 bool has_raycast = GPU_material_flag_get(mat, GPU_MATFLAG_RAYCAST);
1562
1563 bool can_use_default = (is_shadow_pass &&
1564 (!has_vertex_displacement && !has_shadow_transparency)) ||
1565 (is_prepass && (!has_vertex_displacement && !has_transparency &&
1566 !has_raytraced_transmission && !has_raycast));
1567 if (can_use_default) {
1569 thunk->default_mat->nodetree,
1570 pipeline_type,
1571 geometry_type,
1572 false,
1573 nullptr);
1574 return GPU_material_get_pass(mat);
1575 }
1576
1577 return nullptr;
1578}
1579
1581{
1582 Depsgraph *depsgraph = DRW_context_get()->depsgraph;
1583 if (!depsgraph) {
1584 return;
1585 }
1586 if (!DEG_is_active(depsgraph)) {
1587 return;
1588 }
1589 for (const GPUMaterialFromNodeTreeResult::Error &error : material_from_tree.errors) {
1590 const bNodeTree &tree = error.node->owner_tree();
1591 if (const bNodeTree *tree_orig = DEG_get_original(&tree)) {
1592 std::lock_guard lock(tree_orig->runtime->shader_node_errors_mutex);
1593 tree_orig->runtime->shader_node_errors.lookup_or_add_default(error.node->identifier)
1594 .add({nodes::NodeWarningType(error.type), error.message});
1595 }
1596 }
1597}
1598
1600 bNodeTree *nodetree,
1601 eMaterialPipeline pipeline_type,
1602 eMaterialGeometry geometry_type,
1603 bool deferred_compilation,
1604 blender::Material *default_mat)
1605{
1606 eMaterialDisplacement displacement_type = to_displacement_type(blender_mat->displacement_method);
1607 eMaterialThickness thickness_type = to_thickness_type(blender_mat->thickness_mode);
1608
1609 uint64_t shader_uuid = shader_uuid_from_material_type(
1610 pipeline_type, geometry_type, displacement_type, thickness_type, blender_mat->blend_flag);
1611
1612 /* GSplats require transparency independent of the material type; default material must
1613 * be replaced for e.g. transmittance to be present. */
1614 bool is_default_material = default_mat == nullptr && geometry_type != MAT_GEOM_GSPLAT;
1615 BLI_assert(blender_mat != default_mat);
1616
1617 CallbackThunk thunk = {this, default_mat};
1618
1620 blender_mat,
1621 nodetree,
1622 &blender_mat->gpumaterial,
1623 blender_mat->id.name,
1625 shader_uuid,
1626 deferred_compilation,
1628 &thunk,
1629 is_default_material ? nullptr : pass_replacement_cb);
1630 store_node_tree_errors(material_from_tree);
1631 return material_from_tree.material;
1632}
1633
1635 bNodeTree *nodetree,
1636 eMaterialPipeline pipeline_type,
1637 bool deferred_compilation)
1638{
1639 uint64_t shader_uuid = shader_uuid_from_material_type(pipeline_type, MAT_GEOM_WORLD);
1640
1641 CallbackThunk thunk = {this, nullptr};
1642
1644 nullptr,
1645 nodetree,
1646 &blender_world->gpumaterial,
1647 blender_world->id.name,
1649 shader_uuid,
1650 deferred_compilation,
1652 &thunk);
1653 store_node_tree_errors(material_from_tree);
1654 return material_from_tree.material;
1655}
1656
1658
1659/* -------------------------------------------------------------------- */
1663
1664void ShaderModule::material_create_info_pipelines_amend(eMaterialGeometry geometry_type,
1665 eMaterialPipeline pipeline_type,
1667{
1668 /* Pipeline states to compile during shader compilation. */
1669 if (geometry_type == MAT_GEOM_WORLD) {
1670 switch (pipeline_type) {
1672 /* World Volume Pipeline */
1673 r_info.pipeline_state()
1682 .viewports(1)
1683 .depth_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1684 .stencil_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8);
1685
1686 break;
1687 }
1688
1689 default: {
1690 /* World Pipeline */
1691 r_info.pipeline_state()
1700 .viewports(1)
1701 .color_format(gpu::TextureTargetFormat::SFLOAT_16_16_16_16);
1702
1703 /* Background Pipeline */
1704 r_info.pipeline_state()
1713 .viewports(1)
1714 .depth_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1715 .stencil_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1716 .color_format(gpu::TextureTargetFormat::SFLOAT_16_16_16_16);
1717
1718 break;
1719 }
1720 }
1721
1722 return;
1723 }
1724
1725 /* Determine primitive type base on the geometry type. */
1726 /* TODO: For curves we should use the correct one based on the scene settings. Currently it will
1727 * assume it is set to strip or cylinder. */
1728 constexpr GPUPrimType prim_type = GPU_PRIM_TRIS;
1729
1730 switch (pipeline_type) {
1732 /* DeferredLayer pipeline. */
1733 r_info.pipeline_state()
1734 .primitive(prim_type)
1742 .viewports(1)
1743 .depth_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1744 .stencil_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1745 .color_format(gpu::TextureTargetFormat::SFLOAT_16_16);
1746
1747 /* Deferred probe pipeline */
1748 r_info.pipeline_state()
1749 .primitive(prim_type)
1757 .viewports(1)
1758 .depth_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1759 .stencil_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1760 .color_format(gpu::TextureTargetFormat::SFLOAT_16_16);
1761
1762 break;
1763 }
1764
1766 r_info.pipeline_state()
1767 .primitive(prim_type)
1775 .viewports(1)
1776 .depth_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1777 .stencil_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1778 .color_format(gpu::TextureTargetFormat::SFLOAT_16_16);
1779 break;
1780 }
1781 case MAT_PIPE_DEFERRED: {
1782 r_info.pipeline_state()
1783 .primitive(prim_type)
1791 .viewports(1)
1792 .depth_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1793 .stencil_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1794 .color_format(gpu::TextureTargetFormat::SFLOAT_16_16_16_16)
1795 .color_format(gpu::TextureTargetFormat::UINT_32)
1796 .color_format(gpu::TextureTargetFormat::UNORM_16_16)
1797 .color_format(gpu::TextureTargetFormat::UNORM_10_10_10_2)
1798 .color_format(gpu::TextureTargetFormat::UNORM_10_10_10_2);
1799
1800 /* Planar probe */
1801 r_info.pipeline_state()
1802 .primitive(prim_type)
1810 .viewports(1)
1811 .depth_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH)
1812 .color_format(gpu::TextureTargetFormat::UFLOAT_11_11_10)
1813 .color_format(gpu::TextureTargetFormat::UINT_32)
1814 .color_format(gpu::TextureTargetFormat::UNORM_16_16)
1815 .color_format(gpu::TextureTargetFormat::UNORM_10_10_10_2)
1816 .color_format(gpu::TextureTargetFormat::UNORM_10_10_10_2);
1817
1818 break;
1819 }
1820
1822 r_info.pipeline_state()
1823 .primitive(prim_type)
1831 .viewports(1)
1832 .depth_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1833 .stencil_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1834 .color_format(gpu::TextureTargetFormat::SFLOAT_16_16);
1835 break;
1836 }
1838 r_info.pipeline_state()
1839 .primitive(prim_type)
1847 .viewports(1)
1848 .depth_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1849 .stencil_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1850 .color_format(gpu::TextureTargetFormat::SFLOAT_16_16);
1851 break;
1852 }
1853 case MAT_PIPE_FORWARD: {
1854 r_info.pipeline_state()
1855 .primitive(prim_type)
1863 .viewports(1)
1864 .depth_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1865 .stencil_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1866 .color_format(gpu::TextureTargetFormat::SFLOAT_16_16_16_16);
1867 break;
1868 }
1869
1870 case MAT_PIPE_SHADOW: {
1871 r_info.pipeline_state()
1872 .primitive(prim_type)
1880 .viewports(16);
1881 break;
1882 }
1883
1885 r_info.pipeline_state()
1894 .viewports(1)
1895 .depth_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH)
1896 .color_format(gpu::TextureTargetFormat::UFLOAT_11_11_10)
1897 .color_format(gpu::TextureTargetFormat::UINT_32)
1898 .color_format(gpu::TextureTargetFormat::UNORM_16_16)
1899 .color_format(gpu::TextureTargetFormat::UNORM_10_10_10_2)
1900 .color_format(gpu::TextureTargetFormat::UNORM_10_10_10_2);
1901 break;
1902 }
1903
1905 /* Volume Material Pipeline */
1906 r_info.pipeline_state()
1907 .primitive(prim_type)
1915 .viewports(1)
1916 .depth_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1917 .stencil_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8);
1918
1919 break;
1920 }
1922 /* Volume Occupancy Pipeline */
1923 r_info.pipeline_state()
1924 .primitive(prim_type)
1932 .viewports(1)
1933 .depth_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8)
1934 .stencil_format(gpu::TextureTargetFormat::SFLOAT_32_DEPTH_UINT_8);
1935 break;
1936 }
1937
1938 default:
1939 break;
1940 }
1941}
1942
1944
1945} // namespace blender::eevee
General operations, lookup, etc. for materials.
#define ATTR_FALLTHROUGH
#define GPU_UBO_BLOCK_NAME
#define GPU_ATTRIBUTE_UBO_BLOCK_NAME
volatile int lock
#define BLI_assert_unreachable()
#define STRINGIFY(x)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
btScalar max
constexpr IndexRange()=default
void append(const T &value)
void extend(Span< T > array)
constexpr bool is_empty() const
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)
GPUMaterial * world_shader_get(blender::World *blender_world, bNodeTree *nodetree, eMaterialPipeline pipeline_type, bool deferred_compilation)
void material_create_info_amend(GPUMaterial *mat, GPUCodegenOutput *codegen)
GPUMaterial * material_shader_get(blender::Material *blender_mat, bNodeTree *nodetree, eMaterialPipeline pipeline_type, eMaterialGeometry geometry_type, bool deferred_compilation, blender::Material *default_mat)
gpu::Shader * static_shader_get(eShaderType shader_type)
static ShaderModule * module_get()
void reserve_slots(gpu::shader::ShaderCreateInfo &info)
#define RADIANCE_PREVIOUS_LAYER_TEX_SLOT
#define HIZ_PREVIOUS_LAYER_TEX_SLOT
#define HIZ_TEX_SLOT
#define AS_SPAN(arr)
void set_value(float val, float &outval)
@ 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
static GPUPass * pass_replacement_cb(void *void_thunk, GPUMaterial *mat)
static void store_node_tree_errors(GPUMaterialFromNodeTreeResult &material_from_tree)
static SlotAllocator add_pipeline_create_info(gpu::shader::ShaderCreateInfo &info, eMaterialPipeline pipeline_type, eMaterialGeometry geometry_type, const bool use_shader_to_rgba, const bool use_lighting_nodes, const bool use_ao_node, const bool use_raycast, const bool use_additional_data)
static void codegen_callback(void *void_thunk, GPUMaterial *mat, GPUCodegenOutput *codegen)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ GPU_CULL_NONE
Definition GPU_state.hh:157
unsigned __int64 uint64_t
Definition BKE_text.h:91
@ GPU_STENCIL_OP_NONE
Definition GPU_state.hh:149
@ GPU_STENCIL_OP_REPLACE
Definition GPU_state.hh:150
bool GPU_material_has_displacement_output(GPUMaterial *mat)
bool DEG_is_active(const Depsgraph *depsgraph)
Definition depsgraph.cc:324
int GPU_shader_get_constant(gpu::Shader *shader, const char *name)
MINLINE int count_bits_i(unsigned int n)
@ GPU_MATFLAG_SHADER_TO_RGBA
@ GPU_MATFLAG_COAT
@ GPU_MATFLAG_SUBSURFACE
@ GPU_MATFLAG_LIGHT_ATTRIBUTE
@ GPU_MATFLAG_TRANSLUCENT
@ GPU_MATFLAG_GLOSSY
@ GPU_MATFLAG_REFRACT
@ GPU_MATFLAG_BARYCENTRIC
@ GPU_MATFLAG_DIFFUSE
@ GPU_MATFLAG_LIGHTING
@ GPU_MATFLAG_REFLECTION_MAYBE_COLORED
@ GPU_MATFLAG_RAYCAST
@ GPU_MATFLAG_REFRACTION_MAYBE_COLORED
@ GPU_MATFLAG_TRANSPARENT
bool GPU_material_flag_get(const GPUMaterial *mat, eGPUMaterialFlag flag)
void GPU_shader_async_specialization_cancel(AsyncSpecializationHandle &handle)
AsyncSpecializationHandle GPU_shader_async_specialization(const ShaderSpecialization &specialization, CompilationPriority priority=CompilationPriority::High)
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
MINLINE unsigned int bitscan_forward_clear_uint(unsigned int *a)
unsigned int uint32_t
Definition BKE_text.h:81
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
@ GPU_DEPTH_ALWAYS
Definition GPU_state.hh:133
@ GPU_DEPTH_LESS
Definition GPU_state.hh:134
@ GPU_DEPTH_GREATER_EQUAL
Definition GPU_state.hh:138
@ GPU_DEPTH_EQUAL
Definition GPU_state.hh:136
GPUPass * GPU_material_get_pass(GPUMaterial *material)
int GPU_max_textures()
int64_t AsyncSpecializationHandle
GPUMaterialFromNodeTreeResult GPU_material_from_nodetree(Material *ma, bNodeTree *ntree, ListBaseT< LinkData > *gpumaterials, const char *name, eGPUMaterialEngine engine, uint64_t shader_uuid, bool deferred_compilation, GPUCodegenCallbackFn callback, void *thunk, GPUMaterialPassReplacementCallbackFn pass_replacement_cb=nullptr)
@ GPU_STENCIL_ALWAYS
Definition GPU_state.hh:143
@ GPU_STENCIL_NONE
Definition GPU_state.hh:142
@ GPU_STENCIL_NEQUAL
Definition GPU_state.hh:145
const DRWContext * DRW_context_get()
T * DEG_get_original(T *id)
@ GPU_WRITE_COLOR
Definition GPU_state.hh:27
@ GPU_WRITE_STENCIL
Definition GPU_state.hh:26
@ GPU_WRITE_DEPTH
Definition GPU_state.hh:25
const GPUShaderCreateInfo * GPU_shader_create_info_get(const char *info_name)
signed int int32_t
Definition BKE_text.h:78
uint64_t GPU_material_uuid_get(GPUMaterial *mat)
bool GPU_stencil_export_support()
bool GPU_multi_viewport_support()
Material * GPU_material_get_material(GPUMaterial *material)
@ GPU_VERTEX_LAST
Definition GPU_state.hh:163
const GPUUniformAttrList * GPU_material_uniform_attributes(const GPUMaterial *material)
bool GPU_shader_async_specialization_is_ready(AsyncSpecializationHandle &handle)
const gpu::shader::SpecializationConstants & GPU_shader_get_default_constant_state(gpu::Shader *sh)
Depsgraph * depsgraph
GPUShaderCreateInfo * create_info
Vector< GPUGraphOutput > material_functions
std::string serialized_or_default(std::string value) const
Vector< StringRefNull > dependencies
bool evaluate(Span< CompilationConstant > constants) const
gpu::shader::SpecializationConstants constants
blender::Material * default_mat
Self & stencil_format(TextureTargetFormat stencil_format)
Self & depth_format(TextureTargetFormat depth_format)
Self & color_format(TextureTargetFormat color_format)
Self & state(GPUWriteMask write_mask, GPUBlend blend, GPUFaceCullTest culling_test, GPUDepthTest depth_test, GPUStencilTest stencil_test, GPUStencilOp stencil_op, GPUProvokingVertex provoking_vert)
bool evaluate(Span< CompilationConstant > constants) const
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
Self & compilation_constant(Type type, StringRefNull name, double default_value)
Self & fragment_source(StringRefNull filename)
Self & vertex_in(int slot, Type type, StringRefNull name, ConditionFn cond=nullptr)
Vector< CompilationConstant, 0 > compilation_constants_
Vector< StageInterfaceInfoHandle, 0 > vertex_out_interfaces_
Self & vertex_function(StringRefNull function_name)
Self & additional_info(StringRefNull info_name)
Self & builtins(BuiltinBits builtin, ConditionFn cond=nullptr)
Self & fragment_function(StringRefNull function_name)
PipelineState & pipeline_state()
Create a new pipeline state.
Self & sampler(int slot, ImageType type, StringRefNull name, Frequency freq=Frequency::PASS, ConditionFn cond=nullptr)
Self & define(StringRefNull name, StringRefNull value="")