33 GPUNodeLink *link = MEM_cnew<GPUNodeLink>(
"GPUNodeLink");
43 if (link->
users < 0) {
44 fprintf(stderr,
"gpu_node_link_free: negative refcount\n");
47 if (link->
users == 0) {
59 GPUNode *node = MEM_cnew<GPUNode>(
"GPUNode");
77 if (
STR_ELEM(name,
"set_value",
"set_rgb",
"set_rgba") && (input->type == type)) {
80 switch (input->source) {
85 input->uniform_attr->users++;
88 input->layer_attr->users++;
91 input->texture->users++;
100 input->link->users++;
108 input = MEM_cnew<GPUInput>(
"GPUInput");
123 input->texture = link->
texture;
127 input->texture = link->
texture;
131 input->attr = link->
attr;
161 memcpy(input->vec, link->
data, type *
sizeof(
float));
183 BLI_assert_msg(0,
"No gpu function for non-supported eNodeSocketDatatype");
236 else if ((material !=
nullptr) &&
248 GPUOutput *output = MEM_cnew<GPUOutput>(
"GPUOutput");
256 output->link->output =
output;
273 int cmps = strcmp(attr_a->
name, attr_b->name);
275 return cmps > 0 ? 1 : 0;
278 return (attr_a->
use_dupli && !attr_b->use_dupli);
292 if (set_a->
hash_code != set_b->hash_code || set_a->
count != set_b->count) {
299 for (; attr_a && attr_b; attr_a = attr_a->
next, attr_b = attr_b->
next) {
305 return attr_a || attr_b;
340 attr->id = next_id++;
355 switch (attr->
type) {
361 BLI_assert_msg(0,
"GPUVertAttr Prefix type not found : This should not happen!");
376 if (attr->
name[0] !=
'\0') {
387 const bool is_default_color,
388 const bool is_hair_length)
391 int num_attributes = 0;
393 for (; attr; attr = attr->
next) {
403 if (attr ==
nullptr) {
404 attr = MEM_cnew<GPUMaterialAttribute>(__func__);
410 attr->
id = num_attributes;
414 if (attr !=
nullptr) {
430 for (; attr; attr = attr->
next) {
438 attr = MEM_cnew<GPUUniformAttr>(__func__);
447 if (attr !=
nullptr) {
458 ListBase *attrs = &graph->layer_attrs;
461 for (; attr; attr = attr->
next) {
468 if (attr ==
nullptr) {
469 attr = MEM_cnew<GPULayerAttr>(__func__);
475 if (attr !=
nullptr) {
485 GPUTexture **colorband,
491 int num_textures = 0;
494 if (
tex->
ima == ima &&
tex->colorband == colorband &&
tex->sky == sky &&
495 tex->sampler_state == sampler_state)
503 if (
tex ==
nullptr) {
504 tex = MEM_cnew<GPUMaterialTexture>(__func__);
506 if (iuser !=
nullptr) {
508 tex->iuser_available =
true;
510 tex->colorband = colorband;
512 tex->sampler_state = sampler_state;
513 SNPRINTF(
tex->sampler_name,
"samp%d", num_textures);
515 SNPRINTF(
tex->tiled_mapping_name,
"tsamp%d", num_textures);
538 if (attr ==
nullptr) {
554 if (attr ==
nullptr) {
570 if (attr ==
nullptr) {
601 if (attr ==
nullptr) {
658 graph, ima, iuser,
nullptr,
nullptr,
false, sampler_state);
675 graph,
nullptr,
nullptr,
nullptr, sky,
false, sampler_state);
688 graph, ima, iuser,
nullptr,
nullptr,
true, sampler_state);
692 (*r_image_tiled_link)->texture =
texture;
696 (*r_image_tiled_mapping_link)->texture =
texture;
725 fprintf(stderr,
"GPU failed to find function %s\n", name);
732 for (i = 0; i < function->totparam; i++) {
760 int i, totin, totout;
764 fprintf(stderr,
"GPU failed to find function %s\n", name);
773 for (i = 0; !in[i].end; i++) {
782 for (i = 0; !out[i].end; i++) {
790 for (i = 0; i < function->totparam; i++) {
841 switch (input->source) {
843 input->attr->users--;
846 input->uniform_attr->users--;
849 input->layer_attr->users--;
852 input->texture->users--;
874 output->link->output =
nullptr;
889 graph->outlink_surface =
nullptr;
890 graph->outlink_volume =
nullptr;
891 graph->outlink_displacement =
nullptr;
892 graph->outlink_thickness =
nullptr;
907 if (graph->used_libraries) {
909 graph->used_libraries =
nullptr;
919 if (!link || !link->
output) {
924 if (node->tag & tag) {
974 if (attr->users == 0) {
985 if (
tex->users == 0) {
993 if (attr->users == 0) {
1000 if (attr->users == 0) {
#define BLI_assert_msg(a, msg)
unsigned int BLI_ghashutil_uinthash(unsigned int key)
unsigned int BLI_ghashutil_strhash_p(const void *ptr)
GHash * BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
#define LISTBASE_FOREACH(type, var, list)
void BLI_freelinkN(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
void void void void void void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src) ATTR_NONNULL(1
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
void void BLI_listbase_sort(struct ListBase *listbase, int(*cmp)(const void *, const void *)) ATTR_NONNULL(1
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define STRNCPY(dst, src)
#define SNPRINTF(dst, format,...)
@ GPU_MATFLAG_OBJECT_INFO
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
#define GPU_MAX_UNIFORM_ATTR
Read Guarded memory(de)allocation.
local_group_size(16, 16) .push_constant(Type b
local_group_size(16, 16) .push_constant(Type texture
GPUTexture ** gpu_material_ramp_texture_row_set(GPUMaterial *mat, int size, const float *pixels, float *r_row)
GPUTexture ** gpu_material_sky_texture_layer_set(GPUMaterial *mat, int width, int height, const float *pixels, float *row)
GPUNodeGraph * gpu_material_node_graph(GPUMaterial *material)
GPUFunction * gpu_material_library_use_function(GSet *used_libraries, const char *name)
GPUNodeLink * GPU_constant(const float *num)
GPUNodeLink * GPU_attribute_hair_length(GPUMaterial *mat)
static GPUNodeLink * gpu_node_link_create()
GPUNodeLink * GPU_layer_attribute(GPUMaterial *mat, const char *name)
GPUNodeLink * GPU_attribute_default_color(GPUMaterial *mat)
bool GPU_stack_link(GPUMaterial *material, const bNode *bnode, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
static GPUMaterialAttribute * gpu_node_graph_add_attribute(GPUNodeGraph *graph, eCustomDataType type, const char *name, const bool is_default_color, const bool is_hair_length)
static GPUNode * gpu_node_create(const char *name)
static void gpu_node_free(GPUNode *node)
static void gpu_inputs_free(ListBase *inputs)
static void gpu_node_output(GPUNode *node, const eGPUType type, GPUNodeLink **link)
GPUNodeLink * GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *r_row)
static void gpu_node_input_socket(GPUMaterial *material, const bNode *bnode, GPUNode *node, GPUNodeStack *sock, const int index)
static GPULayerAttr * gpu_node_graph_add_layer_attribute(GPUNodeGraph *graph, const char *name)
static GPUUniformAttr * gpu_node_graph_add_uniform_attribute(GPUNodeGraph *graph, const char *name, bool use_dupli)
void gpu_nodes_tag(GPUNodeLink *link, eGPUNodeTag tag)
void gpu_node_graph_finalize_uniform_attrs(GPUNodeGraph *graph)
static void gpu_node_link_free(GPUNodeLink *link)
static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const eGPUType type)
GPUNodeLink * GPU_attribute(GPUMaterial *mat, const eCustomDataType type, const char *name)
void gpu_node_graph_optimize(GPUNodeGraph *graph)
GPUNodeLink * GPU_image(GPUMaterial *mat, Image *ima, ImageUser *iuser, GPUSamplerState sampler_state)
void GPU_uniform_attr_list_copy(GPUUniformAttrList *dest, const GPUUniformAttrList *src)
static uint uniform_attr_list_hash(const void *key)
GHash * GPU_uniform_attr_list_hash_new(const char *info)
void GPU_uniform_attr_list_free(GPUUniformAttrList *set)
GPUNodeLink * GPU_uniform_attribute(GPUMaterial *mat, const char *name, bool use_dupli, uint32_t *r_hash)
GPUNodeLink * GPU_image_sky(GPUMaterial *mat, int width, int height, const float *pixels, float *layer, GPUSamplerState sampler_state)
void gpu_node_graph_free(GPUNodeGraph *graph)
void gpu_node_graph_prune_unused(GPUNodeGraph *graph)
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 char attr_prefix_get(const GPUMaterialAttribute *attr)
static bool uniform_attr_list_cmp(const void *a, const void *b)
static GPUMaterialTexture * gpu_node_graph_add_texture(GPUNodeGraph *graph, Image *ima, ImageUser *iuser, GPUTexture **colorband, GPUTexture **sky, bool is_tiled, GPUSamplerState sampler_state)
static bool gpu_stack_link_v(GPUMaterial *material, const bNode *bnode, const char *name, GPUNodeStack *in, GPUNodeStack *out, va_list params)
GPUNodeLink * GPU_differentiate_float_function(const char *function_name)
static int uniform_attr_sort_cmp(const void *a, const void *b)
static const char * gpu_uniform_set_function_from_type(eNodeSocketDatatype type)
void gpu_node_graph_free_nodes(GPUNodeGraph *graph)
GPUNodeLink * GPU_attribute_with_default(GPUMaterial *mat, const eCustomDataType type, const char *name, eGPUDefaultValue default_value)
static GPUNodeLink * gpu_uniformbuffer_link(GPUMaterial *mat, const bNode *node, GPUNodeStack *stack, const int index, const eNodeSocketInOut in_out)
bool GPU_link(GPUMaterial *mat, const char *name,...)
GPUNodeLink * GPU_uniform(const float *num)
@ GPU_NODE_TAG_DISPLACEMENT
@ GPU_NODE_TAG_COMPOSITOR
@ GPU_SOURCE_FUNCTION_CALL
@ GPU_SOURCE_TEX_TILED_MAPPING
@ GPU_SOURCE_UNIFORM_ATTR
@ GPU_NODE_LINK_IMAGE_SKY
@ GPU_NODE_LINK_LAYER_ATTR
@ GPU_NODE_LINK_IMAGE_TILED
@ GPU_NODE_LINK_IMAGE_TILED_MAPPING
@ GPU_NODE_LINK_COLORBAND
@ GPU_NODE_LINK_UNIFORM_ATTR
@ GPU_NODE_LINK_DIFFERENTIATE_FLOAT_FN
void MEM_freeN(void *vmemh)
void *(* MEM_dupallocN)(const void *vmemh)
eGPUDefaultValue default_value
GPUMaterialAttribute * next
GPUMaterialTexture * texture
GPULayerAttr * layer_attr
GPUNodeLinkType link_type
GPUMaterialAttribute * attr
const char * function_name
GPUUniformAttr * uniform_attr
static constexpr GPUSamplerState internal_sampler()