|
Blender V5.0
|
#include <cstring>#include "BKE_lib_id.hh"#include "MEM_guardedalloc.h"#include "DNA_material_types.h"#include "DNA_scene_types.h"#include "DNA_world_types.h"#include "BLI_listbase.h"#include "BLI_math_vector.h"#include "BLI_string.h"#include "BLI_time.h"#include "BLI_utildefines.h"#include "BKE_main.hh"#include "BKE_material.hh"#include "BKE_node.hh"#include "BKE_node_runtime.hh"#include "NOD_shader.h"#include "NOD_shader_nodes_inline.hh"#include "GPU_material.hh"#include "GPU_pass.hh"#include "GPU_shader.hh"#include "GPU_texture.hh"#include "GPU_uniform_buffer.hh"#include "DRW_engine.hh"#include "gpu_node_graph.hh"#include "atomic_ops.h"Go to the source code of this file.
Classes | |
| struct | GPUColorBandBuilder |
| struct | GPUSkyBuilder |
| struct | GPUMaterial |
Macros | |
| #define | MAX_COLOR_BAND 128 |
| #define | MAX_GPU_SKIES 8 |
Manages materials, lights and textures.
Definition in file gpu/intern/gpu_material.cc.
| #define MAX_COLOR_BAND 128 |
Definition at line 50 of file gpu/intern/gpu_material.cc.
Referenced by gpu_material_ramp_texture_row_set().
| #define MAX_GPU_SKIES 8 |
Definition at line 51 of file gpu/intern/gpu_material.cc.
Referenced by gpu_material_sky_texture_layer_set().
| void GPU_material_add_output_link_aov | ( | GPUMaterial * | material, |
| GPUNodeLink * | link, | ||
| int | hash ) |
Definition at line 555 of file gpu/intern/gpu_material.cc.
References BLI_addtail(), GPUMaterial::graph, GPUNodeGraphOutputLink::hash, hash, MEM_callocN(), GPUNodeGraphOutputLink::outlink, and GPUNodeGraph::outlink_aovs.
Referenced by blender::nodes::node_shader_output_aov_cc::node_shader_gpu_output_aov().
| void GPU_material_add_output_link_composite | ( | GPUMaterial * | material, |
| GPUNodeLink * | link ) |
Definition at line 563 of file gpu/intern/gpu_material.cc.
References BLI_addtail(), GPUMaterial::graph, MEM_callocN(), GPUNodeGraphOutputLink::outlink, and GPUNodeGraph::outlink_compositor.
| ListBase GPU_material_attributes | ( | const GPUMaterial * | material | ) |
Definition at line 395 of file gpu/intern/gpu_material.cc.
References GPUNodeGraph::attributes, and GPUMaterial::graph.
Referenced by blender::draw::attribute_index_in_material(), blender::draw::curves_bind_resources_implementation(), blender::draw::CurvesEvalCache::ensure_attributes(), blender::draw::CurvesEvalCache::ensure_attributes(), blender::draw::mesh_cd_calc_used_gpu_layers(), blender::draw::pointcloud_sub_pass_setup_implementation(), blender::draw::pointcloud_surface_shaded_get(), blender::eevee::SyncModule::sync_volume(), and blender::draw::volume_sub_pass_implementation().
| uint64_t GPU_material_compilation_timestamp | ( | GPUMaterial * | mat | ) |
Definition at line 346 of file gpu/intern/gpu_material.cc.
References GPU_pass_compilation_timestamp(), and GPUMaterial::pass.
| eGPUMaterialFlag GPU_material_flag | ( | const GPUMaterial * | mat | ) |
Definition at line 371 of file gpu/intern/gpu_material.cc.
References GPUMaterial::flag.
Referenced by blender::gpu::shader::GPUCodegen::GPUCodegen().
| bool GPU_material_flag_get | ( | const GPUMaterial * | mat, |
| eGPUMaterialFlag | flag ) |
Definition at line 366 of file gpu/intern/gpu_material.cc.
References flag, and GPUMaterial::flag.
Referenced by blender::eevee::VolumeLayer::material_add(), blender::eevee::ShaderModule::material_create_info_amend(), blender::eevee::ForwardPipeline::material_opaque_add(), blender::eevee::pass_replacement_cb(), blender::eevee::ForwardPipeline::prepass_opaque_add(), and blender::eevee::shader_closure_bits_from_flag().
| void GPU_material_flag_set | ( | GPUMaterial * | mat, |
| eGPUMaterialFlag | flag ) |
Definition at line 376 of file gpu/intern/gpu_material.cc.
References flag, GPUMaterial::flag, GPU_MATFLAG_COAT, and GPU_MATFLAG_GLOSSY.
Referenced by GPU_attribute(), blender::nodes::node_shader_normal_map_cc::gpu_shader_normal_map(), blender::nodes::node_shader_particle_info_cc::gpu_shader_particle_info(), blender::nodes::node_shader_ambient_occlusion_cc::node_shader_gpu_ambient_occlusion(), blender::nodes::node_shader_bsdf_diffuse_cc::node_shader_gpu_bsdf_diffuse(), blender::nodes::node_shader_bsdf_glass_cc::node_shader_gpu_bsdf_glass(), blender::nodes::node_shader_bsdf_glossy_cc::node_shader_gpu_bsdf_glossy(), blender::nodes::node_shader_bsdf_hair_cc::node_shader_gpu_bsdf_hair(), blender::nodes::node_shader_bsdf_metallic_cc::node_shader_gpu_bsdf_metallic(), blender::nodes::node_shader_bsdf_principled_cc::node_shader_gpu_bsdf_principled(), blender::nodes::node_shader_bsdf_ray_portal_cc::node_shader_gpu_bsdf_ray_portal(), blender::nodes::node_shader_bsdf_refraction_cc::node_shader_gpu_bsdf_refraction(), blender::nodes::node_shader_bsdf_sheen_cc::node_shader_gpu_bsdf_sheen(), blender::nodes::node_shader_bsdf_toon_cc::node_shader_gpu_bsdf_toon(), blender::nodes::node_shader_bsdf_translucent_cc::node_shader_gpu_bsdf_translucent(), blender::nodes::node_shader_bsdf_transparent_cc::node_shader_gpu_bsdf_transparent(), blender::nodes::node_shader_eevee_specular_cc::node_shader_gpu_eevee_specular(), blender::nodes::node_shader_emission_cc::node_shader_gpu_emission(), blender::nodes::node_shader_geometry_cc::node_shader_gpu_geometry(), blender::nodes::node_shader_bsdf_hair_principled_cc::node_shader_gpu_hair_principled(), blender::nodes::node_shader_object_info_cc::node_shader_gpu_object_info(), blender::nodes::node_shader_output_aov_cc::node_shader_gpu_output_aov(), blender::nodes::node_shader_shader_to_rgb_cc::node_shader_gpu_shadertorgb(), blender::nodes::node_shader_subsurface_scattering_cc::node_shader_gpu_subsurface_scattering(), blender::nodes::node_shader_volume_absorption_cc::node_shader_gpu_volume_absorption(), blender::nodes::node_shader_volume_coefficients_cc::node_shader_gpu_volume_coefficients(), blender::nodes::node_shader_volume_principled_cc::node_shader_gpu_volume_principled(), blender::nodes::node_shader_volume_scatter_cc::node_shader_gpu_volume_scatter(), and blender::nodes::node_shader_wireframe_cc::node_shader_gpu_wireframe().
| void GPU_material_free | ( | ListBase * | gpumaterial | ) |
Definition at line 266 of file gpu/intern/gpu_material.cc.
References BLI_freelistN(), GPU_material_free_single(), and LISTBASE_FOREACH.
Referenced by BKE_material_defaults_free_gpu(), BKE_material_eval(), BKE_world_eval(), ED_node_set_active(), GPU_materials_free(), material_free_data(), blender::eevee::LookdevWorld::sync(), and world_free_data().
| void GPU_material_free_single | ( | GPUMaterial * | material | ) |
Definition at line 261 of file gpu/intern/gpu_material.cc.
Referenced by GPU_material_free(), and blender::compositor::ShaderOperation::~ShaderOperation().
| GPUMaterial * GPU_material_from_callbacks | ( | eGPUMaterialEngine | engine, |
| ConstructGPUMaterialFn | construct_function_cb, | ||
| GPUCodegenCallbackFn | generate_code_function_cb, | ||
| void * | thunk ) |
Definition at line 219 of file gpu/intern/gpu_material.cc.
References GPU_generate_pass(), gpu_material_ramp_texture_build(), gpu_node_graph_free_nodes(), GPU_pass_should_optimize(), GPUMaterial::graph, GPUMaterial::optimized_pass, and GPUMaterial::pass.
Referenced by blender::compositor::ShaderOperation::ShaderOperation().
| GPUMaterialFromNodeTreeResult GPU_material_from_nodetree | ( | Material * | ma, |
| bNodeTree * | ntree, | ||
| ListBase * | gpumaterials, | ||
| const char * | name, | ||
| eGPUMaterialEngine | engine, | ||
| uint64_t | shader_uuid, | ||
| bool | deferred_compilation, | ||
| GPUCodegenCallbackFn | callback, | ||
| void * | thunk, | ||
| GPUMaterialPassReplacementCallbackFn | pass_replacement_cb = nullptr ) |
WARNING: gpumaterials thread safety must be ensured by the caller.
WORKAROUND: The node tree code is never executed in default replaced passes, but the GPU validation will still complain if the node tree UBO is not bound. So we create a dummy UBO with (at least) the size of the default material one (192 bytes). We allocate 256 bytes to leave some room for future changes.
Definition at line 131 of file gpu/intern/gpu_material.cc.
References blender::nodes::InlineShaderNodeTreeParams::allow_preserving_repeat_zones, BKE_id_free(), BLI_addtail(), LinkData::data, GPUMaterial::engine, error(), GPU_generate_pass(), gpu_material_ramp_texture_build(), gpu_material_sky_texture_build(), gpu_node_graph_free_nodes(), GPU_pass_acquire(), GPU_pass_ensure_its_ready(), GPU_pass_should_optimize(), GPU_uniformbuf_create_ex(), GPUMaterial::graph, bNodeTree::id, bNodeTree::idname, blender::nodes::inline_shader_node_tree(), LISTBASE_FOREACH, MEM_callocN(), GPUMaterial::name, ID::name, name, blender::bke::node_tree_add_tree(), ntreeGPUMaterialNodes, GPUMaterial::optimized_pass, GPUMaterial::pass, blender::nodes::InlineShaderNodeTreeParams::r_error_messages, result, GPUMaterial::source_material, GPUMaterial::ubo, and GPUMaterial::uuid.
Referenced by blender::eevee::ShaderModule::material_shader_get(), and blender::eevee::ShaderModule::world_shader_get().
| Material * GPU_material_get_material | ( | GPUMaterial * | material | ) |
Return can be null if it's a world material.
Definition at line 298 of file gpu/intern/gpu_material.cc.
References GPUMaterial::source_material.
Referenced by blender::gpu::shader::GPUCodegen::generate_cryptomatte(), blender::nodes::node_shader_object_info_cc::node_shader_gpu_object_info(), blender::eevee::pass_replacement_cb(), blender::eevee::SyncModule::sync_curves(), blender::eevee::SyncModule::sync_mesh(), blender::eevee::SyncModule::sync_pointcloud(), and blender::eevee::SyncModule::sync_sculpt().
| const char * GPU_material_get_name | ( | GPUMaterial * | material | ) |
Definition at line 288 of file gpu/intern/gpu_material.cc.
References GPUMaterial::name.
Referenced by blender::eevee::DeferredLayer::material_add(), blender::eevee::DeferredProbePipeline::material_add(), blender::eevee::PlanarProbePipeline::material_add(), blender::eevee::VolumeLayer::material_add(), blender::eevee::ForwardPipeline::material_opaque_add(), blender::eevee::ForwardPipeline::material_transparent_add(), blender::eevee::VolumeLayer::occupancy_add(), blender::eevee::DeferredLayer::prepass_add(), blender::eevee::DeferredProbePipeline::prepass_add(), blender::eevee::PlanarProbePipeline::prepass_add(), blender::eevee::ForwardPipeline::prepass_opaque_add(), blender::eevee::ForwardPipeline::prepass_transparent_add(), blender::eevee::CapturePipeline::surface_material_add(), and blender::eevee::ShadowPipeline::surface_material_add().
| GPUPass * GPU_material_get_pass | ( | GPUMaterial * | material | ) |
Definition at line 303 of file gpu/intern/gpu_material.cc.
References GPU_MAT_OPTIMIZATION_SUCCESS, GPU_material_optimization_status(), GPUMaterial::optimized_pass, and GPUMaterial::pass.
Referenced by GPU_material_get_shader(), blender::draw::detail::PassBase< DrawCommandBufType >::material_set(), blender::eevee::pass_replacement_cb(), and blender::eevee::CapturePipeline::surface_material_add().
| blender::gpu::Shader * GPU_material_get_shader | ( | GPUMaterial * | material | ) |
Return the most optimal shader configuration for the given material.
Definition at line 312 of file gpu/intern/gpu_material.cc.
References GPU_material_get_pass(), and GPU_pass_shader_get().
Referenced by blender::compositor::ShaderOperation::execute(), and blender::eevee::ShaderKey::ShaderKey().
| bool GPU_material_has_displacement_output | ( | GPUMaterial * | mat | ) |
Definition at line 361 of file gpu/intern/gpu_material.cc.
References GPUMaterial::has_displacement_output.
Referenced by blender::eevee::pass_replacement_cb(), blender::eevee::SyncModule::sync_curves(), blender::eevee::SyncModule::sync_mesh(), blender::eevee::SyncModule::sync_pointcloud(), and blender::eevee::SyncModule::sync_sculpt().
| bool GPU_material_has_surface_output | ( | GPUMaterial * | mat | ) |
Definition at line 351 of file gpu/intern/gpu_material.cc.
References GPUMaterial::has_surface_output.
| bool GPU_material_has_volume_output | ( | GPUMaterial * | mat | ) |
Definition at line 356 of file gpu/intern/gpu_material.cc.
References GPUMaterial::has_volume_output.
Referenced by blender::eevee::VolumeLayer::material_add(), blender::eevee::VolumeLayer::occupancy_add(), blender::eevee::WorldVolumePipeline::sync(), and blender::eevee::SyncModule::sync_volume().
| const ListBase * GPU_material_layer_attributes | ( | const GPUMaterial * | material | ) |
Definition at line 411 of file gpu/intern/gpu_material.cc.
References BLI_listbase_is_empty(), GPUMaterial::graph, and GPUNodeGraph::layer_attrs.
Referenced by blender::draw::Manager::register_layer_attributes().
| GPUNodeGraph * gpu_material_node_graph | ( | GPUMaterial * | material | ) |
Definition at line 417 of file gpu/intern/gpu_material.cc.
References GPUMaterial::graph.
Referenced by GPU_attribute(), GPU_attribute_default_color(), GPU_attribute_hair_intercept(), GPU_attribute_hair_length(), GPU_color_band(), GPU_image(), GPU_image_sky(), GPU_image_tiled(), GPU_layer_attribute(), GPU_link(), gpu_stack_link_v(), GPU_stack_link_zone(), and GPU_uniform_attribute().
| eGPUMaterialOptimizationStatus GPU_material_optimization_status | ( | GPUMaterial * | mat | ) |
Return status for asynchronous optimization jobs.
Definition at line 329 of file gpu/intern/gpu_material.cc.
References BLI_assert_unreachable, GPU_MAT_OPTIMIZATION_QUEUED, GPU_MAT_OPTIMIZATION_SKIP, GPU_MAT_OPTIMIZATION_SUCCESS, GPU_PASS_QUEUED, GPU_pass_should_optimize(), GPU_pass_status(), GPU_PASS_SUCCESS, GPUMaterial::optimized_pass, and GPUMaterial::pass.
Referenced by GPU_material_get_pass().
| void GPU_material_output_displacement | ( | GPUMaterial * | material, |
| GPUNodeLink * | link ) |
Definition at line 540 of file gpu/intern/gpu_material.cc.
References GPUMaterial::graph, GPUMaterial::has_displacement_output, and GPUNodeGraph::outlink_displacement.
Referenced by blender::nodes::node_shader_output_material_cc::node_shader_gpu_output_material().
| void GPU_material_output_surface | ( | GPUMaterial * | material, |
| GPUNodeLink * | link ) |
Definition at line 524 of file gpu/intern/gpu_material.cc.
References GPUMaterial::graph, GPUMaterial::has_surface_output, and GPUNodeGraph::outlink_surface.
Referenced by blender::nodes::node_shader_output_light_cc::node_shader_gpu_output_light(), blender::nodes::node_shader_output_material_cc::node_shader_gpu_output_material(), and blender::nodes::node_shader_output_world_cc::node_shader_gpu_output_world().
| void GPU_material_output_thickness | ( | GPUMaterial * | material, |
| GPUNodeLink * | link ) |
Definition at line 548 of file gpu/intern/gpu_material.cc.
References GPUMaterial::graph, and GPUNodeGraph::outlink_thickness.
Referenced by blender::nodes::node_shader_output_material_cc::node_shader_gpu_output_material().
| void GPU_material_output_volume | ( | GPUMaterial * | material, |
| GPUNodeLink * | link ) |
Definition at line 532 of file gpu/intern/gpu_material.cc.
References GPUMaterial::graph, GPUMaterial::has_volume_output, and GPUNodeGraph::outlink_volume.
Referenced by blender::nodes::node_shader_output_material_cc::node_shader_gpu_output_material(), and blender::nodes::node_shader_output_world_cc::node_shader_gpu_output_world().
|
static |
Definition at line 483 of file gpu/intern/gpu_material.cc.
References CM_TABLE, GPUMaterial::coba_builder, GPUMaterial::coba_tex, GPUColorBandBuilder::current_layer, GPU_texture_create_1d_array(), GPU_TEXTURE_USAGE_SHADER_READ, MEM_freeN(), and GPUColorBandBuilder::pixels.
Referenced by GPU_material_from_callbacks(), and GPU_material_from_nodetree().
| blender::gpu::Texture ** gpu_material_ramp_texture_row_set | ( | GPUMaterial * | mat, |
| int | size, | ||
| const float * | pixels, | ||
| float * | r_row ) |
Returns the address of the future pointer to coba_tex.
Definition at line 453 of file gpu/intern/gpu_material.cc.
References BLI_assert, CM_TABLE, GPUMaterial::coba_builder, GPUMaterial::coba_tex, GPUColorBandBuilder::current_layer, float, MAX_COLOR_BAND, MEM_mallocN(), GPUColorBandBuilder::pixels, printf, size(), and UNUSED_VARS_NDEBUG.
Referenced by GPU_color_band().
|
static |
Definition at line 503 of file gpu/intern/gpu_material.cc.
References GPUSkyBuilder::current_layer, GPU_SKY_HEIGHT, GPU_SKY_WIDTH, GPU_texture_create_2d_array(), GPU_TEXTURE_USAGE_SHADER_READ, MEM_freeN(), GPUSkyBuilder::pixels, GPUMaterial::sky_builder, and GPUMaterial::sky_tex.
Referenced by GPU_material_from_nodetree().
| blender::gpu::Texture ** gpu_material_sky_texture_layer_set | ( | GPUMaterial * | mat, |
| int | width, | ||
| int | height, | ||
| const float * | pixels, | ||
| float * | row ) |
Returns the address of the future pointer to sky_tex
Definition at line 424 of file gpu/intern/gpu_material.cc.
References BLI_assert, GPUSkyBuilder::current_layer, float, GPU_SKY_HEIGHT, GPU_SKY_WIDTH, MAX_GPU_SKIES, MEM_mallocN(), GPUSkyBuilder::pixels, printf, GPUMaterial::sky_builder, GPUMaterial::sky_tex, and UNUSED_VARS_NDEBUG.
Referenced by GPU_image_sky().
| char * GPU_material_split_sub_function | ( | GPUMaterial * | material, |
| GPUType | return_type, | ||
| GPUNodeLink ** | link ) |
Wrap a part of the material graph into a function. You need then need to call the function by using something like GPU_differentiate_float_function.
| return_type | sub function return type. Output is cast to this type. |
| link | link to use as the sub function output. |
Definition at line 570 of file gpu/intern/gpu_material.cc.
References BLI_addtail(), BLI_assert, GPUMaterial::generated_function_len, GPU_FLOAT, GPU_link(), GPU_VEC3, GPU_VEC4, GPUMaterial::graph, GPUNodeGraph::material_functions, MEM_callocN(), GPUNodeGraphFunctionLink::name, GPUNodeGraphFunctionLink::outlink, and SNPRINTF.
Referenced by blender::nodes::node_shader_bump_cc::gpu_shader_bump().
| GPUMaterialStatus GPU_material_status | ( | GPUMaterial * | mat | ) |
Return true if the material compilation has not yet begin or begin.
Definition at line 317 of file gpu/intern/gpu_material.cc.
References GPU_MAT_FAILED, GPU_MAT_QUEUED, GPU_MAT_SUCCESS, GPU_PASS_QUEUED, GPU_pass_status(), GPU_PASS_SUCCESS, and GPUMaterial::pass.
Referenced by blender::eevee::World::sync(), and blender::eevee::WorldVolumePipeline::sync().
| ListBase GPU_material_textures | ( | GPUMaterial * | material | ) |
Definition at line 400 of file gpu/intern/gpu_material.cc.
References GPUMaterial::graph, and GPUNodeGraph::textures.
Referenced by image_walk_gpu_materials(), and blender::draw::detail::PassBase< DrawCommandBufType >::material_set().
| const GPUUniformAttrList * GPU_material_uniform_attributes | ( | const GPUMaterial * | material | ) |
Definition at line 405 of file gpu/intern/gpu_material.cc.
References GPUUniformAttrList::count, GPUMaterial::graph, and GPUNodeGraph::uniform_attrs.
Referenced by blender::draw::Manager::extract_object_attributes(), blender::draw::Manager::extract_object_attributes(), and blender::eevee::ShaderModule::material_create_info_amend().
| void GPU_material_uniform_buffer_create | ( | GPUMaterial * | material, |
| ListBase * | inputs ) |
Create dynamic UBO from parameters
Definition at line 385 of file gpu/intern/gpu_material.cc.
References GPU_uniformbuf_create_from_list(), inputs, GPUMaterial::name, and GPUMaterial::ubo.
Referenced by blender::gpu::shader::GPUCodegen::generate_uniform_buffer().
| blender::gpu::UniformBuf * GPU_material_uniform_buffer_get | ( | GPUMaterial * | material | ) |
Definition at line 390 of file gpu/intern/gpu_material.cc.
References GPUMaterial::ubo.
Referenced by blender::draw::detail::PassBase< DrawCommandBufType >::material_set().
| uint64_t GPU_material_uuid_get | ( | GPUMaterial * | mat | ) |
Definition at line 293 of file gpu/intern/gpu_material.cc.
References GPUMaterial::uuid.
Referenced by blender::gpu::shader::GPUCodegen::GPUCodegen(), blender::eevee::ShaderModule::material_create_info_amend(), and blender::eevee::pass_replacement_cb().
| void GPU_materials_free | ( | Main * | bmain | ) |
Definition at line 275 of file gpu/intern/gpu_material.cc.
References BKE_material_defaults_free_gpu(), GPU_material_free(), LISTBASE_FOREACH, Main::materials, and Main::worlds.
Referenced by blender::ed::outliner::outliner_id_remap_exec().