Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_codegen.cc
| Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Type > string conversion | /** \name Type > string conversion | ||||
| * \{ */ | * \{ */ | ||||
| #ifdef DEBUG | |||||
| # define SRC_NAME(io, link, list, type) \ | |||||
| link->node->name << "_" << io << BLI_findindex(&link->node->list, (const void *)link) << "_" \ | |||||
| << type | |||||
| #else | |||||
| # define SRC_NAME(io, list, link, type) type | |||||
| #endif | |||||
| static std::ostream &operator<<(std::ostream &stream, const GPUInput *input) | static std::ostream &operator<<(std::ostream &stream, const GPUInput *input) | ||||
| { | { | ||||
| switch (input->source) { | switch (input->source) { | ||||
| case GPU_SOURCE_FUNCTION_CALL: | case GPU_SOURCE_FUNCTION_CALL: | ||||
| case GPU_SOURCE_OUTPUT: | case GPU_SOURCE_OUTPUT: | ||||
| return stream << "tmp" << input->id; | return stream << SRC_NAME("in", input, inputs, "tmp") << input->id; | ||||
| case GPU_SOURCE_CONSTANT: | case GPU_SOURCE_CONSTANT: | ||||
| return stream << "cons" << input->id; | return stream << SRC_NAME("in", input, inputs, "cons") << input->id; | ||||
| case GPU_SOURCE_UNIFORM: | case GPU_SOURCE_UNIFORM: | ||||
| return stream << "node_tree.u" << input->id; | return stream << "node_tree.u" << input->id; | ||||
| case GPU_SOURCE_ATTR: | case GPU_SOURCE_ATTR: | ||||
| return stream << "var_attrs.v" << input->attr->id; | return stream << "var_attrs.v" << input->attr->id; | ||||
| case GPU_SOURCE_UNIFORM_ATTR: | case GPU_SOURCE_UNIFORM_ATTR: | ||||
| return stream << "unf_attrs[resource_id].attr" << input->uniform_attr->id; | return stream << "unf_attrs[resource_id].attr" << input->uniform_attr->id; | ||||
| case GPU_SOURCE_LAYER_ATTR: | case GPU_SOURCE_LAYER_ATTR: | ||||
| return stream << "attr_load_layer(" << input->layer_attr->hash_code << ")"; | return stream << "attr_load_layer(" << input->layer_attr->hash_code << ")"; | ||||
| case GPU_SOURCE_STRUCT: | case GPU_SOURCE_STRUCT: | ||||
| return stream << "strct" << input->id; | return stream << "strct" << input->id; | ||||
| case GPU_SOURCE_TEX: | case GPU_SOURCE_TEX: | ||||
| return stream << input->texture->sampler_name; | return stream << input->texture->sampler_name; | ||||
| case GPU_SOURCE_TEX_TILED_MAPPING: | case GPU_SOURCE_TEX_TILED_MAPPING: | ||||
| return stream << input->texture->tiled_mapping_name; | return stream << input->texture->tiled_mapping_name; | ||||
| default: | default: | ||||
| BLI_assert(0); | BLI_assert(0); | ||||
| return stream; | return stream; | ||||
| } | } | ||||
| } | } | ||||
| static std::ostream &operator<<(std::ostream &stream, const GPUOutput *output) | static std::ostream &operator<<(std::ostream &stream, const GPUOutput *output) | ||||
| { | { | ||||
| return stream << "tmp" << output->id; | return stream << SRC_NAME("out", output, outputs, "tmp") << output->id; | ||||
| } | } | ||||
| /* Trick type to change overload and keep a somewhat nice syntax. */ | /* Trick type to change overload and keep a somewhat nice syntax. */ | ||||
| struct GPUConstant : public GPUInput { | struct GPUConstant : public GPUInput { | ||||
| }; | }; | ||||
| /* Print data constructor (i.e: vec2(1.0f, 1.0f)). */ | /* Print data constructor (i.e: vec2(1.0f, 1.0f)). */ | ||||
| static std::ostream &operator<<(std::ostream &stream, const GPUConstant *input) | static std::ostream &operator<<(std::ostream &stream, const GPUConstant *input) | ||||
| ▲ Show 20 Lines • Show All 404 Lines • ▼ Show 20 Lines | void GPUCodegen::generate_graphs() | ||||
| if (!BLI_listbase_is_empty(&graph.outlink_compositor)) { | if (!BLI_listbase_is_empty(&graph.outlink_compositor)) { | ||||
| output.composite = graph_serialize(GPU_NODE_TAG_COMPOSITOR); | output.composite = graph_serialize(GPU_NODE_TAG_COMPOSITOR); | ||||
| } | } | ||||
| if (!BLI_listbase_is_empty(&graph.material_functions)) { | if (!BLI_listbase_is_empty(&graph.material_functions)) { | ||||
| std::stringstream eval_ss; | std::stringstream eval_ss; | ||||
| eval_ss << "\n/* Generated Functions */\n\n"; | eval_ss << "\n/* Generated Functions */\n\n"; | ||||
| LISTBASE_FOREACH (GPUNodeGraphFunctionLink *, func_link, &graph.material_functions) { | LISTBASE_FOREACH (GPUNodeGraphFunctionLink *, func_link, &graph.material_functions) { | ||||
| /* Untag every node in the graph to avoid serializing nodes from other functions */ | |||||
| LISTBASE_FOREACH (GPUNode *, node, &graph.nodes) { | |||||
| node->tag &= ~GPU_NODE_TAG_FUNCTION; | |||||
| } | |||||
| /* Tag only the nodes needed for the current function */ | |||||
| gpu_nodes_tag(func_link->outlink, GPU_NODE_TAG_FUNCTION); | |||||
| char *fn = graph_serialize(GPU_NODE_TAG_FUNCTION, func_link->outlink); | char *fn = graph_serialize(GPU_NODE_TAG_FUNCTION, func_link->outlink); | ||||
| eval_ss << "float " << func_link->name << "() {\n" << fn << "}\n\n"; | eval_ss << "float " << func_link->name << "() {\n" << fn << "}\n\n"; | ||||
| MEM_SAFE_FREE(fn); | MEM_SAFE_FREE(fn); | ||||
| } | } | ||||
| output.material_functions = extract_c_str(eval_ss); | output.material_functions = extract_c_str(eval_ss); | ||||
| /* Leave the function tags as they were before serialization */ | |||||
| LISTBASE_FOREACH (GPUNodeGraphFunctionLink *, funclink, &graph.material_functions) { | |||||
| gpu_nodes_tag(funclink->outlink, GPU_NODE_TAG_FUNCTION); | |||||
| } | |||||
| } | } | ||||
| LISTBASE_FOREACH (GPUMaterialAttribute *, attr, &graph.attributes) { | LISTBASE_FOREACH (GPUMaterialAttribute *, attr, &graph.attributes) { | ||||
| BLI_hash_mm2a_add(&hm2a_, (uchar *)attr->name, strlen(attr->name)); | BLI_hash_mm2a_add(&hm2a_, (uchar *)attr->name, strlen(attr->name)); | ||||
| } | } | ||||
| hash_ = BLI_hash_mm2a_end(&hm2a_); | hash_ = BLI_hash_mm2a_end(&hm2a_); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 244 Lines • Show Last 20 Lines | |||||