46 return *std::get<const float *>(link->data);
48 return float2(std::get<const float *>(link->data));
50 return float3(std::get<const float *>(link->data));
52 return float4(std::get<const float *>(link->data));
54 return float3x3(std::get<const float *>(link->data));
56 return float4x4(std::get<const float *>(link->data));
58 return *std::get<const int *>(link->data);
60 return int2(std::get<const int *>(link->data));
62 return int3(std::get<const int *>(link->data));
64 return int4(std::get<const int *>(link->data));
66 return *std::get<const bool *>(link->data);
110 const int2 &value = std::get<int2>(
data);
114 const int3 &value = std::get<int3>(
data);
118 const int4 &value = std::get<int4>(
data);
131 return std::get<bool>(
data);
136 GPUNodeLink *link = MEM_new<GPUNodeLink>(
"GPUNodeLink");
146 if (link->
users < 0) {
147 fprintf(stderr,
"gpu_node_link_free: negative refcount\n");
150 if (link->
users == 0) {
152 link->output->link =
nullptr;
165 node->zone_index = -1;
166 node->is_zone_end =
false;
178 outnode = link->output->node;
179 name = outnode->
name;
180 input = outnode->
inputs.first();
182 if (
STR_ELEM(name,
"set_value",
"set_vec2",
"set_rgb",
"set_rgba") && (input->
type == type)) {
183 input = MEM_dupalloc(outnode->
inputs.first());
187 input->attr->users++;
190 input->uniform_attr->users++;
193 input->layer_attr->users++;
196 input->texture->users++;
213 input = MEM_new<GPUInput>(
"GPUInput");
228 input->texture = link->texture;
232 input->texture = link->texture;
236 input->attr = link->attr;
240 if (input->attr->gputype ==
GPU_NONE ||
243 input->attr->gputype = type;
248 input->uniform_attr = link->uniform_attr;
252 input->layer_attr = link->layer_attr;
270 "dF_branch_incomplete(%s(kg, sd), %g, ",
271 link->differentiate_float.function_name,
272 link->differentiate_float.filter_width);
354 using T = std::decay_t<
decltype(value)>;
355 if constexpr (std::is_same_v<T, std::monostate>) {
357 static const float4 dummy(0.0f);
360 else if constexpr (std::is_arithmetic_v<T>) {
377 using T = std::decay_t<
decltype(value)>;
378 if constexpr (std::is_same_v<T, std::monostate>) {
380 static const float4 dummy(0.0f);
383 else if constexpr (std::is_arithmetic_v<T>) {
464 else if ((material !=
nullptr) &&
501 int cmps = strcmp(attr_a->
name, attr_b->name);
503 return cmps > 0 ? 1 : 0;
506 return (attr_a->
use_dupli && !attr_b->use_dupli);
520 if (set_a->
hash_code != set_b->hash_code || set_a->
count != set_b->count) {
526 for (; attr_a && attr_b; attr_a = attr_a->
next, attr_b = attr_b->
next) {
532 return attr_a || attr_b;
551 set->
list.free_no_destruct();
585 switch (attr->
type) {
591 BLI_assert_msg(0,
"GPUVertAttr Prefix type not found : This should not happen!");
606 if (attr->
name[0] !=
'\0') {
617 const bool is_default_color,
618 const bool is_hair_length,
619 const bool is_hair_intercept)
622 int num_attributes = 0;
624 for (; attr; attr = attr->
next) {
643 attr->
id = num_attributes;
647 if (attr !=
nullptr) {
663 for (; attr; attr = attr->
next) {
669 if (attr ==
nullptr) {
679 if (attr !=
nullptr) {
690 ListBaseT<GPULayerAttr> *attrs = &graph->
layer_attrs;
693 for (; attr; attr = attr->
next) {
700 if (attr ==
nullptr) {
707 if (attr !=
nullptr) {
716 const bool iuser_available = iuser !=
nullptr;
733 int num_textures = 0;
735 for (; tex; tex = tex->
next) {
736 if (tex->
ima == ima && tex->
colorband == colorband && tex->
sky == sky &&
745 if (tex ==
nullptr) {
746 tex = MEM_new<GPUMaterialTexture>(__func__);
748 if (iuser !=
nullptr) {
773 graph, type, name,
false,
false,
false);
781 if (attr ==
nullptr) {
797 if (attr ==
nullptr) {
813 if (attr ==
nullptr) {
828 if (attr ==
nullptr) {
845 link->attr->default_value = default_value;
859 if (attr ==
nullptr) {
868 link->uniform_attr = attr;
879 link->layer_attr = attr;
887 link->differentiate_float.function_name = function_name;
888 link->differentiate_float.filter_width = filter_width;
901 graph, ima, iuser,
nullptr,
nullptr,
false, sampler_state);
918 graph,
nullptr,
nullptr,
nullptr, sky,
false, sampler_state);
931 graph, ima, iuser,
nullptr,
nullptr,
true, sampler_state);
935 (*r_image_tiled_link)->texture =
texture;
939 (*r_image_tiled_mapping_link)->texture =
texture;
968 fprintf(stderr,
"GPU failed to find function %s\n", name);
974 va_start(params, name);
975 for (i = 0; i < function->
totparam; i++) {
1004 int i, totin, totout;
1008 fprintf(stderr,
"GPU failed to find function %s\n", name);
1017 for (i = 0; !
in[i].end; i++) {
1026 for (i = 0; !
out[i].end; i++) {
1034 for (i = 0; i < function->
totparam; i++) {
1073 va_start(params,
out);
1087 int in_argument_count,
1088 int out_argument_count)
1094 node->zone_index = zone_index;
1095 node->is_zone_end = is_zone_end;
1098 for (
int i = 0; !
in[i].end; i++) {
1106 for (
int i = 0; !
out[i].end; i++) {
1113 for (
const auto [i, input] :
node->inputs.enumerate()) {
1114 input.is_zone_io = i >= in_argument_count;
1115 input.is_duplicate = input.is_zone_io && is_zone_end;
1117 for (
const auto [i,
output] :
node->outputs.enumerate()) {
1118 output.is_zone_io = i >= out_argument_count;
1132 switch (input.source) {
1134 input.attr->users--;
1137 input.uniform_attr->users--;
1140 input.layer_attr->users--;
1143 input.texture->users--;
1156 inputs->free_no_destruct();
1165 output.link->output =
nullptr;
1170 node->outputs.free_no_destruct();
1193 graph->
textures.free_no_destruct();
1203 if (!link_start || !link_start->output) {
1209 stack.
push(link_start->output->node);
1214 if (
node->tag & tag) {
1220 if (input.
link && input.
link->output) {
1221 stack.
push(input.
link->output->node);
1227 if (
node->is_zone_end) {
1232 if (input.
link && input.
link->output) {
1233 zone_stack.
push(input.
link->output->node);
1275 if (attr->users == 0) {
1282 if (tex->users == 0) {
1290 if (attr.users == 0) {
1297 if (attr.users == 0) {
1328 return inputs[input->index()];
1337 return outputs[
output->index()];
#define SNPRINTF(dst, format,...)
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
void push(const T &value)
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
static GPUNode * gpu_node_create(const char *name)
GPUNodeLink * GPU_uniform_attribute(GPUMaterial *mat, const char *name, bool use_dupli, uint32_t *r_hash)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
unsigned int BLI_ghashutil_uinthash(unsigned int key)
static void gpu_node_output(GPUNode *node, const GPUType type, GPUNodeLink **link)
char * STRNCPY(char(&dst)[N], const char *src)
static GPUNodeLink * gpu_uniformbuffer_link(GPUMaterial *mat, const bNode *node, GPUNodeStack *stack, const int index, const eNodeSocketInOut in_out)
constexpr bool is_same_any_v
VecBase< int32_t, 4 > int4
GPUNodeGraph * gpu_material_node_graph(GPUMaterial *material)
Span< float > gpu_constant_to_float_span(const GPUInputConstantData &data, const GPUType type)
static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType type)
Span< int > gpu_constant_to_int_span(const GPUInputConstantData &data, const GPUType type)
static void gpu_node_link_free(GPUNodeLink *link)
static bool uniform_attr_list_cmp(const void *a, const void *b)
constexpr int GPU_MAX_CONSTANT_DATA
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
static GPUMaterialTexture * gpu_node_graph_add_texture(GPUNodeGraph *graph, Image *ima, ImageUser *iuser, gpu::Texture **colorband, gpu::Texture **sky, bool is_tiled, GPUSamplerState sampler_state)
static constexpr int GPU_MAX_SAFE_ATTR_NAME
GPUNodeLink * GPU_image(GPUMaterial *mat, Image *ima, ImageUser *iuser, GPUSamplerState sampler_state)
GPUNodeLink * GPU_node_get_input_link(const bNode &node, GPUNodeStack inputs[], StringRef identifier)
GPUNodeLink * GPU_attribute_with_default(GPUMaterial *mat, eCustomDataType type, const char *name, GPUDefaultValue default_value)
@ GPU_MATFLAG_OBJECT_INFO
GPUNodeStack & GPU_node_get_input(const bNode &node, GPUNodeStack inputs[], StringRef identifier)
static constexpr int GPU_MAX_ATTR
GPUNodeLink * GPU_layer_attribute(GPUMaterial *mat, const char *name)
void gpu_nodes_tag(GPUNodeGraph *graph, GPUNodeLink *link_start, GPUNodeTag tag)
MatBase< float, 4, 4 > float4x4
static GPULayerAttr * gpu_node_graph_add_layer_attribute(GPUNodeGraph *graph, const char *name)
gpu::Texture ** gpu_material_ramp_texture_row_set(GPUMaterial *mat, int size, const float *pixels, float *r_row)
GPUNodeLink * GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *r_row)
GPUFunction * gpu_material_library_get_function(const char *name)
GPUNodeLink * GPU_uniform(const float *num)
bool GPU_stack_link_zone(GPUMaterial *material, const bNode *bnode, const char *name, GPUNodeStack *in, GPUNodeStack *out, int zone_index, bool is_zone_end, int in_argument_count, int out_argument_count)
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
VecBase< float, 4 > float4
GPUNodeLink * GPU_attribute_hair_length(GPUMaterial *mat)
gpu::Texture ** gpu_material_sky_texture_layer_set(GPUMaterial *mat, int width, int height, const float *pixels, float *row)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static int uniform_attr_sort_cmp(const void *a, const void *b)
GPUNodeLink * GPU_constant(const float *num)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void GPU_vertformat_safe_attr_name(StringRef attr_name, char *r_safe_name, uint max_len)
bool GPU_link(GPUMaterial *mat, const char *name,...)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
BMesh const char void * data
bool gpu_constant_to_bool(const GPUInputConstantData &data)
@ GPU_NODE_TAG_COMPOSITOR
@ GPU_NODE_TAG_DISPLACEMENT
GPUNodeLink * GPU_attribute_default_color(GPUMaterial *mat)
bool BKE_image_user_match(const ImageUser &a, const ImageUser &b)
GPUNodeStack & GPU_node_get_output(const bNode &node, GPUNodeStack outputs[], StringRef identifier)
static uint uniform_attr_list_hash(const void *key)
static void gpu_inputs_free(ListBaseT< GPUInput > *inputs)
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
static GPUInputConstantData gpu_input_constant_data_from_link(const GPUNodeLink *link, const GPUType type)
void GPU_image_tiled(GPUMaterial *mat, Image *ima, ImageUser *iuser, GPUSamplerState sampler_state, GPUNodeLink **r_image_tiled_link, GPUNodeLink **r_image_tiled_mapping_link)
static void attr_input_name(GPUMaterialAttribute *attr)
static GPUNodeLink * gpu_node_link_create()
void GPU_uniform_attr_list_copy(GPUUniformAttrList *dest, const GPUUniformAttrList *src)
ATTR_WARN_UNUSED_RESULT const size_t num
void gpu_node_graph_free(GPUNodeGraph *graph)
MatBase< float, 3, 3 > float3x3
void gpu_node_graph_free_nodes(GPUNodeGraph *graph)
@ GPU_NODE_LINK_IMAGE_SKY
@ GPU_NODE_LINK_LAYER_ATTR
@ GPU_NODE_LINK_KERNEL_GLOBALS
@ GPU_NODE_LINK_IMAGE_TILED
@ GPU_NODE_LINK_SHADING_DATA
@ GPU_NODE_LINK_DIFFERENTIATE_FLOAT_FN
@ GPU_NODE_LINK_IMAGE_TILED_MAPPING
@ GPU_NODE_LINK_COLORBAND
@ GPU_NODE_LINK_UNIFORM_ATTR
GPUNodeLink * GPU_differentiate_float_function(const char *function_name, const float filter_width)
static const char * gpu_uniform_set_function_from_type(GPUType type)
void void BLI_listbase_sort(ListBase *listbase, int(*cmp)(const void *, const void *)) ATTR_NONNULL(1
GPUNodeLink * GPU_shading_data()
@ GPU_SOURCE_TEX_TILED_MAPPING
@ GPU_SOURCE_SHADING_DATA
@ GPU_SOURCE_FUNCTION_CALL
@ GPU_SOURCE_UNIFORM_ATTR
@ GPU_SOURCE_KERNEL_GLOBALS
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
static bool gpu_stack_link_v(GPUMaterial *material, const bNode *bnode, const char *name, GPUNodeStack *in, GPUNodeStack *out, va_list params)
GPUNodeLink * GPU_image_sky(GPUMaterial *mat, int width, int height, const float *pixels, float *layer, GPUSamplerState sampler_state)
static bool gpu_image_user_match(const GPUMaterialTexture *tex, const ImageUser *iuser)
void gpu_node_graph_finalize_uniform_attrs(GPUNodeGraph *graph)
unsigned int BLI_ghashutil_strhash_p(const void *ptr)
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
static GPUMaterialAttribute * gpu_node_graph_add_attribute(GPUNodeGraph *graph, eCustomDataType type, const char *name, const bool is_default_color, const bool is_hair_length, const bool is_hair_intercept)
GPUNodeLink * GPU_kernel_globals()
static void gpu_node_free(GPUNode *node)
GHash * BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
VecBase< float, 3 > float3
void gpu_node_graph_prune_unused(GPUNodeGraph *graph)
static char attr_prefix_get(const GPUMaterialAttribute *attr)
static void gpu_node_input_socket(GPUMaterial *material, const bNode *bnode, GPUNode *node, GPUNodeStack *sock, const int index)
void GPU_uniform_attr_list_free(GPUUniformAttrList *set)
void gpu_node_graph_optimize(GPUNodeGraph *graph)
static GPUUniformAttr * gpu_node_graph_add_uniform_attribute(GPUNodeGraph *graph, const char *name, bool use_dupli)
constexpr int gpu_type_element_count(const GPUType type)
std::variant< float, float2, float3, float4, float3x3, float4x4, int, int2, int3, int4, bool > GPUInputConstantData
GHash * GPU_uniform_attr_list_hash_new(const char *info)
GPUNodeLink * GPU_attribute_hair_intercept(GPUMaterial *mat)
GPUFunctionQual paramqual[MAX_PARAMETER]
GPUType paramtype[MAX_PARAMETER]
GPUMaterialAttribute * next
GPUSamplerState sampler_state
char tiled_mapping_name[32]
gpu::Texture ** colorband
GPUMaterialTexture * next
ListBaseT< GPUMaterialAttribute > attributes
ListBaseT< GPUNodeGraphFunctionLink > material_functions
GPUNodeLink * outlink_surface
ListBaseT< GPULayerAttr > layer_attrs
GPUNodeLink * outlink_displacement
ListBaseT< GPUNodeGraphOutputLink > outlink_aovs
GPUNodeLink * outlink_thickness
ListBaseT< GPUNode > nodes
ListBaseT< GPUNodeGraphOutputLink > outlink_compositor
GPUNodeLink * outlink_volume
ListBaseT< GPUMaterialTexture > textures
GPUUniformAttrList uniform_attrs
GPUNodeLinkType link_type
ListBaseT< GPUInput > inputs
static constexpr GPUSamplerState internal_sampler()