From 8fb2ff458ba579dba08bfdf57d043ad158b5db07 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Mon, 17 Jan 2022 14:32:03 +0100 Subject: GPUShaderCreateInfo for interface abstraction This is a first part of the Shader Create Info system could be. A shader create info provides a way to define shader structure, resources and interfaces. This makes for a quick way to provide backend agnostic binding informations while also making shader variations easy to declare. - Clear source input (only one file). Cleans up the GPU api since we can create a shader from one descriptor - Resources and interfaces are generated by the backend (much simpler than parsing). - Bindings are explicit from position in the array. - GPUShaderInterface becomes a trivial translation of enums and string copy. - No external dependency to third party lib. - Cleaner code, less fragmentation of resources in several libs. - Easy to modify / extend at runtime. - no parser involve, very easy to code. - Does not hold any data, can be static and kept on disc. - Could hold precompiled bytecode for static shaders. This also includes a new global dependency system. GLSL shaders can include other sources by using #pragma BLENDER_REQUIRE(...). This patch already migrated several builtin shaders. Other shaders should be migrated one at a time, and could be done inside master. There is a new compile directive `WITH_GPU_SHADER_BUILDER` this is an optional directive for linting shaders to increase turn around time. What is remaining: - pyGPU API {T94975} - Migration of other shaders. This could be a community effort. Reviewed By: jbakker Maniphest Tasks: T94975 Differential Revision: https://developer.blender.org/D13360 --- source/blender/gpu/CMakeLists.txt | 452 ++++++++++------ source/blender/gpu/GPU_immediate.h | 1 + source/blender/gpu/GPU_shader.h | 3 + source/blender/gpu/GPU_shader_shared.h | 82 +++ source/blender/gpu/intern/gpu_immediate.cc | 6 + source/blender/gpu/intern/gpu_init_exit.c | 8 + source/blender/gpu/intern/gpu_shader.cc | 192 +++++++ source/blender/gpu/intern/gpu_shader_builder.cc | 102 ++++ .../blender/gpu/intern/gpu_shader_builder_stubs.cc | 258 +++++++++ source/blender/gpu/intern/gpu_shader_builtin.c | 244 ++++----- .../blender/gpu/intern/gpu_shader_create_info.cc | 173 ++++++ .../blender/gpu/intern/gpu_shader_create_info.hh | 595 +++++++++++++++++++++ .../gpu/intern/gpu_shader_create_info_private.hh | 46 ++ source/blender/gpu/intern/gpu_shader_dependency.cc | 197 +++++++ .../gpu/intern/gpu_shader_dependency_private.h | 44 ++ source/blender/gpu/intern/gpu_shader_info_baked.cc | 24 + source/blender/gpu/intern/gpu_shader_interface.hh | 26 +- source/blender/gpu/intern/gpu_shader_private.hh | 12 +- .../blender/gpu/intern/gpu_shader_shared_utils.h | 110 ++++ source/blender/gpu/opengl/gl_backend.cc | 2 + source/blender/gpu/opengl/gl_context.hh | 1 + source/blender/gpu/opengl/gl_shader.cc | 440 ++++++++++++++- source/blender/gpu/opengl/gl_shader.hh | 12 +- source/blender/gpu/opengl/gl_shader_interface.cc | 133 +++++ source/blender/gpu/opengl/gl_shader_interface.hh | 2 + .../shaders/gpu_shader_2D_area_borders_frag.glsl | 3 +- .../shaders/gpu_shader_2D_area_borders_vert.glsl | 3 +- .../gpu/shaders/gpu_shader_2D_flat_color_vert.glsl | 3 +- .../gpu_shader_2D_image_multi_rect_vert.glsl | 4 +- .../gpu/shaders/gpu_shader_2D_image_rect_vert.glsl | 2 + .../gpu/shaders/gpu_shader_2D_image_vert.glsl | 3 +- .../shaders/gpu_shader_2D_line_dashed_frag.glsl | 3 + ...u_shader_2D_line_dashed_uniform_color_vert.glsl | 3 +- .../gpu/shaders/gpu_shader_2D_nodelink_frag.glsl | 3 +- .../gpu/shaders/gpu_shader_2D_nodelink_vert.glsl | 54 +- .../gpu_shader_2D_point_uniform_size_aa_vert.glsl | 2 + ...ader_2D_point_uniform_size_outline_aa_vert.glsl | 3 +- ...r_2D_point_varying_size_varying_color_vert.glsl | 3 +- .../shaders/gpu_shader_2D_smooth_color_frag.glsl | 3 +- .../shaders/gpu_shader_2D_smooth_color_vert.glsl | 3 +- source/blender/gpu/shaders/gpu_shader_2D_vert.glsl | 8 +- .../shaders/gpu_shader_2D_widget_base_frag.glsl | 2 + .../shaders/gpu_shader_2D_widget_base_vert.glsl | 15 +- .../shaders/gpu_shader_2D_widget_shadow_frag.glsl | 2 + .../shaders/gpu_shader_2D_widget_shadow_vert.glsl | 5 + .../gpu_shader_3D_clipped_uniform_color_vert.glsl | 3 +- .../gpu/shaders/gpu_shader_3D_flat_color_vert.glsl | 9 +- .../gpu/shaders/gpu_shader_3D_image_vert.glsl | 2 + ...u_shader_3D_line_dashed_uniform_color_vert.glsl | 7 +- .../gpu/shaders/gpu_shader_3D_normal_vert.glsl | 3 +- .../shaders/gpu_shader_3D_passthrough_vert.glsl | 6 +- ...der_3D_point_fixed_size_varying_color_vert.glsl | 3 +- .../gpu_shader_3D_point_uniform_size_aa_vert.glsl | 9 +- ...r_3D_point_varying_size_varying_color_vert.glsl | 3 +- .../gpu/shaders/gpu_shader_3D_polyline_frag.glsl | 7 +- .../gpu/shaders/gpu_shader_3D_polyline_geom.glsl | 11 +- .../gpu/shaders/gpu_shader_3D_polyline_vert.glsl | 9 +- .../shaders/gpu_shader_3D_smooth_color_frag.glsl | 3 +- .../shaders/gpu_shader_3D_smooth_color_vert.glsl | 9 +- source/blender/gpu/shaders/gpu_shader_3D_vert.glsl | 9 +- .../gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl | 6 + .../gpu/shaders/gpu_shader_checker_frag.glsl | 3 +- .../gpu/shaders/gpu_shader_colorspace_lib.glsl | 2 + .../gpu/shaders/gpu_shader_common_obinfos_lib.glsl | 3 + .../gpu/shaders/gpu_shader_diag_stripes_frag.glsl | 3 +- .../gpu_shader_flat_color_alpha_test_0_frag.glsl | 3 +- .../gpu/shaders/gpu_shader_flat_color_frag.glsl | 3 +- .../gpu/shaders/gpu_shader_flat_id_frag.glsl | 3 +- .../blender/gpu/shaders/gpu_shader_geometry.glsl | 5 +- .../shaders/gpu_shader_gpencil_stroke_frag.glsl | 8 +- .../shaders/gpu_shader_gpencil_stroke_geom.glsl | 138 ++--- .../shaders/gpu_shader_gpencil_stroke_vert.glsl | 14 +- .../gpu/shaders/gpu_shader_image_color_frag.glsl | 3 +- .../shaders/gpu_shader_image_desaturate_frag.glsl | 3 +- .../blender/gpu/shaders/gpu_shader_image_frag.glsl | 3 +- .../gpu_shader_image_modulate_alpha_frag.glsl | 2 + .../gpu_shader_image_overlays_merge_frag.glsl | 2 + ...pu_shader_image_overlays_stereo_merge_frag.glsl | 8 +- .../gpu_shader_image_shuffle_color_frag.glsl | 9 +- .../gpu_shader_image_varying_color_frag.glsl | 3 +- ...instance_variying_size_variying_color_vert.glsl | 9 +- .../shaders/gpu_shader_keyframe_shape_frag.glsl | 2 + .../shaders/gpu_shader_keyframe_shape_vert.glsl | 10 +- .../gpu_shader_point_uniform_color_aa_frag.glsl | 3 +- ...shader_point_uniform_color_outline_aa_frag.glsl | 3 +- .../gpu_shader_point_varying_color_frag.glsl | 3 +- ...oint_varying_color_varying_outline_aa_frag.glsl | 3 +- .../shaders/gpu_shader_simple_lighting_frag.glsl | 17 +- .../blender/gpu/shaders/gpu_shader_text_frag.glsl | 3 +- .../blender/gpu/shaders/gpu_shader_text_vert.glsl | 3 +- .../gpu/shaders/gpu_shader_uniform_color_frag.glsl | 3 +- .../gpu/shaders/infos/gpu_clip_planes_info.hh | 29 + .../gpu/shaders/infos/gpu_interface_info.hh | 33 ++ .../infos/gpu_shader_2D_area_borders_info.hh | 39 ++ .../shaders/infos/gpu_shader_2D_checker_info.hh | 36 ++ .../infos/gpu_shader_2D_diag_stripes_info.hh | 37 ++ .../shaders/infos/gpu_shader_2D_flat_color_info.hh | 38 ++ .../infos/gpu_shader_2D_image_color_info.hh | 30 ++ .../gpu_shader_2D_image_desaturate_color_info.hh | 31 ++ .../gpu/shaders/infos/gpu_shader_2D_image_info.hh | 39 ++ .../gpu_shader_2D_image_overlays_merge_info.hh | 39 ++ ...u_shader_2D_image_overlays_stereo_merge_info.hh | 36 ++ .../infos/gpu_shader_2D_image_rect_color_info.hh | 40 ++ .../gpu_shader_2D_image_shuffle_color_info.hh | 31 ++ ...gpu_shader_2D_line_dashed_uniform_color_info.hh | 35 ++ .../shaders/infos/gpu_shader_2D_nodelink_info.hh | 72 +++ ..._2D_point_uniform_size_uniform_color_aa_info.hh | 36 ++ ...t_uniform_size_uniform_color_outline_aa_info.hh | 38 ++ ...der_2D_point_varying_size_varying_color_info.hh | 36 ++ .../infos/gpu_shader_2D_smooth_color_info.hh | 37 ++ .../infos/gpu_shader_2D_uniform_color_info.hh | 35 ++ .../shaders/infos/gpu_shader_3D_depth_only_info.hh | 38 ++ .../shaders/infos/gpu_shader_3D_flat_color_info.hh | 42 ++ .../gpu_shader_3D_image_modulate_alpha_info.hh | 38 ++ ...gpu_shader_3D_line_dashed_uniform_color_info.hh | 35 ++ .../gpu/shaders/infos/gpu_shader_3D_point_info.hh | 62 +++ .../shaders/infos/gpu_shader_3D_polyline_info.hh | 33 ++ .../infos/gpu_shader_3D_smooth_color_info.hh | 41 ++ .../infos/gpu_shader_3D_uniform_color_info.hh | 39 ++ .../infos/gpu_shader_gpencil_stroke_info.hh | 51 ++ ...der_instance_varying_color_varying_size_info.hh | 39 ++ .../infos/gpu_shader_keyframe_shape_info.hh | 47 ++ .../infos/gpu_shader_simple_lighting_info.hh | 40 ++ .../gpu/shaders/infos/gpu_shader_text_info.hh | 46 ++ .../infos/gpu_srgb_to_framebuffer_space_info.hh | 27 + 125 files changed, 4485 insertions(+), 508 deletions(-) create mode 100644 source/blender/gpu/GPU_shader_shared.h create mode 100644 source/blender/gpu/intern/gpu_shader_builder.cc create mode 100644 source/blender/gpu/intern/gpu_shader_builder_stubs.cc create mode 100644 source/blender/gpu/intern/gpu_shader_create_info.cc create mode 100644 source/blender/gpu/intern/gpu_shader_create_info.hh create mode 100644 source/blender/gpu/intern/gpu_shader_create_info_private.hh create mode 100644 source/blender/gpu/intern/gpu_shader_dependency.cc create mode 100644 source/blender/gpu/intern/gpu_shader_dependency_private.h create mode 100644 source/blender/gpu/intern/gpu_shader_info_baked.cc create mode 100644 source/blender/gpu/intern/gpu_shader_shared_utils.h create mode 100644 source/blender/gpu/shaders/infos/gpu_clip_planes_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_interface_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_area_borders_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_checker_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_diag_stripes_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_flat_color_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_image_color_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_image_desaturate_color_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_image_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_image_overlays_merge_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_image_overlays_stereo_merge_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_image_rect_color_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_image_shuffle_color_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_line_dashed_uniform_color_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_nodelink_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_aa_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_outline_aa_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_point_varying_size_varying_color_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_smooth_color_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_uniform_color_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_3D_depth_only_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_3D_flat_color_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_3D_image_modulate_alpha_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_3D_line_dashed_uniform_color_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_3D_point_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_3D_smooth_color_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_3D_uniform_color_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_gpencil_stroke_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_instance_varying_color_varying_size_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_keyframe_shape_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_simple_lighting_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_shader_text_info.hh create mode 100644 source/blender/gpu/shaders/infos/gpu_srgb_to_framebuffer_space_info.hh (limited to 'source/blender/gpu') diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 2987709c875..a525986e1cd 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -83,6 +83,8 @@ set(SRC intern/gpu_select_sample_query.cc intern/gpu_shader.cc intern/gpu_shader_builtin.c + intern/gpu_shader_create_info.cc + intern/gpu_shader_dependency.cc intern/gpu_shader_interface.cc intern/gpu_shader_log.cc intern/gpu_state.cc @@ -135,6 +137,7 @@ set(SRC GPU_primitive.h GPU_select.h GPU_shader.h + GPU_shader_shared.h GPU_state.h GPU_texture.h GPU_uniform_buffer.h @@ -159,6 +162,8 @@ set(SRC intern/gpu_private.h intern/gpu_query.hh intern/gpu_select_private.h + intern/gpu_shader_create_info.hh + intern/gpu_shader_create_info_private.hh intern/gpu_shader_interface.hh intern/gpu_shader_private.hh intern/gpu_state_private.hh @@ -197,174 +202,250 @@ if(NOT WITH_SYSTEM_GLEW) ) endif() -data_to_c_simple(shaders/gpu_shader_depth_only_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_uniform_color_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_checker_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_diag_stripes_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_simple_lighting_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_flat_color_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_flat_id_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_area_borders_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_area_borders_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_widget_base_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_widget_base_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_widget_shadow_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_widget_shadow_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_nodelink_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_nodelink_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_flat_color_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_line_dashed_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_smooth_color_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_smooth_color_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_image_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_image_rect_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_image_multi_rect_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_image_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_image_desaturate_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_image_overlays_merge_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_image_overlays_stereo_merge_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_image_modulate_alpha_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_image_shuffle_color_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_image_color_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_image_varying_color_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_image_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_normal_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_flat_color_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_polyline_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_polyline_geom.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_polyline_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_smooth_color_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_smooth_color_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_passthrough_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl SRC) - -data_to_c_simple(shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl SRC) - -data_to_c_simple(shaders/gpu_shader_point_uniform_color_aa_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_point_varying_color_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl SRC) - -data_to_c_simple(shaders/gpu_shader_text_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_text_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_keyframe_shape_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_keyframe_shape_frag.glsl SRC) - -data_to_c_simple(shaders/gpu_shader_codegen_lib.glsl SRC) - -data_to_c_simple(shaders/gpu_shader_geometry.glsl SRC) - -data_to_c_simple(shaders/material/gpu_shader_material_add_shader.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_ambient_occlusion.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_anisotropic.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_attribute.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_background.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_bevel.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_wavelength.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_blackbody.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_bright_contrast.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_bump.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_camera.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_clamp.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_color_ramp.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_color_util.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_combine_hsv.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_combine_rgb.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_combine_xyz.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_diffuse.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_displacement.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_eevee_specular.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_emission.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_float_curve.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_fractal_noise.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_fresnel.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_gamma.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_geometry.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_glass.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_glossy.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_hair_info.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_hash.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_holdout.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_hue_sat_val.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_invert.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_layer_weight.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_light_falloff.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_light_path.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_mapping.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_map_range.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_math.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_math_util.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_mix_rgb.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_mix_shader.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_noise.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_normal.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_normal_map.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_object_info.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_output_aov.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_output_material.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_output_world.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_particle_info.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_principled.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_refraction.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_rgb_curves.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_rgb_to_bw.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_separate_hsv.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_separate_rgb.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_separate_xyz.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_set.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_shader_to_rgba.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_squeeze.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_subsurface_scattering.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_tangent.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_tex_brick.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_tex_checker.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_tex_environment.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_tex_gradient.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_tex_image.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_tex_magic.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_tex_musgrave.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_tex_noise.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_tex_sky.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_texture_coordinates.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_tex_voronoi.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_tex_wave.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_tex_white_noise.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_toon.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_translucent.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_transparent.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_uv_map.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_vector_curves.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_vector_displacement.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_vector_math.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_vector_rotate.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_velvet.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_vertex_color.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_volume_absorption.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_volume_info.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_volume_principled.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_volume_scatter.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_wireframe.glsl SRC) -data_to_c_simple(shaders/material/gpu_shader_material_world_normals.glsl SRC) - -data_to_c_simple(shaders/gpu_shader_gpencil_stroke_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_gpencil_stroke_frag.glsl SRC) -data_to_c_simple(shaders/gpu_shader_gpencil_stroke_geom.glsl SRC) - -data_to_c_simple(shaders/gpu_shader_cfg_world_clip_lib.glsl SRC) -data_to_c_simple(shaders/gpu_shader_colorspace_lib.glsl SRC) - -data_to_c_simple(shaders/gpu_shader_common_obinfos_lib.glsl SRC) +set(GLSL_SRC + GPU_shader_shared.h + + shaders/gpu_shader_depth_only_frag.glsl + shaders/gpu_shader_uniform_color_frag.glsl + shaders/gpu_shader_checker_frag.glsl + shaders/gpu_shader_diag_stripes_frag.glsl + shaders/gpu_shader_simple_lighting_frag.glsl + shaders/gpu_shader_flat_color_frag.glsl + shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl + shaders/gpu_shader_flat_id_frag.glsl + shaders/gpu_shader_2D_vert.glsl + shaders/gpu_shader_2D_area_borders_vert.glsl + shaders/gpu_shader_2D_area_borders_frag.glsl + shaders/gpu_shader_2D_widget_base_vert.glsl + shaders/gpu_shader_2D_widget_base_frag.glsl + shaders/gpu_shader_2D_widget_shadow_vert.glsl + shaders/gpu_shader_2D_widget_shadow_frag.glsl + shaders/gpu_shader_2D_nodelink_frag.glsl + shaders/gpu_shader_2D_nodelink_vert.glsl + shaders/gpu_shader_2D_flat_color_vert.glsl + shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl + shaders/gpu_shader_2D_line_dashed_frag.glsl + shaders/gpu_shader_2D_smooth_color_vert.glsl + shaders/gpu_shader_2D_smooth_color_frag.glsl + shaders/gpu_shader_2D_image_vert.glsl + shaders/gpu_shader_2D_image_rect_vert.glsl + shaders/gpu_shader_2D_image_multi_rect_vert.glsl + shaders/gpu_shader_image_frag.glsl + shaders/gpu_shader_image_desaturate_frag.glsl + shaders/gpu_shader_image_overlays_merge_frag.glsl + shaders/gpu_shader_image_overlays_stereo_merge_frag.glsl + shaders/gpu_shader_image_modulate_alpha_frag.glsl + shaders/gpu_shader_image_shuffle_color_frag.glsl + shaders/gpu_shader_image_color_frag.glsl + shaders/gpu_shader_image_varying_color_frag.glsl + shaders/gpu_shader_3D_image_vert.glsl + shaders/gpu_shader_3D_vert.glsl + shaders/gpu_shader_3D_normal_vert.glsl + shaders/gpu_shader_3D_flat_color_vert.glsl + shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl + shaders/gpu_shader_3D_polyline_frag.glsl + shaders/gpu_shader_3D_polyline_geom.glsl + shaders/gpu_shader_3D_polyline_vert.glsl + shaders/gpu_shader_3D_smooth_color_vert.glsl + shaders/gpu_shader_3D_smooth_color_frag.glsl + shaders/gpu_shader_3D_passthrough_vert.glsl + shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl + + shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl + + shaders/gpu_shader_point_uniform_color_aa_frag.glsl + shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl + shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl + shaders/gpu_shader_point_varying_color_frag.glsl + shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl + shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl + shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl + shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl + shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl + shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl + + shaders/gpu_shader_text_vert.glsl + shaders/gpu_shader_text_frag.glsl + shaders/gpu_shader_keyframe_shape_vert.glsl + shaders/gpu_shader_keyframe_shape_frag.glsl + + shaders/gpu_shader_codegen_lib.glsl + + shaders/gpu_shader_geometry.glsl + + shaders/material/gpu_shader_material_add_shader.glsl + shaders/material/gpu_shader_material_ambient_occlusion.glsl + shaders/material/gpu_shader_material_anisotropic.glsl + shaders/material/gpu_shader_material_attribute.glsl + shaders/material/gpu_shader_material_background.glsl + shaders/material/gpu_shader_material_bevel.glsl + shaders/material/gpu_shader_material_wavelength.glsl + shaders/material/gpu_shader_material_blackbody.glsl + shaders/material/gpu_shader_material_bright_contrast.glsl + shaders/material/gpu_shader_material_bump.glsl + shaders/material/gpu_shader_material_camera.glsl + shaders/material/gpu_shader_material_clamp.glsl + shaders/material/gpu_shader_material_color_ramp.glsl + shaders/material/gpu_shader_material_color_util.glsl + shaders/material/gpu_shader_material_combine_hsv.glsl + shaders/material/gpu_shader_material_combine_rgb.glsl + shaders/material/gpu_shader_material_combine_xyz.glsl + shaders/material/gpu_shader_material_diffuse.glsl + shaders/material/gpu_shader_material_displacement.glsl + shaders/material/gpu_shader_material_eevee_specular.glsl + shaders/material/gpu_shader_material_emission.glsl + shaders/material/gpu_shader_material_float_curve.glsl + shaders/material/gpu_shader_material_fractal_noise.glsl + shaders/material/gpu_shader_material_fresnel.glsl + shaders/material/gpu_shader_material_gamma.glsl + shaders/material/gpu_shader_material_geometry.glsl + shaders/material/gpu_shader_material_glass.glsl + shaders/material/gpu_shader_material_glossy.glsl + shaders/material/gpu_shader_material_hair_info.glsl + shaders/material/gpu_shader_material_hash.glsl + shaders/material/gpu_shader_material_holdout.glsl + shaders/material/gpu_shader_material_hue_sat_val.glsl + shaders/material/gpu_shader_material_invert.glsl + shaders/material/gpu_shader_material_layer_weight.glsl + shaders/material/gpu_shader_material_light_falloff.glsl + shaders/material/gpu_shader_material_light_path.glsl + shaders/material/gpu_shader_material_mapping.glsl + shaders/material/gpu_shader_material_map_range.glsl + shaders/material/gpu_shader_material_math.glsl + shaders/material/gpu_shader_material_math_util.glsl + shaders/material/gpu_shader_material_mix_rgb.glsl + shaders/material/gpu_shader_material_mix_shader.glsl + shaders/material/gpu_shader_material_noise.glsl + shaders/material/gpu_shader_material_normal.glsl + shaders/material/gpu_shader_material_normal_map.glsl + shaders/material/gpu_shader_material_object_info.glsl + shaders/material/gpu_shader_material_output_aov.glsl + shaders/material/gpu_shader_material_output_material.glsl + shaders/material/gpu_shader_material_output_world.glsl + shaders/material/gpu_shader_material_particle_info.glsl + shaders/material/gpu_shader_material_principled.glsl + shaders/material/gpu_shader_material_refraction.glsl + shaders/material/gpu_shader_material_rgb_curves.glsl + shaders/material/gpu_shader_material_rgb_to_bw.glsl + shaders/material/gpu_shader_material_separate_hsv.glsl + shaders/material/gpu_shader_material_separate_rgb.glsl + shaders/material/gpu_shader_material_separate_xyz.glsl + shaders/material/gpu_shader_material_set.glsl + shaders/material/gpu_shader_material_shader_to_rgba.glsl + shaders/material/gpu_shader_material_squeeze.glsl + shaders/material/gpu_shader_material_subsurface_scattering.glsl + shaders/material/gpu_shader_material_tangent.glsl + shaders/material/gpu_shader_material_tex_brick.glsl + shaders/material/gpu_shader_material_tex_checker.glsl + shaders/material/gpu_shader_material_tex_environment.glsl + shaders/material/gpu_shader_material_tex_gradient.glsl + shaders/material/gpu_shader_material_tex_image.glsl + shaders/material/gpu_shader_material_tex_magic.glsl + shaders/material/gpu_shader_material_tex_musgrave.glsl + shaders/material/gpu_shader_material_tex_noise.glsl + shaders/material/gpu_shader_material_tex_sky.glsl + shaders/material/gpu_shader_material_texture_coordinates.glsl + shaders/material/gpu_shader_material_tex_voronoi.glsl + 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_translucent.glsl + shaders/material/gpu_shader_material_transparent.glsl + shaders/material/gpu_shader_material_uv_map.glsl + shaders/material/gpu_shader_material_vector_curves.glsl + shaders/material/gpu_shader_material_vector_displacement.glsl + shaders/material/gpu_shader_material_vector_math.glsl + shaders/material/gpu_shader_material_vector_rotate.glsl + shaders/material/gpu_shader_material_velvet.glsl + shaders/material/gpu_shader_material_vertex_color.glsl + shaders/material/gpu_shader_material_volume_absorption.glsl + shaders/material/gpu_shader_material_volume_info.glsl + shaders/material/gpu_shader_material_volume_principled.glsl + shaders/material/gpu_shader_material_volume_scatter.glsl + shaders/material/gpu_shader_material_wireframe.glsl + shaders/material/gpu_shader_material_world_normals.glsl + + shaders/gpu_shader_gpencil_stroke_vert.glsl + shaders/gpu_shader_gpencil_stroke_frag.glsl + shaders/gpu_shader_gpencil_stroke_geom.glsl + + shaders/gpu_shader_cfg_world_clip_lib.glsl + shaders/gpu_shader_colorspace_lib.glsl + + shaders/gpu_shader_common_obinfos_lib.glsl + + intern/gpu_shader_shared_utils.h +) + +set(GLSL_C) +foreach(GLSL_FILE ${GLSL_SRC}) + data_to_c_simple(${GLSL_FILE} GLSL_C) +endforeach() + +blender_add_lib(bf_gpu_shaders "${GLSL_C}" "" "" "") + +list(APPEND LIB + bf_gpu_shaders +) +set(GLSL_SOURCE_CONTENT "") +foreach(GLSL_FILE ${GLSL_SRC}) + get_filename_component(GLSL_FILE_NAME ${GLSL_FILE} NAME) + string(REPLACE "." "_" GLSL_FILE_NAME_UNDERSCORES ${GLSL_FILE_NAME}) + string(APPEND GLSL_SOURCE_CONTENT "SHADER_SOURCE\(datatoc_${GLSL_FILE_NAME_UNDERSCORES}, \"${GLSL_FILE_NAME}\"\)\n") +endforeach() + +set(glsl_source_list_file "${CMAKE_CURRENT_BINARY_DIR}/glsl_gpu_source_list.h") +file(GENERATE OUTPUT ${glsl_source_list_file} CONTENT "${GLSL_SOURCE_CONTENT}") +list(APPEND SRC ${glsl_source_list_file}) +list(APPEND INC ${CMAKE_CURRENT_BINARY_DIR}) + +set(SHADER_CREATE_INFOS +#../draw/engines/workbench/shaders/workbench_effect_cavity_info.hh +#../draw/engines/workbench/shaders/workbench_prepass_info.hh +../draw/intern/shaders/draw_fullscreen_info.hh +../draw/intern/shaders/draw_view_info.hh +../draw/intern/shaders/draw_object_infos_info.hh + +shaders/infos/gpu_clip_planes_info.hh +shaders/infos/gpu_srgb_to_framebuffer_space_info.hh +shaders/infos/gpu_shader_3D_image_modulate_alpha_info.hh +shaders/infos/gpu_shader_2D_checker_info.hh +shaders/infos/gpu_shader_2D_diag_stripes_info.hh +shaders/infos/gpu_shader_2D_uniform_color_info.hh +shaders/infos/gpu_shader_2D_flat_color_info.hh +shaders/infos/gpu_shader_2D_smooth_color_info.hh +shaders/infos/gpu_shader_2D_image_overlays_merge_info.hh +shaders/infos/gpu_shader_2D_image_overlays_stereo_merge_info.hh +shaders/infos/gpu_shader_2D_image_info.hh +shaders/infos/gpu_shader_2D_image_color_info.hh +shaders/infos/gpu_shader_2D_image_desaturate_color_info.hh +shaders/infos/gpu_shader_2D_image_shuffle_color_info.hh +shaders/infos/gpu_shader_2D_image_rect_color_info.hh +shaders/infos/gpu_shader_text_info.hh +shaders/infos/gpu_shader_keyframe_shape_info.hh +shaders/infos/gpu_shader_3D_flat_color_info.hh +shaders/infos/gpu_shader_3D_uniform_color_info.hh +shaders/infos/gpu_shader_3D_smooth_color_info.hh +shaders/infos/gpu_shader_3D_depth_only_info.hh +shaders/infos/gpu_shader_2D_point_varying_size_varying_color_info.hh +shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_aa_info.hh +shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_outline_aa_info.hh +shaders/infos/gpu_shader_2D_area_borders_info.hh +shaders/infos/gpu_shader_instance_varying_color_varying_size_info.hh +shaders/infos/gpu_shader_3D_point_info.hh +shaders/infos/gpu_shader_2D_nodelink_info.hh +shaders/infos/gpu_shader_gpencil_stroke_info.hh +shaders/infos/gpu_shader_simple_lighting_info.hh +) + +set(SHADER_CREATE_INFOS_CONTENT "") +foreach(DESCRIPTOR_FILE ${SHADER_CREATE_INFOS}) +string(APPEND SHADER_CREATE_INFOS_CONTENT "#include \"${DESCRIPTOR_FILE}\"\n") +endforeach() + +set(shader_create_info_list_file "${CMAKE_CURRENT_BINARY_DIR}/gpu_shader_create_info_list.hh") +file(GENERATE OUTPUT ${shader_create_info_list_file} CONTENT "${SHADER_CREATE_INFOS_CONTENT}") if(WITH_MOD_FLUID) add_definitions(-DWITH_FLUID) @@ -377,11 +458,48 @@ if(WITH_IMAGE_DDS) endif() blender_add_lib(bf_gpu "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") +target_link_libraries(bf_gpu PUBLIC + bf_draw_shaders + bf_gpu_shaders +) if(CXX_WARN_NO_SUGGEST_OVERRIDE) target_compile_options(bf_gpu PRIVATE $<$:-Wsuggest-override>) endif() + + +if(WITH_GPU_SHADER_BUILDER) + add_executable(shader_builder + intern/gpu_shader_builder.cc + intern/gpu_shader_builder_stubs.cc + ${shader_create_info_list_file} + ) + + target_link_libraries(shader_builder PUBLIC + bf_blenkernel + ${PLATFORM_LINKLIBS} + ) + target_include_directories(shader_builder PRIVATE ${INC} ${CMAKE_CURRENT_BINARY_DIR}) + + set(BAKED_CREATE_INFOS_FILE ${CMAKE_CURRENT_BINARY_DIR}/shader_baked.hh) + + add_custom_command( + OUTPUT + ${BAKED_CREATE_INFOS_FILE} + COMMAND + "$" ${BAKED_CREATE_INFOS_FILE} + DEPENDS shader_builder + ) + set(GPU_SHADER_INFO_SRC + intern/gpu_shader_info_baked.cc + ${BAKED_CREATE_INFOS_FILE} + ) + + blender_add_lib(bf_gpu_shader_infos "${GPU_SHADER_INFO_SRC}" "" "" "") +endif() + + if(WITH_GTESTS) if(WITH_OPENGL_DRAW_TESTS) set(TEST_SRC diff --git a/source/blender/gpu/GPU_immediate.h b/source/blender/gpu/GPU_immediate.h index a175fc65ba4..1b288d19c4a 100644 --- a/source/blender/gpu/GPU_immediate.h +++ b/source/blender/gpu/GPU_immediate.h @@ -122,6 +122,7 @@ void immUniformMatrix4fv(const char *name, const float data[4][4]); void immBindTexture(const char *name, GPUTexture *tex); void immBindTextureSampler(const char *name, GPUTexture *tex, eGPUSamplerState state); +void immBindUniformBuf(const char *name, GPUUniformBuf *ubo); /* Convenience functions for setting "uniform vec4 color". */ /* The RGB functions have implicit alpha = 1.0. */ diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index f36c8f99064..97b9b26ba2a 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -30,6 +30,8 @@ extern "C" { struct GPUIndexBuf; struct GPUVertBuf; +/** Opaque type hiding #blender::gpu::shader::ShaderCreateInfo */ +typedef struct GPUShaderCreateInfo GPUShaderCreateInfo; /** Opaque type hiding #blender::gpu::Shader */ typedef struct GPUShader GPUShader; @@ -66,6 +68,7 @@ GPUShader *GPU_shader_create_ex(const char *vertcode, const char **tf_names, int tf_count, const char *shname); +GPUShader *GPU_shader_create_from_info(const GPUShaderCreateInfo *_info); struct GPU_ShaderCreateFromArray_Params { const char **vert, **geom, **frag, **defs; diff --git a/source/blender/gpu/GPU_shader_shared.h b/source/blender/gpu/GPU_shader_shared.h new file mode 100644 index 00000000000..4d277921773 --- /dev/null +++ b/source/blender/gpu/GPU_shader_shared.h @@ -0,0 +1,82 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#ifndef USE_GPU_SHADER_CREATE_INFO +# include "intern/gpu_shader_shared_utils.h" +#endif + +#ifdef __cplusplus +using blender::float2; +using blender::float3; +using blender::float4; +using blender::float4x4; +#endif + +struct NodeLinkData { + float4 colors[3]; + float2 bezierPts[4]; + bool1 doArrow; + bool1 doMuted; + float dim_factor; + float thickness; + float dash_factor; + float dash_alpha; + float expandSize; + float arrowSize; +}; +BLI_STATIC_ASSERT_ALIGN(struct NodeLinkData, 16) + +struct NodeLinkInstanceData { + float4 colors[6]; + float expandSize; + float arrowSize; + float2 _pad; +}; +BLI_STATIC_ASSERT_ALIGN(struct NodeLinkInstanceData, 16) + +struct GPencilStrokeData { + float2 viewport; + float pixsize; + float objscale; + float pixfactor; + int xraymode; + int caps_start; + int caps_end; + bool1 keep_size; + bool1 fill_stroke; + float2 _pad; +}; +BLI_STATIC_ASSERT_ALIGN(struct GPencilStrokeData, 16) + +struct GPUClipPlanes { + float4x4 ModelMatrix; + float4 world[6]; +}; +BLI_STATIC_ASSERT_ALIGN(struct GPUClipPlanes, 16) + +struct SimpleLightingData { + float4 color; + float3 light; + float _pad; +}; +BLI_STATIC_ASSERT_ALIGN(struct SimpleLightingData, 16) diff --git a/source/blender/gpu/intern/gpu_immediate.cc b/source/blender/gpu/intern/gpu_immediate.cc index 7ca93252683..e28776c87b3 100644 --- a/source/blender/gpu/intern/gpu_immediate.cc +++ b/source/blender/gpu/intern/gpu_immediate.cc @@ -629,6 +629,12 @@ void immBindTextureSampler(const char *name, GPUTexture *tex, eGPUSamplerState s GPU_texture_bind_ex(tex, state, binding, true); } +void immBindUniformBuf(const char *name, GPUUniformBuf *ubo) +{ + int binding = GPU_shader_get_uniform_block_binding(imm->shader, name); + GPU_uniformbuf_bind(ubo, binding); +} + /* --- convenience functions for setting "uniform vec4 color" --- */ void immUniformColor4f(float r, float g, float b, float a) diff --git a/source/blender/gpu/intern/gpu_init_exit.c b/source/blender/gpu/intern/gpu_init_exit.c index 0eb2fe57c28..5815fb10b0c 100644 --- a/source/blender/gpu/intern/gpu_init_exit.c +++ b/source/blender/gpu/intern/gpu_init_exit.c @@ -32,6 +32,8 @@ #include "intern/gpu_codegen.h" #include "intern/gpu_material_library.h" #include "intern/gpu_private.h" +#include "intern/gpu_shader_create_info_private.hh" +#include "intern/gpu_shader_dependency_private.h" /** * although the order of initialization and shutdown should not matter @@ -49,6 +51,9 @@ void GPU_init(void) initialized = true; + gpu_shader_dependency_init(); + gpu_shader_create_info_init(); + gpu_codegen_init(); gpu_material_library_init(); @@ -70,6 +75,9 @@ void GPU_exit(void) gpu_material_library_exit(); gpu_codegen_exit(); + gpu_shader_dependency_exit(); + gpu_shader_create_info_exit(); + initialized = false; } diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc index 3f5a639d2a0..3b41e804fd4 100644 --- a/source/blender/gpu/intern/gpu_shader.cc +++ b/source/blender/gpu/intern/gpu_shader.cc @@ -31,10 +31,32 @@ #include "gpu_backend.hh" #include "gpu_context_private.hh" +#include "gpu_shader_create_info.hh" +#include "gpu_shader_create_info_private.hh" +#include "gpu_shader_dependency_private.h" #include "gpu_shader_private.hh" +#include + extern "C" char datatoc_gpu_shader_colorspace_lib_glsl[]; +namespace blender::gpu { + +std::string Shader::defines_declare(const shader::ShaderCreateInfo &info) const +{ + std::string defines; + for (const auto &def : info.defines_) { + defines += "#define "; + defines += def[0]; + defines += " "; + defines += def[1]; + defines += "\n"; + } + return defines; +} + +} // namespace blender::gpu + using namespace blender; using namespace blender::gpu; @@ -59,6 +81,8 @@ static void standard_defines(Vector &sources) BLI_assert(sources.size() == 0); /* Version needs to be first. Exact values will be added by implementation. */ sources.append("version"); + /* Define to identify code usage in shading language. */ + sources.append("#define GPU_SHADER\n"); /* some useful defines to detect GPU type */ if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) { sources.append("#define GPU_ATI\n"); @@ -225,6 +249,174 @@ GPUShader *GPU_shader_create_compute(const char *computecode, shname); } +GPUShader *GPU_shader_create_from_info(const GPUShaderCreateInfo *_info) +{ + using namespace blender::gpu::shader; + const ShaderCreateInfo &info = *reinterpret_cast(_info); + + const_cast(info).finalize(); + + /* At least a vertex shader and a fragment shader are required, or only a compute shader. */ + if (info.compute_source_.is_empty()) { + if (info.vertex_source_.is_empty()) { + printf("Missing vertex shader in %s.\n", info.name_.c_str()); + } + if (info.fragment_source_.is_empty()) { + printf("Missing fragment shader in %s.\n", info.name_.c_str()); + } + BLI_assert(!info.vertex_source_.is_empty() && !info.fragment_source_.is_empty()); + } + else { + if (!info.vertex_source_.is_empty()) { + printf("Compute shader has vertex_source_ shader attached in %s.\n", info.name_.c_str()); + } + if (!info.geometry_source_.is_empty()) { + printf("Compute shader has geometry_source_ shader attached in %s.\n", info.name_.c_str()); + } + if (!info.fragment_source_.is_empty()) { + printf("Compute shader has fragment_source_ shader attached in %s.\n", info.name_.c_str()); + } + BLI_assert(info.vertex_source_.is_empty() && info.geometry_source_.is_empty() && + info.fragment_source_.is_empty()); + } + + Shader *shader = GPUBackend::get()->shader_alloc(info.name_.c_str()); + + std::string defines = shader->defines_declare(info); + std::string resources = shader->resources_declare(info); + char *shader_shared_utils = nullptr; + + defines += "#define USE_GPU_SHADER_CREATE_INFO\n"; + + Vector typedefs; + for (auto filename : info.typedef_sources_) { + typedefs.append(gpu_shader_dependency_get_source(filename.c_str())); + } + if (!typedefs.is_empty()) { + shader_shared_utils = gpu_shader_dependency_get_source("gpu_shader_shared_utils.h"); + } + + if (!info.vertex_source_.is_empty()) { + uint32_t builtins = 0; + std::string interface = shader->vertex_interface_declare(info); + char *code = gpu_shader_dependency_get_resolved_source(info.vertex_source_.c_str(), &builtins); + + Vector sources; + standard_defines(sources); + sources.append("#define GPU_VERTEX_SHADER\n"); + if (!info.geometry_source_.is_empty()) { + sources.append("#define USE_GEOMETRY_SHADER\n"); + } + sources.append(defines.c_str()); + if (!typedefs.is_empty()) { + sources.append(shader_shared_utils); + } + for (auto *types : typedefs) { + sources.append(types); + } + sources.append(resources.c_str()); + sources.append(interface.c_str()); + sources.append(code); + + shader->vertex_shader_from_glsl(sources); + + free(code); + } + + if (!info.fragment_source_.is_empty()) { + uint32_t builtins = 0; + std::string interface = shader->fragment_interface_declare(info); + char *code = gpu_shader_dependency_get_resolved_source(info.fragment_source_.c_str(), + &builtins); + + Vector sources; + standard_defines(sources); + sources.append("#define GPU_FRAGMENT_SHADER\n"); + if (!info.geometry_source_.is_empty()) { + sources.append("#define USE_GEOMETRY_SHADER\n"); + } + sources.append(defines.c_str()); + if (!typedefs.is_empty()) { + sources.append(shader_shared_utils); + } + for (auto *types : typedefs) { + sources.append(types); + } + sources.append(resources.c_str()); + sources.append(interface.c_str()); + sources.append(code); + + shader->fragment_shader_from_glsl(sources); + + free(code); + } + + if (!info.geometry_source_.is_empty()) { + uint32_t builtins = 0; + std::string interface = shader->geometry_interface_declare(info); + std::string layout = shader->geometry_layout_declare(info); + char *code = gpu_shader_dependency_get_resolved_source(info.geometry_source_.c_str(), + &builtins); + + Vector sources; + standard_defines(sources); + sources.append("#define GPU_GEOMETRY_SHADER\n"); + sources.append(defines.c_str()); + if (!typedefs.is_empty()) { + sources.append(shader_shared_utils); + } + for (auto *types : typedefs) { + sources.append(types); + } + sources.append(resources.c_str()); + sources.append(layout.c_str()); + sources.append(interface.c_str()); + sources.append(code); + + shader->geometry_shader_from_glsl(sources); + + free(code); + } + + if (!info.compute_source_.is_empty()) { + uint32_t builtins = 0; + char *code = gpu_shader_dependency_get_resolved_source(info.compute_source_.c_str(), + &builtins); + + Vector sources; + standard_defines(sources); + sources.append("#define GPU_COMPUTE_SHADER\n"); + sources.append(defines.c_str()); + if (!typedefs.is_empty()) { + sources.append(shader_shared_utils); + } + for (auto *types : typedefs) { + sources.append(types); + } + sources.append(resources.c_str()); + sources.append(code); + + shader->compute_shader_from_glsl(sources); + + free(code); + } + + for (auto *types : typedefs) { + free(types); + } + + if (shader_shared_utils) { + free(shader_shared_utils); + } + + if (!shader->finalize(&info)) { + delete shader; + return nullptr; + } + + return wrap(shader); +} + GPUShader *GPU_shader_create_from_python(const char *vertcode, const char *fragcode, const char *geomcode, diff --git a/source/blender/gpu/intern/gpu_shader_builder.cc b/source/blender/gpu/intern/gpu_shader_builder.cc new file mode 100644 index 00000000000..334bdb2ec58 --- /dev/null +++ b/source/blender/gpu/intern/gpu_shader_builder.cc @@ -0,0 +1,102 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2021 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + * + * Compile time automation of shader compilation and validation. + */ + +#include + +#include "GHOST_C-api.h" + +#include "GPU_context.h" +#include "GPU_init_exit.h" +#include "gpu_shader_create_info_private.hh" + +#include "CLG_log.h" + +namespace blender::gpu::shader_builder { + +class ShaderBuilder { + private: + GHOST_SystemHandle ghost_system_; + GHOST_ContextHandle ghost_context_; + GPUContext *gpu_context_ = nullptr; + + public: + void init(); + bool bake_create_infos(); + void exit(); +}; + +bool ShaderBuilder::bake_create_infos() +{ + return gpu_shader_create_info_compile_all(); +} + +void ShaderBuilder::init() +{ + CLG_init(); + + GHOST_GLSettings glSettings = {0}; + ghost_system_ = GHOST_CreateSystem(); + ghost_context_ = GHOST_CreateOpenGLContext(ghost_system_, glSettings); + GHOST_ActivateOpenGLContext(ghost_context_); + + gpu_context_ = GPU_context_create(nullptr); + GPU_init(); +} + +void ShaderBuilder::exit() +{ + GPU_backend_exit(); + GPU_exit(); + + GPU_context_discard(gpu_context_); + + GHOST_DisposeOpenGLContext(ghost_system_, ghost_context_); + GHOST_DisposeSystem(ghost_system_); + + CLG_exit(); +} + +} // namespace blender::gpu::shader_builder + +/** \brief Entry point for the shader_builder. */ +int main(int argc, const char *argv[]) +{ + if (argc < 2) { + printf("Usage: %s \n", argv[0]); + exit(1); + } + + int exit_code = 0; + + blender::gpu::shader_builder::ShaderBuilder builder; + builder.init(); + if (!builder.bake_create_infos()) { + exit_code = 1; + } + builder.exit(); + exit(exit_code); + + return exit_code; +} diff --git a/source/blender/gpu/intern/gpu_shader_builder_stubs.cc b/source/blender/gpu/intern/gpu_shader_builder_stubs.cc new file mode 100644 index 00000000000..40e54ab4394 --- /dev/null +++ b/source/blender/gpu/intern/gpu_shader_builder_stubs.cc @@ -0,0 +1,258 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2021 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + * + * Stubs to reduce linking time for shader_builder. + */ + +#include "BLI_utildefines.h" + +#include "IMB_imbuf.h" +#include "IMB_imbuf_types.h" + +#include "BKE_customdata.h" +#include "BKE_global.h" +#include "BKE_material.h" +#include "BKE_mesh.h" +#include "BKE_node.h" +#include "BKE_paint.h" +#include "BKE_pbvh.h" +#include "BKE_subdiv_ccg.h" + +#include "DNA_userdef_types.h" + +#include "DRW_engine.h" + +#include "bmesh.h" + +#include "UI_resources.h" + +extern "C" { + +Global G; +UserDef U; + +/* -------------------------------------------------------------------- */ +/** \name Stubs of BLI_imbuf_types.h + * \{ */ + +void IMB_freeImBuf(ImBuf *UNUSED(ibuf)) +{ + BLI_assert_unreachable(); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Stubs of UI_resources.h + * \{ */ + +void UI_GetThemeColor4fv(int UNUSED(colorid), float UNUSED(col[4])) +{ + BLI_assert_unreachable(); +} + +void UI_GetThemeColor3fv(int UNUSED(colorid), float UNUSED(col[3])) +{ + BLI_assert_unreachable(); +} + +void UI_GetThemeColorShade4fv(int UNUSED(colorid), int UNUSED(offset), float UNUSED(col[4])) +{ + BLI_assert_unreachable(); +} + +void UI_GetThemeColorShadeAlpha4fv(int UNUSED(colorid), + int UNUSED(coloffset), + int UNUSED(alphaoffset), + float UNUSED(col[4])) +{ + BLI_assert_unreachable(); +} +void UI_GetThemeColorBlendShade4fv(int UNUSED(colorid1), + int UNUSED(colorid2), + float UNUSED(fac), + int UNUSED(offset), + float UNUSED(col[4])) +{ + BLI_assert_unreachable(); +} + +void UI_GetThemeColorBlend3ubv(int UNUSED(colorid1), + int UNUSED(colorid2), + float UNUSED(fac), + unsigned char UNUSED(col[3])) +{ + BLI_assert_unreachable(); +} + +void UI_GetThemeColorShadeAlpha4ubv(int UNUSED(colorid), + int UNUSED(coloffset), + int UNUSED(alphaoffset), + unsigned char UNUSED(col[4])) +{ + BLI_assert_unreachable(); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Stubs of BKE_paint.h + * \{ */ +bool paint_is_face_hidden(const struct MLoopTri *UNUSED(lt), + const struct MVert *UNUSED(mvert), + const struct MLoop *UNUSED(mloop)) +{ + BLI_assert_unreachable(); + return false; +} + +void BKE_paint_face_set_overlay_color_get(const int UNUSED(face_set), + const int UNUSED(seed), + uchar UNUSED(r_color[4])) +{ + BLI_assert_unreachable(); +} + +bool paint_is_grid_face_hidden(const unsigned int *UNUSED(grid_hidden), + int UNUSED(gridsize), + int UNUSED(x), + int UNUSED(y)) +{ + BLI_assert_unreachable(); + return false; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Stubs of BKE_mesh.h + * \{ */ +void BKE_mesh_calc_poly_normal(const struct MPoly *UNUSED(mpoly), + const struct MLoop *UNUSED(loopstart), + const struct MVert *UNUSED(mvarray), + float UNUSED(r_no[3])) +{ + BLI_assert_unreachable(); +} + +void BKE_mesh_looptri_get_real_edges(const struct Mesh *UNUSED(mesh), + const struct MLoopTri *UNUSED(looptri), + int UNUSED(r_edges[3])) +{ + BLI_assert_unreachable(); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Stubs of BKE_material.h + * \{ */ + +void BKE_material_defaults_free_gpu(void) +{ + /* This function is reachable via GPU_exit. */ +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Stubs of BKE_customdata.h + * \{ */ + +int CustomData_get_offset(const struct CustomData *UNUSED(data), int UNUSED(type)) +{ + BLI_assert_unreachable(); + return 0; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Stubs of BKE_pbvh.h + * \{ */ + +int BKE_pbvh_count_grid_quads(BLI_bitmap **UNUSED(grid_hidden), + const int *UNUSED(grid_indices), + int UNUSED(totgrid), + int UNUSED(gridsize)) +{ + BLI_assert_unreachable(); + return 0; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Stubs of BKE_subdiv_ccg.h + * \{ */ +int BKE_subdiv_ccg_grid_to_face_index(const SubdivCCG *UNUSED(subdiv_ccg), + const int UNUSED(grid_index)) +{ + BLI_assert_unreachable(); + return 0; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Stubs of BKE_node.h + * \{ */ +void ntreeGPUMaterialNodes(struct bNodeTree *UNUSED(localtree), + struct GPUMaterial *UNUSED(mat), + bool *UNUSED(has_surface_output), + bool *UNUSED(has_volume_output)) +{ + BLI_assert_unreachable(); +} + +struct bNodeTree *ntreeLocalize(struct bNodeTree *UNUSED(ntree)) +{ + BLI_assert_unreachable(); + return nullptr; +} + +void ntreeFreeLocalTree(struct bNodeTree *UNUSED(ntree)) +{ + BLI_assert_unreachable(); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Stubs of bmesh.h + * \{ */ +void BM_face_as_array_vert_tri(BMFace *UNUSED(f), BMVert *UNUSED(r_verts[3])) +{ + BLI_assert_unreachable(); +} +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Stubs of DRW_engine.h + * \{ */ +void DRW_deferred_shader_remove(struct GPUMaterial *UNUSED(mat)) +{ + BLI_assert_unreachable(); +} + +/** \} */ +} diff --git a/source/blender/gpu/intern/gpu_shader_builtin.c b/source/blender/gpu/intern/gpu_shader_builtin.c index 24ca691be78..cae7383f885 100644 --- a/source/blender/gpu/intern/gpu_shader_builtin.c +++ b/source/blender/gpu/intern/gpu_shader_builtin.c @@ -41,6 +41,9 @@ #include "GPU_texture.h" #include "GPU_uniform_buffer.h" +/* TODO(jbakker): Need a better way to retrieve create_infos. */ +#include "gpu_shader_create_info_private.hh" + /* Adjust these constants as needed. */ #define MAX_DEFINE_LENGTH 256 #define MAX_EXT_DEFINE_LENGTH 512 @@ -145,106 +148,68 @@ typedef struct { const char *frag; /** Optional. */ const char *defs; + + const char *create_info; + const char *clipped_create_info; } GPUShaderStages; static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = { [GPU_SHADER_TEXT] = { .name = "GPU_SHADER_TEXT", - .vert = datatoc_gpu_shader_text_vert_glsl, - .frag = datatoc_gpu_shader_text_frag_glsl, + .create_info = "gpu_shader_text", }, [GPU_SHADER_KEYFRAME_SHAPE] = { .name = "GPU_SHADER_KEYFRAME_SHAPE", - .vert = datatoc_gpu_shader_keyframe_shape_vert_glsl, - .frag = datatoc_gpu_shader_keyframe_shape_frag_glsl, + .create_info = "gpu_shader_keyframe_shape", }, [GPU_SHADER_SIMPLE_LIGHTING] = { .name = "GPU_SHADER_SIMPLE_LIGHTING", - .vert = datatoc_gpu_shader_3D_normal_vert_glsl, - .frag = datatoc_gpu_shader_simple_lighting_frag_glsl, + .create_info = "gpu_shader_simple_lighting", }, [GPU_SHADER_3D_IMAGE_MODULATE_ALPHA] = { - .vert = datatoc_gpu_shader_3D_image_vert_glsl, - .frag = datatoc_gpu_shader_image_modulate_alpha_frag_glsl, + .name = "GPU_SHADER_3D_IMAGE_MODULATE_ALPHA", + .create_info = "gpu_shader_3D_image_modulate_alpha", }, [GPU_SHADER_2D_CHECKER] = { .name = "GPU_SHADER_2D_CHECKER", - .vert = datatoc_gpu_shader_2D_vert_glsl, - .frag = datatoc_gpu_shader_checker_frag_glsl, + .create_info = "gpu_shader_2D_checker", }, [GPU_SHADER_2D_DIAG_STRIPES] = { .name = "GPU_SHADER_2D_DIAG_STRIPES", - .vert = datatoc_gpu_shader_2D_vert_glsl, - .frag = datatoc_gpu_shader_diag_stripes_frag_glsl, + .create_info = "gpu_shader_2D_diag_stripes", }, - [GPU_SHADER_2D_UNIFORM_COLOR] = - { - .name = "GPU_SHADER_2D_UNIFORM_COLOR", - .vert = datatoc_gpu_shader_2D_vert_glsl, - .frag = datatoc_gpu_shader_uniform_color_frag_glsl, - }, - [GPU_SHADER_2D_FLAT_COLOR] = - { - .name = "GPU_SHADER_2D_FLAT_COLOR", - .vert = datatoc_gpu_shader_2D_flat_color_vert_glsl, - .frag = datatoc_gpu_shader_flat_color_frag_glsl, - }, - [GPU_SHADER_2D_SMOOTH_COLOR] = - { - .name = "GPU_SHADER_2D_SMOOTH_COLOR", - .vert = datatoc_gpu_shader_2D_smooth_color_vert_glsl, - .frag = datatoc_gpu_shader_2D_smooth_color_frag_glsl, - }, - [GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE] = - { - .name = "GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE", - .vert = datatoc_gpu_shader_2D_image_vert_glsl, - .frag = datatoc_gpu_shader_image_overlays_merge_frag_glsl, - }, + [GPU_SHADER_2D_UNIFORM_COLOR] = {.name = "GPU_SHADER_2D_UNIFORM_COLOR", + .create_info = "gpu_shader_2D_uniform_color"}, + [GPU_SHADER_2D_FLAT_COLOR] = {.name = "GPU_SHADER_2D_FLAT_COLOR", + .create_info = "gpu_shader_2D_flat_color"}, + [GPU_SHADER_2D_SMOOTH_COLOR] = {.name = "GPU_SHADER_2D_SMOOTH_COLOR", + .create_info = "gpu_shader_2D_smooth_color"}, + [GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE] = {.name = "GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE", + .create_info = "gpu_shader_2D_image_overlays_merge"}, [GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE] = - { - .name = "GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE", - .vert = datatoc_gpu_shader_2D_vert_glsl, - .frag = datatoc_gpu_shader_image_overlays_stereo_merge_frag_glsl, - }, - [GPU_SHADER_2D_IMAGE] = - { - .name = "GPU_SHADER_2D_IMAGE", - .vert = datatoc_gpu_shader_2D_image_vert_glsl, - .frag = datatoc_gpu_shader_image_frag_glsl, - }, - [GPU_SHADER_2D_IMAGE_COLOR] = - { - .name = "GPU_SHADER_2D_IMAGE_COLOR", - .vert = datatoc_gpu_shader_2D_image_vert_glsl, - .frag = datatoc_gpu_shader_image_color_frag_glsl, - }, - [GPU_SHADER_2D_IMAGE_DESATURATE_COLOR] = - { - .name = "GPU_SHADER_2D_IMAGE_DESATURATE_COLOR", - .vert = datatoc_gpu_shader_2D_image_vert_glsl, - .frag = datatoc_gpu_shader_image_desaturate_frag_glsl, - }, + {.name = "GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE", + .create_info = "gpu_shader_2D_image_overlays_stereo_merge"}, + [GPU_SHADER_2D_IMAGE] = {.name = "GPU_SHADER_2D_IMAGE", .create_info = "gpu_shader_2D_image"}, + [GPU_SHADER_2D_IMAGE_COLOR] = {.name = "GPU_SHADER_2D_IMAGE_COLOR", + .create_info = "gpu_shader_2D_image_color"}, + [GPU_SHADER_2D_IMAGE_DESATURATE_COLOR] = {.name = "GPU_SHADER_2D_IMAGE_DESATURATE_COLOR", + .create_info = + "gpu_shader_2D_image_desaturate_color"}, [GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR] = { .name = "GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR", - .vert = datatoc_gpu_shader_2D_image_vert_glsl, - .frag = datatoc_gpu_shader_image_shuffle_color_frag_glsl, - }, - [GPU_SHADER_2D_IMAGE_RECT_COLOR] = - { - .name = "GPU_SHADER_2D_IMAGE_RECT_COLOR", - .vert = datatoc_gpu_shader_2D_image_rect_vert_glsl, - .frag = datatoc_gpu_shader_image_color_frag_glsl, + .create_info = "gpu_shader_2D_image_shuffle_color", }, + [GPU_SHADER_2D_IMAGE_RECT_COLOR] = {.name = "GPU_SHADER_2D_IMAGE_RECT_COLOR", + .create_info = "gpu_shader_2D_image_rect_color"}, [GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR] = { .name = "GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR", @@ -255,27 +220,18 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = { [GPU_SHADER_3D_UNIFORM_COLOR] = { .name = "GPU_SHADER_3D_UNIFORM_COLOR", - .vert = datatoc_gpu_shader_3D_vert_glsl, - .frag = datatoc_gpu_shader_uniform_color_frag_glsl, - }, - [GPU_SHADER_3D_FLAT_COLOR] = - { - .name = "GPU_SHADER_3D_FLAT_COLOR", - .vert = datatoc_gpu_shader_3D_flat_color_vert_glsl, - .frag = datatoc_gpu_shader_flat_color_frag_glsl, - }, - [GPU_SHADER_3D_SMOOTH_COLOR] = - { - .name = "GPU_SHADER_3D_SMOOTH_COLOR", - .vert = datatoc_gpu_shader_3D_smooth_color_vert_glsl, - .frag = datatoc_gpu_shader_3D_smooth_color_frag_glsl, - }, - [GPU_SHADER_3D_DEPTH_ONLY] = - { - .name = "GPU_SHADER_3D_DEPTH_ONLY", - .vert = datatoc_gpu_shader_3D_vert_glsl, - .frag = datatoc_gpu_shader_depth_only_frag_glsl, - }, + .create_info = "gpu_shader_3D_uniform_color", + .clipped_create_info = "gpu_shader_3D_uniform_color_clipped", + }, + [GPU_SHADER_3D_FLAT_COLOR] = {.name = "GPU_SHADER_3D_FLAT_COLOR", + .create_info = "gpu_shader_3D_flat_color", + .clipped_create_info = "gpu_shader_3D_flat_color_clipped"}, + [GPU_SHADER_3D_SMOOTH_COLOR] = {.name = "GPU_SHADER_3D_SMOOTH_COLOR", + .create_info = "gpu_shader_3D_smooth_color", + .clipped_create_info = "gpu_shader_3D_smooth_color_clipped"}, + [GPU_SHADER_3D_DEPTH_ONLY] = {.name = "GPU_SHADER_3D_DEPTH_ONLY", + .create_info = "gpu_shader_3D_depth_only", + .clipped_create_info = "gpu_shader_3D_depth_only_clipped"}, [GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR] = { .name = "GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR", @@ -333,33 +289,23 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = { [GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA] = { .name = "GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA", - .vert = datatoc_gpu_shader_2D_point_uniform_size_aa_vert_glsl, - .frag = datatoc_gpu_shader_point_uniform_color_aa_frag_glsl, + .create_info = "gpu_shader_2D_point_uniform_size_uniform_color_aa", }, [GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA] = { .name = "GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA", - .vert = datatoc_gpu_shader_2D_point_uniform_size_outline_aa_vert_glsl, - .frag = datatoc_gpu_shader_point_uniform_color_outline_aa_frag_glsl, + .create_info = "gpu_shader_2D_point_uniform_size_uniform_color_outline_aa", }, [GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR] = - { - .name = "GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR", - .vert = datatoc_gpu_shader_3D_point_fixed_size_varying_color_vert_glsl, - .frag = datatoc_gpu_shader_point_varying_color_frag_glsl, - }, + {.name = "GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR", + .create_info = "gpu_shader_3D_point_fixed_size_varying_color"}, [GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR] = - { - .name = "GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR", - .vert = datatoc_gpu_shader_3D_point_varying_size_varying_color_vert_glsl, - .frag = datatoc_gpu_shader_point_varying_color_frag_glsl, - }, + {.name = "GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR", + .create_info = "gpu_shader_3D_point_varying_size_varying_color"}, [GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA] = - { - .name = "GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA", - .vert = datatoc_gpu_shader_3D_point_uniform_size_aa_vert_glsl, - .frag = datatoc_gpu_shader_point_uniform_color_aa_frag_glsl, - }, + {.name = "GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA", + .create_info = "gpu_shader_3D_point_uniform_size_uniform_color_aa", + .clipped_create_info = "gpu_shader_3D_point_uniform_size_uniform_color_aa_clipped"}, [GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE] = { @@ -369,12 +315,8 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = { .defs = "#define UNIFORM_SCALE\n", }, - [GPU_SHADER_2D_AREA_BORDERS] = - { - .name = "GPU_SHADER_2D_AREA_BORDERS", - .vert = datatoc_gpu_shader_2D_area_borders_vert_glsl, - .frag = datatoc_gpu_shader_2D_area_borders_frag_glsl, - }, + [GPU_SHADER_2D_AREA_BORDERS] = {.name = "GPU_SHADER_2D_AREA_BORDERS", + .create_info = "gpu_shader_2D_area_borders"}, [GPU_SHADER_2D_WIDGET_BASE] = { .name = "GPU_SHADER_2D_WIDGET_BASE", @@ -394,27 +336,14 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = { .vert = datatoc_gpu_shader_2D_widget_shadow_vert_glsl, .frag = datatoc_gpu_shader_2D_widget_shadow_frag_glsl, }, - [GPU_SHADER_2D_NODELINK] = - { - .name = "GPU_SHADER_2D_NODELINK", - .vert = datatoc_gpu_shader_2D_nodelink_vert_glsl, - .frag = datatoc_gpu_shader_2D_nodelink_frag_glsl, - }, - [GPU_SHADER_2D_NODELINK_INST] = - { - .name = "GPU_SHADER_2D_NODELINK_INST", - .vert = datatoc_gpu_shader_2D_nodelink_vert_glsl, - .frag = datatoc_gpu_shader_2D_nodelink_frag_glsl, - .defs = "#define USE_INSTANCE\n", - }, + [GPU_SHADER_2D_NODELINK] = {.name = "GPU_SHADER_2D_NODELINK", + .create_info = "gpu_shader_2D_nodelink"}, - [GPU_SHADER_GPENCIL_STROKE] = - { - .name = "GPU_SHADER_GPENCIL_STROKE", - .vert = datatoc_gpu_shader_gpencil_stroke_vert_glsl, - .geom = datatoc_gpu_shader_gpencil_stroke_geom_glsl, - .frag = datatoc_gpu_shader_gpencil_stroke_frag_glsl, - }, + [GPU_SHADER_2D_NODELINK_INST] = {.name = "GPU_SHADER_2D_NODELINK_INST", + .create_info = "gpu_shader_2D_nodelink_inst"}, + + [GPU_SHADER_GPENCIL_STROKE] = {.name = "GPU_SHADER_GPENCIL_STROKE", + .create_info = "gpu_shader_gpencil_stroke"}, }; GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader, @@ -429,14 +358,20 @@ GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader, /* common case */ if (sh_cfg == GPU_SHADER_CFG_DEFAULT) { - *sh_p = GPU_shader_create_from_arrays_named( - stages->name, - { - .vert = (const char *[]){stages->vert, NULL}, - .geom = (const char *[]){stages->geom, NULL}, - .frag = (const char *[]){datatoc_gpu_shader_colorspace_lib_glsl, stages->frag, NULL}, - .defs = (const char *[]){stages->defs, NULL}, - }); + if (stages->create_info != NULL) { + *sh_p = GPU_shader_create_from_info(gpu_shader_create_info_get(stages->create_info)); + } + else { + *sh_p = GPU_shader_create_from_arrays_named( + stages->name, + { + .vert = (const char *[]){stages->vert, NULL}, + .geom = (const char *[]){stages->geom, NULL}, + .frag = + (const char *[]){datatoc_gpu_shader_colorspace_lib_glsl, stages->frag, NULL}, + .defs = (const char *[]){stages->defs, NULL}, + }); + } } else if (sh_cfg == GPU_SHADER_CFG_CLIPPED) { /* Remove eventually, for now ensure support for each shader has been added. */ @@ -448,17 +383,24 @@ GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader, GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA, GPU_SHADER_3D_FLAT_COLOR, GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR)); - const char *world_clip_lib = datatoc_gpu_shader_cfg_world_clip_lib_glsl; - const char *world_clip_def = "#define USE_WORLD_CLIP_PLANES\n"; /* In rare cases geometry shaders calculate clipping themselves. */ - *sh_p = GPU_shader_create_from_arrays_named( - stages->name, - { - .vert = (const char *[]){world_clip_lib, stages->vert, NULL}, - .geom = (const char *[]){stages->geom ? world_clip_lib : NULL, stages->geom, NULL}, - .frag = (const char *[]){datatoc_gpu_shader_colorspace_lib_glsl, stages->frag, NULL}, - .defs = (const char *[]){world_clip_def, stages->defs, NULL}, - }); + if (stages->clipped_create_info != NULL) { + *sh_p = GPU_shader_create_from_info( + gpu_shader_create_info_get(stages->clipped_create_info)); + } + else { + const char *world_clip_lib = datatoc_gpu_shader_cfg_world_clip_lib_glsl; + const char *world_clip_def = "#define USE_WORLD_CLIP_PLANES\n"; + *sh_p = GPU_shader_create_from_arrays_named( + stages->name, + { + .vert = (const char *[]){world_clip_lib, stages->vert, NULL}, + .geom = (const char *[]){stages->geom ? world_clip_lib : NULL, stages->geom, NULL}, + .frag = + (const char *[]){datatoc_gpu_shader_colorspace_lib_glsl, stages->frag, NULL}, + .defs = (const char *[]){world_clip_def, stages->defs, NULL}, + }); + } } else { BLI_assert(0); diff --git a/source/blender/gpu/intern/gpu_shader_create_info.cc b/source/blender/gpu/intern/gpu_shader_create_info.cc new file mode 100644 index 00000000000..e4e5034026f --- /dev/null +++ b/source/blender/gpu/intern/gpu_shader_create_info.cc @@ -0,0 +1,173 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2021 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + * + * Descriptior type used to define shader structure, resources and interfaces. + */ + +#include "BLI_map.hh" +#include "BLI_set.hh" +#include "BLI_string_ref.hh" + +#include "GPU_shader.h" +#include "GPU_texture.h" + +#include "gpu_shader_create_info.hh" +#include "gpu_shader_create_info_private.hh" + +#undef GPU_SHADER_INTERFACE_INFO +#undef GPU_SHADER_CREATE_INFO + +namespace blender::gpu::shader { + +using CreateInfoDictionnary = Map; +using InterfaceDictionnary = Map; + +static CreateInfoDictionnary *g_create_infos = nullptr; +static InterfaceDictionnary *g_interfaces = nullptr; + +void ShaderCreateInfo::finalize() +{ + if (finalized_) { + return; + } + finalized_ = true; + + for (auto &info_name : additional_infos_) { + const ShaderCreateInfo &info = *reinterpret_cast( + gpu_shader_create_info_get(info_name.c_str())); + + /* Recursive. */ + const_cast(info).finalize(); + + interface_names_size_ += info.interface_names_size_; + + vertex_inputs_.extend(info.vertex_inputs_); + fragment_outputs_.extend(info.fragment_outputs_); + vertex_out_interfaces_.extend(info.vertex_out_interfaces_); + geometry_out_interfaces_.extend(info.geometry_out_interfaces_); + + push_constants_.extend(info.push_constants_); + defines_.extend(info.defines_); + + batch_resources_.extend(info.batch_resources_); + pass_resources_.extend(info.pass_resources_); + typedef_sources_.extend(info.typedef_sources_); + + if (info.local_group_size_[0] != 0) { + BLI_assert(local_group_size_[0] == 0); + for (int i = 0; i < 3; i++) { + local_group_size_[i] = info.local_group_size_[i]; + } + } + if (!info.vertex_source_.is_empty()) { + BLI_assert(vertex_source_.is_empty()); + vertex_source_ = info.vertex_source_; + } + if (!info.geometry_source_.is_empty()) { + BLI_assert(geometry_source_.is_empty()); + geometry_source_ = info.geometry_source_; + } + if (!info.fragment_source_.is_empty()) { + BLI_assert(fragment_source_.is_empty()); + fragment_source_ = info.fragment_source_; + } + if (!info.compute_source_.is_empty()) { + BLI_assert(compute_source_.is_empty()); + compute_source_ = info.compute_source_; + } + + do_static_compilation_ = do_static_compilation_ || info.do_static_compilation_; + } +} + +} // namespace blender::gpu::shader + +using namespace blender::gpu::shader; + +void gpu_shader_create_info_init() +{ + g_create_infos = new CreateInfoDictionnary(); + g_interfaces = new InterfaceDictionnary(); + +#define GPU_SHADER_INTERFACE_INFO(_interface, _inst_name) \ + auto *ptr_##_interface = new StageInterfaceInfo(#_interface, _inst_name); \ + auto &_interface = *ptr_##_interface; \ + g_interfaces->add_new(#_interface, ptr_##_interface); \ + _interface + +#define GPU_SHADER_CREATE_INFO(_info) \ + auto *ptr_##_info = new ShaderCreateInfo(#_info); \ + auto &_info = *ptr_##_info; \ + g_create_infos->add_new(#_info, ptr_##_info); \ + _info + +/* Declare, register and construct the infos. */ +#include "gpu_shader_create_info_list.hh" + +/* Baked shader data appended to create infos. */ +/* TODO(jbakker): should call a function with a callback. so we could switch implementations. We + * cannot compile bf_gpu twice.*/ +#ifdef GPU_RUNTIME +# include "gpu_shader_baked.hh" +#endif + + /* TEST */ + // gpu_shader_create_info_compile_all(); +} + +void gpu_shader_create_info_exit() +{ + for (auto *value : g_create_infos->values()) { + delete value; + } + delete g_create_infos; + + for (auto *value : g_interfaces->values()) { + delete value; + } + delete g_interfaces; +} + +bool gpu_shader_create_info_compile_all() +{ + for (ShaderCreateInfo *info : g_create_infos->values()) { + if (info->do_static_compilation_) { + // printf("Compiling %s: ... \n", info->name_.c_str()); + GPUShader *shader = GPU_shader_create_from_info( + reinterpret_cast(info)); + if (shader == nullptr) { + printf("Compilation %s Failed\n", info->name_.c_str()); + return false; + } + GPU_shader_free(shader); + // printf("Success\n"); + } + } + return true; +} + +/* Runtime create infos are not registered in the dictionnary and cannot be searched. */ +const GPUShaderCreateInfo *gpu_shader_create_info_get(const char *info_name) +{ + ShaderCreateInfo *info = g_create_infos->lookup(info_name); + return reinterpret_cast(info); +} diff --git a/source/blender/gpu/intern/gpu_shader_create_info.hh b/source/blender/gpu/intern/gpu_shader_create_info.hh new file mode 100644 index 00000000000..ced7f7039e7 --- /dev/null +++ b/source/blender/gpu/intern/gpu_shader_create_info.hh @@ -0,0 +1,595 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2021 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + * + * Descriptior type used to define shader structure, resources and interfaces. + * + * Some rule of thumb: + * - Do not include anything else than this file in each info file. + */ + +#pragma once + +#include "BLI_string_ref.hh" +#include "BLI_vector.hh" +#include "GPU_texture.h" + +namespace blender::gpu::shader { + +#ifndef GPU_SHADER_CREATE_INFO +/* Helps intelisense / auto-completion. */ +# define GPU_SHADER_INTERFACE_INFO(_interface, _inst_name) \ + StageInterfaceInfo _interface(#_interface, _inst_name); \ + _interface +# define GPU_SHADER_CREATE_INFO(_info) \ + ShaderCreateInfo _info(#_info); \ + _info +#endif + +enum class Type { + FLOAT = 0, + VEC2, + VEC3, + VEC4, + MAT3, + MAT4, + UINT, + UVEC2, + UVEC3, + UVEC4, + INT, + IVEC2, + IVEC3, + IVEC4, + BOOL, +}; + +enum class BuiltinBits { + /** Allow getting barycentic coordinates inside the fragment shader. NOTE: emulated on OpenGL. */ + BARYCENTRIC_COORD = (1 << 0), + FRAG_COORD = (1 << 2), + FRONT_FACING = (1 << 4), + GLOBAL_INVOCATION_ID = (1 << 5), + INSTANCE_ID = (1 << 6), + LAYER = (1 << 7), + LOCAL_INVOCATION_ID = (1 << 8), + LOCAL_INVOCATION_INDEX = (1 << 9), + NUM_WORK_GROUP = (1 << 10), + POINT_COORD = (1 << 11), + POINT_SIZE = (1 << 12), + PRIMITIVE_ID = (1 << 13), + VERTEX_ID = (1 << 14), + WORK_GROUP_ID = (1 << 15), + WORK_GROUP_SIZE = (1 << 16), +}; +ENUM_OPERATORS(BuiltinBits, BuiltinBits::WORK_GROUP_SIZE); + +/* Samplers & images. */ +enum class ImageType { + /** Color samplers/image. */ + FLOAT_BUFFER = 0, + FLOAT_1D, + FLOAT_1D_ARRAY, + FLOAT_2D, + FLOAT_2D_ARRAY, + FLOAT_3D, + FLOAT_CUBE, + FLOAT_CUBE_ARRAY, + INT_BUFFER, + INT_1D, + INT_1D_ARRAY, + INT_2D, + INT_2D_ARRAY, + INT_3D, + INT_CUBE, + INT_CUBE_ARRAY, + UINT_BUFFER, + UINT_1D, + UINT_1D_ARRAY, + UINT_2D, + UINT_2D_ARRAY, + UINT_3D, + UINT_CUBE, + UINT_CUBE_ARRAY, + /** Depth samplers (not supported as image). */ + SHADOW_2D, + SHADOW_2D_ARRAY, + SHADOW_CUBE, + SHADOW_CUBE_ARRAY, + DEPTH_2D, + DEPTH_2D_ARRAY, + DEPTH_CUBE, + DEPTH_CUBE_ARRAY, +}; + +/* Storage qualifiers. */ +enum class Qualifier { + RESTRICT = (1 << 0), + READ_ONLY = (1 << 1), + WRITE_ONLY = (1 << 2), + QUALIFIER_MAX = (WRITE_ONLY << 1) - 1, +}; +ENUM_OPERATORS(Qualifier, Qualifier::QUALIFIER_MAX); + +enum class Frequency { + BATCH = 0, + PASS, +}; + +/* Dual Source Blending Index. */ +enum class DualBlend { + NONE = 0, + SRC_0, + SRC_1, +}; + +/* Interpolation qualifiers. */ +enum class Interpolation { + SMOOTH = 0, + FLAT, + NO_PERSPECTIVE, +}; + +/** Input layout for geometry shader. */ +enum class InputLayout { + POINTS = 0, + LINES, + LINES_ADJACENCY, + TRIANGLES, + TRIANGLES_ADJACENCY, +}; + +/** Output layout for geometry shader. */ +enum class OutputLayout { + POINTS = 0, + LINE_STRIP, + TRIANGLE_STRIP, +}; + +struct StageInterfaceInfo { + struct InOut { + Interpolation interp; + Type type; + StringRefNull name; + }; + + StringRefNull name; + /** Name of the instance of the block (used to access). + * Can be empty string (i.e: "") only if not using geometry shader. */ + StringRefNull instance_name; + /** List of all members of the interface. */ + Vector inouts; + + StageInterfaceInfo(const char *name_, const char *instance_name_) + : name(name_), instance_name(instance_name_){}; + ~StageInterfaceInfo(){}; + + using Self = StageInterfaceInfo; + + Self &smooth(Type type, StringRefNull _name) + { + inouts.append({Interpolation::SMOOTH, type, _name}); + return *(Self *)this; + } + + Self &flat(Type type, StringRefNull _name) + { + inouts.append({Interpolation::FLAT, type, _name}); + return *(Self *)this; + } + + Self &no_perspective(Type type, StringRefNull _name) + { + inouts.append({Interpolation::NO_PERSPECTIVE, type, _name}); + return *(Self *)this; + } +}; + +/** + * @brief Describe inputs & outputs, stage interfaces, resources and sources of a shader. + * If all data is correctly provided, this is all that is needed to create and compile + * a GPUShader. + * + * IMPORTANT: All strings are references only. Make sure all the strings used by a + * ShaderCreateInfo are not freed until it is consumed or deleted. + */ +struct ShaderCreateInfo { + /** Shader name for debugging. */ + StringRefNull name_; + /** True if the shader is static and can be precompiled at compile time. */ + bool do_static_compilation_ = false; + /** If true, all additionaly linked create info will be merged into this one. */ + bool finalized_ = false; + /** + * Maximum length of all the resource names including each null terminator. + * Only for names used by gpu::ShaderInterface. + */ + size_t interface_names_size_ = 0; + /** Only for compute shaders. */ + int local_group_size_[3] = {0, 0, 0}; + + struct VertIn { + int index; + Type type; + StringRefNull name; + }; + Vector vertex_inputs_; + + struct GeomIn { + InputLayout layout; + }; + GeomIn geom_in_; + + struct GeomOut { + OutputLayout layout; + int max_vertices; + }; + GeomOut geom_out_; + + struct FragOut { + int index; + Type type; + DualBlend blend; + StringRefNull name; + }; + Vector fragment_outputs_; + + struct Sampler { + ImageType type; + eGPUSamplerState sampler; + StringRefNull name; + }; + + struct Image { + eGPUTextureFormat format; + ImageType type; + Qualifier qualifiers; + StringRefNull name; + }; + + struct UniformBuf { + StringRefNull type_name; + StringRefNull name; + }; + + struct StorageBuf { + Qualifier qualifiers; + StringRefNull type_name; + StringRefNull name; + }; + + struct Resource { + enum BindType { + UNIFORM_BUFFER = 0, + STORAGE_BUFFER, + SAMPLER, + IMAGE, + }; + + BindType bind_type; + int slot; + union { + Sampler sampler; + Image image; + UniformBuf uniformbuf; + StorageBuf storagebuf; + }; + + Resource(BindType type, int _slot) : bind_type(type), slot(_slot){}; + }; + /** + * Resources are grouped by frequency of change. + * Pass resources are meants to be valid for the whole pass. + * Batch resources can be changed in a more granular manner (per object/material). + * Mis-usage will only produce suboptimal performance. + */ + Vector pass_resources_, batch_resources_; + + Vector vertex_out_interfaces_; + Vector geometry_out_interfaces_; + + struct PushConst { + int index; + Type type; + StringRefNull name; + int array_size; + }; + + Vector push_constants_; + + /* Sources for resources type definitions. */ + Vector typedef_sources_; + + StringRefNull vertex_source_, geometry_source_, fragment_source_, compute_source_; + + Vector> defines_; + /** + * Name of other infos to recursively merge with this one. + * No data slot must overlap otherwise we throw an error. + */ + Vector additional_infos_; + + public: + ShaderCreateInfo(const char *name) : name_(name){}; + ~ShaderCreateInfo(){}; + + using Self = ShaderCreateInfo; + + /* -------------------------------------------------------------------- */ + /** \name Shaders in/outs (fixed function pipeline config) + * \{ */ + + Self &vertex_in(int slot, Type type, StringRefNull name) + { + vertex_inputs_.append({slot, type, name}); + interface_names_size_ += name.size() + 1; + return *(Self *)this; + } + + Self &vertex_out(StageInterfaceInfo &interface) + { + vertex_out_interfaces_.append(&interface); + return *(Self *)this; + } + + Self &geometry_layout(InputLayout layout_in, OutputLayout layout_out, int max_vertices) + { + geom_in_.layout = layout_in; + geom_out_.layout = layout_out; + geom_out_.max_vertices = max_vertices; + return *(Self *)this; + } + + /* Only needed if geometry shader is enabled. */ + Self &geometry_out(StageInterfaceInfo &interface) + { + geometry_out_interfaces_.append(&interface); + return *(Self *)this; + } + + Self &fragment_out(int slot, Type type, StringRefNull name, DualBlend blend = DualBlend::NONE) + { + fragment_outputs_.append({slot, type, blend, name}); + return *(Self *)this; + } + + /** \} */ + + /* -------------------------------------------------------------------- */ + /** \name Resources bindings points + * \{ */ + + Self &uniform_buf(int slot, + StringRefNull type_name, + StringRefNull name, + Frequency freq = Frequency::PASS) + { + Resource res(Resource::BindType::UNIFORM_BUFFER, slot); + res.uniformbuf.name = name; + res.uniformbuf.type_name = type_name; + ((freq == Frequency::PASS) ? pass_resources_ : batch_resources_).append(res); + interface_names_size_ += name.size() + 1; + return *(Self *)this; + } + + Self &storage_buf(int slot, + Qualifier qualifiers, + StringRefNull type_name, + StringRefNull name, + Frequency freq = Frequency::PASS) + { + Resource res(Resource::BindType::STORAGE_BUFFER, slot); + res.storagebuf.qualifiers = qualifiers; + res.storagebuf.type_name = type_name; + res.storagebuf.name = name; + ((freq == Frequency::PASS) ? pass_resources_ : batch_resources_).append(res); + interface_names_size_ += name.size() + 1; + return *(Self *)this; + } + + Self &image(int slot, + eGPUTextureFormat format, + Qualifier qualifiers, + ImageType type, + StringRefNull name, + Frequency freq = Frequency::PASS) + { + Resource res(Resource::BindType::IMAGE, slot); + res.image.format = format; + res.image.qualifiers = qualifiers; + res.image.type = type; + res.image.name = name; + ((freq == Frequency::PASS) ? pass_resources_ : batch_resources_).append(res); + interface_names_size_ += name.size() + 1; + return *(Self *)this; + } + + Self &sampler(int slot, + ImageType type, + StringRefNull name, + Frequency freq = Frequency::PASS, + eGPUSamplerState sampler = (eGPUSamplerState)-1) + { + Resource res(Resource::BindType::SAMPLER, slot); + res.sampler.type = type; + res.sampler.name = name; + res.sampler.sampler = sampler; + ((freq == Frequency::PASS) ? pass_resources_ : batch_resources_).append(res); + interface_names_size_ += name.size() + 1; + return *(Self *)this; + } + + /** \} */ + + /* -------------------------------------------------------------------- */ + /** \name Shader Source + * \{ */ + + Self &vertex_source(StringRefNull filename) + { + vertex_source_ = filename; + return *(Self *)this; + } + + Self &geometry_source(StringRefNull filename) + { + geometry_source_ = filename; + return *(Self *)this; + } + + Self &fragment_source(StringRefNull filename) + { + fragment_source_ = filename; + return *(Self *)this; + } + + Self &compute_source(StringRefNull filename) + { + compute_source_ = filename; + return *(Self *)this; + } + + /** \} */ + + /* -------------------------------------------------------------------- */ + /** \name Push constants + * + * Data managed by GPUShader. Can be set through uniform functions. Must be less than 128bytes. + * One slot represents 4bytes. Each element needs to have enough empty space left after it. + * example: + * [0] = PUSH_CONSTANT(MAT4, "ModelMatrix"), + * ---- 16 slots occupied by ModelMatrix ---- + * [16] = PUSH_CONSTANT(VEC4, "color"), + * ---- 4 slots occupied by color ---- + * [20] = PUSH_CONSTANT(BOOL, "srgbToggle"), + * The maximum slot is 31. + * \{ */ + + Self &push_constant(int slot, Type type, StringRefNull name, int array_size = 0) + { + BLI_assert_msg(name.find("[") == -1, + "Array syntax is forbidden for push constants." + "Use the array_size parameter instead."); + push_constants_.append({slot, type, name, array_size}); + interface_names_size_ += name.size() + 1; + return *(Self *)this; + } + + /** \} */ + + /* -------------------------------------------------------------------- */ + /** \name Compute shaders Local Group Size + * \{ */ + + Self &local_group_size(int x, int y = 1, int z = 1) + { + local_group_size_[0] = x; + local_group_size_[1] = y; + local_group_size_[2] = z; + return *(Self *)this; + } + + /** \} */ + + /* -------------------------------------------------------------------- */ + /** \name Defines + * \{ */ + + Self &define(StringRefNull name, StringRefNull value = "") + { + defines_.append({name, value}); + return *(Self *)this; + } + + /** \} */ + + /* -------------------------------------------------------------------- */ + /** \name Defines + * \{ */ + + Self &do_static_compilation(bool value) + { + do_static_compilation_ = value; + return *(Self *)this; + } + + /** \} */ + + /* -------------------------------------------------------------------- */ + /** \name Additional Create Info + * + * Used to share parts of the infos that are common to many shaders. + * \{ */ + + Self &additional_info(StringRefNull info_name0, + StringRefNull info_name1 = "", + StringRefNull info_name2 = "", + StringRefNull info_name3 = "", + StringRefNull info_name4 = "") + { + additional_infos_.append(info_name0); + if (!info_name1.is_empty()) { + additional_infos_.append(info_name1); + } + if (!info_name2.is_empty()) { + additional_infos_.append(info_name2); + } + if (!info_name3.is_empty()) { + additional_infos_.append(info_name3); + } + if (!info_name4.is_empty()) { + additional_infos_.append(info_name4); + } + return *(Self *)this; + } + + /** \} */ + + /* -------------------------------------------------------------------- */ + /** \name Typedef Sources + * + * Some resource declarations might need some special structure defined. + * Adding a file using typedef_source will include it before the resource + * and interface definitions. + * \{ */ + + Self &typedef_source(StringRefNull filename) + { + typedef_sources_.append(filename); + return *(Self *)this; + } + + /** \} */ + + /* -------------------------------------------------------------------- */ + /** \name Recursive evaluation. + * + * Flatten all dependency so that this descriptor contains all the data from the additional + * descriptors. This avoids tedious traversal in shader source creation. + * \{ */ + + /* WARNING: Recursive. */ + void finalize(); + + /** \} */ +}; + +} // namespace blender::gpu::shader diff --git a/source/blender/gpu/intern/gpu_shader_create_info_private.hh b/source/blender/gpu/intern/gpu_shader_create_info_private.hh new file mode 100644 index 00000000000..7010fa5e3a2 --- /dev/null +++ b/source/blender/gpu/intern/gpu_shader_create_info_private.hh @@ -0,0 +1,46 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2021 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + * + * Descriptior type used to define shader structure, resources and interfaces. + * + * Some rule of thumb: + * - Do not include anything else than this file in each descriptor file. + */ + +#pragma once + +#include "GPU_shader.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_shader_create_info_init(void); +void gpu_shader_create_info_exit(void); + +bool gpu_shader_create_info_compile_all(void); + +const GPUShaderCreateInfo *gpu_shader_create_info_get(const char *info_name); + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/gpu/intern/gpu_shader_dependency.cc b/source/blender/gpu/intern/gpu_shader_dependency.cc new file mode 100644 index 00000000000..a866e9f1fda --- /dev/null +++ b/source/blender/gpu/intern/gpu_shader_dependency.cc @@ -0,0 +1,197 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2021 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + * + * Shader source dependency builder that make possible to support #include directive inside the + * shader files. + */ + +#include + +#include "BLI_map.hh" +#include "BLI_set.hh" +#include "BLI_string_ref.hh" + +#include "gpu_shader_create_info.hh" +#include "gpu_shader_dependency_private.h" + +extern "C" { +#define SHADER_SOURCE(datatoc, filename) extern char datatoc[]; +#include "glsl_draw_source_list.h" +#include "glsl_gpu_source_list.h" +#undef SHADER_SOURCE +} + +namespace blender::gpu { + +using GPUSourceDictionnary = Map; + +struct GPUSource { + StringRefNull filename; + StringRefNull source; + Vector dependencies; + bool dependencies_init = false; + shader::BuiltinBits builtins = (shader::BuiltinBits)0; + + GPUSource(const char *file, const char *datatoc) : filename(file), source(datatoc) + { + /* Scan for builtins. */ + /* FIXME: This can trigger false positive caused by disabled #if blocks. */ + /* TODO(fclem): Could be made faster by scanning once. */ + /* TODO(fclem): BARYCENTRIC_COORD. */ + if (source.find("gl_FragCoord", 0)) { + builtins |= shader::BuiltinBits::FRAG_COORD; + } + if (source.find("gl_FrontFacing", 0)) { + builtins |= shader::BuiltinBits::FRONT_FACING; + } + if (source.find("gl_GlobalInvocationID", 0)) { + builtins |= shader::BuiltinBits::GLOBAL_INVOCATION_ID; + } + if (source.find("gl_InstanceID", 0)) { + builtins |= shader::BuiltinBits::INSTANCE_ID; + } + if (source.find("gl_Layer", 0)) { + builtins |= shader::BuiltinBits::LAYER; + } + if (source.find("gl_LocalInvocationID", 0)) { + builtins |= shader::BuiltinBits::LOCAL_INVOCATION_ID; + } + if (source.find("gl_LocalInvocationIndex", 0)) { + builtins |= shader::BuiltinBits::LOCAL_INVOCATION_INDEX; + } + if (source.find("gl_NumWorkGroup", 0)) { + builtins |= shader::BuiltinBits::NUM_WORK_GROUP; + } + if (source.find("gl_PointCoord", 0)) { + builtins |= shader::BuiltinBits::POINT_COORD; + } + if (source.find("gl_PointSize", 0)) { + builtins |= shader::BuiltinBits::POINT_SIZE; + } + if (source.find("gl_PrimitiveID", 0)) { + builtins |= shader::BuiltinBits::PRIMITIVE_ID; + } + if (source.find("gl_VertexID", 0)) { + builtins |= shader::BuiltinBits::VERTEX_ID; + } + if (source.find("gl_WorkGroupID", 0)) { + builtins |= shader::BuiltinBits::WORK_GROUP_ID; + } + if (source.find("gl_WorkGroupSize", 0)) { + builtins |= shader::BuiltinBits::WORK_GROUP_SIZE; + } + }; + + void init_dependencies(const GPUSourceDictionnary &dict) + { + if (dependencies_init) { + return; + } + dependencies_init = true; + int64_t pos = 0; + while (true) { + pos = source.find("pragma BLENDER_REQUIRE(", pos); + if (pos == -1) { + return; + } + int64_t start = source.find("(", pos) + 1; + int64_t end = source.find(")", pos); + if (end == -1) { + /* TODO Use clog. */ + std::cout << "Error: " << filename << " : Malformed BLENDER_REQUIRE: Missing \")\"." + << std::endl; + return; + } + StringRef dependency_name = source.substr(start, end - start); + GPUSource *dependency_source = dict.lookup_default(dependency_name, nullptr); + if (dependency_source == nullptr) { + /* TODO Use clog. */ + std::cout << "Error: " << filename << " : Dependency not found \"" << dependency_name + << "\"." << std::endl; + return; + } + /* Recursive. */ + dependency_source->init_dependencies(dict); + + for (auto *dep : dependency_source->dependencies) { + dependencies.append_non_duplicates(dep); + } + dependencies.append_non_duplicates(dependency_source); + pos++; + }; + } + + /* Returns the final string with all inlcudes done. */ + void build(std::string &str, shader::BuiltinBits &out_builtins) + { + for (auto *dep : dependencies) { + out_builtins |= builtins; + str += dep->source; + } + str += source; + } +}; + +} // namespace blender::gpu + +using namespace blender::gpu; + +static GPUSourceDictionnary *g_sources = nullptr; + +void gpu_shader_dependency_init() +{ + g_sources = new GPUSourceDictionnary(); + +#define SHADER_SOURCE(datatoc, filename) \ + g_sources->add_new(filename, new GPUSource(filename, datatoc)); +#include "glsl_draw_source_list.h" +#include "glsl_gpu_source_list.h" +#undef SHADER_SOURCE + + for (auto *value : g_sources->values()) { + value->init_dependencies(*g_sources); + } +} + +void gpu_shader_dependency_exit() +{ + for (auto *value : g_sources->values()) { + delete value; + } + delete g_sources; +} + +char *gpu_shader_dependency_get_resolved_source(const char *shader_source_name, uint32_t *builtins) +{ + GPUSource *source = g_sources->lookup(shader_source_name); + std::string str; + shader::BuiltinBits out_builtins; + source->build(str, out_builtins); + *builtins |= (uint32_t)out_builtins; + return strdup(str.c_str()); +} + +char *gpu_shader_dependency_get_source(const char *shader_source_name) +{ + GPUSource *src = g_sources->lookup(shader_source_name); + return strdup(src->source.c_str()); +} diff --git a/source/blender/gpu/intern/gpu_shader_dependency_private.h b/source/blender/gpu/intern/gpu_shader_dependency_private.h new file mode 100644 index 00000000000..b129ca74a48 --- /dev/null +++ b/source/blender/gpu/intern/gpu_shader_dependency_private.h @@ -0,0 +1,44 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2021 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + * + * Shader source dependency builder that make possible to support #include directive inside the + * shader files. + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +void gpu_shader_dependency_init(void); + +void gpu_shader_dependency_exit(void); + +/* User must free the resulting string using free. */ +char *gpu_shader_dependency_get_resolved_source(const char *shader_source_name, + uint32_t *builtins); +char *gpu_shader_dependency_get_source(const char *shader_source_name); + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/gpu/intern/gpu_shader_info_baked.cc b/source/blender/gpu/intern/gpu_shader_info_baked.cc new file mode 100644 index 00000000000..00af803f765 --- /dev/null +++ b/source/blender/gpu/intern/gpu_shader_info_baked.cc @@ -0,0 +1,24 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2021 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + * + * Intentionally empty for compiling shader builder. + */ \ No newline at end of file diff --git a/source/blender/gpu/intern/gpu_shader_interface.hh b/source/blender/gpu/intern/gpu_shader_interface.hh index 4bd8f245e2b..735b8fea71d 100644 --- a/source/blender/gpu/intern/gpu_shader_interface.hh +++ b/source/blender/gpu/intern/gpu_shader_interface.hh @@ -34,6 +34,7 @@ #include "BLI_utildefines.h" #include "GPU_shader.h" +#include "gpu_shader_create_info.hh" namespace blender::gpu { @@ -50,6 +51,7 @@ typedef struct ShaderInput { * Base class which is then specialized for each implementation (GL, VK, ...). */ class ShaderInterface { + friend shader::ShaderCreateInfo; /* TODO(fclem): should be protected. */ public: /** Flat array. In this order: Attributes, Ubos, Uniforms. */ @@ -72,6 +74,7 @@ class ShaderInterface { public: ShaderInterface(); + ShaderInterface(const shader::ShaderCreateInfo &info); virtual ~ShaderInterface(); void debug_print(); @@ -129,6 +132,10 @@ class ShaderInterface { static inline const char *builtin_uniform_block_name(GPUUniformBlockBuiltin u); inline uint32_t set_input_name(ShaderInput *input, char *name, uint32_t name_len) const; + inline void copy_input_name(ShaderInput *input, + const StringRefNull &name, + char *name_buffer, + uint32_t &name_buffer_offset) const; /** * Finalize interface construction by sorting the #ShaderInputs for faster lookups. @@ -216,8 +223,12 @@ inline uint32_t ShaderInterface::set_input_name(ShaderInput *input, { /* remove "[0]" from array name */ if (name[name_len - 1] == ']') { - name[name_len - 3] = '\0'; - name_len -= 3; + for (; name_len > 1; name_len--) { + if (name[name_len] == '[') { + name[name_len] = '\0'; + break; + } + } } input->name_offset = (uint32_t)(name - name_buffer_); @@ -225,6 +236,17 @@ inline uint32_t ShaderInterface::set_input_name(ShaderInput *input, return name_len + 1; /* include NULL terminator */ } +inline void ShaderInterface::copy_input_name(ShaderInput *input, + const StringRefNull &name, + char *name_buffer, + uint32_t &name_buffer_offset) const +{ + uint32_t name_len = name.size(); + /* Copy include NULL terminator. */ + memcpy(name_buffer + name_buffer_offset, name.c_str(), name_len + 1); + name_buffer_offset += set_input_name(input, name_buffer + name_buffer_offset, name_len); +} + inline const ShaderInput *ShaderInterface::input_lookup(const ShaderInput *const inputs, const uint inputs_len, const char *name) const diff --git a/source/blender/gpu/intern/gpu_shader_private.hh b/source/blender/gpu/intern/gpu_shader_private.hh index 498dd8f3877..7837af0dcf2 100644 --- a/source/blender/gpu/intern/gpu_shader_private.hh +++ b/source/blender/gpu/intern/gpu_shader_private.hh @@ -24,9 +24,12 @@ #include "BLI_string_ref.hh" #include "GPU_shader.h" +#include "gpu_shader_create_info.hh" #include "gpu_shader_interface.hh" #include "gpu_vertex_buffer_private.hh" +#include + namespace blender { namespace gpu { @@ -53,7 +56,7 @@ class Shader { virtual void geometry_shader_from_glsl(MutableSpan sources) = 0; virtual void fragment_shader_from_glsl(MutableSpan sources) = 0; virtual void compute_shader_from_glsl(MutableSpan sources) = 0; - virtual bool finalize() = 0; + virtual bool finalize(const shader::ShaderCreateInfo *info = nullptr) = 0; virtual void transform_feedback_names_set(Span name_list, eGPUShaderTFBType geom_type) = 0; @@ -68,6 +71,13 @@ class Shader { virtual void vertformat_from_shader(GPUVertFormat *) const = 0; + std::string defines_declare(const shader::ShaderCreateInfo &info) const; + virtual std::string resources_declare(const shader::ShaderCreateInfo &info) const = 0; + virtual std::string vertex_interface_declare(const shader::ShaderCreateInfo &info) const = 0; + virtual std::string fragment_interface_declare(const shader::ShaderCreateInfo &info) const = 0; + virtual std::string geometry_interface_declare(const shader::ShaderCreateInfo &info) const = 0; + virtual std::string geometry_layout_declare(const shader::ShaderCreateInfo &info) const = 0; + /* DEPRECATED: Kept only because of BGL API. */ virtual int program_handle_get() const = 0; diff --git a/source/blender/gpu/intern/gpu_shader_shared_utils.h b/source/blender/gpu/intern/gpu_shader_shared_utils.h new file mode 100644 index 00000000000..7e5d2240851 --- /dev/null +++ b/source/blender/gpu/intern/gpu_shader_shared_utils.h @@ -0,0 +1,110 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + * + * Glue definition to make shared declaration of struct & functions work in both C / C++ and GLSL. + * We use the same vector and matrix types as Blender C++. Some math functions are defined to use + * the float version to match the GLSL syntax. + * This file can be used for C & C++ code and the syntax used should follow the same rules. + * Some preprocessing is done by the GPU backend to make it GLSL compatible. + * + * IMPORTANT: + * - Don't add trailing comma at the end of the enum. Our custom pre-processor will noy trim it + * for GLSL. + * - Always use `u` suffix for enum values. GLSL do not support implicit cast. + * - Define all values. This is in order to simplify custom pre-processor code. + * - Always use uint32_t as underlying type. + * - Use float suffix by default for float literals to avoid double promotion in C++. + * - Pack one float or int after a vec3/ivec3 to fullfil alligment rules. + * + * NOTE: Due to alignment restriction and buggy drivers, do not try to use mat3 inside structs. + * NOTE: (UBO only) Do not use arrays of float. They are padded to arrays of vec4 and are not worth + * it. This does not apply to SSBO. + * + * IMPORTANT: Do not forget to align mat4, vec3 and vec4 to 16 bytes, and vec2 to 8 bytes. + * + * NOTE: You can use bool type using bool1 a int boolean type matching the GLSL type. + */ + +#ifdef GPU_SHADER +# define BLI_STATIC_ASSERT_ALIGN(type_, align_) +# define BLI_STATIC_ASSERT_SIZE(type_, size_) +# define static +# define inline +# define cosf cos +# define sinf sin +# define tanf tan +# define acosf acos +# define asinf asin +# define atanf atan +# define floorf floor +# define ceilf ceil +# define sqrtf sqrt + +# define float2 vec2 +# define float3 vec3 +# define float4 vec4 +# define float4x4 mat4 +# define int2 ivec2 +# define int3 ivec3 +# define int4 ivec4 +# define uint2 uvec2 +# define uint3 uvec3 +# define uint4 uvec4 +# define bool1 bool +# define bool2 bvec2 +# define bool3 bvec3 +# define bool4 bvec4 + +#else /* C */ +# pragma once + +# include "BLI_assert.h" + +# ifdef __cplusplus +# include "BLI_float2.hh" +# include "BLI_float3.hh" +# include "BLI_float4.hh" +# include "BLI_float4x4.hh" +/* TODO */ +// # include "BLI_int2.hh" +// # include "BLI_int3.hh" +# else +typedef float float2[2]; +typedef float float3[3]; +typedef float float4[4]; +typedef float float4x4[4][4]; +# endif +typedef int int2[2]; +typedef int int3[2]; +typedef int int4[4]; +typedef uint uint2[2]; +typedef uint uint3[3]; +typedef uint uint4[4]; +typedef int int2[2]; +typedef int int3[2]; +typedef int int4[4]; +typedef int bool1; +typedef int bool2[2]; +typedef int bool3[2]; +typedef int bool4[4]; + +#endif \ No newline at end of file diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc index 7bb88894b81..33574da9f58 100644 --- a/source/blender/gpu/opengl/gl_backend.cc +++ b/source/blender/gpu/opengl/gl_backend.cc @@ -434,6 +434,7 @@ bool GLContext::clear_texture_support = false; bool GLContext::copy_image_support = false; bool GLContext::debug_layer_support = false; bool GLContext::direct_state_access_support = false; +bool GLContext::explicit_location_support = false; bool GLContext::fixed_restart_index_support = false; bool GLContext::multi_bind_support = false; bool GLContext::multi_draw_indirect_support = false; @@ -492,6 +493,7 @@ void GLBackend::capabilities_init() GLContext::copy_image_support = GLEW_ARB_copy_image; GLContext::debug_layer_support = GLEW_VERSION_4_3 || GLEW_KHR_debug || GLEW_ARB_debug_output; GLContext::direct_state_access_support = GLEW_ARB_direct_state_access; + GLContext::explicit_location_support = GLEW_VERSION_4_3; GLContext::fixed_restart_index_support = GLEW_ARB_ES3_compatibility; GLContext::multi_bind_support = GLEW_ARB_multi_bind; GLContext::multi_draw_indirect_support = GLEW_ARB_multi_draw_indirect; diff --git a/source/blender/gpu/opengl/gl_context.hh b/source/blender/gpu/opengl/gl_context.hh index 656f4a1caf2..eb365382d53 100644 --- a/source/blender/gpu/opengl/gl_context.hh +++ b/source/blender/gpu/opengl/gl_context.hh @@ -69,6 +69,7 @@ class GLContext : public Context { static bool copy_image_support; static bool debug_layer_support; static bool direct_state_access_support; + static bool explicit_location_support; static bool fixed_restart_index_support; static bool multi_bind_support; static bool multi_draw_indirect_support; diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc index 8367b0de02b..fe5ffe5a2ad 100644 --- a/source/blender/gpu/opengl/gl_shader.cc +++ b/source/blender/gpu/opengl/gl_shader.cc @@ -38,6 +38,7 @@ using namespace blender; using namespace blender::gpu; +using namespace blender::gpu::shader; /* -------------------------------------------------------------------- */ /** \name Creation / Destruction @@ -70,6 +71,429 @@ GLShader::~GLShader() /** \} */ +/* -------------------------------------------------------------------- */ +/** \name Create Info + * \{ */ + +static const char *to_string(const Interpolation &interp) +{ + switch (interp) { + case Interpolation::SMOOTH: + return "smooth"; + case Interpolation::FLAT: + return "flat"; + case Interpolation::NO_PERSPECTIVE: + return "noperspective"; + default: + return "unkown"; + } +} + +static const char *to_string(const Type &type) +{ + switch (type) { + case Type::FLOAT: + return "float"; + case Type::VEC2: + return "vec2"; + case Type::VEC3: + return "vec3"; + case Type::VEC4: + return "vec4"; + case Type::MAT3: + return "mat3"; + case Type::MAT4: + return "mat4"; + case Type::UINT: + return "uint"; + case Type::UVEC2: + return "uvec2"; + case Type::UVEC3: + return "uvec3"; + case Type::UVEC4: + return "uvec4"; + case Type::INT: + return "int"; + case Type::IVEC2: + return "ivec2"; + case Type::IVEC3: + return "ivec3"; + case Type::IVEC4: + return "ivec4"; + case Type::BOOL: + return "bool"; + default: + return "unkown"; + } +} + +static const char *to_string(const InputLayout &layout) +{ + switch (layout) { + case InputLayout::POINTS: + return "points"; + case InputLayout::LINES: + return "lines"; + case InputLayout::LINES_ADJACENCY: + return "lines_adjacency"; + case InputLayout::TRIANGLES: + return "triangles"; + case InputLayout::TRIANGLES_ADJACENCY: + return "triangles_adjacency"; + default: + return "unknown"; + } +} + +static const char *to_string(const OutputLayout &layout) +{ + switch (layout) { + case OutputLayout::POINTS: + return "points"; + case OutputLayout::LINE_STRIP: + return "line_strip"; + case OutputLayout::TRIANGLE_STRIP: + return "triangle_strip"; + default: + return "unknown"; + } +} + +static void print_image_type(std::ostream &os, + const ImageType &type, + const ShaderCreateInfo::Resource::BindType bind_type) +{ + switch (type) { + case ImageType::INT_BUFFER: + case ImageType::INT_1D: + case ImageType::INT_1D_ARRAY: + case ImageType::INT_2D: + case ImageType::INT_2D_ARRAY: + case ImageType::INT_3D: + case ImageType::INT_CUBE: + case ImageType::INT_CUBE_ARRAY: + os << "i"; + break; + case ImageType::UINT_BUFFER: + case ImageType::UINT_1D: + case ImageType::UINT_1D_ARRAY: + case ImageType::UINT_2D: + case ImageType::UINT_2D_ARRAY: + case ImageType::UINT_3D: + case ImageType::UINT_CUBE: + case ImageType::UINT_CUBE_ARRAY: + os << "u"; + break; + default: + break; + } + + if (bind_type == ShaderCreateInfo::Resource::BindType::IMAGE) { + os << "image"; + } + else { + os << "sampler"; + } + + switch (type) { + case ImageType::FLOAT_BUFFER: + case ImageType::INT_BUFFER: + case ImageType::UINT_BUFFER: + os << "Buffer"; + break; + case ImageType::FLOAT_1D: + case ImageType::FLOAT_1D_ARRAY: + case ImageType::INT_1D: + case ImageType::INT_1D_ARRAY: + case ImageType::UINT_1D: + case ImageType::UINT_1D_ARRAY: + os << "1D"; + break; + case ImageType::FLOAT_2D: + case ImageType::FLOAT_2D_ARRAY: + case ImageType::INT_2D: + case ImageType::INT_2D_ARRAY: + case ImageType::UINT_2D: + case ImageType::UINT_2D_ARRAY: + case ImageType::SHADOW_2D: + case ImageType::SHADOW_2D_ARRAY: + os << "2D"; + break; + case ImageType::FLOAT_3D: + case ImageType::INT_3D: + case ImageType::UINT_3D: + os << "3D"; + break; + case ImageType::FLOAT_CUBE: + case ImageType::FLOAT_CUBE_ARRAY: + case ImageType::INT_CUBE: + case ImageType::INT_CUBE_ARRAY: + case ImageType::UINT_CUBE: + case ImageType::UINT_CUBE_ARRAY: + case ImageType::SHADOW_CUBE: + case ImageType::SHADOW_CUBE_ARRAY: + os << "Cube"; + break; + default: + break; + } + + switch (type) { + case ImageType::FLOAT_1D_ARRAY: + case ImageType::FLOAT_2D_ARRAY: + case ImageType::FLOAT_CUBE_ARRAY: + case ImageType::INT_1D_ARRAY: + case ImageType::INT_2D_ARRAY: + case ImageType::INT_CUBE_ARRAY: + case ImageType::UINT_1D_ARRAY: + case ImageType::UINT_2D_ARRAY: + case ImageType::UINT_CUBE_ARRAY: + case ImageType::SHADOW_2D_ARRAY: + case ImageType::SHADOW_CUBE_ARRAY: + os << "Array"; + break; + default: + break; + } + + switch (type) { + case ImageType::SHADOW_2D: + case ImageType::SHADOW_2D_ARRAY: + case ImageType::SHADOW_CUBE: + case ImageType::SHADOW_CUBE_ARRAY: + os << "Shadow"; + break; + default: + break; + } + os << " "; +} + +static std::ostream &print_qualifier(std::ostream &os, const Qualifier &qualifiers) +{ + if ((qualifiers & Qualifier::RESTRICT) != Qualifier::RESTRICT) { + os << "restrict"; + } + if ((qualifiers & Qualifier::READ_ONLY) != Qualifier::READ_ONLY) { + os << "readonly"; + } + if ((qualifiers & Qualifier::WRITE_ONLY) != Qualifier::WRITE_ONLY) { + os << "writeonly"; + } + return os << " "; +} + +static void print_resource(std::ostream &os, const ShaderCreateInfo::Resource &res) +{ + if (res.bind_type != ShaderCreateInfo::Resource::BindType::SAMPLER || + GLContext::explicit_location_support) { + os << "layout(binding = " << res.slot; + if (res.bind_type == ShaderCreateInfo::Resource::BindType::IMAGE) { + os << ", " << res.image.format; + } + else if (res.bind_type == ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER) { + os << ", std140"; + } + else if (res.bind_type == ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER) { + os << ", std430"; + } + os << ") "; + } + + int64_t array_offset; + StringRef name_no_array; + + switch (res.bind_type) { + case ShaderCreateInfo::Resource::BindType::SAMPLER: + os << "uniform "; + print_image_type(os, res.sampler.type, res.bind_type); + os << res.sampler.name << ";\n"; + break; + case ShaderCreateInfo::Resource::BindType::IMAGE: + os << "uniform "; + print_qualifier(os, res.image.qualifiers); + print_image_type(os, res.image.type, res.bind_type); + os << res.image.name << ";\n"; + break; + case ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER: + array_offset = res.uniformbuf.name.find_first_of("["); + name_no_array = (array_offset == -1) ? res.uniformbuf.name : + StringRef(res.uniformbuf.name.c_str(), array_offset); + os << "uniform " << name_no_array << " { " << res.uniformbuf.type_name << " _" + << res.uniformbuf.name << "; };\n"; + break; + case ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER: + array_offset = res.storagebuf.name.find_first_of("["); + name_no_array = (array_offset == -1) ? res.storagebuf.name : + StringRef(res.storagebuf.name.c_str(), array_offset); + os << "buffer "; + print_qualifier(os, res.storagebuf.qualifiers); + os << name_no_array << " { " << res.storagebuf.type_name << " _" << res.storagebuf.name + << "; };\n"; + break; + } +} + +static void print_resource_alias(std::ostream &os, const ShaderCreateInfo::Resource &res) +{ + int64_t array_offset; + StringRef name_no_array; + + switch (res.bind_type) { + case ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER: + array_offset = res.uniformbuf.name.find_first_of("["); + name_no_array = (array_offset == -1) ? res.uniformbuf.name : + StringRef(res.uniformbuf.name.c_str(), array_offset); + os << "#define " << name_no_array << " (_" << name_no_array << ")\n"; + break; + case ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER: + array_offset = res.storagebuf.name.find_first_of("["); + name_no_array = (array_offset == -1) ? res.storagebuf.name : + StringRef(res.storagebuf.name.c_str(), array_offset); + os << "#define " << name_no_array << " (_" << name_no_array << ")\n"; + break; + default: + break; + } +} + +static void print_interface(std::ostream &os, + const StringRefNull &prefix, + const StageInterfaceInfo &iface, + const StringRefNull &suffix = "") +{ + /* TODO(fclem) Move that to interface check. */ + // if (iface.instance_name.is_empty()) { + // BLI_assert_msg(0, "Interfaces require an instance name for geometry shader."); + // std::cout << iface.name << ": Interfaces require an instance name for geometry shader.\n"; + // continue; + // } + os << prefix << " " << iface.name << "{" << std::endl; + for (const StageInterfaceInfo::InOut &inout : iface.inouts) { + os << " " << to_string(inout.interp) << " " << to_string(inout.type) << " " << inout.name + << ";\n"; + } + os << "}"; + os << (iface.instance_name.is_empty() ? "" : "\n") << iface.instance_name << suffix << ";\n"; +} + +std::string GLShader::resources_declare(const ShaderCreateInfo &info) const +{ + std::stringstream ss; + + /* NOTE: We define macros in GLSL to trigger compilation error if the resource names + * are reused for local variables. This is to match other backend behavior which needs accessors + * macros. */ + + ss << "\n/* Pass Resources. */\n"; + for (const ShaderCreateInfo::Resource &res : info.pass_resources_) { + print_resource(ss, res); + } + for (const ShaderCreateInfo::Resource &res : info.pass_resources_) { + print_resource_alias(ss, res); + } + ss << "\n/* Batch Resources. */\n"; + for (const ShaderCreateInfo::Resource &res : info.batch_resources_) { + print_resource(ss, res); + } + for (const ShaderCreateInfo::Resource &res : info.batch_resources_) { + print_resource_alias(ss, res); + } + ss << "\n/* Push Constants. */\n"; + for (const ShaderCreateInfo::PushConst &uniform : info.push_constants_) { + if (GLContext::explicit_location_support) { + ss << "layout(location = " << uniform.index << ") "; + } + ss << "uniform " << to_string(uniform.type) << " " << uniform.name; + if (uniform.array_size > 0) { + ss << "[" << uniform.array_size << "]"; + } + ss << ";\n"; + } + for (const ShaderCreateInfo::PushConst &uniform : info.push_constants_) { + ss << "#define " << uniform.name << " (" << uniform.name << ")\n"; + } + ss << "\n"; + return ss.str(); +} + +std::string GLShader::vertex_interface_declare(const ShaderCreateInfo &info) const +{ + std::stringstream ss; + + ss << "\n/* Inputs. */\n"; + for (const ShaderCreateInfo::VertIn &attr : info.vertex_inputs_) { + if (GLContext::explicit_location_support) { + ss << "layout(location = " << attr.index << ") "; + } + ss << "in " << to_string(attr.type) << " " << attr.name << ";\n"; + } + ss << "\n/* Interfaces. */\n"; + for (const StageInterfaceInfo *iface : info.vertex_out_interfaces_) { + print_interface(ss, "out", *iface); + } + ss << "\n"; + return ss.str(); +} + +std::string GLShader::fragment_interface_declare(const ShaderCreateInfo &info) const +{ + std::stringstream ss; + ss << "\n/* Interfaces. */\n"; + const Vector &in_interfaces = (info.geometry_source_.is_empty()) ? + info.vertex_out_interfaces_ : + info.geometry_out_interfaces_; + for (const StageInterfaceInfo *iface : in_interfaces) { + print_interface(ss, "in", *iface); + } + ss << "\n/* Outputs. */\n"; + for (const ShaderCreateInfo::FragOut &output : info.fragment_outputs_) { + ss << "layout(location = " << output.index; + switch (output.blend) { + case DualBlend::SRC_0: + ss << ", index = 0"; + break; + case DualBlend::SRC_1: + ss << ", index = 1"; + break; + default: + break; + } + ss << ") "; + ss << "out " << to_string(output.type) << " " << output.name << ";\n"; + } + ss << "\n"; + return ss.str(); +} + +std::string GLShader::geometry_layout_declare(const ShaderCreateInfo &info) const +{ + std::stringstream ss; + ss << "\n/* Layout. */\n"; + ss << "layout(" << to_string(info.geom_in_.layout) << ") in;\n"; + ss << "layout(" << to_string(info.geom_out_.layout) + << ", max_vertices = " << info.geom_out_.max_vertices << ") out;\n"; + ss << "\n"; + return ss.str(); +} + +std::string GLShader::geometry_interface_declare(const ShaderCreateInfo &info) const +{ + std::stringstream ss; + ss << "\n/* Interfaces. */\n"; + for (const StageInterfaceInfo *iface : info.vertex_out_interfaces_) { + print_interface(ss, "in", *iface, "[]"); + } + ss << "\n"; + for (const StageInterfaceInfo *iface : info.geometry_out_interfaces_) { + print_interface(ss, "out", *iface); + } + ss << "\n"; + return ss.str(); +} + +/** \} */ + /* -------------------------------------------------------------------- */ /** \name Shader stage creation * \{ */ @@ -84,7 +508,12 @@ static char *glsl_patch_default_get() size_t slen = 0; /* Version need to go first. */ - STR_CONCAT(patch, slen, "#version 330\n"); + if (GLEW_VERSION_4_3) { + STR_CONCAT(patch, slen, "#version 430\n"); + } + else { + STR_CONCAT(patch, slen, "#version 330\n"); + } /* Enable extensions for features that are not part of our base GLSL version * don't use an extension for something already available! */ @@ -206,7 +635,7 @@ void GLShader::compute_shader_from_glsl(MutableSpan sources) compute_shader_ = this->create_shader_stage(GL_COMPUTE_SHADER, sources); } -bool GLShader::finalize() +bool GLShader::finalize(const shader::ShaderCreateInfo *info) { if (compilation_failed_) { return false; @@ -225,7 +654,12 @@ bool GLShader::finalize() return false; } - interface = new GLShaderInterface(shader_program_); + if (info != nullptr) { + interface = new GLShaderInterface(shader_program_, *info); + } + else { + interface = new GLShaderInterface(shader_program_); + } return true; } diff --git a/source/blender/gpu/opengl/gl_shader.hh b/source/blender/gpu/opengl/gl_shader.hh index 9ea1334b862..af92c77db54 100644 --- a/source/blender/gpu/opengl/gl_shader.hh +++ b/source/blender/gpu/opengl/gl_shader.hh @@ -27,6 +27,7 @@ #include "glew-mx.h" +#include "gpu_shader_create_info.hh" #include "gpu_shader_private.hh" namespace blender { @@ -36,6 +37,9 @@ namespace gpu { * Implementation of shader compilation and uniforms handling using OpenGL. */ class GLShader : public Shader { + friend shader::ShaderCreateInfo; + friend shader::StageInterfaceInfo; + private: /** Handle for full program (links shader stages below). */ GLuint shader_program_ = 0; @@ -58,7 +62,13 @@ class GLShader : public Shader { void geometry_shader_from_glsl(MutableSpan sources) override; void fragment_shader_from_glsl(MutableSpan sources) override; void compute_shader_from_glsl(MutableSpan sources) override; - bool finalize() override; + bool finalize(const shader::ShaderCreateInfo *info = nullptr) override; + + std::string resources_declare(const shader::ShaderCreateInfo &info) const override; + std::string vertex_interface_declare(const shader::ShaderCreateInfo &info) const override; + std::string fragment_interface_declare(const shader::ShaderCreateInfo &info) const override; + std::string geometry_interface_declare(const shader::ShaderCreateInfo &info) const override; + std::string geometry_layout_declare(const shader::ShaderCreateInfo &info) const override; /** Should be called before linking. */ void transform_feedback_names_set(Span name_list, diff --git a/source/blender/gpu/opengl/gl_shader_interface.cc b/source/blender/gpu/opengl/gl_shader_interface.cc index 9900a4e0766..9dd7b1d57c3 100644 --- a/source/blender/gpu/opengl/gl_shader_interface.cc +++ b/source/blender/gpu/opengl/gl_shader_interface.cc @@ -25,7 +25,9 @@ #include "BLI_bitmap.h" +#include "gl_backend.hh" #include "gl_batch.hh" +#include "gl_context.hh" #include "gl_shader_interface.hh" @@ -323,6 +325,137 @@ GLShaderInterface::GLShaderInterface(GLuint program) this->sort_inputs(); } +GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateInfo &info) +{ + using namespace blender::gpu::shader; + + attr_len_ = info.vertex_inputs_.size(); + uniform_len_ = info.push_constants_.size(); + ubo_len_ = 0; + ssbo_len_ = 0; + + Vector all_resources; + all_resources.extend(info.pass_resources_); + all_resources.extend(info.batch_resources_); + + for (ShaderCreateInfo::Resource &res : all_resources) { + switch (res.bind_type) { + case ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER: + ubo_len_++; + break; + case ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER: + ssbo_len_++; + break; + case ShaderCreateInfo::Resource::BindType::SAMPLER: + uniform_len_++; + break; + case ShaderCreateInfo::Resource::BindType::IMAGE: + uniform_len_++; + break; + } + } + + BLI_assert_msg(ubo_len_ <= 16, "enabled_ubo_mask_ is uint16_t"); + + int input_tot_len = attr_len_ + ubo_len_ + uniform_len_ + ssbo_len_; + inputs_ = (ShaderInput *)MEM_callocN(sizeof(ShaderInput) * input_tot_len, __func__); + ShaderInput *input = inputs_; + + name_buffer_ = (char *)MEM_mallocN(info.interface_names_size_, "name_buffer"); + uint32_t name_buffer_offset = 0; + + /* Attributes */ + for (const ShaderCreateInfo::VertIn &attr : info.vertex_inputs_) { + copy_input_name(input, attr.name, name_buffer_, name_buffer_offset); + if (true || !GLContext::explicit_location_support) { + input->location = input->binding = glGetAttribLocation(program, attr.name.c_str()); + } + else { + input->location = input->binding = attr.index; + } + enabled_attr_mask_ |= (1 << input->location); + input++; + } + + /* Uniform Blocks */ + for (const ShaderCreateInfo::Resource &res : all_resources) { + if (res.bind_type == ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER) { + copy_input_name(input, res.uniformbuf.name, name_buffer_, name_buffer_offset); + if (true || !GLContext::explicit_location_support) { + input->location = glGetUniformBlockIndex(program, res.uniformbuf.name.c_str()); + glUniformBlockBinding(program, input->location, res.slot); + } + input->binding = res.slot; + enabled_ubo_mask_ |= (1 << input->binding); + input++; + } + } + + /* Uniforms & samplers & images */ + for (const ShaderCreateInfo::Resource &res : all_resources) { + if (res.bind_type == ShaderCreateInfo::Resource::BindType::SAMPLER) { + copy_input_name(input, res.sampler.name, name_buffer_, name_buffer_offset); + /* Until we make use of explicit uniform location or eliminate all + * sampler manually changing. */ + if (true || !GLContext::explicit_location_support) { + input->location = glGetUniformLocation(program, res.sampler.name.c_str()); + glUniform1i(input->location, res.slot); + } + input->binding = res.slot; + enabled_tex_mask_ |= (1 << input->binding); + input++; + } + else if (res.bind_type == ShaderCreateInfo::Resource::BindType::IMAGE) { + copy_input_name(input, res.image.name, name_buffer_, name_buffer_offset); + /* Until we make use of explicit uniform location. */ + if (true || !GLContext::explicit_location_support) { + input->location = glGetUniformLocation(program, res.image.name.c_str()); + glUniform1i(input->location, res.slot); + } + input->binding = res.slot; + enabled_ima_mask_ |= (1 << input->binding); + input++; + } + } + for (const ShaderCreateInfo::PushConst &uni : info.push_constants_) { + copy_input_name(input, uni.name, name_buffer_, name_buffer_offset); + /* Until we make use of explicit uniform location. */ + if (true || !GLContext::explicit_location_support) { + input->location = glGetUniformLocation(program, uni.name.c_str()); + } + input->binding = -1; + input++; + } + + /* SSBOs */ + for (const ShaderCreateInfo::Resource &res : all_resources) { + if (res.bind_type == ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER) { + copy_input_name(input, res.storagebuf.name, name_buffer_, name_buffer_offset); + input->location = input->binding = res.slot; + enabled_ubo_mask_ |= (1 << input->binding); + input++; + } + } + + /* Builtin Uniforms */ + for (int32_t u_int = 0; u_int < GPU_NUM_UNIFORMS; u_int++) { + GPUUniformBuiltin u = static_cast(u_int); + const ShaderInput *uni = this->uniform_get(builtin_uniform_name(u)); + builtins_[u] = (uni != nullptr) ? uni->location : -1; + } + + /* Builtin Uniforms Blocks */ + for (int32_t u_int = 0; u_int < GPU_NUM_UNIFORM_BLOCKS; u_int++) { + GPUUniformBlockBuiltin u = static_cast(u_int); + const ShaderInput *block = this->ubo_get(builtin_uniform_block_name(u)); + builtin_blocks_[u] = (block != nullptr) ? block->binding : -1; + } + + this->sort_inputs(); + + // this->debug_print(); +} + GLShaderInterface::~GLShaderInterface() { for (auto *ref : refs_) { diff --git a/source/blender/gpu/opengl/gl_shader_interface.hh b/source/blender/gpu/opengl/gl_shader_interface.hh index 89a5b631047..94b6dd58316 100644 --- a/source/blender/gpu/opengl/gl_shader_interface.hh +++ b/source/blender/gpu/opengl/gl_shader_interface.hh @@ -34,6 +34,7 @@ #include "glew-mx.h" +#include "gpu_shader_create_info.hh" #include "gpu_shader_interface.hh" namespace blender::gpu { @@ -49,6 +50,7 @@ class GLShaderInterface : public ShaderInterface { Vector refs_; public: + GLShaderInterface(GLuint program, const shader::ShaderCreateInfo &info); GLShaderInterface(GLuint program); ~GLShaderInterface(); diff --git a/source/blender/gpu/shaders/gpu_shader_2D_area_borders_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_area_borders_frag.glsl index 5a36b414229..4ebcb9c397f 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_area_borders_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_area_borders_frag.glsl @@ -1,10 +1,11 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform vec4 color; uniform float scale; in vec2 uv; out vec4 fragColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_area_borders_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_area_borders_vert.glsl index d20ddcd27c0..c6f01d68eee 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_area_borders_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_area_borders_vert.glsl @@ -1,4 +1,4 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; uniform vec4 rect; @@ -8,6 +8,7 @@ uniform float scale; in vec2 pos; out vec2 uv; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_flat_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_flat_color_vert.glsl index df2507c0dc9..494ef8d888e 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_flat_color_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_flat_color_vert.glsl @@ -1,10 +1,11 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; in vec2 pos; in vec4 color; flat out vec4 finalColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl index bdc0d37a7ae..f4d8a941a6d 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl @@ -4,7 +4,8 @@ */ /* Same as ICON_DRAW_CACHE_SIZE */ -#define MAX_CALLS 16 +#ifndef USE_GPU_SHADER_CREATE_INFO +# define MAX_CALLS 16 uniform vec4 calls_data[MAX_CALLS * 3]; @@ -12,6 +13,7 @@ out vec2 texCoord_interp; flat out vec4 finalColor; in vec2 pos; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl index ab9c30505c2..d9a5aeeef46 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl @@ -3,11 +3,13 @@ * does not need any vertex input (producing less call to immBegin/End) */ +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; uniform vec4 rect_icon; uniform vec4 rect_geom; out vec2 texCoord_interp; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl index cdb066c9c52..0b5e3759dfb 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl @@ -1,10 +1,11 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; /* Keep in sync with intern/opencolorio/gpu_shader_display_transform_vertex.glsl */ in vec2 texCoord; in vec2 pos; out vec2 texCoord_interp; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl index 43f259671fa..af9a24d1280 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl @@ -6,6 +6,8 @@ * Dashed is performed in screen space. */ +#ifndef USE_GPU_SHADER_CREATE_INFO + uniform float dash_width; /* Simple mode, discarding non-dash parts (so no need for blending at all). */ @@ -23,6 +25,7 @@ noperspective in vec2 stipple_pos; flat in vec2 stipple_start; out vec4 fragColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl index 15362d020e4..9d52820188b 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl @@ -5,7 +5,7 @@ * * Dashed is performed in screen space. */ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; uniform vec4 color; @@ -18,6 +18,7 @@ flat out vec4 color_vert; /* We leverage hardware interpolation to compute distance along the line. */ noperspective out vec2 stipple_pos; /* In screen space */ flat out vec2 stipple_start; /* In screen space */ +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl index 134a7d00127..c4d56579b18 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl @@ -1,4 +1,4 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO in float colorGradient; in vec4 finalColor; in float lineU; @@ -8,6 +8,7 @@ flat in float dashAlpha; flat in int isMainLine; out vec4 fragColor; +#endif #define DASH_WIDTH 10.0 #define ANTIALIAS 1.0 diff --git a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl index 8325568988c..3d3a042de65 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl @@ -4,13 +4,15 @@ #define MID_VERTEX 65 +#ifndef USE_GPU_SHADER_CREATE_INFO + /* u is position along the curve, defining the tangent space. * v is "signed" distance (compressed to [0..1] range) from the pos in expand direction */ in vec2 uv; in vec2 pos; /* verts position in the curve tangent space */ in vec2 expand; -#ifdef USE_INSTANCE +# ifdef USE_INSTANCE /* Instance attrs. */ in vec2 P0; in vec2 P1; @@ -27,21 +29,10 @@ in float dash_alpha; uniform vec4 colors[6]; -# define colStart (colid_doarrow[0] < 3 ? start_color : colors[colid_doarrow[0]]) -# define colEnd (colid_doarrow[1] < 3 ? end_color : colors[colid_doarrow[1]]) -# define colShadow colors[colid_doarrow[2]] -# define doArrow (colid_doarrow[3] != 0) -# define doMuted (domuted[0] != 0) - -#else +# else /* Single curve drawcall, use uniform. */ uniform vec2 bezierPts[4]; -# define P0 bezierPts[0] -# define P1 bezierPts[1] -# define P2 bezierPts[2] -# define P3 bezierPts[3] - uniform vec4 colors[3]; uniform bool doArrow; uniform bool doMuted; @@ -50,11 +41,7 @@ uniform float thickness; uniform float dash_factor; uniform float dash_alpha; -# define colShadow colors[0] -# define colStart colors[1] -# define colEnd colors[2] - -#endif +# endif uniform float expandSize; uniform float arrowSize; @@ -67,6 +54,33 @@ flat out float lineLength; flat out float dashFactor; flat out float dashAlpha; flat out int isMainLine; +#endif + +#ifdef USE_INSTANCE +# define colStart (colid_doarrow[0] < 3 ? start_color : node_link_data.colors[colid_doarrow[0]]) +# define colEnd (colid_doarrow[1] < 3 ? end_color : node_link_data.colors[colid_doarrow[1]]) +# define colShadow node_link_data.colors[colid_doarrow[2]] +# define doArrow (colid_doarrow[3] != 0) +# define doMuted (domuted[0] != 0) + +#else +# define P0 node_link_data.bezierPts[0] +# define P1 node_link_data.bezierPts[1] +# define P2 node_link_data.bezierPts[2] +# define P3 node_link_data.bezierPts[3] +# define cols node_link_data.colors +# define doArrow node_link_data.doArrow +# define doMuted node_link_data.doMuted +# define dim_factor node_link_data.dim_factor +# define thickness node_link_data.thickness +# define dash_factor node_link_data.dash_factor +# define dash_alpha node_link_data.dash_alpha + +# define colShadow node_link_data.colors[0] +# define colStart node_link_data.colors[1] +# define colEnd node_link_data.colors[2] + +#endif /* Define where along the noodle the gradient will starts and ends. * Use 0.25 instead of 0.35-0.65, because of a visual shift issue. */ @@ -101,7 +115,7 @@ void main(void) vec2 normal = tangent.yx * vec2(-1.0, 1.0); /* Position vertex on the curve tangent space */ - point += (pos.x * tangent + pos.y * normal) * arrowSize; + point += (pos.x * tangent + pos.y * normal) * node_link_data.arrowSize; gl_Position = ModelViewProjectionMatrix * vec4(point, 0.0, 1.0); @@ -139,7 +153,7 @@ void main(void) finalColor[3] *= dim_factor; /* Expand into a line */ - gl_Position.xy += exp_axis * expandSize * expand_dist * thickness; + gl_Position.xy += exp_axis * node_link_data.expandSize * expand_dist * thickness; /* If the link is not muted or is not a reroute arrow the points are squashed to the center of * the line. Magic numbers are defined in drawnode.c */ diff --git a/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl index 1453393aa9f..f2b6aa1f12c 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl @@ -1,9 +1,11 @@ +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; uniform float size; in vec2 pos; out vec2 radii; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl index 5c555b2d3e7..5d97fca1116 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl @@ -1,10 +1,11 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; uniform float size; uniform float outlineWidth; in vec2 pos; out vec4 radii; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl index 469370b9173..6ba6f980406 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl @@ -1,10 +1,11 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; in vec2 pos; in float size; in vec4 color; out vec4 finalColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl index 1333c00682c..4d887a37807 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl @@ -1,6 +1,7 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO noperspective in vec4 finalColor; out vec4 fragColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl index fcf436d50af..5d19aea9168 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl @@ -1,10 +1,11 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; in vec2 pos; in vec4 color; noperspective out vec4 finalColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_vert.glsl index de6547715f3..698f20ae1f9 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_vert.glsl @@ -1,11 +1,13 @@ +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; -#ifdef UV_POS +# ifdef UV_POS in vec2 u; -# define pos u -#else +# define pos u +# else in vec2 pos; +# endif #endif void main() diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl index 6dd0201535d..a03b88db342 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl @@ -1,3 +1,4 @@ +#ifndef USE_GPU_SHADER_CREATE_INFO uniform vec3 checkerColorAndSize; noperspective in vec2 uvInterp; @@ -12,6 +13,7 @@ flat in vec4 embossColor; flat in float lineWidth; out vec4 fragColor; +#endif vec3 compute_masks(vec2 uv) { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl index b5036b51d9d..80b93baf20a 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl @@ -1,12 +1,13 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; -#define MAX_PARAM 12 -#ifdef USE_INSTANCE -# define MAX_INSTANCE 6 +# define MAX_PARAM 12 +# ifdef USE_INSTANCE +# define MAX_INSTANCE 6 uniform vec4 parameters[MAX_PARAM * MAX_INSTANCE]; -#else +# else uniform vec4 parameters[MAX_PARAM]; +# endif #endif /* gl_InstanceID is supposed to be 0 if not drawing instances, but this seems @@ -41,6 +42,7 @@ uniform vec4 parameters[MAX_PARAM]; #define doAlphaCheck (alphaDiscard < 0.0) #define discardFactor abs(alphaDiscard) +#ifndef USE_GPU_SHADER_CREATE_INFO noperspective out vec2 uvInterp; flat out vec2 outRectSize; flat out vec4 outRoundCorners; @@ -51,8 +53,9 @@ flat out float lineWidth; noperspective out float butCo; flat out float discardFac; -#ifdef OS_MAC +# ifdef OS_MAC in float dummy; +# endif #endif vec2 do_widget(void) diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_frag.glsl index e8a6a43191e..a624d3f2f8b 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_frag.glsl @@ -1,9 +1,11 @@ +#ifndef USE_GPU_SHADER_CREATE_INFO in float shadowFalloff; out vec4 fragColor; uniform float alpha; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl index dc2849c8aa9..d3eed997292 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl @@ -51,9 +51,12 @@ const vec2 cornervec[36] = vec2[36](vec2(0.0, 1.0), #define INNER_FLAG uint(1 << 10) /* is inner vert */ +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; uniform vec4 parameters[4]; +#endif + /* radi and rad per corner */ #define recti parameters[0] #define rect parameters[1] @@ -61,9 +64,11 @@ uniform vec4 parameters[4]; #define rads parameters[2].y #define roundCorners parameters[3] +#ifndef USE_GPU_SHADER_CREATE_INFO in uint vflag; out float shadowFalloff; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl index 16424ece2b6..1a87796f7c4 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl @@ -1,9 +1,10 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelMatrix; uniform vec4 ClipPlane; in vec3 pos; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl index 91f986d23ad..b6132113bc9 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl @@ -1,13 +1,16 @@ +#pragma BLENDER_REQUIRE(gpu_shader_cfg_world_clip_lib.glsl) +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; -#ifdef USE_WORLD_CLIP_PLANES +# ifdef USE_WORLD_CLIP_PLANES uniform mat4 ModelMatrix; -#endif +# endif in vec3 pos; in vec4 color; flat out vec4 finalColor; +#endif void main() { @@ -16,6 +19,6 @@ void main() finalColor = color; #ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz); + world_clip_planes_calc_clip_distance((clipPlanes.ModelMatrix * pos_4d).xyz); #endif } diff --git a/source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl index 0fb8d06e317..908d442739a 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl @@ -1,9 +1,11 @@ +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; in vec2 texCoord; in vec3 pos; out vec2 texCoord_interp; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl index aefa47275f5..9328e0a13e9 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl @@ -6,11 +6,13 @@ * Dashed is performed in screen space. */ +#ifndef USE_GPU_SHADER_CREATE_INFO + uniform mat4 ModelViewProjectionMatrix; -#ifdef USE_WORLD_CLIP_PLANES +# ifdef USE_WORLD_CLIP_PLANES uniform mat4 ModelMatrix; -#endif +# endif uniform vec4 color; uniform vec2 viewport_size; @@ -22,6 +24,7 @@ flat out vec4 color_vert; /* We leverage hardware interpolation to compute distance along the line. */ noperspective out vec2 stipple_pos; /* In screen space */ flat out vec2 stipple_start; /* In screen space */ +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl index 252fee87015..18fed69eff6 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl @@ -1,10 +1,11 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; uniform mat3 NormalMatrix; in vec3 pos; in vec3 nor; out vec3 normal; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_3D_passthrough_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_passthrough_vert.glsl index 12594b04da9..52e9e71fdd8 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_passthrough_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_passthrough_vert.glsl @@ -1,9 +1,11 @@ -#ifdef USE_WORLD_CLIP_PLANES +#ifndef USE_GPU_SHADER_CREATE_INFO +# ifdef USE_WORLD_CLIP_PLANES uniform mat4 ModelMatrix; -#endif +# endif /* Does Nothing */ in vec3 pos; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl index 776656fc2df..504b3f75373 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl @@ -1,9 +1,10 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; in vec3 pos; in vec4 color; out vec4 finalColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl index 5d67658c639..7f143ccc28d 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl @@ -1,12 +1,15 @@ +#pragma BLENDER_REQUIRE(gpu_shader_cfg_world_clip_lib.glsl) +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; -#ifdef USE_WORLD_CLIP_PLANES +# ifdef USE_WORLD_CLIP_PLANES uniform mat4 ModelMatrix; -#endif +# endif uniform float size; in vec3 pos; out vec2 radii; +#endif void main() { @@ -25,6 +28,6 @@ void main() radii /= size; #ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz); + world_clip_planes_calc_clip_distance((clipPlanes.ModelMatrix * pos_4d).xyz); #endif } diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl index 3bc72535266..f048e143da7 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl @@ -1,10 +1,11 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; in vec3 pos; in float size; in vec4 color; out vec4 finalColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl b/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl index 3ea8f7dbfbe..8687763f4c1 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl @@ -1,14 +1,15 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform float lineWidth; uniform bool lineSmooth = true; in vec4 finalColor; noperspective in float smoothline; -#ifdef CLIP +# ifdef CLIP in float clip; -#endif +# endif out vec4 fragColor; +#endif #define SMOOTH_WIDTH 1.0 diff --git a/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl b/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl index 70026398937..627e91af4d6 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl @@ -1,4 +1,4 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO layout(lines) in; layout(triangle_strip, max_vertices = 4) out; @@ -7,17 +7,18 @@ uniform vec2 viewportSize; uniform float lineWidth; uniform bool lineSmooth = true; -#if !defined(UNIFORM) +# if !defined(UNIFORM) in vec4 finalColor_g[]; -#endif +# endif -#ifdef CLIP +# ifdef CLIP in float clip_g[]; out float clip; -#endif +# endif out vec4 finalColor; noperspective out float smoothline; +#endif #define SMOOTH_WIDTH 1.0 diff --git a/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl index 28aa2a4ccc6..5c673494870 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl @@ -1,18 +1,19 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelMatrix; uniform vec4 ClipPlane; in vec3 pos; -#if !defined(UNIFORM) +# if !defined(UNIFORM) in vec4 color; out vec4 finalColor_g; -#endif +# endif -#ifdef CLIP +# ifdef CLIP out float clip_g; +# endif #endif void main() diff --git a/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl index 3a2d96c9929..de555cc5706 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl @@ -1,6 +1,7 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO in vec4 finalColor; out vec4 fragColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl index 4eafb7b7be3..56a1210c957 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl @@ -1,14 +1,17 @@ +#pragma BLENDER_REQUIRE(gpu_shader_cfg_world_clip_lib.glsl) +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; -#ifdef USE_WORLD_CLIP_PLANES +# ifdef USE_WORLD_CLIP_PLANES uniform mat4 ModelMatrix; -#endif +# endif in vec3 pos; in vec4 color; out vec4 finalColor; +#endif void main() { @@ -16,6 +19,6 @@ void main() finalColor = color; #ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz); + world_clip_planes_calc_clip_distance((clipPlanes.ModelMatrix * vec4(pos, 1.0)).xyz); #endif } diff --git a/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl index 70bb881ffea..1d7b7df49a8 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl @@ -1,17 +1,20 @@ +#pragma BLENDER_REQUIRE(gpu_shader_cfg_world_clip_lib.glsl) +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; -#ifdef USE_WORLD_CLIP_PLANES +# ifdef USE_WORLD_CLIP_PLANES uniform mat4 ModelMatrix; -#endif +# endif in vec3 pos; +#endif void main() { gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); #ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz); + world_clip_planes_calc_clip_distance((clipPlanes.ModelMatrix * vec4(pos, 1.0)).xyz); #endif } diff --git a/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl b/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl index 46cf2fe09a2..cdc716db7a4 100644 --- a/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl +++ b/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl @@ -1,7 +1,9 @@ #ifdef USE_WORLD_CLIP_PLANES # if defined(GPU_VERTEX_SHADER) || defined(GPU_GEOMETRY_SHADER) +# ifndef USE_GPU_SHADER_CREATE_INFO uniform vec4 WorldClipPlanes[6]; +# endif # define _world_clip_planes_calc_clip_distance(wpos, _clipplanes) \ { \ @@ -14,6 +16,10 @@ uniform vec4 WorldClipPlanes[6]; gl_ClipDistance[5] = dot(_clipplanes[5], pos); \ } +/* When all shaders are builtin shaders are migrated this could be applied directly. */ +# ifdef USE_GPU_SHADER_CREATE_INFO +# define WorldClipPlanes clipPlanes.world +# endif /* HACK Dirty hack to be able to override the definition in common_view_lib.glsl. * Not doing this would require changing the include order in every shaders. */ # define world_clip_planes_calc_clip_distance(wpos) \ diff --git a/source/blender/gpu/shaders/gpu_shader_checker_frag.glsl b/source/blender/gpu/shaders/gpu_shader_checker_frag.glsl index 156b6cb75ab..9065da0275a 100644 --- a/source/blender/gpu/shaders/gpu_shader_checker_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_checker_frag.glsl @@ -1,9 +1,10 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform vec4 color1; uniform vec4 color2; uniform int size; out vec4 fragColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_colorspace_lib.glsl b/source/blender/gpu/shaders/gpu_shader_colorspace_lib.glsl index aae659516bb..74341701fb0 100644 --- a/source/blender/gpu/shaders/gpu_shader_colorspace_lib.glsl +++ b/source/blender/gpu/shaders/gpu_shader_colorspace_lib.glsl @@ -2,7 +2,9 @@ /* Undefine the macro that avoids compilation errors. */ #undef blender_srgb_to_framebuffer_space +#ifndef USE_GPU_SHADER_CREATE_INFO uniform bool srgbTarget = false; +#endif vec4 blender_srgb_to_framebuffer_space(vec4 color) { diff --git a/source/blender/gpu/shaders/gpu_shader_common_obinfos_lib.glsl b/source/blender/gpu/shaders/gpu_shader_common_obinfos_lib.glsl index 9e1527a9e7f..f5b6de4899f 100644 --- a/source/blender/gpu/shaders/gpu_shader_common_obinfos_lib.glsl +++ b/source/blender/gpu/shaders/gpu_shader_common_obinfos_lib.glsl @@ -9,11 +9,14 @@ struct ObjectInfos { vec4 drw_Infos; }; +# ifndef USE_GPU_SHADER_CREATE_INFO layout(std140) uniform infoBlock { /* DRW_RESOURCE_CHUNK_LEN = 512 */ ObjectInfos drw_infos[512]; }; +# endif + # define OrcoTexCoFactors (drw_infos[resource_id].drw_OrcoTexCoFactors) # define ObjectInfo (drw_infos[resource_id].drw_Infos) # define ObjectColor (drw_infos[resource_id].drw_ObjectColor) diff --git a/source/blender/gpu/shaders/gpu_shader_diag_stripes_frag.glsl b/source/blender/gpu/shaders/gpu_shader_diag_stripes_frag.glsl index 48979af4ad0..a4a24ed8e46 100644 --- a/source/blender/gpu/shaders/gpu_shader_diag_stripes_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_diag_stripes_frag.glsl @@ -1,10 +1,11 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform vec4 color1; uniform vec4 color2; uniform int size1; uniform int size2; out vec4 fragColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl b/source/blender/gpu/shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl index 6f7d68856d5..d3d4b66589b 100644 --- a/source/blender/gpu/shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl @@ -1,6 +1,7 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO flat in vec4 finalColor; out vec4 fragColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl index 99d8b6ab685..1675de3d567 100644 --- a/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl @@ -1,6 +1,7 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO flat in vec4 finalColor; out vec4 fragColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_flat_id_frag.glsl b/source/blender/gpu/shaders/gpu_shader_flat_id_frag.glsl index 8e1287c483a..2aabdb84f16 100644 --- a/source/blender/gpu/shaders/gpu_shader_flat_id_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_flat_id_frag.glsl @@ -1,6 +1,7 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO flat in uint finalId; out uint fragId; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_geometry.glsl b/source/blender/gpu/shaders/gpu_shader_geometry.glsl index 3b4e2e17ccc..4fdc14289e1 100644 --- a/source/blender/gpu/shaders/gpu_shader_geometry.glsl +++ b/source/blender/gpu/shaders/gpu_shader_geometry.glsl @@ -1,4 +1,4 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ProjectionMatrix; uniform int PrimitiveIdBase; @@ -19,6 +19,7 @@ out vec3 varposition; uniform bool osd_flat_shading; uniform int osd_fvar_count; +#endif #define INTERP_FACE_VARYING_2(result, fvarOffset, tessCoord) \ { \ @@ -38,8 +39,10 @@ uniform int osd_fvar_count; result = vec3(tmp, 0); \ } +#ifndef USE_GPU_SHADER_CREATE_INFO uniform samplerBuffer FVarDataBuffer; uniform isamplerBuffer FVarDataOffsetBuffer; +#endif out block { diff --git a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_frag.glsl b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_frag.glsl index fc3f47c0aaa..37541bb91f3 100644 --- a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_frag.glsl @@ -1,16 +1,18 @@ +#ifndef USE_GPU_SHADER_CREATE_INFO in vec4 mColor; in vec2 mTexCoord; out vec4 fragColor; +#endif void main() { const vec2 center = vec2(0, 0.5); - vec4 tColor = vec4(mColor); + vec4 tColor = vec4(geometry_out.mColor); /* if alpha < 0, then encap */ - if (mColor.a < 0) { + if (geometry_out.mColor.a < 0) { tColor.a = tColor.a * -1.0; - float dist = length(mTexCoord - center); + float dist = length(geometry_out.mTexCoord - center); if (dist > 0.25) { discard; } diff --git a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl index b937323f62a..f076655b459 100644 --- a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl +++ b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl @@ -1,3 +1,4 @@ +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; uniform vec2 Viewport; uniform int xraymode; @@ -13,6 +14,7 @@ in float finalThickness[4]; out vec4 mColor; out vec2 mTexCoord; +#endif #define GP_XRAY_FRONT 0 #define GP_XRAY_3DSPACE 1 @@ -23,19 +25,19 @@ out vec2 mTexCoord; /* project 3d point to 2d on screen space */ vec2 toScreenSpace(vec4 vertex) { - return vec2(vertex.xy / vertex.w) * Viewport; + return vec2(vertex.xy / vertex.w) * gpencil_stroke_data.viewport; } /* get zdepth value */ float getZdepth(vec4 point) { - if (xraymode == GP_XRAY_FRONT) { + if (gpencil_stroke_data.xraymode == GP_XRAY_FRONT) { return 0.0; } - if (xraymode == GP_XRAY_3DSPACE) { + if (gpencil_stroke_data.xraymode == GP_XRAY_3DSPACE) { return (point.z / point.w); } - if (xraymode == GP_XRAY_BACK) { + if (gpencil_stroke_data.xraymode == GP_XRAY_BACK) { return 1.0; } @@ -75,7 +77,7 @@ void main(void) vec2 sp3 = toScreenSpace(P3); /* end of next segment */ /* culling outside viewport */ - vec2 area = Viewport * 4.0; + vec2 area = gpencil_stroke_data.viewport * 4.0; if (sp1.x < -area.x || sp1.x > area.x) { return; } @@ -112,8 +114,8 @@ void main(void) if (bn1 == 0) { bn1 = 1; } - float length_a = finalThickness[1] / an1; - float length_b = finalThickness[2] / bn1; + float length_a = geometry_in[1].finalThickness / an1; + float length_b = geometry_in[2].finalThickness / bn1; if (length_a <= 0.0) { length_a = 0.01; } @@ -124,41 +126,49 @@ void main(void) /* prevent excessively long miters at sharp corners */ if (dot(v0, v1) < -MiterLimit) { miter_a = n1; - length_a = finalThickness[1]; + length_a = geometry_in[1].finalThickness; /* close the gap */ if (dot(v0, n1) > 0) { - mTexCoord = vec2(0, 0); - mColor = finalColor[1]; - gl_Position = vec4((sp1 + finalThickness[1] * n0) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 0); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4((sp1 + geometry_in[1].finalThickness * n0) / gpencil_stroke_data.viewport, + getZdepth(P1), + 1.0); EmitVertex(); - mTexCoord = vec2(0, 0); - mColor = finalColor[1]; - gl_Position = vec4((sp1 + finalThickness[1] * n1) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 0); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4((sp1 + geometry_in[1].finalThickness * n1) / gpencil_stroke_data.viewport, + getZdepth(P1), + 1.0); EmitVertex(); - mTexCoord = vec2(0, 0.5); - mColor = finalColor[1]; - gl_Position = vec4(sp1 / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 0.5); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4(sp1 / gpencil_stroke_data.viewport, getZdepth(P1), 1.0); EmitVertex(); EndPrimitive(); } else { - mTexCoord = vec2(0, 1); - mColor = finalColor[1]; - gl_Position = vec4((sp1 - finalThickness[1] * n1) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 1); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4((sp1 - geometry_in[1].finalThickness * n1) / gpencil_stroke_data.viewport, + getZdepth(P1), + 1.0); EmitVertex(); - mTexCoord = vec2(0, 1); - mColor = finalColor[1]; - gl_Position = vec4((sp1 - finalThickness[1] * n0) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 1); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4((sp1 - geometry_in[1].finalThickness * n0) / gpencil_stroke_data.viewport, + getZdepth(P1), + 1.0); EmitVertex(); - mTexCoord = vec2(0, 0.5); - mColor = finalColor[1]; - gl_Position = vec4(sp1 / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 0.5); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4(sp1 / gpencil_stroke_data.viewport, getZdepth(P1), 1.0); EmitVertex(); EndPrimitive(); @@ -167,66 +177,74 @@ void main(void) if (dot(v1, v2) < -MiterLimit) { miter_b = n1; - length_b = finalThickness[2]; + length_b = geometry_in[2].finalThickness; } /* Generate the start end-cap (alpha < 0 used as end-cap flag). */ - float extend = (fill_stroke > 0) ? 2 : 1; - if ((caps_start != GPENCIL_FLATCAP) && is_equal(P0, P2)) { - mTexCoord = vec2(1, 0.5); - mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0); + float extend = gpencil_stroke_data.fill_stroke ? 2 : 1; + if ((gpencil_stroke_data.caps_start != GPENCIL_FLATCAP) && is_equal(P0, P2)) { + geometry_out.mTexCoord = vec2(1, 0.5); + geometry_out.mColor = vec4(geometry_in[1].finalColor.rgb, geometry_in[1].finalColor.a * -1.0); vec2 svn1 = normalize(sp1 - sp2) * length_a * 4.0 * extend; - gl_Position = vec4((sp1 + svn1) / Viewport, getZdepth(P1), 1.0); + gl_Position = vec4((sp1 + svn1) / gpencil_stroke_data.viewport, getZdepth(P1), 1.0); EmitVertex(); - mTexCoord = vec2(0, 0); - mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0); - gl_Position = vec4((sp1 - (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 0); + geometry_out.mColor = vec4(geometry_in[1].finalColor.rgb, geometry_in[1].finalColor.a * -1.0); + gl_Position = vec4( + (sp1 - (length_a * 2.0) * miter_a) / gpencil_stroke_data.viewport, getZdepth(P1), 1.0); EmitVertex(); - mTexCoord = vec2(0, 1); - mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0); - gl_Position = vec4((sp1 + (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 1); + geometry_out.mColor = vec4(geometry_in[1].finalColor.rgb, geometry_in[1].finalColor.a * -1.0); + gl_Position = vec4( + (sp1 + (length_a * 2.0) * miter_a) / gpencil_stroke_data.viewport, getZdepth(P1), 1.0); EmitVertex(); } /* generate the triangle strip */ - mTexCoord = vec2(0, 0); - mColor = finalColor[1]; - gl_Position = vec4((sp1 + length_a * miter_a) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 0); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4( + (sp1 + length_a * miter_a) / gpencil_stroke_data.viewport, getZdepth(P1), 1.0); EmitVertex(); - mTexCoord = vec2(0, 1); - mColor = finalColor[1]; - gl_Position = vec4((sp1 - length_a * miter_a) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 1); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4( + (sp1 - length_a * miter_a) / gpencil_stroke_data.viewport, getZdepth(P1), 1.0); EmitVertex(); - mTexCoord = vec2(0, 0); - mColor = finalColor[2]; - gl_Position = vec4((sp2 + length_b * miter_b) / Viewport, getZdepth(P2), 1.0); + geometry_out.mTexCoord = vec2(0, 0); + geometry_out.mColor = geometry_in[2].finalColor; + gl_Position = vec4( + (sp2 + length_b * miter_b) / gpencil_stroke_data.viewport, getZdepth(P2), 1.0); EmitVertex(); - mTexCoord = vec2(0, 1); - mColor = finalColor[2]; - gl_Position = vec4((sp2 - length_b * miter_b) / Viewport, getZdepth(P2), 1.0); + geometry_out.mTexCoord = vec2(0, 1); + geometry_out.mColor = geometry_in[2].finalColor; + gl_Position = vec4( + (sp2 - length_b * miter_b) / gpencil_stroke_data.viewport, getZdepth(P2), 1.0); EmitVertex(); /* Generate the end end-cap (alpha < 0 used as end-cap flag). */ - if ((caps_end != GPENCIL_FLATCAP) && is_equal(P1, P3)) { - mTexCoord = vec2(0, 1); - mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0); - gl_Position = vec4((sp2 + (length_b * 2.0) * miter_b) / Viewport, getZdepth(P2), 1.0); + if ((gpencil_stroke_data.caps_end != GPENCIL_FLATCAP) && is_equal(P1, P3)) { + geometry_out.mTexCoord = vec2(0, 1); + geometry_out.mColor = vec4(geometry_in[2].finalColor.rgb, geometry_in[2].finalColor.a * -1.0); + gl_Position = vec4( + (sp2 + (length_b * 2.0) * miter_b) / gpencil_stroke_data.viewport, getZdepth(P2), 1.0); EmitVertex(); - mTexCoord = vec2(0, 0); - mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0); - gl_Position = vec4((sp2 - (length_b * 2.0) * miter_b) / Viewport, getZdepth(P2), 1.0); + geometry_out.mTexCoord = vec2(0, 0); + geometry_out.mColor = vec4(geometry_in[2].finalColor.rgb, geometry_in[2].finalColor.a * -1.0); + gl_Position = vec4( + (sp2 - (length_b * 2.0) * miter_b) / gpencil_stroke_data.viewport, getZdepth(P2), 1.0); EmitVertex(); - mTexCoord = vec2(1, 0.5); - mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0); + geometry_out.mTexCoord = vec2(1, 0.5); + geometry_out.mColor = vec4(geometry_in[2].finalColor.rgb, geometry_in[2].finalColor.a * -1.0); vec2 svn2 = normalize(sp2 - sp1) * length_b * 4.0 * extend; - gl_Position = vec4((sp2 + svn2) / Viewport, getZdepth(P2), 1.0); + gl_Position = vec4((sp2 + svn2) / gpencil_stroke_data.viewport, getZdepth(P2), 1.0); EmitVertex(); } diff --git a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_vert.glsl b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_vert.glsl index 07b4ae52110..16e12b2989e 100644 --- a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_vert.glsl @@ -1,3 +1,4 @@ +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; uniform mat4 ProjectionMatrix; @@ -12,22 +13,21 @@ in float thickness; out vec4 finalColor; out float finalThickness; +#endif -#define TRUE 1 - -float defaultpixsize = pixsize * (1000.0 / pixfactor); +float defaultpixsize = gpencil_stroke_data.pixsize * (1000.0 / gpencil_stroke_data.pixfactor); void main(void) { gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); - finalColor = color; + geometry_in.finalColor = color; - if (keep_size == TRUE) { - finalThickness = thickness; + if (gpencil_stroke_data.keep_size) { + geometry_in.finalThickness = thickness; } else { float size = (ProjectionMatrix[3][3] == 0.0) ? (thickness / (gl_Position.z * defaultpixsize)) : (thickness / defaultpixsize); - finalThickness = max(size * objscale, 1.0); + geometry_in.finalThickness = max(size * gpencil_stroke_data.objscale, 1.0); } } diff --git a/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl index 6dc7a1618e1..1846dae346a 100644 --- a/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl @@ -1,9 +1,10 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO in vec2 texCoord_interp; out vec4 fragColor; uniform vec4 color; uniform sampler2D image; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl index dfbaaeda7b5..ad52b9819ab 100644 --- a/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl @@ -1,10 +1,11 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform float factor; in vec2 texCoord_interp; out vec4 fragColor; uniform vec4 color; uniform sampler2D image; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_image_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_frag.glsl index aff6ddf01bf..befd6b57bf8 100644 --- a/source/blender/gpu/shaders/gpu_shader_image_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_image_frag.glsl @@ -1,8 +1,9 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO in vec2 texCoord_interp; out vec4 fragColor; uniform sampler2D image; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl index 613352b4ac8..ceebaae896d 100644 --- a/source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl @@ -1,9 +1,11 @@ +#ifndef USE_GPU_SHADER_CREATE_INFO in vec2 texCoord_interp; out vec4 fragColor; uniform float alpha; uniform sampler2D image; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl index 7f3fe2f5252..2314dbbc5d5 100644 --- a/source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl @@ -1,6 +1,7 @@ /* Merge overlays texture on top of image texture and transform to display space (assume sRGB) */ +#ifndef USE_GPU_SHADER_CREATE_INFO uniform sampler2D image_texture; uniform sampler2D overlays_texture; uniform bool display_transform; @@ -9,6 +10,7 @@ uniform bool overlay; in vec2 texCoord_interp; out vec4 fragColor; +#endif float linearrgb_to_srgb(float c) { diff --git a/source/blender/gpu/shaders/gpu_shader_image_overlays_stereo_merge_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_overlays_stereo_merge_frag.glsl index c6e9860d940..9b1e6fe9d23 100644 --- a/source/blender/gpu/shaders/gpu_shader_image_overlays_stereo_merge_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_image_overlays_stereo_merge_frag.glsl @@ -7,18 +7,20 @@ /* Composite stereo textures */ +#ifndef USE_GPU_SHADER_CREATE_INFO uniform sampler2D imageTexture; uniform sampler2D overlayTexture; uniform int stereoDisplaySettings; +layout(location = 0) out vec4 imageColor; +layout(location = 1) out vec4 overlayColor; +#endif + #define stereo_display_mode (stereoDisplaySettings & ((1 << 3) - 1)) #define stereo_interlace_mode ((stereoDisplaySettings >> 3) & ((1 << 3) - 1)) #define stereo_interlace_swap bool(stereoDisplaySettings >> 6) -layout(location = 0) out vec4 imageColor; -layout(location = 1) out vec4 overlayColor; - bool interlace(ivec2 texel) { int interlace_mode = stereo_interlace_mode; diff --git a/source/blender/gpu/shaders/gpu_shader_image_shuffle_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_shuffle_color_frag.glsl index ed69184ef14..e8bfb70b897 100644 --- a/source/blender/gpu/shaders/gpu_shader_image_shuffle_color_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_image_shuffle_color_frag.glsl @@ -1,15 +1,16 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO in vec2 texCoord_interp; out vec4 fragColor; uniform sampler2D image; uniform vec4 color; uniform vec4 shuffle; +#endif void main() { - vec4 sample = texture(image, texCoord_interp); - fragColor = vec4(sample.r * shuffle.r + sample.g * shuffle.g + sample.b * shuffle.b + - sample.a * shuffle.a) * + vec4 sampled_color = texture(image, texCoord_interp); + fragColor = vec4(sampled_color.r * shuffle.r + sampled_color.g * shuffle.g + + sampled_color.b * shuffle.b + sampled_color.a * shuffle.a) * color; } diff --git a/source/blender/gpu/shaders/gpu_shader_image_varying_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_varying_color_frag.glsl index becf0fbd133..3058f73ab37 100644 --- a/source/blender/gpu/shaders/gpu_shader_image_varying_color_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_image_varying_color_frag.glsl @@ -1,9 +1,10 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO in vec2 texCoord_interp; flat in vec4 finalColor; out vec4 fragColor; uniform sampler2D image; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl index 10228a1e985..14450037ca8 100644 --- a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl @@ -1,4 +1,4 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ViewProjectionMatrix; /* ---- Instantiated Attrs ---- */ @@ -7,13 +7,14 @@ in vec3 pos; /* ---- Per instance Attrs ---- */ in mat4 InstanceModelMatrix; in vec4 color; -#ifdef UNIFORM_SCALE +# ifdef UNIFORM_SCALE in float size; -#else +# else in vec3 size; -#endif +# endif flat out vec4 finalColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_keyframe_shape_frag.glsl b/source/blender/gpu/shaders/gpu_shader_keyframe_shape_frag.glsl index a3b61dca8b4..2a2eaab7340 100644 --- a/source/blender/gpu/shaders/gpu_shader_keyframe_shape_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_keyframe_shape_frag.glsl @@ -11,6 +11,7 @@ #define GPU_KEYFRAME_SHAPE_SQUARE \ (GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL | GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL) +#ifndef USE_GPU_SHADER_CREATE_INFO flat in vec4 radii; flat in vec4 thresholds; @@ -20,6 +21,7 @@ flat in vec4 finalOutlineColor; flat in int finalFlags; out vec4 fragColor; +#endif const float diagonal_scale = sqrt(0.5); diff --git a/source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl b/source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl index 18e8b76ba23..4ef3ff1a8d0 100644 --- a/source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl @@ -11,15 +11,16 @@ #define GPU_KEYFRAME_SHAPE_SQUARE \ (GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL | GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL) -uniform mat4 ModelViewProjectionMatrix; -uniform vec2 ViewportSize = vec2(-1, -1); -uniform float outline_scale = 1.0; - const float line_falloff = 1.0; const float circle_scale = sqrt(2.0 / 3.1416); const float square_scale = sqrt(0.5); const float diagonal_scale = sqrt(0.5); +#ifndef USE_GPU_SHADER_CREATE_INFO +uniform mat4 ModelViewProjectionMatrix; +uniform vec2 ViewportSize = vec2(-1, -1); +uniform float outline_scale = 1.0; + in vec2 pos; in float size; in vec4 color; @@ -33,6 +34,7 @@ flat out int finalFlags; flat out vec4 radii; flat out vec4 thresholds; +#endif bool test(int bit) { diff --git a/source/blender/gpu/shaders/gpu_shader_point_uniform_color_aa_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_aa_frag.glsl index 52d59d2030f..960b5e6efac 100644 --- a/source/blender/gpu/shaders/gpu_shader_point_uniform_color_aa_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_aa_frag.glsl @@ -1,8 +1,9 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform vec4 color; in vec2 radii; out vec4 fragColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl index 2ece73b3845..cdf3aa8024d 100644 --- a/source/blender/gpu/shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl @@ -1,9 +1,10 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform vec4 color; uniform vec4 outlineColor; in vec4 radii; out vec4 fragColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl index 86c0e5c950a..119189ad29b 100644 --- a/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl @@ -1,6 +1,7 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO in vec4 finalColor; out vec4 fragColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl index c9bd9e881bf..04a7e3d80d0 100644 --- a/source/blender/gpu/shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl @@ -1,8 +1,9 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO in vec4 radii; in vec4 fillColor; in vec4 outlineColor; out vec4 fragColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl b/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl index 6bce517fee3..6725bc82841 100644 --- a/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl @@ -1,18 +1,19 @@ - -#ifndef USE_INSTANCE_COLOR +#ifndef USE_GPU_SHADER_CREATE_INFO +# ifndef USE_INSTANCE_COLOR uniform vec4 color; -#endif +# endif uniform vec3 light; in vec3 normal; -#ifdef USE_INSTANCE_COLOR +# ifdef USE_INSTANCE_COLOR flat in vec4 finalColor; -# define color finalColor -#endif +# define color finalColor +# endif out vec4 fragColor; +#endif void main() { - fragColor = color; - fragColor.xyz *= clamp(dot(normalize(normal), light), 0.0, 1.0); + fragColor = simple_lighting_data.color; + fragColor.xyz *= clamp(dot(normalize(normal), simple_lighting_data.light), 0.0, 1.0); } diff --git a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl index 2568cd74445..1456bd0c732 100644 --- a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl @@ -1,4 +1,4 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO flat in vec4 color_flat; noperspective in vec2 texCoord_interp; flat in int glyph_offset; @@ -8,6 +8,7 @@ flat in int interp_size; out vec4 fragColor; uniform sampler2D glyph; +#endif const vec2 offsets4[4] = vec2[4]( vec2(-0.5, 0.5), vec2(0.5, 0.5), vec2(-0.5, -0.5), vec2(-0.5, -0.5)); diff --git a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl index 768638e5229..5b01fea5266 100644 --- a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl @@ -1,4 +1,4 @@ - +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; in vec4 pos; /* rect */ @@ -11,6 +11,7 @@ noperspective out vec2 texCoord_interp; flat out int glyph_offset; flat out ivec2 glyph_dim; flat out int interp_size; +#endif void main() { diff --git a/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl index 08623fa9935..b4a75cc489b 100644 --- a/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl @@ -1,7 +1,8 @@ +#ifndef USE_GPU_SHADER_CREATE_INFO uniform vec4 color; - out vec4 fragColor; +#endif void main() { diff --git a/source/blender/gpu/shaders/infos/gpu_clip_planes_info.hh b/source/blender/gpu/shaders/infos/gpu_clip_planes_info.hh new file mode 100644 index 00000000000..81b3c523628 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_clip_planes_info.hh @@ -0,0 +1,29 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_clip_planes) + .uniform_buf(1, "GPUClipPlanes", "clipPlanes", Frequency::PASS) + .typedef_source("GPU_shader_shared.h") + .define("USE_WORLD_CLIP_PLANES"); diff --git a/source/blender/gpu/shaders/infos/gpu_interface_info.hh b/source/blender/gpu/shaders/infos/gpu_interface_info.hh new file mode 100644 index 00000000000..b53b60fa587 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_interface_info.hh @@ -0,0 +1,33 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#pragma once + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_INTERFACE_INFO(flat_color_iface, "").flat(Type::VEC4, "finalColor"); +GPU_SHADER_INTERFACE_INFO(no_perspective_color_iface, "").no_perspective(Type::VEC4, "finalColor"); +GPU_SHADER_INTERFACE_INFO(smooth_color_iface, "").smooth(Type::VEC4, "finalColor"); +GPU_SHADER_INTERFACE_INFO(smooth_tex_coord_interp_iface, "").smooth(Type::VEC2, "texCoord_interp"); +GPU_SHADER_INTERFACE_INFO(smooth_radii_iface, "").smooth(Type::VEC2, "radii"); +GPU_SHADER_INTERFACE_INFO(smooth_radii_outline_iface, "").smooth(Type::VEC4, "radii"); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_area_borders_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_area_borders_info.hh new file mode 100644 index 00000000000..56c30e79e6d --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_area_borders_info.hh @@ -0,0 +1,39 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_INTERFACE_INFO(smooth_uv_iface, "").smooth(Type::VEC2, "uv"); + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_area_borders) + .vertex_in(0, Type::VEC2, "pos") + .vertex_out(smooth_uv_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::VEC4, "rect") + .push_constant(20, Type::VEC4, "color") + .push_constant(24, Type::FLOAT, "scale") + .push_constant(25, Type::INT, "cornerLen") + .vertex_source("gpu_shader_2D_area_borders_vert.glsl") + .fragment_source("gpu_shader_2D_area_borders_frag.glsl") + .do_static_compilation(true); \ No newline at end of file diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_checker_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_checker_info.hh new file mode 100644 index 00000000000..a69420bede4 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_checker_info.hh @@ -0,0 +1,36 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_checker) + .vertex_in(0, Type::VEC2, "pos") + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::VEC4, "color1") + .push_constant(20, Type::VEC4, "color2") + .push_constant(24, Type::INT, "size") + .vertex_source("gpu_shader_2D_vert.glsl") + .fragment_source("gpu_shader_checker_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_diag_stripes_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_diag_stripes_info.hh new file mode 100644 index 00000000000..fa715cdcb1d --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_diag_stripes_info.hh @@ -0,0 +1,37 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_diag_stripes) + .vertex_in(0, Type::VEC2, "pos") + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::VEC4, "color1") + .push_constant(20, Type::VEC4, "color2") + .push_constant(24, Type::INT, "size1") + .push_constant(28, Type::INT, "size2") + .vertex_source("gpu_shader_2D_vert.glsl") + .fragment_source("gpu_shader_diag_stripes_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_flat_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_flat_color_info.hh new file mode 100644 index 00000000000..93d46f8acd8 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_flat_color_info.hh @@ -0,0 +1,38 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + + +#include "gpu_shader_create_info.hh" + +#include "gpu_interface_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_flat_color) + .vertex_in(0, Type::VEC2, "pos") + .vertex_in(1, Type::VEC4, "color") + .vertex_out(flat_color_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .vertex_source("gpu_shader_2D_flat_color_vert.glsl") + .fragment_source("gpu_shader_flat_color_frag.glsl") + .additional_info("gpu_srgb_to_framebuffer_space") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_image_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_color_info.hh new file mode 100644 index 00000000000..a6cc9076d4a --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_color_info.hh @@ -0,0 +1,30 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_image_color) + .additional_info("gpu_shader_2D_image_common") + .push_constant(16, Type::VEC4, "color") + .fragment_source("gpu_shader_image_color_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_image_desaturate_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_desaturate_color_info.hh new file mode 100644 index 00000000000..e11d6746446 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_desaturate_color_info.hh @@ -0,0 +1,31 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_image_desaturate_color) + .additional_info("gpu_shader_2D_image_common") + .push_constant(16, Type::VEC4, "color") + .push_constant(20, Type::FLOAT, "factor") + .fragment_source("gpu_shader_image_desaturate_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_image_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_info.hh new file mode 100644 index 00000000000..3d20b63c265 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_info.hh @@ -0,0 +1,39 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_image_common) + .vertex_in(0, Type::VEC2, "pos") + .vertex_in(1, Type::VEC2, "texCoord") + .vertex_out(smooth_tex_coord_interp_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .sampler(0, ImageType::FLOAT_2D, "image") + .vertex_source("gpu_shader_2D_image_vert.glsl"); + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_image) + .additional_info("gpu_shader_2D_image_common") + .fragment_source("gpu_shader_image_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_image_overlays_merge_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_overlays_merge_info.hh new file mode 100644 index 00000000000..c2c0e9fec78 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_overlays_merge_info.hh @@ -0,0 +1,39 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_image_overlays_merge) + .vertex_in(0, Type::VEC2, "pos") + .vertex_in(1, Type::VEC2, "texCoord") + .vertex_out(smooth_tex_coord_interp_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::BOOL, "display_transform") + .push_constant(17, Type::BOOL, "overlay") + .sampler(0, ImageType::FLOAT_2D, "image_texture") + .sampler(1, ImageType::FLOAT_2D, "overlays_texture") + .vertex_source("gpu_shader_2D_image_vert.glsl") + .fragment_source("gpu_shader_image_overlays_merge_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_image_overlays_stereo_merge_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_overlays_stereo_merge_info.hh new file mode 100644 index 00000000000..c1e6c3957d3 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_overlays_stereo_merge_info.hh @@ -0,0 +1,36 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_image_overlays_stereo_merge) + .vertex_in(0, Type::VEC2, "pos") + .fragment_out(0, Type::VEC4, "imageColor") + .fragment_out(1, Type::VEC4, "overlayColor") + .sampler(0, ImageType::FLOAT_2D, "imageTexture") + .sampler(1, ImageType::FLOAT_2D, "overlayTexture") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::INT, "stereoDisplaySettings") + .vertex_source("gpu_shader_2D_vert.glsl") + .fragment_source("gpu_shader_image_overlays_stereo_merge_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_image_rect_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_rect_color_info.hh new file mode 100644 index 00000000000..b9b4381eb50 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_rect_color_info.hh @@ -0,0 +1,40 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_image_rect_color) + .vertex_in(0, Type::VEC2, "pos") + .vertex_in(1, Type::VEC2, "texCoord") + .vertex_out(smooth_tex_coord_interp_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::VEC4, "color") + .push_constant(20, Type::VEC4, "rect_icon") + .push_constant(24, Type::VEC4, "rect_geom") + .sampler(0, ImageType::FLOAT_2D, "image") + .vertex_source("gpu_shader_2D_image_rect_vert.glsl") + .fragment_source("gpu_shader_image_color_frag.glsl") + .do_static_compilation(true); + diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_image_shuffle_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_shuffle_color_info.hh new file mode 100644 index 00000000000..3663de0a98f --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_image_shuffle_color_info.hh @@ -0,0 +1,31 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_image_shuffle_color) + .additional_info("gpu_shader_2D_image_common") + .push_constant(16, Type::VEC4, "color") + .push_constant(20, Type::VEC4, "shuffle") + .fragment_source("gpu_shader_image_shuffle_color_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_line_dashed_uniform_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_line_dashed_uniform_color_info.hh new file mode 100644 index 00000000000..419cd4bc47c --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_line_dashed_uniform_color_info.hh @@ -0,0 +1,35 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +/* TODO(jbakker): Skipped as data doesn't fit as push constant. */ +GPU_SHADER_CREATE_INFO(gpu_shader_2D_line_dashed_uniform_color) + .vertex_in(0, Type::VEC3, "pos") + .vertex_out(flat_color_iface) + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .vertex_source("gpu_shader_2D_line_dashed_uniform_color_vert.glsl") + .fragment_source("gpu_shader_2D_line_dashed_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_nodelink_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_nodelink_info.hh new file mode 100644 index 00000000000..b15d7ba3ada --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_nodelink_info.hh @@ -0,0 +1,72 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_INTERFACE_INFO(nodelink_iface, "") + .smooth(Type::VEC4, "finalColor") + .smooth(Type::FLOAT, "colorGradient") + .smooth(Type::FLOAT, "lineU") + .flat(Type::FLOAT, "lineLength") + .flat(Type::FLOAT, "dashFactor") + .flat(Type::FLOAT, "dashAlpha") + .flat(Type::INT, "isMainLine"); + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_nodelink) + .vertex_in(0, Type::VEC2, "uv") + .vertex_in(1, Type::VEC2, "pos") + .vertex_in(2, Type::VEC2, "expand") + .vertex_out(nodelink_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .uniform_buf(0, "NodeLinkData", "node_link_data", Frequency::PASS) + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .vertex_source("gpu_shader_2D_nodelink_vert.glsl") + .fragment_source("gpu_shader_2D_nodelink_frag.glsl") + .typedef_source("GPU_shader_shared.h") + .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_nodelink_inst) + .vertex_in(0, Type::VEC2, "uv") + .vertex_in(1, Type::VEC2, "pos") + .vertex_in(2, Type::VEC2, "expand") + .vertex_in(3, Type::VEC2, "P0") + .vertex_in(4, Type::VEC2, "P1") + .vertex_in(5, Type::VEC2, "P2") + .vertex_in(6, Type::VEC2, "P3") + .vertex_in(7, Type::IVEC4, "colid_doarrow") + .vertex_in(8, Type::VEC4, "start_color") + .vertex_in(9, Type::VEC4, "end_color") + .vertex_in(10, Type::IVEC2, "domuted") + .vertex_in(11, Type::FLOAT, "dim_factor") + .vertex_in(12, Type::FLOAT, "thickness") + .vertex_in(13, Type::FLOAT, "dash_factor") + .vertex_in(14, Type::FLOAT, "dash_alpha") + .vertex_out(nodelink_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .uniform_buf(0, "NodeLinkInstanceData", "node_link_data", Frequency::PASS) + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .vertex_source("gpu_shader_2D_nodelink_vert.glsl") + .fragment_source("gpu_shader_2D_nodelink_frag.glsl") + .typedef_source("GPU_shader_shared.h") + .define("USE_INSTANCE") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_aa_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_aa_info.hh new file mode 100644 index 00000000000..d2753af8e9b --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_aa_info.hh @@ -0,0 +1,36 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_point_uniform_size_uniform_color_aa) + .vertex_in(0, Type::VEC2, "pos") + .vertex_out(smooth_radii_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::VEC4, "color") + .push_constant(20, Type::FLOAT, "size") + .vertex_source("gpu_shader_2D_point_uniform_size_aa_vert.glsl") + .fragment_source("gpu_shader_point_uniform_color_aa_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_outline_aa_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_outline_aa_info.hh new file mode 100644 index 00000000000..edc83534573 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_outline_aa_info.hh @@ -0,0 +1,38 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_point_uniform_size_uniform_color_outline_aa) + .vertex_in(0, Type::VEC2, "pos") + .vertex_out(smooth_radii_outline_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(20, Type::VEC4, "color") + .push_constant(24, Type::VEC4, "outlineColor") + .push_constant(28, Type::FLOAT, "size") + .push_constant(29, Type::FLOAT, "outlineWidth") + .vertex_source("gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl") + .fragment_source("gpu_shader_point_uniform_color_outline_aa_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_point_varying_size_varying_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_point_varying_size_varying_color_info.hh new file mode 100644 index 00000000000..4358e94f91f --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_point_varying_size_varying_color_info.hh @@ -0,0 +1,36 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_point_varying_size_varying_color) + .vertex_in(0, Type::VEC2, "pos") + .vertex_in(1, Type::FLOAT, "size") + .vertex_in(2, Type::VEC4, "color") + .vertex_out(smooth_color_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .vertex_source("gpu_shader_2D_point_varying_size_varying_color_vert.glsl") + .fragment_source("gpu_shader_point_varying_color_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_smooth_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_smooth_color_info.hh new file mode 100644 index 00000000000..60612a51135 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_smooth_color_info.hh @@ -0,0 +1,37 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_smooth_color) + .vertex_in(0, Type::VEC2, "pos") + .vertex_in(1, Type::VEC4, "color") + .vertex_out(smooth_color_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .vertex_source("gpu_shader_2D_smooth_color_vert.glsl") + .fragment_source("gpu_shader_2D_smooth_color_frag.glsl") + .additional_info("gpu_srgb_to_framebuffer_space") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_uniform_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_uniform_color_info.hh new file mode 100644 index 00000000000..8977a34986e --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_uniform_color_info.hh @@ -0,0 +1,35 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_2D_uniform_color) + .vertex_in(0, Type::VEC2, "pos") + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::VEC4, "color") + .vertex_source("gpu_shader_2D_vert.glsl") + .fragment_source("gpu_shader_uniform_color_frag.glsl") + .additional_info("gpu_srgb_to_framebuffer_space") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_3D_depth_only_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_3D_depth_only_info.hh new file mode 100644 index 00000000000..7ea067010cd --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_3D_depth_only_info.hh @@ -0,0 +1,38 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_depth_only) + .vertex_in(0, Type::VEC3, "pos") + .vertex_out(flat_color_iface) + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .vertex_source("gpu_shader_3D_vert.glsl") + .fragment_source("gpu_shader_depth_only_frag.glsl") + .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_depth_only_clipped) + .additional_info("gpu_shader_3D_depth_only") + .additional_info("gpu_clip_planes"); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_3D_flat_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_3D_flat_color_info.hh new file mode 100644 index 00000000000..5857e4cab03 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_3D_flat_color_info.hh @@ -0,0 +1,42 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_flat_color) + .vertex_in(0, Type::VEC3, "pos") + .vertex_in(1, Type::VEC4, "color") + .vertex_out(flat_color_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(1, Type::BOOL, "srgbTarget") + .vertex_source("gpu_shader_3D_flat_color_vert.glsl") + .fragment_source("gpu_shader_flat_color_frag.glsl") + .additional_info("gpu_srgb_to_framebuffer_space") + .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_flat_color_clipped) + .additional_info("gpu_shader_3D_flat_color") + .additional_info("gpu_clip_planes"); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_3D_image_modulate_alpha_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_3D_image_modulate_alpha_info.hh new file mode 100644 index 00000000000..a838f6581dc --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_3D_image_modulate_alpha_info.hh @@ -0,0 +1,38 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_image_modulate_alpha) + .vertex_in(0, Type::VEC3, "pos") + .vertex_in(1, Type::VEC2, "texCoord") + .vertex_out(smooth_tex_coord_interp_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::FLOAT, "alpha") + .sampler(0, ImageType::FLOAT_2D, "image", Frequency::PASS) + .vertex_source("gpu_shader_3D_image_vert.glsl") + .fragment_source("gpu_shader_image_modulate_alpha_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_3D_line_dashed_uniform_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_3D_line_dashed_uniform_color_info.hh new file mode 100644 index 00000000000..93cbf1ab06f --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_3D_line_dashed_uniform_color_info.hh @@ -0,0 +1,35 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +/* TODO(jbakker): Skipped as data doesn't fit as push constant. */ +GPU_SHADER_CREATE_INFO(gpu_shader_3D_line_dashed_uniform_color) + .vertex_in(0, Type::VEC3, "pos") + .vertex_out(flat_color_iface) + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .vertex_source("gpu_shader_3D_line_dashed_uniform_color_vert.glsl") + .fragment_source("gpu_shader_2D_line_dashed_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_3D_point_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_3D_point_info.hh new file mode 100644 index 00000000000..b62c8fe7518 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_3D_point_info.hh @@ -0,0 +1,62 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_point_fixed_size_varying_color) + .vertex_in(0, Type::VEC3, "pos") + .vertex_in(1, Type::VEC4, "color") + .vertex_out(smooth_color_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::FLOAT, "size") + .vertex_source("gpu_shader_3D_point_fixed_size_varying_color_vert.glsl") + .fragment_source("gpu_shader_point_varying_color_frag.glsl") + .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_point_varying_size_varying_color) + .vertex_in(0, Type::VEC3, "pos") + .vertex_in(1, Type::VEC4, "color") + .vertex_in(2, Type::FLOAT, "size") + .vertex_out(smooth_color_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .vertex_source("gpu_shader_3D_point_varying_size_varying_color_vert.glsl") + .fragment_source("gpu_shader_point_varying_color_frag.glsl") + .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_point_uniform_size_uniform_color_aa) + .vertex_in(0, Type::VEC3, "pos") + .vertex_out(smooth_radii_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::VEC4, "color") + .push_constant(20, Type::FLOAT, "size") + .push_constant(24, Type::FLOAT, "outlineWidth") + .vertex_source("gpu_shader_3D_point_uniform_size_aa_vert.glsl") + .fragment_source("gpu_shader_point_uniform_color_aa_frag.glsl") + .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_point_uniform_size_uniform_color_aa_clipped) + .additional_info("gpu_shader_3D_point_uniform_size_uniform_color_aa") + .additional_info("gpu_clip_planes"); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh new file mode 100644 index 00000000000..1e195e7ff23 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh @@ -0,0 +1,33 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +/* TODO(jbakker): Skipped as it needs a uniform/storage buffer. */ +GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline_uniform_color) + .vertex_source("gpu_shader_3D_polyline_vert.glsl") + .geometry_source("gpu_shader_3D_polyline_geom.glsl") + .fragment_source("gpu_shader_3D_polyline_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_3D_smooth_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_3D_smooth_color_info.hh new file mode 100644 index 00000000000..91797b9b414 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_3D_smooth_color_info.hh @@ -0,0 +1,41 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_smooth_color) + .vertex_in(0, Type::VEC3, "pos") + .vertex_in(1, Type::VEC4, "color") + .vertex_out(smooth_color_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .vertex_source("gpu_shader_3D_smooth_color_vert.glsl") + .fragment_source("gpu_shader_3D_smooth_color_frag.glsl") + .additional_info("gpu_srgb_to_framebuffer_space") + .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_smooth_color_clipped) + .additional_info("gpu_shader_3D_smooth_color") + .additional_info("gpu_clip_planes"); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_3D_uniform_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_3D_uniform_color_info.hh new file mode 100644 index 00000000000..6162d68cf2e --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_3D_uniform_color_info.hh @@ -0,0 +1,39 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_uniform_color) + .vertex_in(0, Type::VEC3, "pos") + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::VEC4, "color") + .vertex_source("gpu_shader_3D_vert.glsl") + .fragment_source("gpu_shader_uniform_color_frag.glsl") + .additional_info("gpu_srgb_to_framebuffer_space") + .do_static_compilation(true); + +GPU_SHADER_CREATE_INFO(gpu_shader_3D_uniform_color_clipped) + .additional_info("gpu_shader_3D_uniform_color") + .additional_info("gpu_clip_planes"); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_gpencil_stroke_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_gpencil_stroke_info.hh new file mode 100644 index 00000000000..5fb6c61c5f9 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_gpencil_stroke_info.hh @@ -0,0 +1,51 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_INTERFACE_INFO(gpencil_stroke_vert_iface, "geometry_in") + .smooth(Type::VEC4, "finalColor") + .smooth(Type::FLOAT, "finalThickness"); +GPU_SHADER_INTERFACE_INFO(gpencil_stroke_geom_iface, "geometry_out") + .smooth(Type::VEC4, "mColor") + .smooth(Type::VEC2, "mTexCoord"); + +GPU_SHADER_CREATE_INFO(gpu_shader_gpencil_stroke) + .vertex_in(0, Type::VEC4, "color") + .vertex_in(1, Type::VEC3, "pos") + .vertex_in(2, Type::FLOAT, "thickness") + .vertex_out(gpencil_stroke_vert_iface) + .geometry_layout(InputLayout::LINES_ADJACENCY, OutputLayout::TRIANGLE_STRIP, 13) + .geometry_out(gpencil_stroke_geom_iface) + .fragment_out(0, Type::VEC4, "fragColor") + + .uniform_buf(0, "GPencilStrokeData", "gpencil_stroke_data") + + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::MAT4, "ProjectionMatrix") + .vertex_source("gpu_shader_gpencil_stroke_vert.glsl") + .geometry_source("gpu_shader_gpencil_stroke_geom.glsl") + .fragment_source("gpu_shader_gpencil_stroke_frag.glsl") + .typedef_source("GPU_shader_shared.h") + .do_static_compilation(true); + \ No newline at end of file diff --git a/source/blender/gpu/shaders/infos/gpu_shader_instance_varying_color_varying_size_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_instance_varying_color_varying_size_info.hh new file mode 100644 index 00000000000..0d2daf7388d --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_instance_varying_color_varying_size_info.hh @@ -0,0 +1,39 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_interface_info.hh" +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_shader_instance_varying_color_varying_size) + .vertex_in(0, Type::VEC3, "pos") + .vertex_in(1, Type::MAT4, "InstanceModelMatrix") + .vertex_in(2, Type::VEC4, "color") + .vertex_in(3, Type::FLOAT, "size") + .vertex_out(flat_color_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ViewProjectionMatrix") + .vertex_source("gpu_shader_instance_variying_size_variying_color_vert.glsl") + .fragment_source("gpu_shader_flat_color_frag.glsl") + .additional_info("gpu_srgb_to_framebuffer_space") + .do_static_compilation(true); + \ No newline at end of file diff --git a/source/blender/gpu/shaders/infos/gpu_shader_keyframe_shape_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_keyframe_shape_info.hh new file mode 100644 index 00000000000..8e352af6c1f --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_keyframe_shape_info.hh @@ -0,0 +1,47 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_INTERFACE_INFO(keyframe_shape_iface, "") + .flat(Type::VEC4, "finalColor") + .flat(Type::VEC4, "finalOutlineColor") + .flat(Type::VEC4, "radii") + .flat(Type::VEC4, "thresholds") + .flat(Type::INT, "finalFlags"); + +GPU_SHADER_CREATE_INFO(gpu_shader_keyframe_shape) + .vertex_in(0, Type::VEC4, "color") + .vertex_in(1, Type::VEC4, "outlineColor") + .vertex_in(2, Type::VEC2, "pos") + .vertex_in(3, Type::FLOAT, "size") + .vertex_in(4, Type ::INT, "flags") + .vertex_out(keyframe_shape_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::VEC2, "ViewportSize") + .push_constant(24, Type::FLOAT, "outline_scale") + .vertex_source("gpu_shader_keyframe_shape_vert.glsl") + .fragment_source("gpu_shader_keyframe_shape_frag.glsl") + .do_static_compilation(true); + \ No newline at end of file diff --git a/source/blender/gpu/shaders/infos/gpu_shader_simple_lighting_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_simple_lighting_info.hh new file mode 100644 index 00000000000..c3f86ed2b6f --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_simple_lighting_info.hh @@ -0,0 +1,40 @@ + +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_INTERFACE_INFO(smooth_normal_iface, "").smooth(Type::VEC3, "normal"); + +GPU_SHADER_CREATE_INFO(gpu_shader_simple_lighting) + .vertex_in(0, Type::VEC3, "pos") + .vertex_in(1, Type::VEC3, "nor") + .vertex_out(smooth_normal_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .uniform_buf(0, "SimpleLightingData", "simple_lighting_data", Frequency::PASS) + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .push_constant(16, Type::MAT3, "NormalMatrix") + .typedef_source("GPU_shader_shared.h") + .vertex_source("gpu_shader_3D_normal_vert.glsl") + .fragment_source("gpu_shader_simple_lighting_frag.glsl") + .do_static_compilation(true); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_text_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_text_info.hh new file mode 100644 index 00000000000..a115972694e --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_shader_text_info.hh @@ -0,0 +1,46 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_INTERFACE_INFO(text_iface, "") + .flat(Type::VEC4, "color_flat") + .no_perspective(Type::VEC2, "texCoord_interp") + .flat(Type::INT, "glyph_offset") + .flat(Type::IVEC2, "glyph_dim") + .flat(Type::INT, "interp_size"); + +GPU_SHADER_CREATE_INFO(gpu_shader_text) + .vertex_in(0, Type::VEC4, "pos") + .vertex_in(1, Type::VEC4, "col") + .vertex_in(2, Type ::IVEC2, "glyph_size") + .vertex_in(3, Type ::INT, "offset") + .vertex_out(text_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix") + .sampler(0, ImageType::FLOAT_2D, "glyph", Frequency::PASS) + .vertex_source("gpu_shader_text_vert.glsl") + .fragment_source("gpu_shader_text_frag.glsl") + .additional_info("gpu_srgb_to_framebuffer_space") + .do_static_compilation(true); + \ No newline at end of file diff --git a/source/blender/gpu/shaders/infos/gpu_srgb_to_framebuffer_space_info.hh b/source/blender/gpu/shaders/infos/gpu_srgb_to_framebuffer_space_info.hh new file mode 100644 index 00000000000..3af49b56ab1 --- /dev/null +++ b/source/blender/gpu/shaders/infos/gpu_srgb_to_framebuffer_space_info.hh @@ -0,0 +1,27 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2022 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_shader_create_info.hh" + +GPU_SHADER_CREATE_INFO(gpu_srgb_to_framebuffer_space) + .define("blender_srgb_to_framebuffer_space(a) a"); -- cgit v1.2.3