Revert "Revert "GPUShaderCreateInfo for interface abstraction""

This reverts commit edee5a947b.

Fixes compilation error (Missing file BLI_float2.hh)
This commit is contained in:
Jeroen Bakker 2022-01-17 14:45:22 +01:00
parent edee5a947b
commit 9d3f35a0bf
Notes: blender-bot 2023-02-14 00:44:02 +01:00
Referenced by issue #96290, Regression: Blender crashes when access to gpu.shader.code_from_builtin
Referenced by issue #95981, Setting Masking->Stencil Mask->Stencil Image crashes Blender. Includes fix
Referenced by issue #95036, New noodle not drawn in shader editor.
Referenced by issue #95003, Regression: Proper material shown as magenta
Referenced by issue #94987, Dragged node links are invisible
151 changed files with 5209 additions and 812 deletions

View File

@ -536,12 +536,14 @@ option(WITH_OPENGL "When off limits visibility of the opengl header
option(WITH_GLEW_ES "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
option(WITH_GL_EGL "Use the EGL OpenGL system library instead of the platform specific OpenGL system library (CGL, glX, or WGL)" OFF)
option(WITH_GL_PROFILE_ES20 "Support using OpenGL ES 2.0. (through either EGL or the AGL/WGL/XGL 'es20' profile)" OFF)
option(WITH_GPU_SHADER_BUILDER "Shader builder is a developer option enabling linting on GLSL during compilation" OFF)
mark_as_advanced(
WITH_OPENGL
WITH_GLEW_ES
WITH_GL_EGL
WITH_GL_PROFILE_ES20
WITH_GPU_SHADER_BUILDER
)
if(WIN32)

View File

@ -212,6 +212,7 @@ set(SRC
intern/draw_manager_profiling.h
intern/draw_manager_testing.h
intern/draw_manager_text.h
intern/draw_shader_shared.h
intern/draw_shader.h
intern/draw_subdivision.h
intern/draw_texture_pool.h
@ -233,6 +234,7 @@ set(SRC
engines/image/image_space_node.hh
engines/workbench/workbench_engine.h
engines/workbench/workbench_private.h
engines/workbench/workbench_shader_shared.h
engines/select/select_engine.h
engines/select/select_private.h
engines/overlay/overlay_engine.h
@ -245,268 +247,300 @@ set(LIB
bf_windowmanager
)
data_to_c_simple(engines/eevee/shaders/ambient_occlusion_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/background_vert.glsl SRC)
data_to_c_simple(engines/eevee/shaders/common_uniforms_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/common_utiltex_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lights_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_filter_glossy_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_filter_diffuse_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_filter_visibility_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_geom.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_vert.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_cube_display_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_cube_display_vert.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_grid_display_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_grid_display_vert.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_grid_fill_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_planar_display_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_planar_display_vert.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lookdev_world_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/closure_eval_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/closure_eval_diffuse_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/closure_eval_glossy_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/closure_eval_refraction_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/closure_eval_translucent_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/closure_type_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_bloom_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_dof_bokeh_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_dof_dilate_tiles_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_dof_downsample_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_dof_filter_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_dof_flatten_tiles_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_dof_gather_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_dof_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_dof_reduce_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_dof_resolve_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_dof_scatter_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_dof_scatter_vert.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_dof_setup_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_reflection_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_reflection_resolve_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_reflection_trace_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_downsample_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_downsample_cube_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_gtao_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_velocity_resolve_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_velocity_tile_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_minmaxz_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_mist_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_motion_blur_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_subsurface_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_translucency_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/effect_temporal_aa.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_planar_downsample_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_planar_downsample_geom.glsl SRC)
data_to_c_simple(engines/eevee/shaders/lightprobe_planar_downsample_vert.glsl SRC)
data_to_c_simple(engines/eevee/shaders/object_motion_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/object_motion_vert.glsl SRC)
data_to_c_simple(engines/eevee/shaders/prepass_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/prepass_vert.glsl SRC)
data_to_c_simple(engines/eevee/shaders/shadow_accum_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/shadow_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/shadow_vert.glsl SRC)
data_to_c_simple(engines/eevee/shaders/bsdf_lut_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/btdf_lut_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/bsdf_common_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/irradiance_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/octahedron_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/cubemap_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/bsdf_sampling_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/random_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/raytrace_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/renderpass_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/renderpass_postprocess_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/cryptomatte_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/ltc_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/ssr_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/surface_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/surface_geom.glsl SRC)
data_to_c_simple(engines/eevee/shaders/surface_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/surface_vert.glsl SRC)
data_to_c_simple(engines/eevee/shaders/update_noise_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/volumetric_accum_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/volumetric_lib.glsl SRC)
data_to_c_simple(engines/eevee/shaders/volumetric_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/volumetric_geom.glsl SRC)
data_to_c_simple(engines/eevee/shaders/volumetric_vert.glsl SRC)
data_to_c_simple(engines/eevee/shaders/volumetric_resolve_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/volumetric_scatter_frag.glsl SRC)
data_to_c_simple(engines/eevee/shaders/volumetric_integration_frag.glsl SRC)
set(GLSL_SRC
engines/eevee/shaders/ambient_occlusion_lib.glsl
engines/eevee/shaders/background_vert.glsl
engines/eevee/shaders/common_uniforms_lib.glsl
engines/eevee/shaders/common_utiltex_lib.glsl
engines/eevee/shaders/lights_lib.glsl
engines/eevee/shaders/lightprobe_lib.glsl
engines/eevee/shaders/lightprobe_filter_glossy_frag.glsl
engines/eevee/shaders/lightprobe_filter_diffuse_frag.glsl
engines/eevee/shaders/lightprobe_filter_visibility_frag.glsl
engines/eevee/shaders/lightprobe_geom.glsl
engines/eevee/shaders/lightprobe_vert.glsl
engines/eevee/shaders/lightprobe_cube_display_frag.glsl
engines/eevee/shaders/lightprobe_cube_display_vert.glsl
engines/eevee/shaders/lightprobe_grid_display_frag.glsl
engines/eevee/shaders/lightprobe_grid_display_vert.glsl
engines/eevee/shaders/lightprobe_grid_fill_frag.glsl
engines/eevee/shaders/lightprobe_planar_display_frag.glsl
engines/eevee/shaders/lightprobe_planar_display_vert.glsl
engines/eevee/shaders/lookdev_world_frag.glsl
engines/eevee/shaders/closure_eval_lib.glsl
engines/eevee/shaders/closure_eval_diffuse_lib.glsl
engines/eevee/shaders/closure_eval_glossy_lib.glsl
engines/eevee/shaders/closure_eval_refraction_lib.glsl
engines/eevee/shaders/closure_eval_translucent_lib.glsl
engines/eevee/shaders/closure_type_lib.glsl
engines/eevee/shaders/effect_bloom_frag.glsl
engines/eevee/shaders/effect_dof_bokeh_frag.glsl
engines/eevee/shaders/effect_dof_dilate_tiles_frag.glsl
engines/eevee/shaders/effect_dof_downsample_frag.glsl
engines/eevee/shaders/effect_dof_filter_frag.glsl
engines/eevee/shaders/effect_dof_flatten_tiles_frag.glsl
engines/eevee/shaders/effect_dof_gather_frag.glsl
engines/eevee/shaders/effect_dof_lib.glsl
engines/eevee/shaders/effect_dof_reduce_frag.glsl
engines/eevee/shaders/effect_dof_resolve_frag.glsl
engines/eevee/shaders/effect_dof_scatter_frag.glsl
engines/eevee/shaders/effect_dof_scatter_vert.glsl
engines/eevee/shaders/effect_dof_setup_frag.glsl
engines/eevee/shaders/effect_reflection_lib.glsl
engines/eevee/shaders/effect_reflection_resolve_frag.glsl
engines/eevee/shaders/effect_reflection_trace_frag.glsl
engines/eevee/shaders/effect_downsample_frag.glsl
engines/eevee/shaders/effect_downsample_cube_frag.glsl
engines/eevee/shaders/effect_gtao_frag.glsl
engines/eevee/shaders/effect_velocity_resolve_frag.glsl
engines/eevee/shaders/effect_velocity_tile_frag.glsl
engines/eevee/shaders/effect_minmaxz_frag.glsl
engines/eevee/shaders/effect_mist_frag.glsl
engines/eevee/shaders/effect_motion_blur_frag.glsl
engines/eevee/shaders/effect_subsurface_frag.glsl
engines/eevee/shaders/effect_translucency_frag.glsl
engines/eevee/shaders/effect_temporal_aa.glsl
engines/eevee/shaders/lightprobe_planar_downsample_frag.glsl
engines/eevee/shaders/lightprobe_planar_downsample_geom.glsl
engines/eevee/shaders/lightprobe_planar_downsample_vert.glsl
engines/eevee/shaders/object_motion_frag.glsl
engines/eevee/shaders/object_motion_vert.glsl
engines/eevee/shaders/prepass_frag.glsl
engines/eevee/shaders/prepass_vert.glsl
engines/eevee/shaders/shadow_accum_frag.glsl
engines/eevee/shaders/shadow_frag.glsl
engines/eevee/shaders/shadow_vert.glsl
engines/eevee/shaders/bsdf_lut_frag.glsl
engines/eevee/shaders/btdf_lut_frag.glsl
engines/eevee/shaders/bsdf_common_lib.glsl
engines/eevee/shaders/irradiance_lib.glsl
engines/eevee/shaders/octahedron_lib.glsl
engines/eevee/shaders/cubemap_lib.glsl
engines/eevee/shaders/bsdf_sampling_lib.glsl
engines/eevee/shaders/random_lib.glsl
engines/eevee/shaders/raytrace_lib.glsl
engines/eevee/shaders/renderpass_lib.glsl
engines/eevee/shaders/renderpass_postprocess_frag.glsl
engines/eevee/shaders/cryptomatte_frag.glsl
engines/eevee/shaders/ltc_lib.glsl
engines/eevee/shaders/ssr_lib.glsl
engines/eevee/shaders/surface_frag.glsl
engines/eevee/shaders/surface_geom.glsl
engines/eevee/shaders/surface_lib.glsl
engines/eevee/shaders/surface_vert.glsl
engines/eevee/shaders/update_noise_frag.glsl
engines/eevee/shaders/volumetric_accum_frag.glsl
engines/eevee/shaders/volumetric_lib.glsl
engines/eevee/shaders/volumetric_frag.glsl
engines/eevee/shaders/volumetric_geom.glsl
engines/eevee/shaders/volumetric_vert.glsl
engines/eevee/shaders/volumetric_resolve_frag.glsl
engines/eevee/shaders/volumetric_scatter_frag.glsl
engines/eevee/shaders/volumetric_integration_frag.glsl
data_to_c_simple(engines/workbench/shaders/workbench_cavity_lib.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_common_lib.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_composite_frag.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_curvature_lib.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_data_lib.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_effect_cavity_frag.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_effect_dof_frag.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_effect_outline_frag.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_effect_smaa_frag.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_effect_smaa_vert.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_effect_taa_frag.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_image_lib.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_matcap_lib.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_material_lib.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_merge_infront_frag.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_prepass_frag.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_prepass_hair_vert.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_prepass_pointcloud_vert.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_prepass_vert.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_shader_interface_lib.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_shadow_caps_geom.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_shadow_debug_frag.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_shadow_geom.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_shadow_vert.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_transparent_accum_frag.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_transparent_resolve_frag.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_volume_frag.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_volume_vert.glsl SRC)
data_to_c_simple(engines/workbench/shaders/workbench_world_light_lib.glsl SRC)
engines/workbench/shaders/workbench_cavity_lib.glsl
engines/workbench/shaders/workbench_common_lib.glsl
engines/workbench/shaders/workbench_composite_frag.glsl
engines/workbench/shaders/workbench_curvature_lib.glsl
engines/workbench/shaders/workbench_data_lib.glsl
engines/workbench/shaders/workbench_effect_cavity_frag.glsl
engines/workbench/shaders/workbench_effect_dof_frag.glsl
engines/workbench/shaders/workbench_effect_outline_frag.glsl
engines/workbench/shaders/workbench_effect_smaa_frag.glsl
engines/workbench/shaders/workbench_effect_smaa_vert.glsl
engines/workbench/shaders/workbench_effect_taa_frag.glsl
engines/workbench/shaders/workbench_image_lib.glsl
engines/workbench/shaders/workbench_matcap_lib.glsl
engines/workbench/shaders/workbench_material_lib.glsl
engines/workbench/shaders/workbench_merge_infront_frag.glsl
engines/workbench/shaders/workbench_prepass_frag.glsl
engines/workbench/shaders/workbench_prepass_hair_vert.glsl
engines/workbench/shaders/workbench_prepass_pointcloud_vert.glsl
engines/workbench/shaders/workbench_prepass_vert.glsl
engines/workbench/shaders/workbench_shader_interface_lib.glsl
engines/workbench/shaders/workbench_shadow_caps_geom.glsl
engines/workbench/shaders/workbench_shadow_debug_frag.glsl
engines/workbench/shaders/workbench_shadow_geom.glsl
engines/workbench/shaders/workbench_shadow_vert.glsl
engines/workbench/shaders/workbench_transparent_accum_frag.glsl
engines/workbench/shaders/workbench_transparent_resolve_frag.glsl
engines/workbench/shaders/workbench_volume_frag.glsl
engines/workbench/shaders/workbench_volume_vert.glsl
engines/workbench/shaders/workbench_world_light_lib.glsl
data_to_c_simple(intern/shaders/common_colormanagement_lib.glsl SRC)
data_to_c_simple(intern/shaders/common_globals_lib.glsl SRC)
data_to_c_simple(intern/shaders/common_pointcloud_lib.glsl SRC)
data_to_c_simple(intern/shaders/common_hair_lib.glsl SRC)
data_to_c_simple(intern/shaders/common_hair_refine_vert.glsl SRC)
data_to_c_simple(intern/shaders/common_hair_refine_comp.glsl SRC)
data_to_c_simple(intern/shaders/common_math_lib.glsl SRC)
data_to_c_simple(intern/shaders/common_math_geom_lib.glsl SRC)
data_to_c_simple(intern/shaders/common_view_lib.glsl SRC)
data_to_c_simple(intern/shaders/common_fxaa_lib.glsl SRC)
data_to_c_simple(intern/shaders/common_smaa_lib.glsl SRC)
data_to_c_simple(intern/shaders/common_fullscreen_vert.glsl SRC)
data_to_c_simple(intern/shaders/common_subdiv_custom_data_interp_comp.glsl SRC)
data_to_c_simple(intern/shaders/common_subdiv_ibo_lines_comp.glsl SRC)
data_to_c_simple(intern/shaders/common_subdiv_ibo_tris_comp.glsl SRC)
data_to_c_simple(intern/shaders/common_subdiv_lib.glsl SRC)
data_to_c_simple(intern/shaders/common_subdiv_normals_accumulate_comp.glsl SRC)
data_to_c_simple(intern/shaders/common_subdiv_normals_finalize_comp.glsl SRC)
data_to_c_simple(intern/shaders/common_subdiv_patch_evaluation_comp.glsl SRC)
data_to_c_simple(intern/shaders/common_subdiv_vbo_edge_fac_comp.glsl SRC)
data_to_c_simple(intern/shaders/common_subdiv_vbo_edituv_strech_angle_comp.glsl SRC)
data_to_c_simple(intern/shaders/common_subdiv_vbo_edituv_strech_area_comp.glsl SRC)
data_to_c_simple(intern/shaders/common_subdiv_vbo_lnor_comp.glsl SRC)
data_to_c_simple(intern/shaders/common_subdiv_vbo_sculpt_data_comp.glsl SRC)
engines/workbench/workbench_shader_shared.h
data_to_c_simple(engines/gpencil/shaders/gpencil_frag.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_vert.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_antialiasing_frag.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_antialiasing_vert.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_common_lib.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_layer_blend_frag.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_mask_invert_frag.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_depth_merge_frag.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_depth_merge_vert.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_vfx_frag.glsl SRC)
intern/shaders/common_colormanagement_lib.glsl
intern/shaders/common_globals_lib.glsl
intern/shaders/common_pointcloud_lib.glsl
intern/shaders/common_hair_lib.glsl
intern/shaders/common_hair_refine_vert.glsl
intern/shaders/common_hair_refine_comp.glsl
intern/shaders/common_math_lib.glsl
intern/shaders/common_math_geom_lib.glsl
intern/shaders/common_view_lib.glsl
intern/shaders/common_fxaa_lib.glsl
intern/shaders/common_smaa_lib.glsl
intern/shaders/common_fullscreen_vert.glsl
data_to_c_simple(engines/select/shaders/selection_id_3D_vert.glsl SRC)
data_to_c_simple(engines/select/shaders/selection_id_frag.glsl SRC)
intern/shaders/common_subdiv_custom_data_interp_comp.glsl
intern/shaders/common_subdiv_ibo_lines_comp.glsl
intern/shaders/common_subdiv_ibo_tris_comp.glsl
intern/shaders/common_subdiv_lib.glsl
intern/shaders/common_subdiv_normals_accumulate_comp.glsl
intern/shaders/common_subdiv_normals_finalize_comp.glsl
intern/shaders/common_subdiv_patch_evaluation_comp.glsl
intern/shaders/common_subdiv_vbo_edge_fac_comp.glsl
intern/shaders/common_subdiv_vbo_edituv_strech_angle_comp.glsl
intern/shaders/common_subdiv_vbo_edituv_strech_area_comp.glsl
intern/shaders/common_subdiv_vbo_lnor_comp.glsl
intern/shaders/common_subdiv_vbo_sculpt_data_comp.glsl
data_to_c_simple(engines/basic/shaders/conservative_depth_geom.glsl SRC)
data_to_c_simple(engines/basic/shaders/depth_vert.glsl SRC)
data_to_c_simple(engines/basic/shaders/depth_frag.glsl SRC)
intern/draw_shader_shared.h
data_to_c_simple(engines/overlay/shaders/common_overlay_lib.glsl SRC)
data_to_c_simple(engines/overlay/shaders/antialiasing_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/antialiasing_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_dof_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_dof_solid_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_envelope_outline_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_envelope_solid_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_envelope_solid_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_shape_outline_geom.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_shape_outline_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_shape_solid_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_shape_solid_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_shape_wire_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_sphere_outline_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_sphere_solid_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_sphere_solid_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_stick_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_stick_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_wire_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/armature_wire_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/background_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/clipbound_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/depth_only_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_curve_handle_geom.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_curve_handle_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_curve_point_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_curve_wire_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_gpencil_canvas_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_gpencil_guide_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_gpencil_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_lattice_point_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_lattice_wire_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_mesh_common_lib.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_mesh_facefill_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_mesh_facefill_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_mesh_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_mesh_geom.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_mesh_normal_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_mesh_analysis_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_mesh_analysis_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_mesh_skin_root_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_mesh_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_particle_strand_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_particle_point_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_uv_edges_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_uv_edges_geom.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_uv_edges_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_uv_verts_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_uv_verts_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_uv_faces_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_uv_face_dots_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_uv_image_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_uv_image_mask_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_uv_stretching_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/edit_uv_tiled_image_borders_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_groundline_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_lightprobe_grid_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_loose_point_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_loose_point_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_point_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_wire_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/extra_wire_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/facing_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/facing_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/grid_background_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/grid_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/grid_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/image_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/image_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/motion_path_line_geom.glsl SRC)
data_to_c_simple(engines/overlay/shaders/motion_path_line_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/motion_path_point_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/outline_detect_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/outline_prepass_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/outline_prepass_geom.glsl SRC)
data_to_c_simple(engines/overlay/shaders/outline_prepass_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/paint_face_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/paint_point_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/paint_texture_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/paint_texture_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/paint_vertcol_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/paint_vertcol_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/paint_weight_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/paint_weight_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/paint_wire_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/particle_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/particle_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/sculpt_mask_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/sculpt_mask_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/volume_velocity_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/volume_gridlines_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/wireframe_vert.glsl SRC)
data_to_c_simple(engines/overlay/shaders/wireframe_frag.glsl SRC)
data_to_c_simple(engines/overlay/shaders/xray_fade_frag.glsl SRC)
engines/gpencil/shaders/gpencil_frag.glsl
engines/gpencil/shaders/gpencil_vert.glsl
engines/gpencil/shaders/gpencil_antialiasing_frag.glsl
engines/gpencil/shaders/gpencil_antialiasing_vert.glsl
engines/gpencil/shaders/gpencil_common_lib.glsl
engines/gpencil/shaders/gpencil_layer_blend_frag.glsl
engines/gpencil/shaders/gpencil_mask_invert_frag.glsl
engines/gpencil/shaders/gpencil_depth_merge_frag.glsl
engines/gpencil/shaders/gpencil_depth_merge_vert.glsl
engines/gpencil/shaders/gpencil_vfx_frag.glsl
data_to_c_simple(engines/image/shaders/engine_image_frag.glsl SRC)
data_to_c_simple(engines/image/shaders/engine_image_vert.glsl SRC)
engines/select/shaders/selection_id_3D_vert.glsl
engines/select/shaders/selection_id_frag.glsl
engines/basic/shaders/conservative_depth_geom.glsl
engines/basic/shaders/depth_vert.glsl
engines/basic/shaders/depth_frag.glsl
engines/overlay/shaders/common_overlay_lib.glsl
engines/overlay/shaders/antialiasing_frag.glsl
engines/overlay/shaders/antialiasing_vert.glsl
engines/overlay/shaders/armature_dof_vert.glsl
engines/overlay/shaders/armature_dof_solid_frag.glsl
engines/overlay/shaders/armature_envelope_outline_vert.glsl
engines/overlay/shaders/armature_envelope_solid_frag.glsl
engines/overlay/shaders/armature_envelope_solid_vert.glsl
engines/overlay/shaders/armature_shape_outline_geom.glsl
engines/overlay/shaders/armature_shape_outline_vert.glsl
engines/overlay/shaders/armature_shape_solid_frag.glsl
engines/overlay/shaders/armature_shape_solid_vert.glsl
engines/overlay/shaders/armature_shape_wire_vert.glsl
engines/overlay/shaders/armature_sphere_outline_vert.glsl
engines/overlay/shaders/armature_sphere_solid_frag.glsl
engines/overlay/shaders/armature_sphere_solid_vert.glsl
engines/overlay/shaders/armature_stick_frag.glsl
engines/overlay/shaders/armature_stick_vert.glsl
engines/overlay/shaders/armature_wire_frag.glsl
engines/overlay/shaders/armature_wire_vert.glsl
engines/overlay/shaders/background_frag.glsl
engines/overlay/shaders/clipbound_vert.glsl
engines/overlay/shaders/depth_only_vert.glsl
engines/overlay/shaders/edit_curve_handle_geom.glsl
engines/overlay/shaders/edit_curve_handle_vert.glsl
engines/overlay/shaders/edit_curve_point_vert.glsl
engines/overlay/shaders/edit_curve_wire_vert.glsl
engines/overlay/shaders/edit_gpencil_canvas_vert.glsl
engines/overlay/shaders/edit_gpencil_guide_vert.glsl
engines/overlay/shaders/edit_gpencil_vert.glsl
engines/overlay/shaders/edit_lattice_point_vert.glsl
engines/overlay/shaders/edit_lattice_wire_vert.glsl
engines/overlay/shaders/edit_mesh_common_lib.glsl
engines/overlay/shaders/edit_mesh_facefill_frag.glsl
engines/overlay/shaders/edit_mesh_facefill_vert.glsl
engines/overlay/shaders/edit_mesh_frag.glsl
engines/overlay/shaders/edit_mesh_geom.glsl
engines/overlay/shaders/edit_mesh_normal_vert.glsl
engines/overlay/shaders/edit_mesh_analysis_frag.glsl
engines/overlay/shaders/edit_mesh_analysis_vert.glsl
engines/overlay/shaders/edit_mesh_skin_root_vert.glsl
engines/overlay/shaders/edit_mesh_vert.glsl
engines/overlay/shaders/edit_particle_strand_vert.glsl
engines/overlay/shaders/edit_particle_point_vert.glsl
engines/overlay/shaders/edit_uv_edges_vert.glsl
engines/overlay/shaders/edit_uv_edges_geom.glsl
engines/overlay/shaders/edit_uv_edges_frag.glsl
engines/overlay/shaders/edit_uv_verts_vert.glsl
engines/overlay/shaders/edit_uv_verts_frag.glsl
engines/overlay/shaders/edit_uv_faces_vert.glsl
engines/overlay/shaders/edit_uv_face_dots_vert.glsl
engines/overlay/shaders/edit_uv_image_vert.glsl
engines/overlay/shaders/edit_uv_image_mask_frag.glsl
engines/overlay/shaders/edit_uv_stretching_vert.glsl
engines/overlay/shaders/edit_uv_tiled_image_borders_vert.glsl
engines/overlay/shaders/extra_frag.glsl
engines/overlay/shaders/extra_vert.glsl
engines/overlay/shaders/extra_groundline_vert.glsl
engines/overlay/shaders/extra_lightprobe_grid_vert.glsl
engines/overlay/shaders/extra_loose_point_frag.glsl
engines/overlay/shaders/extra_loose_point_vert.glsl
engines/overlay/shaders/extra_point_vert.glsl
engines/overlay/shaders/extra_wire_frag.glsl
engines/overlay/shaders/extra_wire_vert.glsl
engines/overlay/shaders/facing_frag.glsl
engines/overlay/shaders/facing_vert.glsl
engines/overlay/shaders/grid_background_frag.glsl
engines/overlay/shaders/grid_frag.glsl
engines/overlay/shaders/grid_vert.glsl
engines/overlay/shaders/image_vert.glsl
engines/overlay/shaders/image_frag.glsl
engines/overlay/shaders/motion_path_line_geom.glsl
engines/overlay/shaders/motion_path_line_vert.glsl
engines/overlay/shaders/motion_path_point_vert.glsl
engines/overlay/shaders/outline_detect_frag.glsl
engines/overlay/shaders/outline_prepass_frag.glsl
engines/overlay/shaders/outline_prepass_geom.glsl
engines/overlay/shaders/outline_prepass_vert.glsl
engines/overlay/shaders/paint_face_vert.glsl
engines/overlay/shaders/paint_point_vert.glsl
engines/overlay/shaders/paint_texture_frag.glsl
engines/overlay/shaders/paint_texture_vert.glsl
engines/overlay/shaders/paint_vertcol_frag.glsl
engines/overlay/shaders/paint_vertcol_vert.glsl
engines/overlay/shaders/paint_weight_frag.glsl
engines/overlay/shaders/paint_weight_vert.glsl
engines/overlay/shaders/paint_wire_vert.glsl
engines/overlay/shaders/particle_vert.glsl
engines/overlay/shaders/particle_frag.glsl
engines/overlay/shaders/sculpt_mask_vert.glsl
engines/overlay/shaders/sculpt_mask_frag.glsl
engines/overlay/shaders/volume_velocity_vert.glsl
engines/overlay/shaders/volume_gridlines_vert.glsl
engines/overlay/shaders/wireframe_vert.glsl
engines/overlay/shaders/wireframe_frag.glsl
engines/overlay/shaders/xray_fade_frag.glsl
engines/image/shaders/engine_image_frag.glsl
engines/image/shaders/engine_image_vert.glsl
)
set(GLSL_C)
foreach(GLSL_FILE ${GLSL_SRC})
data_to_c_simple(${GLSL_FILE} GLSL_C)
endforeach()
blender_add_lib(bf_draw_shaders "${GLSL_C}" "" "" "")
list(APPEND LIB
bf_draw_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_draw_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})
target_include_directories(bf_draw_shaders PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
list(APPEND INC
)

View File

@ -3,10 +3,6 @@
#define CAVITY_BUFFER_RANGE 4.0
#ifdef WORKBENCH_ENCODE_NORMALS
# define WB_Normal vec2
/* From http://aras-p.info/texts/CompactNormalStorage.html
* Using Method #4: Spheremap Transform */
vec3 workbench_normal_decode(vec4 enc)
@ -22,7 +18,7 @@ vec3 workbench_normal_decode(vec4 enc)
/* From http://aras-p.info/texts/CompactNormalStorage.html
* Using Method #4: Spheremap Transform */
WB_Normal workbench_normal_encode(bool front_face, vec3 n)
vec2 workbench_normal_encode(bool front_face, vec3 n)
{
n = normalize(front_face ? n : -n);
float p = sqrt(n.z * 8.0 + 8.0);
@ -30,13 +26,6 @@ WB_Normal workbench_normal_encode(bool front_face, vec3 n)
return n.xy;
}
#else
# define WB_Normal vec3
/* Well just do nothing... */
# define workbench_normal_encode(f, a) (a)
# define workbench_normal_decode(a) (a.xyz)
#endif /* WORKBENCH_ENCODE_NORMALS */
/* Encoding into the alpha of a RGBA16F texture. (10bit mantissa) */
#define TARGET_BITCOUNT 8u
#define METALLIC_BITS 3u /* Metallic channel is less important. */

View File

@ -1,3 +1,5 @@
#ifndef WORKBENCH_SHADER_SHARED_H
struct LightData {
vec4 direction;
vec4 specular_color;
@ -37,9 +39,10 @@ struct WorldData {
int _pad2;
};
#define viewport_size_inv viewport_size.zw
# define viewport_size_inv viewport_size.zw
layout(std140) uniform world_block
{
WorldData world_data;
};
#endif

View File

@ -4,6 +4,8 @@
#pragma BLENDER_REQUIRE(workbench_cavity_lib.glsl)
#pragma BLENDER_REQUIRE(workbench_curvature_lib.glsl)
#ifndef DRW_SHADER_SHARED_H
uniform sampler2D depthBuffer;
uniform sampler2D normalBuffer;
uniform usampler2D objectIdBuffer;
@ -12,6 +14,8 @@ in vec4 uvcoordsvar;
out vec4 fragColor;
#endif
void main()
{
float cavity = 0.0, edges = 0.0, curvature = 0.0;

View File

@ -0,0 +1,28 @@
#include "gpu_shader_create_info.hh"
GPU_SHADER_CREATE_INFO(workbench_effect_cavity_common)
.fragment_out(0, Type::VEC4, "fragColor")
.sampler(0, ImageType::FLOAT_2D, "depthBuffer")
.sampler(1, ImageType::FLOAT_2D, "normalBuffer")
.sampler(2, ImageType::UINT_2D, "objectIdBuffer")
.uniform_buf(3, "vec4", "samples_coords[512]")
.fragment_source("workbench_effect_cavity_frag.glsl")
.additional_info("draw_fullscreen")
.additional_info("draw_view");
GPU_SHADER_CREATE_INFO(workbench_effect_cavity)
.do_static_compilation(true)
.define("USE_CAVITY")
.additional_info("workbench_effect_cavity_common");
GPU_SHADER_CREATE_INFO(workbench_effect_curvature)
.do_static_compilation(true)
.define("USE_CURVATURE")
.additional_info("workbench_effect_cavity_common");
GPU_SHADER_CREATE_INFO(workbench_effect_cavity_curvature)
.do_static_compilation(true)
.define("USE_CAVITY")
.define("USE_CURVATURE")
.additional_info("workbench_effect_cavity_common");

View File

@ -25,12 +25,14 @@ bool node_tex_tile_lookup(inout vec3 co, sampler2DArray ima, sampler1DArray map)
return true;
}
#ifndef WORKBENCH_SHADER_SHARED_H
uniform sampler2DArray imageTileArray;
uniform sampler1DArray imageTileData;
uniform sampler2D imageTexture;
uniform float imageTransparencyCutoff = 0.1;
uniform bool imagePremult;
#endif
vec3 workbench_image_color(vec2 uvs)
{

View File

@ -4,9 +4,11 @@
#pragma BLENDER_REQUIRE(workbench_common_lib.glsl)
#pragma BLENDER_REQUIRE(workbench_image_lib.glsl)
#ifndef WORKBENCH_SHADER_SHARED_H
layout(location = 0) out vec4 materialData;
layout(location = 1) out WB_Normal normalData;
layout(location = 1) out vec2 normalData;
layout(location = 2) out uint objectId;
#endif
uniform bool useMatcap = false;

View File

@ -5,8 +5,10 @@
#pragma BLENDER_REQUIRE(workbench_material_lib.glsl)
#pragma BLENDER_REQUIRE(workbench_image_lib.glsl)
#ifndef WORKBENCH_SHADER_SHARED_H
uniform samplerBuffer ac; /* active color layer */
uniform samplerBuffer au; /* active texture layer */
#endif
/* From http://libnoise.sourceforge.net/noisegen/index.html */
float integer_noise(int n)
@ -71,8 +73,10 @@ void main()
normal_interp = normalize(normal_world_to_view(nor));
#ifdef OPAQUE_MATERIAL
#ifndef WORKBENCH_SHADER_SHARED_H
# ifdef OPAQUE_MATERIAL
float metallic, roughness;
# endif
#endif
workbench_material_data_get(resource_handle, color_interp, alpha_interp, roughness, metallic);

View File

@ -0,0 +1,136 @@
#include "gpu_shader_create_info.hh"
/* -------------------------------------------------------------------- */
/** \name Object Type
* \{ */
GPU_SHADER_CREATE_INFO(workbench_mesh)
.vertex_in(0, Type::VEC3, "pos")
.vertex_in(1, Type::VEC3, "nor")
.vertex_in(2, Type::VEC4, "ac")
.vertex_in(3, Type::VEC2, "au")
.vertex_source("workbench_prepass_vert.glsl")
.additional_info("draw_mesh");
GPU_SHADER_CREATE_INFO(workbench_hair)
.sampler(0, ImageType::FLOAT_BUFFER, "ac", Frequency::BATCH)
.sampler(1, ImageType::FLOAT_BUFFER, "au", Frequency::BATCH)
.vertex_source("workbench_prepass_hair_vert.glsl")
.additional_info("draw_hair");
GPU_SHADER_CREATE_INFO(workbench_pointcloud)
.vertex_source("workbench_prepass_pointcloud_vert.glsl")
.additional_info("draw_pointcloud");
/** \} */
/* -------------------------------------------------------------------- */
/** \name Texture Type
* \{ */
GPU_SHADER_CREATE_INFO(workbench_texture_none).define("TEXTURE_NONE");
GPU_SHADER_CREATE_INFO(workbench_texture_single)
.sampler(2, ImageType::FLOAT_2D, "imageTexture", Frequency::BATCH)
.push_constant(1, Type::BOOL, "imagePremult")
.push_constant(2, Type::FLOAT, "imageTransparencyCutoff")
.define("V3D_SHADING_TEXTURE_COLOR");
GPU_SHADER_CREATE_INFO(workbench_texture_tile)
.sampler(2, ImageType::FLOAT_2D_ARRAY, "imageTileArray", Frequency::BATCH)
.sampler(3, ImageType::FLOAT_1D_ARRAY, "imageTileData", Frequency::BATCH)
.push_constant(1, Type::BOOL, "imagePremult")
.push_constant(2, Type::FLOAT, "imageTransparencyCutoff")
.define("TEXTURE_IMAGE_ARRAY");
/** \} */
/* -------------------------------------------------------------------- */
/** \name Lighting Type
* \{ */
GPU_SHADER_CREATE_INFO(workbench_lighting_studio).define("V3D_LIGHTING_STUDIO");
GPU_SHADER_CREATE_INFO(workbench_lighting_matcap).define("V3D_LIGHTING_MATCAP");
GPU_SHADER_CREATE_INFO(workbench_lighting_flat).define("V3D_LIGHTING_FLAT");
/** \} */
/* -------------------------------------------------------------------- */
/** \name Material Interface
* \{ */
GPU_SHADER_INTERFACE_INFO(workbench_material_iface, "")
.smooth(Type::VEC3, "normal_interp")
.smooth(Type::VEC3, "color_interp")
.smooth(Type::FLOAT, "alpha_interp")
.smooth(Type::VEC2, "uv_interp")
.flat(Type::INT, "object_id")
.flat(Type::FLOAT, "roughness")
.flat(Type::FLOAT, "metallic");
GPU_SHADER_CREATE_INFO(workbench_material).vertex_out(workbench_material_iface);
/** \} */
/* -------------------------------------------------------------------- */
/** \name Pipeline Type
* \{ */
GPU_SHADER_CREATE_INFO(workbench_transparent_accum)
/* Note: Blending will be skipped on objectId because output is a
non-normalized integer buffer. */
.fragment_out(0, Type::VEC4, "transparentAccum")
.fragment_out(1, Type::VEC4, "revealageAccum")
.fragment_out(2, Type::UINT, "objectId")
.uniform_buf(4, "WorldData", "world_data", Frequency::PASS)
.typedef_source("workbench_shader_shared.h")
.fragment_source("workbench_transparent_accum_frag.glsl")
.additional_info("workbench_material");
GPU_SHADER_CREATE_INFO(workbench_opaque)
.fragment_out(0, Type::VEC4, "materialData")
.fragment_out(1, Type::VEC2, "normalData")
.fragment_out(2, Type::UINT, "objectId")
.uniform_buf(4, "WorldData", "world_data", Frequency::PASS)
.typedef_source("workbench_shader_shared.h")
.fragment_source("workbench_prepass_frag.glsl")
.additional_info("workbench_material");
/** \} */
/* -------------------------------------------------------------------- */
/** \name Variations Declaration
* \{ */
#define WORKBENCH_SURFACETYPE_VARIATIONS(prefix, ...) \
GPU_SHADER_CREATE_INFO(prefix##_mesh) \
.additional_info("workbench_mesh", __VA_ARGS__) \
.do_static_compilation(true); \
GPU_SHADER_CREATE_INFO(prefix##_hair) \
.additional_info("workbench_hair", __VA_ARGS__) \
.do_static_compilation(true); \
GPU_SHADER_CREATE_INFO(prefix##_ptcloud) \
.additional_info("workbench_pointcloud", __VA_ARGS__) \
.do_static_compilation(true);
#define WORKBENCH_PIPELINE_VARIATIONS(prefix, ...) \
WORKBENCH_SURFACETYPE_VARIATIONS(prefix##_transp_studio, \
"workbench_transparent_accum", \
"workbench_lighting_studio", \
__VA_ARGS__) \
WORKBENCH_SURFACETYPE_VARIATIONS(prefix##_transp_matcap, \
"workbench_transparent_accum", \
"workbench_lighting_matcap", \
__VA_ARGS__) \
WORKBENCH_SURFACETYPE_VARIATIONS(prefix##_transp_flat, \
"workbench_transparent_accum", \
"workbench_lighting_flat", \
__VA_ARGS__) \
WORKBENCH_SURFACETYPE_VARIATIONS(prefix##_opaque, "workbench_opaque", __VA_ARGS__)
WORKBENCH_PIPELINE_VARIATIONS(workbench_tex_none, "workbench_texture_none")
WORKBENCH_PIPELINE_VARIATIONS(workbench_tex_single, "workbench_texture_single")
WORKBENCH_PIPELINE_VARIATIONS(workbench_tex_tile, "workbench_texture_tile")
/** \} */

View File

@ -21,8 +21,10 @@ void main()
uv_interp = vec2(0.0);
#ifdef OPAQUE_MATERIAL
#ifndef WORKBENCH_SHADER_SHARED_H
# ifdef OPAQUE_MATERIAL
float metallic, roughness;
# endif
#endif
workbench_material_data_get(resource_handle, color_interp, alpha_interp, roughness, metallic);

View File

@ -5,10 +5,12 @@
#pragma BLENDER_REQUIRE(workbench_material_lib.glsl)
#pragma BLENDER_REQUIRE(workbench_image_lib.glsl)
#ifndef WORKBENCH_SHADER_SHARED_H
in vec3 pos;
in vec3 nor;
in vec4 ac; /* active color */
in vec2 au; /* active texture layer */
#endif
void main()
{
@ -23,8 +25,10 @@ void main()
normal_interp = normalize(normal_object_to_view(nor));
#ifdef OPAQUE_MATERIAL
#ifndef WORKBENCH_SHADER_SHARED_H
# ifdef OPAQUE_MATERIAL
float metallic, roughness;
# endif
#endif
workbench_material_data_get(resource_handle, color_interp, alpha_interp, roughness, metallic);

View File

@ -1,15 +1,17 @@
#ifndef WORKBENCH_SHADER_SHARED_H
IN_OUT ShaderStageInterface
{
vec3 normal_interp;
vec3 color_interp;
float alpha_interp;
vec2 uv_interp;
#ifdef TRANSPARENT_MATERIAL
# ifdef TRANSPARENT_MATERIAL
flat float roughness;
flat float metallic;
#else
# else
flat float packed_rough_metal;
#endif
# endif
flat int object_id;
};
#endif

View File

@ -6,6 +6,7 @@
#pragma BLENDER_REQUIRE(workbench_matcap_lib.glsl)
#pragma BLENDER_REQUIRE(workbench_world_light_lib.glsl)
#ifndef WORKBENCH_SHADER_SHARED_H
/* Revealage is actually stored in transparentAccum alpha channel.
* This is a workaround to older hardware not having separate blend equation per render target. */
layout(location = 0) out vec4 transparentAccum;
@ -13,6 +14,7 @@ layout(location = 1) out vec4 revealageAccum;
/* NOTE: Blending will be skipped on objectId because output is a non-normalized integer buffer. */
layout(location = 2) out uint objectId;
#endif
/* Special function only to be used with calculate_transparent_weight(). */
float linear_zdepth(float depth, vec4 viewvecs[2], mat4 proj_mat)

View File

@ -0,0 +1,48 @@
#ifndef GPU_SHADER
# include "gpu_shader_shared_utils.h"
#endif
#define WORKBENCH_SHADER_SHARED_H
struct LightData {
float4 direction;
float4 specular_color;
float4 diffuse_color_wrap; /* rgb: diffuse col a: wrapped lighting factor */
};
struct WorldData {
float4 viewport_size;
float4 object_outline_color;
float4 shadow_direction_vs;
float shadow_focus;
float shadow_shift;
float shadow_mul;
float shadow_add;
/* - 16 bytes alignment - */
LightData lights[4];
float4 ambient_color;
int cavity_sample_start;
int cavity_sample_end;
float cavity_sample_count_inv;
float cavity_jitter_scale;
float cavity_valley_factor;
float cavity_ridge_factor;
float cavity_attenuation;
float cavity_distance;
float curvature_ridge;
float curvature_valley;
float ui_scale;
float _pad0;
int matcap_orientation;
bool use_specular;
int _pad1;
int _pad2;
};
#define viewport_size_inv viewport_size.zw
#define packed_rough_metal roughness

View File

@ -70,6 +70,7 @@
#include "GPU_framebuffer.h"
#include "GPU_immediate.h"
#include "GPU_matrix.h"
#include "GPU_shader_shared.h"
#include "GPU_state.h"
#include "GPU_uniform_buffer.h"
#include "GPU_viewport.h"
@ -2756,11 +2757,15 @@ void DRW_draw_depth_object(
GPU_framebuffer_clear_depth(depth_fb, 1.0f);
GPU_depth_test(GPU_DEPTH_LESS_EQUAL);
const float(*world_clip_planes)[4] = NULL;
if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
struct GPUClipPlanes planes;
const bool use_clipping_planes = RV3D_CLIPPING_ENABLED(v3d, rv3d);
if (use_clipping_planes) {
GPU_clip_distances(6);
ED_view3d_clipping_local(rv3d, object->obmat);
world_clip_planes = rv3d->clip_local;
for (int i = 0; i < 6; i++) {
copy_v4_v4(planes.world[i], rv3d->clip_local[i]);
}
copy_m4_m4(planes.ModelMatrix, object->obmat);
}
drw_batch_cache_validate(object);
@ -2782,14 +2787,19 @@ void DRW_draw_depth_object(
BLI_task_graph_work_and_wait(task_graph);
BLI_task_graph_free(task_graph);
const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED :
GPU_SHADER_CFG_DEFAULT;
const eGPUShaderConfig sh_cfg = use_clipping_planes ? GPU_SHADER_CFG_CLIPPED :
GPU_SHADER_CFG_DEFAULT;
GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_DEPTH_ONLY, sh_cfg);
if (world_clip_planes != NULL) {
GPU_batch_uniform_4fv_array(batch, "WorldClipPlanes", 6, world_clip_planes);
GPUUniformBuf *ubo = NULL;
if (use_clipping_planes) {
ubo = GPU_uniformbuf_create_ex(sizeof(struct GPUClipPlanes), &planes, __func__);
GPU_batch_uniformbuf_bind(batch, "clipPlanes", ubo);
}
GPU_batch_draw(batch);
GPU_uniformbuf_free(ubo);
} break;
case OB_CURVE:
case OB_SURF:

View File

@ -0,0 +1,41 @@
#ifndef GPU_SHADER
# include "gpu_shader_shared_utils.h"
#endif
#define DRW_SHADER_SHARED_H
#define DRW_RESOURCE_CHUNK_LEN 512
struct ViewInfos {
/* View matrices */
float4x4 persmat;
float4x4 persinv;
float4x4 viewmat;
float4x4 viewinv;
float4x4 winmat;
float4x4 wininv;
float4 clipplanes[6];
float4 viewvecs[2];
/* Should not be here. Not view dependent (only main view). */
float4 viewcamtexcofac;
};
BLI_STATIC_ASSERT_ALIGN(ViewInfos, 16)
/* TODO(fclem) Mass rename. */
#define ViewProjectionMatrix drw_view.persmat
#define ViewProjectionMatrixInverse drw_view.persinv
#define ViewMatrix drw_view.viewmat
#define ViewMatrixInverse drw_view.viewinv
#define ProjectionMatrix drw_view.winmat
#define ProjectionMatrixInverse drw_view.wininv
#define clipPlanes drw_view.clipplanes
#define ViewVecs drw_view.viewvecs
#define CameraTexCoFactors drw_view.viewcamtexcofac
struct ObjectMatrices {
float4x4 drw_modelMatrix;
float4x4 drw_modelMatrixInverse;
};
BLI_STATIC_ASSERT_ALIGN(ViewInfos, 16)

View File

@ -1,5 +1,7 @@
#ifndef USE_GPU_SHADER_CREATE_INFO
out vec4 uvcoordsvar;
#endif
void main()
{

View File

@ -2,6 +2,8 @@
/* NOTE: To be used with UNIFORM_RESOURCE_ID and INSTANCED_ATTR as define. */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#ifndef DRW_SHADER_SHARED_H
in vec4 pos; /* Position and radius. */
/* ---- Instanced attribs ---- */
@ -9,6 +11,8 @@ in vec4 pos; /* Position and radius. */
in vec3 pos_inst;
in vec3 nor;
#endif
mat3 pointcloud_get_facing_matrix(vec3 p)
{
mat3 facing_mat;

View File

@ -1,5 +1,7 @@
#define COMMON_VIEW_LIB
#define DRW_RESOURCE_CHUNK_LEN 512
/* Temporary until we fully make the switch. */
#ifndef DRW_SHADER_SHARED_H
# define DRW_RESOURCE_CHUNK_LEN 512
/* keep in sync with DRWManager.view_data */
layout(std140) uniform viewBlock
@ -22,6 +24,8 @@ layout(std140) uniform viewBlock
vec4 CameraTexCoFactors;
};
#endif /* DRW_SHADER_SHARED_H */
#define ViewNear (ViewVecs[0].w)
#define ViewFar (ViewVecs[1].w)
@ -141,6 +145,10 @@ flat in int resourceIDFrag;
/* clang-format off */
#if !defined(GPU_INTEL) && !defined(GPU_DEPRECATED_AMD_DRIVER) && !defined(OS_MAC) && !defined(INSTANCED_ATTR)
/* clang-format on */
/* Temporary until we fully make the switch. */
# ifndef DRW_SHADER_SHARED_H
struct ObjectMatrices {
mat4 drw_modelMatrix;
mat4 drw_modelMatrixInverse;
@ -150,17 +158,23 @@ layout(std140) uniform modelBlock
{
ObjectMatrices drw_matrices[DRW_RESOURCE_CHUNK_LEN];
};
# endif /* DRW_SHADER_SHARED_H */
# define ModelMatrix (drw_matrices[resource_id].drw_modelMatrix)
# define ModelMatrixInverse (drw_matrices[resource_id].drw_modelMatrixInverse)
#else /* GPU_INTEL */
/* Temporary until we fully make the switch. */
# ifndef DRW_SHADER_SHARED_H
/* Intel GPU seems to suffer performance impact when the model matrix is in UBO storage.
* So for now we just force using the legacy path. */
/* Note that this is also a workaround of a problem on osx (amd or nvidia)
* and older amd driver on windows. */
uniform mat4 ModelMatrix;
uniform mat4 ModelMatrixInverse;
# endif /* DRW_SHADER_SHARED_H */
#endif
#define resource_handle (resourceChunk * DRW_RESOURCE_CHUNK_LEN + resource_id)

View File

@ -0,0 +1,8 @@
#include "gpu_shader_create_info.hh"
GPU_SHADER_INTERFACE_INFO(fullscreen_iface, "").smooth(Type::VEC4, "uvcoordsvar");
GPU_SHADER_CREATE_INFO(draw_fullscreen)
.vertex_out(fullscreen_iface)
.vertex_source("common_fullscreen_vert.glsl");

View File

@ -0,0 +1,5 @@
#include "gpu_shader_create_info.hh"
GPU_SHADER_CREATE_INFO(draw_object_infos)
.uniform_buf(1, "ObjectInfos", "drw_infos[DRW_RESOURCE_CHUNK_LEN]", Frequency::BATCH);

View File

@ -0,0 +1,40 @@
#include "gpu_shader_create_info.hh"
/* -------------------------------------------------------------------- */
/** \name Draw View
* \{ */
GPU_SHADER_CREATE_INFO(draw_view)
.uniform_buf(0, "ViewInfos", "drw_view", Frequency::PASS)
.typedef_source("draw_shader_shared.h");
GPU_SHADER_CREATE_INFO(draw_view_instanced_attr)
.push_constant(0, Type::MAT4, "ModelMatrix")
.push_constant(16, Type::MAT4, "ModelMatrixInverse")
.additional_info("draw_view");
/** \} */
/* -------------------------------------------------------------------- */
/** \name Geometry Type
* \{ */
GPU_SHADER_CREATE_INFO(draw_mesh)
.uniform_buf(8, "ObjectMatrices", "drw_matrices[DRW_RESOURCE_CHUNK_LEN]", Frequency::BATCH)
.additional_info("draw_view");
GPU_SHADER_CREATE_INFO(draw_hair)
/* TODO(fclem) Finish */
.uniform_buf(8, "ObjectMatrices", "drw_matrices[DRW_RESOURCE_CHUNK_LEN]", Frequency::BATCH)
.additional_info("draw_view");
GPU_SHADER_CREATE_INFO(draw_pointcloud)
.vertex_in(0, Type::VEC4, "pos")
.vertex_in(1, Type::VEC3, "pos_inst")
.vertex_in(2, Type::VEC3, "nor")
.define("UNIFORM_RESOURCE_ID")
.define("INSTANCED_ATTR")
.additional_info("draw_view_instanced_attr");
/** \} */

View File

@ -61,9 +61,12 @@
#include "WM_api.h"
#include "GPU_batch.h"
#include "GPU_immediate.h"
#include "GPU_matrix.h"
#include "GPU_shader_shared.h"
#include "GPU_state.h"
#include "GPU_uniform_buffer.h"
#include "ED_gpencil.h"
#include "ED_screen.h"
@ -189,21 +192,27 @@ static void gpencil_draw_stroke_3d(tGPDdraw *tgpw,
};
immBindBuiltinProgram(GPU_SHADER_GPENCIL_STROKE);
immUniform2fv("Viewport", viewport);
immUniform1f("pixsize", tgpw->rv3d->pixsize);
float obj_scale = tgpw->ob ?
(tgpw->ob->scale[0] + tgpw->ob->scale[1] + tgpw->ob->scale[2]) / 3.0f :
1.0f;
immUniform1f("objscale", obj_scale);
struct GPencilStrokeData gpencil_stroke_data;
copy_v2_v2(gpencil_stroke_data.viewport, viewport);
gpencil_stroke_data.pixsize = tgpw->rv3d->pixsize;
gpencil_stroke_data.objscale = obj_scale;
int keep_size = (int)((tgpw->gpd) && (tgpw->gpd->flag & GP_DATA_STROKE_KEEPTHICKNESS));
immUniform1i("keep_size", keep_size);
immUniform1f("pixfactor", tgpw->gpd->pixfactor);
gpencil_stroke_data.keep_size = keep_size;
gpencil_stroke_data.pixfactor = tgpw->gpd->pixfactor;
/* xray mode always to 3D space to avoid wrong zdepth calculation (T60051) */
immUniform1i("xraymode", GP_XRAY_3DSPACE);
immUniform1i("caps_start", (int)tgpw->gps->caps[0]);
immUniform1i("caps_end", (int)tgpw->gps->caps[1]);
immUniform1i("fill_stroke", (int)tgpw->is_fill_stroke);
gpencil_stroke_data.xraymode = GP_XRAY_3DSPACE;
gpencil_stroke_data.caps_start = tgpw->gps->caps[0];
gpencil_stroke_data.caps_end = tgpw->gps->caps[1];
gpencil_stroke_data.fill_stroke = tgpw->is_fill_stroke;
GPUUniformBuf *ubo = GPU_uniformbuf_create_ex(
sizeof(struct GPencilStrokeData), &gpencil_stroke_data, __func__);
immBindUniformBuf("gpencil_stroke_data", ubo);
/* draw stroke curve */
immBeginAtMost(GPU_PRIM_LINE_STRIP_ADJ, totpoints + cyclic_add + 2);
@ -255,6 +264,8 @@ static void gpencil_draw_stroke_3d(tGPDdraw *tgpw,
immEnd();
immUnbindProgram();
GPU_uniformbuf_free(ubo);
}
/* ----- Strokes Drawing ------ */

View File

@ -57,6 +57,7 @@
#include "GPU_immediate.h"
#include "GPU_immediate_util.h"
#include "GPU_matrix.h"
#include "GPU_shader_shared.h"
#include "GPU_state.h"
#include "UI_interface.h"
@ -1384,10 +1385,16 @@ void ui_draw_but_UNITVEC(uiBut *but,
GPU_matrix_scale_1f(size);
GPUBatch *sphere = GPU_batch_preset_sphere(2);
struct SimpleLightingData simple_lighting_data;
copy_v4_fl4(simple_lighting_data.color, diffuse[0], diffuse[1], diffuse[2], 1.0f);
copy_v3_v3(simple_lighting_data.light, light);
GPUUniformBuf *ubo = GPU_uniformbuf_create_ex(
sizeof(struct SimpleLightingData), &simple_lighting_data, __func__);
GPU_batch_program_set_builtin(sphere, GPU_SHADER_SIMPLE_LIGHTING);
GPU_batch_uniform_4f(sphere, "color", diffuse[0], diffuse[1], diffuse[2], 1.0f);
GPU_batch_uniform_3fv(sphere, "light", light);
GPU_batch_uniformbuf_bind(sphere, "simple_lighting_data", ubo);
GPU_batch_draw(sphere);
GPU_uniformbuf_free(ubo);
/* Restore. */
GPU_face_culling(GPU_CULL_NONE);

View File

@ -51,7 +51,9 @@
#include "GPU_immediate.h"
#include "GPU_matrix.h"
#include "GPU_platform.h"
#include "GPU_shader_shared.h"
#include "GPU_state.h"
#include "GPU_uniform_buffer.h"
#include "DRW_engine.h"
@ -1873,23 +1875,29 @@ static void nodelink_batch_draw(const SpaceNode &snode)
}
GPU_blend(GPU_BLEND_ALPHA);
NodeLinkInstanceData node_link_data;
float colors[6][4] = {{0.0f}};
UI_GetThemeColor4fv(TH_WIRE_INNER, colors[nodelink_get_color_id(TH_WIRE_INNER)]);
UI_GetThemeColor4fv(TH_WIRE, colors[nodelink_get_color_id(TH_WIRE)]);
UI_GetThemeColor4fv(TH_ACTIVE, colors[nodelink_get_color_id(TH_ACTIVE)]);
UI_GetThemeColor4fv(TH_EDGE_SELECT, colors[nodelink_get_color_id(TH_EDGE_SELECT)]);
UI_GetThemeColor4fv(TH_REDALERT, colors[nodelink_get_color_id(TH_REDALERT)]);
UI_GetThemeColor4fv(TH_WIRE_INNER, node_link_data.colors[nodelink_get_color_id(TH_WIRE_INNER)]);
UI_GetThemeColor4fv(TH_WIRE, node_link_data.colors[nodelink_get_color_id(TH_WIRE)]);
UI_GetThemeColor4fv(TH_ACTIVE, node_link_data.colors[nodelink_get_color_id(TH_ACTIVE)]);
UI_GetThemeColor4fv(TH_EDGE_SELECT,
node_link_data.colors[nodelink_get_color_id(TH_EDGE_SELECT)]);
UI_GetThemeColor4fv(TH_REDALERT, node_link_data.colors[nodelink_get_color_id(TH_REDALERT)]);
node_link_data.expandSize = snode.runtime->aspect * LINK_WIDTH;
node_link_data.arrowSize = ARROW_SIZE;
GPUUniformBuf *ubo = GPU_uniformbuf_create_ex(sizeof(node_link_data), &node_link_data, __func__);
GPU_vertbuf_data_len_set(g_batch_link.inst_vbo, g_batch_link.count);
GPU_vertbuf_use(g_batch_link.inst_vbo); /* force update. */
GPU_batch_program_set_builtin(g_batch_link.batch, GPU_SHADER_2D_NODELINK_INST);
GPU_batch_uniform_4fv_array(g_batch_link.batch, "colors", 6, colors);
GPU_batch_uniform_1f(g_batch_link.batch, "expandSize", snode.runtime->aspect * LINK_WIDTH);
GPU_batch_uniform_1f(g_batch_link.batch, "arrowSize", ARROW_SIZE);
GPU_batch_uniformbuf_bind(g_batch_link.batch, "node_link_data", ubo);
GPU_batch_draw(g_batch_link.batch);
GPU_uniformbuf_unbind(ubo);
GPU_uniformbuf_free(ubo);
nodelink_batch_reset();
GPU_blend(GPU_BLEND_NONE);
@ -2060,19 +2068,32 @@ void node_draw_link_bezier(const bContext &C,
copy_v4_v4(colors[2], link_preselection_highlight_color);
}
NodeLinkData node_link_data;
for (int i = 0; i < 4; i++) {
copy_v2_v2(node_link_data.bezierPts[i], vec[i]);
}
for (int i = 0; i < 3; i++) {
copy_v2_v2(node_link_data.colors[i], colors[i]);
}
node_link_data.doArrow = drawarrow;
node_link_data.doMuted = drawmuted;
node_link_data.dim_factor = dim_factor;
node_link_data.thickness = thickness;
node_link_data.dash_factor = dash_factor;
node_link_data.dash_alpha = dash_alpha;
node_link_data.expandSize = snode.runtime->aspect * LINK_WIDTH;
node_link_data.arrowSize = ARROW_SIZE;
GPUBatch *batch = g_batch_link.batch_single;
GPUUniformBuf *ubo = GPU_uniformbuf_create_ex(
sizeof(node_link_data), &node_link_data, __func__);
GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_NODELINK);
GPU_batch_uniform_2fv_array(batch, "bezierPts", 4, vec);
GPU_batch_uniform_4fv_array(batch, "colors", 3, colors);
GPU_batch_uniform_1f(batch, "expandSize", snode.runtime->aspect * LINK_WIDTH);
GPU_batch_uniform_1f(batch, "arrowSize", ARROW_SIZE);
GPU_batch_uniform_1i(batch, "doArrow", drawarrow);
GPU_batch_uniform_1i(batch, "doMuted", drawmuted);
GPU_batch_uniform_1f(batch, "dim_factor", dim_factor);
GPU_batch_uniform_1f(batch, "thickness", thickness);
GPU_batch_uniform_1f(batch, "dash_factor", dash_factor);
GPU_batch_uniform_1f(batch, "dash_alpha", dash_alpha);
GPU_batch_uniformbuf_bind(batch, "node_link_data", ubo);
GPU_batch_draw(batch);
GPU_uniformbuf_unbind(ubo);
GPU_uniformbuf_free(ubo);
}
}
}

View File

@ -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)
set(GLSL_SRC
GPU_shader_shared.h
data_to_c_simple(shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl SRC)
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
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)
shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl
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)
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
data_to_c_simple(shaders/gpu_shader_codegen_lib.glsl SRC)
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
data_to_c_simple(shaders/gpu_shader_geometry.glsl SRC)
shaders/gpu_shader_codegen_lib.glsl
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)
shaders/gpu_shader_geometry.glsl
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)
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
data_to_c_simple(shaders/gpu_shader_cfg_world_clip_lib.glsl SRC)
data_to_c_simple(shaders/gpu_shader_colorspace_lib.glsl SRC)
shaders/gpu_shader_gpencil_stroke_vert.glsl
shaders/gpu_shader_gpencil_stroke_frag.glsl
shaders/gpu_shader_gpencil_stroke_geom.glsl
data_to_c_simple(shaders/gpu_shader_common_obinfos_lib.glsl SRC)
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 $<$<COMPILE_LANGUAGE:CXX>:-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
"$<TARGET_FILE:shader_builder>" ${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

View File

@ -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. */

View File

@ -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;

View File

@ -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)

View File

@ -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)

View File

@ -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;
}

View File

@ -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 <string>
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<const char *> &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<const ShaderCreateInfo *>(_info);
const_cast<ShaderCreateInfo &>(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<char *> 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<const char *> 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<const char *> 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<const char *> 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<const char *> 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,

View File

@ -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 <iostream>
#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 <data_file_to>\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;
}

View File

@ -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();
}
/** \} */
}

View File

@ -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);

View File

@ -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<StringRef, ShaderCreateInfo *>;
using InterfaceDictionnary = Map<StringRef, StageInterfaceInfo *>;
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<const ShaderCreateInfo *>(
gpu_shader_create_info_get(info_name.c_str()));
/* Recursive. */
const_cast<ShaderCreateInfo &>(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<const GPUShaderCreateInfo *>(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<const GPUShaderCreateInfo *>(info);
}

View File

@ -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<InOut> 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<VertIn> 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<FragOut> 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<Resource> pass_resources_, batch_resources_;
Vector<StageInterfaceInfo *> vertex_out_interfaces_;
Vector<StageInterfaceInfo *> geometry_out_interfaces_;
struct PushConst {
int index;
Type type;
StringRefNull name;
int array_size;
};
Vector<PushConst> push_constants_;
/* Sources for resources type definitions. */
Vector<StringRefNull> typedef_sources_;
StringRefNull vertex_source_, geometry_source_, fragment_source_, compute_source_;
Vector<std::array<StringRefNull, 2>> defines_;
/**
* Name of other infos to recursively merge with this one.
* No data slot must overlap otherwise we throw an error.
*/
Vector<StringRefNull> 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

View File

@ -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

View File

@ -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 <iostream>
#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<StringRef, struct GPUSource *>;
struct GPUSource {
StringRefNull filename;
StringRefNull source;
Vector<GPUSource *> 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());
}

View File

@ -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

View File

@ -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.
*/

View File

@ -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

View File

@ -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 <string>
namespace blender {
namespace gpu {
@ -53,7 +56,7 @@ class Shader {
virtual void geometry_shader_from_glsl(MutableSpan<const char *> sources) = 0;
virtual void fragment_shader_from_glsl(MutableSpan<const char *> sources) = 0;
virtual void compute_shader_from_glsl(MutableSpan<const char *> sources) = 0;
virtual bool finalize() = 0;
virtual bool finalize(const shader::ShaderCreateInfo *info = nullptr) = 0;
virtual void transform_feedback_names_set(Span<const char *> 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;

View File

@ -0,0 +1,105 @@
/*
* 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_float4x4.hh"
# include "BLI_float4x4.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

View File

@ -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;

View File

@ -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;

View File

@ -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<StageInterfaceInfo *> &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<const char *> 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;
}

View File

@ -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<const char *> sources) override;
void fragment_shader_from_glsl(MutableSpan<const char *> sources) override;
void compute_shader_from_glsl(MutableSpan<const char *> 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<const char *> name_list,

View File

@ -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<ShaderCreateInfo::Resource> 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<GPUUniformBuiltin>(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<GPUUniformBlockBuiltin>(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_) {

View File

@ -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<GLVaoCache *> refs_;
public:
GLShaderInterface(GLuint program, const shader::ShaderCreateInfo &info);
GLShaderInterface(GLuint program);
~GLShaderInterface();

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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

View File

@ -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 */

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -1,6 +1,7 @@
#ifndef USE_GPU_SHADER_CREATE_INFO
noperspective in vec4 finalColor;
out vec4 fragColor;
#endif
void main()
{

View File

@ -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()
{

View File

@ -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()

View File

@ -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)
{

View File

@ -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)

View File

@ -1,9 +1,11 @@
#ifndef USE_GPU_SHADER_CREATE_INFO
in float shadowFalloff;
out vec4 fragColor;
uniform float alpha;
#endif
void main()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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
}

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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
}

View File

@ -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()
{

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -1,6 +1,7 @@
#ifndef USE_GPU_SHADER_CREATE_INFO
in vec4 finalColor;
out vec4 fragColor;
#endif
void main()
{

View File

@ -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
}

View File

@ -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
}

View File

@ -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) \

View File

@ -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()
{

View File

@ -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)
{

View File

@ -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)

View File

@ -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()
{

View File

@ -1,6 +1,7 @@
#ifndef USE_GPU_SHADER_CREATE_INFO
flat in vec4 finalColor;
out vec4 fragColor;
#endif
void main()
{

View File

@ -1,6 +1,7 @@
#ifndef USE_GPU_SHADER_CREATE_INFO
flat in vec4 finalColor;
out vec4 fragColor;
#endif
void main()
{

View File

@ -1,6 +1,7 @@
#ifndef USE_GPU_SHADER_CREATE_INFO
flat in uint finalId;
out uint fragId;
#endif
void main()
{

View File

@ -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
{

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -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()
{

View File

@ -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()
{

Some files were not shown because too many files have changed in this diff Show More