Differential D16990 Diff 60050 source/blender/compositor/realtime_compositor/intern/shader_operation.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/compositor/realtime_compositor/intern/shader_operation.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| #include <memory> | #include <memory> | ||||
| #include <string> | #include <string> | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_map.hh" | #include "BLI_map.hh" | ||||
| #include "BLI_string_ref.hh" | #include "BLI_string_ref.hh" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "DNA_customdata_types.h" | #include "DNA_customdata_types.h" | ||||
| #include "GPU_context.h" | |||||
| #include "GPU_material.h" | #include "GPU_material.h" | ||||
| #include "GPU_shader.h" | #include "GPU_shader.h" | ||||
| #include "GPU_texture.h" | #include "GPU_texture.h" | ||||
| #include "GPU_uniform_buffer.h" | #include "GPU_uniform_buffer.h" | ||||
| #include "gpu_shader_create_info.hh" | #include "gpu_shader_create_info.hh" | ||||
| #include "NOD_derived_node_tree.hh" | #include "NOD_derived_node_tree.hh" | ||||
| ▲ Show 20 Lines • Show All 303 Lines • ▼ Show 20 Lines | void ShaderOperation::generate_code(void *thunk, | ||||
| /* The source shader is a compute shader with a main function that calls the dynamically | /* The source shader is a compute shader with a main function that calls the dynamically | ||||
| * generated evaluate function. The evaluate function includes the serialized GPU material graph | * generated evaluate function. The evaluate function includes the serialized GPU material graph | ||||
| * preceded by code that initialized the inputs of the operation. Additionally, the storer | * preceded by code that initialized the inputs of the operation. Additionally, the storer | ||||
| * functions that writes the outputs are defined outside the evaluate function. */ | * functions that writes the outputs are defined outside the evaluate function. */ | ||||
| shader_create_info.compute_source("gpu_shader_compositor_main.glsl"); | shader_create_info.compute_source("gpu_shader_compositor_main.glsl"); | ||||
| /* The main function is emitted in the shader before the evaluate function, so the evaluate | /* The main function is emitted in the shader before the evaluate function, so the evaluate | ||||
| * function needs to be forward declared here. */ | * function needs to be forward declared here. | ||||
| * NOTE(Metal): Metal does not require forward declarations. */ | |||||
| if (GPU_backend_get_type() != GPU_BACKEND_METAL) { | |||||
| shader_create_info.typedef_source_generated += "void evaluate();\n"; | shader_create_info.typedef_source_generated += "void evaluate();\n"; | ||||
| } | |||||
| operation->generate_code_for_outputs(shader_create_info); | operation->generate_code_for_outputs(shader_create_info); | ||||
| shader_create_info.compute_source_generated += "void evaluate()\n{\n"; | shader_create_info.compute_source_generated += "void evaluate()\n{\n"; | ||||
| operation->generate_code_for_inputs(material, shader_create_info); | operation->generate_code_for_inputs(material, shader_create_info); | ||||
| shader_create_info.compute_source_generated += code_generator_output->composite; | shader_create_info.compute_source_generated += code_generator_output->composite; | ||||
| Show All 36 Lines | |||||
| void ShaderOperation::generate_code_for_outputs(ShaderCreateInfo &shader_create_info) | void ShaderOperation::generate_code_for_outputs(ShaderCreateInfo &shader_create_info) | ||||
| { | { | ||||
| const std::string store_float_function_header = "void store_float(const uint id, float value)"; | const std::string store_float_function_header = "void store_float(const uint id, float value)"; | ||||
| const std::string store_vector_function_header = "void store_vector(const uint id, vec3 vector)"; | const std::string store_vector_function_header = "void store_vector(const uint id, vec3 vector)"; | ||||
| const std::string store_color_function_header = "void store_color(const uint id, vec4 color)"; | const std::string store_color_function_header = "void store_color(const uint id, vec4 color)"; | ||||
| /* The store functions are used by the node_compositor_store_output_[float|vector|color] | /* The store functions are used by the node_compositor_store_output_[float|vector|color] | ||||
| * functions but are only defined later as part of the compute source, so they need to be forward | * functions but are only defined later as part of the compute source, so they need to be forward | ||||
| * declared. */ | * declared. | ||||
| * NOTE(Metal): Metal does not require forward declarations. */ | |||||
| if (GPU_backend_get_type() != GPU_BACKEND_METAL) { | |||||
| shader_create_info.typedef_source_generated += store_float_function_header + ";\n"; | shader_create_info.typedef_source_generated += store_float_function_header + ";\n"; | ||||
| shader_create_info.typedef_source_generated += store_vector_function_header + ";\n"; | shader_create_info.typedef_source_generated += store_vector_function_header + ";\n"; | ||||
| shader_create_info.typedef_source_generated += store_color_function_header + ";\n"; | shader_create_info.typedef_source_generated += store_color_function_header + ";\n"; | ||||
| } | |||||
| /* Each of the store functions is essentially a single switch case on the given ID, so start by | /* Each of the store functions is essentially a single switch case on the given ID, so start by | ||||
| * opening the function with a curly bracket followed by opening a switch statement in each of | * opening the function with a curly bracket followed by opening a switch statement in each of | ||||
| * the functions. */ | * the functions. */ | ||||
| std::stringstream store_float_function; | std::stringstream store_float_function; | ||||
| std::stringstream store_vector_function; | std::stringstream store_vector_function; | ||||
| std::stringstream store_color_function; | std::stringstream store_color_function; | ||||
| const std::string store_function_start = "\n{\n switch (id) {\n"; | const std::string store_function_start = "\n{\n switch (id) {\n"; | ||||
| ▲ Show 20 Lines • Show All 129 Lines • Show Last 20 Lines | |||||