Commit: 7881629e1eb8e2fd6b01bf6b26c51790bb776a67 Author: Omar Emara Date: Mon Mar 21 08:52:32 2022 +0200 Branches: temp-viewport-compositor-compiler https://developer.blender.org/rB7881629e1eb8e2fd6b01bf6b26c51790bb776a67
Viewport Compositor: Add GPU material operation This patch adds supports for compiling nodes into a GPU material operation and ports existing node implementations to the appropriate interface. =================================================================== M source/blender/blenkernel/BKE_node.h M source/blender/draw/engines/compositor/compositor_engine.cc M source/blender/gpu/CMakeLists.txt M source/blender/gpu/GPU_material.h M source/blender/gpu/intern/gpu_codegen.cc M source/blender/gpu/intern/gpu_material.c M source/blender/gpu/intern/gpu_material_library.h M source/blender/gpu/intern/gpu_node_graph.c M source/blender/gpu/intern/gpu_node_graph.h M source/blender/gpu/intern/gpu_shader.cc M source/blender/gpu/intern/gpu_shader_create_info.hh M source/blender/gpu/intern/gpu_shader_dependency.cc M source/blender/gpu/shaders/common/gpu_shader_common_curves.glsl M source/blender/gpu/shaders/common/gpu_shader_common_math_util.glsl D source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_box_mask.glsl M source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_bright_contrast.glsl M source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_color_correction.glsl M source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_color_to_luminance.glsl D source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_ellipse_mask.glsl M source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_invert.glsl A source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_load_input.glsl M source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_luminance_matte.glsl D source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_split_viewer.glsl A source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_store_output.glsl A source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_type_conversion.glsl A source/blender/gpu/shaders/material/gpu_shader_material_transform_utils.glsl M source/blender/nodes/NOD_compositor_execute.hh M source/blender/nodes/composite/nodes/node_composite_alpha_over.cc M source/blender/nodes/composite/nodes/node_composite_brightness.cc M source/blender/nodes/composite/nodes/node_composite_channel_matte.cc M source/blender/nodes/composite/nodes/node_composite_chroma_matte.cc M source/blender/nodes/composite/nodes/node_composite_color_matte.cc M source/blender/nodes/composite/nodes/node_composite_color_spill.cc M source/blender/nodes/composite/nodes/node_composite_colorbalance.cc M source/blender/nodes/composite/nodes/node_composite_colorcorrection.cc M source/blender/nodes/composite/nodes/node_composite_curves.cc M source/blender/nodes/composite/nodes/node_composite_diff_matte.cc M source/blender/nodes/composite/nodes/node_composite_distance_matte.cc M source/blender/nodes/composite/nodes/node_composite_ellipsemask.cc M source/blender/nodes/composite/nodes/node_composite_exposure.cc M source/blender/nodes/composite/nodes/node_composite_gamma.cc M source/blender/nodes/composite/nodes/node_composite_hue_sat_val.cc M source/blender/nodes/composite/nodes/node_composite_huecorrect.cc M source/blender/nodes/composite/nodes/node_composite_invert.cc M source/blender/nodes/composite/nodes/node_composite_luma_matte.cc M source/blender/nodes/composite/nodes/node_composite_map_range.cc M source/blender/nodes/composite/nodes/node_composite_map_value.cc M source/blender/nodes/composite/nodes/node_composite_math.cc M source/blender/nodes/composite/nodes/node_composite_mixrgb.cc M source/blender/nodes/composite/nodes/node_composite_normal.cc M source/blender/nodes/composite/nodes/node_composite_posterize.cc M source/blender/nodes/composite/nodes/node_composite_premulkey.cc M source/blender/nodes/composite/nodes/node_composite_rgb.cc M source/blender/nodes/composite/nodes/node_composite_sepcomb_hsva.cc M source/blender/nodes/composite/nodes/node_composite_sepcomb_rgba.cc M source/blender/nodes/composite/nodes/node_composite_sepcomb_ycca.cc M source/blender/nodes/composite/nodes/node_composite_sepcomb_yuva.cc M source/blender/nodes/composite/nodes/node_composite_setalpha.cc M source/blender/nodes/composite/nodes/node_composite_val_to_rgb.cc M source/blender/nodes/composite/nodes/node_composite_value.cc M source/blender/nodes/intern/node_compositor_execute.cc =================================================================== diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 5cce6ccaf7a..c9bf7f2056a 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -129,6 +129,7 @@ class MFDataType; namespace viewport_compositor { class Context; class NodeOperation; +class GPUMaterialNode; } // namespace viewport_compositor } // namespace blender @@ -146,9 +147,12 @@ using NodeGatherSocketLinkOperationsFunction = using NodeGetCompositorOperationFunction = blender::viewport_compositor::NodeOperation *(*)(blender::viewport_compositor::Context &context, blender::nodes::DNode node); +using NodeGetCompositorGPUMaterialNodeFunction = + blender::viewport_compositor::GPUMaterialNode *(*)(blender::nodes::DNode node); #else typedef void *NodeGetCompositorOperationFunction; +typedef void *NodeGetCompositorGPUMaterialNodeFunction; typedef void *NodeMultiFunctionBuildFunction; typedef void *NodeGeometryExecFunction; typedef void *NodeDeclareFunction; @@ -331,9 +335,14 @@ typedef struct bNodeType { /* gpu */ NodeGPUExecFunction gpu_fn; - /* Get an instance of this node's compositor operation. */ + /* Get an instance of this node's compositor operation. Freeing the instance is the + * responsibility of the caller. */ NodeGetCompositorOperationFunction get_compositor_operation; + /* Get an instance of this node's compositor GPU material node. Freeing the instance is the + * responsibility of the caller. */ + NodeGetCompositorGPUMaterialNodeFunction get_compositor_gpu_material_node; + /* Build a multi-function for this node. */ NodeMultiFunctionBuildFunction build_multi_function; diff --git a/source/blender/draw/engines/compositor/compositor_engine.cc b/source/blender/draw/engines/compositor/compositor_engine.cc index 231bd763e4a..bfdf8ed3147 100644 --- a/source/blender/draw/engines/compositor/compositor_engine.cc +++ b/source/blender/draw/engines/compositor/compositor_engine.cc @@ -88,6 +88,7 @@ static void draw() DRWContext context(texture_pool); const Scene *scene = get_scene(); Evaluator evaluator(context, scene->nodetree); + evaluator.compile(); evaluator.evaluate(); } diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 924cf5a1c8f..1cdd60b65cf 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -281,9 +281,8 @@ set(GLSL_SRC shaders/common/gpu_shader_common_math.glsl shaders/common/gpu_shader_common_mix_rgb.glsl shaders/common/gpu_shader_common_hash.glsl - + shaders/compositor/material/gpu_shader_compositor_alpha_over.glsl - shaders/compositor/material/gpu_shader_compositor_box_mask.glsl shaders/compositor/material/gpu_shader_compositor_bright_contrast.glsl shaders/compositor/material/gpu_shader_compositor_channel_matte.glsl shaders/compositor/material/gpu_shader_compositor_chroma_matte.glsl @@ -294,19 +293,20 @@ set(GLSL_SRC shaders/compositor/material/gpu_shader_compositor_color_to_luminance.glsl shaders/compositor/material/gpu_shader_compositor_difference_matte.glsl shaders/compositor/material/gpu_shader_compositor_distance_matte.glsl - shaders/compositor/material/gpu_shader_compositor_ellipse_mask.glsl shaders/compositor/material/gpu_shader_compositor_exposure.glsl shaders/compositor/material/gpu_shader_compositor_gamma.glsl shaders/compositor/material/gpu_shader_compositor_hue_correct.glsl shaders/compositor/material/gpu_shader_compositor_hue_saturation_value.glsl shaders/compositor/material/gpu_shader_compositor_invert.glsl + shaders/compositor/material/gpu_shader_compositor_load_input.glsl shaders/compositor/material/gpu_shader_compositor_luminance_matte.glsl shaders/compositor/material/gpu_shader_compositor_map_value.glsl shaders/compositor/material/gpu_shader_compositor_normal.glsl shaders/compositor/material/gpu_shader_compositor_posterize.glsl shaders/compositor/material/gpu_shader_compositor_separate_combine.glsl shaders/compositor/material/gpu_shader_compositor_set_alpha.glsl - shaders/compositor/material/gpu_shader_compositor_split_viewer.glsl + shaders/compositor/material/gpu_shader_compositor_store_output.glsl + shaders/compositor/material/gpu_shader_compositor_type_conversion.glsl shaders/compositor/compositor_convert_color_to_float.glsl shaders/compositor/compositor_convert_float_to_color.glsl @@ -385,6 +385,7 @@ set(GLSL_SRC shaders/material/gpu_shader_material_tex_wave.glsl shaders/material/gpu_shader_material_tex_white_noise.glsl shaders/material/gpu_shader_material_toon.glsl + shaders/material/gpu_shader_material_transform_utils.glsl shaders/material/gpu_shader_material_translucent.glsl shaders/material/gpu_shader_material_transparent.glsl shaders/material/gpu_shader_material_uv_map.glsl diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index 0f8e10e71f1..84bdd4172e2 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -76,6 +76,7 @@ typedef enum eGPUType { GPU_TEX2D = 1002, GPU_TEX2D_ARRAY = 1003, GPU_TEX3D = 1004, + GPU_IMAGE_2D = 1005, /* GLSL Struct types */ GPU_CLOSURE = 1007, @@ -136,6 +137,7 @@ typedef struct GPUCodegenOutput { char *surface; char *volume; char *thickness; + char *compute; GPUShaderCreateInfo *create_info; } GPUCodegenOutput; @@ -146,6 +148,7 @@ GPUNodeLink *GPU_constant(const float *num); GPUNodeLink *GPU_uniform(const float *num); GPUNodeLink *GPU_attribute(GPUMaterial *mat, CustomDataType type, const char *name); GPUNodeLink *GPU_uniform_attribute(GPUMaterial *mat, const char *name, bool use_dupli); +GPUNodeLink *GPU_texture(GPUMaterial *material, eGPUSamplerState sampler_state); GPUNodeLink *GPU_image(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser, @@ -159,10 +162,7 @@ GPUNodeLink *GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *ro GPUNodeLink *GPU_volume_grid(GPUMaterial *mat, const char *name, eGPUVolumeDefaultValue default_value); -GPUNodeLink *GPU_render_pass(GPUMaterial *mat, - struct Scene *scene, - int view_layer, - eScenePassType pass_type); +GPUNodeLink *GPU_image_texture(GPUMaterial *material, eGPUTextureFormat format); bool GPU_link(GPUMaterial *mat, const char *name, ...); bool GPU_stack_link(GPUMaterial *mat, @@ -220,6 +220,7 @@ GPUMaterial *GPU_material_from_nodetree(struct Scene *scene, void *thunk); void GPU_material_compile(GPUMaterial *mat); +void GPU_material_free_single(GPUMaterial *material); void GPU_material_free(struct ListBase *gpumaterial); void GPU_materials_free(struct Main *bmain); @@ -237,6 +238,9 @@ struct Material *GPU_material_get_material(GPUMaterial *material); eGPUMaterialStatus GPU_material_status(GPUMaterial *mat); void GPU_material_status_set(GPUMaterial *mat, eGPUMaterialStatus status); +bool GPU_material_is_compute(GPUMaterial *material); +void GPU_material_is_compute_set(GPUMaterial *material, bool is_compute); + struct GPUUniformBuf *GPU_material_uniform_buffer_get(GPUMaterial *material); /** * Create dynamic UBO from parameters @@ -289,22 +293,20 @@ typedef struct GPUMaterialVolumeGrid { int users; } GPUMaterialVolumeGrid; -/* NOTE(fclem): Not to be confused with actual rendering passes. - * This is a reference to texture input which is the result of a rendering pass. */ -typedef struct GPUMaterialRenderPass { - struct GPUMaterialRenderPass *next, *prev; - struct Scene *scene; - int viewlayer; - eScenePassType pass_type; - char sampler_name[32]; /* Name of sampler in GLSL. */ - int users; - eGPUSamplerState sampler_state; -} GPUMaterialRenderPass; +/* A reference to a write only 2D image of a specific format. */ +typedef struct GPUMaterialImage { + struct GPUMaterialImage *next, *prev; + eGPUTextureFormat format; + char name_in_shader[32]; +} GPUMaterialImage; ListBase GPU_material_attributes(GPUMaterial *material); ListBase GPU_material_textures(GPUMaterial *material); ListBase GPU_material_volume_grids(GPUMaterial *material); -ListBase GPU_material_render_passes(GPUMaterial *material); +ListBase GPU_material_images(GPUMaterial *material); + +GPUMaterialTexture *GPU_material_get_link_texture(GPUNodeLink *link); +GPUMaterialImage *GPU_material_get_link_image(GPUNodeLink *link); typedef struct GPUUniformAttr { struct GPUUniformAttr *next, *prev; @@ -331,6 +333,19 @@ struct GHash *GPU_uniform_attr_list_hash_new(const char *info); void GPU_uniform_attr_list_copy(GPUUniformAttrList *dest, GPUUniformAttrList *src); void GPU_uniform_attr_list_free(GPUUniformAttrList *set); +typedef void (*GPUMaterialSetupFn)(void *thunk, GPUMaterial *material); +typedef void (*GPUMaterialCompileFn)(void *thunk, GPUMaterial *material); + +/* Construct and immediately compile a GPU material from a set of callbacks. The setup callback + * should set the appropriate flags or members to the material. The compile callback should + * construct the material graph by adding and linking the necessary GPU material graph nodes. The + * generate function should construct the needed shader by initializing the passed shader create + * info structure. The given thunk will be passed as the first parameter of each callback. */ +GPUMaterial *GPU_material_from_callbacks(GPUMaterialSetupFn setup_function, + GPUMaterialCompileFn compile_function, + GPUCodegenCallbackFn generate_function, + void *thunk); + #ifdef __cplusplus } #endif diff --git a/source/blender/gpu/intern/gpu_codegen.cc b/source/blender/gpu/intern/gpu_codegen.cc index db55c3b3be8..f31ec23b86d 100644 --- a/source/blender/gpu/intern/gpu_codegen.cc +++ b/source/blender/gpu/intern/gpu_codegen.cc @@ -186,8 +186,8 @@ static std::ostream &operator<<(std::ostream &stream, const GPUInput *input) return stream << input @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs