From 46bd0370767d993fff2d0037f7615530b5199d98 Mon Sep 17 00:00:00 2001 From: Weizhen Huang Date: Tue, 7 Feb 2023 18:46:14 +0100 Subject: [PATCH 01/11] Gizmo: press shift key to scale area lights uniformly --- source/blender/editors/space_view3d/view3d_gizmo_light.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/space_view3d/view3d_gizmo_light.c b/source/blender/editors/space_view3d/view3d_gizmo_light.c index f3db63b9a20..bdc5bd9b792 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_light.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_light.c @@ -468,7 +468,8 @@ static void WIDGETGROUP_light_area_refresh(const bContext *C, wmGizmoGroup *gzgr copy_m4_m4(gz->matrix_basis, ob->object_to_world); int flag = ED_GIZMO_CAGE_XFORM_FLAG_SCALE; - if (ELEM(la->area_shape, LA_AREA_SQUARE, LA_AREA_DISK)) { + const wmEvent *event = CTX_wm_window(C)->eventstate; + if (ELEM(la->area_shape, LA_AREA_SQUARE, LA_AREA_DISK) || (event->modifier & KM_SHIFT)) { flag |= ED_GIZMO_CAGE_XFORM_FLAG_SCALE_UNIFORM; } RNA_enum_set(gz->ptr, "transform", flag); -- 2.30.2 From 0c87ff3de55c2f86d5f8f5d923ae819826cf590b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Sun, 12 Feb 2023 16:09:23 +0100 Subject: [PATCH 02/11] GPU: Move gpu_shader_builtin.c to C++ This also removes all unused part of it now that we have converted all shaders to use create infos. --- source/blender/gpu/CMakeLists.txt | 2 +- ...shader_builtin.c => gpu_shader_builtin.cc} | 162 ++---------------- 2 files changed, 18 insertions(+), 146 deletions(-) rename source/blender/gpu/intern/{gpu_shader_builtin.c => gpu_shader_builtin.cc} (55%) diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 623dd899717..4f207fd7572 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -70,7 +70,7 @@ set(SRC intern/gpu_select_pick.c intern/gpu_select_sample_query.cc intern/gpu_shader.cc - intern/gpu_shader_builtin.c + intern/gpu_shader_builtin.cc intern/gpu_shader_create_info.cc intern/gpu_shader_dependency.cc intern/gpu_shader_interface.cc diff --git a/source/blender/gpu/intern/gpu_shader_builtin.c b/source/blender/gpu/intern/gpu_shader_builtin.cc similarity index 55% rename from source/blender/gpu/intern/gpu_shader_builtin.c rename to source/blender/gpu/intern/gpu_shader_builtin.cc index 470643ba863..a2f4addf36d 100644 --- a/source/blender/gpu/intern/gpu_shader_builtin.c +++ b/source/blender/gpu/intern/gpu_shader_builtin.cc @@ -9,109 +9,13 @@ #include "GPU_shader.h" -/* Adjust these constants as needed. */ -#define MAX_DEFINE_LENGTH 256 -#define MAX_EXT_DEFINE_LENGTH 512 - -/* Non-generated shaders */ -extern char datatoc_gpu_shader_depth_only_frag_glsl[]; -extern char datatoc_gpu_shader_uniform_color_frag_glsl[]; -extern char datatoc_gpu_shader_checker_frag_glsl[]; -extern char datatoc_gpu_shader_diag_stripes_frag_glsl[]; -extern char datatoc_gpu_shader_simple_lighting_frag_glsl[]; -extern char datatoc_gpu_shader_flat_color_frag_glsl[]; -extern char datatoc_gpu_shader_flat_color_alpha_test_0_frag_glsl[]; -extern char datatoc_gpu_shader_flat_id_frag_glsl[]; -extern char datatoc_gpu_shader_2D_area_borders_vert_glsl[]; -extern char datatoc_gpu_shader_2D_area_borders_frag_glsl[]; -extern char datatoc_gpu_shader_2D_vert_glsl[]; -extern char datatoc_gpu_shader_2D_smooth_color_uniform_alpha_vert_glsl[]; -extern char datatoc_gpu_shader_2D_image_vert_glsl[]; -extern char datatoc_gpu_shader_2D_image_rect_vert_glsl[]; -extern char datatoc_gpu_shader_2D_image_multi_rect_vert_glsl[]; -extern char datatoc_gpu_shader_2D_widget_base_vert_glsl[]; -extern char datatoc_gpu_shader_2D_widget_base_frag_glsl[]; -extern char datatoc_gpu_shader_2D_widget_shadow_vert_glsl[]; -extern char datatoc_gpu_shader_2D_widget_shadow_frag_glsl[]; -extern char datatoc_gpu_shader_2D_nodelink_frag_glsl[]; -extern char datatoc_gpu_shader_2D_nodelink_vert_glsl[]; - -extern char datatoc_gpu_shader_3D_image_vert_glsl[]; -extern char datatoc_gpu_shader_image_frag_glsl[]; -extern char datatoc_gpu_shader_image_overlays_merge_frag_glsl[]; -extern char datatoc_gpu_shader_image_overlays_stereo_merge_frag_glsl[]; -extern char datatoc_gpu_shader_image_color_frag_glsl[]; -extern char datatoc_gpu_shader_image_desaturate_frag_glsl[]; -extern char datatoc_gpu_shader_image_modulate_alpha_frag_glsl[]; -extern char datatoc_gpu_shader_image_varying_color_frag_glsl[]; -extern char datatoc_gpu_shader_image_shuffle_color_frag_glsl[]; -extern char datatoc_gpu_shader_3D_vert_glsl[]; -extern char datatoc_gpu_shader_3D_normal_vert_glsl[]; -extern char datatoc_gpu_shader_3D_flat_color_vert_glsl[]; -extern char datatoc_gpu_shader_3D_polyline_frag_glsl[]; -extern char datatoc_gpu_shader_3D_polyline_geom_glsl[]; -extern char datatoc_gpu_shader_3D_polyline_vert_glsl[]; -extern char datatoc_gpu_shader_3D_smooth_color_vert_glsl[]; -extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[]; -extern char datatoc_gpu_shader_3D_passthrough_vert_glsl[]; -extern char datatoc_gpu_shader_3D_clipped_uniform_color_vert_glsl[]; - -extern char datatoc_gpu_shader_instance_variying_size_variying_color_vert_glsl[]; - -extern char datatoc_gpu_shader_point_uniform_color_aa_frag_glsl[]; -extern char datatoc_gpu_shader_point_uniform_color_outline_aa_frag_glsl[]; -extern char datatoc_gpu_shader_point_varying_color_varying_outline_aa_frag_glsl[]; -extern char datatoc_gpu_shader_point_varying_color_frag_glsl[]; -extern char datatoc_gpu_shader_3D_point_fixed_size_varying_color_vert_glsl[]; -extern char datatoc_gpu_shader_3D_point_varying_size_varying_color_vert_glsl[]; -extern char datatoc_gpu_shader_3D_point_uniform_size_aa_vert_glsl[]; -extern char datatoc_gpu_shader_2D_point_uniform_size_aa_vert_glsl[]; -extern char datatoc_gpu_shader_2D_point_uniform_size_outline_aa_vert_glsl[]; - -extern char datatoc_gpu_shader_2D_line_dashed_uniform_color_vert_glsl[]; -extern char datatoc_gpu_shader_2D_line_dashed_frag_glsl[]; -extern char datatoc_gpu_shader_3D_line_dashed_uniform_color_vert_glsl[]; - -extern char datatoc_gpu_shader_text_vert_glsl[]; -extern char datatoc_gpu_shader_text_frag_glsl[]; -extern char datatoc_gpu_shader_keyframe_shape_vert_glsl[]; -extern char datatoc_gpu_shader_keyframe_shape_frag_glsl[]; - -extern char datatoc_gpu_shader_gpencil_stroke_vert_glsl[]; -extern char datatoc_gpu_shader_gpencil_stroke_frag_glsl[]; -extern char datatoc_gpu_shader_gpencil_stroke_geom_glsl[]; - -extern char datatoc_gpu_shader_cfg_world_clip_lib_glsl[]; - -extern char datatoc_gpu_shader_colorspace_lib_glsl[]; - -const struct GPUShaderConfigData GPU_shader_cfg_data[GPU_SHADER_CFG_LEN] = { - [GPU_SHADER_CFG_DEFAULT] = - { - .lib = "", - .def = "#define blender_srgb_to_framebuffer_space(a) a\n", - }, - [GPU_SHADER_CFG_CLIPPED] = - { - .lib = datatoc_gpu_shader_cfg_world_clip_lib_glsl, - .def = "#define USE_WORLD_CLIP_PLANES\n" - "#define blender_srgb_to_framebuffer_space(a) a\n", - }, -}; - -/* cache of built-in shaders (each is created on first use) */ -static GPUShader *builtin_shaders[GPU_SHADER_CFG_LEN][GPU_SHADER_BUILTIN_LEN] = {{NULL}}; +/* Cache of built-in shaders (each is created on first use). */ +static GPUShader *builtin_shaders[GPU_SHADER_CFG_LEN][GPU_SHADER_BUILTIN_LEN] = {{nullptr}}; typedef struct { const char *name; - const char *vert; - /** Optional. */ - const char *geom; - const char *frag; - /** Optional. */ - const char *defs; - const char *create_info; + /** Optional. */ const char *clipped_create_info; } GPUShaderStages; @@ -287,7 +191,6 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = { [GPU_SHADER_2D_WIDGET_BASE_INST] = { .name = "GPU_SHADER_2D_WIDGET_BASE_INST", - .defs = "#define USE_INSTANCE\n", .create_info = "gpu_shader_2D_widget_base_inst", }, [GPU_SHADER_2D_WIDGET_SHADOW] = @@ -321,61 +224,30 @@ GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader, BLI_assert(sh_cfg < GPU_SHADER_CFG_LEN); GPUShader **sh_p = &builtin_shaders[sh_cfg][shader]; - if (*sh_p == NULL) { + if (*sh_p == nullptr) { const GPUShaderStages *stages = &builtin_shader_stages[shader]; /* common case */ if (sh_cfg == GPU_SHADER_CFG_DEFAULT) { - if (stages->create_info != NULL) { - *sh_p = GPU_shader_create_from_info_name(stages->create_info); - if (ELEM(shader, - GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR, - GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR, - GPU_SHADER_3D_POLYLINE_FLAT_COLOR, - GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR)) { - /* Set a default value for `lineSmooth`. - * Ideally this value should be set by the caller. */ - GPU_shader_bind(*sh_p); - GPU_shader_uniform_1i(*sh_p, "lineSmooth", 1); - } - } - 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}, - }); + *sh_p = GPU_shader_create_from_info_name(stages->create_info); + if (ELEM(shader, + GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR, + GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR, + GPU_SHADER_3D_POLYLINE_FLAT_COLOR, + GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR)) { + /* Set a default value for `lineSmooth`. + * Ideally this value should be set by the caller. */ + GPU_shader_bind(*sh_p); + GPU_shader_uniform_1i(*sh_p, "lineSmooth", 1); } } else if (sh_cfg == GPU_SHADER_CFG_CLIPPED) { - /* Remove eventually, for now ensure support for each shader has been added. */ - BLI_assert(ELEM(shader, - GPU_SHADER_3D_UNIFORM_COLOR, - GPU_SHADER_3D_SMOOTH_COLOR, - GPU_SHADER_3D_DEPTH_ONLY, - GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA, - GPU_SHADER_3D_FLAT_COLOR, - GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR)); /* In rare cases geometry shaders calculate clipping themselves. */ - if (stages->clipped_create_info != NULL) { + if (stages->clipped_create_info != nullptr) { *sh_p = GPU_shader_create_from_info_name(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}, - }); + BLI_assert_msg(0, "Shader doesn't support clip mode."); } } else { @@ -397,7 +269,7 @@ void GPU_shader_free_builtin_shaders(void) for (int j = 0; j < GPU_SHADER_BUILTIN_LEN; j++) { if (builtin_shaders[i][j]) { GPU_shader_free(builtin_shaders[i][j]); - builtin_shaders[i][j] = NULL; + builtin_shaders[i][j] = nullptr; } } } -- 2.30.2 From 4099f24817e07b53824cc675f67bde8deb6ba1f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Sun, 12 Feb 2023 17:20:18 +0100 Subject: [PATCH 03/11] GPU: Remove GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR This replaces `GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR` by GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA`. None of the usage made sense to not use the AA shader. Scale the point size to account for the rounded shape. --- source/blender/editors/gpencil/gpencil_fill.c | 4 ++-- .../blender/editors/sculpt_paint/curves_sculpt_ops.cc | 5 ++--- source/blender/editors/space_view3d/view3d_draw.cc | 4 ++-- source/blender/gpu/CMakeLists.txt | 1 - source/blender/gpu/GPU_shader.h | 8 -------- source/blender/gpu/intern/gpu_shader_builtin.cc | 5 ----- ..._shader_3D_point_fixed_size_varying_color_vert.glsl | 6 ------ .../gpu/shaders/infos/gpu_shader_3D_point_info.hh | 10 ---------- source/blender/gpu/tests/gpu_shader_builtin_test.cc | 2 -- 9 files changed, 6 insertions(+), 39 deletions(-) delete mode 100644 source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c index 0401fdfc963..7f8ff54cc12 100644 --- a/source/blender/editors/gpencil/gpencil_fill.c +++ b/source/blender/editors/gpencil/gpencil_fill.c @@ -1003,8 +1003,8 @@ static void draw_mouse_position(tGPDfill *tgpf) uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT); /* Draw mouse click position in Blue. */ - immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR); - GPU_point_size(point_size); + immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA); + immUniform1f("size", point_size * M_SQRT2); immBegin(GPU_PRIM_POINTS, 1); immAttr4ubv(col, mouse_color); immVertex3fv(pos, &pt->x); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc index 89f0f9031df..54bef8d2257 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc @@ -966,9 +966,8 @@ static void min_distance_edit_draw(bContext *C, int /*x*/, int /*y*/, void *cust const uint pos3d = GPU_vertformat_attr_add(format3d, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); const uint col3d = GPU_vertformat_attr_add(format3d, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR); - - GPU_point_size(3.0f); + immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA); + immUniform1f("size", 4.0f); immBegin(GPU_PRIM_POINTS, points_wo.size()); float3 brush_origin_wo = math::transform_point(op_data.curves_to_world_mat, op_data.pos_cu); diff --git a/source/blender/editors/space_view3d/view3d_draw.cc b/source/blender/editors/space_view3d/view3d_draw.cc index 7018fa16fe6..b50721a22c5 100644 --- a/source/blender/editors/space_view3d/view3d_draw.cc +++ b/source/blender/editors/space_view3d/view3d_draw.cc @@ -1104,8 +1104,8 @@ static void draw_rotation_guide(const RegionView3D *rv3d) immUnbindProgram(); /* -- draw rotation center -- */ - immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR); - GPU_point_size(5.0f); + immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA); + immUniform1f("size", 7.0f); immBegin(GPU_PRIM_POINTS, 1); immAttr4ubv(col, color); immVertex3fv(pos, o); diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 4f207fd7572..2f345ec6a90 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -377,7 +377,6 @@ set(GLSL_SRC 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 diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index 3cf64edaa6e..48cbc13b530 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -322,14 +322,6 @@ typedef enum eGPUBuiltinShader { * \param pos: in vec2 */ GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA, - /** - * Draw round points with a hardcoded size. - * Take a single color for all the vertices and a 3D position for each vertex. - * - * \param color: uniform vec4 - * \param pos: in vec3 - */ - GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR, /** * Draw round points with a constant size. * Take a single color for all the vertices and a 3D position for each vertex. diff --git a/source/blender/gpu/intern/gpu_shader_builtin.cc b/source/blender/gpu/intern/gpu_shader_builtin.cc index a2f4addf36d..03c3702c08b 100644 --- a/source/blender/gpu/intern/gpu_shader_builtin.cc +++ b/source/blender/gpu/intern/gpu_shader_builtin.cc @@ -161,11 +161,6 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = { .name = "GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA", .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", - .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", diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl deleted file mode 100644 index a43c1aa40cf..00000000000 --- a/source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl +++ /dev/null @@ -1,6 +0,0 @@ - -void main() -{ - gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); - finalColor = color; -} diff --git a/source/blender/gpu/shaders/infos/gpu_shader_3D_point_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_3D_point_info.hh index c71d7cf632a..e7a4705761f 100644 --- a/source/blender/gpu/shaders/infos/gpu_shader_3D_point_info.hh +++ b/source/blender/gpu/shaders/infos/gpu_shader_3D_point_info.hh @@ -7,16 +7,6 @@ #include "gpu_shader_create_info.hh" -GPU_SHADER_CREATE_INFO(gpu_shader_3D_point_fixed_size_varying_color) - .vertex_in(0, Type::VEC3, "pos") - .vertex_in(1, Type::VEC4, "color") - .vertex_out(smooth_color_iface) - .fragment_out(0, Type::VEC4, "fragColor") - .push_constant(Type::MAT4, "ModelViewProjectionMatrix") - .vertex_source("gpu_shader_3D_point_fixed_size_varying_color_vert.glsl") - .fragment_source("gpu_shader_point_varying_color_frag.glsl") - .do_static_compilation(true); - GPU_SHADER_CREATE_INFO(gpu_shader_3D_point_varying_size_varying_color) .vertex_in(0, Type::VEC3, "pos") .vertex_in(1, Type::VEC4, "color") diff --git a/source/blender/gpu/tests/gpu_shader_builtin_test.cc b/source/blender/gpu/tests/gpu_shader_builtin_test.cc index 567f1370f00..bb3f9f1a2ae 100644 --- a/source/blender/gpu/tests/gpu_shader_builtin_test.cc +++ b/source/blender/gpu/tests/gpu_shader_builtin_test.cc @@ -52,8 +52,6 @@ static void test_shader_builtin() GPU_SHADER_CFG_DEFAULT); test_compile_builtin_shader(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA, GPU_SHADER_CFG_DEFAULT); - test_compile_builtin_shader(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR, - GPU_SHADER_CFG_DEFAULT); test_compile_builtin_shader(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR, GPU_SHADER_CFG_DEFAULT); test_compile_builtin_shader(GPU_SHADER_GPENCIL_STROKE, GPU_SHADER_CFG_DEFAULT); -- 2.30.2 From 589160d05c3e1201b43dd1551bbfffa2f18a0aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Sun, 12 Feb 2023 17:37:01 +0100 Subject: [PATCH 04/11] Cleanup: GPUShader: Split Builtins to their own header Also improve documentation and cleanup. --- source/blender/gpu/GPU_shader.h | 175 +----------------------- source/blender/gpu/GPU_shader_builtin.h | 147 ++++++++++++++++++++ 2 files changed, 149 insertions(+), 173 deletions(-) create mode 100644 source/blender/gpu/GPU_shader_builtin.h diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index 48cbc13b530..92c74234871 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -7,6 +7,8 @@ #pragma once +#include "GPU_shader_builtin.h" + #ifdef __cplusplus extern "C" { #endif @@ -202,179 +204,6 @@ bool GPU_shader_get_attribute_info(const GPUShader *shader, void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear); -/* Builtin/Non-generated shaders */ -typedef enum eGPUBuiltinShader { - /* specialized drawing */ - GPU_SHADER_TEXT, - GPU_SHADER_KEYFRAME_SHAPE, - GPU_SHADER_SIMPLE_LIGHTING, - /** - * Draw an icon, leaving a semi-transparent rectangle on top of the icon. - */ - GPU_SHADER_ICON, - /** - * Take a 2D position and color for each vertex with linear interpolation in window space. - * - * \param color: in vec4 - * \param pos: in vec2 - */ - GPU_SHADER_2D_IMAGE_DESATURATE_COLOR, - GPU_SHADER_2D_IMAGE_RECT_COLOR, - GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR, - GPU_SHADER_2D_CHECKER, - GPU_SHADER_2D_DIAG_STRIPES, - /* for simple 3D drawing */ - /** - * Take a single color for all the vertices and a 3D position for each vertex. - * - * \param color: uniform vec4 - * \param pos: in vec3 - */ - GPU_SHADER_3D_UNIFORM_COLOR, - GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR, - /** - * Take a 3D position and color for each vertex without color interpolation. - * - * \param color: in vec4 - * \param pos: in vec3 - */ - GPU_SHADER_3D_FLAT_COLOR, - /** - * Take a 3D position and color for each vertex with perspective correct interpolation. - * - * \param color: in vec4 - * \param pos: in vec3 - */ - GPU_SHADER_3D_SMOOTH_COLOR, - /** - * Take a single color for all the vertices and a 3D position for each vertex. - * Used for drawing wide lines. - * - * \param color: uniform vec4 - * \param pos: in vec3 - */ - GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR, - GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR, - /** - * Take a 3D position and color for each vertex without color interpolation. - * Used for drawing wide lines. - * - * \param color: in vec4 - * \param pos: in vec3 - */ - GPU_SHADER_3D_POLYLINE_FLAT_COLOR, - /** - * Take a 3D position and color for each vertex with perspective correct interpolation. - * Used for drawing wide lines. - * - * \param color: in vec4 - * \param pos: in vec3 - */ - GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR, - /** - * Take a 3D position for each vertex and output only depth. - * Used for drawing wide lines. - * - * \param pos: in vec3 - */ - GPU_SHADER_3D_DEPTH_ONLY, - /* basic image drawing */ - GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE, - GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE, - GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR, - /** - * Draw a texture in 3D. Take a 3D position and a 2D texture coordinate for each vertex. - * - * Exposed via Python-API for add-ons. - * - * \param image: uniform sampler2D - * \param texCoord: in vec2 - * \param pos: in vec3 - */ - GPU_SHADER_3D_IMAGE, - /** - * Take a 3D position and color for each vertex with linear interpolation in window space. - * - * \param color: uniform vec4 - * \param image: uniform sampler2D - * \param texCoord: in vec2 - * \param pos: in vec3 - */ - GPU_SHADER_3D_IMAGE_COLOR, - /* points */ - /** - * Draw round points with a constant size. - * Take a single color for all the vertices and a 2D position for each vertex. - * - * \param size: uniform float - * \param color: uniform vec4 - * \param pos: in vec2 - */ - GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA, - /** - * Draw round points with a constant size and an outline. - * Take a single color for all the vertices and a 2D position for each vertex. - * - * \param size: uniform float - * \param outlineWidth: uniform float - * \param color: uniform vec4 - * \param outlineColor: uniform vec4 - * \param pos: in vec2 - */ - GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA, - /** - * Draw round points with a constant size. - * Take a single color for all the vertices and a 3D position for each vertex. - * - * \param size: uniform float - * \param color: uniform vec4 - * \param pos: in vec3 - */ - GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA, - /** - * Draw round points with a constant size and an outline. - * Take a 3D position and a color for each vertex. - * - * \param size: in float - * \param color: in vec4 - * \param pos: in vec3 - */ - GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR, - /* lines */ - GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR, - /* grease pencil drawing */ - GPU_SHADER_GPENCIL_STROKE, - /* specialized for widget drawing */ - GPU_SHADER_2D_AREA_BORDERS, - GPU_SHADER_2D_WIDGET_BASE, - GPU_SHADER_2D_WIDGET_BASE_INST, - GPU_SHADER_2D_WIDGET_SHADOW, - GPU_SHADER_2D_NODELINK, - GPU_SHADER_2D_NODELINK_INST, -} eGPUBuiltinShader; -#define GPU_SHADER_BUILTIN_LEN (GPU_SHADER_2D_NODELINK_INST + 1) - -/** Support multiple configurations. */ -typedef enum eGPUShaderConfig { - GPU_SHADER_CFG_DEFAULT = 0, - GPU_SHADER_CFG_CLIPPED = 1, -} eGPUShaderConfig; -#define GPU_SHADER_CFG_LEN (GPU_SHADER_CFG_CLIPPED + 1) - -typedef struct GPUShaderConfigData { - const char *lib; - const char *def; -} GPUShaderConfigData; -/* gpu_shader.c */ - -extern const GPUShaderConfigData GPU_shader_cfg_data[GPU_SHADER_CFG_LEN]; - -GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader, - eGPUShaderConfig sh_cfg); -GPUShader *GPU_shader_get_builtin_shader(eGPUBuiltinShader shader); - -void GPU_shader_free_builtin_shaders(void); - /* Vertex attributes for shaders */ /* Hardware limit is 16. Position attribute is always needed so we reduce to 15. diff --git a/source/blender/gpu/GPU_shader_builtin.h b/source/blender/gpu/GPU_shader_builtin.h new file mode 100644 index 00000000000..bd9fa9eb232 --- /dev/null +++ b/source/blender/gpu/GPU_shader_builtin.h @@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2023 Blender Foundation. All rights reserved. */ + +/** \file + * \ingroup gpu + * + * Set of shaders used for interface drawing. + * + * 2D shaders are not expected to work in 3D. + * 3D shaders can work with 2D geometry and matrices. + * + * `INST` suffix means instance, which means the shader is build to leverage instancing + * capabilities to reduce the number of draw-calls. + * + * For full list of parameters, search for the the associated #ShaderCreateInfo. + * Example: `GPU_SHADER_ICON` is defined by `GPU_SHADER_CREATE_INFO(gpu_shader_icon)` + * Some parameters are builtins and are set automatically (ex: `ModelViewProjectionMatrix`). + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +struct GPUShader; + +typedef enum eGPUBuiltinShader { + /** Glyph drawing shader used by the BLF module. */ + GPU_SHADER_TEXT, + /** Draws keyframe markers. All markers shapes are supported through a single shader. */ + GPU_SHADER_KEYFRAME_SHAPE, + /** Draw solid mesh with a single distant light using a clamped simple dot product. */ + GPU_SHADER_SIMPLE_LIGHTING, + /** Draw an icon, leaving a semi-transparent rectangle on top of the icon. */ + GPU_SHADER_ICON, + /** Draw a texture with a uniform color multiplied. */ + GPU_SHADER_2D_IMAGE_RECT_COLOR, + /** Draw a texture with a desaturation factor. */ + GPU_SHADER_2D_IMAGE_DESATURATE_COLOR, + /** Draw a group of texture rectangle with an associated color multiplied. */ + GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR, + /** Draw a two color checker based on screen position (not UV coordinates). */ + GPU_SHADER_2D_CHECKER, + /** Draw diagonal stripes with two alternating colors. */ + GPU_SHADER_2D_DIAG_STRIPES, + /** Draw dashed lines with custom dash length and uniform color. */ + GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR, + /** Draw triangles / lines / points with only depth output. */ + GPU_SHADER_3D_DEPTH_ONLY, + /** Merge viewport overlay texture with the render output. */ + GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE, + GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE, + /** Merge viewport overlay texture with the render output. */ + GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR, + /** Used for drawing of annotations (former grease pencil). */ + GPU_SHADER_GPENCIL_STROKE, + /** Draw rounded area borders with silky smooth anti-aliasing without any over-draw. */ + GPU_SHADER_2D_AREA_BORDERS, + /** Multi usage widget shaders for drawing buttons and other UI elements. */ + GPU_SHADER_2D_WIDGET_BASE, + GPU_SHADER_2D_WIDGET_BASE_INST, + GPU_SHADER_2D_WIDGET_SHADOW, + /** Draw a node link given an input quadratic Bezier curve. */ + GPU_SHADER_2D_NODELINK, + GPU_SHADER_2D_NODELINK_INST, + + /** Draw round points with per vertex size and color. */ + GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR, + /** Draw round points with a uniform size. Disabling blending will disable AA. */ + GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA, + GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA, + /** Draw round points with a uniform size and an outline. Disabling blending will disable AA. */ + GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA, + + /** Draw geometry with uniform color. Has an additional clip plane parameter. */ + GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR, + /** Draw wide lines with uniform color. Has an additional clip plane parameter. */ + GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR, + + /** + * ----------------------- Shaders exposed through pyGPU module ----------------------- + * + * Avoid breaking the interface of these shaders as they are used by addons. + * Polyline versions are used for drawing wide lines (> 1px width). + */ + + /** + * Take a 3D position and color for each vertex without color interpolation. + * + * \param color: in vec4 + * \param pos: in vec3 + */ + GPU_SHADER_3D_FLAT_COLOR, + GPU_SHADER_3D_POLYLINE_FLAT_COLOR, + /** + * Take a 3D position and color for each vertex with perspective correct interpolation. + * + * \param color: in vec4 + * \param pos: in vec3 + */ + GPU_SHADER_3D_SMOOTH_COLOR, + GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR, + /** + * Take a single color for all the vertices and a 3D position for each vertex. + * + * \param color: uniform vec4 + * \param pos: in vec3 + */ + GPU_SHADER_3D_UNIFORM_COLOR, + GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR, + /** + * Draw a texture in 3D. Take a 3D position and a 2D texture coordinate for each vertex. + * + * \param image: uniform sampler2D + * \param texCoord: in vec2 + * \param pos: in vec3 + */ + GPU_SHADER_3D_IMAGE, + /** + * Take a 3D position and color for each vertex with linear interpolation in window space. + * + * \param color: uniform vec4 + * \param image: uniform sampler2D + * \param texCoord: in vec2 + * \param pos: in vec3 + */ + GPU_SHADER_3D_IMAGE_COLOR, +} eGPUBuiltinShader; +#define GPU_SHADER_BUILTIN_LEN (GPU_SHADER_3D_IMAGE_COLOR + 1) + +/** Support multiple configurations. */ +typedef enum eGPUShaderConfig { + GPU_SHADER_CFG_DEFAULT = 0, + GPU_SHADER_CFG_CLIPPED = 1, +} eGPUShaderConfig; +#define GPU_SHADER_CFG_LEN (GPU_SHADER_CFG_CLIPPED + 1) + +struct GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader, + eGPUShaderConfig sh_cfg); +struct GPUShader *GPU_shader_get_builtin_shader(eGPUBuiltinShader shader); + +void GPU_shader_free_builtin_shaders(void); + +#ifdef __cplusplus +} +#endif -- 2.30.2 From bfe3239ff7bf2221c4abfd1c00d093ce0f53abb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Sun, 12 Feb 2023 17:40:13 +0100 Subject: [PATCH 05/11] Cleanup: GPUShader: Reorganize GPU_shader.h to separate depecated API This avoid confusion to what to use nowadays. Also improves documentation. --- source/blender/gpu/GPU_shader.h | 275 +++++++++++------- source/blender/gpu/intern/gpu_immediate.cc | 2 +- source/blender/gpu/intern/gpu_shader.cc | 102 ++----- .../blender/gpu/intern/gpu_shader_private.hh | 4 + source/blender/gpu/metal/mtl_framebuffer.mm | 2 +- source/blender/gpu/opengl/gl_framebuffer.cc | 2 +- 6 files changed, 210 insertions(+), 177 deletions(-) diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index 92c74234871..33a5fa01860 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -3,6 +3,8 @@ /** \file * \ingroup gpu + * + * A #GPUShader is a container for backend specific shader program. */ #pragma once @@ -20,6 +22,162 @@ typedef struct GPUShaderCreateInfo GPUShaderCreateInfo; /** Opaque type hiding #blender::gpu::Shader */ typedef struct GPUShader GPUShader; +/* Hardware limit is 16. Position attribute is always needed so we reduce to 15. + * This makes sure the GPUVertexFormat name buffer does not overflow. */ +#define GPU_MAX_ATTR 15 + +/* Determined by the maximum uniform buffer size divided by chunk size. */ +#define GPU_MAX_UNIFORM_ATTR 8 + +/* -------------------------------------------------------------------- */ +/** \name Creation + * \{ */ + +/** + * Create a shader using the given #GPUShaderCreateInfo. + * Can return a NULL pointer if compilation fails. + */ +GPUShader *GPU_shader_create_from_info(const GPUShaderCreateInfo *_info); + +/** + * Create a shader using a named #GPUShaderCreateInfo registered at startup. + * These are declared inside `*_info.hh` files using the `GPU_SHADER_CREATE_INFO()` macro. + * They are also expected to have been flagged using `do_static_compilation`. + * Can return a NULL pointer if compilation fails. + */ +GPUShader *GPU_shader_create_from_info_name(const char *info_name); + +/** + * Fetch a named #GPUShaderCreateInfo registered at startup. + * These are declared inside `*_info.hh` files using the `GPU_SHADER_CREATE_INFO()` macro. + * Can return a NULL pointer if no match is found. + */ +const GPUShaderCreateInfo *GPU_shader_create_info_get(const char *info_name); + +/** + * Error checking for user created shaders. + * \return true is create info is valid. + */ +bool GPU_shader_create_info_check_error(const GPUShaderCreateInfo *_info, char r_error[128]); + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Free + * \{ */ + +void GPU_shader_free(GPUShader *shader); + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Binding + * \{ */ + +/** + * Set the given shader as active shader for the active GPU context. + * It replaces any already bound shader. + * All following draw-calls and dispatches will use this shader. + * Uniform functions need to have the shader bound in order to work. (TODO: until we use + * glProgramUniform) + */ +void GPU_shader_bind(GPUShader *shader); + +/** + * Unbind the active shader. + * \note this is a no-op in release builds. But it make sense to actually do it in user land code + * to detect incorrect API usage. + */ +void GPU_shader_unbind(void); + +/** + * Return the currently bound shader to the active GPU context. + * \return NULL pointer if no shader is bound of if no context is active. + */ +GPUShader *GPU_shader_get_bound(void); + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Debugging introspection API. + * \{ */ + +const char *GPU_shader_get_name(GPUShader *shader); + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Uniform API. + * \{ */ + +/** + * Returns binding point location. + * Binding location are given to be set at compile time and immutable. + */ +/* TODO(fclem): Make naming consistent. ubo_binding, ssbo_binding */ +int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name); +int GPU_shader_get_texture_binding(GPUShader *shader, const char *name); +int GPU_shader_get_ssbo(GPUShader *shader, const char *name); + +/** + * Returns uniform location. + * If cached, it is faster than querying the interface for each uniform assignment. + */ +int GPU_shader_get_uniform(GPUShader *shader, const char *name); + +/** + * Sets a generic push constant (a.k.a. uniform). + * \a length and \a array_size should match the create info push_constant declaration. + */ +void GPU_shader_uniform_vector( + GPUShader *shader, int location, int length, int array_size, const float *value); +void GPU_shader_uniform_vector_int( + GPUShader *shader, int location, int length, int array_size, const int *value); + +/** + * Sets a generic push constant (a.k.a. uniform). + * \a length and \a array_size should match the create info push_constant declaration. + * These functions need to have the shader bound in order to work. (TODO: until we use + * glProgramUniform) + */ +void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value); +void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value); +void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value); +void GPU_shader_uniform_2f(GPUShader *sh, const char *name, float x, float y); +void GPU_shader_uniform_3f(GPUShader *sh, const char *name, float x, float y, float z); +void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, float z, float w); +void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2]); +void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3]); +void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4]); +void GPU_shader_uniform_2iv(GPUShader *sh, const char *name, const int data[2]); +void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4]); +void GPU_shader_uniform_mat3_as_mat4(GPUShader *sh, const char *name, const float data[3][3]); +void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float (*val)[2]); +void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float (*val)[4]); + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Attribute API. + * + * Used to create #GPUVertexFormat from the shader's vertex input layout. + * \{ */ + +unsigned int GPU_shader_get_attribute_len(const GPUShader *shader); +int GPU_shader_get_attribute(const GPUShader *shader, const char *name); +bool GPU_shader_get_attribute_info(const GPUShader *shader, + int attr_location, + char r_name[256], + int *r_type); + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Legacy API + * + * All of this section is deprecated and should be ported to use the API described above. + * \{ */ + typedef enum eGPUShaderTFBType { GPU_SHADER_TFB_NONE = 0, /* Transform feedback unsupported. */ GPU_SHADER_TFB_POINTS = 1, @@ -53,54 +211,6 @@ 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); -GPUShader *GPU_shader_create_from_info_name(const char *info_name); - -const GPUShaderCreateInfo *GPU_shader_create_info_get(const char *info_name); -bool GPU_shader_create_info_check_error(const GPUShaderCreateInfo *_info, char r_error[128]); - -struct GPU_ShaderCreateFromArray_Params { - const char **vert, **geom, **frag, **defs; -}; -/** - * Use via #GPU_shader_create_from_arrays macro (avoids passing in param). - * - * Similar to #DRW_shader_create_with_lib with the ability to include libraries for each type of - * shader. - * - * It has the advantage that each item can be conditionally included - * without having to build the string inline, then free it. - * - * \param params: NULL terminated arrays of strings. - * - * Example: - * \code{.c} - * sh = GPU_shader_create_from_arrays({ - * .vert = (const char *[]){shader_lib_glsl, shader_vert_glsl, NULL}, - * .geom = (const char *[]){shader_geom_glsl, NULL}, - * .frag = (const char *[]){shader_frag_glsl, NULL}, - * .defs = (const char *[]){"#define DEFINE\n", test ? "#define OTHER_DEFINE\n" : "", NULL}, - * }); - * \endcode - */ -struct GPUShader *GPU_shader_create_from_arrays_impl( - const struct GPU_ShaderCreateFromArray_Params *params, const char *func, int line); - -#define GPU_shader_create_from_arrays(...) \ - GPU_shader_create_from_arrays_impl( \ - &(const struct GPU_ShaderCreateFromArray_Params)__VA_ARGS__, __func__, __LINE__) - -#define GPU_shader_create_from_arrays_named(name, ...) \ - GPU_shader_create_from_arrays_impl( \ - &(const struct GPU_ShaderCreateFromArray_Params)__VA_ARGS__, name, 0) - -void GPU_shader_free(GPUShader *shader); - -void GPU_shader_bind(GPUShader *shader); -void GPU_shader_unbind(void); -GPUShader *GPU_shader_get_bound(void); - -const char *GPU_shader_get_name(GPUShader *shader); /** * Returns true if transform feedback was successfully enabled. @@ -111,6 +221,9 @@ void GPU_shader_transform_feedback_disable(GPUShader *shader); /** DEPRECATED: Kept only because of BGL API. */ int GPU_shader_get_program(GPUShader *shader); +/** + * Indexed commonly used uniform name for faster lookup into the uniform cache. + */ typedef enum { GPU_UNIFORM_MODEL = 0, /* mat4 ModelMatrix */ GPU_UNIFORM_VIEW, /* mat4 ViewMatrix */ @@ -134,16 +247,19 @@ typedef enum { GPU_UNIFORM_RESOURCE_CHUNK, /* int resourceChunk */ GPU_UNIFORM_RESOURCE_ID, /* int resourceId */ GPU_UNIFORM_SRGB_TRANSFORM, /* bool srgbTarget */ - - GPU_NUM_UNIFORMS, /* Special value, denotes number of builtin uniforms. */ } GPUUniformBuiltin; +#define GPU_NUM_UNIFORMS (GPU_UNIFORM_SRGB_TRANSFORM + 1) +/** TODO: To be moved as private API. Not really used outside of gpu_matrix.cc and doesn't really + * offer a noticeable perf boost. */ +int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin); + +/** DEPRECATED: Use hardcoded buffer location instead. */ typedef enum { - /** Deprecated */ GPU_UNIFORM_BLOCK_VIEW = 0, /* viewBlock */ GPU_UNIFORM_BLOCK_MODEL, /* modelBlock */ GPU_UNIFORM_BLOCK_INFO, /* infoBlock */ - /** New ones */ + GPU_UNIFORM_BLOCK_DRW_VIEW, GPU_UNIFORM_BLOCK_DRW_MODEL, GPU_UNIFORM_BLOCK_DRW_INFOS, @@ -152,6 +268,10 @@ typedef enum { GPU_NUM_UNIFORM_BLOCKS, /* Special value, denotes number of builtin uniforms block. */ } GPUUniformBlockBuiltin; +/** DEPRECATED: Use hardcoded buffer location instead. */ +int GPU_shader_get_builtin_block(GPUShader *shader, int builtin); + +/** DEPRECATED: Use hardcoded buffer location instead. */ typedef enum { GPU_STORAGE_BUFFER_DEBUG_VERTS = 0, /* drw_debug_verts_buf */ GPU_STORAGE_BUFFER_DEBUG_PRINT, /* drw_debug_print_buf */ @@ -159,60 +279,19 @@ typedef enum { GPU_NUM_STORAGE_BUFFERS, /* Special value, denotes number of builtin buffer blocks. */ } GPUStorageBufferBuiltin; -void GPU_shader_set_srgb_uniform(GPUShader *shader); - -int GPU_shader_get_uniform(GPUShader *shader, const char *name); -int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin); -int GPU_shader_get_builtin_block(GPUShader *shader, int builtin); +/** DEPRECATED: Use hardcoded buffer location instead. */ int GPU_shader_get_builtin_ssbo(GPUShader *shader, int builtin); + /** DEPRECATED: Kept only because of Python GPU API. */ int GPU_shader_get_uniform_block(GPUShader *shader, const char *name); -int GPU_shader_get_ssbo(GPUShader *shader, const char *name); - -int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name); -int GPU_shader_get_texture_binding(GPUShader *shader, const char *name); - -void GPU_shader_uniform_vector( - GPUShader *shader, int location, int length, int arraysize, const float *value); -void GPU_shader_uniform_vector_int( - GPUShader *shader, int location, int length, int arraysize, const int *value); +/** DEPRECATED: To be replaced by GPU_shader_uniform_vector. */ void GPU_shader_uniform_float(GPUShader *shader, int location, float value); void GPU_shader_uniform_int(GPUShader *shader, int location, int value); -void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value); -void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value); -void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value); -void GPU_shader_uniform_2f(GPUShader *sh, const char *name, float x, float y); -void GPU_shader_uniform_3f(GPUShader *sh, const char *name, float x, float y, float z); -void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, float z, float w); -void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2]); -void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3]); -void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4]); -void GPU_shader_uniform_2iv(GPUShader *sh, const char *name, const int data[2]); -void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4]); -void GPU_shader_uniform_mat3_as_mat4(GPUShader *sh, const char *name, const float data[3][3]); -void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float (*val)[2]); -void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float (*val)[4]); - -unsigned int GPU_shader_get_attribute_len(const GPUShader *shader); -int GPU_shader_get_attribute(GPUShader *shader, const char *name); -bool GPU_shader_get_attribute_info(const GPUShader *shader, - int attr_location, - char r_name[256], - int *r_type); - -void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear); - -/* Vertex attributes for shaders */ - -/* Hardware limit is 16. Position attribute is always needed so we reduce to 15. - * This makes sure the GPUVertexFormat name buffer does not overflow. */ -#define GPU_MAX_ATTR 15 - -/* Determined by the maximum uniform buffer size divided by chunk size. */ -#define GPU_MAX_UNIFORM_ATTR 8 +/** \} */ +/* TODO: Move to shader shared. */ typedef enum eGPUKeyframeShapes { GPU_KEYFRAME_SHAPE_DIAMOND = (1 << 0), GPU_KEYFRAME_SHAPE_CIRCLE = (1 << 1), diff --git a/source/blender/gpu/intern/gpu_immediate.cc b/source/blender/gpu/intern/gpu_immediate.cc index 2c4f43cdde8..a983d1da6ca 100644 --- a/source/blender/gpu/intern/gpu_immediate.cc +++ b/source/blender/gpu/intern/gpu_immediate.cc @@ -54,7 +54,7 @@ void immBindShader(GPUShader *shader) GPU_shader_bind(shader); GPU_matrix_bind(shader); - GPU_shader_set_srgb_uniform(shader); + Shader::set_srgb_uniform(shader); } void immBindBuiltinProgram(eGPUBuiltinShader shader_id) diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc index 0653ae11a0a..b073f993919 100644 --- a/source/blender/gpu/intern/gpu_shader.cc +++ b/source/blender/gpu/intern/gpu_shader.cc @@ -46,8 +46,6 @@ std::string Shader::defines_declare(const shader::ShaderCreateInfo &info) const using namespace blender; using namespace blender::gpu; -static bool gpu_shader_srgb_uniform_dirty_get(); - /* -------------------------------------------------------------------- */ /** \name Creation / Destruction * \{ */ @@ -443,58 +441,6 @@ GPUShader *GPU_shader_create_from_python(const char *vertcode, return sh; } -static const char *string_join_array_maybe_alloc(const char **str_arr, bool *r_is_alloc) -{ - bool is_alloc = false; - if (str_arr == nullptr) { - *r_is_alloc = false; - return nullptr; - } - /* Skip empty strings (avoid alloc if we can). */ - while (str_arr[0] && str_arr[0][0] == '\0') { - str_arr++; - } - int i; - for (i = 0; str_arr[i]; i++) { - if (i != 0 && str_arr[i][0] != '\0') { - is_alloc = true; - } - } - *r_is_alloc = is_alloc; - if (is_alloc) { - return BLI_string_join_arrayN(str_arr, i); - } - - return str_arr[0]; -} - -struct GPUShader *GPU_shader_create_from_arrays_impl( - const struct GPU_ShaderCreateFromArray_Params *params, const char *func, int line) -{ - struct { - const char *str; - bool is_alloc; - } str_dst[4] = {{nullptr}}; - const char **str_src[4] = {params->vert, params->frag, params->geom, params->defs}; - - for (int i = 0; i < ARRAY_SIZE(str_src); i++) { - str_dst[i].str = string_join_array_maybe_alloc(str_src[i], &str_dst[i].is_alloc); - } - - char name[64]; - BLI_snprintf(name, sizeof(name), "%s_%d", func, line); - - GPUShader *sh = GPU_shader_create( - str_dst[0].str, str_dst[1].str, str_dst[2].str, nullptr, str_dst[3].str, name); - - for (auto &i : str_dst) { - if (i.is_alloc) { - MEM_freeN((void *)i.str); - } - } - return sh; -} - /** \} */ /* -------------------------------------------------------------------- */ @@ -511,11 +457,11 @@ void GPU_shader_bind(GPUShader *gpu_shader) ctx->shader = shader; shader->bind(); GPU_matrix_bind(gpu_shader); - GPU_shader_set_srgb_uniform(gpu_shader); + Shader::set_srgb_uniform(gpu_shader); } else { - if (gpu_shader_srgb_uniform_dirty_get()) { - GPU_shader_set_srgb_uniform(gpu_shader); + if (Shader::srgb_uniform_dirty_get()) { + Shader::set_srgb_uniform(gpu_shader); } if (GPU_matrix_dirty_get()) { GPU_matrix_bind(gpu_shader); @@ -580,66 +526,66 @@ void GPU_shader_transform_feedback_disable(GPUShader *shader) int GPU_shader_get_uniform(GPUShader *shader, const char *name) { - ShaderInterface *interface = unwrap(shader)->interface; + const ShaderInterface *interface = unwrap(shader)->interface; const ShaderInput *uniform = interface->uniform_get(name); return uniform ? uniform->location : -1; } int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin) { - ShaderInterface *interface = unwrap(shader)->interface; + const ShaderInterface *interface = unwrap(shader)->interface; return interface->uniform_builtin((GPUUniformBuiltin)builtin); } int GPU_shader_get_builtin_block(GPUShader *shader, int builtin) { - ShaderInterface *interface = unwrap(shader)->interface; + const ShaderInterface *interface = unwrap(shader)->interface; return interface->ubo_builtin((GPUUniformBlockBuiltin)builtin); } int GPU_shader_get_builtin_ssbo(GPUShader *shader, int builtin) { - ShaderInterface *interface = unwrap(shader)->interface; + const ShaderInterface *interface = unwrap(shader)->interface; return interface->ssbo_builtin((GPUStorageBufferBuiltin)builtin); } int GPU_shader_get_ssbo(GPUShader *shader, const char *name) { - ShaderInterface *interface = unwrap(shader)->interface; + const ShaderInterface *interface = unwrap(shader)->interface; const ShaderInput *ssbo = interface->ssbo_get(name); return ssbo ? ssbo->location : -1; } int GPU_shader_get_uniform_block(GPUShader *shader, const char *name) { - ShaderInterface *interface = unwrap(shader)->interface; + const ShaderInterface *interface = unwrap(shader)->interface; const ShaderInput *ubo = interface->ubo_get(name); return ubo ? ubo->location : -1; } int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name) { - ShaderInterface *interface = unwrap(shader)->interface; + const ShaderInterface *interface = unwrap(shader)->interface; const ShaderInput *ubo = interface->ubo_get(name); return ubo ? ubo->binding : -1; } int GPU_shader_get_texture_binding(GPUShader *shader, const char *name) { - ShaderInterface *interface = unwrap(shader)->interface; + const ShaderInterface *interface = unwrap(shader)->interface; const ShaderInput *tex = interface->uniform_get(name); return tex ? tex->binding : -1; } uint GPU_shader_get_attribute_len(const GPUShader *shader) { - ShaderInterface *interface = unwrap(shader)->interface; + const ShaderInterface *interface = unwrap(shader)->interface; return interface->attr_len_; } -int GPU_shader_get_attribute(GPUShader *shader, const char *name) +int GPU_shader_get_attribute(const GPUShader *shader, const char *name) { - ShaderInterface *interface = unwrap(shader)->interface; + const ShaderInterface *interface = unwrap(shader)->interface; const ShaderInput *attr = interface->attr_get(name); return attr ? attr->location : -1; } @@ -649,7 +595,7 @@ bool GPU_shader_get_attribute_info(const GPUShader *shader, char r_name[256], int *r_type) { - ShaderInterface *interface = unwrap(shader)->interface; + const ShaderInterface *interface = unwrap(shader)->interface; const ShaderInput *attr = interface->attr_get(attr_location); if (!attr) { @@ -679,15 +625,15 @@ int GPU_shader_get_program(GPUShader *shader) * \{ */ void GPU_shader_uniform_vector( - GPUShader *shader, int loc, int len, int arraysize, const float *value) + GPUShader *shader, int loc, int len, int array_size, const float *value) { - unwrap(shader)->uniform_float(loc, len, arraysize, value); + unwrap(shader)->uniform_float(loc, len, array_size, value); } void GPU_shader_uniform_vector_int( - GPUShader *shader, int loc, int len, int arraysize, const int *value) + GPUShader *shader, int loc, int len, int array_size, const int *value) { - unwrap(shader)->uniform_int(loc, len, arraysize, value); + unwrap(shader)->uniform_int(loc, len, array_size, value); } void GPU_shader_uniform_int(GPUShader *shader, int location, int value) @@ -797,15 +743,17 @@ void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, cons * frame-buffer color-space. * \{ */ +namespace blender::gpu { + static int g_shader_builtin_srgb_transform = 0; static bool g_shader_builtin_srgb_is_dirty = false; -static bool gpu_shader_srgb_uniform_dirty_get() +bool Shader::srgb_uniform_dirty_get() { return g_shader_builtin_srgb_is_dirty; } -void GPU_shader_set_srgb_uniform(GPUShader *shader) +void Shader::set_srgb_uniform(GPUShader *shader) { int32_t loc = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_SRGB_TRANSFORM); if (loc != -1) { @@ -814,7 +762,7 @@ void GPU_shader_set_srgb_uniform(GPUShader *shader) g_shader_builtin_srgb_is_dirty = false; } -void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear) +void Shader::set_framebuffer_srgb_target(int use_srgb_to_linear) { if (g_shader_builtin_srgb_transform != use_srgb_to_linear) { g_shader_builtin_srgb_transform = use_srgb_to_linear; @@ -822,4 +770,6 @@ void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear) } } +} // namespace blender::gpu + /** \} */ diff --git a/source/blender/gpu/intern/gpu_shader_private.hh b/source/blender/gpu/intern/gpu_shader_private.hh index a822cd8aa38..e4d036a9554 100644 --- a/source/blender/gpu/intern/gpu_shader_private.hh +++ b/source/blender/gpu/intern/gpu_shader_private.hh @@ -71,6 +71,10 @@ class Shader { return name; }; + static bool srgb_uniform_dirty_get(); + static void set_srgb_uniform(GPUShader *shader); + static void set_framebuffer_srgb_target(int use_srgb_to_linear); + protected: void print_log( Span sources, char *log, const char *stage, bool error, GPULogParser *parser); diff --git a/source/blender/gpu/metal/mtl_framebuffer.mm b/source/blender/gpu/metal/mtl_framebuffer.mm index dc8741e377b..9b334dd7166 100644 --- a/source/blender/gpu/metal/mtl_framebuffer.mm +++ b/source/blender/gpu/metal/mtl_framebuffer.mm @@ -109,7 +109,7 @@ void MTLFrameBuffer::bind(bool enabled_srgb) this->mark_dirty(); } enabled_srgb_ = enabled_srgb; - GPU_shader_set_framebuffer_srgb_target(enabled_srgb && srgb_); + Shader::set_framebuffer_srgb_target(enabled_srgb && srgb_); } /* Reset clear state on bind -- Clears and load/store ops are set after binding. */ diff --git a/source/blender/gpu/opengl/gl_framebuffer.cc b/source/blender/gpu/opengl/gl_framebuffer.cc index e94f5b66b97..cc7ecae5c55 100644 --- a/source/blender/gpu/opengl/gl_framebuffer.cc +++ b/source/blender/gpu/opengl/gl_framebuffer.cc @@ -280,7 +280,7 @@ void GLFrameBuffer::bind(bool enabled_srgb) else { glDisable(GL_FRAMEBUFFER_SRGB); } - GPU_shader_set_framebuffer_srgb_target(enabled_srgb && srgb_); + Shader::set_framebuffer_srgb_target(enabled_srgb && srgb_); } if (context_->active_fb != this) { -- 2.30.2 From 7396420f39cfb6e8f043fc7f4e5dc0ae6562af92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Sun, 12 Feb 2023 20:53:42 +0100 Subject: [PATCH 06/11] Cleanup: GPU: Move `eGPUKeyframeShapes` to shader shared Removes code duplication. --- source/blender/editors/animation/keyframes_draw.c | 1 + source/blender/editors/space_node/node_draw.cc | 1 + source/blender/gpu/GPU_shader.h | 14 -------------- source/blender/gpu/GPU_shader_shared.h | 13 +++++++++++++ .../shaders/gpu_shader_keyframe_shape_frag.glsl | 12 ------------ .../shaders/gpu_shader_keyframe_shape_vert.glsl | 12 ------------ .../infos/gpu_shader_keyframe_shape_info.hh | 1 + 7 files changed, 16 insertions(+), 38 deletions(-) diff --git a/source/blender/editors/animation/keyframes_draw.c b/source/blender/editors/animation/keyframes_draw.c index d0b978b7adf..6b1fdb977ff 100644 --- a/source/blender/editors/animation/keyframes_draw.c +++ b/source/blender/editors/animation/keyframes_draw.c @@ -22,6 +22,7 @@ #include "DNA_scene_types.h" #include "GPU_immediate.h" +#include "GPU_shader_shared.h" #include "GPU_state.h" #include "UI_interface.h" diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 53a86e23ce1..31dc2695c97 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -51,6 +51,7 @@ #include "GPU_immediate.h" #include "GPU_immediate_util.h" #include "GPU_matrix.h" +#include "GPU_shader_shared.h" #include "GPU_state.h" #include "GPU_viewport.h" diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index 33a5fa01860..d1824de62ed 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -291,20 +291,6 @@ void GPU_shader_uniform_int(GPUShader *shader, int location, int value); /** \} */ -/* TODO: Move to shader shared. */ -typedef enum eGPUKeyframeShapes { - GPU_KEYFRAME_SHAPE_DIAMOND = (1 << 0), - GPU_KEYFRAME_SHAPE_CIRCLE = (1 << 1), - GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL = (1 << 2), - GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL = (1 << 3), - GPU_KEYFRAME_SHAPE_INNER_DOT = (1 << 4), - GPU_KEYFRAME_SHAPE_ARROW_END_MAX = (1 << 8), - GPU_KEYFRAME_SHAPE_ARROW_END_MIN = (1 << 9), - GPU_KEYFRAME_SHAPE_ARROW_END_MIXED = (1 << 10), -} eGPUKeyframeShapes; -#define GPU_KEYFRAME_SHAPE_SQUARE \ - (GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL | GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL) - #ifdef __cplusplus } #endif diff --git a/source/blender/gpu/GPU_shader_shared.h b/source/blender/gpu/GPU_shader_shared.h index 4fb321ce502..630a503690e 100644 --- a/source/blender/gpu/GPU_shader_shared.h +++ b/source/blender/gpu/GPU_shader_shared.h @@ -11,6 +11,19 @@ typedef struct TestOutputRawData TestOutputRawData; #endif +enum eGPUKeyframeShapes { + GPU_KEYFRAME_SHAPE_DIAMOND = (1u << 0u), + GPU_KEYFRAME_SHAPE_CIRCLE = (1u << 1u), + GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL = (1u << 2u), + GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL = (1u << 3u), + GPU_KEYFRAME_SHAPE_INNER_DOT = (1u << 4u), + GPU_KEYFRAME_SHAPE_ARROW_END_MAX = (1u << 8u), + GPU_KEYFRAME_SHAPE_ARROW_END_MIN = (1u << 9u), + GPU_KEYFRAME_SHAPE_ARROW_END_MIXED = (1u << 10u), + GPU_KEYFRAME_SHAPE_SQUARE = (GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL | + GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL), +}; + struct NodeLinkData { float4 colors[3]; /* bezierPts Is actually a float2, but due to std140 each element needs to be aligned to 16 diff --git a/source/blender/gpu/shaders/gpu_shader_keyframe_shape_frag.glsl b/source/blender/gpu/shaders/gpu_shader_keyframe_shape_frag.glsl index 3690dd8d1d2..3b1dad24182 100644 --- a/source/blender/gpu/shaders/gpu_shader_keyframe_shape_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_keyframe_shape_frag.glsl @@ -1,16 +1,4 @@ -/* Values in GPU_shader.h. */ -#define GPU_KEYFRAME_SHAPE_DIAMOND (1u << 0) -#define GPU_KEYFRAME_SHAPE_CIRCLE (1u << 1) -#define GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL (1u << 2) -#define GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL (1u << 3) -#define GPU_KEYFRAME_SHAPE_INNER_DOT (1u << 4) -#define GPU_KEYFRAME_SHAPE_ARROW_END_MAX (1u << 8) -#define GPU_KEYFRAME_SHAPE_ARROW_END_MIN (1u << 9) -#define GPU_KEYFRAME_SHAPE_ARROW_END_MIXED (1u << 10) -#define GPU_KEYFRAME_SHAPE_SQUARE \ - (GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL | GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL) - const float diagonal_scale = sqrt(0.5); const float minmax_bias = 0.7; diff --git a/source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl b/source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl index 78e8f40b25e..22599ca9fe5 100644 --- a/source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl @@ -1,16 +1,4 @@ -/* Values in GPU_shader.h. */ -#define GPU_KEYFRAME_SHAPE_DIAMOND (1u << 0) -#define GPU_KEYFRAME_SHAPE_CIRCLE (1u << 1) -#define GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL (1u << 2) -#define GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL (1u << 3) -#define GPU_KEYFRAME_SHAPE_INNER_DOT (1u << 4) -#define GPU_KEYFRAME_SHAPE_ARROW_END_MAX (1u << 8) -#define GPU_KEYFRAME_SHAPE_ARROW_END_MIN (1u << 9) -#define GPU_KEYFRAME_SHAPE_ARROW_END_MIXED (1u << 10) -#define GPU_KEYFRAME_SHAPE_SQUARE \ - (GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL | GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL) - const float line_falloff = 1.0; const float circle_scale = sqrt(2.0 / 3.1416); const float square_scale = sqrt(0.5); diff --git a/source/blender/gpu/shaders/infos/gpu_shader_keyframe_shape_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_keyframe_shape_info.hh index f203a08eea5..eccbd50bf21 100644 --- a/source/blender/gpu/shaders/infos/gpu_shader_keyframe_shape_info.hh +++ b/source/blender/gpu/shaders/infos/gpu_shader_keyframe_shape_info.hh @@ -15,6 +15,7 @@ GPU_SHADER_INTERFACE_INFO(keyframe_shape_iface, "") .flat(Type::UINT, "finalFlags"); GPU_SHADER_CREATE_INFO(gpu_shader_keyframe_shape) + .typedef_source("GPU_shader_shared.h") .vertex_in(0, Type::VEC4, "color") .vertex_in(1, Type::VEC4, "outlineColor") .vertex_in(2, Type::VEC2, "pos") -- 2.30.2 From 3b0c887835beec2266b610ff7d94e74a2094c3da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Sun, 12 Feb 2023 22:52:27 +0100 Subject: [PATCH 07/11] Cleanup: GPU: Rename some functions for consistency --- .../intern/algorithm_parallel_reduction.cc | 4 +-- .../morphological_distance_feather_weights.cc | 4 +-- .../intern/symmetric_blur_weights.cc | 2 +- .../symmetric_separable_blur_weights.cc | 2 +- .../realtime_compositor/intern/result.cc | 4 +-- .../intern/shader_operation.cc | 4 +-- .../engines/workbench/workbench_shadow.cc | 11 +++---- .../intern/draw_cache_impl_subdivision.cc | 2 +- source/blender/draw/intern/draw_command.cc | 8 ++--- source/blender/draw/intern/draw_manager.cc | 6 ++-- .../blender/draw/intern/draw_manager_data.cc | 31 +++++++++--------- source/blender/draw/intern/draw_pass.hh | 32 +++++++++---------- source/blender/draw/intern/draw_view.cc | 6 ++-- .../editors/interface/interface_icons.cc | 6 ++-- source/blender/gpu/GPU_batch.h | 4 +-- source/blender/gpu/GPU_shader.h | 9 +++--- source/blender/gpu/intern/gpu_immediate.cc | 6 ++-- source/blender/gpu/intern/gpu_shader.cc | 6 ++-- source/blender/gpu/tests/gpu_shader_test.cc | 14 ++++---- .../nodes/node_composite_composite.cc | 6 ++-- .../composite/nodes/node_composite_dilate.cc | 8 ++--- .../composite/nodes/node_composite_image.cc | 6 ++-- .../nodes/node_composite_movieclip.cc | 4 +-- .../nodes/node_composite_split_viewer.cc | 2 +- .../composite/nodes/node_composite_viewer.cc | 6 ++-- source/blender/python/gpu/gpu_py_shader.c | 4 +-- source/blender/windowmanager/intern/wm_draw.c | 2 +- 27 files changed, 98 insertions(+), 101 deletions(-) diff --git a/source/blender/compositor/realtime_compositor/algorithms/intern/algorithm_parallel_reduction.cc b/source/blender/compositor/realtime_compositor/algorithms/intern/algorithm_parallel_reduction.cc index ba0e7eb21ac..b45b3e100e8 100644 --- a/source/blender/compositor/realtime_compositor/algorithms/intern/algorithm_parallel_reduction.cc +++ b/source/blender/compositor/realtime_compositor/algorithms/intern/algorithm_parallel_reduction.cc @@ -41,10 +41,10 @@ static float *parallel_reduction_dispatch(Context &context, GPUTexture *reduced_texture = context.texture_pool().acquire(reduced_size, format); GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH); - const int texture_image_unit = GPU_shader_get_texture_binding(shader, "input_tx"); + const int texture_image_unit = GPU_shader_get_sampler_binding(shader, "input_tx"); GPU_texture_bind(texture_to_reduce, texture_image_unit); - const int image_unit = GPU_shader_get_texture_binding(shader, "output_img"); + const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img"); GPU_texture_image_bind(reduced_texture, image_unit); GPU_compute_dispatch(shader, reduced_size.x, reduced_size.y, 1); diff --git a/source/blender/compositor/realtime_compositor/cached_resources/intern/morphological_distance_feather_weights.cc b/source/blender/compositor/realtime_compositor/cached_resources/intern/morphological_distance_feather_weights.cc index eac88b907b8..98e7b67dca7 100644 --- a/source/blender/compositor/realtime_compositor/cached_resources/intern/morphological_distance_feather_weights.cc +++ b/source/blender/compositor/realtime_compositor/cached_resources/intern/morphological_distance_feather_weights.cc @@ -135,7 +135,7 @@ void MorphologicalDistanceFeatherWeights::compute_distance_falloffs(int type, in void MorphologicalDistanceFeatherWeights::bind_weights_as_texture(GPUShader *shader, const char *texture_name) const { - const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name); + const int texture_image_unit = GPU_shader_get_sampler_binding(shader, texture_name); GPU_texture_bind(weights_texture_, texture_image_unit); } @@ -147,7 +147,7 @@ void MorphologicalDistanceFeatherWeights::unbind_weights_as_texture() const void MorphologicalDistanceFeatherWeights::bind_distance_falloffs_as_texture( GPUShader *shader, const char *texture_name) const { - const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name); + const int texture_image_unit = GPU_shader_get_sampler_binding(shader, texture_name); GPU_texture_bind(distance_falloffs_texture_, texture_image_unit); } diff --git a/source/blender/compositor/realtime_compositor/cached_resources/intern/symmetric_blur_weights.cc b/source/blender/compositor/realtime_compositor/cached_resources/intern/symmetric_blur_weights.cc index b3200d468c9..db4c0f777f2 100644 --- a/source/blender/compositor/realtime_compositor/cached_resources/intern/symmetric_blur_weights.cc +++ b/source/blender/compositor/realtime_compositor/cached_resources/intern/symmetric_blur_weights.cc @@ -103,7 +103,7 @@ SymmetricBlurWeights::~SymmetricBlurWeights() void SymmetricBlurWeights::bind_as_texture(GPUShader *shader, const char *texture_name) const { - const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name); + const int texture_image_unit = GPU_shader_get_sampler_binding(shader, texture_name); GPU_texture_bind(texture_, texture_image_unit); } diff --git a/source/blender/compositor/realtime_compositor/cached_resources/intern/symmetric_separable_blur_weights.cc b/source/blender/compositor/realtime_compositor/cached_resources/intern/symmetric_separable_blur_weights.cc index b8c47d5a5d0..07d45531921 100644 --- a/source/blender/compositor/realtime_compositor/cached_resources/intern/symmetric_separable_blur_weights.cc +++ b/source/blender/compositor/realtime_compositor/cached_resources/intern/symmetric_separable_blur_weights.cc @@ -81,7 +81,7 @@ SymmetricSeparableBlurWeights::~SymmetricSeparableBlurWeights() void SymmetricSeparableBlurWeights::bind_as_texture(GPUShader *shader, const char *texture_name) const { - const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name); + const int texture_image_unit = GPU_shader_get_sampler_binding(shader, texture_name); GPU_texture_bind(texture_, texture_image_unit); } diff --git a/source/blender/compositor/realtime_compositor/intern/result.cc b/source/blender/compositor/realtime_compositor/intern/result.cc index e301aa6e0ed..902eede7dd7 100644 --- a/source/blender/compositor/realtime_compositor/intern/result.cc +++ b/source/blender/compositor/realtime_compositor/intern/result.cc @@ -82,7 +82,7 @@ void Result::bind_as_texture(GPUShader *shader, const char *texture_name) const /* Make sure any prior writes to the texture are reflected before reading from it. */ GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH); - const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name); + const int texture_image_unit = GPU_shader_get_sampler_binding(shader, texture_name); GPU_texture_bind(texture_, texture_image_unit); } @@ -93,7 +93,7 @@ void Result::bind_as_image(GPUShader *shader, const char *image_name, bool read) GPU_memory_barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS); } - const int image_unit = GPU_shader_get_texture_binding(shader, image_name); + const int image_unit = GPU_shader_get_sampler_binding(shader, image_name); GPU_texture_image_bind(texture_, image_unit); } diff --git a/source/blender/compositor/realtime_compositor/intern/shader_operation.cc b/source/blender/compositor/realtime_compositor/intern/shader_operation.cc index 4ac997db42b..b4976e5eff0 100644 --- a/source/blender/compositor/realtime_compositor/intern/shader_operation.cc +++ b/source/blender/compositor/realtime_compositor/intern/shader_operation.cc @@ -95,14 +95,14 @@ void ShaderOperation::bind_material_resources(GPUShader *shader) * no uniforms. */ GPUUniformBuf *ubo = GPU_material_uniform_buffer_get(material_); if (ubo) { - GPU_uniformbuf_bind(ubo, GPU_shader_get_uniform_block_binding(shader, GPU_UBO_BLOCK_NAME)); + GPU_uniformbuf_bind(ubo, GPU_shader_get_ubo_binding(shader, GPU_UBO_BLOCK_NAME)); } /* Bind color band textures needed by curve and ramp nodes. */ ListBase textures = GPU_material_textures(material_); LISTBASE_FOREACH (GPUMaterialTexture *, texture, &textures) { if (texture->colorband) { - const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture->sampler_name); + const int texture_image_unit = GPU_shader_get_sampler_binding(shader, texture->sampler_name); GPU_texture_bind(*texture->colorband, texture_image_unit); } } diff --git a/source/blender/draw/engines/workbench/workbench_shadow.cc b/source/blender/draw/engines/workbench/workbench_shadow.cc index 2bc5584abe7..ff50fd3732c 100644 --- a/source/blender/draw/engines/workbench/workbench_shadow.cc +++ b/source/blender/draw/engines/workbench/workbench_shadow.cc @@ -259,17 +259,16 @@ void ShadowPass::ShadowView::compute_visibility(ObjectBoundsBuf &bounds, GPU_shader_uniform_1i(shader, "visibility_word_per_draw", word_per_draw); GPU_shader_uniform_1b(shader, "force_fail_method", force_fail_method_); GPU_shader_uniform_3fv(shader, "shadow_direction", light_direction_); - GPU_uniformbuf_bind(extruded_frustum_, - GPU_shader_get_uniform_block_binding(shader, "extruded_frustum")); - GPU_storagebuf_bind(bounds, GPU_shader_get_ssbo(shader, "bounds_buf")); + GPU_uniformbuf_bind(extruded_frustum_, GPU_shader_get_ubo_binding(shader, "extruded_frustum")); + GPU_storagebuf_bind(bounds, GPU_shader_get_ssbo_binding(shader, "bounds_buf")); if (current_pass_type_ == ShadowPass::FORCED_FAIL) { - GPU_storagebuf_bind(visibility_buf_, GPU_shader_get_ssbo(shader, "visibility_buf")); + GPU_storagebuf_bind(visibility_buf_, GPU_shader_get_ssbo_binding(shader, "visibility_buf")); } else { GPU_storagebuf_bind(pass_visibility_buf_, - GPU_shader_get_ssbo(shader, "pass_visibility_buf")); + GPU_shader_get_ssbo_binding(shader, "pass_visibility_buf")); GPU_storagebuf_bind(fail_visibility_buf_, - GPU_shader_get_ssbo(shader, "fail_visibility_buf")); + GPU_shader_get_ssbo_binding(shader, "fail_visibility_buf")); } GPU_uniformbuf_bind(data_, DRW_VIEW_UBO_SLOT); GPU_compute_dispatch(shader, divide_ceil_u(resource_len, DRW_VISIBILITY_GROUP_SIZE), 1, 1); diff --git a/source/blender/draw/intern/draw_cache_impl_subdivision.cc b/source/blender/draw/intern/draw_cache_impl_subdivision.cc index fb21e58d527..0fe5eba26f4 100644 --- a/source/blender/draw/intern/draw_cache_impl_subdivision.cc +++ b/source/blender/draw/intern/draw_cache_impl_subdivision.cc @@ -1350,7 +1350,7 @@ static void draw_subdiv_ubo_update_and_bind(const DRWSubdivCache *cache, GPU_uniformbuf_update(cache->ubo, &storage); - const int binding = GPU_shader_get_uniform_block_binding(shader, "shader_data"); + const int binding = GPU_shader_get_ubo_binding(shader, "shader_data"); GPU_uniformbuf_bind(cache->ubo, binding); } diff --git a/source/blender/draw/intern/draw_command.cc b/source/blender/draw/intern/draw_command.cc index 775ee9f695b..c06ff88537a 100644 --- a/source/blender/draw/intern/draw_command.cc +++ b/source/blender/draw/intern/draw_command.cc @@ -646,10 +646,10 @@ void DrawMultiBuf::bind(RecordingState &state, GPU_shader_uniform_1i(shader, "prototype_len", prototype_count_); GPU_shader_uniform_1i(shader, "visibility_word_per_draw", visibility_word_per_draw); GPU_shader_uniform_1i(shader, "view_shift", log2_ceil_u(view_len)); - GPU_storagebuf_bind(group_buf_, GPU_shader_get_ssbo(shader, "group_buf")); - GPU_storagebuf_bind(visibility_buf, GPU_shader_get_ssbo(shader, "visibility_buf")); - GPU_storagebuf_bind(prototype_buf_, GPU_shader_get_ssbo(shader, "prototype_buf")); - GPU_storagebuf_bind(command_buf_, GPU_shader_get_ssbo(shader, "command_buf")); + GPU_storagebuf_bind(group_buf_, GPU_shader_get_ssbo_binding(shader, "group_buf")); + GPU_storagebuf_bind(visibility_buf, GPU_shader_get_ssbo_binding(shader, "visibility_buf")); + GPU_storagebuf_bind(prototype_buf_, GPU_shader_get_ssbo_binding(shader, "prototype_buf")); + GPU_storagebuf_bind(command_buf_, GPU_shader_get_ssbo_binding(shader, "command_buf")); GPU_storagebuf_bind(resource_id_buf_, DRW_RESOURCE_ID_SLOT); GPU_compute_dispatch(shader, divide_ceil_u(prototype_count_, DRW_COMMAND_GROUP_SIZE), 1, 1); if (GPU_shader_draw_parameters_support() == false) { diff --git a/source/blender/draw/intern/draw_manager.cc b/source/blender/draw/intern/draw_manager.cc index 74108ab2f7c..f34650255a5 100644 --- a/source/blender/draw/intern/draw_manager.cc +++ b/source/blender/draw/intern/draw_manager.cc @@ -114,9 +114,9 @@ void Manager::end_sync() GPUShader *shader = DRW_shader_draw_resource_finalize_get(); GPU_shader_bind(shader); GPU_shader_uniform_1i(shader, "resource_len", resource_len_); - GPU_storagebuf_bind(matrix_buf.current(), GPU_shader_get_ssbo(shader, "matrix_buf")); - GPU_storagebuf_bind(bounds_buf.current(), GPU_shader_get_ssbo(shader, "bounds_buf")); - GPU_storagebuf_bind(infos_buf.current(), GPU_shader_get_ssbo(shader, "infos_buf")); + GPU_storagebuf_bind(matrix_buf.current(), GPU_shader_get_ssbo_binding(shader, "matrix_buf")); + GPU_storagebuf_bind(bounds_buf.current(), GPU_shader_get_ssbo_binding(shader, "bounds_buf")); + GPU_storagebuf_bind(infos_buf.current(), GPU_shader_get_ssbo_binding(shader, "infos_buf")); GPU_compute_dispatch(shader, thread_groups, 1, 1); GPU_memory_barrier(GPU_BARRIER_SHADER_STORAGE); diff --git a/source/blender/draw/intern/draw_manager_data.cc b/source/blender/draw/intern/draw_manager_data.cc index a88d59fbd28..2079baf53a2 100644 --- a/source/blender/draw/intern/draw_manager_data.cc +++ b/source/blender/draw/intern/draw_manager_data.cc @@ -256,7 +256,7 @@ void DRW_shgroup_uniform_texture_ex(DRWShadingGroup *shgroup, eGPUSamplerState sampler_state) { BLI_assert(tex != nullptr); - int loc = GPU_shader_get_texture_binding(shgroup->shader, name); + int loc = GPU_shader_get_sampler_binding(shgroup->shader, name); drw_shgroup_uniform_create_ex(shgroup, loc, DRW_UNIFORM_TEXTURE, tex, sampler_state, 0, 1); } @@ -271,7 +271,7 @@ void DRW_shgroup_uniform_texture_ref_ex(DRWShadingGroup *shgroup, eGPUSamplerState sampler_state) { BLI_assert(tex != nullptr); - int loc = GPU_shader_get_texture_binding(shgroup->shader, name); + int loc = GPU_shader_get_sampler_binding(shgroup->shader, name); drw_shgroup_uniform_create_ex(shgroup, loc, DRW_UNIFORM_TEXTURE_REF, tex, sampler_state, 0, 1); } @@ -283,14 +283,14 @@ void DRW_shgroup_uniform_texture_ref(DRWShadingGroup *shgroup, const char *name, void DRW_shgroup_uniform_image(DRWShadingGroup *shgroup, const char *name, const GPUTexture *tex) { BLI_assert(tex != nullptr); - int loc = GPU_shader_get_texture_binding(shgroup->shader, name); + int loc = GPU_shader_get_sampler_binding(shgroup->shader, name); drw_shgroup_uniform_create_ex(shgroup, loc, DRW_UNIFORM_IMAGE, tex, GPU_SAMPLER_DEFAULT, 0, 1); } void DRW_shgroup_uniform_image_ref(DRWShadingGroup *shgroup, const char *name, GPUTexture **tex) { BLI_assert(tex != nullptr); - int loc = GPU_shader_get_texture_binding(shgroup->shader, name); + int loc = GPU_shader_get_sampler_binding(shgroup->shader, name); drw_shgroup_uniform_create_ex( shgroup, loc, DRW_UNIFORM_IMAGE_REF, tex, GPU_SAMPLER_DEFAULT, 0, 1); } @@ -300,7 +300,7 @@ void DRW_shgroup_uniform_block_ex(DRWShadingGroup *shgroup, const GPUUniformBuf *ubo DRW_DEBUG_FILE_LINE_ARGS) { BLI_assert(ubo != nullptr); - int loc = GPU_shader_get_uniform_block_binding(shgroup->shader, name); + int loc = GPU_shader_get_ubo_binding(shgroup->shader, name); if (loc == -1) { #ifdef DRW_UNUSED_RESOURCE_TRACKING printf("%s:%d: Unable to locate binding of shader uniform buffer object: %s.\n", @@ -321,7 +321,7 @@ void DRW_shgroup_uniform_block_ref_ex(DRWShadingGroup *shgroup, GPUUniformBuf **ubo DRW_DEBUG_FILE_LINE_ARGS) { BLI_assert(ubo != nullptr); - int loc = GPU_shader_get_uniform_block_binding(shgroup->shader, name); + int loc = GPU_shader_get_ubo_binding(shgroup->shader, name); if (loc == -1) { #ifdef DRW_UNUSED_RESOURCE_TRACKING printf("%s:%d: Unable to locate binding of shader uniform buffer object: %s.\n", @@ -344,7 +344,7 @@ void DRW_shgroup_storage_block_ex(DRWShadingGroup *shgroup, { BLI_assert(ssbo != nullptr); /* TODO(@fclem): Fix naming inconsistency. */ - int loc = GPU_shader_get_ssbo(shgroup->shader, name); + int loc = GPU_shader_get_ssbo_binding(shgroup->shader, name); if (loc == -1) { #ifdef DRW_UNUSED_RESOURCE_TRACKING printf("%s:%d: Unable to locate binding of shader storage buffer object: %s.\n", @@ -367,7 +367,7 @@ void DRW_shgroup_storage_block_ref_ex(DRWShadingGroup *shgroup, { BLI_assert(ssbo != nullptr); /* TODO(@fclem): Fix naming inconsistency. */ - int loc = GPU_shader_get_ssbo(shgroup->shader, name); + int loc = GPU_shader_get_ssbo_binding(shgroup->shader, name); if (loc == -1) { #ifdef DRW_UNUSED_RESOURCE_TRACKING printf("%s:%d: Unable to locate binding of shader storage buffer object: %s.\n", @@ -539,7 +539,7 @@ void DRW_shgroup_vertex_buffer_ex(DRWShadingGroup *shgroup, const char *name, GPUVertBuf *vertex_buffer DRW_DEBUG_FILE_LINE_ARGS) { - int location = GPU_shader_get_ssbo(shgroup->shader, name); + int location = GPU_shader_get_ssbo_binding(shgroup->shader, name); if (location == -1) { #ifdef DRW_UNUSED_RESOURCE_TRACKING printf("%s:%d: Unable to locate binding of shader storage buffer object: %s.\n", @@ -564,7 +564,7 @@ void DRW_shgroup_vertex_buffer_ref_ex(DRWShadingGroup *shgroup, const char *name, GPUVertBuf **vertex_buffer DRW_DEBUG_FILE_LINE_ARGS) { - int location = GPU_shader_get_ssbo(shgroup->shader, name); + int location = GPU_shader_get_ssbo_binding(shgroup->shader, name); if (location == -1) { #ifdef DRW_UNUSED_RESOURCE_TRACKING printf("%s:%d: Unable to locate binding of shader storage buffer object: %s.\n", @@ -589,7 +589,7 @@ void DRW_shgroup_buffer_texture(DRWShadingGroup *shgroup, const char *name, GPUVertBuf *vertex_buffer) { - int location = GPU_shader_get_texture_binding(shgroup->shader, name); + int location = GPU_shader_get_sampler_binding(shgroup->shader, name); if (location == -1) { return; } @@ -606,7 +606,7 @@ void DRW_shgroup_buffer_texture_ref(DRWShadingGroup *shgroup, const char *name, GPUVertBuf **vertex_buffer) { - int location = GPU_shader_get_texture_binding(shgroup->shader, name); + int location = GPU_shader_get_sampler_binding(shgroup->shader, name); if (location == -1) { return; } @@ -698,7 +698,7 @@ static void drw_call_obinfos_init(DRWObjectInfos *ob_infos, Object *ob) drw_call_calc_orco(ob, ob_infos->orcotexfac); /* Random float value. */ uint random = (DST.dupli_source) ? - DST.dupli_source->random_id : + DST.dupli_source->random_id : /* TODO(fclem): this is rather costly to do at runtime. Maybe we can * put it in ob->runtime and make depsgraph ensure it is up to date. */ BLI_hash_int_2d(BLI_hash_string(ob->id.name + 2), 0); @@ -1850,15 +1850,14 @@ void DRW_shgroup_add_material_resources(DRWShadingGroup *grp, GPUMaterial *mater const GPUUniformAttrList *uattrs = GPU_material_uniform_attributes(material); if (uattrs != nullptr) { - int loc = GPU_shader_get_uniform_block_binding(grp->shader, GPU_ATTRIBUTE_UBO_BLOCK_NAME); + int loc = GPU_shader_get_ubo_binding(grp->shader, GPU_ATTRIBUTE_UBO_BLOCK_NAME); drw_shgroup_uniform_create_ex( grp, loc, DRW_UNIFORM_BLOCK_OBATTRS, uattrs, GPU_SAMPLER_DEFAULT, 0, 1); grp->uniform_attrs = uattrs; } if (GPU_material_layer_attributes(material) != nullptr) { - int loc = GPU_shader_get_uniform_block_binding(grp->shader, - GPU_LAYER_ATTRIBUTE_UBO_BLOCK_NAME); + int loc = GPU_shader_get_ubo_binding(grp->shader, GPU_LAYER_ATTRIBUTE_UBO_BLOCK_NAME); drw_shgroup_uniform_create_ex( grp, loc, DRW_UNIFORM_BLOCK_VLATTRS, nullptr, GPU_SAMPLER_DEFAULT, 0, 1); } diff --git a/source/blender/draw/intern/draw_pass.hh b/source/blender/draw/intern/draw_pass.hh index 8fc8298491e..d05564c415a 100644 --- a/source/blender/draw/intern/draw_pass.hh +++ b/source/blender/draw/intern/draw_pass.hh @@ -861,42 +861,42 @@ template inline int PassBase::push_constant_offset(const char *name) template inline void PassBase::bind_ssbo(const char *name, GPUStorageBuf *buffer) { - this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer); + this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer); } template inline void PassBase::bind_ssbo(const char *name, GPUUniformBuf *buffer) { - this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer); + this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer); } template inline void PassBase::bind_ssbo(const char *name, GPUUniformBuf **buffer) { - this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer); + this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer); } template inline void PassBase::bind_ssbo(const char *name, GPUVertBuf *buffer) { - this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer); + this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer); } template inline void PassBase::bind_ssbo(const char *name, GPUVertBuf **buffer) { - this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer); + this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer); } template inline void PassBase::bind_ssbo(const char *name, GPUIndexBuf *buffer) { - this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer); + this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer); } template inline void PassBase::bind_ssbo(const char *name, GPUIndexBuf **buffer) { - this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer); + this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer); } template inline void PassBase::bind_ubo(const char *name, GPUUniformBuf *buffer) { - this->bind_ubo(GPU_shader_get_uniform_block_binding(shader_, name), buffer); + this->bind_ubo(GPU_shader_get_ubo_binding(shader_, name), buffer); } template @@ -904,22 +904,22 @@ inline void PassBase::bind_texture(const char *name, GPUTexture *texture, eGPUSamplerState state) { - this->bind_texture(GPU_shader_get_texture_binding(shader_, name), texture, state); + this->bind_texture(GPU_shader_get_sampler_binding(shader_, name), texture, state); } template inline void PassBase::bind_texture(const char *name, GPUVertBuf *buffer) { - this->bind_texture(GPU_shader_get_texture_binding(shader_, name), buffer); + this->bind_texture(GPU_shader_get_sampler_binding(shader_, name), buffer); } template inline void PassBase::bind_texture(const char *name, GPUVertBuf **buffer) { - this->bind_texture(GPU_shader_get_texture_binding(shader_, name), buffer); + this->bind_texture(GPU_shader_get_sampler_binding(shader_, name), buffer); } template inline void PassBase::bind_image(const char *name, GPUTexture *image) { - this->bind_image(GPU_shader_get_texture_binding(shader_, name), image); + this->bind_image(GPU_shader_get_sampler_binding(shader_, name), image); } template inline void PassBase::bind_ssbo(int slot, GPUStorageBuf *buffer) @@ -991,12 +991,12 @@ template inline void PassBase::bind_image(int slot, GPUTexture *imag template inline void PassBase::bind_ssbo(const char *name, GPUStorageBuf **buffer) { - this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer); + this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer); } template inline void PassBase::bind_ubo(const char *name, GPUUniformBuf **buffer) { - this->bind_ubo(GPU_shader_get_uniform_block_binding(shader_, name), buffer); + this->bind_ubo(GPU_shader_get_ubo_binding(shader_, name), buffer); } template @@ -1004,12 +1004,12 @@ inline void PassBase::bind_texture(const char *name, GPUTexture **texture, eGPUSamplerState state) { - this->bind_texture(GPU_shader_get_texture_binding(shader_, name), texture, state); + this->bind_texture(GPU_shader_get_sampler_binding(shader_, name), texture, state); } template inline void PassBase::bind_image(const char *name, GPUTexture **image) { - this->bind_image(GPU_shader_get_texture_binding(shader_, name), image); + this->bind_image(GPU_shader_get_sampler_binding(shader_, name), image); } template inline void PassBase::bind_ssbo(int slot, GPUStorageBuf **buffer) diff --git a/source/blender/draw/intern/draw_view.cc b/source/blender/draw/intern/draw_view.cc index 670b0c5ecf5..46fd82a239e 100644 --- a/source/blender/draw/intern/draw_view.cc +++ b/source/blender/draw/intern/draw_view.cc @@ -244,7 +244,7 @@ void View::compute_procedural_bounds() GPUShader *shader = DRW_shader_draw_view_finalize_get(); GPU_shader_bind(shader); - GPU_uniformbuf_bind_as_ssbo(culling_, GPU_shader_get_ssbo(shader, "view_culling_buf")); + GPU_uniformbuf_bind_as_ssbo(culling_, GPU_shader_get_ssbo_binding(shader, "view_culling_buf")); GPU_uniformbuf_bind(data_, DRW_VIEW_UBO_SLOT); GPU_compute_dispatch(shader, 1, 1, 1); GPU_memory_barrier(GPU_BARRIER_UNIFORM); @@ -289,8 +289,8 @@ void View::compute_visibility(ObjectBoundsBuf &bounds, uint resource_len, bool d GPU_shader_uniform_1i(shader, "resource_len", resource_len); GPU_shader_uniform_1i(shader, "view_len", view_len_); GPU_shader_uniform_1i(shader, "visibility_word_per_draw", word_per_draw); - GPU_storagebuf_bind(bounds, GPU_shader_get_ssbo(shader, "bounds_buf")); - GPU_storagebuf_bind(visibility_buf_, GPU_shader_get_ssbo(shader, "visibility_buf")); + GPU_storagebuf_bind(bounds, GPU_shader_get_ssbo_binding(shader, "bounds_buf")); + GPU_storagebuf_bind(visibility_buf_, GPU_shader_get_ssbo_binding(shader, "visibility_buf")); GPU_uniformbuf_bind(frozen_ ? data_freeze_ : data_, DRW_VIEW_UBO_SLOT); GPU_uniformbuf_bind(frozen_ ? culling_freeze_ : culling_, DRW_VIEW_CULLING_UBO_SLOT); GPU_compute_dispatch(shader, divide_ceil_u(resource_len, DRW_VISIBILITY_GROUP_SIZE), 1, 1); diff --git a/source/blender/editors/interface/interface_icons.cc b/source/blender/editors/interface/interface_icons.cc index 7959339980a..634f45283f6 100644 --- a/source/blender/editors/interface/interface_icons.cc +++ b/source/blender/editors/interface/interface_icons.cc @@ -1620,12 +1620,12 @@ static void icon_draw_cache_texture_flush_ex(GPUTexture *texture, GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR); GPU_shader_bind(shader); - const int data_binding = GPU_shader_get_uniform_block_binding(shader, "multi_rect_data"); + const int data_binding = GPU_shader_get_ubo_binding(shader, "multi_rect_data"); GPUUniformBuf *ubo = GPU_uniformbuf_create_ex( sizeof(MultiRectCallData), texture_draw_calls->drawcall_cache, __func__); GPU_uniformbuf_bind(ubo, data_binding); - const int img_binding = GPU_shader_get_texture_binding(shader, "image"); + const int img_binding = GPU_shader_get_sampler_binding(shader, "image"); GPU_texture_bind_ex(texture, GPU_SAMPLER_ICON, img_binding, false); GPUBatch *quad = GPU_batch_preset_quad(); @@ -1797,7 +1797,7 @@ static void icon_draw_texture(float x, GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_ICON); GPU_shader_bind(shader); - const int img_binding = GPU_shader_get_texture_binding(shader, "image"); + const int img_binding = GPU_shader_get_sampler_binding(shader, "image"); const int color_loc = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_COLOR); const int rect_tex_loc = GPU_shader_get_uniform(shader, "rect_icon"); const int rect_geom_loc = GPU_shader_get_uniform(shader, "rect_geom"); diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h index 1e5adab15d4..35d2d3f6e1a 100644 --- a/source/blender/gpu/GPU_batch.h +++ b/source/blender/gpu/GPU_batch.h @@ -263,9 +263,9 @@ void GPU_batch_program_set_imm_shader(GPUBatch *batch); #define GPU_batch_uniform_mat4(batch, name, val) \ GPU_shader_uniform_mat4((batch)->shader, name, val); #define GPU_batch_uniformbuf_bind(batch, name, ubo) \ - GPU_uniformbuf_bind(ubo, GPU_shader_get_uniform_block_binding((batch)->shader, name)); + GPU_uniformbuf_bind(ubo, GPU_shader_get_ubo_binding((batch)->shader, name)); #define GPU_batch_texture_bind(batch, name, tex) \ - GPU_texture_bind(tex, GPU_shader_get_texture_binding((batch)->shader, name)); + GPU_texture_bind(tex, GPU_shader_get_sampler_binding((batch)->shader, name)); /** \} */ diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index d1824de62ed..bbb74f1970e 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -112,12 +112,11 @@ const char *GPU_shader_get_name(GPUShader *shader); /** * Returns binding point location. - * Binding location are given to be set at compile time and immutable. + * Binding location are given to be set at shader compile time and immutable. */ -/* TODO(fclem): Make naming consistent. ubo_binding, ssbo_binding */ -int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name); -int GPU_shader_get_texture_binding(GPUShader *shader, const char *name); -int GPU_shader_get_ssbo(GPUShader *shader, const char *name); +int GPU_shader_get_ubo_binding(GPUShader *shader, const char *name); +int GPU_shader_get_ssbo_binding(GPUShader *shader, const char *name); +int GPU_shader_get_sampler_binding(GPUShader *shader, const char *name); /** * Returns uniform location. diff --git a/source/blender/gpu/intern/gpu_immediate.cc b/source/blender/gpu/intern/gpu_immediate.cc index a983d1da6ca..ada34fdaeee 100644 --- a/source/blender/gpu/intern/gpu_immediate.cc +++ b/source/blender/gpu/intern/gpu_immediate.cc @@ -602,19 +602,19 @@ void immUniform1i(const char *name, int x) void immBindTexture(const char *name, GPUTexture *tex) { - int binding = GPU_shader_get_texture_binding(imm->shader, name); + int binding = GPU_shader_get_sampler_binding(imm->shader, name); GPU_texture_bind(tex, binding); } void immBindTextureSampler(const char *name, GPUTexture *tex, eGPUSamplerState state) { - int binding = GPU_shader_get_texture_binding(imm->shader, name); + int binding = GPU_shader_get_sampler_binding(imm->shader, name); 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); + int binding = GPU_shader_get_ubo_binding(imm->shader, name); GPU_uniformbuf_bind(ubo, binding); } diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc index b073f993919..8d845b36d5b 100644 --- a/source/blender/gpu/intern/gpu_shader.cc +++ b/source/blender/gpu/intern/gpu_shader.cc @@ -549,7 +549,7 @@ int GPU_shader_get_builtin_ssbo(GPUShader *shader, int builtin) return interface->ssbo_builtin((GPUStorageBufferBuiltin)builtin); } -int GPU_shader_get_ssbo(GPUShader *shader, const char *name) +int GPU_shader_get_ssbo_binding(GPUShader *shader, const char *name) { const ShaderInterface *interface = unwrap(shader)->interface; const ShaderInput *ssbo = interface->ssbo_get(name); @@ -563,14 +563,14 @@ int GPU_shader_get_uniform_block(GPUShader *shader, const char *name) return ubo ? ubo->location : -1; } -int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name) +int GPU_shader_get_ubo_binding(GPUShader *shader, const char *name) { const ShaderInterface *interface = unwrap(shader)->interface; const ShaderInput *ubo = interface->ubo_get(name); return ubo ? ubo->binding : -1; } -int GPU_shader_get_texture_binding(GPUShader *shader, const char *name) +int GPU_shader_get_sampler_binding(GPUShader *shader, const char *name) { const ShaderInterface *interface = unwrap(shader)->interface; const ShaderInput *tex = interface->uniform_get(name); diff --git a/source/blender/gpu/tests/gpu_shader_test.cc b/source/blender/gpu/tests/gpu_shader_test.cc index c07fda843c7..ce1397f3327 100644 --- a/source/blender/gpu/tests/gpu_shader_test.cc +++ b/source/blender/gpu/tests/gpu_shader_test.cc @@ -47,7 +47,7 @@ static void test_gpu_shader_compute_2d() EXPECT_NE(texture, nullptr); GPU_shader_bind(shader); - GPU_texture_image_bind(texture, GPU_shader_get_texture_binding(shader, "img_output")); + GPU_texture_image_bind(texture, GPU_shader_get_sampler_binding(shader, "img_output")); /* Dispatch compute task. */ GPU_compute_dispatch(shader, SIZE, SIZE, 1); @@ -93,7 +93,7 @@ static void test_gpu_shader_compute_1d() EXPECT_NE(texture, nullptr); GPU_shader_bind(shader); - GPU_texture_image_bind(texture, GPU_shader_get_texture_binding(shader, "img_output")); + GPU_texture_image_bind(texture, GPU_shader_get_sampler_binding(shader, "img_output")); /* Dispatch compute task. */ GPU_compute_dispatch(shader, SIZE, 1, 1); @@ -142,7 +142,7 @@ static void test_gpu_shader_compute_vbo() GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); GPUVertBuf *vbo = GPU_vertbuf_create_with_format_ex(&format, GPU_USAGE_DEVICE_ONLY); GPU_vertbuf_data_alloc(vbo, SIZE); - GPU_vertbuf_bind_as_ssbo(vbo, GPU_shader_get_ssbo(shader, "out_positions")); + GPU_vertbuf_bind_as_ssbo(vbo, GPU_shader_get_ssbo_binding(shader, "out_positions")); /* Dispatch compute task. */ GPU_compute_dispatch(shader, SIZE, 1, 1); @@ -186,7 +186,7 @@ static void test_gpu_shader_compute_ibo() /* Construct IBO. */ GPUIndexBuf *ibo = GPU_indexbuf_build_on_device(SIZE); - GPU_indexbuf_bind_as_ssbo(ibo, GPU_shader_get_ssbo(shader, "out_indices")); + GPU_indexbuf_bind_as_ssbo(ibo, GPU_shader_get_ssbo_binding(shader, "out_indices")); /* Dispatch compute task. */ GPU_compute_dispatch(shader, SIZE, 1, 1); @@ -228,7 +228,7 @@ static void test_gpu_shader_compute_ssbo() /* Construct IBO. */ GPUStorageBuf *ssbo = GPU_storagebuf_create_ex( SIZE * sizeof(uint32_t), nullptr, GPU_USAGE_DEVICE_ONLY, __func__); - GPU_storagebuf_bind(ssbo, GPU_shader_get_ssbo(shader, "out_indices")); + GPU_storagebuf_bind(ssbo, GPU_shader_get_ssbo_binding(shader, "out_indices")); /* Dispatch compute task. */ GPU_compute_dispatch(shader, SIZE, 1, 1); @@ -264,8 +264,8 @@ static void test_gpu_shader_ssbo_binding() EXPECT_NE(shader, nullptr); GPU_shader_bind(shader); - EXPECT_EQ(0, GPU_shader_get_ssbo(shader, "data0")); - EXPECT_EQ(1, GPU_shader_get_ssbo(shader, "data1")); + EXPECT_EQ(0, GPU_shader_get_ssbo_binding(shader, "data0")); + EXPECT_EQ(1, GPU_shader_get_ssbo_binding(shader, "data1")); /* Cleanup. */ GPU_shader_unbind(); diff --git a/source/blender/nodes/composite/nodes/node_composite_composite.cc b/source/blender/nodes/composite/nodes/node_composite_composite.cc index 70e4c2b5d3b..dafa87f93f0 100644 --- a/source/blender/nodes/composite/nodes/node_composite_composite.cc +++ b/source/blender/nodes/composite/nodes/node_composite_composite.cc @@ -94,7 +94,7 @@ class CompositeOperation : public NodeOperation { image.bind_as_texture(shader, "input_tx"); GPUTexture *output_texture = context().get_output_texture(); - const int image_unit = GPU_shader_get_texture_binding(shader, "output_img"); + const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img"); GPU_texture_image_bind(output_texture, image_unit); const int2 compositing_region_size = context().get_compositing_region_size(); @@ -122,7 +122,7 @@ class CompositeOperation : public NodeOperation { image.bind_as_texture(shader, "input_tx"); GPUTexture *output_texture = context().get_output_texture(); - const int image_unit = GPU_shader_get_texture_binding(shader, "output_img"); + const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img"); GPU_texture_image_bind(output_texture, image_unit); const int2 compositing_region_size = context().get_compositing_region_size(); @@ -152,7 +152,7 @@ class CompositeOperation : public NodeOperation { alpha.bind_as_texture(shader, "alpha_tx"); GPUTexture *output_texture = context().get_output_texture(); - const int image_unit = GPU_shader_get_texture_binding(shader, "output_img"); + const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img"); GPU_texture_image_bind(output_texture, image_unit); const int2 compositing_region_size = context().get_compositing_region_size(); diff --git a/source/blender/nodes/composite/nodes/node_composite_dilate.cc b/source/blender/nodes/composite/nodes/node_composite_dilate.cc index 07063c1a06b..b34a7bd6646 100644 --- a/source/blender/nodes/composite/nodes/node_composite_dilate.cc +++ b/source/blender/nodes/composite/nodes/node_composite_dilate.cc @@ -122,7 +122,7 @@ class DilateErodeOperation : public NodeOperation { const int2 transposed_domain = int2(domain.size.y, domain.size.x); GPUTexture *horizontal_pass_result = texture_pool().acquire_color(transposed_domain); - const int image_unit = GPU_shader_get_texture_binding(shader, "output_img"); + const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img"); GPU_texture_image_bind(horizontal_pass_result, image_unit); compute_dispatch_threads_at_least(shader, domain.size); @@ -143,7 +143,7 @@ class DilateErodeOperation : public NodeOperation { GPU_shader_uniform_1i(shader, "radius", math::abs(get_distance())); GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH); - const int texture_image_unit = GPU_shader_get_texture_binding(shader, "input_tx"); + const int texture_image_unit = GPU_shader_get_sampler_binding(shader, "input_tx"); GPU_texture_bind(horizontal_pass_result, texture_image_unit); const Domain domain = compute_domain(); @@ -273,7 +273,7 @@ class DilateErodeOperation : public NodeOperation { const int2 transposed_domain = int2(domain.size.y, domain.size.x); GPUTexture *horizontal_pass_result = texture_pool().acquire_color(transposed_domain); - const int image_unit = GPU_shader_get_texture_binding(shader, "output_img"); + const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img"); GPU_texture_image_bind(horizontal_pass_result, image_unit); compute_dispatch_threads_at_least(shader, domain.size); @@ -293,7 +293,7 @@ class DilateErodeOperation : public NodeOperation { GPU_shader_bind(shader); GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH); - const int texture_image_unit = GPU_shader_get_texture_binding(shader, "input_tx"); + const int texture_image_unit = GPU_shader_get_sampler_binding(shader, "input_tx"); GPU_texture_bind(horizontal_pass_result, texture_image_unit); const MorphologicalDistanceFeatherWeights &weights = diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc index ad49d687220..27b864f9856 100644 --- a/source/blender/nodes/composite/nodes/node_composite_image.cc +++ b/source/blender/nodes/composite/nodes/node_composite_image.cc @@ -525,7 +525,7 @@ class ImageOperation : public NodeOperation { GPUShader *shader = shader_manager().get(get_shader_name(identifier)); GPU_shader_bind(shader); - const int input_unit = GPU_shader_get_texture_binding(shader, "input_tx"); + const int input_unit = GPU_shader_get_sampler_binding(shader, "input_tx"); GPU_texture_bind(image_texture, input_unit); result.bind_as_image(shader, "output_img"); @@ -859,7 +859,7 @@ class RenderLayerOperation : public NodeOperation { const int2 lower_bound = int2(compositing_region.xmin, compositing_region.ymin); GPU_shader_uniform_2iv(shader, "compositing_region_lower_bound", lower_bound); - const int input_unit = GPU_shader_get_texture_binding(shader, "input_tx"); + const int input_unit = GPU_shader_get_sampler_binding(shader, "input_tx"); GPU_texture_bind(pass_texture, input_unit); const int2 compositing_region_size = context().get_compositing_region_size(); @@ -889,7 +889,7 @@ class RenderLayerOperation : public NodeOperation { const int2 lower_bound = int2(compositing_region.xmin, compositing_region.ymin); GPU_shader_uniform_2iv(shader, "compositing_region_lower_bound", lower_bound); - const int input_unit = GPU_shader_get_texture_binding(shader, "input_tx"); + const int input_unit = GPU_shader_get_sampler_binding(shader, "input_tx"); GPU_texture_bind(pass_texture, input_unit); const int2 compositing_region_size = context().get_compositing_region_size(); diff --git a/source/blender/nodes/composite/nodes/node_composite_movieclip.cc b/source/blender/nodes/composite/nodes/node_composite_movieclip.cc index c55df061873..a3fa99d8356 100644 --- a/source/blender/nodes/composite/nodes/node_composite_movieclip.cc +++ b/source/blender/nodes/composite/nodes/node_composite_movieclip.cc @@ -128,7 +128,7 @@ class MovieClipOperation : public NodeOperation { GPUShader *shader = shader_manager().get("compositor_convert_color_to_half_color"); GPU_shader_bind(shader); - const int input_unit = GPU_shader_get_texture_binding(shader, "input_tx"); + const int input_unit = GPU_shader_get_sampler_binding(shader, "input_tx"); GPU_texture_bind(movie_clip_texture, input_unit); result.bind_as_image(shader, "output_img"); @@ -162,7 +162,7 @@ class MovieClipOperation : public NodeOperation { GPUShader *shader = shader_manager().get("compositor_extract_alpha_from_color"); GPU_shader_bind(shader); - const int input_unit = GPU_shader_get_texture_binding(shader, "input_tx"); + const int input_unit = GPU_shader_get_sampler_binding(shader, "input_tx"); GPU_texture_bind(movie_clip_texture, input_unit); result.bind_as_image(shader, "output_img"); diff --git a/source/blender/nodes/composite/nodes/node_composite_split_viewer.cc b/source/blender/nodes/composite/nodes/node_composite_split_viewer.cc index 73dcf42904c..c03a3a42dc9 100644 --- a/source/blender/nodes/composite/nodes/node_composite_split_viewer.cc +++ b/source/blender/nodes/composite/nodes/node_composite_split_viewer.cc @@ -77,7 +77,7 @@ class ViewerOperation : public NodeOperation { second_image.bind_as_texture(shader, "second_image_tx"); GPUTexture *output_texture = context().get_output_texture(); - const int image_unit = GPU_shader_get_texture_binding(shader, "output_img"); + const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img"); GPU_texture_image_bind(output_texture, image_unit); compute_dispatch_threads_at_least(shader, compositing_region_size); diff --git a/source/blender/nodes/composite/nodes/node_composite_viewer.cc b/source/blender/nodes/composite/nodes/node_composite_viewer.cc index 66a16905d67..0beee8621ac 100644 --- a/source/blender/nodes/composite/nodes/node_composite_viewer.cc +++ b/source/blender/nodes/composite/nodes/node_composite_viewer.cc @@ -123,7 +123,7 @@ class ViewerOperation : public NodeOperation { image.bind_as_texture(shader, "input_tx"); GPUTexture *output_texture = context().get_output_texture(); - const int image_unit = GPU_shader_get_texture_binding(shader, "output_img"); + const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img"); GPU_texture_image_bind(output_texture, image_unit); const int2 compositing_region_size = context().get_compositing_region_size(); @@ -151,7 +151,7 @@ class ViewerOperation : public NodeOperation { image.bind_as_texture(shader, "input_tx"); GPUTexture *output_texture = context().get_output_texture(); - const int image_unit = GPU_shader_get_texture_binding(shader, "output_img"); + const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img"); GPU_texture_image_bind(output_texture, image_unit); const int2 compositing_region_size = context().get_compositing_region_size(); @@ -181,7 +181,7 @@ class ViewerOperation : public NodeOperation { alpha.bind_as_texture(shader, "alpha_tx"); GPUTexture *output_texture = context().get_output_texture(); - const int image_unit = GPU_shader_get_texture_binding(shader, "output_img"); + const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img"); GPU_texture_image_bind(output_texture, image_unit); const int2 compositing_region_size = context().get_compositing_region_size(); diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c index 9352e7cc9b1..2c13e271e36 100644 --- a/source/blender/python/gpu/gpu_py_shader.c +++ b/source/blender/python/gpu/gpu_py_shader.c @@ -533,7 +533,7 @@ static PyObject *pygpu_shader_uniform_sampler(BPyGPUShader *self, PyObject *args } GPU_shader_bind(self->shader); - int slot = GPU_shader_get_texture_binding(self->shader, name); + int slot = GPU_shader_get_sampler_binding(self->shader, name); GPU_texture_bind(py_texture->tex, slot); GPU_shader_uniform_1i(self->shader, name, slot); @@ -559,7 +559,7 @@ static PyObject *pygpu_shader_uniform_block(BPyGPUShader *self, PyObject *args) return NULL; } - int binding = GPU_shader_get_uniform_block_binding(self->shader, name); + int binding = GPU_shader_get_ubo_binding(self->shader, name); if (binding == -1) { PyErr_SetString( PyExc_BufferError, diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index 290fd602dfa..5ce080e575a 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -842,7 +842,7 @@ void wm_draw_region_blend(ARegion *region, int view, bool blend) int color_loc = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_COLOR); int rect_tex_loc = GPU_shader_get_uniform(shader, "rect_icon"); int rect_geo_loc = GPU_shader_get_uniform(shader, "rect_geom"); - int texture_bind_loc = GPU_shader_get_texture_binding(shader, "image"); + int texture_bind_loc = GPU_shader_get_sampler_binding(shader, "image"); GPU_texture_bind(texture, texture_bind_loc); -- 2.30.2 From 699e9369dc3b36f24e0b3c1aef2f0b99c0a6fd55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Sun, 12 Feb 2023 23:04:04 +0100 Subject: [PATCH 08/11] GPU: Removes GPU_shader_get_builtin_ssbo Simplify the API. Use hardcoded ssbo location instead. --- source/blender/draw/intern/draw_debug.cc | 10 +++---- .../blender/draw/intern/draw_manager_data.cc | 30 ------------------- .../draw/intern/shaders/draw_debug_info.hh | 4 +-- source/blender/gpu/GPU_shader.h | 11 ------- source/blender/gpu/intern/gpu_shader.cc | 6 ---- .../gpu/intern/gpu_shader_interface.hh | 21 ------------- .../blender/gpu/opengl/gl_shader_interface.cc | 14 --------- 7 files changed, 6 insertions(+), 90 deletions(-) diff --git a/source/blender/draw/intern/draw_debug.cc b/source/blender/draw/intern/draw_debug.cc index ca17aa1de82..4698d6eb5ff 100644 --- a/source/blender/draw/intern/draw_debug.cc +++ b/source/blender/draw/intern/draw_debug.cc @@ -523,19 +523,18 @@ void DebugDraw::display_lines() GPUBatch *batch = drw_cache_procedural_lines_get(); GPUShader *shader = DRW_shader_debug_draw_display_get(); GPU_batch_set_shader(batch, shader); - int slot = GPU_shader_get_builtin_ssbo(shader, GPU_STORAGE_BUFFER_DEBUG_VERTS); GPU_shader_uniform_mat4(shader, "persmat", persmat.ptr()); if (gpu_draw_buf_used) { GPU_debug_group_begin("GPU"); - GPU_storagebuf_bind(gpu_draw_buf_, slot); + GPU_storagebuf_bind(gpu_draw_buf_, DRW_DEBUG_DRAW_SLOT); GPU_batch_draw_indirect(batch, gpu_draw_buf_, 0); GPU_storagebuf_unbind(gpu_draw_buf_); GPU_debug_group_end(); } GPU_debug_group_begin("CPU"); - GPU_storagebuf_bind(cpu_draw_buf_, slot); + GPU_storagebuf_bind(cpu_draw_buf_, DRW_DEBUG_DRAW_SLOT); GPU_batch_draw_indirect(batch, cpu_draw_buf_, 0); GPU_storagebuf_unbind(cpu_draw_buf_); GPU_debug_group_end(); @@ -556,21 +555,20 @@ void DebugDraw::display_prints() GPUBatch *batch = drw_cache_procedural_points_get(); GPUShader *shader = DRW_shader_debug_print_display_get(); GPU_batch_set_shader(batch, shader); - int slot = GPU_shader_get_builtin_ssbo(shader, GPU_STORAGE_BUFFER_DEBUG_PRINT); float f_viewport[4]; GPU_viewport_size_get_f(f_viewport); GPU_shader_uniform_2fv(shader, "viewport_size", &f_viewport[2]); if (gpu_print_buf_used) { GPU_debug_group_begin("GPU"); - GPU_storagebuf_bind(gpu_print_buf_, slot); + GPU_storagebuf_bind(gpu_print_buf_, DRW_DEBUG_PRINT_SLOT); GPU_batch_draw_indirect(batch, gpu_print_buf_, 0); GPU_storagebuf_unbind(gpu_print_buf_); GPU_debug_group_end(); } GPU_debug_group_begin("CPU"); - GPU_storagebuf_bind(cpu_print_buf_, slot); + GPU_storagebuf_bind(cpu_print_buf_, DRW_DEBUG_PRINT_SLOT); GPU_batch_draw_indirect(batch, cpu_print_buf_, 0); GPU_storagebuf_unbind(cpu_print_buf_); GPU_debug_group_end(); diff --git a/source/blender/draw/intern/draw_manager_data.cc b/source/blender/draw/intern/draw_manager_data.cc index 2079baf53a2..546ccbf7ef8 100644 --- a/source/blender/draw/intern/draw_manager_data.cc +++ b/source/blender/draw/intern/draw_manager_data.cc @@ -1719,36 +1719,6 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader) 1); } -#ifdef DEBUG - /* TODO(Metal): Support Shader debug print. - * This is not currently supported by Metal Backend. */ - if (GPU_backend_get_type() != GPU_BACKEND_METAL) { - int debug_print_location = GPU_shader_get_builtin_ssbo(shader, GPU_STORAGE_BUFFER_DEBUG_PRINT); - if (debug_print_location != -1) { - GPUStorageBuf *buf = drw_debug_gpu_print_buf_get(); - drw_shgroup_uniform_create_ex(shgroup, - debug_print_location, - DRW_UNIFORM_STORAGE_BLOCK, - buf, - GPU_SAMPLER_DEFAULT, - 0, - 1); -# ifndef DISABLE_DEBUG_SHADER_PRINT_BARRIER - /* Add a barrier to allow multiple shader writing to the same buffer. */ - DRW_shgroup_barrier(shgroup, GPU_BARRIER_SHADER_STORAGE); -# endif - } - - int debug_draw_location = GPU_shader_get_builtin_ssbo(shader, GPU_STORAGE_BUFFER_DEBUG_VERTS); - if (debug_draw_location != -1) { - GPUStorageBuf *buf = drw_debug_gpu_draw_buf_get(); - drw_shgroup_uniform_create_ex( - shgroup, debug_draw_location, DRW_UNIFORM_STORAGE_BLOCK, buf, GPU_SAMPLER_DEFAULT, 0, 1); - /* NOTE(fclem): No barrier as ordering is not important. */ - } - } -#endif - /* Not supported. */ BLI_assert(GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODELVIEW_INV) == -1); BLI_assert(GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODELVIEW) == -1); diff --git a/source/blender/draw/intern/shaders/draw_debug_info.hh b/source/blender/draw/intern/shaders/draw_debug_info.hh index 4b5590824ba..e2dc2d0208e 100644 --- a/source/blender/draw/intern/shaders/draw_debug_info.hh +++ b/source/blender/draw/intern/shaders/draw_debug_info.hh @@ -18,7 +18,7 @@ GPU_SHADER_INTERFACE_INFO(draw_debug_print_display_iface, "").flat(Type::UINT, " GPU_SHADER_CREATE_INFO(draw_debug_print_display) .do_static_compilation(true) .typedef_source("draw_shader_shared.h") - .storage_buf(7, Qualifier::READ, "uint", "drw_debug_print_buf[]") + .storage_buf(DRW_DEBUG_PRINT_SLOT, Qualifier::READ, "uint", "drw_debug_print_buf[]") .vertex_out(draw_debug_print_display_iface) .fragment_out(0, Type::VEC4, "out_color") .push_constant(Type::VEC2, "viewport_size") @@ -46,7 +46,7 @@ GPU_SHADER_INTERFACE_INFO(draw_debug_draw_display_iface, "interp").flat(Type::VE GPU_SHADER_CREATE_INFO(draw_debug_draw_display) .do_static_compilation(true) .typedef_source("draw_shader_shared.h") - .storage_buf(6, Qualifier::READ, "DRWDebugVert", "drw_debug_verts_buf[]") + .storage_buf(DRW_DEBUG_DRAW_SLOT, Qualifier::READ, "DRWDebugVert", "drw_debug_verts_buf[]") .vertex_out(draw_debug_draw_display_iface) .fragment_out(0, Type::VEC4, "out_color") .push_constant(Type::MAT4, "persmat") diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index bbb74f1970e..6e9998af625 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -270,17 +270,6 @@ typedef enum { /** DEPRECATED: Use hardcoded buffer location instead. */ int GPU_shader_get_builtin_block(GPUShader *shader, int builtin); -/** DEPRECATED: Use hardcoded buffer location instead. */ -typedef enum { - GPU_STORAGE_BUFFER_DEBUG_VERTS = 0, /* drw_debug_verts_buf */ - GPU_STORAGE_BUFFER_DEBUG_PRINT, /* drw_debug_print_buf */ - - GPU_NUM_STORAGE_BUFFERS, /* Special value, denotes number of builtin buffer blocks. */ -} GPUStorageBufferBuiltin; - -/** DEPRECATED: Use hardcoded buffer location instead. */ -int GPU_shader_get_builtin_ssbo(GPUShader *shader, int builtin); - /** DEPRECATED: Kept only because of Python GPU API. */ int GPU_shader_get_uniform_block(GPUShader *shader, const char *name); diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc index 8d845b36d5b..6460e23e373 100644 --- a/source/blender/gpu/intern/gpu_shader.cc +++ b/source/blender/gpu/intern/gpu_shader.cc @@ -543,12 +543,6 @@ int GPU_shader_get_builtin_block(GPUShader *shader, int builtin) return interface->ubo_builtin((GPUUniformBlockBuiltin)builtin); } -int GPU_shader_get_builtin_ssbo(GPUShader *shader, int builtin) -{ - const ShaderInterface *interface = unwrap(shader)->interface; - return interface->ssbo_builtin((GPUStorageBufferBuiltin)builtin); -} - int GPU_shader_get_ssbo_binding(GPUShader *shader, const char *name) { const ShaderInterface *interface = unwrap(shader)->interface; diff --git a/source/blender/gpu/intern/gpu_shader_interface.hh b/source/blender/gpu/intern/gpu_shader_interface.hh index c27b5cc1a37..fc9eafca3a5 100644 --- a/source/blender/gpu/intern/gpu_shader_interface.hh +++ b/source/blender/gpu/intern/gpu_shader_interface.hh @@ -57,7 +57,6 @@ class ShaderInterface { /** Location of builtin uniforms. Fast access, no lookup needed. */ int32_t builtins_[GPU_NUM_UNIFORMS]; int32_t builtin_blocks_[GPU_NUM_UNIFORM_BLOCKS]; - int32_t builtin_buffers_[GPU_NUM_STORAGE_BUFFERS]; /** * Currently only used for `GPU_shader_get_attribute_info`. @@ -128,17 +127,9 @@ class ShaderInterface { return builtin_blocks_[builtin]; } - /* Returns binding position. */ - inline int32_t ssbo_builtin(const GPUStorageBufferBuiltin builtin) const - { - BLI_assert(builtin >= 0 && builtin < GPU_NUM_STORAGE_BUFFERS); - return builtin_buffers_[builtin]; - } - protected: static inline const char *builtin_uniform_name(GPUUniformBuiltin u); static inline const char *builtin_uniform_block_name(GPUUniformBlockBuiltin u); - static inline const char *builtin_storage_block_name(GPUStorageBufferBuiltin u); inline uint32_t set_input_name(ShaderInput *input, char *name, uint32_t name_len) const; inline void copy_input_name(ShaderInput *input, @@ -234,18 +225,6 @@ inline const char *ShaderInterface::builtin_uniform_block_name(GPUUniformBlockBu } } -inline const char *ShaderInterface::builtin_storage_block_name(GPUStorageBufferBuiltin u) -{ - switch (u) { - case GPU_STORAGE_BUFFER_DEBUG_VERTS: - return "drw_debug_verts_buf"; - case GPU_STORAGE_BUFFER_DEBUG_PRINT: - return "drw_debug_print_buf"; - default: - return nullptr; - } -} - /* Returns string length including '\0' terminator. */ inline uint32_t ShaderInterface::set_input_name(ShaderInput *input, char *name, diff --git a/source/blender/gpu/opengl/gl_shader_interface.cc b/source/blender/gpu/opengl/gl_shader_interface.cc index ef97d74bf81..4b10780e551 100644 --- a/source/blender/gpu/opengl/gl_shader_interface.cc +++ b/source/blender/gpu/opengl/gl_shader_interface.cc @@ -371,13 +371,6 @@ GLShaderInterface::GLShaderInterface(GLuint program) builtin_blocks_[u] = (block != nullptr) ? block->binding : -1; } - /* Builtin Storage Buffers */ - for (int32_t u_int = 0; u_int < GPU_NUM_STORAGE_BUFFERS; u_int++) { - GPUStorageBufferBuiltin u = static_cast(u_int); - const ShaderInput *block = this->ssbo_get(builtin_storage_block_name(u)); - builtin_buffers_[u] = (block != nullptr) ? block->binding : -1; - } - MEM_freeN(uniforms_from_blocks); /* Resize name buffer to save some memory. */ @@ -550,13 +543,6 @@ GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateI builtin_blocks_[u] = (block != nullptr) ? block->binding : -1; } - /* Builtin Storage Buffers */ - for (int32_t u_int = 0; u_int < GPU_NUM_STORAGE_BUFFERS; u_int++) { - GPUStorageBufferBuiltin u = static_cast(u_int); - const ShaderInput *block = this->ssbo_get(builtin_storage_block_name(u)); - builtin_buffers_[u] = (block != nullptr) ? block->binding : -1; - } - this->sort_inputs(); // this->debug_print(); -- 2.30.2 From 6bf20d4d5e93719443903699c8c0bbe8bec8d0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Sun, 12 Feb 2023 23:28:06 +0100 Subject: [PATCH 09/11] Cleanup: GPUShader: Remove `GPU_shader_uniform_int/float` Simplify the API, leaving only one function to set uniform without the uniform name. --- intern/cycles/blender/display_driver.cpp | 3 ++- source/blender/draw/intern/draw_manager_exec.c | 10 ++++++---- source/blender/editors/include/BIF_glutil.h | 2 +- source/blender/gpu/GPU_shader.h | 4 ---- source/blender/gpu/intern/gpu_shader.cc | 14 ++------------ source/blender/makesrna/intern/rna_render.c | 5 +---- 6 files changed, 12 insertions(+), 26 deletions(-) diff --git a/intern/cycles/blender/display_driver.cpp b/intern/cycles/blender/display_driver.cpp index 8df0061d8ca..e5b496dab87 100644 --- a/intern/cycles/blender/display_driver.cpp +++ b/intern/cycles/blender/display_driver.cpp @@ -105,7 +105,8 @@ GPUShader *BlenderFallbackDisplayShader::bind(int width, int height) /* Bind shader now to enable uniform assignment. */ GPU_shader_bind(shader_program_); - GPU_shader_uniform_int(shader_program_, image_texture_location_, 0); + float slot = 0; + GPU_shader_uniform_vector_int(shader_program_, image_texture_location_, 1, 1, &slot); float size[2]; size[0] = width; size[1] = height; diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 3be04137695..35a83d5635a 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -687,10 +687,12 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup, state->vlattrs_loc = uni->location; GPU_uniformbuf_bind(drw_ensure_layer_attribute_buffer(), uni->location); break; - case DRW_UNIFORM_RESOURCE_CHUNK: + case DRW_UNIFORM_RESOURCE_CHUNK: { state->chunkid_loc = uni->location; - GPU_shader_uniform_int(shgroup->shader, uni->location, 0); + int zero = 0; + GPU_shader_uniform_vector_int(shgroup->shader, uni->location, 1, 1, &zero); break; + } case DRW_UNIFORM_RESOURCE_ID: state->resourceid_loc = uni->location; break; @@ -807,7 +809,7 @@ static void draw_call_resource_bind(DRWCommandsState *state, const DRWResourceHa int chunk = DRW_handle_chunk_get(handle); if (state->resource_chunk != chunk) { if (state->chunkid_loc != -1) { - GPU_shader_uniform_int(DST.shader, state->chunkid_loc, chunk); + GPU_shader_uniform_vector_int(DST.shader, state->chunkid_loc, 1, 1, &chunk); } if (state->obmats_loc != -1) { GPU_uniformbuf_unbind(DST.vmempool->matrices_ubo[state->resource_chunk]); @@ -827,7 +829,7 @@ static void draw_call_resource_bind(DRWCommandsState *state, const DRWResourceHa if (state->resourceid_loc != -1) { int id = DRW_handle_id_get(handle); if (state->resource_id != id) { - GPU_shader_uniform_int(DST.shader, state->resourceid_loc, id); + GPU_shader_uniform_vector_int(DST.shader, state->resourceid_loc, 1, 1, &id); state->resource_id = id; } } diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h index 84512653a24..931e0c10575 100644 --- a/source/blender/editors/include/BIF_glutil.h +++ b/source/blender/editors/include/BIF_glutil.h @@ -34,7 +34,7 @@ typedef struct IMMDrawPixelsTexState { * To be used before calling #immDrawPixelsTex * Default shader is #GPU_SHADER_2D_IMAGE_COLOR * You can still set uniforms with: - * `GPU_shader_uniform_int(shader, GPU_shader_get_uniform(shader, "name"), 0);` + * `GPU_shader_uniform_*(shader, "name", value);` */ IMMDrawPixelsTexState immDrawPixelsTexSetup(int builtin); diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index 6e9998af625..c8a8f817f96 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -273,10 +273,6 @@ int GPU_shader_get_builtin_block(GPUShader *shader, int builtin); /** DEPRECATED: Kept only because of Python GPU API. */ int GPU_shader_get_uniform_block(GPUShader *shader, const char *name); -/** DEPRECATED: To be replaced by GPU_shader_uniform_vector. */ -void GPU_shader_uniform_float(GPUShader *shader, int location, float value); -void GPU_shader_uniform_int(GPUShader *shader, int location, int value); - /** \} */ #ifdef __cplusplus diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc index 6460e23e373..2875763fb5e 100644 --- a/source/blender/gpu/intern/gpu_shader.cc +++ b/source/blender/gpu/intern/gpu_shader.cc @@ -630,20 +630,10 @@ void GPU_shader_uniform_vector_int( unwrap(shader)->uniform_int(loc, len, array_size, value); } -void GPU_shader_uniform_int(GPUShader *shader, int location, int value) -{ - GPU_shader_uniform_vector_int(shader, location, 1, 1, &value); -} - -void GPU_shader_uniform_float(GPUShader *shader, int location, float value) -{ - GPU_shader_uniform_vector(shader, location, 1, 1, &value); -} - void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value) { const int loc = GPU_shader_get_uniform(sh, name); - GPU_shader_uniform_int(sh, loc, value); + GPU_shader_uniform_vector_int(sh, loc, 1, 1, &value); } void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value) @@ -672,7 +662,7 @@ void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, fl void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value) { const int loc = GPU_shader_get_uniform(sh, name); - GPU_shader_uniform_float(sh, loc, value); + GPU_shader_uniform_vector(sh, loc, 1, 1, &value); } void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2]) diff --git a/source/blender/makesrna/intern/rna_render.c b/source/blender/makesrna/intern/rna_render.c index 6a66445ee4c..5eb00175c33 100644 --- a/source/blender/makesrna/intern/rna_render.c +++ b/source/blender/makesrna/intern/rna_render.c @@ -120,10 +120,7 @@ static void engine_bind_display_space_shader(RenderEngine *UNUSED(engine), Scene { GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE); GPU_shader_bind(shader); - - int img_loc = GPU_shader_get_uniform(shader, "image"); - - GPU_shader_uniform_int(shader, img_loc, 0); + /** \note "image" binding slot is 0. */ } static void engine_unbind_display_space_shader(RenderEngine *UNUSED(engine)) -- 2.30.2 From d1b830f3eba019a2423a4b57d5fa93837901f623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Sun, 12 Feb 2023 23:39:48 +0100 Subject: [PATCH 10/11] Cleanup: GPUShader: Rename `GPU_shader_uniform_vector` Rename to `GPU_shader_uniform_float/int_ex` to make more sense as a general purpose function. --- intern/cycles/blender/display_driver.cpp | 4 ++-- source/blender/draw/intern/draw_command.cc | 8 +++---- .../blender/draw/intern/draw_manager_exec.c | 22 ++++++++--------- .../editors/interface/interface_icons.cc | 8 +++---- source/blender/editors/mask/mask_draw.c | 2 +- source/blender/gpu/GPU_shader.h | 4 ++-- source/blender/gpu/intern/gpu_immediate.cc | 2 +- source/blender/gpu/intern/gpu_matrix.cc | 13 +++++----- source/blender/gpu/intern/gpu_shader.cc | 24 +++++++++---------- source/blender/gpu/metal/mtl_batch.mm | 20 ++++++++-------- source/blender/gpu/metal/mtl_immediate.mm | 20 ++++++++-------- source/blender/python/gpu/gpu_py_shader.c | 10 ++++---- source/blender/windowmanager/intern/wm_draw.c | 6 ++--- .../blender/windowmanager/intern/wm_gesture.c | 2 +- 14 files changed, 73 insertions(+), 72 deletions(-) diff --git a/intern/cycles/blender/display_driver.cpp b/intern/cycles/blender/display_driver.cpp index e5b496dab87..9b8f031bc25 100644 --- a/intern/cycles/blender/display_driver.cpp +++ b/intern/cycles/blender/display_driver.cpp @@ -106,11 +106,11 @@ GPUShader *BlenderFallbackDisplayShader::bind(int width, int height) /* Bind shader now to enable uniform assignment. */ GPU_shader_bind(shader_program_); float slot = 0; - GPU_shader_uniform_vector_int(shader_program_, image_texture_location_, 1, 1, &slot); + GPU_shader_uniform_int_ex(shader_program_, image_texture_location_, 1, 1, &slot); float size[2]; size[0] = width; size[1] = height; - GPU_shader_uniform_vector(shader_program_, fullscreen_location_, 2, 1, size); + GPU_shader_uniform_float_ex(shader_program_, fullscreen_location_, 2, 1, size); return shader_program_; } diff --git a/source/blender/draw/intern/draw_command.cc b/source/blender/draw/intern/draw_command.cc index c06ff88537a..86a0480b3f7 100644 --- a/source/blender/draw/intern/draw_command.cc +++ b/source/blender/draw/intern/draw_command.cc @@ -76,16 +76,16 @@ void PushConstant::execute(RecordingState &state) const } switch (type) { case PushConstant::Type::IntValue: - GPU_shader_uniform_vector_int(state.shader, location, comp_len, array_len, int4_value); + GPU_shader_uniform_int_ex(state.shader, location, comp_len, array_len, int4_value); break; case PushConstant::Type::IntReference: - GPU_shader_uniform_vector_int(state.shader, location, comp_len, array_len, int_ref); + GPU_shader_uniform_int_ex(state.shader, location, comp_len, array_len, int_ref); break; case PushConstant::Type::FloatValue: - GPU_shader_uniform_vector(state.shader, location, comp_len, array_len, float4_value); + GPU_shader_uniform_float_ex(state.shader, location, comp_len, array_len, float4_value); break; case PushConstant::Type::FloatReference: - GPU_shader_uniform_vector(state.shader, location, comp_len, array_len, float_ref); + GPU_shader_uniform_float_ex(state.shader, location, comp_len, array_len, float_ref); break; } } diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 35a83d5635a..4139ffcb261 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -522,10 +522,10 @@ BLI_INLINE void draw_legacy_matrix_update(DRWShadingGroup *shgroup, /* Still supported for compatibility with gpu_shader_* but should be forbidden. */ DRWObjectMatrix *ob_mats = DRW_memblock_elem_from_handle(DST.vmempool->obmats, handle); if (obmat_loc != -1) { - GPU_shader_uniform_vector(shgroup->shader, obmat_loc, 16, 1, (float *)ob_mats->model); + GPU_shader_uniform_float_ex(shgroup->shader, obmat_loc, 16, 1, (float *)ob_mats->model); } if (obinv_loc != -1) { - GPU_shader_uniform_vector(shgroup->shader, obinv_loc, 16, 1, (float *)ob_mats->modelinverse); + GPU_shader_uniform_float_ex(shgroup->shader, obinv_loc, 16, 1, (float *)ob_mats->modelinverse); } } @@ -549,7 +549,7 @@ BLI_INLINE void draw_geometry_execute(DRWShadingGroup *shgroup, if (baseinst_loc != -1) { /* Fallback when ARB_shader_draw_parameters is not supported. */ - GPU_shader_uniform_vector_int(shgroup->shader, baseinst_loc, 1, 1, (int *)&inst_first); + GPU_shader_uniform_int_ex(shgroup->shader, baseinst_loc, 1, 1, (int *)&inst_first); /* Avoids VAO reconfiguration on older hardware. (see GPU_batch_draw_advanced) */ inst_first = 0; } @@ -615,7 +615,7 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup, memcpy(&mat4_stack[array_index], uni->fvalue, sizeof(float) * uni->length); /* Flush array data to shader. */ if (array_index <= 0) { - GPU_shader_uniform_vector(shgroup->shader, uni->location, 16, 1, mat4_stack); + GPU_shader_uniform_float_ex(shgroup->shader, uni->location, 16, 1, mat4_stack); array_uniform_loc = -1; } continue; @@ -626,23 +626,23 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup, case DRW_UNIFORM_INT_COPY: BLI_assert(uni->arraysize == 1); if (uni->arraysize == 1) { - GPU_shader_uniform_vector_int( + GPU_shader_uniform_int_ex( shgroup->shader, uni->location, uni->length, uni->arraysize, uni->ivalue); } break; case DRW_UNIFORM_INT: - GPU_shader_uniform_vector_int( + GPU_shader_uniform_int_ex( shgroup->shader, uni->location, uni->length, uni->arraysize, uni->pvalue); break; case DRW_UNIFORM_FLOAT_COPY: BLI_assert(uni->arraysize == 1); if (uni->arraysize == 1) { - GPU_shader_uniform_vector( + GPU_shader_uniform_float_ex( shgroup->shader, uni->location, uni->length, uni->arraysize, uni->fvalue); } break; case DRW_UNIFORM_FLOAT: - GPU_shader_uniform_vector( + GPU_shader_uniform_float_ex( shgroup->shader, uni->location, uni->length, uni->arraysize, uni->pvalue); break; case DRW_UNIFORM_TEXTURE: @@ -690,7 +690,7 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup, case DRW_UNIFORM_RESOURCE_CHUNK: { state->chunkid_loc = uni->location; int zero = 0; - GPU_shader_uniform_vector_int(shgroup->shader, uni->location, 1, 1, &zero); + GPU_shader_uniform_int_ex(shgroup->shader, uni->location, 1, 1, &zero); break; } case DRW_UNIFORM_RESOURCE_ID: @@ -809,7 +809,7 @@ static void draw_call_resource_bind(DRWCommandsState *state, const DRWResourceHa int chunk = DRW_handle_chunk_get(handle); if (state->resource_chunk != chunk) { if (state->chunkid_loc != -1) { - GPU_shader_uniform_vector_int(DST.shader, state->chunkid_loc, 1, 1, &chunk); + GPU_shader_uniform_int_ex(DST.shader, state->chunkid_loc, 1, 1, &chunk); } if (state->obmats_loc != -1) { GPU_uniformbuf_unbind(DST.vmempool->matrices_ubo[state->resource_chunk]); @@ -829,7 +829,7 @@ static void draw_call_resource_bind(DRWCommandsState *state, const DRWResourceHa if (state->resourceid_loc != -1) { int id = DRW_handle_id_get(handle); if (state->resource_id != id) { - GPU_shader_uniform_vector_int(DST.shader, state->resourceid_loc, 1, 1, &id); + GPU_shader_uniform_int_ex(DST.shader, state->resourceid_loc, 1, 1, &id); state->resource_id = id; } } diff --git a/source/blender/editors/interface/interface_icons.cc b/source/blender/editors/interface/interface_icons.cc index 634f45283f6..7e0b17aa128 100644 --- a/source/blender/editors/interface/interface_icons.cc +++ b/source/blender/editors/interface/interface_icons.cc @@ -1804,18 +1804,18 @@ static void icon_draw_texture(float x, if (rgb) { const float color[4] = {rgb[0], rgb[1], rgb[2], alpha}; - GPU_shader_uniform_vector(shader, color_loc, 4, 1, color); + GPU_shader_uniform_float_ex(shader, color_loc, 4, 1, color); } else { const float color[4] = {alpha, alpha, alpha, alpha}; - GPU_shader_uniform_vector(shader, color_loc, 4, 1, color); + GPU_shader_uniform_float_ex(shader, color_loc, 4, 1, color); } const float tex_color[4] = {x1, y1, x2, y2}; const float geom_color[4] = {x, y, x + w, y + h}; - GPU_shader_uniform_vector(shader, rect_tex_loc, 4, 1, tex_color); - GPU_shader_uniform_vector(shader, rect_geom_loc, 4, 1, geom_color); + GPU_shader_uniform_float_ex(shader, rect_tex_loc, 4, 1, tex_color); + GPU_shader_uniform_float_ex(shader, rect_geom_loc, 4, 1, geom_color); GPU_shader_uniform_1f(shader, "text_width", text_width); GPU_texture_bind_ex(texture, GPU_SAMPLER_ICON, img_binding, false); diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c index 77014fde8a8..ea4050d0ba0 100644 --- a/source/blender/editors/mask/mask_draw.c +++ b/source/blender/editors/mask/mask_draw.c @@ -722,7 +722,7 @@ void ED_mask_draw_region( GPU_matrix_mul(stabmat); } IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR); - GPU_shader_uniform_vector( + GPU_shader_uniform_float_ex( state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, buf_col); if (overlay_mode == MASK_OVERLAY_COMBINED) { diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index c8a8f817f96..b9be4a5ec55 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -128,9 +128,9 @@ int GPU_shader_get_uniform(GPUShader *shader, const char *name); * Sets a generic push constant (a.k.a. uniform). * \a length and \a array_size should match the create info push_constant declaration. */ -void GPU_shader_uniform_vector( +void GPU_shader_uniform_float_ex( GPUShader *shader, int location, int length, int array_size, const float *value); -void GPU_shader_uniform_vector_int( +void GPU_shader_uniform_int_ex( GPUShader *shader, int location, int length, int array_size, const int *value); /** diff --git a/source/blender/gpu/intern/gpu_immediate.cc b/source/blender/gpu/intern/gpu_immediate.cc index ada34fdaeee..645a920fc83 100644 --- a/source/blender/gpu/intern/gpu_immediate.cc +++ b/source/blender/gpu/intern/gpu_immediate.cc @@ -625,7 +625,7 @@ void immUniformColor4f(float r, float g, float b, float a) int32_t uniform_loc = GPU_shader_get_builtin_uniform(imm->shader, GPU_UNIFORM_COLOR); BLI_assert(uniform_loc != -1); float data[4] = {r, g, b, a}; - GPU_shader_uniform_vector(imm->shader, uniform_loc, 4, 1, data); + GPU_shader_uniform_float_ex(imm->shader, uniform_loc, 4, 1, data); /* For wide Line workaround. */ copy_v4_v4(imm->uniform_color, data); } diff --git a/source/blender/gpu/intern/gpu_matrix.cc b/source/blender/gpu/intern/gpu_matrix.cc index b46860cf0f4..d285ff5ef99 100644 --- a/source/blender/gpu/intern/gpu_matrix.cc +++ b/source/blender/gpu/intern/gpu_matrix.cc @@ -623,30 +623,31 @@ void GPU_matrix_bind(GPUShader *shader) int32_t P_inv = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_PROJECTION_INV); if (MV != -1) { - GPU_shader_uniform_vector( + GPU_shader_uniform_float_ex( shader, MV, 16, 1, (const float *)GPU_matrix_model_view_get(nullptr)); } if (P != -1) { - GPU_shader_uniform_vector(shader, P, 16, 1, (const float *)GPU_matrix_projection_get(nullptr)); + GPU_shader_uniform_float_ex( + shader, P, 16, 1, (const float *)GPU_matrix_projection_get(nullptr)); } if (MVP != -1) { - GPU_shader_uniform_vector( + GPU_shader_uniform_float_ex( shader, MVP, 16, 1, (const float *)GPU_matrix_model_view_projection_get(nullptr)); } if (N != -1) { - GPU_shader_uniform_vector(shader, N, 9, 1, (const float *)GPU_matrix_normal_get(nullptr)); + GPU_shader_uniform_float_ex(shader, N, 9, 1, (const float *)GPU_matrix_normal_get(nullptr)); } if (MV_inv != -1) { Mat4 m; GPU_matrix_model_view_get(m); invert_m4(m); - GPU_shader_uniform_vector(shader, MV_inv, 16, 1, (const float *)m); + GPU_shader_uniform_float_ex(shader, MV_inv, 16, 1, (const float *)m); } if (P_inv != -1) { Mat4 m; GPU_matrix_projection_get(m); invert_m4(m); - GPU_shader_uniform_vector(shader, P_inv, 16, 1, (const float *)m); + GPU_shader_uniform_float_ex(shader, P_inv, 16, 1, (const float *)m); } gpu_matrix_state_active_set_dirty(false); diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc index 2875763fb5e..0edc2072302 100644 --- a/source/blender/gpu/intern/gpu_shader.cc +++ b/source/blender/gpu/intern/gpu_shader.cc @@ -618,13 +618,13 @@ int GPU_shader_get_program(GPUShader *shader) /** \name Uniforms setters * \{ */ -void GPU_shader_uniform_vector( +void GPU_shader_uniform_float_ex( GPUShader *shader, int loc, int len, int array_size, const float *value) { unwrap(shader)->uniform_float(loc, len, array_size, value); } -void GPU_shader_uniform_vector_int( +void GPU_shader_uniform_int_ex( GPUShader *shader, int loc, int len, int array_size, const int *value) { unwrap(shader)->uniform_int(loc, len, array_size, value); @@ -633,7 +633,7 @@ void GPU_shader_uniform_vector_int( void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value) { const int loc = GPU_shader_get_uniform(sh, name); - GPU_shader_uniform_vector_int(sh, loc, 1, 1, &value); + GPU_shader_uniform_int_ex(sh, loc, 1, 1, &value); } void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value) @@ -662,37 +662,37 @@ void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, fl void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value) { const int loc = GPU_shader_get_uniform(sh, name); - GPU_shader_uniform_vector(sh, loc, 1, 1, &value); + GPU_shader_uniform_float_ex(sh, loc, 1, 1, &value); } void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2]) { const int loc = GPU_shader_get_uniform(sh, name); - GPU_shader_uniform_vector(sh, loc, 2, 1, data); + GPU_shader_uniform_float_ex(sh, loc, 2, 1, data); } void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3]) { const int loc = GPU_shader_get_uniform(sh, name); - GPU_shader_uniform_vector(sh, loc, 3, 1, data); + GPU_shader_uniform_float_ex(sh, loc, 3, 1, data); } void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4]) { const int loc = GPU_shader_get_uniform(sh, name); - GPU_shader_uniform_vector(sh, loc, 4, 1, data); + GPU_shader_uniform_float_ex(sh, loc, 4, 1, data); } void GPU_shader_uniform_2iv(GPUShader *sh, const char *name, const int data[2]) { const int loc = GPU_shader_get_uniform(sh, name); - GPU_shader_uniform_vector_int(sh, loc, 2, 1, data); + GPU_shader_uniform_int_ex(sh, loc, 2, 1, data); } void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4]) { const int loc = GPU_shader_get_uniform(sh, name); - GPU_shader_uniform_vector(sh, loc, 16, 1, (const float *)data); + GPU_shader_uniform_float_ex(sh, loc, 16, 1, (const float *)data); } void GPU_shader_uniform_mat3_as_mat4(GPUShader *sh, const char *name, const float data[3][3]) @@ -705,13 +705,13 @@ void GPU_shader_uniform_mat3_as_mat4(GPUShader *sh, const char *name, const floa void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float (*val)[2]) { const int loc = GPU_shader_get_uniform(sh, name); - GPU_shader_uniform_vector(sh, loc, 2, len, (const float *)val); + GPU_shader_uniform_float_ex(sh, loc, 2, len, (const float *)val); } void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float (*val)[4]) { const int loc = GPU_shader_get_uniform(sh, name); - GPU_shader_uniform_vector(sh, loc, 4, len, (const float *)val); + GPU_shader_uniform_float_ex(sh, loc, 4, len, (const float *)val); } /** \} */ @@ -741,7 +741,7 @@ void Shader::set_srgb_uniform(GPUShader *shader) { int32_t loc = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_SRGB_TRANSFORM); if (loc != -1) { - GPU_shader_uniform_vector_int(shader, loc, 1, 1, &g_shader_builtin_srgb_transform); + GPU_shader_uniform_int_ex(shader, loc, 1, 1, &g_shader_builtin_srgb_transform); } g_shader_builtin_srgb_is_dirty = false; } diff --git a/source/blender/gpu/metal/mtl_batch.mm b/source/blender/gpu/metal/mtl_batch.mm index 13496e8ad6f..07aaa5cfe62 100644 --- a/source/blender/gpu/metal/mtl_batch.mm +++ b/source/blender/gpu/metal/mtl_batch.mm @@ -530,16 +530,16 @@ id MTLBatch::bind(uint v_first, uint v_count, uint i_fi /* Set SSBO-fetch-mode status uniforms. */ BLI_assert(active_shader_->uni_ssbo_input_prim_type_loc != -1); BLI_assert(active_shader_->uni_ssbo_input_vert_count_loc != -1); - GPU_shader_uniform_vector_int(reinterpret_cast(wrap(active_shader_)), - active_shader_->uni_ssbo_input_prim_type_loc, - 1, - 1, - (const int *)(&final_prim_type)); - GPU_shader_uniform_vector_int(reinterpret_cast(wrap(active_shader_)), - active_shader_->uni_ssbo_input_vert_count_loc, - 1, - 1, - (const int *)(&v_count)); + GPU_shader_uniform_int_ex(reinterpret_cast(wrap(active_shader_)), + active_shader_->uni_ssbo_input_prim_type_loc, + 1, + 1, + (const int *)(&final_prim_type)); + GPU_shader_uniform_int_ex(reinterpret_cast(wrap(active_shader_)), + active_shader_->uni_ssbo_input_vert_count_loc, + 1, + 1, + (const int *)(&v_count)); } /* Ensure Context Render Pipeline State is fully setup and ready to execute the draw. diff --git a/source/blender/gpu/metal/mtl_immediate.mm b/source/blender/gpu/metal/mtl_immediate.mm index f0809e6e9d3..985b962cc99 100644 --- a/source/blender/gpu/metal/mtl_immediate.mm +++ b/source/blender/gpu/metal/mtl_immediate.mm @@ -248,16 +248,16 @@ void MTLImmediate::end() "ssbo_input_prim_type uniform location invalid!"); BLI_assert_msg(active_mtl_shader->uni_ssbo_input_vert_count_loc != -1, "ssbo_input_vert_count uniform location invalid!"); - GPU_shader_uniform_vector_int(reinterpret_cast(wrap(active_mtl_shader)), - active_mtl_shader->uni_ssbo_input_prim_type_loc, - 1, - 1, - (const int *)(&this->prim_type)); - GPU_shader_uniform_vector_int(reinterpret_cast(wrap(active_mtl_shader)), - active_mtl_shader->uni_ssbo_input_vert_count_loc, - 1, - 1, - (const int *)(&this->vertex_idx)); + GPU_shader_uniform_int_ex(reinterpret_cast(wrap(active_mtl_shader)), + active_mtl_shader->uni_ssbo_input_prim_type_loc, + 1, + 1, + (const int *)(&this->prim_type)); + GPU_shader_uniform_int_ex(reinterpret_cast(wrap(active_mtl_shader)), + active_mtl_shader->uni_ssbo_input_vert_count_loc, + 1, + 1, + (const int *)(&this->vertex_idx)); } MTLPrimitiveType mtl_prim_type = gpu_prim_type_to_metal(this->prim_type); diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c index 2c13e271e36..80c22bd7a97 100644 --- a/source/blender/python/gpu/gpu_py_shader.c +++ b/source/blender/python/gpu/gpu_py_shader.c @@ -269,7 +269,7 @@ static PyObject *pygpu_shader_uniform_vector_float(BPyGPUShader *self, PyObject } GPU_shader_bind(self->shader); - GPU_shader_uniform_vector(self->shader, location, length, count, pybuffer.buf); + GPU_shader_uniform_float_ex(self->shader, location, length, count, pybuffer.buf); PyBuffer_Release(&pybuffer); @@ -292,7 +292,7 @@ static PyObject *pygpu_shader_uniform_vector_int(BPyGPUShader *self, PyObject *a } GPU_shader_bind(self->shader); - GPU_shader_uniform_vector_int(self->shader, location, length, count, pybuffer.buf); + GPU_shader_uniform_int_ex(self->shader, location, length, count, pybuffer.buf); PyBuffer_Release(&pybuffer); @@ -367,7 +367,7 @@ static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args) } GPU_shader_bind(self->shader); - GPU_shader_uniform_vector_int(self->shader, location, length, 1, values); + GPU_shader_uniform_int_ex(self->shader, location, length, 1, values); Py_RETURN_NONE; } @@ -437,7 +437,7 @@ static PyObject *pygpu_shader_uniform_float(BPyGPUShader *self, PyObject *args) } GPU_shader_bind(self->shader); - GPU_shader_uniform_vector(self->shader, location, length, 1, values); + GPU_shader_uniform_float_ex(self->shader, location, length, 1, values); Py_RETURN_NONE; } @@ -509,7 +509,7 @@ static PyObject *pygpu_shader_uniform_int(BPyGPUShader *self, PyObject *args) } GPU_shader_bind(self->shader); - GPU_shader_uniform_vector_int(self->shader, location, length, 1, values); + GPU_shader_uniform_int_ex(self->shader, location, length, 1, values); Py_RETURN_NONE; } diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index 5ce080e575a..ebe670bfa21 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -846,9 +846,9 @@ void wm_draw_region_blend(ARegion *region, int view, bool blend) GPU_texture_bind(texture, texture_bind_loc); - GPU_shader_uniform_vector(shader, rect_tex_loc, 4, 1, rectt); - GPU_shader_uniform_vector(shader, rect_geo_loc, 4, 1, rectg); - GPU_shader_uniform_vector(shader, color_loc, 4, 1, (const float[4]){1, 1, 1, 1}); + GPU_shader_uniform_float_ex(shader, rect_tex_loc, 4, 1, rectt); + GPU_shader_uniform_float_ex(shader, rect_geo_loc, 4, 1, rectg); + GPU_shader_uniform_float_ex(shader, color_loc, 4, 1, (const float[4]){1, 1, 1, 1}); GPUBatch *quad = GPU_batch_preset_quad(); GPU_batch_set_shader(quad, shader); diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c index bb03c2c1413..fecbcca3c90 100644 --- a/source/blender/windowmanager/intern/wm_gesture.c +++ b/source/blender/windowmanager/intern/wm_gesture.c @@ -326,7 +326,7 @@ static void draw_filled_lasso(wmGesture *gt) IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR); GPU_shader_bind(state.shader); - GPU_shader_uniform_vector( + GPU_shader_uniform_float_ex( state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red); immDrawPixelsTexTiled( -- 2.30.2 From d219cd25cff2642312f500f4f432c4ebff985d15 Mon Sep 17 00:00:00 2001 From: Weizhen Huang Date: Mon, 13 Feb 2023 11:39:12 +0100 Subject: [PATCH 11/11] Refactor: Gizmo: handle modifier event in gizmo modal instead of gizmo group --- .../gizmo_library/gizmo_types/cage2d_gizmo.c | 42 ++++++++++++++++--- .../editors/space_view3d/view3d_gizmo_light.c | 3 +- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c index cc75d83b923..75179cc2d9d 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c @@ -44,6 +44,8 @@ /* The same as in `draw_cache.c` */ #define CIRCLE_RESOL 32 +static int gizmo_cage2d_transform_flag_get(const wmGizmo *gz); + static bool gizmo_calc_rect_view_scale(const wmGizmo *gz, const float dims[2], float scale[2]) { float matrix_final_no_offset[4][4]; @@ -616,7 +618,7 @@ static void gizmo_cage2d_draw_intern(wmGizmo *gz, RNA_float_get_array(gz->ptr, "dimensions", dims); float matrix_final[4][4]; - const int transform_flag = RNA_enum_get(gz->ptr, "transform"); + const int transform_flag = gizmo_cage2d_transform_flag_get(gz); const int draw_style = RNA_enum_get(gz->ptr, "draw_style"); const int draw_options = RNA_enum_get(gz->ptr, "draw_options"); @@ -831,7 +833,7 @@ static int gizmo_cage2d_test_select(bContext *C, wmGizmo *gz, const int mval[2]) /* Expand for hots-pot. */ const float size[2] = {size_real[0] + margin[0] / 2, size_real[1] + margin[1] / 2}; - const int transform_flag = RNA_enum_get(gz->ptr, "transform"); + const int transform_flag = gizmo_cage2d_transform_flag_get(gz); const int draw_options = RNA_enum_get(gz->ptr, "draw_options"); if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_TRANSLATE) { @@ -934,8 +936,21 @@ typedef struct RectTransformInteraction { float orig_matrix_offset[4][4]; float orig_matrix_final_no_offset[4][4]; Dial *dial; + bool use_temp_uniform; } RectTransformInteraction; +static int gizmo_cage2d_transform_flag_get(const wmGizmo *gz) +{ + RectTransformInteraction *data = gz->interaction_data; + int transform_flag = RNA_enum_get(gz->ptr, "transform"); + if (data) { + if (data->use_temp_uniform) { + transform_flag |= ED_GIZMO_CAGE_XFORM_FLAG_SCALE_UNIFORM; + } + } + return transform_flag; +} + static void gizmo_cage2d_setup(wmGizmo *gz) { gz->flag |= WM_GIZMO_DRAW_MODAL | WM_GIZMO_DRAW_NO_SCALE; @@ -1020,9 +1035,6 @@ static int gizmo_cage2d_modal(bContext *C, const wmEvent *event, eWM_GizmoFlagTweak UNUSED(tweak_flag)) { - if (event->type != MOUSEMOVE) { - return OPERATOR_RUNNING_MODAL; - } /* For transform logic to be manageable we operate in -0.5..0.5 2D space, * no matter the size of the rectangle, mouse coords are scaled to unit space. * The mouse coords have been projected into the matrix @@ -1032,6 +1044,25 @@ static int gizmo_cage2d_modal(bContext *C, * - Matrix translation is also multiplied by 'dims'. */ RectTransformInteraction *data = gz->interaction_data; + int transform_flag = RNA_enum_get(gz->ptr, "transform"); + if ((transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_SCALE_UNIFORM) == 0) { + /* WARNING: Checking the events modifier only makes sense as long as `tweak_flag` + * remains unused (this controls #WM_GIZMO_TWEAK_PRECISE by default). */ + const bool use_temp_uniform = (event->modifier & KM_SHIFT) != 0; + const bool changed = data->use_temp_uniform != use_temp_uniform; + data->use_temp_uniform = data->use_temp_uniform; + if (use_temp_uniform) { + transform_flag |= ED_GIZMO_CAGE_XFORM_FLAG_SCALE_UNIFORM; + } + + if (changed) { + /* Always refresh. */ + } + else if (event->type != MOUSEMOVE) { + return OPERATOR_RUNNING_MODAL; + } + } + float point_local[2]; float dims[2]; @@ -1050,7 +1081,6 @@ static int gizmo_cage2d_modal(bContext *C, } } - const int transform_flag = RNA_enum_get(gz->ptr, "transform"); wmGizmoProperty *gz_prop; gz_prop = WM_gizmo_target_property_find(gz, "matrix"); diff --git a/source/blender/editors/space_view3d/view3d_gizmo_light.c b/source/blender/editors/space_view3d/view3d_gizmo_light.c index bdc5bd9b792..f3db63b9a20 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_light.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_light.c @@ -468,8 +468,7 @@ static void WIDGETGROUP_light_area_refresh(const bContext *C, wmGizmoGroup *gzgr copy_m4_m4(gz->matrix_basis, ob->object_to_world); int flag = ED_GIZMO_CAGE_XFORM_FLAG_SCALE; - const wmEvent *event = CTX_wm_window(C)->eventstate; - if (ELEM(la->area_shape, LA_AREA_SQUARE, LA_AREA_DISK) || (event->modifier & KM_SHIFT)) { + if (ELEM(la->area_shape, LA_AREA_SQUARE, LA_AREA_DISK)) { flag |= ED_GIZMO_CAGE_XFORM_FLAG_SCALE_UNIFORM; } RNA_enum_set(gz->ptr, "transform", flag); -- 2.30.2